:root {
  --bg: #f4f2ee;
  --panel: #ffffff;
  --panel-2: #f8f7f4;
  --text: #1f1d1a;
  --muted: #6d6860;
  --border: #e2ded6;
  --accent: #4f46e5;
  --accent-soft: #e8e7fd;
  --good: #15803d;
  --good-soft: #dcf3e3;
  --bad: #c2410c;
  --bad-soft: #fde6da;
  --warn: #b45309;
  --target: rgba(79, 70, 229, 0.16);
  --grid: #ece9e3;
  --pale: #cfcbc3; /* earlier attempts on the pitch graph */
  --black-key: rgba(0, 0, 0, 0.05);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15151a;
    --panel: #1e1e25;
    --panel-2: #25252d;
    --text: #ecebf2;
    --muted: #9b99a8;
    --border: #33333d;
    --accent: #8b85ff;
    --accent-soft: #2d2b4d;
    --good: #4ade80;
    --good-soft: #173323;
    --bad: #fb923c;
    --bad-soft: #3a2518;
    --warn: #fbbf24;
    --target: rgba(139, 133, 255, 0.2);
    --grid: #2a2a33;
    --pale: #4b4b57;
    --black-key: rgba(255, 255, 255, 0.05);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
[hidden] { display: none !important; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.logo { font-size: 24px; color: var(--accent); }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab {
  border: none; background: none; padding: 8px 14px; border-radius: 8px;
  color: var(--muted); font-weight: 600; cursor: pointer;
}
.tab:hover:not(:disabled) { background: var(--panel-2); color: var(--text); }
.tab.active { background: var(--accent-soft); color: var(--accent); }
.tab:disabled { opacity: 0.45; cursor: default; }
.settings-btn, .sheet-head, .sheet-backdrop { display: none; } /* phones only (see the end of this file) */

/* Layout */
.layout { display: grid; grid-template-columns: 300px 1fr; gap: 20px; padding: 20px; max-width: 1280px; margin: 0 auto; }
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; padding: 12px 16px; } }

.settings {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 4px 16px 16px; align-self: start;
}
.settings section { padding: 12px 0; border-bottom: 1px solid var(--border); }
.settings section:last-child { border-bottom: none; }
.settings h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
/* data-only="identify single sing" lists the themes an element appears in. */
body[data-mode="identify"] [data-only]:not([data-only~="identify"]),
body[data-mode="single"] [data-only]:not([data-only~="single"]),
body[data-mode="sing"] [data-only]:not([data-only~="sing"]),
body[data-mode="range"] [data-only]:not([data-only~="range"]),
body[data-mode="pattern"] [data-only]:not([data-only~="pattern"]),
body[data-mode="chord"] [data-only]:not([data-only~="chord"]) { display: none; }
.settings .seg { margin: 4px 0 8px; }

select, button { font: inherit; color: inherit; }
select {
  width: 100%; padding: 7px 8px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel-2);
}
button {
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel-2); cursor: pointer; font-weight: 500;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
button.primary:hover:not(:disabled) { filter: brightness(1.08); }
button.small { padding: 3px 10px; font-size: 13px; }
button.link { background: none; border: none; padding: 2px 0; color: var(--accent); font-size: 13px; }
kbd { font-size: 11px; padding: 0 4px; border: 1px solid var(--border); border-radius: 4px; color: var(--muted); background: none; }
.primary kbd { color: #fff; border-color: rgba(255, 255, 255, 0.5); }

.hint { font-size: 12px; color: var(--muted); margin-top: 6px; min-height: 1em; }
.hint.warn { color: var(--warn); }
.field-label { font-size: 13px; color: var(--muted); }
.row-btns { display: flex; gap: 6px; margin-bottom: 8px; }

.checklist { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.chip { display: flex; align-items: center; gap: 6px; font-size: 13px; padding: 4px 6px; border-radius: 6px; cursor: pointer; }
.chip:hover { background: var(--panel-2); }
.chip b { display: inline-block; min-width: 22px; color: var(--accent); }

.seg { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg label { flex: 1; text-align: center; cursor: pointer; }
.seg input { display: none; }
.seg span { display: block; padding: 6px 4px; font-size: 13px; }
.seg input:checked + span { background: var(--accent); color: #fff; }
.seg.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--border); }
.seg.grid2 span { background: var(--panel); }
.seg.grid2 input:checked + span { background: var(--accent); }
body[data-mode="sing"] .seg.grid2 label:nth-child(3) { grid-column: span 2; } /* Harmonic hidden there */

.sub { margin-top: 10px; }
.sub .field-label { margin-bottom: 3px; }
.sub select + .check, .sub select + .seg, .sub .seg + .field-label, .sub .seg + .slider { margin-top: 8px; }
.vowel-row { display: grid; grid-template-columns: 90px 1fr; align-items: center; gap: 8px; margin-bottom: 6px; }
.range-row { display: flex; align-items: center; gap: 6px; margin: 4px 0; }
.range-row span { color: var(--muted); font-size: 13px; }

.slider { display: block; font-size: 14px; margin: 6px 0; }
.slider output { float: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.slider input { width: 100%; accent-color: var(--accent); }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; margin: 6px 0; cursor: pointer; }
.check input { accent-color: var(--accent); }

/* Main cards */
main { min-width: 0; }
.view { display: grid; gap: 20px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.prompt { font-size: 17px; margin-bottom: 14px; }
.controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.controls .auto-next { margin: 0 0 0 auto; color: var(--muted); }

.answers { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; margin-top: 18px; }
.answers button { padding: 12px 8px; text-align: center; position: relative; }
.answers button kbd.key { position: absolute; top: 5px; right: 6px; }
.answers button b { display: block; font-size: 18px; color: var(--accent); }
.answers button small { color: var(--muted); }
.answers button.correct { background: var(--good-soft); border-color: var(--good); }
.answers button.wrong { background: var(--bad-soft); border-color: var(--bad); }

.feedback { margin-top: 16px; min-height: 1.5em; }
.feedback .verdict { font-weight: 700; font-size: 17px; }
.feedback .verdict.ok { color: var(--good); }
.feedback .verdict.no { color: var(--bad); }
.feedback .detail { color: var(--muted); margin: 4px 0 8px; }

.stats-head { display: flex; justify-content: space-between; align-items: center; }
.stats-head h3 { margin: 0; font-size: 15px; }
.summary { display: flex; gap: 24px; margin: 12px 0; flex-wrap: wrap; }
.summary div { font-size: 13px; color: var(--muted); }
.summary b { display: block; font-size: 22px; color: var(--text); }
.bars { display: grid; grid-template-columns: 110px 1fr 70px; gap: 6px 10px; font-size: 13px; align-items: center; }
.bar { height: 8px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.bar > div { height: 100%; background: var(--accent); }
.bars .num { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); font-size: 13px; margin-top: 8px; }

/* Singing */
.interval-label .sound { font-size: 15px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.interval-label { font-size: 26px; font-weight: 700; color: var(--accent); margin-bottom: 12px; min-height: 1.4em; }
.phase-row { display: flex; align-items: center; gap: 16px; margin: 16px 0 8px; }
.phase { flex: 1; font-weight: 600; font-size: 16px; }
.phase.live { color: var(--bad); }
.meter { width: 120px; height: 8px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 4px; overflow: hidden; }
.meter > div { height: 100%; width: 0; background: var(--good); transition: width 60ms linear; }
.spectrum-box { margin-top: 12px; }
.spectrum-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 6px 16px; flex-wrap: wrap; margin-bottom: 6px; }
.spectrum-head > .field-label { flex: 1 1 260px; }
.noise-ctl { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.noise-ctl .check { margin: 0; font-size: 13px; }
.noise-ctl .check:has(input:disabled) { opacity: 0.5; cursor: default; }
.noise-status { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.noise-status.warn { color: var(--warn); }
canvas.spectrum-canvas { width: 100%; height: 240px; display: block; background: var(--panel-2); border-radius: 8px; }
canvas.pitch-canvas { width: 100%; height: 260px; display: block; background: var(--panel-2); border-radius: 8px; }
.results { margin-top: 14px; }
.results .notes { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin: 10px 0; }
.results .note { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.results .note.ok { border-color: var(--good); background: var(--good-soft); }
.results .note.no { border-color: var(--bad); background: var(--bad-soft); }
.results .note .score { font-size: 22px; font-weight: 700; }
.results .note .line { font-size: 13px; color: var(--muted); }
.compare { margin-top: 12px; }

.credits { max-width: 1280px; margin: 0 auto; padding: 4px 20px 24px; font-size: 12px; color: var(--muted); }
.credits a { color: inherit; }

/* Single Note: vertical range slider with a checkbox per note */
.note-range { position: relative; margin-top: 8px; user-select: none; }
.nr-track { position: absolute; left: 0; top: 0; bottom: 0; width: 28px; cursor: pointer; touch-action: none; }
.nr-rail { position: absolute; left: 12px; top: 0; bottom: 0; width: 4px; border-radius: 2px; background: var(--border); }
.nr-fill { position: absolute; left: 12px; width: 4px; border-radius: 2px; background: var(--accent); }
.nr-thumb {
  position: absolute; left: 5px; width: 18px; height: 18px; margin-top: -9px; border-radius: 50%;
  background: var(--panel); border: 3px solid var(--accent); cursor: grab; box-sizing: border-box;
}
.nr-thumb:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.nr-list { position: absolute; left: 36px; right: 0; top: 0; bottom: 0; }
.nr-row {
  position: absolute; left: 0; right: 0; height: var(--nr-row, 16px); display: flex; align-items: center; gap: 6px;
  font-size: 11px; line-height: 16px; padding-left: 4px; border-radius: 3px; cursor: pointer;
}
.nr-row.black { background: var(--black-key); }
.nr-row input { margin: 0; width: 12px; height: 12px; accent-color: var(--accent); }
.nr-row.out { cursor: default; color: var(--muted); opacity: 0.35; }
.nr-row.out input { visibility: hidden; }
.nr-hear {
  margin-left: auto; padding: 0 6px; height: 14px; line-height: 12px; font-size: 8px;
  border-radius: 4px; color: var(--accent); background: var(--panel); flex: none;
}
.nr-row.out .nr-hear { display: none; }

/* Single Note: pitch-following counter and hold progress */
.follow-box { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; margin: 4px 0 10px; }
.counter { display: flex; align-items: baseline; gap: 8px; }
.counter b { font-size: 30px; color: var(--good); font-variant-numeric: tabular-nums; }
.counter span { color: var(--muted); font-size: 13px; }
.hold { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 200px; }
.hold-bar { flex: 1; height: 10px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 5px; overflow: hidden; }
.hold-bar > div { height: 100%; width: 0; background: var(--good); transition: width 60ms linear; }
.hold-setting { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.hold-setting input { width: 110px; accent-color: var(--accent); }
.hold-setting output { min-width: 34px; font-variant-numeric: tabular-nums; }
.hold span { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 72px; }
.attempts { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip-score { font-size: 12px; padding: 1px 8px; border-radius: 10px; border: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.chip-score.ok { border-color: var(--good); color: var(--good); }
.chip-score.no { border-color: var(--bad); color: var(--bad); }
.chip-score.latest { font-weight: 700; }

/* Vocal Range */
.siren-on { margin-top: 10px; }
.held-box {
  font-size: 13px; padding: 5px 12px; border-radius: 16px; border: 1px solid var(--border);
  color: var(--muted); background: var(--panel-2); font-variant-numeric: tabular-nums;
}
.save-take { margin-left: auto; }
.held-box.ok { color: var(--good); border-color: var(--good); background: var(--good-soft); font-weight: 600; }
.range-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; margin: 6px 0 12px; }
.range-facts > div { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; }
.range-facts .field-label { display: block; }
.range-facts b { font-size: 18px; }
.switches { margin: 4px 0 8px; padding-left: 20px; }
.switches li { margin: 2px 0; }
.switches li.clear b { color: var(--bad); }
.switches li.possible b { color: var(--warn); }
canvas.summary-canvas { width: 100%; height: 240px; display: block; margin-top: 10px; }
.voice-type { margin-top: 8px; font-size: 14px; }

/* Interval ID: song references */
.songs-card summary { cursor: pointer; list-style-position: outside; }
.songs-card summary h3 { display: inline; margin: 0; font-size: 15px; }
.song-grid { display: grid; gap: 6px; margin-top: 10px; }
.song-row { display: grid; grid-template-columns: 36px 1fr 1fr; gap: 8px; align-items: center; }
.song-row b { color: var(--accent); }
.song-cell { display: flex; align-items: center; gap: 6px; min-width: 0; }
.song-cell button { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
.song-yt, .song-link { font-size: 11px; color: var(--muted); flex: none; }
button.link.song-link { color: var(--muted); padding: 0; min-height: 0; }
.video-btn { flex: none; }
/* Docked YouTube player */
.yt-dock {
  position: fixed; right: 16px; bottom: 16px; z-index: 15; width: 380px; max-width: calc(100vw - 32px);
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25); overflow: hidden;
}
.yt-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 10px; font-size: 13px; font-weight: 600; }
.yt-head button { font-size: 16px; padding: 0 4px; min-height: 0; }
.yt-frame { aspect-ratio: 16 / 9; background: #000; }
.yt-frame iframe { width: 100%; height: 100%; border: 0; display: block; }
@media (max-width: 560px) {
  .yt-dock { right: 0; left: 0; bottom: 0; width: auto; max-width: none; border-radius: 12px 12px 0 0;
    padding-bottom: env(safe-area-inset-bottom); }
}
.song-none { font-size: 12px; color: var(--muted); }
.song-now { min-height: 1.2em; }
.song-btns { margin-top: 6px; }
@media (max-width: 560px) {
  .song-row { grid-template-columns: 30px 1fr; }
  .song-row .song-cell + .song-cell, .song-row .song-cell + .song-none, .song-row .song-none + .song-cell { grid-column: 2; }
}

/* Patterns */
.pattern-notes { font-size: 14px; font-weight: 500; color: var(--muted); margin-top: 2px; word-spacing: 2px; }
.pattern-chips .chip-score { font-size: 13px; padding: 2px 8px; }
.pattern-chips .chip-score b { font-weight: 600; margin-right: 2px; }
#ptResults > .line { font-size: 13px; color: var(--muted); margin-top: 6px; }
.bars.wide { grid-template-columns: minmax(110px, 240px) 1fr 70px; }

/* Interval ID spectrum */
.bright-line { margin-top: 6px; font-size: 14px; }
.bright-line .clash { display: block; color: var(--warn); margin-top: 2px; }
.bright-line > div + div { margin-top: 6px; }
/* Roughness of every interval for the sound just played (notes together) */
.rough-curve { display: flex; gap: 3px; align-items: stretch; height: 56px; margin-top: 4px; max-width: 420px; }
.rough-curve span { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; min-width: 0; }
.rough-curve i { display: block; width: 100%; background: var(--pale); border-radius: 2px 2px 0 0; }
.rough-curve span.now i { background: var(--warn); }
.rough-curve small { font-size: 10px; color: var(--muted); line-height: 14px; }
.rough-curve span.now small { color: var(--text); font-weight: 600; }

/* ---- Phones and narrow windows ------------------------------------------------------
   The exercise comes first; settings move into a bottom sheet opened from the top bar;
   the theme tabs become one strip that scrolls sideways. */
@media (max-width: 860px) {
  .topbar {
    gap: 4px 12px; padding: 8px 12px 0;
    padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right));
    padding-top: max(8px, env(safe-area-inset-top));
  }
  .brand { font-size: 16px; }
  .logo { font-size: 20px; }
  .settings-btn { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; }
  .tabs {
    flex: 1 0 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; overscroll-behavior-x: contain;
    margin: 0 -12px; padding: 0 12px 6px; scroll-padding: 0 12px;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: none; white-space: nowrap; }

  .layout {
    padding: 12px; gap: 12px;
    padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right));
  }
  .view { gap: 12px; }
  .card { padding: 14px; }
  .credits { padding: 4px 16px calc(20px + env(safe-area-inset-bottom)); }

  /* Settings: bottom sheet */
  .settings {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    max-height: 85vh; max-height: 85dvh; overflow-y: auto; overscroll-behavior: contain;
    border-radius: 16px 16px 0 0; border-bottom: none;
    padding: 0 16px calc(16px + env(safe-area-inset-bottom));
    transform: translateY(100%); visibility: hidden;
    transition: transform 0.25s ease, visibility 0s 0.25s;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.25);
  }
  body.sheet-open .settings { transform: none; visibility: visible; transition: transform 0.25s ease; }
  body.sheet-open { overflow: hidden; } /* the page behind doesn't scroll */
  .sheet-head {
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 1; background: var(--panel);
    margin: 0 -16px; padding: 18px 16px 10px; border-bottom: 1px solid var(--border);
  }
  .sheet-head::before { /* grab handle */
    content: ""; position: absolute; top: 7px; left: 50%; width: 36px; height: 4px; margin-left: -18px;
    border-radius: 2px; background: var(--border);
  }
  .sheet-head h2 { margin: 0; font-size: 17px; }
  .sheet-backdrop {
    display: block; position: fixed; inset: 0; z-index: 19; background: rgba(0, 0, 0, 0.45);
    opacity: 0; pointer-events: none; transition: opacity 0.25s ease;
  }
  body.sheet-open .sheet-backdrop { opacity: 1; pointer-events: auto; }

  .controls .auto-next { margin-left: 0; flex-basis: 100%; }
  .summary { gap: 16px; }
  .bars { grid-template-columns: 92px 1fr 56px; }
  .save-take { margin-left: 0; }
  canvas.spectrum-canvas, canvas.summary-canvas { height: 210px; }
  canvas.pitch-canvas { height: 230px; }
}
@media (prefers-reduced-motion: reduce) {
  .settings, .sheet-backdrop { transition: none !important; }
}

/* Narrow phones: all the answer buttons on one screen (short names only) */
@media (max-width: 560px) {
  .answers { grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 14px; }
  .answers button { padding: 6px 2px; min-height: 52px; }
  .answers button small { display: none; }
  .interval-label { font-size: 22px; }
}

/* Touch screens: finger-sized targets, no keyboard hints, no zoom-on-focus (16px inputs) */
@media (pointer: coarse) {
  button, .tab { min-height: 44px; }
  button.small, button.link { min-height: 38px; padding: 6px 12px; }
  button.link { padding-left: 0; }
  select { min-height: 44px; font-size: 16px; }
  kbd { display: none; }
  .seg span { padding: 11px 4px; font-size: 14px; }
  .chip { min-height: 40px; font-size: 14px; }
  .check { min-height: 36px; margin: 4px 0; }
  .noise-ctl .check { font-size: 14px; }
  input[type="checkbox"] { width: 20px; height: 20px; flex: none; }
  input[type="range"] { height: 32px; }
  .hold-setting input { width: 140px; }
  .vowel-row { grid-template-columns: 1fr; gap: 2px; }
  .nr-track { width: 40px; }
  .nr-rail, .nr-fill { left: 18px; }
  .nr-thumb { left: 6px; width: 28px; height: 28px; margin-top: -14px; }
  .nr-list { left: 48px; }
  .nr-row { font-size: 13px; }
  .nr-row input { width: 20px; height: 20px; }
  .nr-hear { min-height: 0; height: 24px; line-height: 20px; font-size: 11px; padding: 0 12px; }
}
