/* WordSpan. Dark blue, yellow accent, Barlow Condensed headings, Instrument Sans body. */
:root {
  --bg: #081533;
  --bg2: #0c1d45;
  --panel: #0f1f4a;
  --line: #22376e;
  --text: #eef2ff;
  --muted: #a9b6dc;
  --accent: #ffd23f;
  --on-accent: #0c1d45;
  --ok: #2fd27a;
  --bad: #ff5c5c;
  --slot: #1a2d63;
  --shadow: 0 10px 30px rgba(3, 8, 24, 0.45);
  --head: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --body: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --tile: clamp(40px, 11vw, 64px);
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
:root[data-theme="light"] {
  --bg: #eef2fb;
  --bg2: #e3e9f8;
  --panel: #ffffff;
  --line: #c9d4f0;
  --text: #0c1d45;
  --muted: #4a5a85;
  --accent: #f2bb00;
  --on-accent: #0c1d45;
  --ok: #138a4a;
  --bad: #c62828;
  --slot: #e6ecfa;
  --shadow: 0 8px 24px rgba(12, 29, 69, 0.12);
}
:root.cb { --ok: #3d8bff; --bad: #ff9f1c; }
:root.cb[data-theme="light"] { --ok: #1f5fd1; --bad: #b35900; }

*, *::before, *::after { box-sizing: inherit; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background: radial-gradient(1200px 600px at 10% -10%, var(--bg2), var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--body);
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { font-family: var(--head); font-weight: 800; line-height: 1.05; margin: 0 0 0.5rem; letter-spacing: 0.01em; }
h2 { font-size: 1.35rem; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* Header */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px clamp(12px, 3vw, 28px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-mark { display: inline-flex; align-items: center; gap: 3px; }
.brand-mark b {
  display: grid; place-items: center; width: 26px; height: 30px; border-radius: 6px;
  background: var(--accent); color: var(--on-accent); font: 800 18px/1 var(--head);
}
.brand-mark i { width: 14px; height: 4px; border-radius: 2px; background: var(--line); }
.brand-name { font: 800 1.5rem/1 var(--head); }
.hub-link { margin-left: 10px; font-weight: 600; font-size: 0.9rem; color: var(--muted); text-decoration: none; align-self: flex-end; padding-bottom: 1px; }
.hub-link:hover { color: var(--text); }
.tools { display: flex; gap: 6px; flex-wrap: wrap; }
.tbtn {
  background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px;
  font-size: 0.85rem; font-weight: 600; cursor: pointer; color: var(--text);
}
.tbtn:hover { border-color: var(--accent); }
.tbtn[aria-pressed="true"]#btnCb { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

main { padding: clamp(12px, 3vw, 28px); max-width: 1120px; margin: 0 auto; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 18px; box-shadow: var(--shadow); }

/* Buttons and fields */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg2);
  font-weight: 600; cursor: pointer; min-height: 44px;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); font-weight: 700; }
.btn.ghost { background: transparent; }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: 0.85rem; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
input, select {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; min-height: 44px; width: 100%;
}
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
.msg { min-height: 1.5em; margin: 10px 0 0; color: var(--muted); font-size: 0.9rem; }

.colors { display: flex; gap: 8px; flex-wrap: wrap; }
.cdot { width: 34px; height: 34px; border-radius: 50%; border: 3px solid transparent; background: var(--c); cursor: pointer; box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.15); }
.cdot[aria-checked="true"] { border-color: var(--text); }

.dot {
  display: inline-grid; place-items: center; flex: none; width: 22px; height: 22px; border-radius: 50%;
  background: var(--c); color: transparent; font: 800 12px/1 var(--head);
}
:root.cb .dot { color: #0c1d45; }

/* Landing */
.landing { display: grid; grid-template-columns: 1.15fr 1fr; gap: clamp(16px, 4vw, 40px); align-items: start; }
.landing-hero { padding-top: clamp(8px, 6vw, 72px); }
.title { font-size: clamp(3.2rem, 11vw, 6.5rem); margin: 0; text-transform: none; }
.lede { font-size: 1.15rem; color: var(--muted); max-width: 32ch; margin: 6px 0 24px; }
.play-modes { display: grid; gap: 8px; }
.mode {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; cursor: pointer;
  padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg2);
}
.mode b { font: 800 1.25rem/1.1 var(--head); }
.mode span { font-size: 0.85rem; color: var(--muted); }
.mode:hover, .mode.on { border-color: var(--accent); }
.mode.on { box-shadow: inset 4px 0 0 var(--accent); }
.sub { margin-top: 14px; }
.invite { margin: 0 0 10px; }
.join-box .btn + .btn { margin-top: 8px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.toggles { border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px 4px; margin: 0 0 14px; }
.toggles legend { font-size: 0.85rem; font-weight: 600; color: var(--muted); padding: 0 4px; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; font-size: 0.92rem; cursor: pointer; }
.check input { width: 20px; height: 20px; min-height: 0; margin: 2px 0 0; flex: none; accent-color: var(--accent); }
.solo-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.how { margin-top: 24px; }
.how summary { cursor: pointer; font: 800 1.35rem/1 var(--head); list-style: none; }
.how summary::-webkit-details-marker { display: none; }
.how summary::after { content: ' +'; color: var(--accent); }
.how[open] summary::after { content: ' \2212'; }
.how-body { max-width: 68ch; }
.how-body p { margin: 0.8em 0; }

/* The span: the game's signature element */
.span, .hero-span { display: flex; align-items: center; justify-content: center; gap: clamp(4px, 1vw, 8px); min-height: calc(var(--tile) + 24px); }
.tile {
  display: inline-grid; place-items: center; width: var(--tile); height: calc(var(--tile) * 1.12); border-radius: 12px;
  font: 800 calc(var(--tile) * 0.62)/1 var(--head); text-transform: uppercase; flex: none;
}
.tile.anchor {
  width: calc(var(--tile) * 1.18); height: calc(var(--tile) * 1.3); font-size: calc(var(--tile) * 0.8);
  background: var(--accent); color: var(--on-accent); box-shadow: 0 6px 0 rgba(0, 0, 0, 0.25);
  transition: box-shadow 0.15s, transform 0.15s;
}
.tile.anchor.ok { box-shadow: 0 6px 0 rgba(0, 0, 0, 0.25), 0 0 0 4px var(--ok); }
.tile.anchor.bad { box-shadow: 0 6px 0 rgba(0, 0, 0, 0.25), 0 0 0 4px var(--bad); }
.tile.anchor.ghost { background: var(--slot); color: var(--muted); box-shadow: none; }
.mid {
  position: relative; display: flex; gap: clamp(3px, 0.8vw, 6px); align-items: center; padding: 0 2px; flex-wrap: nowrap; max-width: 100%; overflow-x: auto;
}
.mid::before {
  content: ''; position: absolute; left: -10px; right: -10px; top: 50%; height: 4px; border-radius: 2px;
  background: var(--accent); opacity: 0.35; z-index: 0;
}
.mid .tile { position: relative; z-index: 1; width: calc(var(--tile) * 0.8); height: var(--tile); font-size: calc(var(--tile) * 0.55); }
.tile.slot { background: var(--panel); border: 2px dashed var(--line); }
.tile.fill { background: var(--text); color: var(--bg); }
.span.reveal .tile.fill, .hero-span .tile.fill { animation: drop 0.35s cubic-bezier(.2, .8, .3, 1.3) both; animation-delay: calc(var(--i, 0) * 60ms); }
@keyframes drop { from { transform: translateY(-16px); opacity: 0; } to { transform: none; opacity: 1; } }
.count {
  display: grid; place-items: center; min-width: calc(var(--tile) * 2.4); font: 800 calc(var(--tile) * 1.3)/1 var(--head); color: var(--accent);
}
.hero-span { justify-content: flex-start; --tile: clamp(38px, 7vw, 58px); }

/* Lobby */
.lobby { display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 16px; align-items: start; }
.room-card .grid3 { grid-template-columns: 1fr; }
.room-card .settings { margin-top: 16px; }
.code { font: 800 clamp(3rem, 9vw, 4.4rem)/1 var(--head); letter-spacing: 0.12em; color: var(--accent); margin: 0 0 6px; }
.summary { margin: 14px 0 0; padding-left: 18px; color: var(--muted); font-size: 0.92rem; }
.players, .scores, .feed, .chat, .final, #wordLog { list-style: none; margin: 0; padding: 0; }
.prow, .srow { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.prow:last-child, .srow:last-child { border-bottom: 0; }
.pname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 0.72rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.away { opacity: 0.5; }
.kick { margin-left: auto; background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; font-size: 0.75rem; cursor: pointer; color: var(--muted); }
.kick:hover { border-color: var(--bad); color: var(--bad); }

/* Chat */
.chat { max-height: 220px; overflow-y: auto; font-size: 0.92rem; margin-bottom: 8px; }
.chat li { display: flex; gap: 6px; align-items: baseline; padding: 3px 0; }
.chat li .dot { width: 12px; height: 12px; font-size: 0; transform: translateY(1px); }
.chat li.sys { color: var(--muted); font-style: italic; font-size: 0.85rem; }
.chat-form { display: flex; gap: 6px; }

/* Game */
.game { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.board { background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: clamp(14px, 3vw, 24px); box-shadow: var(--shadow); }
.status-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.round-label { font: 800 1.4rem/1 var(--head); }
.pill { font-size: 0.8rem; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--bg2); border: 1px solid var(--line); }
.time { margin-left: auto; font: 800 1.6rem/1 var(--head); font-variant-numeric: tabular-nums; }
.mini-scores { display: none; list-style: none; margin: 10px 0 0; padding: 0; gap: 6px; flex-wrap: wrap; }
.mini-scores li { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 4px; border-radius: 999px; background: var(--bg2); border: 1px solid var(--line); font-size: 0.85rem; }
.mini-scores li.me { border-color: var(--accent); }
.mini-scores .dot { width: 16px; height: 16px; }
.mini-scores b { font: 800 1rem/1 var(--head); }
.timer { height: 8px; border-radius: 4px; background: var(--bg2); overflow: hidden; margin: 12px 0 8px; }
.timer i { display: block; height: 100%; background: var(--accent); transform-origin: left; }
.timer i.low { background: var(--bad); }
.stage { padding: clamp(16px, 4vw, 36px) 0 8px; text-align: center; }
.stage-note { color: var(--muted); min-height: 3em; margin: 14px auto 0; max-width: 46ch; }
.stage-note b { color: var(--text); }
.accept-list { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 8px; }
.answer { display: flex; gap: 8px; max-width: 520px; margin: 4px auto 0; }
.answer input { font: 700 1.3rem/1 var(--body); letter-spacing: 0.04em; text-transform: lowercase; text-align: center; min-height: 52px; }
.answer input.cool { border-color: var(--bad); opacity: 0.6; }
.answer .btn { min-height: 52px; padding: 0 22px; }
.feedback { text-align: center; min-height: 1.5em; margin: 10px 0 0; font-weight: 600; }
.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--bad); }
.reacts { display: flex; justify-content: center; gap: 6px; margin-top: 14px; flex-wrap: wrap; }
.react { font-size: 1.3rem; width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg2); cursor: pointer; }
.side { display: grid; gap: 12px; }
.side .card { padding: 14px; }
.srow.me { box-shadow: inset 3px 0 0 var(--accent); padding-left: 8px; }
.srow.out { opacity: 0.45; }
.score { margin-left: auto; font: 800 1.4rem/1 var(--head); font-variant-numeric: tabular-nums; }
.srow .kick { margin-left: 6px; }
.feed { max-height: 200px; overflow-y: auto; font-size: 0.9rem; }
.att { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.att .dot { width: 14px; height: 14px; font-size: 0; }
.att .aw { font-weight: 600; }
.att .ar { margin-left: auto; font-size: 0.78rem; color: var(--bad); white-space: nowrap; }
.att.valid .ar { color: var(--ok); }

body.offline::before {
  content: 'Reconnecting...'; position: fixed; top: 0; left: 0; right: 0; z-index: 50; text-align: center; padding: 6px;
  background: var(--bad); color: #fff; font-weight: 700; font-size: 0.85rem;
}

/* Game over */
.over { max-width: 560px; margin: 0 auto; text-align: center; }
.over-title { font-size: clamp(2.4rem, 8vw, 3.6rem); color: var(--accent); }
.final li { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--line); font-size: 1.05rem; }
.final li b { margin-left: auto; font: 800 1.6rem/1 var(--head); }
.final li.won .pname::after { content: ' \2605'; color: var(--accent); }
.words-played { text-align: left; margin-top: 16px; }
.words-played summary { cursor: pointer; font-weight: 600; }
#wordLog li { padding: 4px 0; font-size: 0.92rem; }
#wordLog .pair { display: inline-block; min-width: 4.5em; font: 700 0.95rem/1 var(--head); color: var(--muted); }
.over .row { justify-content: center; }

/* Dialog */
.dialog { border: 1px solid var(--line); border-radius: 18px; background: var(--panel); color: var(--text); max-width: min(640px, 92vw); padding: 18px 22px; }
.dialog::backdrop { background: rgba(3, 8, 24, 0.6); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; }

/* Reactions */
#floaters { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 40; }
.floater { position: absolute; bottom: 10%; display: flex; flex-direction: column; align-items: center; animation: rise 2.2s ease-out forwards; }
.fe { font-size: 2.2rem; }
.fn { font-size: 0.75rem; font-weight: 700; background: var(--c); color: #0c1d45; padding: 1px 8px; border-radius: 999px; }
@keyframes rise { from { transform: translateY(0); opacity: 1; } to { transform: translateY(-50vh); opacity: 0; } }

.copyright { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 24px 12px 32px; }

@media (max-width: 900px) {
  .lobby { grid-template-columns: 1fr; }
  .game { grid-template-columns: 1fr; }
  .side { grid-template-columns: 1fr; }
  .mini-scores { display: flex; }
}
@media (max-width: 760px) {
  .landing { grid-template-columns: 1fr; }
  .hero-span { justify-content: center; }
  .landing-hero { text-align: center; }
  .lede { margin-left: auto; margin-right: auto; }
  .grid3 { grid-template-columns: 1fr; }
  .tools .tbtn { padding: 5px 9px; font-size: 0.78rem; }
  .answer input { font-size: 1.1rem; }
  .answer input::placeholder { font-size: 0.95rem; letter-spacing: 0; }
  .top { padding-top: 8px; padding-bottom: 8px; }
  .brand { flex-wrap: wrap; row-gap: 4px; }
  .brand-name { font-size: 1.3rem; }
  .hub-link { font-size: 0.8rem; margin-left: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
