/* MusicBox Phase 0 — dark "recording studio" theme. */
:root {
  --bg: #121214;
  --bg-2: #18181b;
  --card: #1e1e22;
  --card-2: #26262b;
  --line: #34343b;
  --text: #ecebe6;
  --muted: #a3a29b;
  --accent: #f2b544;
  --accent-2: #e0892c;
  --accent-ink: #1a1408;
  --ok: #6fd39a;
  --warn: #f2b544;
  --err: #ff7a6b;
  --radius: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(1200px 500px at 15% -10%, rgba(242, 181, 68, 0.10), transparent 60%),
    radial-gradient(900px 400px at 100% 0%, rgba(224, 137, 44, 0.07), transparent 60%),
    linear-gradient(180deg, var(--bg-2), var(--bg) 40%);
  background-color: var(--bg);
  background-attachment: fixed;
}

.wrap { max-width: 1400px; margin: 0 auto; padding: 0 16px; }

/* Header */
.site-header { padding: 32px 0 16px; }
.site-header h1 {
  margin: 0;
  font-size: clamp(1.4rem, 2.6vw, 2.1rem);
  font-weight: 700;
  letter-spacing: -0.01em;
}
.brand {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.sep { color: var(--muted); font-weight: 400; }
.phase { color: var(--muted); font-weight: 500; font-size: 0.75em; }
.subtitle { margin: 6px 0 0; color: var(--muted); max-width: 70ch; }

/* Cards */
main { display: grid; gap: 20px; padding-bottom: 32px; }
.grid-2 { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 520px), 1fr)); }
.card {
  background: linear-gradient(180deg, var(--card-2), var(--card));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 12px 30px rgba(0, 0, 0, 0.35);
  min-width: 0;
}
.card h2 { margin: 0; font-size: 1.15rem; display: flex; align-items: center; gap: 10px; }
.card h3 { margin: 18px 0 8px; font-size: 0.95rem; font-weight: 600; color: var(--text); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.num {
  display: inline-grid; place-items: center;
  width: 26px; height: 26px; border-radius: 50%;
  background: rgba(242, 181, 68, 0.15); color: var(--accent);
  font-size: 0.85rem; font-weight: 700;
}
.intro { border-color: rgba(242, 181, 68, 0.35); }
.steps { margin: 8px 0 0; padding-left: 1.3em; display: grid; gap: 4px; }
.steps strong { color: var(--accent); font-weight: 600; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.mono { font-family: var(--mono); }
.label { display: block; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.message { padding: 12px 14px; border-radius: 10px; background: rgba(255, 122, 107, 0.12); border: 1px solid rgba(255, 122, 107, 0.4); color: #ffd3cc; }

/* Pills */
.pill { display: inline-block; padding: 4px 12px; border-radius: 999px; font-size: 0.82rem; font-weight: 600; border: 1px solid transparent; }
.pill-wait { background: rgba(163, 162, 155, 0.12); color: var(--muted); border-color: var(--line); }
.pill-ok { background: rgba(111, 211, 154, 0.14); color: var(--ok); border-color: rgba(111, 211, 154, 0.4); }
.pill-err { background: rgba(255, 122, 107, 0.14); color: var(--err); border-color: rgba(255, 122, 107, 0.4); }

/* Buttons */
.btn {
  font: inherit; font-size: 0.9rem; font-weight: 600;
  padding: 8px 16px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); color: var(--text); background: var(--card-2);
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:focus-visible, input:focus-visible, .report:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: linear-gradient(180deg, var(--accent), var(--accent-2)); color: var(--accent-ink); border-color: transparent; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.07); }
.btn-ghost { background: transparent; }
.btn-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Tables */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.data-table td { padding: 6px 8px; border-bottom: 1px solid rgba(52, 52, 59, 0.6); }
.log-scroll { max-height: 360px; overflow: auto; border-radius: 10px; }
.log-table td { font-family: var(--mono); font-size: 0.82rem; white-space: nowrap; }
.log-table thead th { position: sticky; top: 0; background: var(--card-2); }
.t-noteon { color: var(--accent); }
.t-noteoff { color: var(--muted); }
.t-cc { color: #8fc7ff; }
.t-pitchbend { color: #c9a3ff; }

/* Last note */
.last-note { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; flex-wrap: wrap; margin-bottom: 14px; }
.last-note-main { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.last-note-main .label { width: 100%; }
.last-note-es { font-size: clamp(2.6rem, 6vw, 4rem); font-weight: 800; line-height: 1; color: var(--accent); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.last-note-en { font-size: 1.4rem; color: var(--muted); font-weight: 600; }
.last-note-meta { display: flex; gap: 28px; flex-wrap: wrap; }
.big-num { font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.mid-num { font-size: 1.15rem; font-weight: 600; font-variant-numeric: tabular-nums; }

/* Keyboard */
.keyboard-scroll { overflow-x: auto; padding-bottom: 6px; }
.keyboard {
  position: relative;
  width: max(100%, 760px);
  aspect-ratio: 52 / 6.4;
  max-height: 220px;
  background: #0b0b0c;
  border-radius: 8px;
  padding-top: 6px;
  box-shadow: inset 0 6px 10px rgba(0, 0, 0, 0.6);
  border-top: 3px solid #3a1d1d;
  user-select: none;
}
.key { position: absolute; top: 0; --v: 0; transition: background 0.04s; }
.key.white {
  height: 100%;
  background: linear-gradient(180deg, #e9e6dc 0%, #f7f5ef 70%, #dedad0 100%);
  border: 1px solid #2a2a2a;
  border-top: none;
  border-radius: 0 0 4px 4px;
  z-index: 1;
}
.key.black {
  height: 63%;
  background: linear-gradient(180deg, #2b2b2e 0%, #111 85%, #232326 100%);
  border: 1px solid #000;
  border-top: none;
  border-radius: 0 0 3px 3px;
  z-index: 2;
  box-shadow: 0 3px 4px rgba(0, 0, 0, 0.5);
}
.key.white.on {
  background: linear-gradient(180deg,
    rgba(242, 181, 68, calc(0.35 + var(--v) * 0.65)) 0%,
    rgba(224, 137, 44, calc(0.35 + var(--v) * 0.65)) 100%), #f7f5ef;
  box-shadow: 0 0 calc(4px + var(--v) * 16px) rgba(242, 181, 68, 0.7);
}
.key.black.on {
  background: linear-gradient(180deg,
    rgba(242, 181, 68, calc(0.45 + var(--v) * 0.55)) 0%,
    rgba(224, 137, 44, calc(0.45 + var(--v) * 0.55)) 100%), #111;
  box-shadow: 0 0 calc(4px + var(--v) * 16px) rgba(242, 181, 68, 0.8);
}
.key-label {
  position: absolute; bottom: 4px; left: 0; right: 0;
  text-align: center; font-size: clamp(7px, 0.7vw, 10px); font-weight: 600;
  color: #6b675d; pointer-events: none;
}
.key.middle-c .key-label { color: #b06a10; }

/* Pedal */
.pedal { display: grid; gap: 12px; margin: 6px 0 10px; }
.pedal-row { display: grid; grid-template-columns: minmax(110px, 1fr) 3fr 48px 76px; align-items: center; gap: 12px; }
.pedal-name { font-weight: 600; }
.pedal-value { font-family: var(--mono); text-align: right; }
.meter { height: 12px; background: #0e0e10; border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.meter-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent-2), var(--accent)); transition: width 0.06s; }
.pedal-state { text-align: center; font-size: 0.8rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; }
.pedal-state.off { background: rgba(163, 162, 155, 0.12); color: var(--muted); }
.pedal-state.on { background: var(--accent); color: var(--accent-ink); }

/* Calibration */
.cal-stages { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin: 12px 0; }
.cal-stage { padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.18); }
.cal-stage.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.cal-stage.done { border-color: rgba(111, 211, 154, 0.5); }
.cal-stage-name { font-weight: 700; margin-bottom: 6px; }
.dots { display: flex; gap: 5px; margin-bottom: 6px; flex-wrap: wrap; }
.dot { width: 14px; height: 14px; border-radius: 50%; background: #0e0e10; border: 1px solid var(--line); }
.dot.filled { background: var(--accent); border-color: var(--accent); }
.cal-prompt { font-weight: 600; color: var(--accent); min-height: 1.5em; }
.cal-result { padding: 12px 14px; border-radius: 12px; background: rgba(242, 181, 68, 0.07); border: 1px solid rgba(242, 181, 68, 0.3); }
.cal-result ul { margin: 6px 0 0; padding-left: 1.2em; }
.cal-result .bad { color: var(--err); font-weight: 600; }
.cal-result .good { color: var(--ok); font-weight: 600; }

/* Histogram */
.histogram { display: grid; grid-template-columns: repeat(16, 1fr); gap: 4px; align-items: end; height: 160px; padding: 8px 0 0; }
.hbar { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; gap: 2px; min-width: 0; }
.hbar-fill { width: 100%; background: linear-gradient(180deg, var(--accent), var(--accent-2)); border-radius: 4px 4px 0 0; min-height: 1px; transition: height 0.15s; }
.hbar-count { font-size: 0.7rem; color: var(--text); font-variant-numeric: tabular-nums; }
.hbar-label { font-size: 0.62rem; color: var(--muted); white-space: nowrap; }

/* Stats */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.stat { padding: 10px 12px; border-radius: 10px; background: rgba(0, 0, 0, 0.2); border: 1px solid var(--line); }

/* Switch */
.toggle-row { margin-top: 16px; display: grid; gap: 4px; }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { width: 42px; height: 24px; border-radius: 999px; background: #0e0e10; border: 1px solid var(--line); position: relative; transition: background 0.15s; }
.switch-track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--muted); transition: transform 0.15s, background 0.15s; }
.switch input:checked + .switch-track { background: rgba(242, 181, 68, 0.3); border-color: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(18px); background: var(--accent); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Rhythm */
.rhythm-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 12px 0; }
.rhythm-controls input { width: 80px; font: inherit; padding: 7px 10px; border-radius: 10px; border: 1px solid var(--line); background: #0e0e10; color: var(--text); }
.beat-display { display: flex; align-items: baseline; gap: 14px; margin: 6px 0 12px; }
.beat-display .label { display: inline; }
.beat-count { font-size: 2.2rem; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; line-height: 1; }
.beat-count.pulse { animation: pulse 0.18s ease-out; }
@keyframes pulse { from { transform: scale(1.25); } to { transform: scale(1); } }
.rhythm-strip { position: relative; height: 44px; border-radius: 10px; background: #0e0e10; border: 1px solid var(--line); overflow: hidden; }
.strip-zone { position: absolute; top: 0; bottom: 0; left: 40%; width: 20%; background: rgba(111, 211, 154, 0.12); }
.strip-center { position: absolute; top: 0; bottom: 0; left: 50%; width: 1px; background: var(--ok); }
.strip-dot { position: absolute; top: 50%; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 6px rgba(242, 181, 68, 0.8); }
.strip-dot.out { background: var(--err); box-shadow: 0 0 6px rgba(255, 122, 107, 0.8); }
.strip-axis { display: flex; justify-content: space-between; margin: 4px 0 12px; }

/* Report */
.report {
  margin: 0; max-height: 420px; overflow: auto;
  padding: 14px; border-radius: 10px;
  background: #0b0b0c; border: 1px solid var(--line);
  font-family: var(--mono); font-size: 0.8rem; line-height: 1.45; color: #d8d4c8;
  white-space: pre-wrap; word-break: break-word;
}

.site-footer { padding: 8px 16px 32px; color: var(--muted); font-size: 0.8rem; }

@media (max-width: 640px) {
  .card { padding: 16px; }
  .pedal-row { grid-template-columns: 1fr 48px 70px; }
  .pedal-row .meter { grid-column: 1 / -1; grid-row: 2; }
  .hbar-label { display: none; }
}

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