:root {
  --bg: #F4F4F2;
  --surface: #FFFFFF;
  --line: #D6D6D1;
  --ink: #1B1B1A;
  --muted: #55554F;
  --faint: #A3A39E;
  --accent: #2457D6;
  --accent-soft: #E3EAFB;
  --accent-ink: #1A3FA0;
  --warn: #C25400;
  --warn-soft: #FBEADD;
  --warn-ink: #8A3A00;
  --ok: #1F8A4C;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

button { font: inherit; color: inherit; }
kbd {
  display: inline-block;
  min-width: 20px;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface);
  font: 600 11px Inter, system-ui, sans-serif;
  text-align: center;
}
.muted { color: var(--muted); }
.small { font-size: 13px; }
.warn { color: var(--warn); }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 12px 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; font-size: 17px; margin-right: 4px; }
.pill {
  padding: 5px 11px;
  border-radius: 999px;
  background: #ECECE8;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.pill-btn {
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.device { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.device .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.device.on .dot { background: var(--ok); }

.switch { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 36px; height: 20px; border-radius: 99px; background: #C9C9C4; position: relative; transition: background .15s; }
.switch .track::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: left .15s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { left: 19px; }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn {
  height: 38px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { border-color: #B5B5AF; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.icon-btn {
  width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface);
  display: flex; align-items: center; justify-content: center; color: var(--muted); cursor: pointer;
}
.settings-wrap { position: relative; }
.popover {
  position: absolute; right: 0; top: 46px; z-index: 30; width: 250px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px;
  box-shadow: 0 8px 30px rgba(0,0,0,.12);
  display: flex; flex-direction: column; gap: 4px;
}
.popover .row { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; font-size: 14px; cursor: pointer; }
.popover .row:hover { background: var(--bg); }
.link { border: 0; background: none; text-align: left; padding: 8px; font-size: 14px; font-weight: 600; cursor: pointer; border-radius: 8px; }
.link.danger { color: var(--warn-ink); }
.link:hover { background: var(--bg); }

/* ---------- Stage ---------- */
.stage {
  flex: 1;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 32px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.hud { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px; min-height: 52px; }
.combo { display: flex; align-items: baseline; gap: 8px; }
.combo span { font-size: 40px; font-weight: 900; color: var(--accent-ink); font-variant-numeric: tabular-nums; }
.combo small { font-size: 13px; font-weight: 700; color: var(--muted); }
.beats { display: flex; gap: 10px; align-items: center; }
.beats span { width: 12px; height: 12px; border-radius: 50%; background: var(--line); transition: transform .08s, background .08s; }
.beats span.on { background: var(--accent); transform: scale(1.35); }
.beats span:first-child.on { background: var(--accent-ink); transform: scale(1.6); }

.judge { justify-self: end; font-size: 22px; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
.judge.perfect { color: var(--accent); }
.judge.good { color: var(--ink); }
.judge.late, .judge.fixed, .judge.count { color: var(--muted); }
.judge.miss { color: var(--warn); }
.judge.pop { animation: pop .45s ease-out; }
@keyframes pop {
  0% { transform: scale(1.35); opacity: .3; }
  60% { transform: scale(.96); opacity: 1; }
  100% { transform: scale(1); }
}

/* ---------- Lane ---------- */
.lane {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px 0 4px;
  overflow: hidden;
}
.lane-caption {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 0 24px; font-size: 12px; font-weight: 600; color: var(--muted);
}
.waiting-note { color: var(--accent-ink); }
.staff { display: block; }
.staff .staff-lines line { stroke: var(--ink); stroke-width: 1.4; }
.staff .band { fill: var(--accent-soft); }
.lane.waiting .band { animation: breathe 1.2s ease-in-out infinite; }
@keyframes breathe {
  0%, 100% { fill: var(--accent-soft); }
  50% { fill: #CCD9F7; }
}
.staff .clef { font-family: 'Noto Music', 'Apple Symbols', serif; font-size: 62px; fill: var(--ink); dominant-baseline: alphabetic; }

.chord .head { fill: none; stroke: var(--ink); stroke-width: 2.4; }
.chord .acc { fill: none; stroke: var(--ink); stroke-linecap: butt; }
.chord .ledger { stroke: var(--ink); stroke-width: 1.4; }
.chord .bar { stroke: #C4C4BE; stroke-width: 1.2; }
.chord .name { font: 700 20px Inter, system-ui, sans-serif; fill: var(--ink); text-anchor: middle; }
.chord .name.unknown { fill: var(--faint); }
.chord .reason { font: 700 12px Inter, system-ui, sans-serif; fill: var(--muted); text-anchor: middle; }
.chord .reason.review { fill: var(--warn); }
.chord .verdict { font: 800 12px Inter, system-ui, sans-serif; letter-spacing: .08em; text-transform: uppercase; fill: var(--accent); text-anchor: middle; }
.chord.mistake .head { stroke: var(--warn); }
.chord.mistake .acc { stroke: var(--warn); }
.chord.hit .head { stroke: var(--accent); }
.chord.hit .acc { stroke: var(--accent); }
.chord.hit .name { fill: var(--accent); }
.chord.fixed .verdict, .chord.miss .verdict { fill: var(--warn); }
.chord.miss .head { stroke: var(--warn); }
.chord.done { opacity: .5; transition: opacity .5s; }

.legend { display: flex; flex-wrap: wrap; gap: 18px; font-size: 12px; font-weight: 600; color: var(--muted); padding: 0 4px; }
.legend b { font-weight: 800; color: var(--ink); }
.legend b.warn { color: var(--warn); }

/* ---------- Keyboard ---------- */
.kb {
  position: relative;
  display: flex;
  height: 130px;
  border-left: 1px solid #8E8E89;
  user-select: none;
  touch-action: none;
}
.key { cursor: pointer; }
.key.white {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  background: #fff;
  border: 1px solid #8E8E89;
  border-left: 0;
  border-top: 0;
  border-radius: 0 0 5px 5px;
}
.key.black {
  position: absolute;
  top: 0;
  height: 62%;
  background: #1E1E1C;
  border-radius: 0 0 4px 4px;
  z-index: 2;
}
.key .lbl { position: absolute; bottom: 6px; left: 0; right: 0; text-align: center; font-size: 10px; color: #8E8E89; pointer-events: none; }
.key.held { background: #8EA5DE; }
.key.good { background: var(--accent); }
.key.bad { background: var(--warn); }
.key.white.hint { background: #DCE5FA; box-shadow: inset 0 0 0 3px var(--accent); }
.key.black.hint { background: #7D97DA; }
.key.good .lbl, .key.bad .lbl { color: #fff; }

.keys-hint { margin: 0; font-size: 12px; color: var(--muted); text-align: center; line-height: 2; }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(244, 244, 242, .94);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.card {
  width: 100%;
  max-width: 620px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 40px;
  box-shadow: 0 20px 60px rgba(0,0,0,.08);
}
.start-card { text-align: center; }
.start-card h1 { margin: 18px 0 8px; font-size: 32px; letter-spacing: -.01em; }
.start-card h1.big { font-size: 40px; }
.start-card p { margin: 0 auto; max-width: 440px; color: var(--muted); font-size: 16px; line-height: 1.5; }
.piano-art { color: var(--ink); }
.status {
  display: inline-flex; align-items: center; gap: 10px; margin-top: 22px;
  padding: 9px 16px; border-radius: 999px; background: #ECECE8; font-size: 14px; color: var(--muted);
}
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; }
.dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 100% { opacity: .2; } 40% { opacity: 1; } }
.found {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 999px;
  background: #E6F3EB; color: #145C33; font-size: 14px; font-weight: 600;
}
.found .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.returning { margin-top: 18px !important; color: var(--accent-ink) !important; font-weight: 600; font-size: 14px !important; }
.alt { margin-top: 26px !important; font-size: 14px !important; }

.checkin h1 { margin: 0; font-size: 28px; letter-spacing: -.01em; }
.checkin #ciSub { margin: 8px 0 20px; font-size: 15px; line-height: 1.5; }
.ci-rows { border: 1px solid var(--line); border-radius: 14px; padding: 0 18px; }
.ci-row { display: flex; align-items: center; gap: 16px; padding: 13px 0; border-bottom: 1px solid #ECECE8; flex-wrap: wrap; }
.ci-row:last-child { border-bottom: 0; }
.ci-label { width: 110px; font-size: 13px; font-weight: 700; color: var(--muted); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 4px 9px; border-radius: 6px; font-size: 14px; font-weight: 700; }
.chip.new { background: var(--ink); color: #fff; }
.chip.solid { background: var(--accent-soft); color: var(--accent-ink); }
.chip.tricky { background: var(--warn-soft); color: var(--warn-ink); }
.checkin .small { margin: 16px 0 0; }
.actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.actions .btn { height: 48px; flex: 1 1 160px; font-size: 15px; }
.actions .btn.primary { flex-grow: 2; }

@media (max-width: 720px) {
  .topbar, .stage { padding-left: 16px; padding-right: 16px; }
  .card { padding: 28px 20px; }
  .kb { height: 100px; }
  .combo span { font-size: 30px; }
}
