:root {
  --bg: #1F2023;
  --raised: #2A2B2F;
  --line: #3A3B40;
  --text: #E8E6E1;
  --muted: #8E8D89;
  --blue: #4BA3E3;
  --green: #8FD694;
  --yellow: #F5C66B;
  --red: #FF6B6B;
  --magenta: #D78BE5;
  --cyan: #5FD3D9;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --head: 38px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.4;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }

.tile {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 12px 10px;
}

/* ---------- header ---------- */
.bar {
  flex: none;
  height: var(--head);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}
.bar h1 { margin: 0; font-size: 14px; font-weight: 600; color: var(--yellow); white-space: nowrap; }
.stats { display: flex; gap: 14px; margin: 0; }
.stats div { display: flex; gap: 6px; align-items: baseline; }
.stats dt { color: var(--muted); font-size: 11px; }
.stats dd { margin: 0; font-variant-numeric: tabular-nums; min-width: 2ch; text-align: right; }
#combo { color: var(--cyan); }
#best { color: var(--yellow); }

/* ---------- dance floor ---------- */
.floor {
  position: relative;
  flex: 1 1 auto;
  min-height: 120px;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: #2a2420;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.floor.live { cursor: pointer; }
#lane { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.judge {
  position: absolute;
  top: 26px;
  left: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
  pointer-events: none;
  text-shadow: 0 1px 0 #000;
  white-space: nowrap;
}
.judge.on { color: var(--green); }
.judge.early { color: var(--yellow); }
.judge.late { color: var(--magenta); }
.judge.miss { color: var(--red); }
.judge.stray { color: var(--muted); }
.judge.accent { color: var(--magenta); }

@media (prefers-reduced-motion: no-preference) {
  .judge.pop { animation: pop 0.45s ease-out both; transform-origin: left center; }
  @keyframes pop {
    0% { transform: translate(0, 4px) scale(0.9); opacity: 0.2; }
    25% { transform: translate(0, 0) scale(1.08); opacity: 1; }
    100% { transform: translate(0, -3px) scale(1); opacity: 0.85; }
  }
}

/* ---------- count strip ---------- */
.countline { flex: none; display: flex; flex-direction: column; gap: 5px; }
.pattern { margin: 0; min-height: 1.4em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pattern em { font-style: normal; color: var(--yellow); }
.pattern .next { color: var(--muted); }
.counts {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
}
.counts li {
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 4px;
  text-align: center;
  padding: 2px 0 3px;
  line-height: 1.2;
}
.counts b { display: block; font-weight: 600; color: var(--muted); }
.counts i { display: block; font-style: normal; font-size: 10px; color: var(--muted); min-height: 1.2em; }
.counts li.has b { color: var(--text); }
.counts li.rock i { color: var(--yellow); }
.counts li.replace i { color: var(--green); }
.counts li.triple i { color: var(--cyan); }
.counts li.accent b { color: var(--magenta); }
.counts li.now { border-color: var(--blue); background: #24313d; }
.counts li.now b { color: var(--blue); }

/* ---------- controls ---------- */
.controls { flex: none; display: flex; align-items: center; gap: 8px; }
.controls button, .panel button {
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 5px 10px;
  cursor: pointer;
}
.controls button:hover:not(:disabled), .panel button:hover { border-color: var(--muted); }
.controls button:disabled { opacity: 0.45; cursor: default; }
.hint { color: var(--muted); font-size: 11px; margin-left: auto; text-align: right; }
button:focus-visible, .tempo input:focus-visible + span { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ---------- panels ---------- */
.panel {
  position: absolute;
  left: 0;
  right: 0;
  top: var(--head);
  bottom: 0;
  z-index: 2;
  padding: 14px 16px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 10px;
  overflow: auto;
}
.panel[hidden] { display: none; }
.panel h2 { margin: 0; font-size: 15px; color: var(--yellow); font-weight: 600; }
.panel p { margin: 0; max-width: 62ch; }
.panel .small { color: var(--muted); font-size: 12px; }
.panel .big { font-size: 22px; color: var(--text); font-variant-numeric: tabular-nums; }
.panel .row { display: flex; flex-wrap: wrap; gap: 8px; }
.panel button.primary { background: #23384a; border-color: var(--blue); color: var(--text); padding: 6px 14px; }
kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 3px; padding: 0 4px; font: inherit; font-size: 12px; }

.tempo { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tempo legend { float: left; color: var(--muted); margin-right: 6px; padding: 0; }
.tempo label { position: relative; }
.tempo input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.tempo span {
  display: inline-block;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--raised);
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.tempo small { color: var(--muted); font-size: 11px; }
.tempo input:checked + span { border-color: var(--yellow); color: var(--yellow); }
.tempo input:checked + span small { color: var(--yellow); opacity: 0.8; }

/* ---------- small frames ---------- */
@media (max-width: 440px) {
  .stats { gap: 10px; }
  .stats dt { font-size: 10px; }
  .hint { display: none; }
  .counts i { font-size: 9px; }
}
@media (max-width: 380px) {
  .bar h1 { font-size: 13px; }
  .stats { gap: 8px; }
  .stats div { gap: 4px; }
}
@media (max-height: 380px) {
  .tile { gap: 6px; padding-bottom: 8px; }
  .panel { padding: 10px 14px; gap: 8px; }
}

.settings { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.check input { accent-color: var(--yellow); width: 15px; height: 15px; margin: 0; }
.check input:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.counts li.accent { border-color: rgba(215,139,229,0.55); }
