: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 {
    --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 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; }
