:root {
  --paper: #eef1f5;
  --card: #ffffff;
  --ink: #15203b;
  --ink-soft: #26345a;
  --muted: #56617d;
  --line: #d3d9e5;
  --tile: #ffcf33;
  --tile-edge: #d19f00;
  --unique: #0d6f4e;
  --unique-bg: #d9f2e7;
  --cancel: #b8232f;
  --cancel-bg: #fbe3e5;
  --focus: #2455e6;

  --font-display: "Bricolage Grotesque", "Trebuchet MS", system-ui, sans-serif;
  --font-body: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}

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

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.5;
}

h1, h2, h3 { font-family: var(--font-display); margin: 0; line-height: 1.1; }
p { margin: 0; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 1080px; margin: 0 auto; padding: 18px 20px 0;
}
.brand {
  font-family: var(--font-display); font-weight: 800; font-size: 1.6rem;
  letter-spacing: -0.02em; color: var(--ink); text-decoration: none;
}
.top-right { display: flex; gap: 10px; align-items: center; }
.you-chip {
  background: var(--ink); color: #fff; padding: 4px 12px; border-radius: 999px;
  font-size: 0.875rem; font-weight: 600;
}
.conn {
  background: var(--cancel-bg); color: var(--cancel); padding: 4px 12px;
  border-radius: 999px; font-size: 0.875rem; font-weight: 600;
}

/* ---------- layout ---------- */
.layout {
  max-width: 1080px; margin: 0 auto; padding: 24px 20px 72px;
  display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 32px; align-items: start;
}
.layout.solo { grid-template-columns: minmax(0, 1fr); max-width: 680px; }
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .side { order: 2; }
}

.screen { display: flex; flex-direction: column; gap: 20px; }

.hero {
  font-weight: 800; font-size: clamp(2rem, 5.2vw, 3.1rem); letter-spacing: -0.025em;
  max-width: 18ch;
}
.hero-sm { font-size: clamp(1.6rem, 4vw, 2.2rem); max-width: none; }
.lede { font-size: 1.125rem; color: var(--ink-soft); max-width: 58ch; }
.subhead { font-size: 1.4rem; font-weight: 700; margin-top: 12px; }
.error { color: var(--cancel); font-weight: 600; min-height: 1.5em; }
.empty { color: var(--muted); }

/* ---------- buttons & inputs ---------- */
.btn {
  font: inherit; font-weight: 700; cursor: pointer;
  background: var(--ink); color: #fff; border: 2px solid var(--ink);
  border-radius: 10px; padding: 12px 22px; min-height: 48px;
}
.btn:hover:not(:disabled) { background: var(--ink-soft); border-color: var(--ink-soft); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-big { align-self: flex-start; padding: 14px 32px; font-size: 1.125rem; }

input[type="text"], input:not([type]) {
  font: inherit; font-size: 1.125rem; color: var(--ink); background: #fff;
  border: 2px solid var(--ink); border-radius: 10px; padding: 11px 14px; min-height: 48px;
  width: 100%; min-width: 0;
}
input:disabled { background: var(--line); }

.join-form { display: flex; flex-direction: column; gap: 8px; max-width: 480px; }
.join-form label { font-weight: 600; }
.row { display: flex; gap: 10px; }

.rules {
  margin: 8px 0 0; padding: 0 0 0 1.1em; color: var(--ink-soft); max-width: 62ch;
  display: flex; flex-direction: column; gap: 8px;
}

/* ---------- stage (the base word) ---------- */
.stage {
  background: var(--ink); color: #fff; border-radius: 20px;
  padding: 20px 22px 26px; display: flex; flex-direction: column; gap: 14px;
}
.stage-head { display: flex; justify-content: space-between; align-items: baseline; }
.round-label { font-weight: 600; color: #c9d2ea; }
.timer {
  font-family: var(--font-display); font-weight: 800; font-size: 2.6rem;
  font-variant-numeric: tabular-nums; line-height: 1;
}
.bar { height: 8px; background: rgba(255, 255, 255, 0.16); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; width: 100%; background: var(--tile); transition: width 0.25s linear; }
.urgent .timer { color: #ff8b95; }
.urgent .bar-fill { background: #ff5a68; }

.tiles { display: flex; flex-wrap: wrap; gap: 7px; padding-top: 6px; }
.tile {
  --size: clamp(34px, 7.4vw, 54px);
  width: var(--size); height: var(--size);
  display: grid; place-items: center;
  background: var(--tile); color: var(--ink);
  font-family: var(--font-display); font-weight: 800; font-size: calc(var(--size) * 0.56);
  text-transform: uppercase; border-radius: 8px;
  box-shadow: 0 4px 0 var(--tile-edge);
  transition: opacity 0.12s, transform 0.12s, box-shadow 0.12s;
}
.tile.used { opacity: 0.3; transform: translateY(3px); box-shadow: 0 1px 0 var(--tile-edge); }

/* ---------- entry ---------- */
.entry { display: flex; gap: 10px; }
.entry.shake { animation: shake 0.3s; }
@keyframes shake {
  20% { transform: translateX(-6px); } 40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); } 80% { transform: translateX(4px); }
}
.feedback { min-height: 1.5em; font-weight: 600; margin-top: -8px; }
.feedback.ok { color: var(--unique); }
.feedback.error { color: var(--cancel); }

.mywords h2, .side h2 { font-size: 1.25rem; font-weight: 700; margin-bottom: 12px; }
.count {
  display: inline-block; min-width: 1.8em; text-align: center; padding: 0 8px; margin-left: 6px;
  background: var(--tile); border-radius: 999px; font-size: 1rem;
}

/* ---------- word chips ---------- */
.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-block; padding: 4px 10px; border-radius: 6px; font-weight: 600;
  background: #fff; border: 1px solid var(--line);
}
.chip.unique { background: var(--unique-bg); border-color: #a9dcc6; color: var(--unique); }
.chip.cancelled {
  background: var(--cancel-bg); border-color: #f0b9bf; color: var(--cancel);
  text-decoration: line-through; text-decoration-thickness: 2px;
}
.legend { color: var(--muted); font-size: 0.9375rem; line-height: 2; }

/* ---------- results ---------- */
.results-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.result-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.result-card.mine { border: 2px solid var(--ink); }
.result-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.result-head h3 { font-size: 1.125rem; font-weight: 700; overflow-wrap: anywhere; }
.result-score { font-family: var(--font-display); font-weight: 800; font-size: 1.4rem; white-space: nowrap; }

/* ---------- scoreboard ---------- */
.side {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px 18px 8px;
  position: sticky; top: 16px;
}
@media (max-width: 860px) { .side { position: static; } }
.score-list { list-style: none; margin: 0; padding: 0; }
.score-row {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: center;
  padding: 10px 0; border-top: 1px solid var(--line);
}
.score-row:first-child { border-top: 0; }
.score-name { font-weight: 600; overflow-wrap: anywhere; }
.score-name .me { color: var(--muted); font-weight: 500; }
.score-sub { grid-column: 1; color: var(--muted); font-size: 0.875rem; }
.score-total {
  grid-column: 2; grid-row: 1 / span 2; font-family: var(--font-display);
  font-weight: 800; font-size: 1.5rem; text-align: right;
}
.score-total small { display: block; font-size: 0.8125rem; font-weight: 600; color: var(--unique); }
.score-row.offline .score-name { color: var(--muted); }

/* ---------- final ---------- */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.standings { border-collapse: collapse; width: 100%; min-width: 420px; }
.standings th, .standings td { padding: 12px 14px; text-align: right; border-bottom: 1px solid var(--line); }
.standings th:first-child, .standings td:first-child { text-align: left; }
.standings tbody tr:last-child td { border-bottom: 0; }
.standings th { font-weight: 600; color: var(--muted); }
.standings td.total { font-family: var(--font-display); font-weight: 800; font-size: 1.25rem; }
.standings tr.winner td:first-child { font-weight: 700; }
.standings tr.winner td.total { background: var(--tile); }

@media (prefers-reduced-motion: reduce) {
  .tile, .bar-fill { transition: none; }
  .entry.shake { animation: none; }
}

/* ---------- rounds stepper ---------- */
.rounds-picker { display: flex; align-items: center; gap: 14px; }
.rounds-label { font-weight: 600; }
.stepper { display: inline-flex; align-items: stretch; border: 2px solid var(--ink); border-radius: 10px; overflow: hidden; background: #fff; }
.step-btn {
  font: inherit; font-size: 1.4rem; font-weight: 700; width: 48px; min-height: 48px;
  border: 0; background: transparent; color: var(--ink); cursor: pointer;
}
.step-btn:hover:not(:disabled) { background: var(--tile); }
.step-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.step-value {
  min-width: 56px; display: grid; place-items: center; font-family: var(--font-display);
  font-weight: 800; font-size: 1.4rem; border-left: 2px solid var(--ink); border-right: 2px solid var(--ink);
}

/* ---------- medals ---------- */
.medal {
  display: inline-grid; place-items: center; flex: none;
  width: 1.65em; height: 1.65em; border-radius: 50%;
  font-family: var(--font-display); font-weight: 800; font-size: 0.85rem; line-height: 1;
  color: var(--ink); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.18);
}
.medal-gold { background: #f5b800; }
.medal-silver { background: #c3cad6; }
.medal-bronze { background: #cd7f3c; }

.medal-summary { display: flex; flex-direction: column; gap: 8px; }
.medal-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.medal-line .names { font-weight: 700; overflow-wrap: anywhere; }
.medal-line .pts { color: var(--muted); }

.result-head h3 { display: flex; align-items: center; gap: 8px; }

/* ---------- final table medals ---------- */
.standings th .medal { font-size: 0.7rem; }
.standings td.medal-count { color: var(--muted); }

/* ---------- popup scoreboard ---------- */
.popup {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  padding: 16px; background: rgba(21, 32, 59, 0.66);
  animation: fade-in 0.2s ease-out;
}
.popup-card {
  width: min(480px, 100%); max-height: 92vh; overflow-y: auto;
  background: var(--paper); border-radius: 20px; padding: 24px 22px 22px;
  display: flex; flex-direction: column; gap: 18px;
  animation: pop-in 0.25s ease-out;
}
.popup-title { font-size: 1.7rem; font-weight: 800; letter-spacing: -0.02em; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(12px) scale(0.98); } }

/* Rows are absolutely positioned and slid with transforms; keep ROW_H in app.js in sync (52px row + 8px gap). */
.rank-list { list-style: none; margin: 0; padding: 0; position: relative; }
.rank-row {
  position: absolute; left: 0; right: 0; top: 0; height: 52px;
  display: grid; grid-template-columns: 32px minmax(0, 1fr) auto auto 52px; align-items: center; gap: 10px;
  padding: 0 14px 0 10px; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  transition: transform 0.9s cubic-bezier(0.3, 0.9, 0.3, 1);
}
.rank-row.mine { border: 2px solid var(--ink); }
.rank-row.lifted { z-index: 2; box-shadow: 0 6px 18px rgba(21, 32, 59, 0.18); }
.rank-pos { font-family: var(--font-display); font-weight: 800; font-size: 1.15rem; color: var(--muted); text-align: center; }
.rank-name { display: flex; align-items: center; gap: 8px; font-weight: 600; min-width: 0; }
.rank-name span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-gain {
  font-family: var(--font-display); font-weight: 800; color: var(--unique);
  opacity: 0; transition: opacity 0.3s;
}
.rank-gain.show { opacity: 1; }
.rank-move { font-size: 0.8125rem; font-weight: 700; opacity: 0; transition: opacity 0.3s; white-space: nowrap; }
.rank-move.show { opacity: 1; }
.rank-move.up { color: var(--unique); }
.rank-move.down { color: var(--cancel); }
.rank-total { font-family: var(--font-display); font-weight: 800; font-size: 1.4rem; text-align: right; font-variant-numeric: tabular-nums; }

@media (max-width: 420px) {
  .rank-row { grid-template-columns: 26px minmax(0, 1fr) auto 44px; }
  .rank-move { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .popup, .popup-card { animation: none; }
  .rank-row { transition: none; }
}

/* ---------- rooms ---------- */
.layout.wide { grid-template-columns: minmax(0, 1fr); }
.top-right { flex-wrap: wrap; justify-content: flex-end; }
.room-chip {
  border: 2px solid var(--ink); padding: 2px 12px; border-radius: 999px;
  font-size: 0.875rem; font-weight: 600; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.btn-quiet {
  font: inherit; font-size: 0.9375rem; font-weight: 600; background: transparent; color: var(--ink);
  border: 0; text-decoration: underline; cursor: pointer; padding: 8px 4px;
}
.btn-outline { background: #fff; color: var(--ink); }
.btn-outline:hover:not(:disabled) { background: var(--tile); border-color: var(--ink); }
.btn-small { padding: 8px 18px; min-height: 40px; }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; }
.panel h2 { font-size: 1.25rem; font-weight: 700; margin-bottom: 12px; }
.form-stack { display: flex; flex-direction: column; gap: 8px; }
.form-stack label { font-weight: 600; }
.form-stack h2 { margin-bottom: 4px; }
.hint { color: var(--muted); font-weight: 400; }
.check { display: flex; gap: 10px; align-items: center; font-weight: 500 !important; margin: 4px 0 8px; }
.check input { width: 20px; height: 20px; accent-color: var(--ink); }
select {
  font: inherit; font-size: 1.125rem; color: var(--ink); background: #fff;
  border: 2px solid var(--ink); border-radius: 10px; padding: 10px 12px; min-height: 48px;
}

.rooms-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.rooms-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.rooms-side { display: flex; flex-direction: column; gap: 20px; }
@media (max-width: 860px) { .rooms-grid { grid-template-columns: minmax(0, 1fr); } }

.room-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.room-item {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px;
}
.room-info { display: flex; flex-direction: column; min-width: 0; }
.room-name { font-family: var(--font-display); font-weight: 700; font-size: 1.125rem; overflow-wrap: anywhere; }
.room-meta { color: var(--muted); font-size: 0.9375rem; overflow-wrap: anywhere; }
.room-status { font-size: 0.875rem; font-weight: 600; color: var(--muted); }
.room-status.open { color: var(--unique); }

.invite { display: flex; flex-direction: column; gap: 12px; }
.invite-label { display: block; color: var(--muted); font-weight: 600; }
.room-code { font-family: var(--font-display); font-weight: 800; font-size: 2.6rem; letter-spacing: 0.14em; line-height: 1.1; }
.invite-link { display: flex; gap: 10px; }
.host-controls { display: flex; flex-direction: column; gap: 18px; align-items: flex-start; }
.badge {
  display: inline-block; background: var(--tile); color: var(--ink); border-radius: 6px;
  padding: 0 6px; margin-left: 6px; font-size: 0.75rem; font-weight: 700; line-height: 1.5;
}

/* ---------- legal pages & consent ---------- */
.legal-body { min-height: 100vh; display: flex; flex-direction: column; }
.legal-page { width: min(720px, calc(100% - 40px)); margin: 0 auto; padding: 64px 0 72px; flex: 1; }
.eyebrow { color: var(--unique); font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.8125rem; }
.legal-section { border-top: 1px solid var(--line); padding: 24px 0; display: flex; flex-direction: column; gap: 10px; }
.legal-section h2 { font-size: 1.35rem; font-weight: 700; }
.legal-section p { color: var(--ink-soft); max-width: 68ch; }
.legal-section a, .site-footer a, .contact-link { color: var(--focus); font-weight: 700; }
.site-footer { width: min(1080px, calc(100% - 40px)); margin: 0 auto; padding: 20px 0 28px; display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: 0.9375rem; }
.site-footer nav { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; }
.footer-button { font: inherit; color: var(--focus); background: transparent; border: 0; padding: 0; cursor: pointer; text-decoration: underline; }
.cookie-banner { position: fixed; z-index: 60; left: 16px; right: 16px; bottom: 16px; margin: 0 auto; max-width: 860px; padding: 16px 18px; background: var(--ink); color: #fff; border-radius: 14px; box-shadow: 0 12px 32px rgba(21, 32, 59, 0.28); display: flex; align-items: center; gap: 18px; justify-content: space-between; }
.cookie-banner p { color: #e5e9f2; font-size: 0.9375rem; max-width: 62ch; }
.cookie-actions { display: flex; gap: 8px; flex: none; }
.cookie-banner .btn-outline { background: transparent; color: #fff; border-color: #fff; }
.cookie-banner .btn-outline:hover:not(:disabled) { color: var(--ink); background: #fff; }
@media (max-width: 640px) {
  .legal-page { padding-top: 40px; }
  .cookie-banner { align-items: stretch; flex-direction: column; gap: 12px; }
  .cookie-actions { justify-content: flex-end; }
}
