/* Clicky Icky — dark, high contrast, thumb-sized targets */

:root {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-sunk: #0b1220;
  --line: #334155;
  --fg: #e2e8f0;
  --fg-dim: #94a3b8;
  --accent: #22d3ee;
  --accent-ink: #062a33;    /* text on an accent-filled control */
  --raised: #334155;        /* default button face */
  --edge: #475569;          /* a border that needs to stand out from --line */
  --good: #34d399;
  --danger: #f87171;
  --danger-edge: #7f1d1d;
  --radius: 12px;
  --tap: 44px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}

body {
  padding-bottom: env(safe-area-inset-bottom);
  max-width: 720px;
  margin: 0 auto;
}

h1 { font-size: 18px; margin: 0; letter-spacing: .5px; }
h2 { font-size: 15px; margin: 0 0 8px; }
h3 { font-size: 13px; margin: 12px 0 6px; text-transform: uppercase; letter-spacing: .08em; color: var(--fg-dim); }
p { margin: 8px 0; }

.muted { color: var(--fg-dim); }
.small { font-size: 13px; }
.bullets { padding-left: 18px; }
.bullets li { margin: 6px 0; }

/* ---------- chrome ---------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; }
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--edge); flex: none; transition: background .2s;
}
.dot.live { background: var(--good); box-shadow: 0 0 0 4px rgba(52,211,153,.18); }
.dot.rec  { background: var(--accent); box-shadow: 0 0 0 4px rgba(34,211,238,.18); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.status { font-size: 13px; color: var(--fg-dim); font-variant-numeric: tabular-nums; }

.tabs {
  position: sticky; top: 45px; z-index: 19;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.tab {
  appearance: none; border: 0; background: none; color: var(--fg-dim);
  font: inherit; font-size: 13px; padding: 11px 2px; min-height: var(--tap);
  border-bottom: 2px solid transparent; cursor: pointer;
}
.tab.active { color: var(--fg); border-bottom-color: var(--accent); }

main { padding: 12px 12px 32px; }
.panel { display: none; }
.panel.active { display: block; }

.card {
  background: var(--bg-card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
}
.divider { height: 1px; background: var(--line); margin: 14px 0; }

/* ---------- controls ---------- */

button {
  appearance: none; font: inherit; font-weight: 600; cursor: pointer;
  border-radius: 10px; min-height: var(--tap); padding: 0 16px;
  border: 1px solid var(--line); background: var(--raised); color: var(--fg);
  touch-action: manipulation;
}
button:active { transform: translateY(1px); }
/* The hold button must own the whole gesture. With any panning left to the
   browser, a few pixels of finger drift are read as the start of a scroll, the
   browser claims the pointer and fires pointercancel - which ended the
   recording mid-sound. Nothing here scrolls, so nothing is lost by refusing. */
#holdBtn {
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.ghost { background: transparent; }
button.danger { background: transparent; border-color: var(--danger-edge); color: var(--danger); }
button.small { min-height: 36px; padding: 0 12px; font-size: 13px; font-weight: 500; }
button.big { min-height: 52px; font-size: 16px; flex: 1; }
button.huge { width: 100%; min-height: 62px; font-size: 18px; }
button.listening { background: var(--danger); border-color: var(--danger); color: #2a0a0a; }

.row { display: flex; gap: 8px; align-items: center; margin: 10px 0; }
.row.wrap { flex-wrap: wrap; gap: 10px 14px; }

.field { display: block; margin: 12px 0; }
.field > span { display: block; font-size: 13px; color: var(--fg-dim); margin-bottom: 5px; }
.field.inline { display: flex; align-items: center; gap: 8px; margin: 0; }
.field.inline > span { margin: 0; white-space: nowrap; }

input[type=text], input[type=number], input[type=time], select {
  width: 100%; font: inherit; color: var(--fg);
  background: var(--bg-sunk); border: 1px solid var(--line);
  border-radius: 9px; padding: 10px 12px; min-height: var(--tap);
}
input.tiny { width: 92px; min-height: 36px; padding: 6px 8px; }
input[type=color] {
  width: 46px; height: 36px; padding: 2px; background: var(--bg-sunk);
  border: 1px solid var(--line); border-radius: 8px;
}
input[type=range] { width: 100%; accent-color: var(--accent); height: var(--tap); }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 20px; height: 20px; }

.checks { display: grid; gap: 2px; margin-bottom: 10px; }
.check, .radio {
  display: flex; align-items: center; gap: 9px;
  min-height: var(--tap); cursor: pointer;
}
.radio { gap: 7px; }
.radio input { flex: none; }

/* ---------- meters ---------- */

.hold-bar {
  height: 4px; border-radius: 2px; background: var(--bg-sunk);
  overflow: hidden; margin: 0 0 4px;
}
.hold-fill { height: 100%; width: 0%; background: var(--accent); transition: width .1s linear; }
button.holding { background: var(--danger); border-color: var(--danger); color: #fff; }

.meter-wrap { margin: 14px 0 10px; }
.meter {
  position: relative; height: 12px; border-radius: 6px;
  background: var(--bg-sunk); border: 1px solid var(--line); overflow: hidden;
}
.meter-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #3b82f6, var(--accent) 45%, var(--good) 78%, #fbbf24);
  transition: width .05s linear;
}
.meter-gate {
  position: absolute; top: -2px; bottom: -2px; width: 2px;
  background: var(--accent); left: 0; opacity: .9;
}
.meter-labels { display: flex; justify-content: space-between; font-size: 12px; color: var(--fg-dim); margin-top: 4px; }

.spectro {
  width: 100%; height: auto; display: block; border-radius: 8px;
  background: var(--bg-sunk); border: 1px solid var(--line);
  image-rendering: pixelated;
}

/* ---------- sound list ---------- */

.list { display: grid; gap: 8px; }
.item {
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; background: var(--bg-sunk);
}
.item-head { display: flex; align-items: center; gap: 10px; }
.item-name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-sub { font-size: 12px; color: var(--fg-dim); }
.item-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.badge {
  font-size: 11px; padding: 2px 7px; border-radius: 20px;
  border: 1px solid var(--line); color: var(--fg-dim); white-space: nowrap;
}
.badge.hit { border-color: var(--good); color: var(--good); }
.badge.cooling { border-color: var(--edge); color: var(--fg-dim); font-variant-numeric: tabular-nums; }

.advice { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 5px; }
.advice li {
  font-size: 13px; line-height: 1.45; color: var(--fg-dim);
  padding-left: 20px; position: relative;
}
.advice li::before { position: absolute; left: 0; top: 0; }
.advice li.good { color: var(--good); }
.advice li.good::before { content: '✓'; }
.advice li.warn::before { content: '!'; color: var(--danger); font-weight: 700; }
.advice li.tip::before { content: '→'; color: var(--accent); }

.merge { margin-top: 8px; }
.merge-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.merge-row select { flex: 1; min-width: 150px; }
.merge p { margin-top: 6px; }

/* Beside the live number, which moves too fast to read while also making a
   noise. Green once it has been over the line at least once, so "never got
   close" and "got there and something else stopped it" differ at a glance. */
.peak {
  font-size: 12px; color: var(--fg-dim); font-variant-numeric: tabular-nums;
  white-space: nowrap; flex: none;
}
.peak.over { color: var(--good); }

/* The scores it actually fired at. Tabular, because the point is comparing
   them against each other to find where the threshold belongs. */
.fired {
  font-size: 12px; line-height: 1.4; color: var(--fg-dim);
  font-variant-numeric: tabular-nums; margin: 6px 0 0;
}

/* The evidence that something nearly happened, for a sound nobody can produce
   on demand. Warned rather than dimmed: a near miss is usually a setting that
   wants moving, not information to be glanced past. */
.near-miss {
  font-size: 12px; line-height: 1.4; color: var(--danger);
  margin: 6px 0 0;
}

/* Said where the score bar is, because the bar is what contradicts it. */
.gate-note {
  font-size: 12px; line-height: 1.4; color: var(--danger);
  margin: 6px 0 0;
}
/* A gap doing what it was told is information, not a fault. */
.gate-note.calm { color: var(--fg-dim); }

.thr-wrap { display: flex; gap: 8px; align-items: flex-end; }
.thr-wrap .thr { flex: 1; min-width: 0; }
.thr-lock { flex: none; }
.field.thr.is-locked span { color: var(--fg-dim); }

.takes { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 8px; }
.take { display: flex; align-items: center; gap: 10px; padding: 5px 0; }
.take-thumb {
  width: 84px; height: 26px; flex: none; border-radius: 4px;
  background: var(--bg); image-rendering: pixelated;
}
.take-meta { font-size: 12px; color: var(--fg-dim); font-variant-numeric: tabular-nums; }
.take-verdict { font-size: 12px; color: var(--fg-dim); flex: 1; font-variant-numeric: tabular-nums; }
.take-verdict.good { color: var(--good); }
.take-verdict.bad { color: var(--danger); }

.score-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.score-bar {
  position: relative; flex: 1; height: 10px; border-radius: 5px;
  background: var(--bg); border: 1px solid var(--line); overflow: hidden;
}
.score-fill { height: 100%; width: 0%; background: #3b82f6; transition: width .08s linear; }
.score-fill.over { background: var(--good); }
/* Light neutral, not the accent: the marker sits on the dark track, on the
   blue under-threshold fill AND on the green over-threshold fill, and an accent
   marker vanished against the green - exactly when it matters most. */
.score-mark {
  position: absolute; top: -3px; bottom: -3px; width: 2px;
  background: var(--fg); box-shadow: 0 0 0 1px rgba(15, 23, 42, .7);
}
.score-num { font-size: 12px; color: var(--fg-dim); font-variant-numeric: tabular-nums; width: 70px; text-align: right; }

.card.action { border-color: var(--edge); }
.spaced { margin-top: 10px; }
.field.thr { margin: 8px 0 0; }
.session-stats { display: flex; gap: 10px 14px; align-items: baseline; margin-top: 10px; flex-wrap: wrap; }
.push { margin-left: auto; }
.sub {
  margin: 0 0 16px 29px; padding-left: 12px;
  border-left: 2px solid var(--line);
}
.sub > .field:first-child { margin-top: 6px; }

.linkish {
  background: none; border: 0; padding: 0; min-height: 0;
  color: var(--accent); font: inherit; font-size: 13px; text-decoration: underline;
}
.stat { font-size: 15px; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- log ---------- */

.table-wrap { overflow-x: auto; margin-top: 10px; max-height: 55vh; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--bg-card); color: var(--fg-dim); font-weight: 500; }
td.num { font-variant-numeric: tabular-nums; color: var(--fg-dim); }

.diag {
  background: var(--bg-sunk); border: 1px solid var(--line); border-radius: 9px;
  padding: 10px; margin: 10px 0; overflow-x: auto; white-space: pre;
  font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--fg-dim);
}

.logtext {
  width: 100%; height: 190px; resize: vertical;
  background: var(--bg-sunk); color: var(--fg); border: 1px solid var(--line);
  border-radius: 9px; padding: 10px;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---------- overlays ---------- */

/* The overlay sets display:flex, which would beat the `hidden` attribute's
   default display:none - so it needs an explicit rule to stay hidden. */
[hidden] { display: none !important; }

.countdown {
  position: fixed; inset: 0; z-index: 90;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; text-align: center; padding: 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
  background: #facc15; color: #1c1300;
  transition: background-color .2s linear, color .2s linear;
}
.countdown.mark { animation: cdmark .45s ease-out; }
@keyframes cdmark {
  0%   { filter: brightness(2.6); }
  60%  { filter: brightness(1.3); }
  100% { filter: brightness(1); }
}
.cd-stage { font-size: 15px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; opacity: .75; }
.cd-num {
  font-size: min(34vw, 42vh); line-height: .95; font-weight: 800;
  font-variant-numeric: tabular-nums; letter-spacing: -.03em;
}
.cd-label { font-size: 16px; font-weight: 600; opacity: .8; }
/* Fixed to the overlay's corner rather than sitting in the flow: the digits are
   sized off the viewport and would otherwise push it around. */
.cd-close {
  position: absolute; top: 0; right: 0;
  margin: max(10px, env(safe-area-inset-top)) 10px 0 0;
  width: 48px; height: 48px; min-height: 48px; padding: 0;
  background: transparent; border: 2px solid currentColor; color: inherit;
  border-radius: 10px; font-size: 26px; font-weight: 700; line-height: 1;
}
.cd-controls { width: min(420px, 100%); margin-top: 18px; display: grid; gap: 10px; }
/* Equal columns, so neither reads as the safer one to press. */
.cd-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cd-btn {
  background: transparent; border: 2px solid currentColor; color: inherit;
  font-weight: 700; min-height: 48px; padding: 0 16px; border-radius: 10px;
}
.cd-btn:disabled { opacity: .4; }
/* Reset throws away where the ladder had got to, so it is set apart from the
   two that only step it, and is quieter than both. */
.cd-reset { font-weight: 600; border-width: 1px; opacity: .85; }

#flash {
  position: fixed; inset: 0; z-index: 100; pointer-events: none;
  background: #fff; opacity: 0;
}
#flash.on { animation: flash .42s ease-out; }
@keyframes flash {
  0%   { opacity: .92; }
  55%  { opacity: .35; }
  100% { opacity: 0; }
}

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  z-index: 110; background: var(--raised); border: 1px solid var(--line);
  color: var(--fg); padding: 10px 16px; border-radius: 22px;
  font-size: 14px; box-shadow: 0 6px 22px rgba(0,0,0,.45);
  max-width: calc(100% - 32px); text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  #flash.on { animation-duration: .2s; }
  * { transition: none !important; }
}
