:root {
  color-scheme: dark;
  --amber: #e8a13d;
  --amber-dim: #7b5119;
  --ink: #f4efe8;
  --muted: #b9ad9c;
  --panel: rgba(16, 16, 14, .86);
  --line: #332c22;
  --bg: #070706;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  line-height: 1.6;
}
button, select, input { font: inherit; }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ── instrument stage ─────────────────────────────────────────────────── */

#stage {
  position: relative;
  width: 100%;
  height: 100svh;
  overflow: hidden;
  background: radial-gradient(circle at 50% 60%, #17120b, #070706 55%);
}
#webcam { display: none; }
#overlay {
  position: absolute; inset: 0; width: 100%; height: 100%;
  transition: filter .4s, opacity .4s;
}
#overlay.dimmed { filter: grayscale(1) brightness(.38); opacity: .7; }

.controls {
  position: absolute; top: 16px; left: 16px; z-index: 5;
  display: grid; gap: 10px; justify-items: start;
}
/* Nothing to configure until an instrument is actually running — showing a
   dead control stack behind the start card just looks broken. */
#stage:not(.live) .controls { display: none; }
.toolbar-toggle {
  min-height: 42px; padding: 8px 14px; border-radius: 7px; cursor: pointer;
  border: 1px solid rgba(232, 161, 61, .24); background: var(--panel);
  color: var(--amber); font-size: 14px; font-weight: 700; letter-spacing: .04em;
  box-shadow: 0 8px 30px #0005;
}
.toolbar-body { display: grid; gap: 10px; justify-items: start; }
.toolbar-body.collapsed { display: none; }
.control-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
select, .controls button {
  min-height: 42px;
  background: var(--panel); color: var(--amber);
  border: 1px solid rgba(232, 161, 61, .24); border-radius: 7px;
  padding: 8px 14px; font-size: 15px; font-weight: 700;
  box-shadow: 0 8px 30px #0005; cursor: pointer;
}
select { appearance: none; padding-right: 34px; min-width: 120px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--amber) 50%),
    linear-gradient(135deg, var(--amber) 50%, transparent 50%);
  background-position: calc(100% - 17px) 18px, calc(100% - 11px) 18px;
  background-size: 6px 6px; background-repeat: no-repeat;
}
select:disabled { opacity: .45; cursor: not-allowed; }
.check {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 42px; padding: 8px 14px; border-radius: 7px;
  background: var(--panel); border: 1px solid rgba(232, 161, 61, .24);
  color: var(--amber); font-size: 14px; font-weight: 700; cursor: pointer;
}
.check input { accent-color: var(--amber); width: 17px; height: 17px; }

.panel {
  display: grid; gap: 10px; width: min(330px, 84vw);
  padding: 16px; border: 1px solid var(--line); border-radius: 10px;
  background: linear-gradient(135deg, rgba(20, 20, 18, .96), rgba(20, 20, 18, .82));
  box-shadow: 0 18px 50px #0008;
}
.panel { max-height: min(74vh, 640px); overflow-y: auto; }
.panel hr { border: 0; border-top: 1px solid var(--line); width: 100%; margin: 2px 0; }
.panel-head {
  margin: 0; font-size: 10px; letter-spacing: .16em; text-transform: uppercase;
  color: var(--amber); opacity: .8;
}
.field { display: grid; gap: 5px; font-size: 12px; color: var(--muted); letter-spacing: .05em; }
.field select { width: 100%; }
.field-row { display: flex; gap: 8px; align-items: flex-end; }
.field-row .grow { flex: 1; min-width: 0; }
.field-row .grow select { min-width: 0; }
.panel input[type="range"] {
  width: 100%; accent-color: var(--amber); height: 22px; cursor: pointer;
}
.tap {
  min-height: 38px; padding: 8px 12px; border-radius: 7px; cursor: pointer;
  border: 1px solid rgba(232, 161, 61, .3); background: var(--panel);
  color: var(--amber); font-weight: 800; font-size: 12px; letter-spacing: .1em;
}
.tap:active { background: var(--amber); color: #111; }

.gesture-guide {
  display: grid; gap: 6px; padding: 12px 15px;
  border: 1px solid var(--line); border-radius: 9px;
  background: linear-gradient(135deg, rgba(20, 20, 18, .94), rgba(20, 20, 18, .68));
  box-shadow: 0 16px 40px #0007;
}
.gesture-guide.hidden, .panel.hidden, .modal.hidden { display: none; }
.guide-row { display: flex; gap: 16px; align-items: center; min-width: 118px; }
.guide-row b { width: 34px; color: var(--amber); }
.guide-row span { font-size: 21px; }
.guide-row span.txt { font-size: 12px; color: var(--muted); letter-spacing: .04em; }

.meters {
  position: absolute; right: 16px; top: 16px; z-index: 4;
  color: var(--amber); text-align: right; font-size: 15px; font-weight: 700;
}
.volume-meter { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; margin-bottom: 10px; }
.volume-meter i {
  display: block; width: 104px; height: 10px; border-radius: 3px;
  background: #332c22; transition: background .08s, box-shadow .08s;
}
.volume-meter i.lit { background: var(--amber); box-shadow: 0 0 14px #e8a13d77; }

.record-bar {
  position: absolute; right: 16px; bottom: 16px; z-index: 6;
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end;
}
.record-bar button {
  min-height: 46px; padding: 10px 18px; border-radius: 8px; cursor: pointer;
  border: 1px solid rgba(232, 161, 61, .3); background: var(--panel);
  color: var(--amber); font-weight: 800; font-size: 15px;
}
#recordBtn.recording { background: #b0281f; border-color: #ff6a5e; color: #fff; }
#midiBtn { border-color: #4d8f6a; color: #7fe0aa; }

#countdown {
  position: absolute; inset: 0; z-index: 12;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; pointer-events: none; background: rgba(0, 0, 0, .25);
}
#countdown[hidden] { display: none; }
#countdownLabel {
  font-size: clamp(14px, 3vw, 22px); letter-spacing: .22em; text-transform: uppercase;
  color: var(--amber); text-shadow: 0 0 24px #000;
}
#countdownNum {
  font-size: clamp(80px, 22vw, 220px); font-weight: 900; color: #fff;
  line-height: 1; text-shadow: 0 0 40px #000;
}

#status {
  position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%);
  z-index: 4; text-align: center; pointer-events: none; text-shadow: 0 0 18px #000;
}
#chordDisplay { color: var(--amber); font-size: clamp(34px, 5vw, 64px); font-weight: 900; text-shadow: 0 0 22px #e8a13d66; }
#qualityDisplay { color: #e8d8bd; font-size: 13px; letter-spacing: .07em; margin-top: 2px; }

#helpButton {
  position: absolute; z-index: 7; left: 16px; bottom: 16px;
  width: 46px; height: 46px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--panel);
  color: var(--amber); font-size: 23px; cursor: pointer;
}

.modal {
  position: absolute; inset: 0; z-index: 20; display: grid; place-items: center;
  padding: 18px; background: #000c; backdrop-filter: blur(8px);
}
.help-card {
  position: relative; width: min(640px, 94vw); max-height: 86vh; overflow: auto;
  padding: 30px; border: 1px solid var(--amber); border-radius: 14px;
  background: #151411; box-shadow: 0 30px 100px #000;
}
.help-card h2 { margin: 6px 0 12px; font-size: 28px; color: var(--amber); }
.help-card h3, .eyebrow { color: var(--amber); }
.help-card p { color: #d9d1c6; }
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
#closeHelp { position: absolute; right: 16px; top: 12px; border: 0; background: none; color: var(--amber); font-size: 30px; cursor: pointer; }
.privacy { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 16px; }
.legend { display: grid; gap: 5px; margin: 10px 0 4px; }
.legend-row { display: flex; gap: 12px; align-items: baseline; font-size: 13px; color: #d9d1c6; }
.legend-row kbd { min-width: 84px; }

kbd {
  display: inline-block; padding: 2px 7px; border: 1px solid var(--line);
  border-bottom-width: 2px; border-radius: 5px; background: #201d18;
  color: var(--amber); font-size: 12px; font-weight: 700;
}

/* Non-blocking strip: the camera preview stays visible behind it. */
#loading {
  position: absolute; z-index: 16; left: 50%; top: 16px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
  padding: 9px 15px; border-radius: 999px;
  border: 1px solid rgba(232, 161, 61, .28); background: rgba(10, 9, 7, .88);
  font-size: 12px; color: var(--muted); white-space: nowrap;
}
#loading[hidden] { display: none; }
#loading .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); animation: pulse 1.1s ease-in-out infinite; }
#loading .label { color: var(--ink); }
#loading .bar { display: block; width: min(140px, 26vw); height: 5px; border-radius: 3px; background: #2a251d; overflow: hidden; }
#loading .bar i { display: block; height: 100%; width: 0; background: var(--amber); transition: width .2s linear; }
#loadingPct { color: var(--amber); font-weight: 700; min-width: 34px; text-align: right; }
@keyframes pulse { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }

#startOverlay {
  position: absolute; inset: 0; z-index: 15;
  display: grid; place-items: center; padding: 20px;
  background: #000a; backdrop-filter: blur(3px);
}
#startOverlay[hidden] { display: none; }
#startOverlay { overflow-y: auto; align-items: start; }
.start-card {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  width: min(620px, 94vw); text-align: center; margin: auto; padding: 24px 0;
}
.brand {
  margin: 0; font-size: clamp(15px, 3.2vw, 22px); font-weight: 900; letter-spacing: .16em;
  background: linear-gradient(135deg, #f7c469, var(--amber) 45%, #c0703a);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.hero-title {
  margin: 0; font-size: clamp(28px, 6.4vw, 50px); font-weight: 900;
  line-height: 1.08; color: #fff; letter-spacing: -.01em;
}
.hero-sub {
  margin: 0; max-width: 460px; font-size: 15px; line-height: 1.6; color: #cfc4b5;
}
.hero-sub b { color: var(--amber); }

.badges {
  display: flex; flex-wrap: wrap; gap: 7px; justify-content: center;
  list-style: none; margin: 2px 0 0; padding: 0;
}
.badges li {
  padding: 5px 11px; border-radius: 999px; font-size: 11.5px; letter-spacing: .05em;
  border: 1px solid rgba(232, 161, 61, .3); background: rgba(232, 161, 61, .07);
  color: var(--amber);
}

.hero-guide {
  width: 100%; margin-top: 6px; padding: 15px 18px; text-align: left;
  border: 1px solid rgba(232, 161, 61, .16); border-radius: 11px;
  background: rgba(16, 15, 12, .72);
}
.hero-guide-head {
  margin: 0 0 10px; font-size: 10px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--amber);
}
.hero-guide-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.hero-guide-grid b { display: block; color: #fff; font-size: 13px; margin-bottom: 3px; }
.hero-guide-grid span { font-size: 12px; line-height: 1.55; color: var(--muted); }

.scroll-cue {
  margin-top: 4px; font-size: 12.5px; color: var(--amber); text-decoration: none;
  letter-spacing: .08em; opacity: .85;
}
.scroll-cue:hover { text-decoration: underline; }

.start-actions { display: flex; flex-wrap: wrap; gap: 10px; width: 100%; justify-content: center; }
.start-actions button { flex: 1 1 240px; max-width: 300px; }
.start-actions button {
  min-height: 50px; padding: 12px 20px; border-radius: 9px; cursor: pointer;
  border: 1px solid rgba(232, 161, 61, .4); background: rgba(16, 16, 14, .9);
  color: var(--amber); font-size: 15px; font-weight: 700;
}
.start-actions button.primary { background: var(--amber); color: #14100a; border-color: var(--amber); }
.start-actions button:disabled { opacity: .5; cursor: progress; }
.start-note { margin: 0; font-size: 12px; color: var(--muted); line-height: 1.5; }
.start-note b { color: var(--amber); }

#toast {
  position: absolute; z-index: 30; left: 50%; top: 62px;
  transform: translateX(-50%) translateY(-30px);
  padding: 11px 16px; border: 1px solid #684818; border-radius: 8px;
  background: #151411; color: #f1c57f; opacity: 0; transition: .25s; pointer-events: none;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.keyboard-mode #overlay { opacity: .18; }

/* ── SEO content ──────────────────────────────────────────────────────── */

.page { background: linear-gradient(180deg, #070706, #100d09 40%, #14100a); padding: 48px 0 8px; }
.page-inner { max-width: 820px; margin: 0 auto; padding: 0 20px; }
.page h2 { font-size: clamp(22px, 4vw, 32px); color: var(--amber); margin: 0 0 10px; }
.page h3 { font-size: 19px; color: var(--amber); margin: 0 0 10px; }
.page h4 { font-size: 15px; color: var(--ink); margin: 22px 0 6px; }
.page p, .page li { color: #c6bcae; font-size: 15px; }
.lede { color: #ddd2c2 !important; font-size: 16px !important; margin-bottom: 28px; }
.card {
  border: 1px solid rgba(232, 161, 61, .12); border-radius: 12px;
  background: rgba(22, 20, 16, .55); padding: 24px; margin-bottom: 18px;
}
.card ol, .card ul { padding-left: 20px; margin: 10px 0; }
.card li { margin-bottom: 5px; }
.card code { background: #201d18; padding: 1px 6px; border-radius: 4px; color: var(--amber); font-size: 13px; }
.note { border-left: 2px solid var(--amber-dim); padding-left: 12px; font-size: 14px !important; }

.page table { width: 100%; border-collapse: collapse; font-size: 14px; margin: 8px 0 4px; display: block; overflow-x: auto; }
.page th {
  text-align: left; padding: 8px 10px; color: var(--amber); font-size: 11px;
  letter-spacing: .08em; text-transform: uppercase;
  border-bottom: 1px solid rgba(232, 161, 61, .22); background: rgba(232, 161, 61, .04);
  white-space: nowrap;
}
.page td { padding: 7px 10px; color: #cfc4b5; border-bottom: 1px solid rgba(255, 255, 255, .05); white-space: nowrap; }

details { border-bottom: 1px solid rgba(255, 255, 255, .06); padding: 12px 0; }
details summary { cursor: pointer; font-weight: 700; color: var(--ink); list-style: none; }
details summary::before { content: '▸ '; color: var(--amber); }
details[open] summary::before { content: '▾ '; }
details p { margin: 10px 0 0; font-size: 14px; }

.page a { color: var(--amber); }
.site-footer { border-top: 1px solid rgba(232, 161, 61, .1); margin-top: 26px; padding: 24px 0 40px; text-align: center; }
.site-footer p { font-size: 13px; color: #8d8375; }

@media (max-width: 640px) {
  /* Keep the folded stack inside the viewport instead of running off it. */
  .controls { top: 10px; left: 10px; right: 10px; gap: 7px; }
  .toolbar-body { width: 100%; }
  .control-row { width: 100%; }
  .control-row .select-wrap { flex: 1 1 46%; }
  .control-row select { width: 100%; }
  .panel { width: 100%; }
  select, .controls button, .check { min-height: 38px; font-size: 13px; padding: 6px 11px; }
  select { padding-right: 30px; background-position: calc(100% - 15px) 16px, calc(100% - 9px) 16px; min-width: 104px; }
  .meters { top: 10px; right: 10px; font-size: 12px; }
  .volume-meter i { width: 62px; height: 7px; }
  .help-grid { grid-template-columns: 1fr; }
  .help-card { padding: 24px 18px; }
  #helpButton { left: 10px; bottom: 10px; width: 40px; height: 40px; font-size: 20px; }
  .record-bar { right: 10px; bottom: 10px; }
  .record-bar button { min-height: 40px; padding: 8px 13px; font-size: 13px; }
  #status { bottom: 66px; }
  .card { padding: 18px; }
  .page { padding-top: 32px; }
  .hero-guide-grid { grid-template-columns: 1fr; gap: 12px; }
  .start-actions button { flex: 1 1 100%; max-width: none; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
