:root {
  --bg: #0C0E16;
  --panel: #161a28;
  --panel-2: #1e2334;
  --text: #e8eaf2;
  --muted: #8a90a8;
  --accent: #6C5CE7;
  --accent-2: #8a7dff;
  --danger: #ff6b6b;
  --dot: #d9dcea;
  --line-free: #2a3044;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
.top {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 16px; max-width: 1100px; margin: 0 auto;
}
.top h1 { margin: 0; font-size: 20px; letter-spacing: .3px; display: flex; align-items: center; gap: 10px; flex: 1; }
.logo { width: 18px; height: 18px; border-radius: 4px; background: var(--accent); box-shadow: 0 0 0 3px var(--bg), 0 0 0 4px var(--accent-2); display: inline-block; }
.back { color: var(--muted); text-decoration: none; font-size: 14px; }
.back:hover { color: var(--text); }
.conn:empty { display: none; }
.conn { font-size: 12px; color: var(--muted); padding: 3px 9px; border-radius: 999px; background: var(--panel); }
.conn.online { color: #7ee2a8; }
.conn.connecting { color: #ffd166; }
.conn.offline { color: var(--danger); }
.conn.local { color: var(--muted); }

main { max-width: 1100px; margin: 0 auto; padding: 8px 16px 32px; }

.card {
  background: var(--panel); border-radius: var(--radius); padding: 22px; max-width: 520px; margin: 16px auto;
  box-shadow: 0 10px 40px rgba(0,0,0,.35);
}
.lead { margin: 0 0 18px; color: var(--muted); }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
label.check { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 14px; }
input[type="text"], input:not([type]), select, input[readonly] {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px; font: inherit; color: var(--text);
  background: var(--panel-2); border: 1px solid #2b3147; border-radius: 10px; outline: none;
}
input:focus, select:focus { border-color: var(--accent-2); }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
button {
  font: inherit; font-weight: 600; padding: 10px 16px; border-radius: 10px; border: 1px solid #2b3147;
  background: var(--panel-2); color: var(--text); cursor: pointer; transition: transform .05s ease, background .15s ease;
}
button:hover { background: #262c40; }
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-2); }
button[hidden] { display: none; }
.error { color: var(--danger); margin: 10px 0 0; font-size: 14px; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 2px; opacity: .85; }

.game { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
@media (max-width: 820px) { .game { grid-template-columns: 1fr; } .panel { order: 2; } }
.board-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; }
canvas#board { touch-action: manipulation; border-radius: var(--radius); background: var(--panel); max-width: 100%; display: block; }
.status { margin: 0; min-height: 24px; font-size: 16px; color: var(--muted); text-align: center; }
.status.mine { color: #fff; font-weight: 600; }
.status.warn { color: #ffd166; }

.panel { background: var(--panel); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.scores { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.scores li {
  display: grid; grid-template-columns: 14px 1fr auto auto; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 10px; background: var(--panel-2); border: 1px solid transparent;
}
.scores li.turn { border-color: var(--seat, var(--accent)); box-shadow: inset 0 0 0 1px var(--seat, var(--accent)); }
.scores li.empty { opacity: .55; }
.scores li.away .name { opacity: .7; }
.presence { font-size: 11px; padding: 2px 8px; border-radius: 999px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.presence::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; }
.presence.on { color: #7ee2a8; background: rgba(126,226,168,.1); }
.presence.on::before { background: #7ee2a8; box-shadow: 0 0 6px #7ee2a8; }
.presence.off { color: #ffd166; background: rgba(255,209,102,.1); }
.presence.off::before { background: #ffd166; }
.swatch { width: 14px; height: 14px; border-radius: 4px; background: var(--seat); }
.name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.name small { color: var(--muted); font-weight: 400; }
.score { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 18px; }
.share-row { display: flex; gap: 8px; }
.share-row input { margin: 0; font-size: 13px; }
.hint { margin: 6px 0 0; font-size: 12px; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #2a1f1f; color: #ffd9d9; border: 1px solid #5a2e2e; padding: 10px 16px; border-radius: 10px;
  font-size: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.4); z-index: 10;
}
.toast.info { background: #1f2436; color: var(--text); border-color: #2b3147; }

button.small { padding: 7px 12px; font-size: 14px; }
button.danger { color: var(--danger); border-color: #4a2a2a; }
button.danger:hover { background: #2a1f1f; }

/* away / parking */
.away { border: 1px solid #2b3147; border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.away summary { cursor: pointer; color: var(--muted); font-size: 13px; font-weight: 600; }
.away.alert { border-color: #5a4a1f; background: rgba(255,209,102,.06); }
.away.alert summary { color: #ffd166; }
.away p { margin: 8px 0 10px; color: var(--text); }
.away p b { font-variant-numeric: tabular-nums; }
.park-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; margin-bottom: 10px; }
.park-row label.inline { flex: 1; margin: 0; min-width: 160px; }
.park-row select { margin-top: 4px; padding: 7px 10px; }
.away .actions { margin-top: 0; }

/* your games (lobby) */
.my-games { margin-top: 22px; border-top: 1px solid #2b3147; padding-top: 16px; }
.my-games h2 { margin: 0 0 2px; font-size: 15px; }
.my-games ul { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.my-games li { display: flex; align-items: center; gap: 10px; background: var(--panel-2); border-radius: 10px; padding: 8px 10px; }
.mg-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.mg-main .code { font-size: 13px; color: var(--accent-2); }
.mg-names { font-weight: 600; margin-left: 6px; }
.mg-main small { color: var(--muted); font-size: 12px; }
.mg-actions { display: flex; gap: 6px; }

.code.big { font-size: 16px; color: var(--text); font-weight: 700; }

/* --- review scrubber ------------------------------------------------------ */
.review { display: flex; align-items: center; gap: 8px; width: 100%; max-width: 520px; }
.review button { padding: 6px 12px; font-size: 18px; line-height: 1; }
.review input[type="range"] { flex: 1; accent-color: var(--accent); margin: 0; }
.review-label { font-size: 13px; color: var(--muted); min-width: 90px; text-align: right; font-variant-numeric: tabular-nums; }

/* --- touch move pad -------------------------------------------------------- */
.pad { background: var(--panel); border: 1px solid #2b3147; border-radius: var(--radius); padding: 10px 14px 6px; display: flex; flex-direction: column; align-items: center; gap: 4px; box-shadow: 0 10px 40px rgba(0,0,0,.35); animation: pad-in .15s ease-out; }
.pad-head { display: flex; align-items: center; justify-content: space-between; width: 100%; font-size: 13px; color: var(--muted); }
.pad-head button { padding: 4px 10px; font-size: 13px; }
.pad svg { touch-action: manipulation; }
.pad .side .hit { fill: transparent; }
.pad .side .bar, .pad .side text { pointer-events: none; }
.pad .side.free .hit { cursor: pointer; }
.pad .side.free:active .bar, .pad .side.free .hit:focus-visible + .bar { opacity: .9 !important; }
.pad .side.free .bar { animation: pad-pulse 1.4s ease-in-out infinite; }
.pad .hint { margin: 0 0 4px; }
@keyframes pad-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes pad-pulse { 0%, 100% { opacity: .35; } 50% { opacity: .6; } }

/* --- win effects ------------------------------------------------------------ */
.scores li.won { border-color: var(--seat); box-shadow: 0 0 0 1px var(--seat), 0 0 18px color-mix(in srgb, var(--seat) 45%, transparent); animation: won-pop .5s ease-out; }
.status.win { animation: win-text .6s ease-out; }
@keyframes won-pop { 0% { transform: scale(.96); } 60% { transform: scale(1.03); } 100% { transform: none; } }
@keyframes win-text { 0% { transform: scale(.9); opacity: 0; } 100% { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .pad, .scores li.won, .status.win, .pad .side.free .bar { animation: none; }
}
