/* Fret Sharp styles.
 *
 * Palette values come from the dataviz skill's validated reference palette and
 * were re-checked with scripts/validate_palette.js for both light and dark
 * surfaces. Do not hand-pick new chart colours — run the validator.
 */

:root {
  color-scheme: light;

  /* Surfaces and ink */
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);

  /* Categorical series slots (validated: adjacent CVD dE 9.1 light) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;

  /* Sequential blue ramp, for the mastery heatmap */
  --seq-100: #cde2fb;
  --seq-250: #86b6ef;
  --seq-350: #5598e7;
  --seq-450: #2a78d6;
  --seq-500: #256abf;
  --seq-650: #104281;

  /* Status — reserved, never reused as a series colour */
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-critical: #d03b3b;
  --success-text: #006300;

  --radius: 10px;
  --radius-lg: 16px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;

    /* Dark ordinal steps: validated separately — the light ramp's steps sit too
     * close together against a dark surface. */
    --seq-100: #b7d3f6;
    --seq-250: #6da7ec;
    --seq-350: #3987e5;
    --seq-450: #2a78d6;
    --seq-500: #256abf;
    --seq-650: #184f95;

    --success-text: #0ca30c;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--page);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--series-1); }

h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5rem; font-weight: 600; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }

p { margin: 0 0 0.75rem; }

.muted { color: var(--text-muted); }
.secondary { color: var(--text-secondary); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }

/* --- Layout --------------------------------------------------------------- */

.shell {
  max-width: 940px;
  margin: 0 auto;
  padding: 0 1rem 4rem;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar .brand {
  font-weight: 600;
  text-decoration: none;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.topbar nav {
  display: flex;
  gap: 0.35rem;
  margin-left: auto;
  flex-wrap: wrap;
}

.topbar nav a {
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.topbar nav a:hover { background: var(--page); }
.topbar nav a[aria-current="page"] {
  color: var(--text-primary);
  background: var(--page);
  font-weight: 600;
}

.code-chip {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  padding: 0.2rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.15rem;
  margin: 1rem 0;
}

.card > h2:first-child, .card > h3:first-child { margin-top: 0; }

.grid { display: grid; gap: 1rem; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

.row { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: center; }
.row.tight { gap: 0.4rem; }
.spacer { flex: 1; }

/* --- Buttons and forms ---------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1rem;
  min-height: 44px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}

.btn:hover { background: var(--page); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn.primary {
  background: var(--series-1);
  border-color: var(--series-1);
  color: #fff;
}
.btn.primary:hover { filter: brightness(1.06); }

.btn.small { padding: 0.35rem 0.7rem; min-height: 36px; font-size: 0.85rem; }
.btn.block { width: 100%; }

input[type="text"], select {
  font: inherit;
  padding: 0.6rem 0.7rem;
  min-height: 44px;
  border-radius: var(--radius);
  border: 1px solid var(--baseline);
  background: var(--surface-1);
  color: var(--text-primary);
}

.code-input {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.5rem;
  letter-spacing: 0.35em;
  text-align: center;
  text-transform: uppercase;
  width: 100%;
  max-width: 320px;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem 1rem;
  margin: 0 0 1rem;
}
legend { padding: 0 0.4rem; font-weight: 600; font-size: 0.9rem; }

.checks { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.check {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.7rem;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
  font-size: 0.9rem;
}
.check:has(input:checked) {
  border-color: var(--series-1);
  background: color-mix(in oklab, var(--series-1) 10%, var(--surface-1));
  font-weight: 500;
}

.error {
  border-left: 3px solid var(--status-critical);
  padding: 0.6rem 0.85rem;
  background: color-mix(in oklab, var(--status-critical) 8%, var(--surface-1));
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.notice {
  border-left: 3px solid var(--status-good);
  padding: 0.6rem 0.85rem;
  background: color-mix(in oklab, var(--status-good) 8%, var(--surface-1));
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

/* --- Stat tiles ----------------------------------------------------------- */

.stat {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.9rem 1rem;
}

.stat .label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.2rem;
}

/* Proportional figures, not tabular: at display sizes tabular-nums makes a
 * number like 121 look loose. */
.stat .value { font-size: 1.65rem; font-weight: 600; letter-spacing: -0.02em; }
.stat .sub { font-size: 0.8rem; color: var(--text-muted); }

.hero {
  font-size: 3rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1;
}

/* Daily-goal ring */
.ring { --pct: 0; display: grid; place-items: center; width: 92px; height: 92px; }
.ring .track {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  background: conic-gradient(
    var(--series-1) calc(var(--pct) * 1%),
    var(--gridline) 0
  );
  display: grid;
  place-items: center;
  grid-area: 1 / 1;
}
.ring .hole {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--surface-1);
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 0.95rem;
}
.ring.met .track { background: conic-gradient(var(--status-good) 100%, var(--status-good) 0); }

.streak-flame { font-size: 1.3rem; }

/* --- Fretboard ------------------------------------------------------------ */

.fretboard-wrap {
  position: relative;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 0.25rem 0;
  /* The board scrolls sideways; the browser must not claim vertical drags that
   * start on a cell, or a tap-vs-scroll ambiguity turns into a wrong answer. */
  touch-action: pan-x;
}

.fretboard { display: block; min-width: 620px; width: 100%; height: auto; }

.fb-neck { fill: color-mix(in oklab, var(--baseline) 22%, var(--surface-1)); }
.fb-fretwire { stroke: var(--baseline); stroke-width: 1.5; }
.fb-nut { stroke: var(--text-secondary); stroke-width: 5; stroke-linecap: round; }
.fb-string { stroke: var(--text-muted); stroke-linecap: round; }
.fb-inlay { fill: var(--baseline); opacity: 0.55; }
.fb-fretnum { fill: var(--text-muted); font-size: 11px; text-anchor: middle; }
.fb-stringlabel {
  fill: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  text-anchor: middle;
  dominant-baseline: middle;
}

.fb-cell { cursor: pointer; }
.fb-cell.inactive { cursor: default; }
.fb-hit { fill: transparent; }
.fb-cell:not(.inactive):hover .fb-hit {
  fill: color-mix(in oklab, var(--series-1) 14%, transparent);
}
.fb-cell.dimmed { opacity: 0.25; pointer-events: none; }

.fb-dot { fill: var(--surface-1); stroke: var(--baseline); stroke-width: 1; }
.fb-dot.filled { fill: var(--series-1); stroke: none; }
.fb-label {
  font-size: 11px;
  font-weight: 600;
  text-anchor: middle;
  dominant-baseline: middle;
  fill: var(--text-primary);
  pointer-events: none;
}
/* Fill-aware ink. A heat cell's fill is chosen by strength, so its label can't
 * inherit the theme's text token — a pale ramp step in dark mode would get white
 * text on it. The renderer names the ink instead. */
.fb-label.on-fill { fill: #fff; }
.fb-label.on-light-fill { fill: #0b0b0b; }

/* Answer states */
.fb-dot.marked { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }
.fb-dot.correct { fill: var(--status-good); stroke: var(--surface-1); stroke-width: 2; }
.fb-dot.wrong { fill: var(--status-critical); stroke: var(--surface-1); stroke-width: 2; }

/* The target ring on "name this note" questions: a ring, not a fill, so it
 * cannot be mistaken for an answer that's already been given. */
.fb-target {
  fill: none;
  stroke: var(--series-1);
  stroke-width: 3;
  animation: pulse 1.6s ease-in-out infinite;
}
.fb-root { fill: var(--series-2); stroke: var(--surface-1); stroke-width: 2; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

@media (prefers-reduced-motion: reduce) {
  .fb-target { animation: none; }
}

/* Heatmap cells use the sequential ramp; unseen is the surface, not a colour,
 * so "never tried" never reads as a magnitude. */
.fb-heat { stroke: var(--surface-1); stroke-width: 2; }
.fb-heat.s0 { fill: var(--page); }
.fb-heat.s1 { fill: var(--seq-100); }
.fb-heat.s2 { fill: var(--seq-250); }
.fb-heat.s3 { fill: var(--seq-350); }
.fb-heat.s4 { fill: var(--seq-500); }
.fb-heat.s5 { fill: var(--seq-650); }

.heat-legend { display: flex; align-items: center; gap: 0.4rem; font-size: 0.8rem;
  color: var(--text-secondary); flex-wrap: wrap; }
.heat-legend .swatch {
  width: 22px; height: 12px; border-radius: 2px; display: inline-block;
  border: 1px solid var(--border);
}
.heat-legend .swatch.s0 { background: var(--page); }
.heat-legend .swatch.s1 { background: var(--seq-100); }
.heat-legend .swatch.s2 { background: var(--seq-250); }
.heat-legend .swatch.s3 { background: var(--seq-350); }
.heat-legend .swatch.s4 { background: var(--seq-500); }
.heat-legend .swatch.s5 { background: var(--seq-650); }

.fb-tooltip {
  position: absolute;
  z-index: 30;
  transform: translate(-50%, -100%);
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--baseline);
  border-radius: var(--radius);
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
  line-height: 1.45;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.14);
}

/* --- Drill runner --------------------------------------------------------- */

.drill-head {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.timer {
  font-size: 1.5rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.timer.urgent { color: var(--status-critical); }

.prompt {
  font-size: 1.35rem;
  font-weight: 600;
  min-height: 2.4rem;
  margin: 0.25rem 0 0.15rem;
}
.prompt .note {
  color: var(--series-1);
  font-size: 1.6rem;
}

.hint {
  font-size: 0.88rem;
  color: var(--text-secondary);
  border-left: 3px solid var(--series-4);
  padding-left: 0.6rem;
  margin: 0.35rem 0;
}

.feedback { min-height: 2.6rem; margin: 0.5rem 0; font-weight: 500; }
.feedback .ok { color: var(--success-text); }
.feedback .bad { color: var(--status-critical); }
.feedback .slow { color: var(--text-secondary); font-weight: 400; }

.note-picker {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.4rem;
  margin-top: 0.75rem;
}

/* Chromatic order is fixed on purpose: the picker itself must not become a
 * source of latency noise. */
.note-btn {
  min-height: 52px;
  font-size: 1rem;
  font-weight: 600;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  cursor: pointer;
}
.note-btn:hover:not(:disabled) { background: var(--page); }
.note-btn.accidental { color: var(--text-secondary); }
.note-btn.chosen { border-color: var(--series-1); border-width: 2px; }
.note-btn.correct { background: var(--status-good); border-color: var(--status-good); color: #fff; }
.note-btn.wrong { background: var(--status-critical); border-color: var(--status-critical); color: #fff; }

@media (max-width: 520px) {
  .note-picker { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.progress-bar {
  height: 6px;
  background: var(--gridline);
  border-radius: 3px;
  overflow: hidden;
  margin: 0.5rem 0;
}
.progress-bar > span {
  display: block;
  height: 100%;
  background: var(--series-1);
  border-radius: 3px;
  transition: width 0.2s ease;
}

.session-summary { text-align: center; padding: 1rem 0; }
.session-summary .hero { color: var(--series-1); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid var(--border);
}
.badge.best {
  background: color-mix(in oklab, var(--status-good) 14%, var(--surface-1));
  border-color: var(--status-good);
  color: var(--success-text);
}

/* --- Charts and tables ---------------------------------------------------- */

.chart-card { background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1rem 1.15rem 1.25rem; margin: 1rem 0; }
.chart-head { margin-bottom: 0.5rem; }
.chart-head h3 { margin-bottom: 0.15rem; }
.chart-sub { font-size: 0.85rem; color: var(--text-secondary); }

/* Sized to include the x-axis band, so the card never gets a nested scrollbar. */
.chart-box { position: relative; height: 220px; }
.chart-box.short { height: 170px; }

.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: 0.85rem;
  color: var(--text-secondary); margin-top: 0.5rem; }
.legend .key { display: inline-flex; align-items: center; gap: 0.35rem; }
.legend .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.legend .line { width: 16px; height: 2px; border-radius: 1px; display: inline-block; }

.filter-row {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 1rem;
}

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); }
th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: none; }

.table-scroll { overflow-x: auto; }

details.table-view { margin-top: 0.75rem; }
details.table-view summary {
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-secondary);
  padding: 0.3rem 0;
}

.bar-cell { display: flex; align-items: center; gap: 0.5rem; }
.bar-cell .track { flex: 1; height: 8px; background: var(--gridline); border-radius: 4px; }
.bar-cell .fill { height: 100%; border-radius: 4px; background: var(--series-1); }

.empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-secondary);
}

/* --- Reference page ------------------------------------------------------- */

.ref-table { font-variant-numeric: tabular-nums; }
.ref-table td { text-align: center; padding: 0.35rem 0.25rem; font-size: 0.85rem; }
.ref-table td.open { font-weight: 600; }
.ref-table td.natural { font-weight: 600; }
.ref-table td.accidental { color: var(--text-muted); }
.ref-table th.string-head { text-align: right; }
.ref-table tr.inlay-col { background: var(--page); }
.ref-table col.inlay { background: color-mix(in oklab, var(--series-1) 6%, transparent); }

.shape-list { list-style: none; padding: 0; margin: 0; }
.shape-list li {
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 0.75rem;
  align-items: baseline;
}
.shape-list li:last-child { border-bottom: none; }
.shape-list .key {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  color: var(--series-1);
  min-width: 4.5rem;
}

.fact-list { padding-left: 1.1rem; margin: 0; }
.fact-list li { margin-bottom: 0.4rem; }

@media (max-width: 640px) {
  .shell { padding: 0 0.75rem 3rem; }
  .card, .chart-card { padding: 0.9rem; border-radius: var(--radius); }
  h1 { font-size: 1.3rem; }
  .hero { font-size: 2.4rem; }
}
