:root { color-scheme: dark; --bg:#0b0b12; --panel:#13131c; --cell:#ffffff08; --cell-given:#ffffff14; --cell-sel:#f5c45133; --cell-peer:#ffffff0e; --cell-same:#6b8afd33; --err:#ff4d4d; --accent:#f5c451; --accent2:#a78bfa; --text:#eaeaf0; --muted:#9a9aaa; --border:#ffffff14; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; color: var(--text); font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  background: radial-gradient(1200px 600px at 15% -10%, #2a1a4a 0%, transparent 60%), radial-gradient(900px 500px at 110% 20%, #0a3a4a 0%, transparent 55%), var(--bg); }
header { display: flex; align-items: baseline; gap: 1rem; padding: 1rem 1.5rem; border-bottom: 1px solid var(--border); }
header h1 { margin: 0; font-size: 1.3rem; letter-spacing: -.01em; }
a.home { color: var(--muted); text-decoration: none; font-size: .9rem; }
a.home:hover { color: #fff; }

/* ---------- Menu & lobby ---------- */
.card { max-width: 560px; margin: 2.5rem auto; padding: 1.75rem; background: linear-gradient(180deg, #ffffff0a, #ffffff05); border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 20px 60px -30px #000; }
.card h2 { margin: 0 0 .5rem; font-size: 1.3rem; letter-spacing: -.01em; }
.dim { opacity: .55; font-size: .9rem; }

label { display: flex; flex-direction: column; gap: .35rem; margin-bottom: .85rem; font-size: .78rem; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
input, select, button { font: inherit; padding: .65rem .85rem; border-radius: 10px; border: 1px solid var(--border); background: #ffffff0c; color: inherit; text-transform: none; letter-spacing: 0; }
input::placeholder { color: #fff4; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
button { background: var(--accent); color: #111; border: none; cursor: pointer; font-weight: 700; }
button:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-1px); }
button:active { transform: translateY(0); }
button { transition: transform .1s, filter .1s, background .1s; }
button:disabled { opacity: .4; cursor: default; transform: none; }
button.tiny { padding: .25rem .55rem; font-size: .75rem; background: #ffffff14; color: inherit; font-weight: 500; }
button.ghost { background: #ffffff10; color: inherit; }
button.ghost:hover:not(:disabled) { background: #ffffff18; }
button.danger { background: #ff4d6a; color: #fff; }
button.primary-lg { width: 100%; padding: .85rem; font-size: 1rem; margin-top: .5rem; }

.mode-picker { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; padding: .35rem; background: #00000040; border-radius: 12px; margin-bottom: 1.5rem; }
.mode-picker button { background: transparent; color: var(--muted); font-weight: 600; padding: .7rem; border-radius: 9px; }
.mode-picker button.active { background: linear-gradient(135deg, var(--accent), #f0a050); color: #111; box-shadow: 0 4px 14px -4px #f5c45155; }
.mode-picker button:hover:not(.active) { color: var(--text); background: #ffffff08; transform: none; }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: .3rem; padding: .25rem; background: #00000050; border-radius: 10px; margin-bottom: 1.25rem; }
.seg button { background: transparent; color: var(--muted); padding: .5rem; font-weight: 600; font-size: .9rem; border-radius: 7px; }
.seg button.active { background: #ffffff14; color: var(--text); }
.seg button:hover:not(.active) { color: var(--text); transform: none; }

.pane { display: flex; flex-direction: column; }

.msg { min-height: 1.2em; opacity: .9; margin: .75rem 0 0; font-size: .85rem; }
.msg.err { color: #ff9090; }

/* Lobby */
#lobby h2 { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
#lobby h2 #lRoom { font-family: ui-monospace, monospace; background: var(--accent); color: #111; padding: .15em .5em; border-radius: 6px; font-size: 1rem; letter-spacing: .15em; }
#lPlayers { list-style: none; padding: 0; margin: 1rem 0; display: flex; flex-direction: column; gap: .4rem; }
#lPlayers li { padding: .6rem .85rem; background: #ffffff08; border: 1px solid var(--border); border-radius: 10px; display: flex; justify-content: space-between; align-items: center; }
#lPlayers li .host { font-size: .65rem; background: var(--accent); color: #111; padding: .15rem .45rem; border-radius: 4px; margin-left: .4rem; font-weight: 700; letter-spacing: .08em; }

/* ---------- Game ---------- */
#game { padding: 1.25rem; max-width: 1100px; margin: 0 auto; }
.top { display: flex; justify-content: space-between; align-items: center; gap: .75rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.meta { display: flex; gap: 1.25rem; font-variant-numeric: tabular-nums; align-items: baseline; }
#timer { font-size: 1.6rem; font-weight: 700; letter-spacing: -.01em; }
#diffLabel, #mistakesLabel { font-size: .85rem; color: var(--muted); }
.ctrls { display: flex; gap: .4rem; flex-wrap: wrap; }
.ctrls button { padding: .55rem .75rem; background: #ffffff10; color: inherit; font-weight: 500; }
.ctrls button.active { background: var(--accent); color: #111; }
.kbd { font-size: .7rem; opacity: .6; margin-left: .3rem; padding: 0 .3rem; border: 1px solid #ffffff33; border-radius: 3px; }

.gameGrid { display: grid; grid-template-columns: 1fr 280px; gap: 1.75rem; align-items: start; }
@media (max-width: 900px) { .gameGrid { grid-template-columns: 1fr; } }

#boardWrap { display: grid; gap: 1rem; justify-items: center; }
#grid { width: min(92vw, 560px); aspect-ratio: 1/1; display: grid; grid-template-columns: repeat(9, 1fr); grid-template-rows: repeat(9, 1fr); background: #000; gap: 1px; padding: 2px; border-radius: 8px; box-shadow: 0 24px 60px -20px #000; }
.cell { position: relative; background: var(--cell); display: grid; place-items: center; font-size: clamp(1.3rem, 4.5vw, 2rem); font-weight: 500; cursor: pointer; user-select: none; transition: background .1s; }
.cell.given { background: var(--cell-given); font-weight: 700; }
.cell.peer { background: var(--cell-peer); }
.cell.same { background: var(--cell-same); }
.cell.sel { background: var(--cell-sel); outline: 2px solid var(--accent); outline-offset: -2px; z-index: 2; }
.cell.err { color: var(--err); }
.cell .notes { position: absolute; inset: 4%; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); font-size: clamp(.55rem, 1.4vw, .75rem); color: #ffffff77; pointer-events: none; }
.cell .notes span { display: grid; place-items: center; }
.cell[data-c="2"], .cell[data-c="5"] { border-right: 2px solid #000; }
.cell[data-r="2"], .cell[data-r="5"] { border-bottom: 2px solid #000; }

.pad { display: grid; grid-template-columns: repeat(9, 1fr); gap: .3rem; width: min(92vw, 560px); }
.pad button { padding: .75rem 0; font-size: 1.1rem; background: #ffffff10; color: inherit; font-weight: 600; }
.pad button:hover { background: #ffffff18; }

#race h3 { margin: 0 0 .6rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
#raceList { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .45rem; }
#raceList li { background: #ffffff08; border: 1px solid var(--border); border-radius: 10px; padding: .55rem .75rem; }
#raceList .name { display: flex; justify-content: space-between; align-items: center; font-size: .9rem; }
#raceList .rank { font-size: .72rem; background: var(--accent); color: #111; padding: .15rem .45rem; border-radius: 4px; font-weight: 700; }
#raceList .bar { height: 5px; background: #ffffff14; border-radius: 3px; margin-top: .4rem; overflow: hidden; }
#raceList .bar > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .3s; }
#raceList .quit { opacity: .4; }
#raceList .quit .name { text-decoration: line-through; }

#scoreboard { list-style: none; padding: 0; margin: 1rem 0; counter-reset: rank; }
#scoreboard li { padding: .8rem 1rem; background: #ffffff08; border: 1px solid var(--border); border-radius: 10px; margin-bottom: .45rem; display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
#scoreboard li::before { content: counter(rank); counter-increment: rank; font-size: 1.4rem; font-weight: 800; margin-right: .75rem; color: var(--accent); min-width: 1.5rem; }
#scoreboard li:nth-child(1)::before { color: #ffd166; }
#scoreboard li:nth-child(2)::before { color: #c0c0c0; }
#scoreboard li:nth-child(3)::before { color: #cd7f32; }
#scoreboard li.me { outline: 2px solid var(--accent); }
#scoreboard .time { opacity: .6; font-variant-numeric: tabular-nums; font-size: .85rem; }
