:root {
  --bg0: #071018;
  --bg1: #0f1c2b;
  --bg2: #152536;
  --ink: #e8f0f7;
  --muted: #8aa0b5;
  --line: rgba(232, 240, 247, 0.12);
  --accent: #e85d04;
  --accent-2: #ffba08;
  --good: #2dd4a8;
  --warn: #f4a261;
  --danger: #ef476f;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font-display: "Bebas Neue", Impact, sans-serif;
  --font-body: "IBM Plex Sans", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(120% 80% at 50% -10%, #1c334d 0%, transparent 55%),
    radial-gradient(90% 60% at 100% 100%, rgba(232, 93, 4, 0.18) 0%, transparent 45%),
    linear-gradient(180deg, var(--bg0), var(--bg1) 40%, #050a10);
  color: var(--ink);
  font-family: var(--font-body);
  overscroll-behavior: none;
  transition: background 0.2s ease, color 0.2s ease;
}

body {
  min-height: 100dvh;
}

/* Standby — waiting for start beep */
body.phase-delay {
  background: #FFFF00;
  color: #1a1200;
  --ink: #1a1200;
  --muted: #5c4a14;
  --line: rgba(26, 18, 0, 0.18);
  --bg0: #FFFF00;
  --bg1: #FFFF00;
  --bg2: #FFFF00;
}

/* Live — recording / shooting */
body.phase-live {
  background: #00FF00;
  color: #04140c;
  --ink: #04140c;
  --muted: #14532d;
  --line: rgba(4, 20, 12, 0.18);
  --bg0: #00FF00;
  --bg1: #00FF00;
  --bg2: #00FF00;
}

body.phase-delay .primary-btn,
body.phase-live .primary-btn {
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.2);
}

body.phase-delay .secondary-btn,
body.phase-live .secondary-btn,
body.phase-delay .icon-btn,
body.phase-live .icon-btn,
body.phase-delay .inline-field input,
body.phase-delay .inline-field select,
body.phase-live .inline-field input,
body.phase-live .inline-field select,
body.phase-delay .badge,
body.phase-live .badge,
body.phase-delay .shot-list li,
body.phase-live .shot-list li,
body.phase-delay .score-list li,
body.phase-live .score-list li {
  background: rgba(255, 255, 255, 0.35);
  border-color: rgba(0, 0, 0, 0.12);
  color: inherit;
}

body.phase-delay #levelMeter,
body.phase-live #levelMeter {
  background: rgba(0, 0, 0, 0.15);
  border-color: rgba(0, 0, 0, 0.15);
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(16px + var(--safe-top)) 18px calc(28px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 100dvh;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, var(--accent-2), var(--accent));
  box-shadow: 0 0 0 4px rgba(232, 93, 4, 0.18);
}

.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 2rem;
  letter-spacing: 0.06em;
  font-weight: 400;
  line-height: 1;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  display: grid;
  place-items: center;
}

.status-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
}

.badge.idle { color: var(--muted); }
.badge.delay { color: var(--warn); border-color: rgba(244, 162, 97, 0.35); }
.badge.live { color: var(--good); border-color: rgba(45, 212, 168, 0.4); background: rgba(45, 212, 168, 0.08); }
.badge.done { color: var(--accent-2); }
.badge.mic.on { color: var(--good); }
.badge.mic.off { color: var(--muted); }
.badge.par.on { color: var(--accent-2); border-color: rgba(255, 186, 8, 0.4); }
.badge.par.off { color: var(--muted); }
.badge.par.under { color: var(--good); border-color: rgba(45, 212, 168, 0.4); }
.badge.par.over { color: var(--danger); border-color: rgba(239, 71, 111, 0.4); }

.session-bar {
  display: grid;
  grid-template-columns: 1fr 1.15fr;
  gap: 10px;
}

.inline-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.inline-field input,
.inline-field select {
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.28);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  padding: 0 12px;
  outline: none;
}

.inline-field select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 18px, calc(100% - 12px) 18px;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 32px;
}

.par-result {
  margin: -8px 0 14px;
  font-family: var(--font-display);
  font-size: 1.6rem;
  letter-spacing: 0.08em;
}

.par-result.under { color: var(--good); }
.par-result.over { color: var(--danger); }

.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.metrics:has(#parMetric:not(.hidden)) {
  grid-template-columns: repeat(2, 1fr);
}

.metric {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 1.35rem;
  font-weight: 600;
}

.drill-hint {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
  min-height: 1.1em;
}

.scores-panel {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.score-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.chip {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  font-family: var(--font-body);
}

.chip.active {
  color: var(--accent-2);
  border-color: rgba(255, 186, 8, 0.35);
  background: rgba(255, 186, 8, 0.08);
}

.score-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 40vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.score-list li {
  padding: 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.score-list li:hover,
.score-list li.expanded {
  border-color: rgba(255, 186, 8, 0.4);
  background: rgba(255, 255, 255, 0.07);
}

.score-list .row1 {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-weight: 700;
  margin-bottom: 4px;
  align-items: center;
}

.score-list .chev {
  color: var(--muted);
  font-size: 0.75rem;
  margin-left: 8px;
  transition: transform 0.15s ease;
}

.score-list li.expanded .chev {
  transform: rotate(180deg);
}

.score-list .time {
  font-family: var(--font-mono);
  color: var(--accent-2);
  display: flex;
  align-items: center;
}

.score-list .row2 {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  color: var(--muted);
  font-size: 0.8rem;
}

.score-list .tag.under { color: var(--good); }
.score-list .tag.over { color: var(--danger); }

.score-detail {
  display: none;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.score-list li.expanded .score-detail {
  display: block;
}

.score-detail .detail-head {
  display: grid;
  grid-template-columns: 40px 1fr 1fr;
  gap: 8px;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 6px;
  padding: 0 2px;
}

.score-detail .detail-head span:last-child {
  text-align: right;
}

.score-detail ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.score-detail li {
  display: grid;
  grid-template-columns: 40px 1fr 1fr;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  cursor: default;
}

.score-detail li:hover {
  border-color: var(--line);
  background: rgba(0, 0, 0, 0.18);
}

.score-detail .n { color: var(--muted); font-weight: 600; }
.score-detail .t { font-weight: 600; }
.score-detail .s { text-align: right; color: var(--accent-2); }
.score-detail .empty-detail {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.settings-group {
  margin: 8px 0 8px;
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-2);
  font-weight: 700;
}

.settings-note,
.toggle-note {
  display: block;
  margin: -4px 0 14px;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.4;
}

#levelMeter {
  width: 100%;
  height: 40px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--line);
  display: block;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.primary-btn,
.secondary-btn,
.text-btn {
  font-family: var(--font-body);
  font-weight: 700;
  border: none;
  cursor: pointer;
}

.primary-btn {
  height: 64px;
  border-radius: 16px;
  background: linear-gradient(180deg, #ff7a1a, var(--accent));
  color: #140800;
  font-size: 1.25rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  box-shadow: 0 12px 28px rgba(232, 93, 4, 0.35);
}

.primary-btn:disabled {
  opacity: 0.45;
  box-shadow: none;
}

.primary-btn.running {
  background: linear-gradient(180deg, #ff6b8a, var(--danger));
  color: #fff;
  box-shadow: 0 12px 28px rgba(239, 71, 111, 0.3);
}

.secondary-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.secondary-btn {
  height: 48px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  border: 1px solid var(--line);
  font-size: 0.95rem;
}

.secondary-btn:disabled {
  opacity: 0.4;
}

.shots-panel {
  flex: 1;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.shots-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.shots-head h2 {
  margin: 0;
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.text-btn {
  background: none;
  color: var(--accent-2);
  font-size: 0.85rem;
  padding: 6px 0;
}

.shot-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 28vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.shot-list li {
  display: grid;
  grid-template-columns: 40px 1fr 1fr;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 0.95rem;
}

.shot-list .n {
  color: var(--muted);
  font-weight: 600;
}

.shot-list .t {
  font-weight: 600;
}

.shot-list .s {
  text-align: right;
  color: var(--accent-2);
}

.empty {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.install-hint {
  margin: 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(255, 186, 8, 0.1);
  border: 1px solid rgba(255, 186, 8, 0.28);
  color: #ffd56a;
  font-size: 0.86rem;
  line-height: 1.4;
}

.hidden { display: none !important; }

.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.sheet-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 88vh;
  overflow: auto;
  background: linear-gradient(180deg, var(--bg2), var(--bg0));
  border-radius: 22px 22px 0 0;
  padding: 12px 18px calc(22px + var(--safe-bottom));
  border-top: 1px solid var(--line);
}

.sheet-handle {
  width: 42px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  margin: 4px auto 14px;
}

.sheet-panel h2 {
  margin: 0 0 16px;
  font-family: var(--font-display);
  font-size: 1.8rem;
  letter-spacing: 0.05em;
  font-weight: 400;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 18px;
  font-size: 0.95rem;
}

.field span {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
}

.field em {
  font-style: normal;
  color: var(--accent-2);
  font-family: var(--font-mono);
}

.field small {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.field input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.toggle {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 14px;
  font-size: 0.95rem;
  line-height: 1.35;
}

.toggle input {
  margin-top: 3px;
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.sheet-close {
  width: 100%;
  margin-top: 8px;
}

@media (min-width: 600px) {
  .app {
    padding-top: 28px;
  }
}
