:root {
  --bg: #0d1117;
  --panel: #161b22;
  --ink: #e6edf3;
  --dim: #8b949e;
  --line: #30363d;
  --good: #3fb950;
  --ok: #d29922;
  --off: #f85149;
  --steel1: #b9c2cc;
  --steel2: #6e7681;
  --accent: #58a6ff;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: radial-gradient(1200px 600px at 50% -10%, #1b2430, var(--bg));
  color: var(--ink);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
main { max-width: 760px; margin: 0 auto; padding: 28px 20px 60px; }

header { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
header h1 {
  margin: 0; font-size: 30px; letter-spacing: .5px; font-weight: 700;
}
header h1 .sub { font-weight: 400; color: var(--dim); font-size: 18px; }
#lang { padding: 6px 8px; font-size: 13px; min-width: auto; }
/* RTL (Arabic): keep the diagrams/meter LTR so note positions don't mirror */
[dir="rtl"] .pan, [dir="rtl"] .kbd, [dir="rtl"] .fret, [dir="rtl"] .meter-track { direction: ltr; }
.tagline { margin: 4px 0 0; color: var(--dim); }

.controls {
  display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-end;
  margin: 22px 0; padding: 16px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px;
}
.ctrl { display: flex; flex-direction: column; gap: 6px; }
.ctrl label { font-size: 12px; color: var(--dim); text-transform: uppercase; letter-spacing: .06em; }
.ref-row { display: flex; align-items: center; gap: 6px; }
input[type=number] {
  width: 78px; background: #0d1117; color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px; font-size: 15px;
}
.unit { color: var(--dim); }
input[type=range] { width: 160px; accent-color: var(--accent); }

button {
  cursor: pointer; border: 1px solid var(--line); border-radius: 8px;
  background: #21262d; color: var(--ink); padding: 8px 12px; font-size: 14px;
}
button:hover { border-color: var(--accent); }
.primary {
  background: var(--accent); color: #04121f; border-color: var(--accent);
  font-weight: 600; padding: 12px 18px; font-size: 15px;
}
.primary.live { background: var(--good); border-color: var(--good); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .72; } }
.chip { padding: 6px 9px; font-size: 12px; }

select {
  background: #0d1117; color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; font-size: 15px; min-width: 170px;
}
select:hover { border-color: var(--accent); }

/* --- identify panel --- */
.identify {
  margin: 0 0 22px; padding: 14px 16px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px;
}
.id-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
#idToggle.live { background: var(--good); border-color: var(--good); color: #04121f; font-weight: 600; animation: pulse 1.4s infinite; }
.id-notes { color: var(--dim); font-size: 13px; font-variant-numeric: tabular-nums; }
.guesses { display: flex; gap: 14px; margin-top: 14px; flex-wrap: wrap; }
.guess {
  flex: 1 1 240px; padding: 12px 14px; border: 1px solid var(--line);
  border-radius: 10px; background: #0d1117;
}
.guess.lead { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(88,166,255,.3); }
.g-rank { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--dim); }
.guess.lead .g-rank { color: var(--accent); }
.g-name { font-size: 18px; font-weight: 700; margin: 2px 0; }
.g-meta { font-size: 12px; color: var(--dim); margin-bottom: 10px; }
.g-use { width: 100%; font-size: 13px; }
.guess.lead .g-use { background: var(--accent); color: #04121f; border-color: var(--accent); font-weight: 600; }

/* --- stage: pan diagram + readout --- */
.stage { display: grid; grid-template-columns: 300px 1fr; gap: 24px; align-items: center; }
@media (max-width: 640px) { .stage { grid-template-columns: 1fr; } }

.pan {
  position: relative; width: 300px; height: 300px; margin: 0 auto;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 42%, #dfe6ec 0%, var(--steel1) 24%, var(--steel2) 62%, #3a4048 100%);
  box-shadow: inset 0 6px 24px rgba(255,255,255,.25), inset 0 -14px 40px rgba(0,0,0,.6), 0 18px 40px rgba(0,0,0,.5);
}
.field {
  position: absolute; transform: translate(-50%, -50%);
  min-width: 40px; padding: 6px 8px; text-align: center;
  background: rgba(13,17,23,.72); color: var(--ink);
  border: 1px solid rgba(255,255,255,.18); border-radius: 999px;
  font-size: 13px; font-weight: 600; backdrop-filter: blur(2px);
  transition: transform .1s, box-shadow .1s, background .1s;
}
.field.ding {
  width: 74px; height: 74px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 40% 35%, #2b3138, #0d1117);
  box-shadow: inset 0 3px 10px rgba(0,0,0,.7);
}
.field.active {
  background: var(--accent); color: #04121f; border-color: #fff;
  transform: translate(-50%, -50%) scale(1.18);
  box-shadow: 0 0 0 3px rgba(88,166,255,.35);
}

.readout { min-width: 0; }
.note-line { display: flex; align-items: baseline; gap: 6px; }
.note-name { font-size: 64px; font-weight: 800; line-height: 1; }
.note-name.good { color: var(--good); }
.note-name.ok { color: var(--ok); }
.note-name.off { color: var(--off); }
.octave { font-size: 24px; color: var(--dim); }

.meter { margin: 14px 0 10px; }
.meter-scale { display: flex; justify-content: space-between; font-size: 11px; color: var(--dim); }
.meter-scale .zero { color: var(--ink); }
.meter-track {
  position: relative; height: 26px; margin-top: 4px;
  background: #0d1117; border: 1px solid var(--line); border-radius: 6px; overflow: hidden;
}
.meter-zone { position: absolute; top: 0; bottom: 0; background: rgba(63,185,80,.18); }
.meter-center { position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; background: var(--dim); }
.meter-needle {
  position: absolute; left: 50%; top: -3px; bottom: -3px; width: 3px;
  background: var(--accent); transform: translateX(-50%);
  transition: left .08s linear; box-shadow: 0 0 8px var(--accent);
}

.verdict { font-size: 18px; font-weight: 600; min-height: 26px; }
.verdict.good { color: var(--good); }
.verdict.ok { color: var(--ok); }
.verdict.off { color: var(--off); }
.detail { color: var(--dim); font-variant-numeric: tabular-nums; margin-top: 2px; }

/* --- table --- */
.list { margin-top: 30px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--dim); font-weight: 600; }
tr.good td { background: rgba(63,185,80,.07); }
tr.ok td { background: rgba(210,153,34,.07); }
tr.off td { background: rgba(248,81,73,.09); }
tr.good .status { color: var(--good); }
tr.ok .status { color: var(--ok); }
tr.off .status { color: var(--off); }
.tag { font-size: 10px; color: var(--dim); border: 1px solid var(--line); border-radius: 4px; padding: 1px 4px; }
.hint { color: var(--dim); font-size: 13px; }

footer { margin-top: 34px; color: var(--dim); font-size: 12px; display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }
.foot-right { display: flex; gap: 10px; align-items: center; }
.mark { letter-spacing: 2px; opacity: .5; }
/* footer wordmark doubles as a "go home / start over" link */
.home-link { text-decoration: none; color: inherit; transition: opacity .12s; }
.home-link:hover .mark { opacity: 1; }
.home-hint { font-size: 11px; color: var(--dim); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; }
.home-hint::before { content: "⌂ "; }
.home-link:hover .home-hint { border-color: var(--accent); color: var(--accent); }

/* ---------------- guided flow ---------------- */
.hidden { display: none !important; }
.step { margin: 24px 0; }

#stepStart { text-align: center; padding: 30px 0; }
.big { font-size: 19px; padding: 18px 26px; }
.tagline { margin: 14px 0 0; color: var(--dim); }
.linkbtn { background: none; border: none; color: var(--accent); margin-top: 16px; font-size: 14px; padding: 8px; }
.linkbtn:hover { text-decoration: underline; }

#stepIdentify h2 { font-size: 20px; margin: 0 0 12px; }

/* guess cards are now buttons */
.guesses { display: flex; gap: 14px; flex-wrap: wrap; }
.guess {
  flex: 1 1 240px; text-align: left; padding: 16px; border: 1px solid var(--line);
  border-radius: 12px; background: #0d1117; color: var(--ink); cursor: pointer;
}
.guess:hover { border-color: var(--accent); }
.guess.lead { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(88,166,255,.3); background: rgba(88,166,255,.06); }
.g-rank { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--dim); }
.guess.lead .g-rank { color: var(--accent); }
.g-name { font-size: 20px; font-weight: 700; margin: 3px 0; }
.g-meta { font-size: 12px; color: var(--dim); }

/* confirm bar (basic inputs, prefilled + overridable) */
.confirm { display: flex; flex-wrap: wrap; gap: 18px; align-items: flex-end;
  padding: 14px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.chip.ghost { background: none; margin-left: auto; align-self: center; }

/* adjustment summary */
.summary { margin: 16px 0; padding: 14px 16px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--panel); font-size: 15px; }
.summary.good { border-color: var(--good); color: var(--good); }
.summary.off { border-color: var(--off); }
.summary strong { display: inline-block; margin-right: 8px; }
.chip-note { display: inline-block; margin: 3px 6px 3px 0; padding: 3px 9px; font-size: 13px;
  border-radius: 999px; background: rgba(248,81,73,.14); color: #ffb3ae; font-variant-numeric: tabular-nums; }
.untested { margin-top: 8px; font-size: 12px; color: var(--dim); font-variant-numeric: tabular-nums; }

/* pro panel */
.pro { margin: 16px 0; padding: 14px 16px; background: var(--panel);
  border: 1px dashed var(--accent); border-radius: 12px; }
.pro-note { margin: 8px 0 0; font-size: 12px; color: var(--dim); }
kbd { font: inherit; font-size: 11px; background: #21262d; border: 1px solid var(--line);
  border-bottom-width: 2px; border-radius: 5px; padding: 1px 6px; }

/* always-present but understated tolerance control, tucked at the foot of tuning */
.tune-extra { margin-top: 24px; padding-top: 14px; border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; opacity: .65; }
.tune-extra:hover, .tune-extra:focus-within { opacity: 1; }
.tune-extra label { color: var(--dim); font-size: 12px; }
.tune-extra input[type=range] { width: 150px; accent-color: var(--accent); }

/* keep wide table from breaking mobile layout */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.field { -webkit-backdrop-filter: blur(2px); }

@media (max-width: 640px) {
  main { padding: 20px 14px 48px; }
  .confirm { gap: 12px; }
  .chip.ghost { margin-left: 0; }
  .note-name { font-size: 52px; }
}

/* ---------------- identify: live input cue ---------------- */
.listening { display: flex; align-items: center; gap: 12px; margin: 4px 0 16px; }
.mic-dot { width: 12px; height: 12px; border-radius: 50%; flex: none;
  background: var(--line); transition: background .12s, box-shadow .12s; }
.mic-dot.on { background: var(--good); box-shadow: 0 0 0 4px rgba(63,185,80,.18); animation: micpulse 1s infinite; }
@keyframes micpulse { 50% { box-shadow: 0 0 0 7px rgba(63,185,80,.05); } }
.level { flex: 1; height: 10px; background: #0d1117; border: 1px solid var(--line);
  border-radius: 999px; overflow: hidden; }
.level-fill { height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--good), var(--accent));
  border-radius: 999px; transition: width .06s linear; }
.level-label { font-size: 12px; color: var(--dim); min-width: 92px; }

/* last-heard note badge, pulses on each new detection */
.last-note { display: flex; align-items: baseline; gap: 10px; margin: 0 0 14px; min-height: 46px; }
.ln-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--dim); }
.ln-note { font-size: 40px; font-weight: 800; line-height: 1; color: var(--accent);
  font-variant-numeric: tabular-nums; }
.last-note.flash .ln-note { animation: noteflash .45s ease-out; }
@keyframes noteflash {
  0% { transform: scale(1.45); color: #fff; text-shadow: 0 0 18px var(--accent); }
  100% { transform: scale(1); }
}

/* heard-note chips */
.id-notes { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 0 0 16px; }
.id-notes .dim { color: var(--dim); font-size: 14px; }
.hchip { padding: 4px 10px; border-radius: 999px; font-size: 14px; font-weight: 600;
  background: rgba(88,166,255,.14); color: #a9d0ff; font-variant-numeric: tabular-nums; }
.hcount { margin-left: 4px; font-size: 12px; color: var(--dim); }

/* confident top guess reads as a call-to-action */
.guess.confident { animation: guesspop .5s ease-out; box-shadow: 0 0 0 2px var(--accent), 0 0 22px rgba(88,166,255,.25); }
.guess .g-meta b { color: var(--accent); }
@keyframes guesspop { 0% { transform: scale(.97); } 60% { transform: scale(1.02); } 100% { transform: scale(1); } }

@media (prefers-reduced-motion: reduce) {
  .mic-dot.on, .last-note.flash .ln-note, .guess.confident { animation: none; }
}

/* ---------------- piano hint ---------------- */
.piano-hint { margin: 16px 0; padding: 4px 16px 16px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px; }
.piano-hint summary { cursor: pointer; padding: 12px 0; font-weight: 600; font-size: 15px; }
.piano-hint summary::marker { color: var(--dim); }
.ph-sub { color: var(--dim); font-weight: 400; font-size: 13px; }
.ph-line { margin: 2px 0 12px; color: var(--ink); font-size: 14px; }
.ph-line b { color: var(--accent); }

/* keyboard */
.kbd { position: relative; height: 108px; margin: 4px 0 14px; user-select: none; }
.kbd .whites { display: flex; height: 100%; }
.wkey { flex: 1; position: relative; background: #e8edf3; border: 1px solid #0d1117;
  border-radius: 0 0 4px 4px; display: flex; align-items: flex-end; justify-content: center; }
.bkey { position: absolute; top: 0; height: 63%; background: #1c2230; border: 1px solid #0d1117;
  border-radius: 0 0 4px 4px; z-index: 2; }
.wkey.in-scale { background: linear-gradient(#bcd6ff, #8fbcff); }
.bkey.in-scale { background: linear-gradient(#3f6bb0, #2b4d86); }
.wkey.root { background: linear-gradient(#ffd9a0, var(--ok)); box-shadow: inset 0 0 0 2px var(--ok); }
.bkey.root { background: linear-gradient(#b9791f, #8a5a12); box-shadow: 0 0 0 2px var(--ok); }
.wkey.lit, .bkey.lit { background: var(--accent) !important; box-shadow: 0 0 12px var(--accent); }
.wlbl { font-size: 11px; font-weight: 700; color: #0d1117; padding-bottom: 4px; }
.mclbl { position: absolute; bottom: 2px; left: 0; right: 0; text-align: center;
  font-size: 9px; color: var(--dim); }
.wkey.mc { border-bottom: 3px solid var(--dim); }

/* piano + guitar side by side */
.ref-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 14px; }
@media (max-width: 680px) { .ref-grid { grid-template-columns: 1fr; } }
.ref-label { font-size: 12px; color: var(--dim); margin-bottom: 6px; }
.ref-label .dim { opacity: .85; }

/* fretboard */
.fret { background: linear-gradient(#3a2c1e, #2a2016); border: 1px solid #0d1117;
  border-radius: 6px; padding: 6px 6px 2px; }
.fstring { position: relative; display: flex; height: 20px; }
.fstring::before { content: ""; position: absolute; left: 20px; right: 0; top: 50%;
  height: 1px; background: #b6a07f; }
.fcell { flex: 1; position: relative; display: flex; align-items: center; justify-content: center;
  border-right: 1px solid #6b563f; }
.fcell.open { flex: 0 0 20px; border-right: 3px solid #d8c9b0; }   /* the nut */
.fdot { width: 13px; height: 13px; border-radius: 50%; z-index: 2;
  background: #8fbcff; box-shadow: 0 1px 2px rgba(0,0,0,.5); }
.fdot.root { background: var(--ok); box-shadow: 0 0 0 2px rgba(210,153,34,.4); }
.fdot.lit { background: var(--accent) !important; box-shadow: 0 0 10px var(--accent); }
.fnums { display: flex; margin-top: 2px; }
.fnum { flex: 1; text-align: center; font-size: 10px; color: var(--dim); }
.fnum.open { flex: 0 0 20px; }

/* degree chips + legend swatches */
.ph-degrees { display: flex; flex-wrap: wrap; gap: 6px; }
.dchip { display: inline-flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 5px 10px; border-radius: 8px; background: #0d1117; border: 1px solid var(--line);
  font-variant-numeric: tabular-nums; }
.dchip b { font-size: 14px; }
.dchip .dname { font-size: 11px; color: var(--accent); }
.ph-foot { margin: 12px 0 0; font-size: 12px; color: var(--dim); }
.k-root { color: var(--ok); } .k-mc { color: var(--ink); border-bottom: 2px solid var(--dim); }
