/* Ludo — dark UI from the design key (Tokens, die & board key@1x.png). */

:root {
  --bg: #171A26;
  --bg-2: #1C2030;
  --panel: #22263A;
  --panel-2: #2A2F42;
  --panel-3: #323852;
  --line: #343A52;
  --ink: #262B3A;
  --text: #F4F5F9;
  --muted: #A8AEC2;
  --dim: #6F7690;
  --ok: #34C77B;
  --warn: #F1B52E;
  --danger: #E5484D;
  --radius: 16px;
  --font-title: 'Space Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --font-head: 'Space Grotesk', 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --topbar: 56px;
  /* Non-zero only when opened from an iPhone Home Screen, where the page runs
     under the status bar (apple-mobile-web-app-status-bar-style). */
  --safe-top: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.5 var(--font-body);
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* ── top bar ─────────────────────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: calc(var(--topbar) + var(--safe-top));
  display: flex;
  align-items: center;
  gap: 14px;
  padding: var(--safe-top) 16px 0;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  background: rgba(23, 26, 38, 0.86);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid #22263A;
}
.brand {
  font: 700 22px/1 var(--font-title);
  color: var(--text);
  text-decoration: none;
  letter-spacing: 0.02em;
}
.topbar-room { display: flex; align-items: center; gap: 8px; }
.topbar-room .label { margin: 0; }
.room-chip {
  font: 700 15px/1 var(--font-title);
  letter-spacing: 0.14em;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px 6px 10px;
  cursor: pointer;
}
.room-chip:hover { background: var(--panel-2); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  display: inline-grid;
  place-items: center;
  font: 700 16px/1 var(--font-head);
  cursor: pointer;
  padding: 0;
}
.icon-btn:hover { background: var(--panel-2); }
.icon-btn svg { width: 18px; height: 18px; }

/* Full screen and the Leave icon are for phones; wider screens keep the text button. */
.phone-only { display: none; }
.leave-icon { color: #FFB4B6; }

/* ── shared bits ─────────────────────────────────────────────────────── */

main {
  max-width: 1320px;
  margin: 0 auto;
  padding: 20px 16px 40px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

.label {
  display: block;
  margin: 0 0 10px;
  font: 600 12px/1.3 var(--font-head);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.label-note { letter-spacing: 0.04em; text-transform: none; color: var(--dim); font-weight: 500; }
.hint { margin: 0; color: var(--muted); font-size: 13px; }
.hint.center { text-align: center; }

.card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 20px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font: 600 15px/1.1 var(--font-head);
  cursor: pointer;
  transition: background 0.15s, transform 0.08s, opacity 0.15s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--panel-3); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--text); color: var(--bg); border-color: transparent; }
.btn.primary:hover:not(:disabled) { background: #fff; }
.btn.ghost { background: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--panel); }
.btn.danger { color: #FFB4B6; }
.btn.small { min-height: 32px; padding: 6px 12px; font-size: 13px; border-radius: 10px; }
.btn.tiny { min-height: 28px; padding: 4px 10px; font-size: 12px; border-radius: 8px; }
.btn.wide { width: 100%; }

.input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 16px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
.input::placeholder { color: var(--dim); }
.input:focus { border-color: var(--muted); }
.input.code {
  width: 132px;
  flex: none;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.3em;
  font: 700 18px/1 var(--font-title);
  padding-left: 18px;
}
.input.code::placeholder { letter-spacing: 0.2em; }

/* token icon (rim, body, white centre — same proportions as the board tokens) */
.ptoken {
  --s: 28px;
  width: var(--s);
  height: var(--s);
  flex: none;
  border-radius: 50%;
  background: radial-gradient(circle closest-side, #fff 0 30%, var(--pc) 31% 81%, var(--pcd) 82% 100%);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.3);
}
.ptoken.big { --s: 46px; }
.ptoken.small { --s: 20px; }
.ptoken.ghosted { opacity: 0.28; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border-radius: 999px;
  padding: 6px 8px 6px 12px;
  font: 500 14px var(--font-head);
}
.chip .x {
  border: 0;
  background: var(--panel-2);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  line-height: 1;
  padding: 0;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.dot.off { background: var(--dim); }

.badge {
  display: inline-block;
  font: 600 11px/1.6 var(--font-head);
  letter-spacing: 0.04em;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--panel-3);
  color: var(--text);
  white-space: nowrap;
}
.badge.gold { background: var(--warn); color: var(--bg); }
.badge.muted { background: transparent; color: var(--muted); border: 1px solid var(--line); }

/* ── home ────────────────────────────────────────────────────────────── */

.home-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  gap: 48px;
  align-items: center;
  min-height: calc(100dvh - var(--topbar) - 80px);
}
.title {
  margin: 0;
  font: 700 clamp(64px, 10vw, 112px)/0.95 var(--font-title);
  letter-spacing: 0.02em;
}
.lede { color: var(--muted); font-size: 18px; max-width: 34ch; margin: 16px 0 28px; }
.play-card { display: flex; flex-direction: column; gap: 12px; max-width: 440px; }
.play-card .label { margin-bottom: -4px; }
.invite-banner {
  background: var(--bg-2);
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  color: var(--muted);
}
.invite-banner strong { font-family: var(--font-title); color: var(--text); letter-spacing: 0.12em; }
.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--dim);
  font-size: 13px;
  margin: 4px 0;
}
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.join-form { display: flex; gap: 8px; }
.join-form .btn { flex: 1; }
.status-line { margin: 0; min-height: 1.5em; color: var(--muted); font-size: 13px; text-align: center; }
.home-board { display: grid; place-items: center; }
.home-board svg { width: 100%; max-width: 600px; height: auto; }

.how { max-width: 860px; margin: 56px 0 0; }
.steps {
  list-style: none;
  padding: 0;
  margin: 0 0 32px;
  display: grid;
  gap: 14px;
  counter-reset: step;
}
.steps li {
  counter-increment: step;
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 14px;
  align-items: start;
  line-height: 1.55;
}
.steps li::before {
  content: counter(step);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--panel-2);
  display: grid;
  place-items: center;
  font: 600 13px/1 var(--font-head);
}
.fullscreen-steps { margin: 18px 0 4px; }
.key { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px 32px; margin-bottom: 8px; }
.key-item { display: grid; grid-template-columns: 52px 1fr; gap: 14px; align-items: center; }
.key-item svg { width: 52px; height: 52px; display: block; }
.key-item b { display: block; font: 700 16px/1.3 var(--font-head); margin-bottom: 2px; }
.key-item span { color: var(--muted); font-size: 14px; line-height: 1.4; }

/* ── lobby ───────────────────────────────────────────────────────────── */

.lobby-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(300px, 0.7fr);
  gap: 28px;
  align-items: start;
}
.lobby-main { display: flex; flex-direction: column; gap: 28px; min-width: 0; }
.lobby-main section { min-width: 0; }
.invite-card { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 28px; align-items: center; }
.big-code { font: 700 46px/1 var(--font-title); letter-spacing: 0.12em; }
.link-row { display: flex; gap: 8px; }
.input.link { flex: 1; min-width: 0; font-size: 14px; color: var(--muted); }
.invite-body .hint { margin-top: 8px; }

.seats { display: grid; grid-template-columns: repeat(var(--cols, 4), minmax(0, 1fr)); gap: 12px; }
.seat {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 168px;
  padding: 18px 12px 14px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 2px solid transparent;
  text-align: center;
}
.seat.mine { border-color: var(--pc); }
.seat-color { font: 700 16px/1.3 var(--font-head); margin-top: 8px; }
.seat-name { font-size: 13px; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat-name.taken { color: var(--text); font-weight: 500; }
.seat-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: auto; padding-top: 10px; }
.seat .seat-tag { position: absolute; top: 10px; right: 10px; }

.board-picker { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.board-opt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 4px 10px;
  border-radius: 14px;
  background: var(--panel);
  border: 2px solid transparent;
  color: var(--muted);
  font: 600 13px/1.2 var(--font-head);
  cursor: pointer;
}
.board-opt svg { width: 38px; height: 38px; }
.board-opt small { font: 500 11px var(--font-body); color: var(--dim); }
.board-opt[aria-checked='true'] { border-color: var(--text); color: var(--text); }
.board-opt:disabled { cursor: default; }
.board-opt:disabled:not([aria-checked='true']) { opacity: 0.55; }

.rules { display: grid; gap: 8px; }
.rule {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--panel);
}
.rule-text b { display: block; font: 600 15px/1.3 var(--font-head); }
.rule-text span { display: block; color: var(--muted); font-size: 13px; }
.switch {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 46px;
  height: 28px;
  margin: 0;
  border-radius: 999px;
  background: #3A4058;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
}
.switch::after {
  content: '';
  position: absolute;
  top: 4px;
  left: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}
.switch:checked { background: var(--ok); }
.switch:checked::after { transform: translateX(18px); }
.switch:disabled { cursor: default; opacity: 0.7; }
.segmented { display: inline-flex; flex: none; gap: 2px; padding: 3px; border-radius: 10px; background: var(--bg); }
.segmented button {
  min-width: 40px;
  padding: 6px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: 600 13px/1 var(--font-head);
  cursor: pointer;
}
.segmented button[aria-pressed='true'] { background: var(--panel-3); color: var(--text); }
.segmented button:disabled { cursor: default; }

.lobby-side { display: flex; flex-direction: column; gap: 14px; position: sticky; top: calc(var(--topbar) + 16px); }
.lobby-preview svg { width: 100%; height: auto; display: block; }

/* ── game ────────────────────────────────────────────────────────────── */

.game-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 22px;
  align-items: start;
}
.board-area { display: flex; justify-content: center; min-width: 0; }
.board-wrap {
  position: relative;
  width: min(100%, calc((100dvh - var(--topbar) - 44px) * var(--ar, 1)));
  aspect-ratio: var(--ar, 1);
}
.board-wrap svg { width: 100%; height: 100%; display: block; }
.game-side {
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: sticky;
  top: calc(var(--topbar) + 16px);
  height: calc(100dvh - var(--topbar) - 44px);
  min-height: 420px;
}

.turn-card {
  --pc: var(--line);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  padding: 18px 14px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 2px solid var(--pc);
  overflow: hidden;
  transition: border-color 0.3s;
}
.turn-text { width: 100%; min-width: 0; }
.turn-who { font: 700 18px/1.25 var(--font-head); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.turn-hint { color: var(--muted); font-size: 13px; margin-top: 2px; }
.turn-timer { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; }
.turn-timer span {
  display: block;
  height: 100%;
  background: var(--pc);
  transform-origin: left center;
  transform: scaleX(0);
}
.turn-timer.urgent span { background: var(--danger); }

.die {
  --pc: var(--line);
  position: relative;
  width: 64px;
  height: 64px;
  flex: none;
  padding: 9px;
  border: 0;
  border-radius: 14px;
  background: #fff;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  box-shadow: inset 0 -5px 0 #C9CDDA, 0 6px 16px rgba(0, 0, 0, 0.35);
  cursor: default;
}
.die .pip {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--bg);
  place-self: center;
  opacity: 0;
}
.die[data-v='1'] .p5,
.die[data-v='2'] :is(.p1, .p9),
.die[data-v='3'] :is(.p1, .p5, .p9),
.die[data-v='4'] :is(.p1, .p3, .p7, .p9),
.die[data-v='5'] :is(.p1, .p3, .p5, .p7, .p9),
.die[data-v='6'] :is(.p1, .p3, .p4, .p6, .p7, .p9) { opacity: 1; }
.die:disabled { opacity: 1; }
.die.ready {
  cursor: pointer;
  box-shadow: inset 0 -5px 0 #C9CDDA, 0 0 0 4px var(--pc), 0 10px 24px rgba(0, 0, 0, 0.45);
  animation: nudge 1.4s ease-in-out infinite;
}
.die.rolling { animation: tumble 0.42s ease-in-out infinite; }
.die-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font: 700 12px var(--font-head);
  letter-spacing: 0.12em;
  color: var(--dim);
}
@keyframes nudge { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@keyframes tumble {
  0% { transform: rotate(0) scale(1); }
  25% { transform: rotate(-16deg) scale(1.08) translateY(-4px); }
  50% { transform: rotate(10deg) scale(0.95); }
  75% { transform: rotate(-6deg) scale(1.05) translateY(-2px); }
  100% { transform: rotate(0) scale(1); }
}

.players { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.prow {
  --pc: var(--line);
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 12px;
  background: var(--panel);
  border: 2px solid transparent;
}
.prow.turn { border-color: var(--pc); }
.prow.finished { opacity: 0.8; }
.pname { min-width: 0; font: 600 15px/1.3 var(--font-head); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pname small { font: 500 12px var(--font-body); color: var(--muted); margin-left: 4px; }
.psub { display: flex; align-items: center; gap: 8px; margin-top: 3px; }
.phome { display: inline-flex; gap: 3px; }
.phome i { width: 8px; height: 8px; border-radius: 50%; background: #3A4058; }
.phome i.on { background: var(--pc); }
.pend { display: flex; align-items: center; gap: 6px; }

.feed {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  min-height: 0;
}
.feed-slot { min-height: 0; display: flex; flex-direction: column; }
.game-side .feed-slot { flex: 1 1 auto; }
.game-side .feed { flex: 1 1 auto; }
.feed-list {
  list-style: none;
  margin: 0;
  padding: 0 4px 0 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 110px;
  max-height: 260px;
  font-size: 14px;
  overscroll-behavior: contain;
}
.game-side .feed-list { flex: 1 1 auto; max-height: none; }
.msg { line-height: 1.4; overflow-wrap: anywhere; }
.msg b { font: 600 14px var(--font-head); color: var(--pc, var(--text)); margin-right: 4px; }
.msg.system, .msg.event { color: var(--muted); font-size: 13px; }
.msg.event { padding-left: 10px; border-left: 2px solid var(--pc, var(--line)); }
.reactions { display: flex; flex-wrap: wrap; gap: 2px; }
.reactions button {
  border: 0;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  padding: 5px 6px;
  border-radius: 8px;
  cursor: pointer;
}
.reactions button:hover { background: var(--panel-2); }
.chat-form { display: flex; gap: 8px; }
.chat-form .input { flex: 1; min-width: 0; padding: 9px 12px; font-size: 15px; }
.chat-form .btn { min-height: 40px; }

/* ── board (SVG) ─────────────────────────────────────────────────────── */

svg.board {
  overflow: visible;
  filter: drop-shadow(0 16px 26px rgba(0, 0, 0, 0.45));
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.board .home-text { font: 700 30px var(--font-head); letter-spacing: 3px; fill: var(--ink); }
.board .halo { fill: none; stroke: #fff; stroke-width: 0.11; opacity: 0; pointer-events: none; }
.board .halo.on { animation: halo 1.3s ease-in-out infinite; }
.board .token .tk-ring { fill: none; stroke: #fff; stroke-width: 0.08; stroke-dasharray: 0.24 0.14; opacity: 0; }
.board .token.movable { cursor: pointer; }
.board .token.movable .tk-ring { opacity: 1; animation: ring-spin 1.1s linear infinite; }
.board .token.movable .tk-body { animation: bob 0.85s ease-in-out infinite; }
.board .token.dim { opacity: 0.55; }
.board .token:focus { outline: none; }
.board .token:focus-visible .tk-ring { opacity: 1; stroke: #F1B52E; }
.board .ghost { fill: none; stroke-width: 0.08; stroke-dasharray: 0.18 0.12; pointer-events: none; }
.board .float text { animation: float-up 1.9s ease-out forwards; transform-box: fill-box; transform-origin: center; }
@keyframes halo { 0%, 100% { opacity: 0.2; } 50% { opacity: 0.95; } }
@keyframes ring-spin { to { stroke-dashoffset: -0.76; } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-0.09px); } }
@keyframes float-up {
  0% { transform: translateY(20px) scale(0.6); opacity: 0; }
  14% { transform: translateY(0) scale(1.15); opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translateY(-120px) scale(1); opacity: 0; }
}

/* ── dialogs, toasts, banners ────────────────────────────────────────── */

.modal, .overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(10, 12, 20, 0.66);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.overlay { z-index: 70; }
.modal-card {
  position: relative;
  width: min(460px, 100%);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: 26px 24px 22px;
  border-radius: 20px;
  background: var(--panel);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
  animation: pop-in 0.22s ease-out;
}
.modal-card.wide { width: min(680px, 100%); }
.modal-card .close { position: absolute; top: 14px; right: 14px; }
.modal-title { margin: 0 0 18px; padding-right: 40px; font: 700 24px/1.2 var(--font-head); }
.modal-card .label { margin-top: 22px; }
.modal-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.ranking { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.ranking li {
  display: grid;
  grid-template-columns: 36px auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--bg-2);
}
.ranking .place { font: 700 15px var(--font-title); color: var(--muted); }
.ranking li:first-child { background: linear-gradient(90deg, rgba(241, 181, 46, 0.18), var(--bg-2)); }
.ranking li:first-child .place { color: var(--warn); }
.ranking .rname { font: 600 16px var(--font-head); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking .rstat { color: var(--muted); font-size: 13px; text-align: right; }
.rule-list { margin: 0; padding-left: 18px; color: var(--muted); display: grid; gap: 4px; }

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 80;
  display: grid;
  gap: 8px;
  width: min(420px, calc(100% - 32px));
  pointer-events: none;
}
.toast {
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font: 600 14px/1.35 var(--font-head);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
  animation: toast-in 0.22s ease-out;
}
.toast.error { background: var(--danger); color: #fff; }
.toast.out { opacity: 0; transform: translateY(6px); transition: 0.25s; }

.conn-banner {
  position: fixed;
  top: calc(var(--topbar) + var(--safe-top) + 10px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--warn);
  color: var(--bg);
  font: 600 13px var(--font-head);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 90; overflow: hidden; }
.confetti i {
  position: absolute;
  top: -20px;
  width: 9px;
  height: 14px;
  border-radius: 2px;
  animation: fall linear forwards;
}
@keyframes fall { to { transform: translate3d(var(--dx), 110vh, 0) rotate(var(--rot)); } }
@keyframes pop-in { from { transform: scale(0.96); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.noscript { text-align: center; padding: 40px; color: var(--muted); }

/* ── small screens ───────────────────────────────────────────────────── */

@media (max-width: 1080px) {
  .game-grid { grid-template-columns: minmax(0, 1fr) 300px; }
}

@media (max-width: 900px) {
  :root { --topbar: 52px; }
  main { padding-top: 14px; }
  .home-grid { grid-template-columns: 1fr; gap: 28px; min-height: 0; }
  .home-board svg { max-width: 420px; }
  .lede { font-size: 16px; margin-bottom: 20px; }
  .key { grid-template-columns: 1fr; }
  .how { margin-top: 36px; }

  /* Phones: seats, then the start/waiting area and chat, then the settings. */
  .lobby-grid { display: flex; flex-direction: column; gap: 26px; }
  .lobby-main { display: contents; }
  .invite-card { order: 1; }
  .seats-section { order: 2; }
  .spectators { order: 3; }
  .lobby-side { order: 4; position: static; }
  .board-section { order: 5; }
  .rules-section { order: 6; }
  .seats { grid-template-columns: repeat(min(var(--cols, 4), 4), minmax(0, 1fr)); }
  .lobby-preview { max-width: 380px; margin: 0 auto; width: 100%; }
  .invite-card { grid-template-columns: 1fr; gap: 14px; }
  .board-picker { gap: 6px; }

  .game-grid { grid-template-columns: 1fr; gap: 14px; }
  .board-wrap { width: min(100%, 640px); }
  /* Centre the board in the screen between the top bar and the turn card
     (about 160px with its margin); players and chat follow below. */
  .board-area {
    align-items: center;
    min-height: calc(100dvh - var(--topbar) - var(--safe-top) - 160px - env(safe-area-inset-bottom) - 28px);
  }
  .game-side { position: static; height: auto; min-height: 0; }
  #screen-game { padding-bottom: 176px; } /* room for the fixed turn card below */
  .turn-card {
    position: fixed;
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    bottom: calc(8px + env(safe-area-inset-bottom));
    z-index: 20;
    box-shadow: 0 12px 34px rgba(0, 0, 0, 0.55);
    background: var(--panel); /* solid: the player list scrolls underneath */
  }
  .game-side .feed-list { max-height: 240px; min-height: 120px; }
  .toasts { bottom: auto; top: calc(var(--topbar) + var(--safe-top) + 12px); }

  /* Top bar: every option as an icon. */
  .topbar { gap: 10px; }
  .topbar-actions { gap: 6px; }
  .phone-only { display: inline-grid; }
  .desktop-only { display: none; }
}

@media (max-width: 520px) {
  .topbar { gap: 10px; }
  .topbar-room .label { display: none; }
  .big-code { font-size: 38px; }
  .link-row { flex-wrap: wrap; }
  .input.link { flex-basis: 100%; }
  .seats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .seat { min-height: 150px; }
  .board-opt small { display: none; }
  .rule { align-items: flex-start; flex-direction: column; gap: 10px; }
  .die { width: 58px; height: 58px; padding: 8px; }
  .die .pip { width: 10px; height: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
