/* Design tokens — shared look with the site's home page (see docs/DESIGN.md).
   Light is the default; dark follows the system unless the player picked a theme (html[data-theme]).
   Every token must exist in the three blocks below. */
:root {
  --bg: #f6f5f1;
  --bg-glow-1: rgb(91 140 255 / 0.16);
  --bg-glow-2: rgb(139 108 255 / 0.12);
  --surface: #ffffff;
  --surface-2: #f1efe9;
  --text: #17161a;
  --muted: #6b6875;
  --border: #e6e2d9;
  --accent: #3f6ef0;
  --accent-2: #7c5cff;
  --accent-text: #ffffff;
  --good: #1f8a4c;
  --bad: #c83a3a;
  --warn: #b26a00;
  --tile-bg: #ffffff;
  --tile-border: #dcd8ce;
  --tile-text: #17161a;
  --shadow: 0 1px 2px rgb(20 18 30 / 0.05), 0 12px 32px -12px rgb(20 18 30 / 0.12);
  --radius: 18px;
  --radius-sm: 10px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0f13;
    --bg-glow-1: rgb(91 140 255 / 0.14);
    --bg-glow-2: rgb(139 108 255 / 0.12);
    --surface: #16171d;
    --surface-2: #1c1e26;
    --text: #ecebf1;
    --muted: #9b99a8;
    --border: #262833;
    --accent: #6f97ff;
    --accent-2: #a08bff;
    --accent-text: #0e0f13;
    --good: #48b874;
    --bad: #ef6b6b;
    --warn: #e0a440;
    --tile-bg: #1d1f28;
    --tile-border: #2f3240;
    --tile-text: #ecebf1;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 16px 40px -16px rgb(0 0 0 / 0.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e0f13;
  --bg-glow-1: rgb(91 140 255 / 0.14);
  --bg-glow-2: rgb(139 108 255 / 0.12);
  --surface: #16171d;
  --surface-2: #1c1e26;
  --text: #ecebf1;
  --muted: #9b99a8;
  --border: #262833;
  --accent: #6f97ff;
  --accent-2: #a08bff;
  --accent-text: #0e0f13;
  --good: #48b874;
  --bad: #ef6b6b;
  --warn: #e0a440;
  --tile-bg: #1d1f28;
  --tile-border: #2f3240;
  --tile-text: #ecebf1;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 16px 40px -16px rgb(0 0 0 / 0.6);
  color-scheme: dark;
}

/* ---------------------------------------------------------------- base */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(900px 480px at 85% -10%, var(--bg-glow-1), transparent 70%),
    radial-gradient(700px 420px at -10% 10%, var(--bg-glow-2), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 16px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
h2 { font-size: 1.1rem; font-weight: 800; letter-spacing: -0.01em; margin: 0 0 12px; }
.muted { color: var(--muted); font-weight: normal; }
.small { font-size: 0.85rem; }
.error { color: var(--bad); min-height: 1.5em; margin: 0; }

/* ---------------------------------------------------------------- top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 960px; margin: 0 auto; padding: 18px 16px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { margin: 0; font-size: 1.45rem; font-weight: 800; letter-spacing: -0.03em; }
.logo-link { color: inherit; text-decoration: none; }
.logo span {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.logo-link:hover span, .logo-link:focus-visible span { text-decoration: underline; text-underline-offset: 4px; text-decoration-color: var(--accent); }

/* "Back to the home page" (only shown when the server knows the home URL) */
.home-link {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.85rem; font-weight: 700; color: var(--muted); text-decoration: none;
  padding: 6px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  white-space: nowrap;
}
.home-link:hover { color: var(--text); border-color: var(--accent); }
.home-link svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.topbar-right { display: flex; align-items: center; gap: 8px; }
.connection { font-size: 0.8rem; color: var(--muted); }
.connection[data-state="online"] { color: var(--good); }
.connection[data-state="offline"] { color: var(--bad); }

.volume { display: flex; align-items: center; gap: 4px; }
.volume input[type="range"] { width: 90px; padding: 0; border: 0; background: transparent; accent-color: var(--accent); }
.volume input[type="range"]:focus { outline-offset: 4px; }
.volume.silent input[type="range"] { opacity: 0.45; }

.icon-btn, .ui-lang {
  font: inherit; font-size: 0.85rem; font-weight: 700; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  height: 36px; cursor: pointer;
}
.icon-btn { width: 36px; display: grid; place-items: center; padding: 0; font-size: 1rem; line-height: 1; }
.icon-btn:hover, .ui-lang:hover { border-color: var(--accent); }
.ui-lang { width: auto; padding: 0 8px; }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn .icon-moon { fill: currentColor; stroke: none; }
.icon-sun { display: none; }
:root[data-theme="dark"] .icon-sun { display: block; }
:root[data-theme="dark"] .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun { display: block; }
  :root:not([data-theme="light"]) .icon-moon { display: none; }
}

@media (max-width: 520px) {
  .topbar { padding: 12px 16px; }
  .topbar-right { gap: 4px; }
  .connection { display: none; } /* not enough room on phones; state still shown by the toasts */
  .volume input[type="range"] { width: 52px; }
  .home-link .home-link-text { display: none; } /* icon only */
  .home-link { padding: 6px 8px; }
}

/* ---------------------------------------------------------------- layout & cards */
main { max-width: 960px; margin: 0 auto; padding: 0 16px 56px; }
.tagline { font-size: 1.15rem; color: var(--muted); margin: 8px 0 20px; max-width: 620px; }
.tagline strong { color: var(--text); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.grid-2 > .card { margin-bottom: 0; }
@media (max-width: 680px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- forms & buttons */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field span, .field small { font-size: 0.85rem; color: var(--muted); }
input, select {
  font: inherit; color: inherit; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
input:disabled, select:disabled { opacity: 0.7; }
.code-input { text-transform: uppercase; letter-spacing: 0.3em; font-weight: 700; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 700; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 12px; padding: 10px 18px;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent; color: #fff;
  box-shadow: 0 8px 20px -10px var(--accent);
}
.btn.primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 12px 26px -10px var(--accent); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; font-size: 0.9rem; border-radius: 10px; }
.btn.confirming { border-color: var(--bad); color: var(--bad); }

/* ---------------------------------------------------------------- home: room list */
.room-list { margin-top: 16px; }
.rooms { list-style: none; margin: 0; padding: 0; }
.room-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.room-item:last-child { border-bottom: 0; }
.room-main { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.room-title { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.room-code-sm { font-weight: 800; letter-spacing: 0.15em; }
.room-meta { font-size: 0.85rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 12px; }
.room-item .btn { flex: none; }

/* ---------------------------------------------------------------- lobby */
.room-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.room-code { font-size: 2rem; font-weight: 800; letter-spacing: 0.25em; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.player-list { list-style: none; margin: 0; padding: 0; }
.player-list li { display: flex; align-items: center; gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.player-list li:last-child { border-bottom: 0; }
.badge {
  font-size: 0.75rem; font-weight: 600; padding: 2px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.badge.you { color: var(--accent); }
.badge.status-lobby { color: var(--good); }
.badge.status-playing { color: var(--warn); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); flex: none; }
.dot.off { background: var(--muted); }

/* ---------------------------------------------------------------- game */
.game-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-bottom: 16px; }
.game-players { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; padding: 0; margin: 0 0 12px; }
.game-players li {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 9px 14px; min-width: 120px; box-shadow: var(--shadow);
}
.game-players li.current { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.game-players li.out { opacity: 0.45; }
.game-players .name { font-weight: 700; display: block; }
.hearts { letter-spacing: 2px; color: var(--bad); }

.board {
  text-align: center;
  background:
    radial-gradient(120% 90% at 0% 0%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 60%),
    radial-gradient(120% 90% at 100% 100%, color-mix(in srgb, var(--accent-2) 10%, transparent), transparent 60%),
    var(--surface);
}
.turn-label { font-weight: 700; margin-bottom: 14px; min-height: 1.5em; }
.turn-label.mine { color: var(--accent); }
.word { display: flex; justify-content: center; gap: 8px; margin: 8px 0 22px; flex-wrap: wrap; perspective: 600px; }
.tile {
  width: 58px; height: 66px; display: grid; place-items: center;
  font-size: 2rem; font-weight: 800; text-transform: uppercase;
  color: var(--tile-text); background: var(--tile-bg);
  border: 1px solid var(--tile-border); border-radius: 12px;
  box-shadow: 0 2px 0 var(--tile-border);
}
.tile.changed {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent; color: #fff; box-shadow: none;
}
.word.flash .tile { animation: tile-flip 0.45s ease; }
@keyframes tile-flip { 50% { transform: rotateX(90deg); } }
@media (max-width: 480px) { .tile { width: 44px; height: 52px; font-size: 1.5rem; } }

.timer { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.timer-bar { height: 100%; width: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 0.25s linear; }
.timer-bar.low { background: var(--bad); }
.timer-text { font-variant-numeric: tabular-nums; color: var(--muted); margin: 6px 0 14px; }

.submit-row { display: flex; gap: 8px; max-width: 420px; margin: 0 auto; }
.submit-row input { text-transform: uppercase; letter-spacing: 0.2em; font-size: 1.2rem; text-align: center; font-weight: 800; }
.hint { min-height: 1.5em; color: var(--muted); margin: 10px 0 0; }
.hint.bad { color: var(--bad); }
.hint.good { color: var(--good); }

.finished { text-align: center; }
.history { margin: 0; padding-left: 0; list-style: none; max-height: 320px; overflow: auto; }
.history li { padding: 6px 0; border-bottom: 1px dashed var(--border); display: flex; gap: 8px; }
.history .w { font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; }
.history .ok { color: var(--good); }
.history .ko { color: var(--bad); }
.history .sys { color: var(--muted); }

/* ---------------------------------------------------------------- toasts */
.toasts {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 10; width: min(92vw, 420px);
}
.toast {
  background: var(--text); color: var(--bg); padding: 11px 15px; border-radius: 12px;
  box-shadow: var(--shadow); animation: fadein 0.2s ease; font-size: 0.95rem;
}
.toast.bad { background: var(--bad); color: #fff; }
.toast.good { background: var(--good); color: #fff; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
