/* ==========================================================================
   Narde — site and board styles
   All colours are tokens below; components only reference variables.
   ========================================================================== */

:root {
  /* neutrals (warm stone) */
  --bg: #fafaf9;
  --surface: #ffffff;
  --surface-2: #f5f5f4;
  --ink: #1c1917;
  --ink-soft: #44403c;
  --muted: #78716c;
  --line: #e7e5e4;
  --line-strong: #d6d3d1;

  /* single accent: deep green ("play") */
  --accent: #15803d;
  --accent-strong: #166534;
  --accent-soft: #f0fdf4;
  --accent-border: #bbf7d0;
  --accent-ring: rgba(21, 128, 61, 0.2);
  --accent-ink: #ffffff;

  /* account (user chip in the header) */
  --user: #2563eb;
  --user-strong: #1d4ed8;

  /* status */
  --good: #15803d;
  --online: #22c55e;
  --pending: #f59e0b;
  --danger: #dc2626;
  --danger-strong: #b91c1c;
  --gold: #f2c14e;

  /* board */
  --board-frame: #292524;
  --board-bar: #1c1917;
  --board-tray: #1c1917;
  --board-felt: #f2ebe0;
  --point-a: #b85a3e;
  --point-b: #3d5a50;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(28, 25, 23, 0.04), 0 2px 8px rgba(28, 25, 23, 0.04);
  --shadow-lg: 0 24px 48px rgba(28, 25, 23, 0.18);
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: var(--font-body);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 var(--font-body);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; margin: 0 0 0.5em; }
h1 { font-size: clamp(1.7rem, 4vw, 2.4rem); letter-spacing: -0.03em; }
h2 { font-size: 1.2rem; }
p { margin: 0 0 1em; }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-strong); }
img, svg { max-width: 100%; }
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.center { text-align: center; }
.lead { font-size: 1.1rem; color: var(--ink-soft); }
.eyebrow { text-transform: uppercase; letter-spacing: 0.1em; font-size: 0.75rem; color: var(--accent); font-weight: 700; margin-bottom: 0.6em; }

/* -- header / footer ------------------------------------------------------ */

.site-header {
  background: var(--surface);
  color: var(--ink);
  padding-top: env(safe-area-inset-top, 0px);
  border-bottom: 1px solid var(--line);
}
.site-header__inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0.7rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.brand { display: inline-flex; align-items: center; gap: 0.5rem; color: var(--ink); text-decoration: none; font-size: 1.25rem; font-weight: 800; letter-spacing: -0.02em; }
.brand:hover { color: var(--ink); }
.brand__mark { width: 28px; height: 28px; }
.brand__light { fill: var(--surface); stroke: var(--ink); stroke-width: 1.6; }
.brand__dark { fill: var(--ink); stroke: var(--surface); stroke-width: 1.2; }
.site-nav { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
.site-nav a, .site-nav .link-button { color: var(--ink-soft); text-decoration: none; font-weight: 500; }
.site-nav a:hover, .site-nav .link-button:hover { color: var(--ink); }
.site-nav .button { color: var(--accent-ink); }
.site-nav > a:not(.button) { padding: 0.35rem 0; border-bottom: 2px solid transparent; }
.site-nav > a.is-current { color: var(--ink); border-bottom-color: var(--accent); }
.site-nav .nav-play { font-weight: 700; color: var(--ink); }
.nav-account { display: inline-flex; align-items: center; gap: 0.5rem; margin-left: 0.25rem; }
.site-nav .user-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  max-width: 14rem;
  min-height: 36px;
  padding: 0.25rem 0.85rem 0.25rem 0.25rem;
  border-radius: 999px;
  background: var(--user);
  color: #ffffff;
  font-weight: 600;
  transition: background 0.15s;
}
.site-nav .user-chip:hover { background: var(--user-strong); color: #ffffff; }
.user-chip__avatar { display: grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: 50%; background: rgba(255, 255, 255, 0.22); font-size: 0.85rem; font-weight: 700; }
.user-chip__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-nav button.nav-signout {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 36px;
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink-soft);
  font: 500 0.9rem/1.2 var(--font-body);
  box-shadow: none;
  cursor: pointer;
}
.site-nav button.nav-signout:hover { background: #fef2f2; border-color: #fecaca; color: var(--danger-strong); }
.nav-signout svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.site-main { flex: 1; width: 100%; max-width: 1280px; margin: 0 auto; padding: 1.75rem 1rem 3rem; }
.page-game .site-main { padding-top: 1rem; }

.site-footer { text-align: center; color: var(--muted); font-size: 0.85rem; padding: 1.5rem 1rem calc(1.5rem + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); }

/* -- building blocks --------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.4rem;
  margin-bottom: 1.25rem;
}
.narrow { max-width: 560px; margin-left: auto; margin-right: auto; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: 1.25rem; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 { margin-bottom: 1.25rem; }
.page-head { margin-bottom: 1.25rem; }

.button, button[type="submit"], .auth-card button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 44px;
  padding: 0.55rem 1.15rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  font: 600 1rem/1.2 var(--font-body);
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.1s;
  box-shadow: 0 1px 2px rgba(28, 25, 23, 0.08);
}
.button:hover, button[type="submit"]:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--accent-ink); }
.button:active, button[type="submit"]:active { transform: translateY(1px); }
.button:disabled { opacity: 0.55; cursor: progress; }
.button:focus-visible, a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--accent-ring); outline-offset: 2px; }
.button--ghost, button[type="submit"].button--ghost, .auth-card button.button--ghost { background: var(--surface); border-color: var(--line-strong); color: var(--ink); box-shadow: none; }
.button--ghost:hover, button[type="submit"].button--ghost:hover { background: var(--surface-2); border-color: var(--line-strong); color: var(--ink); }
.button--small { min-height: 36px; padding: 0.35rem 0.85rem; font-size: 0.9rem; }
.button--large { min-height: 52px; padding: 0.7rem 1.5rem; font-size: 1.05rem; }
.button--danger { background: var(--danger); border-color: var(--danger); }
.button--danger:hover { background: var(--danger-strong); border-color: var(--danger-strong); }

.link-button { background: none; border: 0; padding: 0; font: inherit; cursor: pointer; color: var(--accent); box-shadow: none; min-height: 0; }
.site-nav .link-button { min-height: 0; border: 0; background: none; box-shadow: none; padding: 0; font-weight: 500; }
.link-button.danger { color: var(--danger); text-decoration: underline; }
.inline-form { display: inline; margin: 0; }

input[type="text"], input[type="email"], input[type="password"], input[type="search"], select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); outline: none; }
textarea { min-height: 90px; }
label { font-weight: 600; font-size: 0.9rem; color: var(--ink-soft); }
.stack-form { display: flex; flex-direction: column; gap: 0.55rem; align-items: stretch; }
.stack-form .button, .stack-form button { align-self: flex-start; margin-top: 0.4rem; }
.ruleset-notes { margin: 0 0 0.3rem; padding-left: 1.1rem; font-size: 0.85rem; }

.badge { display: inline-block; padding: 0.1rem 0.55rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-soft); margin-left: 0.4rem; vertical-align: middle; }
.badge--active { background: var(--accent-soft); border-color: var(--accent-border); color: var(--accent-strong); }
.badge--waiting { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.badge--finished { background: var(--surface-2); border-color: var(--line); color: var(--ink-soft); }
.badge--cancelled { background: #fef2f2; border-color: #fecaca; color: #991b1b; }

.messages { max-width: 1280px; margin: 1rem auto 0; padding: 0 1rem; width: 100%; }
.message { padding: 0.75rem 1rem; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--line); margin-bottom: 0.5rem; transition: opacity 0.5s; }
.message--success { border-color: var(--accent-border); background: var(--accent-soft); }
.message--error { border-color: #fecaca; background: #fef2f2; }
.message.is-leaving { opacity: 0; }

.game-list { list-style: none; margin: 0; padding: 0; }
.game-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 0.75rem 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.game-row:first-child { border-top: 0; }
.row-actions { display: flex; gap: 0.5rem; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
.table th, .table td { text-align: left; padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th { color: var(--muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; }
.table tbody tr:last-child td { border-bottom: 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.9rem; margin-bottom: 1.25rem; }
.stat { display: flex; flex-direction: column; align-items: center; margin: 0; padding: 1rem; }
.stat__value { font-size: 1.8rem; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat__label { color: var(--muted); font-size: 0.85rem; }
.pager { display: flex; gap: 1rem; justify-content: center; margin-top: 1rem; }

.facts { display: grid; grid-template-columns: auto auto; justify-content: center; gap: 0.3rem 1rem; margin: 1rem 0 1.5rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; }

/* auth pages (django-allauth) */
.auth-card { max-width: 480px; margin: 1rem auto; }
.auth-card form { display: flex; flex-direction: column; gap: 0.6rem; }
.auth-card form p { margin: 0; display: flex; flex-direction: column; gap: 0.3rem; }
.auth-card ul { padding-left: 1.1rem; }
.auth-card .helptext, .auth-card .errorlist { font-size: 0.85rem; color: var(--muted); }
.auth-card .errorlist { color: var(--danger); }
.auth-card input[type="checkbox"] { width: auto; min-height: 0; }

/* -- landing page ---------------------------------------------------------- */

.hero { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 2.5rem; align-items: center; padding: 1.5rem 0 2.5rem; }
.hero__actions { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: 1.5rem; }
.hero__art svg { width: 100%; filter: drop-shadow(0 16px 32px rgba(28, 25, 23, 0.16)); }
.art-frame { fill: var(--board-frame); }
.art-felt { fill: var(--board-felt); }
.art-points polygon { fill: var(--point-a); }
.art-points--alt polygon { fill: var(--point-b); }
.art-light circle { fill: #fafaf9; stroke: #a8a29e; }
.art-dark circle { fill: var(--ink); stroke: #57534e; }
.art-dice rect { fill: #ffffff; stroke: var(--line-strong); }
.art-dice circle { fill: var(--ink); }

@media (max-width: 760px) {
  .hero { grid-template-columns: 1fr; padding-top: 0.5rem; }
  .hero__art { order: -1; max-width: 420px; }
}

/* ==========================================================================
   Game page
   ========================================================================== */

.game { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1.25rem; align-items: start; }
.game__board { display: flex; flex-direction: column; gap: 0.5rem; min-width: 0; }
.game__panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  position: sticky;
  top: 1rem;
}

.board-frame { position: relative; }
.board {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1000 / 760;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  border-radius: 16px;
  box-shadow: 0 12px 32px rgba(28, 25, 23, 0.16);
}

/* board surfaces */
.frame { fill: var(--board-frame); }
.felt { fill: var(--board-felt); }
.bar { fill: var(--board-bar); }
.tray { fill: var(--board-tray); }
.tray-divider { stroke: rgba(255, 255, 255, 0.12); stroke-width: 2; }
.pt--a { fill: var(--point-a); }
.pt--b { fill: var(--point-b); }
.home-zone { fill: rgba(21, 128, 61, 0.07); }
.home-zone--opponent { fill: rgba(28, 25, 23, 0.04); }
.direction { fill: none; stroke: rgba(28, 25, 23, 0.14); stroke-width: 3; stroke-dasharray: 2 10; stroke-linecap: round; }
.pt-num { fill: #a8a29e; font: 600 11px var(--font-body); text-anchor: middle; opacity: 0.75; }
.zone-label { fill: rgba(28, 25, 23, 0.38); font: 700 13px var(--font-body); letter-spacing: 0.12em; text-transform: uppercase; }

/* checkers */
.checker__body { stroke-width: 1.5; }
.checker--white .checker__body { stroke: #b8b0a2; }
.checker--black .checker__body { stroke: #0c0a09; }
.checker__ring { fill: none; stroke-width: 2; }
.checker--white .checker__ring { stroke: rgba(87, 83, 78, 0.22); }
.checker--black .checker__ring { stroke: rgba(255, 255, 255, 0.1); }
.checker__halo { fill: none; stroke: transparent; stroke-width: 4; pointer-events: none; }
.is-selectable .checker__halo { stroke: var(--gold); animation: halo-pulse 1.4s ease-in-out infinite; }
.is-selected .checker__halo { stroke: #ffe08a; stroke-width: 7; animation: none; }
.is-selected .checker__body { filter: brightness(1.08); }
.is-moving .checker__halo { stroke: rgba(255, 224, 138, 0.8); }
.checker-count { font: 700 19px var(--font-body); text-anchor: middle; pointer-events: none; }
.checker-count--white { fill: var(--ink-soft); }
.checker-count--black { fill: #fafaf9; }

@keyframes halo-pulse {
  0%, 100% { stroke-opacity: 0.35; }
  50% { stroke-opacity: 1; }
}

/* move hints */
.dest-tri { fill: rgba(150, 236, 160, 0.72); stroke: #e9ffe9; stroke-width: 2; pointer-events: none; }
.source-tri { fill: rgba(255, 208, 102, 0.42); pointer-events: none; }
.ghost { fill: rgba(255, 255, 255, 0.35); stroke: #fff; stroke-width: 2.5; stroke-dasharray: 6 5; pointer-events: none; animation: ghost-pulse 1.2s ease-in-out infinite; }
.tray-target { fill: rgba(126, 214, 141, 0.28); stroke: #9fe0a9; stroke-width: 2.5; stroke-dasharray: 7 6; pointer-events: none; animation: ghost-pulse 1.2s ease-in-out infinite; }
@keyframes ghost-pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}
.trail { fill: none; stroke: #f7d27a; stroke-width: 4; stroke-linecap: round; stroke-dasharray: 1 9; opacity: 0.95; pointer-events: none; }
.trail--faded { opacity: 0.4; }
.trail-arrow { fill: #f7d27a; }
.slab { stroke-width: 1.2; }
.slab--white { fill: #f1ede6; stroke: #b8b0a2; }
.slab--black { fill: #292524; stroke: #57534e; }

.hit { fill: transparent; }
.hit--active { cursor: pointer; }
.hit:focus { outline: none; }
.hit--active:focus-visible { stroke: var(--gold); stroke-width: 3; }

/* dice */
.die__body { fill: #ffffff; stroke: var(--line-strong); stroke-width: 1.5; filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.35)); }
.die__pip { fill: var(--ink); }
.die { transition: opacity 0.25s; }
.die.is-used { opacity: 0.3; }
.die.is-rolling .die__body { fill: #ffffff; }
.die.is-rolling { opacity: 0.92; }
.roll-hint { cursor: pointer; }
.roll-hint .die { animation: roll-hint 1.6s ease-in-out infinite; }
.roll-hint .die:last-child { animation-delay: 0.2s; }
.roll-hint:focus { outline: none; }
.roll-hint:focus-visible .die__body { stroke: var(--gold); stroke-width: 4; }
@keyframes roll-hint {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* player cards */
.player-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.55rem 0.9rem;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1.5px solid var(--line);
  min-height: 48px;
  transition: border-color 0.3s, box-shadow 0.3s, background 0.3s;
}
.player-card.is-active { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-ring); background: var(--accent-soft); }
.player-card { position: relative; overflow: hidden; }
.player-card__stats .is-warning { color: var(--danger); font-weight: 600; }

/* turn clock */
.clock {
  margin-left: auto;
  padding: 0.1rem 0.6rem;
  border-radius: 999px;
  background: var(--ink);
  color: #ffffff;
  font: 700 0.95rem/1.4 var(--font-body);
  font-variant-numeric: tabular-nums;
  order: 2;
}
.clock.is-low { background: var(--danger); animation: ghost-pulse 1s ease-in-out infinite; }
.clock-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 4px;
  background: var(--accent);
  transform-origin: left center;
  transition: transform 0.25s linear;
}
.clock-bar.is-low { background: var(--danger); }
.field-help { margin: 0; }
.player-card__identity { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.player-card__name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-card__you { font-weight: 400; color: var(--muted); }
.player-card__stats { display: flex; gap: 1rem; font-size: 0.85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.color-chip { width: 18px; height: 18px; border-radius: 50%; flex: none; border: 1.5px solid #b8b0a2; }
.color-chip--white { background: radial-gradient(circle at 40% 35%, #ffffff, #d6d0c4); }
.color-chip--black { background: radial-gradient(circle at 40% 35%, #57534e, #0c0a09); border-color: #0c0a09; }
.color-chip--none { background: var(--line); }
.presence { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.presence.is-online { background: var(--online); box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.18); }
.presence.is-offline { background: var(--line-strong); }

/* side panel */
.panel-row { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.connection { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; color: var(--muted); }
.connection__dot { width: 9px; height: 9px; border-radius: 50%; background: var(--pending); }
.connection[data-state="connected"] .connection__dot { background: var(--online); }
.connection[data-state="reconnecting"] .connection__dot { background: var(--pending); animation: ghost-pulse 1s infinite; }
.connection[data-state="denied"] .connection__dot { background: var(--danger); }
.ruleset-chip { font-size: 0.78rem; color: var(--muted); }
.status-line { font-weight: 600; font-size: 1.05rem; margin: 0; min-height: 1.6em; }
.controls { display: flex; flex-direction: column; gap: 0.55rem; }
.controls .button { width: 100%; }
.invite-box { background: var(--accent-soft); border: 1px solid var(--accent-border); border-radius: var(--radius-sm); padding: 0.9rem; }
.invite-box h2 { font-size: 1.05rem; margin-bottom: 0.3rem; }
.copy-field { display: flex; gap: 0.4rem; }
.copy-field input { min-width: 0; font-size: 0.85rem; }
.match-box { border-top: 1px solid var(--line); padding-top: 0.75rem; }
.match-box__title { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 0.4rem; }
.match-box__score { display: flex; flex-direction: column; gap: 0.3rem; }
.match-box__cell { display: flex; align-items: center; gap: 0.5rem; }
.match-box__name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.match-box__points { font-size: 1.3rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.resign-box { border-top: 1px solid var(--line); padding-top: 0.75rem; font-size: 0.9rem; }
.resign-confirm p { margin-bottom: 0.5rem; }
.resign-confirm .button { margin-right: 0.3rem; }
.help summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; }

/* banner, toast, result */
.board-banner {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 0.6rem 1.4rem;
  border-radius: 999px;
  background: rgba(28, 25, 23, 0.86);
  color: #ffffff;
  font-weight: 700;
  pointer-events: none;
  opacity: 0;
}
.board-banner.is-visible { animation: banner 1.6s ease forwards; }
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -40%) scale(0.95); }
  15%, 75% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -55%) scale(1); }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 20px);
  max-width: min(92vw, 520px);
  padding: 0.75rem 1.1rem;
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: #fafaf9;
  box-shadow: 0 10px 30px rgba(28, 25, 23, 0.25);
  z-index: 50;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast[data-kind="error"] { background: var(--danger-strong); }

.result {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(28, 25, 23, 0.45);
  backdrop-filter: blur(4px);
  z-index: 40;
  animation: fade-in 0.3s ease;
}
.result__card {
  position: relative;
  overflow: hidden;
  width: min(100%, 440px);
  background: var(--surface);
  border-radius: 18px;
  padding: 2rem 1.5rem 1.5rem;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: pop-in 0.45s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.result__title { font-size: 1.9rem; position: relative; }
.result__detail, .result__score { position: relative; }
.result__score { color: var(--muted); font-size: 0.92rem; }
.result__actions { position: relative; display: flex; gap: 0.5rem; justify-content: center; flex-wrap: wrap; margin-top: 1rem; }
.result__confetti { position: absolute; inset: 0; pointer-events: none; opacity: 0; }
.result.is-celebrating .result__confetti {
  opacity: 0.4;
  background-image:
    radial-gradient(circle, #f2c14e 3px, transparent 4px),
    radial-gradient(circle, #b85a3e 3px, transparent 4px),
    radial-gradient(circle, #22c55e 3px, transparent 4px),
    radial-gradient(circle, #3d5a50 2px, transparent 3px);
  background-size: 70px 70px, 90px 90px, 110px 110px, 60px 60px;
  background-position: 0 0, 30px 20px, 50px 40px, 10px 50px;
  animation: confetti 2.4s linear infinite;
}
@keyframes confetti {
  from { background-position: 0 -70px, 30px -70px, 50px -70px, 10px -60px; }
  to { background-position: 0 140px, 30px 200px, 50px 260px, 10px 120px; }
}
@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { transform: scale(0.85); opacity: 0; } }

@media (max-width: 960px) {
  .game { grid-template-columns: 1fr; }
  .game__panel { position: static; }
  .controls {
    position: sticky;
    bottom: 0;
    z-index: 5;
    background: var(--surface);
    padding: 0.5rem 0 calc(0.5rem + env(safe-area-inset-bottom, 0px));
  }
  .controls:not(:has(.button:not([hidden]))) { display: none; }
}

@media (max-width: 560px) {
  .site-main { padding-left: 0.6rem; padding-right: 0.6rem; }
  .page-game .site-main { padding-top: 0.5rem; }
  .board { border-radius: 10px; }
  .player-card { padding: 0.4rem 0.7rem; }
  .player-card__stats { gap: 0.6rem; font-size: 0.8rem; }
  .site-footer { display: none; }
}

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

/* ==========================================================================
   Lobby: matchmaking and open games
   ========================================================================== */

.play-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 0.5rem; }
.stack-form .play-actions .button { margin-top: 0; align-self: auto; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.inline-label { display: inline-flex; align-items: center; gap: 0.5rem; font-weight: 600; }
.inline-label select { width: auto; min-height: 38px; }
.badge--warning { background: #fff7ed; border-color: #fed7aa; color: #9a3412; }

.search-status { display: grid; grid-template-columns: auto 1fr; gap: 0.9rem 1rem; align-items: center; padding: 0.5rem 0; }
.search-status .button, .search-status > p { grid-column: 1 / -1; margin: 0; }
.search-status__text { display: flex; flex-direction: column; gap: 0.15rem; }
.search-status__text strong { font-size: 1.1rem; }
.search-status__pulse { position: relative; width: 56px; height: 56px; }
.search-status__pulse span {
  position: absolute;
  top: 12px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  animation: seek-bounce 1.4s ease-in-out infinite;
}
.search-status__pulse span:first-child { left: 0; background: radial-gradient(circle at 40% 35%, #ffffff, #d6d0c4); border: 1.5px solid #b8b0a2; }
.search-status__pulse span:last-child { right: 0; background: radial-gradient(circle at 40% 35%, #57534e, #0c0a09); animation-delay: 0.7s; }
@keyframes seek-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.seek-list { list-style: none; margin: 0.5rem 0 0; padding: 0; }
.seek-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.7rem 0;
  border-top: 1px solid var(--line);
}
.seek-row:first-child { border-top: 0; }
.seek-row.is-own { background: var(--accent-soft); border-radius: 10px; padding-left: 0.6rem; padding-right: 0.6rem; }
.seek-row__info { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }
.seek-row__who { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.seek-row__rating { font-weight: 700; font-variant-numeric: tabular-nums; padding: 0 0.45rem; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); }
.seek-row__details { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.seek-row__confirm { max-width: 420px; }
.seek-row__confirm p { margin-bottom: 0.4rem; }
.seek-row__confirm .button { margin-right: 0.3rem; }

.proposal h2 { margin-bottom: 0.6rem; }
.proposal__players { font-weight: 600; }
.proposal__gap { color: var(--accent-strong); }
.proposal__state { min-height: 1.4em; font-weight: 600; color: var(--good); }
.proposal__timer { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: 0.5rem 0 0.25rem; }
.proposal__timer span { display: block; height: 100%; background: var(--accent); transform-origin: left center; transition: transform 1s linear; }

/* ==========================================================================
   Home, rules and leaderboard pages
   ========================================================================== */

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.site-footer nav { margin-bottom: 0.4rem; }
.site-footer a { color: var(--muted); }

.page-home .hero { padding-bottom: 1.75rem; }
.page-home .hero h1 { font-size: clamp(2.3rem, 5.5vw, 3.6rem); letter-spacing: -0.04em; line-height: 1.05; margin-bottom: 0.3em; }
.hero__tagline { font-size: clamp(1.25rem, 2.6vw, 1.6rem); font-weight: 700; letter-spacing: -0.02em; color: var(--accent); margin-bottom: 0.35em; }
.live-stats { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; margin: 1.25rem 0 0; color: var(--muted); font-size: 0.95rem; }
.live-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--online); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6); animation: live-pulse 2s infinite; }
@keyframes live-pulse {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55); }
  70% { box-shadow: 0 0 0 10px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.home-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.home-grid > .card { margin-bottom: 0; }
.home-grid .card-head { margin-bottom: 0.3rem; }
.home-rules { text-align: center; margin: 1.75rem 0 0; font-size: 1.05rem; }
.empty-state { text-align: center; padding: 1rem 0 0.5rem; }
.empty-state p { color: var(--muted); max-width: 46ch; margin: 0 auto 1rem; }

.rating-chip { font-weight: 700; font-variant-numeric: tabular-nums; padding: 0 0.45rem; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); }
.cell-action { text-align: right; }
.seek-table td, .leader-table td { white-space: normal; vertical-align: middle; }
.leader-table tr.is-me td { background: var(--accent-soft); }
.rank { display: inline-grid; place-items: center; min-width: 1.8rem; height: 1.8rem; border-radius: 50%; font-weight: 700; font-variant-numeric: tabular-nums; }
.rank--1 { background: #f2c14e; color: #4a3500; }
.rank--2 { background: #d9d9d9; color: #3a3a3a; }
.rank--3 { background: #d79b6a; color: #45220a; }
.my-rank { padding: 1rem 1.4rem; }
.my-rank a { margin-left: 0.5rem; }

.breadcrumbs { font-size: 0.88rem; color: var(--muted); margin-bottom: 0.75rem; }
.breadcrumbs a { color: var(--muted); }

.rules { max-width: 860px; margin: 0 auto; }
.rules__head { margin-bottom: 1.25rem; }
.rules section { margin-bottom: 1.75rem; scroll-margin-top: 1rem; }
.rules section > h2 { font-size: 1.45rem; }
.rules p, .rules li { line-height: 1.7; }
.rules ul { padding-left: 1.2rem; }
.rules__toc ol { columns: 2; column-gap: 2rem; margin: 0; padding-left: 1.3rem; }
.rules__toc li { margin-bottom: 0.25rem; break-inside: avoid; }
.rules__summary ul { margin: 0; }
.rules__figure { margin: 0 0 1rem; }
.rules__figure svg { width: 100%; max-width: 560px; display: block; margin: 0 auto; filter: drop-shadow(0 10px 24px rgba(28, 25, 23, 0.14)); }
.rules__figure figcaption { text-align: center; color: var(--muted); font-size: 0.9rem; margin-top: 0.6rem; }
.rules__cta { text-align: center; }
.diagram-zone--dark { fill: rgba(28, 25, 23, 0.06); }
.diagram-zone--light { fill: rgba(21, 128, 61, 0.1); }
.diagram-path { fill: none; stroke-width: 4; stroke-linecap: round; stroke-dasharray: 2 9; }
.diagram-path--light { stroke: #ffffff; }
.diagram-path--dark { stroke: var(--board-frame); }
.diagram-arrow--light { fill: #ffffff; }
.diagram-arrow--dark { fill: var(--board-frame); }
.diagram-label { font: 700 15px var(--font-body); fill: var(--ink); }

@media (max-width: 900px) {
  .home-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .rules__toc ol { columns: 1; }
  /* Open games become stacked cards on phones. */
  .seek-table thead { display: none; }
  .seek-table, .seek-table tbody, .seek-table tr, .seek-table td { display: block; width: 100%; }
  .seek-table tr { padding: 0.6rem 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 0.15rem 0.75rem; }
  .seek-table td { border: 0; padding: 0; }
  .seek-table td:first-child { grid-column: 1; }
  .seek-table td:nth-child(2) { grid-column: 2; grid-row: 1; text-align: right; }
  .seek-table td:nth-child(3), .seek-table td:nth-child(4) { grid-column: 1; font-size: 0.88rem; }
  .seek-table .cell-action { grid-column: 2; grid-row: 2 / span 2; align-self: center; }
}

@media (max-width: 760px) {
  /* Headline and "Joacă acum" first on phones: the illustration is decorative. */
  .page-home .hero__art { display: none; }
  .page-home .hero { padding-top: 0.5rem; }
}

@media (max-width: 560px) {
  .site-nav { gap: 0.4rem 0.9rem; font-size: 0.95rem; }
  .nav-account { margin-left: 0; }
  .site-nav .user-chip { max-width: 10rem; }
  .nav-signout span { display: none; }  /* icon only on phones */
  .site-header__inner { padding-top: 0.55rem; padding-bottom: 0.55rem; }
}
