/* css/app.css — "Night practice room."
 * Ink-dark surface, brass accent, one teal counterpoint. Serif display faces,
 * system body text, monospace stimulus glyphs. System fonts only (offline).
 */

:root {
  --ink: #0C1017;
  --panel: #131926;
  --panel-2: #1A2233;
  --line: #232D42;
  --text: #E7EAF2;
  --muted: #8A93A8;
  --brass: #E0A458;
  --brass-soft: #E0A45833;
  --teal: #6FD3C7;
  --err: #E4636F;
  --ok: #7FC98F;
  --radius: 14px;
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: "SF Mono", SFMono-Regular, ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background:
    radial-gradient(1200px 600px at 70% -10%, #16203311, transparent),
    var(--ink);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ---------- shell ---------- */
.shell-head {
  display: flex; align-items: center; gap: 20px;
  padding: max(14px, env(safe-area-inset-top)) max(22px, env(safe-area-inset-right)) 14px max(22px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--ink) 88%, black);
  position: sticky; top: 0; z-index: 10;
}

.brand { display: flex; align-items: baseline; gap: 9px; text-decoration: none; color: var(--text); }
.brand-mark { color: var(--brass); font-size: 1.05rem; }
.brand-name { font-family: var(--font-display); font-size: 1.25rem; letter-spacing: 0.01em; }

.shell-nav { display: flex; gap: 4px; margin-left: auto; }
.nav-link {
  color: var(--muted); text-decoration: none; padding: 8px 12px;
  display: inline-flex; align-items: center; min-height: 44px;
  border-radius: 8px; font-size: 0.95rem;
}
.nav-link:hover { color: var(--text); background: var(--panel); }
.nav-link.active { color: var(--brass); }

.ai-toggle { font-size: 1.05rem; color: var(--teal); }

.shell-main { max-width: 980px; margin: 0 auto; padding: 26px max(22px, env(safe-area-inset-right)) max(90px, calc(70px + env(safe-area-inset-bottom))) max(22px, env(safe-area-inset-left)); }

.view-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; margin-bottom: 20px;
}
.view-head h2 { font-family: var(--font-display); font-weight: 500; font-size: 1.7rem; margin: 0; }

/* ---------- buttons & inputs ---------- */
.btn {
  font: inherit; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--line);
  padding: 8px 15px; border-radius: 10px; cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { border-color: var(--brass); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--brass); border-color: var(--brass); color: #1B1206; font-weight: 600; }
.btn-primary:hover { background: #EBB56C; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); border-color: var(--line); }
.btn-danger:hover { color: var(--err); border-color: var(--err); }
.btn-sm { padding: 4px 9px; font-size: 0.85rem; }
.btn-big { padding: 14px 34px; font-size: 1.15rem; border-radius: 12px; }

.input {
  font: inherit; color: var(--text);
  background: var(--ink); border: 1px solid var(--line);
  border-radius: 9px; padding: 8px 11px; width: 100%;
}
.input:focus { outline: none; border-color: var(--brass); box-shadow: 0 0 0 3px var(--brass-soft); }
.input.knob-flash { border-color: var(--teal); box-shadow: 0 0 0 3px #6FD3C733; }
.input.midi-armed { border-color: var(--teal); box-shadow: 0 0 0 3px #6FD3C755; }
.in-glyph { width: 4.5em; text-align: center; font-family: var(--font-mono); }
.in-midi { width: 6.5em; font-family: var(--font-mono); }

select.input { appearance: auto; }
input[type="range"] { accent-color: var(--brass); }

/* ---------- cards ---------- */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px;
  display: flex; flex-direction: column; gap: 10px;
}
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-title { font-family: var(--font-display); font-weight: 500; font-size: 1.15rem; margin: 0; }
.card-sub { margin: 0; font-size: 0.9rem; color: var(--muted); }
.card-actions { display: flex; gap: 8px; margin-top: auto; flex-wrap: wrap; }
.card-actions.center { justify-content: center; }

.pad-badge {
  font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.06em;
  color: var(--brass); border: 1px solid var(--brass);
  border-radius: 6px; padding: 2px 7px; white-space: nowrap;
}
.tag {
  font-size: 0.75rem; color: var(--muted);
  border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px;
  font-family: var(--font-mono);
}

.hint { font-size: 0.85rem; margin-top: 18px; }
.muted { color: var(--muted); }

/* ---------- forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 15px; margin-bottom: 18px; }
.form-grid.two { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.field { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-size: 0.84rem; color: var(--muted); }
.field-hint { font-size: 0.76rem; }

/* Clickable label → toggles a plain-language description (programEditor). */
.field-label-btn {
  background: none; border: 0; margin: 0; padding: 0; font: inherit;
  font-size: 0.84rem; color: var(--muted); cursor: pointer; text-align: left;
  display: inline-flex; align-items: center; gap: 5px;
}
.field-label-btn:hover { color: var(--text); }
.field-label-btn .info-dot { font-size: 0.82em; opacity: 0.5; }
.field-label-btn:hover .info-dot,
.field-label-btn.is-open .info-dot { opacity: 1; color: var(--brass); }
.field-help {
  display: none; margin-top: 3px; font-size: 0.78rem; line-height: 1.5;
  padding: 8px 11px; border-radius: 6px; border-left: 2px solid var(--brass);
  background: color-mix(in srgb, var(--brass) 9%, transparent);
}
.field-help.show { display: block; }
.form-row {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 16px; margin: 0 0 14px; display: flex; gap: 22px; flex-wrap: wrap;
}
.form-row legend { color: var(--muted); font-size: 0.84rem; padding: 0 6px; }
.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; }
.check input { accent-color: var(--brass); }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* ---------- panels (settings) ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px;
}
.panel-title { font-family: var(--font-display); font-weight: 500; margin: 0 0 14px; font-size: 1.15rem; }

.monitor {
  background: var(--ink); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; margin: 14px 0 0;
  font-family: var(--font-mono); font-size: 0.78rem; line-height: 1.55;
  color: var(--teal); min-height: 5em; max-height: 15em; overflow: auto;
  white-space: pre;
}
.pad-learn-row { display: flex; gap: 6px; flex-wrap: wrap; }

/* MIDI activity tester — the lamp flashes on every incoming message */
.midi-activity { display: flex; align-items: center; gap: 12px; margin: 12px 0 2px; }
.midi-led {
  width: 20px; height: 20px; border-radius: 50%;
  background: #2A303C; border: 1px solid var(--line); flex: 0 0 auto;
  transition: background 0.08s ease, box-shadow 0.08s ease;
}
.midi-led.lit { background: var(--ok); border-color: var(--ok); box-shadow: 0 0 14px var(--ok); }
.midi-led-text { font-family: var(--font-mono); font-size: 0.82rem; }

/* ---------- tables ---------- */
.set-table { width: 100%; border-collapse: collapse; margin-bottom: 14px; }
.set-table th {
  text-align: left; font-size: 0.78rem; font-weight: 600; color: var(--muted);
  padding: 6px 8px; border-bottom: 1px solid var(--line);
}
.set-table td { padding: 6px 8px; border-bottom: 1px solid color-mix(in srgb, var(--line) 55%, transparent); }

/* Clickable column headings → shared help row (set editor). */
.th-info {
  background: none; border: 0; margin: 0; padding: 0; font: inherit; color: inherit;
  cursor: pointer; display: inline-flex; align-items: center; gap: 5px;
}
.th-info:hover { color: var(--text); }
.th-info.th-active { color: var(--brass); }
.th-info .info-dot { font-size: 0.82em; opacity: 0.5; }
.th-info:hover .info-dot,
.th-info.th-active .info-dot { opacity: 1; color: var(--brass); }
.col-help-row td { border-bottom: 0; padding: 4px 8px 12px; }
.col-help {
  font-size: 0.8rem; line-height: 1.5; padding: 9px 12px; border-radius: 6px;
  border-left: 2px solid var(--brass); background: color-mix(in srgb, var(--brass) 9%, transparent);
}
.cell-learn { white-space: nowrap; }
.cell-learn .input { display: inline-block; width: auto; min-width: 5.5em; margin-right: 6px; }
.chord-toggle.is-on { color: var(--brass); border-color: var(--brass); background: var(--brass-soft); }
.input:disabled { opacity: 0.45; cursor: not-allowed; }
.stats-table td { font-size: 0.92rem; }

/* ---------- trainer ---------- */
.stage {
  min-height: 320px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px;
  padding: 26px 0 10px;
}
.stage-status { text-align: center; font-family: var(--font-mono); font-size: 0.85rem; min-height: 1.4em; }

.ready-card, .summary-card {
  text-align: center; display: flex; flex-direction: column; gap: 18px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 34px 44px;
}
.summary-card h3 { font-family: var(--font-display); font-weight: 500; font-size: 1.5rem; margin: 0; }
.summary-nums { display: flex; gap: 40px; }
.summary-nums .num { display: flex; flex-direction: column; gap: 2px; }
.summary-nums strong { font-family: var(--font-display); font-size: 2.1rem; color: var(--brass); }

.aperture-wrap { position: relative; width: 230px; height: 230px; }
.aperture { width: 100%; height: 100%; }
.aperture .arc-bg { fill: var(--panel); stroke: var(--line); stroke-width: 3; }
.aperture .arc-fg {
  fill: none; stroke: var(--brass); stroke-width: 3.5; stroke-linecap: round;
  transition: stroke-dashoffset 0.25s linear;
}
.aperture-glyph {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: 6rem; font-weight: 500; color: var(--text);
  user-select: none;
}
.aperture-glyph.count { color: var(--muted); font-size: 4rem; }

/* progress alternatives to the ring (which leaks sequence length) */
.present-plain { position: relative; width: 230px; height: 230px; }
.present-grid-wrap { display: flex; flex-direction: column; align-items: center; gap: 20px; }
.present-glyph-box { position: relative; width: 230px; height: 110px; }
.present-grid-wrap .aperture-glyph { font-size: 4rem; }
.present-grid { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.lamp-row { display: flex; gap: 16px; }
.lamp-group {
  display: flex; gap: 9px; padding: 7px;
  border: 1px solid var(--brass-soft); border-radius: 9px; background: rgba(224, 164, 88, 0.045);
}
.lamp {
  width: 26px; height: 26px; border-radius: 6px;
  background: #2A303C; border: 1px solid var(--line);
  transition: background 0.12s ease, box-shadow 0.12s ease;
}
.lamp.on { background: var(--brass); border-color: var(--brass); box-shadow: 0 0 12px var(--brass-soft); }

.stage-prompt { font-family: var(--font-display); font-size: 1.2rem; margin: 0; }

.slots { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; max-width: 100%; }
.slot {
  width: 58px; height: 72px; border: 1.5px solid var(--line); border-radius: 12px;
  background: var(--panel);
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: 2rem;
  transition: border-color 0.15s, background 0.15s;
}
.slot.filled { border-color: var(--brass); }
.slot.ok { border-color: var(--ok); background: #7FC98F14; }
.slot.bad { border-color: var(--err); background: #E4636F14; }

.verdict { font-family: var(--font-mono); font-size: 1rem; margin: 4px 0 0; }
.verdict.ok { color: var(--ok); }
.verdict.bad { color: var(--err); }

/* ---------- keypad ---------- */
.input-host { display: flex; flex-direction: column; align-items: center; gap: 10px; padding-bottom: 26px; }
.keypad { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.keypad-grid.phone { display: grid; grid-template-columns: repeat(3, 76px); gap: 10px; }
.keypad-grid.chips { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; max-width: 520px; }

.pad-key {
  font-family: var(--font-mono); font-size: 1.5rem; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px;
  height: 62px; cursor: pointer;
  transition: background 0.1s, border-color 0.1s, transform 0.04s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.pad-key.chip { min-width: 62px; padding: 0 16px; }
.pad-key:hover { border-color: var(--brass); }
.pad-key:active { background: var(--brass); color: #1B1206; transform: scale(0.96); }
.pad-hole { visibility: hidden; }
.pad-undo { font-size: 0.95rem; height: 44px; padding: 0 22px; color: var(--muted); }

/* ---------- piano ---------- */
/* align-items: safe center -> centered when the keyboard fits, but left-aligned
   when it's wider than the screen so ALL keys stay reachable by horizontal scroll
   (plain `center` clips the low keys off the left, unreachable — mobile bug). */
.piano { display: flex; flex-direction: column; align-items: safe center; gap: 12px; max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch; padding: 4px; }
.piano-row { position: relative; height: 150px; display: flex; }
.pk-white {
  width: 44px; height: 150px; border: 1px solid var(--line); border-radius: 0 0 8px 8px;
  background: #E9E4D8; cursor: pointer; position: relative; padding: 0;
  display: flex; align-items: flex-end; justify-content: center;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
/* “live” = a note the current set can answer; the rest are still playable. */
.pk-white.live { border-bottom: 6px solid var(--brass); }
.pk-white:active { background: #D8D0BE; }
.pk-white.live:active { background: var(--brass); }
.pk-black {
  position: absolute; top: 0; width: 28px; height: 92px; z-index: 2;
  background: #14181F; border: 1px solid #000; border-radius: 0 0 6px 6px;
  cursor: pointer; padding: 0;
  display: flex; align-items: flex-end; justify-content: center;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.pk-black.live { border-bottom: 6px solid var(--brass); }
.pk-black:active { background: #2A303C; }
.pk-black.live:active { background: var(--brass); }
.pk-glyph {
  font-family: var(--font-mono); font-size: 0.78rem; margin-bottom: 7px;
  color: #1B1206; pointer-events: none;
}
.pk-black .pk-glyph { color: var(--text); }

/* ---------- AI drawer ---------- */
.ai-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(360px, 92vw); z-index: 30;
  background: var(--panel); border-left: 1px solid var(--line);
  padding: 18px 20px; transform: translateX(102%);
  transition: transform 0.25s ease; overflow-y: auto;
  display: flex; flex-direction: column; gap: 14px;
}
.ai-drawer.open { transform: translateX(0); }
.ai-head { display: flex; align-items: center; justify-content: space-between; }
.ai-head strong { font-family: var(--font-display); font-size: 1.1rem; color: var(--teal); }
.ai-body { display: flex; flex-direction: column; gap: 12px; }
.ai-body textarea { resize: vertical; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px);
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 10px 18px; font-size: 0.92rem;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 40;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { border-color: var(--ok); }
.toast.err { border-color: var(--err); }

/* ---------- error-driven feedback (Feedback Lab) ---------- */
.lab-view .stage-prompt { color: var(--teal); }
.lab-view .stage { border-radius: var(--radius); }
.lab-training .stage { background: linear-gradient(180deg, color-mix(in srgb, var(--teal) 6%, transparent), transparent 60%); }
.lab-benchmark .stage { background: linear-gradient(180deg, color-mix(in srgb, var(--brass) 6%, transparent), transparent 60%); }

.lab-badge {
  display: inline-block; font-size: 0.82rem; padding: 5px 12px; border-radius: 999px;
  border: 1px solid var(--teal); color: var(--teal); background: color-mix(in srgb, var(--teal) 10%, transparent);
  margin-bottom: 12px;
}
.lab-benchmark .lab-badge { border-color: var(--brass); color: var(--brass); background: var(--brass-soft); }

.feedback-panel {
  width: min(560px, 96%); margin: 8px auto; text-align: left;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; display: flex; flex-direction: column; gap: 12px;
}
.fb-note { font-size: 0.82rem; margin: 0; }
.fb-head { display: flex; align-items: center; gap: 9px; font-size: 1.05rem; }
.fb-head.fb-exact { color: var(--ok); }
.fb-head.fb-mismatch { color: var(--brass); }
.fb-dot { font-size: 1.1rem; }
.fb-explain { margin: 0; color: var(--text); line-height: 1.5; }

.seq-grid { display: flex; flex-direction: column; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.seq-row { display: flex; align-items: stretch; gap: 6px; }
.seq-label { flex: 0 0 auto; width: 3.4em; align-self: center; font-size: 0.76rem; color: var(--muted); }
.seq-cell {
  position: relative; min-width: 2.1em; height: 2.1em; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); border-radius: 8px; border: 1px solid var(--line); background: var(--ink);
}
.seq-cell .seq-mark { position: absolute; top: -8px; right: -4px; font-size: 0.7rem; }
.seq-cell.ok { border-color: var(--teal); color: var(--teal); }
.seq-cell.exp { color: var(--muted); }
.seq-cell.mis { border-color: var(--brass); color: var(--brass); background: var(--brass-soft); }
.seq-cell.gap { border-style: dashed; color: var(--muted); }

.strategy-card {
  border: 1px solid var(--line); border-left: 3px solid var(--brass); border-radius: 8px;
  padding: 10px 13px; background: color-mix(in srgb, var(--brass) 7%, transparent);
}
.strategy-title { font-weight: 600; color: var(--brass); margin-bottom: 4px; }
.strategy-text { margin: 0; line-height: 1.5; font-size: 0.92rem; }
.fb-actions { display: flex; gap: 9px; flex-wrap: wrap; }

.lab-summary { text-align: left; margin: 4px 0 8px; display: flex; flex-direction: column; gap: 5px; }
.lab-summary p { margin: 0; }
.lab-summary .small { font-size: 0.8rem; }
.slot.locked { opacity: 0.6; }

/* Subtle pause control below the session + its Tab shortcut. */
.session-foot { text-align: center; margin-top: 12px; min-height: 1.6em; }
.pause-toggle { color: var(--muted); letter-spacing: 0.02em; }
.pause-toggle:hover { color: var(--text); }

/* Paused overlay — a non-blocking watermark over the stage. */
.paused .stage { position: relative; }
.paused .stage::after {
  content: '⏸ Paused'; position: absolute; inset: 0; z-index: 4; pointer-events: none;
  display: flex; align-items: center; justify-content: center; letter-spacing: 0.02em;
  font-size: 1.5rem; color: var(--text); border-radius: var(--radius);
  background: color-mix(in srgb, var(--ink) 64%, transparent);
}

/* Session note on the summary card + in stats. */
.note-field { text-align: left; margin: 10px auto 2px; width: min(560px, 96%); }
textarea.note-input { width: 100%; resize: vertical; min-height: 2.6em; line-height: 1.4; }
.stats-table .note-row td { padding: 0 8px 8px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 0.9rem; }

/* ---------- reward burst ---------- */
/* Full-screen celebratory particle overlay — never intercepts input, sits under
   toasts (40) but over everything else. Painted by js/ui/components/reward.js. */
.reward-canvas { position: fixed; inset: 0; pointer-events: none; z-index: 39; }

/* ---------- responsive & motion ---------- */
@media (max-width: 640px) {
  .shell-head { padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left)); gap: 10px; flex-wrap: wrap; }
  .shell-main { padding: 18px max(14px, env(safe-area-inset-right)) max(70px, calc(70px + env(safe-area-inset-bottom))) max(14px, env(safe-area-inset-left)); }
  .brand-name { font-size: 1.1rem; }
  .nav-link { padding: 8px 10px; font-size: 0.88rem; }
  .aperture-wrap { width: 190px; height: 190px; }
  .aperture-glyph { font-size: 4.6rem; }
  .slot { width: 46px; height: 60px; font-size: 1.6rem; }
  .keypad-grid.phone { grid-template-columns: repeat(3, 68px); }
  .summary-nums { gap: 24px; }
  .ready-card, .summary-card { padding: 26px 22px; }
}

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