:root {
  color-scheme: light;
  --bg: #f5f6fb;
  --surface: #ffffff;
  --surface-soft: #f0f2f9;
  --text: #101828;
  --muted: #667085;
  --line: #e4e7ec;
  --brand: #6a5cff;
  --brand-soft: #ece9ff;
  --accent: #12b981;
  --warn: #f79009;
  --danger: #f04438;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(16, 24, 40, 0.08);
}
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1117;
  --surface: #171a23;
  --surface-soft: #1f2330;
  --text: #f2f4f7;
  --muted: #98a2b3;
  --line: #262b38;
  --brand: #8b7cff;
  --brand-soft: #241f3f;
  --accent: #32d583;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
.app { display: flex; flex-direction: column; min-height: 100%; height: 100%; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { font-size: 22px; }
.brand-text { min-width: 0; }
.brand-text h1 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: .2px; }
.brand-text p { margin: 0; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.main { flex: 1; min-height: 0; display: flex; }
.btn {
  font: inherit; font-size: 13px; font-weight: 600; border-radius: 10px; padding: 8px 14px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer;
  transition: transform .06s ease, background .15s ease, border-color .15s ease;
}
.btn:hover { border-color: var(--brand); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.lobby { flex: 1; display: grid; place-items: center; padding: 24px; }
.lobby-card {
  width: min(460px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px;
}
.lobby-card h2 { margin: 0 0 6px; font-size: 18px; }
.muted { color: var(--muted); }
.lobby-card p.muted { margin: 0 0 16px; font-size: 13px; }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.field input, .guessbar input {
  width: 100%; font: inherit; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface-soft); color: var(--text);
}
.field input:focus, .guessbar input:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.lobby-actions { display: flex; gap: 10px; margin: 4px 0 14px; }
.lobby-actions .btn { flex: 1; }
.tips { margin: 0; padding-left: 18px; color: var(--muted); font-size: 12.5px; line-height: 1.7; }
.game { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 14px; padding: 14px; min-height: 0; }
.stage { display: flex; flex-direction: column; gap: 10px; min-width: 0; min-height: 0; }
.stage-head { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.pill { background: var(--brand-soft); color: var(--brand); border-radius: 999px; padding: 3px 10px; font-weight: 600; }
.timer { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 700; color: var(--brand); }
.canvas-wrap {
  position: relative; flex: 1; min-height: 220px; background: #fff; border-radius: var(--radius);
  border: 1px solid var(--line); overflow: hidden; box-shadow: var(--shadow);
}
html[data-theme="dark"] .canvas-wrap { background: #f7f8fb; }
#canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
#canvas.readonly { cursor: default; }
.overlay, .waiting {
  position: absolute; inset: 0; display: grid; place-content: center; gap: 6px; text-align: center;
  background: rgba(16, 24, 40, .72); color: #fff; padding: 18px; backdrop-filter: blur(2px);
}
.overlay .big { font-size: 26px; font-weight: 700; }
.overlay .sub { font-size: 13px; opacity: .85; }
.waiting { background: rgba(16, 24, 40, .45); font-size: 14px; }
.tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.swatches { display: flex; gap: 6px; }
.swatch { width: 22px; height: 22px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.swatch.active { border-color: var(--brand); }
.sizes { display: flex; gap: 6px; }
.size { width: 26px; height: 26px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; cursor: pointer; padding: 0; }
.size span { display: block; background: var(--text); border-radius: 50%; }
.size.active { border-color: var(--brand); }
.guessbar { display: flex; gap: 8px; }
.guessbar input { flex: 1; }
.side { display: flex; flex-direction: column; gap: 10px; min-height: 0; overflow: hidden; }
.word-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; text-align: center;
}
.word-card .label { font-size: 12px; color: var(--muted); }
.word-card .word { font-size: 22px; font-weight: 700; letter-spacing: 3px; margin-top: 4px; }
.word-card .hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px;
  display: flex; flex-direction: column; min-height: 0;
}
.panel h3 { margin: 0 0 8px; font-size: 13px; font-weight: 650; display: flex; justify-content: space-between; }
.players { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 190px; overflow: auto; }
.players li { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.players .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.players .dot.off { background: var(--line); }
.players .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players .tag { font-size: 11px; color: var(--brand); background: var(--brand-soft); border-radius: 6px; padding: 1px 6px; }
.players .score { font-variant-numeric: tabular-nums; font-weight: 650; }
.feed-panel { flex: 1; min-height: 120px; }
.feed { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; overflow: auto; font-size: 12.5px; flex: 1; }
.feed li { color: var(--muted); }
.feed li .who { color: var(--text); font-weight: 600; margin-right: 4px; }
.feed li.correct { color: var(--accent); font-weight: 600; }
.side-actions { display: flex; gap: 8px; }
.side-actions .btn { flex: 1; }
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: rgba(16, 24, 40, .92); color: #fff; padding: 9px 16px; border-radius: 999px; font-size: 13px; z-index: 40;
}
.immersive .game { position: fixed; inset: 0; z-index: 30; background: var(--bg); padding: 10px; }
.immersive .topbar { display: none; }
@media (max-width: 820px) {
  .game { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .side { max-height: 44vh; overflow: auto; }
  .players { max-height: 120px; }
}
