:root {
  --bg: #14161c;
  --panel: #1f232d;
  --text: #f2f4f8;
  --muted: #8d95a6;
  --green: #3ecf8e;
  --amber: #f5b942;
  --coral: #ff6b6b;
  --accent: #5b8cff;
  --violet: #9b7bff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.app {
  min-height: calc(100vh - 92px);
  min-height: calc(100dvh - 92px);
  max-width: 560px;
  margin: 0 auto;
  padding: 14px 20px max(20px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.readout { text-align: center; padding-top: 8px; }
.note { font-size: clamp(88px, 28vw, 150px); font-weight: 700; line-height: 1; }
.frequency { font-size: 24px; color: var(--muted); margin-top: 6px; font-variant-numeric: tabular-nums; }

/* Meter */
.meter-track {
  position: relative;
  height: 64px;
  background: var(--panel);
  border-radius: 12px;
  overflow: hidden;
}
.zone { position: absolute; top: 0; bottom: 0; }
.zone-good { background: rgba(245, 185, 66, 0.28); }
.zone-bullseye { background: rgba(62, 207, 142, 0.5); }
.center-mark {
  position: absolute; left: 50%; top: 0; bottom: 0; width: 2px;
  background: rgba(255, 255, 255, 0.35); transform: translateX(-1px);
}
.needle {
  position: absolute; top: 6px; bottom: 6px; width: 8px; border-radius: 4px;
  left: 50%; transform: translateX(-4px);
  background: var(--muted); opacity: 0.35;
  transition: left 90ms linear, opacity 150ms, background 150ms;
}
.needle.active { opacity: 1; }
.needle.bullseye { background: var(--green); }
.needle.good { background: var(--amber); }
.needle.off { background: var(--coral); }

.meter-labels { display: flex; justify-content: space-between; color: var(--muted); font-size: 14px; margin-top: 6px; }
.cents { text-align: center; font-size: 36px; font-weight: 600; font-variant-numeric: tabular-nums; }
.verdict { text-align: center; font-size: 28px; font-weight: 600; margin-top: 12px; min-height: 36px; }
.verdict.in-tune { color: var(--green); }
.verdict.out { color: var(--text); }

.teacher-toggle {
  align-self: center;
  background: transparent; color: var(--muted);
  border: 1px solid #3a4050; border-radius: 999px;
  padding: 8px 16px; font-size: 14px; cursor: pointer;
}
.teacher-toggle[aria-expanded="true"] { color: var(--text); border-color: var(--accent); }

/* Stable-note light */
.stable-row { display: flex; align-items: center; justify-content: center; gap: 12px; color: var(--muted); font-size: 18px; }
.light {
  width: 28px; height: 28px; border-radius: 50%;
  background: #2b303c; border: 2px solid #3a4050;
  transition: background 80ms, box-shadow 80ms;
}
.light.on { background: var(--green); border-color: var(--green); box-shadow: 0 0 16px 4px rgba(62, 207, 142, 0.6); }
.stable-row.on { color: var(--text); }

/* Start / Stop */
.big-button {
  margin-top: auto;
  min-height: 84px;
  border: 0; border-radius: 20px;
  background: var(--accent); color: #fff;
  font-size: 30px; font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.big-button:active { filter: brightness(0.9); }
.big-button.running { background: var(--coral); }
.big-button:disabled { opacity: 0.6; }

.status { text-align: center; color: var(--muted); font-size: 16px; min-height: 24px; margin: 0; }
.status.error { color: var(--coral); }


/* ---- Tune up screen ---- */
.tuneup { gap: 16px; }

.instruments { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.instrument-btn {
  min-height: 48px; border-radius: 12px; border: 2px solid #3a4050;
  background: var(--panel); color: var(--text); font-size: 16px; cursor: pointer;
}
.instrument-btn[aria-checked="true"] { border-color: var(--accent); background: #26304a; font-weight: 700; }

.peg-note { margin: 0; padding: 10px 12px; border-radius: 10px; background: #2a2630; color: #d9c9a8; font-size: 14px; line-height: 1.4; }
.how-to { margin: 0 0 10px; color: var(--muted); font-size: 15px; line-height: 1.5; }

.strings { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }

.tuneup .readout { padding-top: 0; }
.tuneup .note { font-size: clamp(56px, 18vw, 96px); }
.tuneup .frequency { font-size: 20px; }
.zone-lock { background: rgba(62, 207, 142, 0.55); }
.target-info { text-align: center; color: var(--muted); font-size: 16px; }

.progress { height: 10px; border-radius: 5px; background: var(--panel); overflow: hidden; margin-top: 12px; }
.progress-fill { height: 100%; width: 0; background: var(--green); transition: width 60ms linear; }

.big-button:disabled { opacity: 0.4; }

.secondary-button { min-height: 52px; padding: 0 24px; border-radius: 14px; border: 2px solid var(--green); background: transparent; color: var(--text); font-size: 18px; cursor: pointer; }
.finish { text-align: center; padding: 18px; border-radius: 16px; background: #1d3a2e; border: 2px solid var(--green); display: flex; flex-direction: column; gap: 10px; align-items: center; }
.finish[hidden] { display: none; }
.finish-title { font-size: 28px; font-weight: 700; }
.finish-detail { color: #bfe9d2; font-size: 16px; }

@keyframes flash-green { 0% { box-shadow: 0 0 0 0 rgba(62,207,142,.9); } 100% { box-shadow: 0 0 0 28px rgba(62,207,142,0); } }
.meter-track.flash-bullseye { animation: flash-green 800ms ease-out; }

/* ---- Scored notes list ---- */
.tier-bullseye { color: var(--green); }
.tier-good { color: var(--amber); }
.tier-miss { color: var(--muted); }

/* ---- Session log (visible to everyone) ---- */
.session-log { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.session-log h2 { font-size: 18px; margin: 0; color: var(--muted); font-weight: 600; }
.log-totals { font-size: 16px; }
.log-scroll { max-height: 260px; overflow-y: auto; border: 1px solid #262b36; border-radius: 10px; }
.log-table { width: 100%; border-collapse: collapse; font-size: 16px; font-variant-numeric: tabular-nums; }
.log-table th { position: sticky; top: 0; background: var(--panel); text-align: left; padding: 8px 10px; color: var(--muted); font-weight: 600; }
.log-table td { padding: 7px 10px; border-top: 1px solid #262b36; }
.copy-log { align-self: flex-start; }
.copy-log:disabled { opacity: 0.4; }

/* ---- Screens (tuner / teacher setup / Streak Mode) ---- */
.view[hidden] { display: none; }
.muted { color: var(--muted); font-weight: 400; font-size: 15px; }
.setup-h { font-size: 20px; margin: 0 0 10px; }
.setup-hint { margin: 8px 0 0; color: var(--muted); font-size: 14px; line-height: 1.4; }

.key-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.key-btn, .note-btn {
  min-height: 52px; border-radius: 12px; border: 2px solid #3a4050;
  background: var(--panel); color: var(--text); font-size: 20px; font-weight: 600; cursor: pointer;
}
.key-btn[aria-checked="true"] { border-color: var(--accent); background: #26304a; }
.note-row { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.note-btn { font-size: 18px; min-height: 56px; opacity: 0.55; }
.note-btn[aria-pressed="true"] { opacity: 1; border-color: var(--green); background: #1d3a2e; }

.game-play { display: flex; flex-direction: column; gap: 18px; padding-top: 10px; }
.big-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; text-align: center; }
.stat-num { font-size: clamp(64px, 22vw, 110px); font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: 16px; margin-top: 4px; }
.streak-line { text-align: center; font-size: 24px; font-weight: 600; }

.over-best { font-size: 20px; color: var(--amber); font-weight: 600; }
.over-headline { font-size: 22px; font-weight: 600; margin: 0; }
.over-advice { font-size: 18px; color: var(--muted); margin: 0; }

.teacher-only { display: none; }
.teacher-on .teacher-only { display: block; }
.why-line { text-align: left; font-size: 15px; color: var(--muted); border-left: 3px solid var(--accent); padding-left: 10px; margin: 0; }
.round-history { text-align: left; font-size: 14px; color: var(--muted); padding-left: 22px; margin: 0; }

/* Anything marked hidden stays hidden, even if another rule sets its display. */
[hidden] { display: none !important; }


/* ---- Top bar: always visible ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  padding: max(10px, env(safe-area-inset-top)) 16px 8px;
  border-bottom: 1px solid #262b36;
  display: flex; flex-direction: column; gap: 8px;
  max-width: 560px; margin: 0 auto;
}
.mode-nav { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mode-tab {
  min-height: 52px; border-radius: 14px; border: 2px solid #3a4050;
  background: var(--panel); color: var(--muted);
  font-size: 17px; font-weight: 600; cursor: pointer;
}
.mode-tab.current { border-color: var(--accent); background: #26304a; color: var(--text); }
.topbar-row { display: flex; justify-content: flex-end; gap: 8px; }
.topbar .teacher-toggle { padding: 5px 12px; }

/* ---- Teacher tools: one switch for the live controls ---- */
.teacher-panel { gap: 14px; }
.teacher-on .teacher-panel.teacher-only { display: flex; flex-direction: column; }

/* ---- Free Play ---- */

/* ---- Streak Mode setup ---- */
.setup-button {
  min-height: 44px; padding: 0 18px; border-radius: 12px; border: 2px solid var(--accent);
  background: transparent; color: var(--text); font-size: 17px; font-weight: 600; cursor: pointer;
}
.setup-button:disabled { opacity: 0.4; cursor: default; }
.setup-panel { display: flex; flex-direction: column; gap: 18px; padding: 14px; border-radius: 14px; background: var(--panel); }

/* ---- Round-over screens ---- */
.big-stats.one { grid-template-columns: 1fr; }
.earlier-list { text-align: left; font-size: 14px; padding-left: 22px; margin: 0; display: flex; flex-direction: column; gap: 2px; max-height: 8.5em; overflow-y: auto; overscroll-behavior: contain; }
.log-summaries { text-align: left; font-size: 14px; color: var(--muted); padding-left: 22px; margin: 0; display: flex; flex-direction: column; gap: 3px; }

/* ---- Tune Up: one big button per string ---- */
html, body, button { touch-action: manipulation; }  /* a quick double tap must not zoom the page */
.strings { user-select: none; -webkit-user-select: none; }
.string-btn {
  min-height: 104px; border-radius: 18px; border: 3px solid #3a4050;
  background: var(--panel); color: var(--text); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  padding: 8px 6px; -webkit-tap-highlight-color: transparent;
}
.string-name { font-size: 30px; font-weight: 700; }
.string-sub { font-size: 14px; color: var(--muted); line-height: 1.25; text-align: center; }
/* What a tap will do is shown by the colour: blue = hear it, violet = listening */
.string-btn.state-tone { background: #25407d; border-color: var(--accent); }
.string-btn.state-tone .string-sub { color: #cfdcff; }
.string-btn.state-listening, .string-btn.state-settling { background: #3d2d78; border-color: var(--violet); }
.string-btn.state-listening .string-sub, .string-btn.state-settling .string-sub { color: #dcd2ff; }
/* The green badge stays once a string has locked in */
.string-btn.locked { border-color: var(--green); }
.string-badge { font-size: 15px; font-weight: 700; color: #0e2a1d; background: var(--green); border-radius: 999px; padding: 1px 12px; }
.string-badge:empty { display: none; }

/* ---- Streak Mode: end-of-round feedback ---- */
/* ONE soft red-orange pulse over the whole screen (single fade in and out, about half a second). */
.buzz-visual { position: fixed; inset: 0; pointer-events: none; z-index: 50; opacity: 0; }
.buzz-visual.pulse {
  background: radial-gradient(ellipse at center, rgba(255, 140, 90, 0.28), rgba(255, 90, 60, 0.5));
  animation: buzz-pulse 500ms ease-in-out 1 both;
}
@keyframes buzz-pulse { 0% { opacity: 0; } 40% { opacity: 1; } 100% { opacity: 0; } }
/* "Reduce motion": no pulse, a steady coloured border instead. */
.buzz-visual.border { opacity: 1; box-shadow: inset 0 0 0 10px #ff7a45; }
@media (prefers-reduced-motion: reduce) { .buzz-visual.pulse { animation: none; opacity: 0; } }

/* The wrong note, in large type */
.over-note { font-size: clamp(110px, 32vw, 180px); font-weight: 800; line-height: 1; text-align: center; color: #ffb08a; margin: 4px 0; }

/* ---- Note summary (visible to everyone) ---- */
.note-summary { display: flex; flex-direction: column; gap: 8px; }
.note-summary h2 { font-size: 18px; margin: 0; color: var(--muted); font-weight: 600; }
.ns-workon { margin: 0; font-size: 16px; line-height: 1.4; }
.ns-chart { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.ns-row { display: grid; grid-template-columns: 44px 1fr; column-gap: 10px; row-gap: 2px; align-items: center; }
.ns-name { grid-row: 1; font-size: 20px; font-weight: 700; }
.ns-bar { grid-row: 1; grid-column: 2; display: flex; height: 26px; border-radius: 6px; overflow: hidden; background: var(--panel); }
.ns-seg { display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700; color: #10131a; min-width: 20px; }
.ns-bullseye { background: var(--green); }
.ns-good { background: var(--amber); }
.ns-miss { background: var(--coral); }
.ns-counts { grid-row: 2; grid-column: 2; font-size: 14px; color: var(--text); font-variant-numeric: tabular-nums; }
.ns-tend { grid-row: 3; grid-column: 2; font-size: 14px; color: var(--muted); }

/* ---- Streak Mode checks ---- */
/* Greyed out and ignored */
.is-off { opacity: 0.35; pointer-events: none; }

/* ---- Streak Mode: allowed notes strip (Teacher tools, during a round) ---- */
.note-strip { display: none; }
.teacher-on .note-strip { display: block; }
.strip-label { font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.edited { color: var(--amber); font-weight: 700; }
.strip-row { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.strip-btn {
  min-height: 40px; border-radius: 9px; border: 2px solid #3a4050; background: var(--panel);
  color: var(--muted); font-size: 16px; font-weight: 700; cursor: pointer; opacity: 0.6;
}
.strip-btn[aria-pressed="true"] { border-color: var(--green); background: #1d3a2e; color: var(--text); opacity: 1; }
.log-changes-box h2 { font-size: 16px; margin: 0 0 4px; color: var(--muted); font-weight: 600; }
.log-changes { margin: 0; padding-left: 22px; font-size: 14px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
.edited-label { color: var(--amber); font-size: 14px; font-weight: 700; }

/* ---- Streak Mode: the control row (Play in key, Play in tune, Setup) ---- */
.control-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: stretch; }
.control-row .setup-button { flex: 1 1 90px; min-height: 56px; }
/* Visible but greyed out while a round is being played */
/* The "why you cannot start" message under the Start button */
.status.notice { color: var(--amber); font-weight: 600; }


/* ---- Streak Mode top row: Play in key (on/off toggle) and Play in tune (three-position switch button) ---- */
.control-row .toggle-btn { flex: 1 1 150px; }
.control-row .tune-btn { flex: 2 1 200px; }

/* Play in key: green when on, greyed out when off */
.toggle-btn {
  min-height: 72px; border-radius: 12px; border: 2px solid #3a4050; background: var(--panel);
  color: var(--muted); font-size: 16px; font-weight: 600; cursor: pointer;
  padding: 6px 10px; line-height: 1.25; white-space: normal; overflow-wrap: anywhere;
}
.toggle-btn[aria-pressed="true"] { border-color: var(--green); background: #1d3a2e; color: var(--text); }
.toggle-btn[aria-pressed="true"]::after { content: "  ON"; font-size: 13px; color: var(--green); }
.toggle-btn[aria-pressed="false"]::after { content: "  OFF"; font-size: 13px; }

/* Play in tune: one button with a small picture of a three-position switch inside */
.tune-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 72px; border-radius: 12px; border: 2px solid #3a4050; background: var(--panel);
  color: var(--muted); cursor: pointer; padding: 6px 10px;
}
.tune-title { font-size: 16px; font-weight: 600; }
.tune-switch { display: block; width: 100%; max-width: 280px; }
.tune-track { position: relative; display: block; height: 20px; }
.tune-line { position: absolute; left: 16.667%; right: 16.667%; top: 9px; height: 3px; border-radius: 2px; background: #4a5266; }
.tune-stop { position: absolute; top: 5px; width: 11px; height: 11px; margin-left: -5.5px; border-radius: 50%; background: #4a5266; }
.tune-stop[data-v="off"] { left: 16.667%; }
.tune-stop[data-v="good"] { left: 50%; }
.tune-stop[data-v="bullseye"] { left: 83.333%; }
.tune-knob {
  position: absolute; top: 1px; left: 50%; width: 18px; height: 18px; margin-left: -9px; border-radius: 50%;
  background: var(--text); box-shadow: 0 0 0 2px #14161c;
  transition: left 160ms ease, background 160ms ease;
}
.tune-labels { display: grid; grid-template-columns: 1fr 1fr 1fr; text-align: center; font-size: 13px; margin-top: 2px; }
.tune-labels span { color: var(--muted); }
/* The knob sits at the current setting, and that setting's word is bright and bold */
.tune-btn[data-level="off"] .tune-knob { left: 16.667%; background: #9aa3b5; }
.tune-btn[data-level="good"] .tune-knob { left: 50%; }
.tune-btn[data-level="bullseye"] .tune-knob { left: 83.333%; }
.tune-btn[data-level="off"] .tune-labels [data-v="off"],
.tune-btn[data-level="good"] .tune-labels [data-v="good"],
.tune-btn[data-level="bullseye"] .tune-labels [data-v="bullseye"] { color: var(--text); font-weight: 800; font-size: 15px; }
/* Greyed out when Off, highlighted (green) when Good or Bullseye */
.tune-btn[data-level="good"], .tune-btn[data-level="bullseye"] { border-color: var(--green); background: #1d3a2e; color: var(--text); }
.tune-btn[data-level="good"] .tune-knob, .tune-btn[data-level="bullseye"] .tune-knob { background: var(--green); }
.tune-btn[data-level="good"] .tune-stop, .tune-btn[data-level="bullseye"] .tune-stop,
.tune-btn[data-level="good"] .tune-line, .tune-btn[data-level="bullseye"] .tune-line { background: #3f7a60; }
/* A device with "reduce motion" on gets no slide: the knob just jumps to the new setting */
@media (prefers-reduced-motion: reduce) { .tune-knob { transition: none; } }

/* Locked while a round is being played: visible but greyed out and not tappable */
.toggle-btn:disabled, .tune-btn:disabled { opacity: 0.4; cursor: default; }

/* ---- Teacher tools panel: buzzer sound and Live display ---- */
.tools-panel { max-width: 560px; margin: 0 auto; padding: 10px 20px 0; }
.tools-row { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.tool-btn, .tool-opt {
  min-height: 40px; padding: 4px 12px; border-radius: 10px; border: 2px solid #3a4050;
  background: var(--panel); color: var(--muted); font-size: 15px; font-weight: 600; cursor: pointer;
}
.tool-btn[aria-pressed="true"], .tool-opt[aria-pressed="true"] { border-color: var(--green); background: #1d3a2e; color: var(--text); }
.tool-group { display: flex; align-items: center; gap: 6px; }
.tool-label { font-size: 14px; color: var(--muted); font-weight: 600; }
.tools-hint { margin: 8px 0 0; font-size: 13px; color: var(--muted); line-height: 1.4; }
/* Teacher tools' panel is for Free Play and Streak Mode; Tune Up stays exactly as it was */
body[data-mode="tuneup"] .tools-panel { display: none !important; }

/* ---- The live meter (no words) ---- */
.meter-block { display: flex; flex-direction: column; gap: 14px; padding-top: 6px; }
.meter-block .meter-labels { font-size: 22px; }

/* ---- Wrong note in large type (Streak Mode), above the Start button ---- */
.end-note { text-align: center; }

/* ---- Round summary: below the main controls, after a round has ended ---- */
.round-summary { display: flex; flex-direction: column; gap: 12px; padding-top: 14px; border-top: 1px solid #262b36; }
.rs-heading { font-size: 24px; margin: 0; }
.rs-message { display: flex; flex-direction: column; gap: 6px; }
.rs-message .over-headline { font-size: 20px; font-weight: 600; margin: 0; text-align: left; }
.rs-message .over-advice { font-size: 16px; color: var(--muted); margin: 0; text-align: left; }
.rs-score { font-size: 18px; font-weight: 700; }
.rs-message .over-best { font-size: 17px; color: var(--amber); font-weight: 600; text-align: left; }
/* The section buttons: one row when they fit; on a screen too narrow for five they wrap onto a second line */
.rs-tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.rs-tab {
  min-height: 46px; border-radius: 12px; border: 2px solid #3a4050; background: var(--panel);
  color: var(--muted); font-size: 15px; padding: 0 5px; font-weight: 600; cursor: pointer; flex: 1 1 auto;
}
.rs-tab[aria-pressed="true"] { border-color: var(--accent); background: #26304a; color: var(--text); font-weight: 800; box-shadow: inset 0 0 0 2px var(--accent); }
/* Notes scrolls on their own if they get long; the Log keeps its scrolling inside its own table panel */
.rs-panel { max-height: min(60vh, 520px); overflow-y: auto; padding: 2px; overscroll-behavior: contain; }
.rs-panel[data-section="log"] { max-height: none; overflow-y: visible; }
.earlier h3 { font-size: 15px; margin: 0 0 4px; color: var(--muted); font-weight: 600; }
.rs-stats { margin: 0; font-size: 16px; font-weight: 600; }
/* Earlier rounds: small, and scrolls inside its own panel if it gets long */
.earlier-stars { color: var(--amber); letter-spacing: 1px; }
.rs-panel .ns-workon { margin: 10px 0 0; }
.rs-panel .log-scroll { max-height: 40vh; overflow-y: auto; }

/* ---- Stars and the highlight line (only earned stars are drawn, never empty ones) ---- */
.rs-stars { font-size: 38px; line-height: 1.1; color: var(--amber); letter-spacing: 6px; }
.rs-stars.fade { animation: stars-in 700ms ease-out both; }
@keyframes stars-in { from { opacity: 0; } to { opacity: 1; } }
/* "Reduce motion": no animation at all */
@media (prefers-reduced-motion: reduce) { .rs-stars.fade { animation: none; } }
.rs-next { margin: 0; font-size: 16px; color: var(--muted); }
.rs-highlight { margin: 0; font-size: 19px; font-weight: 600; line-height: 1.35; }

/* ---- Timeline: one dot per note, in five fixed rows, scrolling sideways on its own ---- */
.rs-panel[data-section="timeline"] { max-height: none; overflow: visible; }
/* The panel is a self-contained card with its own colours, so it reads well in dark mode and in light mode */
.tl {
  --tl-bg: #1b1f28; --tl-text: #f2f4f8; --tl-muted: #aab2c3; --tl-grid: #3a4050; --tl-edge: #0b0d12;
  --tl-bullseye: #3ecf8e; --tl-good: #f5b942; --tl-miss: #ff6b6b; --tl-dot-text: #10131a;
  --tl-band: rgba(62, 207, 142, 0.18); --tl-line: rgba(62, 207, 142, 0.7);
  min-width: 0;
}
@media (prefers-color-scheme: light) {
  .tl {
    --tl-bg: #f4f6fa; --tl-text: #1b1f28; --tl-muted: #4a5266; --tl-grid: #8d96a8; --tl-edge: #1b1f28;
    --tl-miss: #c62828; --tl-band: rgba(30, 140, 95, 0.18); --tl-line: #1f8a5f;
  }
}
.tl-wrap {
  position: relative; display: grid; grid-template-columns: 58px minmax(0, 1fr);
  background: var(--tl-bg); color: var(--tl-text); border: 1px solid var(--tl-grid); border-radius: 12px; min-width: 0;
}
/* Fixed row labels: they stay in place while the dots scroll */
.tl-labels { display: grid; grid-template-rows: 24px 68px 34px 68px; border-right: 1px solid var(--tl-grid); font-size: 12px; font-weight: 600; color: var(--tl-muted); }
.tl-label { display: flex; align-items: center; padding-left: 8px; }
/* The panel scrolls sideways by itself; the page never does */
.tl-scroll { overflow-x: auto; overflow-y: hidden; min-width: 0; max-width: 100%; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch; border-radius: 0 12px 12px 0; }
.tl-scroll:focus-visible { outline: 3px solid var(--tl-text); outline-offset: -3px; }
.tl-canvas { position: relative; min-width: 100%; }
.tl-band { position: absolute; left: 0; right: 0; background: var(--tl-band); }
.tl-centerline { position: absolute; left: 0; right: 0; height: 1px; background: var(--tl-line); }
.tl-divider { position: absolute; top: 0; width: 0; border-left: 2px dashed var(--tl-grid); }
.tl-round { position: absolute; top: 4px; font-size: 12px; font-weight: 700; color: var(--tl-muted); white-space: nowrap; }
.tl-dot {
  position: absolute; display: flex; align-items: center; justify-content: center; padding: 0; border: 0; border-radius: 50%;
  font-family: inherit; font-size: 12px; font-weight: 800; line-height: 1; cursor: pointer; color: var(--tl-dot-text);
  box-shadow: 0 0 0 1.5px var(--tl-edge);
}
.tl-dot.is-bullseye { background: var(--tl-bullseye); }
.tl-dot.is-good { background: var(--tl-good); }
/* A Miss is a hollow ring (red outline, the panel colour inside), so it can be told apart without colour */
.tl-dot.is-miss { background: var(--tl-bg); border: 3px solid var(--tl-miss); box-shadow: none; color: var(--tl-text); }
.tl-dot:focus-visible { outline: 3px solid var(--tl-text); outline-offset: 2px; z-index: 2; }
.tl-tip {
  position: absolute; z-index: 5; max-width: 92%; padding: 6px 10px; border-radius: 8px; pointer-events: none;
  background: var(--tl-text); color: var(--tl-bg); font-size: 13px; font-weight: 600; line-height: 1.3; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}
.tl-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; list-style: none; margin: 8px 0 0; padding: 0; font-size: 14px; color: var(--text); }
.tl-legend li { display: flex; align-items: center; gap: 6px; }
.tl-key { display: inline-block; width: 16px; height: 16px; border-radius: 50%; box-sizing: border-box; }
.tl-key.is-bullseye { background: #3ecf8e; }
.tl-key.is-good { background: #f5b942; }
.tl-key.is-miss { background: transparent; border: 3px solid #ff6b6b; }

/* ---- Trends: where each note landed on average (the sharp/flat chart) ---- */
.rs-panel[data-section="trends"] { max-height: none; overflow: visible; }
.tr {
  --tr-bg: #1b1f28; --tr-text: #f2f4f8; --tr-muted: #aab2c3; --tr-grid: #3a4050;
  --tr-inside: #3ecf8e; --tr-outside: #f5b942; --tr-few: #6b7385;
  --tr-band: rgba(62, 207, 142, 0.18); --tr-line: rgba(62, 207, 142, 0.8);
  min-width: 0;
}
@media (prefers-color-scheme: light) {
  .tr {
    --tr-bg: #f4f6fa; --tr-text: #1b1f28; --tr-muted: #4a5266; --tr-grid: #8d96a8;
    --tr-inside: #1f8a5f; --tr-outside: #a86e00; --tr-few: #707889;
    --tr-band: rgba(30, 140, 95, 0.18); --tr-line: #1f8a5f;
  }
}
.tr h2 { margin: 0 0 8px; }
.tr-empty { margin: 0 0 8px; color: var(--muted); }
/* Only this panel scrolls sideways on a narrow screen, never the page */
/* The whole chart always fits the screen width: nothing here scrolls sideways */
.tr-box { min-width: 0; max-width: 100%; overflow: hidden; background: var(--tr-bg); color: var(--tr-text); border: 1px solid var(--tr-grid); border-radius: 12px; }
.tr-chart { padding: 10px 12px 12px; }
/* Narrow screens: two columns (note name, bar area); each row's details sit on a line under its bar. */
.tr-axis, .tr-row { display: grid; grid-template-columns: 44px minmax(0, 1fr); column-gap: 8px; }
.tr-axis { font-size: 13px; font-weight: 700; color: var(--tr-muted); margin-bottom: 4px; }
.tr-axis-plot { position: relative; height: 18px; }
.tr-flat { position: absolute; left: 0; }
.tr-sharp { position: absolute; right: 0; }
.tr-target { position: absolute; left: 50%; transform: translateX(-50%); }
/* every row has exactly the same height, with or without details text */
.tr-row { margin-top: 8px; align-items: center; grid-template-rows: 22px 15px; row-gap: 3px; } /* the gap keeps the details clear of the centre line, which sticks out 2 px below the bar area */
.tr-name { font-size: 16px; font-weight: 800; }
.tr-plot { position: relative; height: 22px; border-left: 1px solid var(--tr-grid); border-right: 1px solid var(--tr-grid); }
.tr-band { position: absolute; top: 0; bottom: 0; background: var(--tr-band); }
.tr-center { position: absolute; top: -2px; bottom: -2px; left: 50%; width: 2px; margin-left: -1px; background: var(--tr-line); }
.tr-bar { position: absolute; top: 4px; bottom: 4px; min-width: 3px; border-radius: 3px; background: var(--tr-inside); box-shadow: 0 0 0 1px var(--tr-bg); }
.tr-row.is-outside .tr-bar { background: var(--tr-outside); }
.tr-row.is-few .tr-bar { background: var(--tr-few); }
.tr-arrow { position: absolute; top: 3px; font-size: 12px; line-height: 16px; color: var(--tr-text); }
/* details text: small, two lines of fixed height */
.tr-details { grid-column: 2; grid-row: 2; font-size: 11px; line-height: 15px; height: 15px; color: var(--tr-muted); white-space: nowrap; overflow: hidden; }
.tr-d { display: none; }
.tr-d-simple { display: block; }
.teacher-on .tr-d-simple { display: none; }
.teacher-on .tr-d-teacher { display: block; }
.tr-line { height: 15px; display: inline; }
.tr-line:empty { display: none; }
.tr-line + .tr-line:not(:empty)::before { content: ' · '; }
/* The average in cents and the number of tries: Teacher tools only */
.tr-teacher { display: none; }
.teacher-on .tr-teacher { display: block; }
.tr-caption { margin: 8px 0 0; font-size: 14px; color: var(--muted); line-height: 1.4; }
.tr-visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---- Teacher tools: frequency numbers (Hz). Everything here is hidden until Teacher tools is on. ---- */
.hz-line { text-align: center; color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; min-height: 1.3em; }
.teacher-col { display: none; }
.teacher-on th.teacher-col, .teacher-on td.teacher-col { display: table-cell; }
.teacher-inline { display: none; }
.teacher-on .teacher-inline { display: inline; }
.teacher-on .tt-hide { display: none; }

/* Trends bars: the simple fixed-shape bars (Teacher tools off) or the true-length bars (Teacher tools on) */
.tr-bar-true { display: none; }
.teacher-on .tr-bar-true { display: block; }
.teacher-on .tr-bar-simple { display: none; }
.tr-sr-teacher { display: none; }
.teacher-on .tr-sr-teacher { display: block; }
.teacher-on .tr-sr-simple { display: none; }

/* Wider than about 600 px: three columns (name, bar area, a fixed-width details column). The details column is always there,
   and holds up to two short lines of small text, centred on the row, so every row is the same height. */
@media (min-width: 601px) {
  .tr-axis, .tr-row { grid-template-columns: 44px minmax(0, 1fr) 132px; }
  .tr-row { grid-template-rows: 34px; row-gap: 0; }
  .tr-details { grid-column: 3; grid-row: 1; height: 30px; align-self: center; }
  /* one or two lines, centred on the row */
  .tr-d-simple, .teacher-on .tr-d-teacher { display: flex; flex-direction: column; justify-content: center; height: 30px; }
  .teacher-on .tr-d-simple { display: none; }
  .tr-line { display: block; }
  .tr-line + .tr-line:not(:empty)::before { content: none; }
}

/* ---- About and Feedback: two small buttons in the top row, two dialogs, and the microphone help message ---- */
.topbar-row { flex-wrap: wrap; } /* on a narrow phone the buttons wrap onto a second line */
.topbar .teacher-toggle:disabled { opacity: 0.4; cursor: not-allowed; } /* greyed out while a round is in progress; the layout does not move */
.teacher-toggle:focus-visible, .dialog-close:focus-visible, .dialog-action:focus-visible, .info-dialog a:focus-visible, .link-button:focus-visible, .mic-help a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
body[data-mode="tuneup"] .topbar-info { display: none; }
body:has(dialog[open]) { overflow: hidden; } /* the page behind does not scroll while a dialog is open (only while: it cannot get stuck) */
.info-dialog { width: min(92vw, 480px); max-height: 86vh; padding: 0; border: 1px solid #3a4050; border-radius: 16px; background: var(--panel); color: var(--text); overflow: auto; margin: auto; }
.info-dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.dialog-body { padding: 18px 20px 20px; font-size: 15px; line-height: 1.5; }
.dialog-body h2 { font-size: 20px; margin: 0 0 10px; }
.dialog-body p { margin: 0 0 12px; }
.dialog-close { display: block; margin: 0 0 8px auto; background: transparent; color: var(--muted); border: 1px solid #3a4050; border-radius: 999px; padding: 6px 14px; font-size: 14px; cursor: pointer; }
.info-dialog a, .mic-help a { color: var(--accent); }
.dialog-action { display: inline-block; padding: 12px 18px; border-radius: 12px; background: var(--accent); color: #0b1020 !important; font-weight: 700; text-decoration: none; }
.about-links { margin: 0 0 12px; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.about-hint, .about-privacy, .about-version { color: var(--muted); font-size: 14px; }
.about-version { margin-bottom: 0 !important; font-size: 13px; }
.link-button { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); text-decoration: underline; cursor: pointer; }
.mic-help { max-width: 560px; margin: 8px auto 0; padding: 12px 14px; border: 1px solid #5a4a2a; border-radius: 12px; background: #2a2418; color: var(--text); font-size: 14px; line-height: 1.45; text-align: left; }
.mic-help[hidden] { display: none; }
.mic-head { margin: 0 0 6px; font-weight: 700; font-size: 15px; }
.mic-help ul { margin: 0 0 8px; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }
.mic-stuck { margin: 0; font-size: 13px; }

/* Tune Up: shown only on an iPhone or iPad where the "playback" audio type could not be set */
.no-sound-hint { margin: 10px 0 0; text-align: center; color: var(--muted); font-size: 14px; line-height: 1.4; }
.no-sound-hint[hidden] { display: none; }
