:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef0f6;
  --text: #1c1f2a;
  --muted: #6b7184;
  --border: #dde1ea;
  --accent: #4f6bed;
  --accent-text: #ffffff;
  --danger: #e5484d;
  --success: #30a46c;
  --warn: #f5a524;
  --shadow: 0 1px 3px rgba(20, 24, 40, .08), 0 4px 16px rgba(20, 24, 40, .06);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12141b;
    --surface: #1b1e28;
    --surface-2: #252937;
    --text: #e8eaf2;
    --muted: #9399ad;
    --border: #2e3344;
    --accent: #7b91ff;
    --accent-text: #0d0f16;
    --danger: #ff6b6f;
    --success: #4cc38a;
    --warn: #ffc053;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12141b;
  --surface: #1b1e28;
  --surface-2: #252937;
  --text: #e8eaf2;
  --muted: #9399ad;
  --border: #2e3344;
  --accent: #7b91ff;
  --accent-text: #0d0f16;
  --danger: #ff6b6f;
  --success: #4cc38a;
  --warn: #ffc053;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-decoration: none; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { flex: 1; margin: 0; font-size: 18px; font-weight: 600; }
.topbar a { white-space: nowrap; }

main { max-width: 960px; margin: 0 auto; padding: 16px; }

.btn {
  font: inherit; font-size: 14px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
select {
  font: inherit; font-size: 14px; padding: 6px 10px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.stats {
  display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center;
  margin-bottom: 12px;
  font-variant-numeric: tabular-nums;
}
.stats .label { color: var(--muted); font-size: 13px; margin-right: 4px; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 12px 0; }

.stage { position: relative; margin: 0 auto; }
.overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  border-radius: var(--radius);
  text-align: center;
  font-size: 20px; font-weight: 600;
}
.overlay[hidden] { display: none; }
.overlay.cover { inset: -3px; border-radius: 0; background: var(--bg); cursor: pointer; z-index: 1; }
.overlay small { font-size: 14px; font-weight: 400; color: var(--muted); }

canvas { display: block; max-width: 100%; touch-action: none; }

.dpad {
  display: none;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(2, 56px);
  gap: 6px; justify-content: center; margin: 16px auto;
}
.dpad .btn { font-size: 22px; padding: 0; }
.dpad [data-dir="up"] { grid-column: 2; grid-row: 1; }
.dpad [data-dir="left"] { grid-column: 1; grid-row: 2; }
.dpad [data-dir="down"] { grid-column: 2; grid-row: 2; }
.dpad [data-dir="right"] { grid-column: 3; grid-row: 2; }
.touch-only { display: none; }
@media (pointer: coarse) {
  .dpad { display: grid; }
  .touch-only { display: flex; }
  .key-hint { display: none; }
}
.key-hint { color: var(--muted); font-size: 13px; }

/* Lobby */
.lobby-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}
.card {
  display: flex; flex-direction: column; gap: 4px;
  padding: 18px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--text);
  transition: transform .12s, border-color .12s;
}
.card:hover, .card:focus-visible { transform: translateY(-2px); border-color: var(--accent); outline: none; }
.card .icon { font-size: 36px; line-height: 1.2; }
.card .name { font-weight: 600; font-size: 17px; }
.card .desc { color: var(--muted); font-size: 13px; }
.card .ver { color: var(--muted); font-size: 11px; margin-top: auto; }

dialog.options {
  padding: 0; width: min(100% - 32px, 360px);
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
dialog.options::backdrop { background: rgba(0, 0, 0, .4); }
.options > div { display: grid; gap: 12px; padding: 16px; }
.options h2 { margin: 0; font-size: 18px; }
.options label { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; }
.options label:has(select:disabled) { opacity: .5; }
.options .btn.primary { justify-self: end; }

footer.version { text-align: center; color: var(--muted); font-size: 12px; padding: 8px 16px 16px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 10;
  max-width: calc(100% - 32px); padding: 8px 16px; border-radius: 8px;
  background: var(--text); color: var(--bg); font-size: 14px; box-shadow: var(--shadow);
}
.overlay.counting { background: transparent; font-size: 64px; text-shadow: 0 0 8px var(--bg); pointer-events: none; }

/* Replay: overlays and pause covers step aside so the board shows; the bar floats over the page */
.replaying .overlay { display: none; }
.replaying { padding-bottom: 80px; }
.replay-bar {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 5;
  display: flex; align-items: center; gap: 8px; width: min(100% - 32px, 480px); padding: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.replay-bar[hidden] { display: none; }
.replay-bar input { flex: 1; min-width: 0; accent-color: var(--accent); }
.replay-bar .btn { min-width: 44px; }
