:root {
  --bg: #101511; --panel: #18201a; --panel2: #1f2a22; --line: #2c3a30;
  --text: #efe9dc; --muted: #9aa597; --red: #d4433a; --green: #3aa45f; --cream: #f2e6c9;
  --gold: #e8b64c; --focus: #f2e6c9;
  --r: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { min-height: 100vh; font-size: 16px; line-height: 1.45; }
a { color: var(--cream); }
.muted { color: var(--muted); }
.center { text-align: center; }
[hidden] { display: none !important; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: #0c100d; position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; text-decoration: none; letter-spacing: .02em; }
nav { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
nav a { text-decoration: none; padding: 6px 10px; border-radius: 8px; color: var(--muted); }
nav a.active { color: var(--text); background: var(--panel2); }
.conn { background: var(--red); color: #fff; text-align: center; padding: 4px; font-size: 14px; }

main { max-width: 1100px; margin: 0 auto; padding: 18px 16px 120px; }
h1 { font-size: 1.5rem; margin: 0 0 14px; }
h2 { font-size: 1.1rem; margin: 0 0 10px; color: var(--cream); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; margin-bottom: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 760px) { .grid2 { grid-template-columns: 1fr; } }

label { display: block; font-size: 14px; color: var(--muted); margin: 10px 0 4px; }
input, select { width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: #0d120e; color: var(--text); font-size: 16px; }
input:focus, select:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); margin: 8px 0; }
.check input { width: auto; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > * { flex: 1 1 auto; }

button { font: inherit; cursor: pointer; border: 0; border-radius: 8px; padding: 10px 14px;
  background: var(--green); color: #07130b; font-weight: 650; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.secondary { background: var(--panel2); color: var(--text); border: 1px solid var(--line); }
button.danger { background: transparent; color: var(--red); border: 1px solid var(--red); }
button.ghost { background: transparent; color: var(--muted); padding: 6px 10px; }
button.ghost.on { color: var(--gold); }
.err { color: #ff8a80; min-height: 1.4em; margin: 8px 0 0; font-size: 14px; }

.auth { max-width: 420px; margin: 6vh auto; }
.tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.tabs button { flex: 1; background: var(--panel2); color: var(--muted); }
.tabs button.on { background: var(--cream); color: #1a1a1a; }

.games { list-style: none; padding: 0; margin: 0; }
.games li { display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 12px 0; border-bottom: 1px solid var(--line); }
.games li:last-child { border-bottom: 0; }
.games a { text-decoration: none; font-weight: 600; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--panel2); color: var(--muted); white-space: nowrap; }
.badge.playing { background: #173a24; color: #8fe0ab; }
.badge.lobby { background: #3a3117; color: var(--gold); }
.badge.turn { background: var(--red); color: #fff; }

.code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 2rem; letter-spacing: .2em;
  background: #0d120e; border: 1px dashed var(--gold); color: var(--gold); padding: 8px 14px; border-radius: 8px; display: inline-block; }
.token { font-family: ui-monospace, Menlo, Consolas, monospace; word-break: break-all; background: #0d120e;
  padding: 10px; border-radius: 8px; border: 1px solid var(--gold); color: var(--gold); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #555; margin-right: 6px; }
.dot.on { background: #4cd17a; box-shadow: 0 0 6px #4cd17a; }

/* ---------- partie ---------- */
.gamehead { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.gamehead h1 { margin: 0; }
.layout { display: grid; grid-template-columns: 1fr 360px; gap: 16px; align-items: start; }
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }

.players { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.player { background: var(--panel); border: 2px solid var(--line); border-radius: var(--r); padding: 14px; position: relative; }
.player.cur { border-color: var(--green); box-shadow: 0 0 0 1px var(--green), 0 0 24px #3aa45f33; }
.player.win { border-color: var(--gold); }
.player .name { font-weight: 700; display: flex; justify-content: space-between; gap: 6px; }
.player .big { font-size: 3.6rem; font-weight: 800; line-height: 1.05; font-variant-numeric: tabular-nums; margin: 6px 0; }
.player .stats { color: var(--muted); font-size: 14px; display: flex; gap: 12px; flex-wrap: wrap; }
.legs { color: var(--gold); font-weight: 700; }

.visit { display: flex; gap: 8px; margin: 14px 0; }
.visit span { flex: 1; text-align: center; padding: 10px 0; border-radius: 8px; background: var(--panel2);
  font-weight: 700; font-size: 1.3rem; font-variant-numeric: tabular-nums; min-height: 2.2em; }
.visit span.empty { color: #3d4a40; }
.hint { color: var(--gold); font-weight: 650; }
.hint.bust { color: var(--red); }

.history { list-style: none; padding: 0; margin: 0; font-size: 14px; }
.history li { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid var(--line); gap: 8px; }
.history .pts { font-weight: 700; font-variant-numeric: tabular-nums; }

/* cricket */
.cricket { width: 100%; border-collapse: collapse; text-align: center; font-variant-numeric: tabular-nums; }
.cricket th, .cricket td { padding: 8px 4px; border-bottom: 1px solid var(--line); }
.cricket th { font-size: 14px; color: var(--muted); font-weight: 600; }
.cricket th.cur { color: var(--green); }
.cricket td.num { font-weight: 800; font-size: 1.25rem; color: var(--cream); }
.cricket td.num.dead { color: #4b564d; text-decoration: line-through; }
.mark { font-size: 1.5rem; font-weight: 800; line-height: 1; }
.mark.m3 { color: var(--green); }
.cricket tr.pts td { font-size: 1.6rem; font-weight: 800; border-bottom: 0; }

/* pavé de saisie */
.pad { margin-bottom: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; }
.mult { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 8px; }
.mult button { background: var(--panel2); color: var(--text); border: 1px solid var(--line); }
.mult button.on[data-m="1"] { background: var(--cream); color: #111; }
.mult button.on[data-m="2"] { background: var(--green); color: #07130b; }
.mult button.on[data-m="3"] { background: var(--red); color: #fff; }
.nums { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.nums button { background: #0d120e; color: var(--text); border: 1px solid var(--line); padding: 14px 0; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.nums button:active { background: var(--panel2); }
.padbar { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 6px; margin-top: 8px; }
.padbar button { padding: 12px 4px; }
.waiting { text-align: center; color: var(--muted); padding: 18px 8px; }

.banner { background: linear-gradient(90deg, #3a2f12, #18201a); border: 1px solid var(--gold); color: var(--gold);
  border-radius: var(--r); padding: 14px 16px; font-size: 1.2rem; font-weight: 700; margin-bottom: 14px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--cream); color: #111;
  padding: 10px 16px; border-radius: 8px; font-weight: 600; z-index: 10; max-width: 90vw; }
.toast.bad { background: var(--red); color: #fff; }

/* mode TV : tableau seul, en grand */
body.tv .top, body.tv .side, body.tv .gamehead .actions { display: none; }
body.tv main { max-width: none; padding: 2vh 3vw; }
body.tv .layout { grid-template-columns: 1fr; }
body.tv .player .big { font-size: 9vw; }
body.tv .player .name { font-size: 2.4vw; }
body.tv .player .stats { font-size: 1.6vw; }
body.tv .visit span { font-size: 3vw; }
body.tv .hint { font-size: 2.4vw; }
body.tv .cricket td, body.tv .cricket th { font-size: 2.4vw; padding: 1vh; }
body.tv .cricket .mark { font-size: 3vw; }
body.tv .exit-tv { display: block; }
.exit-tv { display: none; position: fixed; top: 8px; right: 8px; opacity: .4; }

@media (max-width: 600px) {
  .top { padding: 8px 10px; }
  .brand { font-size: 0; gap: 0; }
  nav { gap: 2px; flex-wrap: nowrap; }
  nav a, button.ghost { padding: 6px 8px; font-size: 15px; }
  main { padding: 12px 12px 40px; }
  .players { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
  .player { padding: 10px; }
  .player .big { font-size: 2.6rem; }
  .gamehead h1 { font-size: 1.3rem; }
  .nums button { padding: 12px 0; }
}
.upper { text-transform: uppercase; letter-spacing: .1em; }
