/* "Studio Paper": warm paper, ink outlines with offset shadows, cobalt + sun-yellow accents. */
:root {
  color-scheme: light;
  --bg: #f3efe6;
  --surface: #fffdf8;
  --ink: #151515;          /* outlines and offset shadows */
  --text: #151515;
  --text-2: #4a4843;
  --text-3: #6b675f;
  --rule: #d9d4c7;         /* table row dividers */
  --grid: #e6e1d5;         /* chart gridlines */
  --cobalt: #2446ff;
  --sun: #ffd23f;
  --error: #c62828;
  --pitch-lo: #0b1766;     /* low notes dark, high notes light */
  --pitch-mid: #2446ff;
  --pitch-hi: #b7c3ff;
  --key-white: #fffdf8;
  --key-black: #151515;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #141413;
    --surface: #1f1e1b;
    --ink: #f3efe6;
    --text: #f3efe6;
    --text-2: #c9c4b6;
    --text-3: #a29d90;
    --rule: #3a3833;
    --grid: #2e2c28;
    --cobalt: #4d6bff;
    --error: #ff7a70;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141413; --surface: #1f1e1b; --ink: #f3efe6; --text: #f3efe6;
  --text-2: #c9c4b6; --text-3: #a29d90; --rule: #3a3833; --grid: #2e2c28;
  --cobalt: #4d6bff; --error: #ff7a70;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
main {
  max-width: 720px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
}
h1, h2, .timer { font-family: "Bricolage Grotesque", "Instrument Sans", system-ui, sans-serif; }
h1 { margin: 0; font-size: 2.75rem; font-weight: 800; line-height: .95; letter-spacing: -.03em; }
h2 { margin: 0; font-size: 1.6rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.hint { margin: 10px 0 0; color: var(--text-2); font-size: .85rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
:focus-visible { outline: 3px solid var(--cobalt); outline-offset: 3px; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 16px 0 22px; }
.logo-keys { width: 70px; height: 34px; flex-shrink: 0; }
.lk-white { fill: var(--key-white); }
.lk-accent { fill: var(--sun); }
.lk-line { stroke: var(--key-black); stroke-width: 2; }
.lk-black { fill: var(--key-black); }
.lk-frame { fill: none; stroke: var(--ink); stroke-width: 2; }

.card {
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: 18px;
  padding: 20px 16px 16px;
  margin-bottom: 24px;
  box-shadow: 5px 5px 0 var(--ink);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* Chunky buttons: ink outline + offset shadow that "presses" on tap. */
.rec-btn, .pill-btn, td button {
  border: 2px solid var(--ink);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .08s ease, box-shadow .08s ease;
}
.rec-btn:active, .pill-btn:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }

/* Recorder */
.recorder { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 14px 20px; padding: 20px; }
.rec-info { min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.recorder .save-toggle { grid-column: 1 / -1; }
.rec-btn {
  width: 96px; height: 96px; margin: 0 4px 4px 0; padding: 0; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--cobalt); color: #fff;
  box-shadow: 4px 4px 0 var(--ink);
}
.rec-btn:disabled { opacity: .5; cursor: default; }
.rec-btn .icon { width: 36px; height: 36px; fill: currentColor; }
.rec-btn .icon-stop { display: none; width: 30px; height: 30px; }
.rec-btn.recording { background: var(--sun); color: #151515; }
.rec-btn.recording .icon-mic { display: none; }
.rec-btn.recording .icon-stop { display: block; }
.rec-badge { display: flex; align-items: center; gap: 8px; font-size: .75rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; }
.rec-badge[hidden] { display: none; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--cobalt); animation: blink 1s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }
@media (prefers-reduced-motion: reduce) { .rec-dot { animation: none; } }
.timer { font-size: 2.4rem; font-weight: 800; line-height: 1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.meter { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 3px; }
.meter span { height: 12px; border: 1.5px solid var(--ink); border-radius: 3px; background: var(--surface); }
.meter span.on { background: var(--cobalt); }
.status { color: var(--text); font-size: .9rem; line-height: 1.4; min-height: 1.4em; }
.status.error { color: var(--error); font-weight: 600; }
.save-toggle { display: flex; align-items: center; gap: 10px; color: var(--text-2); font-size: .85rem; cursor: pointer; }
.save-toggle input { width: 18px; height: 18px; accent-color: var(--cobalt); margin: 0; }
.save-status { margin: -8px 0 16px; color: var(--text-3); font-size: .8rem; min-height: 1.2em; overflow-wrap: anywhere; }

.pill-btn {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px;
  border-radius: 999px; background: var(--sun); color: #151515;
  font: 600 .9rem/1 inherit; box-shadow: 3px 3px 0 var(--ink);
}
.pill-btn svg { width: 12px; height: 12px; fill: currentColor; }

/* Notes chart */
.blocks-wrap { margin-top: 16px; }
svg { display: block; font-family: inherit; }
svg text { fill: var(--text-2); font-size: 11px; font-weight: 500; }
svg .note-name { fill: var(--text); font-size: 13px; font-weight: 600; }
svg .axis-label { fill: var(--text-2); font-size: 12px; font-weight: 600; }
svg .grid { stroke: var(--grid); stroke-width: 1; }
svg .baseline { stroke: var(--ink); stroke-width: 2; }
svg .block { stroke: var(--ink); stroke-width: 1.5; }
svg .mark:hover .block { stroke-width: 2.5; }
svg .mark.active .block, svg .mark:focus-visible .block { stroke-width: 3; }
svg .hit { fill: transparent; cursor: pointer; }
svg .mark:focus { outline: none; }
svg .kb-white { fill: var(--key-white); stroke: var(--key-black); stroke-width: 1; }
svg .kb-black { fill: var(--key-black); }
svg .kb-frame { fill: none; stroke: var(--ink); stroke-width: 1.5; }

/* Table */
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 8px -4px 0; padding: 0 4px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: .9rem; }
th, td { padding: 9px 6px; text-align: left; white-space: nowrap; }
th { font-size: .78rem; font-weight: 600; color: var(--text-2); border-bottom: 2px solid var(--ink); }
td { border-bottom: 1px solid var(--rule); }
td:nth-child(1) { color: var(--text-3); }
td:nth-child(2) { font-weight: 600; }
td.num, th.num { text-align: right; }
tr.active td { background: color-mix(in srgb, var(--sun) 35%, transparent); }
td button {
  width: 36px; height: 36px; padding: 0; border-width: 1.5px; border-radius: 50%;
  display: inline-grid; place-items: center; background: var(--surface); color: var(--text);
}
td button svg { width: 10px; height: 10px; fill: currentColor; }
td button:active { transform: scale(.92); }

.tooltip {
  position: fixed; z-index: 10; pointer-events: none;
  background: var(--surface); color: var(--text);
  border: 2px solid var(--ink); border-radius: 10px; box-shadow: 3px 3px 0 var(--ink);
  padding: 8px 10px; font-size: .85rem; line-height: 1.35; max-width: 220px;
}
.tooltip strong { font-family: "Bricolage Grotesque", sans-serif; font-size: 1.1rem; }
.tooltip .muted { color: var(--text-2); }

footer { color: var(--text-3); font-size: .8rem; text-align: center; margin-top: 4px; }

@media (max-width: 600px) {
  h1 { font-size: 2.6rem; }
  .card { padding: 18px 14px 14px; }
  .recorder { padding: 18px 16px; gap: 14px 16px; }
  .timer { font-size: 2.2rem; }
}
