/* ─────────────────────────────────────────────────────────────────────────────
   Wiki-Guesser — Wikipedia-inspired theme. Light by default, dark via
   :root[data-theme="dark"]. Serif headings, thin borders, boxy panels.
   ───────────────────────────────────────────────────────────────────────────── */
:root {
  --font-serif: "Linux Libertine", "Georgia", "Times New Roman", serif;
  --font-sans: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  /* Light theme (default) */
  --bg: #ffffff;
  --bg2: #f8f9fa;
  --bg3: #eaecf0;
  --text: #202122;
  --muted: #54595d;
  --border: #a2a9b1;
  --border-light: #c8ccd1;
  --link: #3366cc;
  --link-hover: #2a4b8d;
  --link-visited: #795cb2;
  --progressive: #3366cc;
  --progressive-hover: #2a4b8d;
  --green: #14866d;
  --red: #d33;
  --score: #b32424;
  --shadow: rgba(0, 0, 0, 0.08);
}

:root[data-theme="dark"] {
  --bg: #101418;
  --bg2: #1a1d21;
  --bg3: #26292d;
  --text: #eaecf0;
  --muted: #a2a9b1;
  --border: #494e54;
  --border-light: #3a3f45;
  --link: #6699ff;
  --link-hover: #88aaff;
  --link-visited: #a58cff;
  --progressive: #3b5fb0;
  --progressive-hover: #4a72cc;
  --green: #4ab38f;
  --red: #ff6d6d;
  --score: #ff8a8a;
  --shadow: rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100%;
}

a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); text-decoration: underline; }

h1, h2, h3 { font-family: var(--font-serif); font-weight: 400; line-height: 1.3; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.15rem; }

.subtitle, .muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.85rem; }
.green { color: var(--green); }
.red { color: var(--red); }

/* ── Buttons (OOUI-ish) ─────────────────────────────────────────────────────── */
button {
  font: inherit;
  font-family: var(--font-sans);
  font-weight: 600;
  color: var(--text);
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 0.5rem 1rem;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
}
button:hover { background: var(--bg3); border-color: var(--muted); }
button:active { background: var(--border-light); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.primary {
  background: var(--progressive);
  border-color: var(--progressive);
  color: #fff;
}
button.primary:hover { background: var(--progressive-hover); border-color: var(--progressive-hover); color: #fff; }
button.ghost { background: transparent; border-color: transparent; }
button.ghost:hover { background: var(--bg2); border-color: var(--border-light); }
button.small { padding: 0.35rem 0.7rem; font-size: 0.85rem; }

input[type="text"], input[type="password"], input[type="number"], select {
  font: inherit;
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 0.5rem 0.7rem;
  width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--progressive); box-shadow: 0 0 0 2px rgba(51, 102, 204, 0.2); }

.card {
  background: var(--bg2);
  border: 1px solid var(--border-light);
  border-radius: 2px;
  padding: 1.2rem;
}

.container { width: 100%; max-width: 1000px; margin: 0 auto; padding: 1.2rem; }

/* ── Top nav ─────────────────────────────────────────────────────────────────── */
.nav {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: 0.7rem 1.4rem; border-bottom: 1px solid var(--border);
  background: var(--bg2);
}
.brand { display: flex; align-items: center; gap: 0.5rem; font-family: var(--font-serif); font-weight: 700; font-size: 1.35rem; color: var(--text); }
.brand:hover { text-decoration: none; color: var(--text); }
.brand .logo { font-size: 1.4rem; }
.nav-right { display: flex; align-items: center; gap: 0.6rem; }

.pill {
  display: inline-flex; align-items: center; gap: 0.35rem;
  background: var(--bg); border: 1px solid var(--border-light);
  border-radius: 2px; padding: 0.3rem 0.6rem; font-size: 0.85rem;
}
.avatar { width: 24px; height: 24px; border-radius: 2px; object-fit: cover; background: var(--bg3); }
.avatar.sm { width: 20px; height: 20px; }
.avatar.mono {
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--font-sans); font-weight: 700; font-size: 0.7rem;
  color: var(--muted); background: var(--bg3); border: 1px solid var(--border-light);
}
.avatar.mono.sm { font-size: 0.62rem; }

.theme-toggle { padding: 0.35rem 0.7rem; font-size: 0.85rem; font-weight: 600; }

/* ── Landing / lobby ─────────────────────────────────────────────────────────── */
.hero { padding: 1.6rem 0 0.8rem; border-bottom: 1px solid var(--border-light); margin-bottom: 1.4rem; }
.hero h1 { font-size: 2.4rem; }
.hero .tagline { font-size: 1.05rem; color: var(--muted); margin-top: 0.4rem; max-width: 640px; }

.mode-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 1rem; }
.mode-card { display: flex; flex-direction: column; gap: 0.5rem; transition: border-color 0.12s; }
.mode-card:hover { border-color: var(--border); }
.mode-card h2 { margin: 0; }
.mode-card p { color: var(--muted); flex: 1; font-size: 0.92rem; }
.mode-card .row { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }

.section-title {
  font-family: var(--font-serif); font-weight: 400; font-size: 1.5rem;
  margin: 2rem 0 0.7rem; padding-bottom: 0.25rem; border-bottom: 1px solid var(--border-light);
}

/* ── Leaderboard ─────────────────────────────────────────────────────────────── */
table.board { width: 100%; border-collapse: collapse; }
.board th, .board td { text-align: left; padding: 0.5rem 0.7rem; border-bottom: 1px solid var(--border-light); }
.board th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
.board td .who { display: flex; align-items: center; gap: 0.5rem; }
.board .rating { font-weight: 700; color: var(--link); }
.board tr:last-child td { border-bottom: none; }
.board tbody tr:hover { background: var(--bg); }

/* ── Game screen ─────────────────────────────────────────────────────────────── */
.game-top { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; padding-bottom: 0.6rem; border-bottom: 1px solid var(--border-light); margin-bottom: 1rem; }
.round-chip { color: var(--muted); font-weight: 600; }
#room-label { color: var(--text); font-family: var(--font-serif); font-size: 1.15rem; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.25rem; min-width: 3ch; text-align: center; }
.timer.low { color: var(--red); }

.stage { display: grid; grid-template-columns: 1fr 300px; gap: 1.2rem; }
@media (max-width: 820px) { .stage { grid-template-columns: 1fr; } }

#image-frame {
  width: 100%; aspect-ratio: 3 / 2; background: var(--bg2);
  border: 1px solid var(--border); border-radius: 2px;
  display: flex; align-items: center; justify-content: center; overflow: hidden; position: relative;
}
#image-frame img { max-width: 100%; max-height: 100%; object-fit: contain; }
#image-frame .loading { color: var(--muted); font-size: 1.05rem; padding: 1rem; text-align: center; }

/* Description ("read the article") clue mode */
#image-frame.text-mode {
  aspect-ratio: auto; min-height: 220px; flex-direction: column;
  align-items: stretch; justify-content: center; padding: 1.6rem 1.8rem; gap: 1rem;
}
.clue-text { font-family: var(--font-serif); font-size: 1.35rem; line-height: 1.65; text-align: left; }
.clue-speak { align-self: flex-start; }

.guess-area { display: flex; gap: 0.6rem; margin-top: 1rem; }
.guess-area input { flex: 1; font-size: 1.05rem; }

.side { display: flex; flex-direction: column; gap: 1rem; }
.players-list { display: flex; flex-direction: column; gap: 0.3rem; }
.player-row {
  display: flex; align-items: center; gap: 0.5rem; padding: 0.4rem 0.55rem;
  background: var(--bg); border: 1px solid var(--border-light); border-radius: 2px;
}
.player-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-row .score { font-weight: 700; color: var(--score); font-variant-numeric: tabular-nums; }
.player-row.disconnected { opacity: 0.5; }
.player-row .status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); flex: none; }
.player-row .status-dot.ready { background: var(--green); }
.player-row .status-dot.host { background: var(--link); }

.reveal { margin-top: 1rem; }
.reveal .answer { font-family: var(--font-serif); font-size: 1.9rem; color: var(--text); }
.reveal .answer-desc { color: var(--muted); margin-top: 0.15rem; font-style: italic; }
.result-list { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 1rem; }
.result-item { display: flex; align-items: center; gap: 0.7rem; background: var(--bg); border: 1px solid var(--border-light); border-radius: 2px; padding: 0.6rem 0.8rem; }
.result-item .pts { font-size: 1.3rem; font-weight: 700; min-width: 2.5ch; text-align: right; color: var(--score); }
.result-item .meta { flex: 1; }
.result-item .meta .g { color: var(--muted); font-style: italic; font-size: 0.9rem; }
.result-item .credit { font-size: 0.8rem; color: var(--link); }
.result-item .score { font-weight: 700; color: var(--score); font-variant-numeric: tabular-nums; }

/* End-of-game round recap */
.recap-title {
  font-family: var(--font-serif); font-weight: 400; font-size: 1.2rem; text-align: left;
  margin: 1.2rem 0 0.6rem; padding-top: 0.9rem; border-top: 1px solid var(--border-light);
}
.recap-list { max-height: 340px; overflow-y: auto; display: flex; flex-direction: column; gap: 0.5rem; }
.recap-item {
  display: flex; gap: 0.7rem; align-items: flex-start; text-align: left;
  background: var(--bg); border: 1px solid var(--border-light); border-radius: 2px; padding: 0.55rem;
}
.recap-img { width: 68px; height: 68px; object-fit: cover; border-radius: 2px; background: var(--bg3); flex: none; }
.recap-img-text {
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
  padding: 0.3rem 0.4rem; font-size: 0.62rem; line-height: 1.25; color: var(--muted); text-align: left;
}
.recap-meta { flex: 1; min-width: 0; }
.recap-topic { font-weight: 700; }
.recap-num { color: var(--muted); font-weight: 700; margin-right: 0.2rem; }
.recap-scores { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; margin-top: 0.35rem; font-size: 0.9rem; color: var(--muted); }
.recap-scores b { color: var(--score); }

.lobby-box { display: flex; flex-direction: column; gap: 1rem; }
.share-row { display: flex; gap: 0.5rem; }
.share-row input { font-weight: 600; letter-spacing: 0.1em; }
.settings-row { display: flex; gap: 1rem; flex-wrap: wrap; align-items: end; }
.field { display: flex; flex-direction: column; gap: 0.25rem; }
.field label { font-size: 0.8rem; color: var(--muted); }
.field select, .field input { width: auto; min-width: 110px; }

.chat { display: flex; flex-direction: column; gap: 0.5rem; }
.chat-log { height: 150px; overflow-y: auto; display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; }
.chat-log .msg .who { color: var(--link); font-weight: 600; }
.chat-row { display: flex; gap: 0.5rem; }
.chat-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.chat-title { font-weight: 600; font-size: 0.9rem; }
.chat-hint { margin: 0.15rem 0 0; font-size: 0.75rem; }
button.tiny { padding: 0.15rem 0.5rem; font-size: 0.75rem; }

/* The report control stays out of the way until you go looking for it — chat
   should not read as a wall of accusation buttons. Revealed on hover, and kept
   permanently visible once armed or on touch devices, where hover never fires. */
.chat-log .msg { position: relative; }
.chat-report {
  opacity: 0;
  padding: 0 0.25rem;
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.8rem;
  transition: opacity 0.12s ease;
}
.chat-log .msg:hover .chat-report,
.chat-report:focus-visible,
.chat-report.armed { opacity: 1; }
.chat-report.armed { color: var(--danger, #c0392b); font-weight: 600; }
.chat-log .msg.reported { opacity: 0.55; }
@media (hover: none) {
  .chat-report { opacity: 0.6; }
}

.delta-up { color: var(--green); font-weight: 700; }
.delta-down { color: var(--red); font-weight: 700; }

.toast {
  position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%);
  background: var(--bg2); border: 1px solid var(--border); border-radius: 2px;
  padding: 0.6rem 1.1rem; box-shadow: 0 4px 16px var(--shadow); z-index: 50;
  opacity: 0; transition: opacity 0.2s; pointer-events: none;
}
.toast.show { opacity: 1; }

/* ── Ads ─────────────────────────────────────────────────────────────────────── */
.ad-slot {
  width: 100%; max-width: 970px; margin: 1.2rem auto; min-height: 90px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg2); border: 1px solid var(--border-light); border-radius: 2px;
  color: var(--muted); font-size: 0.8rem; overflow: hidden;
}
.ad-slot.hidden { display: none; }

footer { border-top: 1px solid var(--border-light); color: var(--muted); padding: 1.6rem 1rem; font-size: 0.85rem; text-align: center; margin-top: 2rem; }
.hidden { display: none !important; }

/* ── Modal ───────────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4);
  display: flex; align-items: center; justify-content: center; z-index: 40; padding: 1rem;
}
.modal { max-width: 420px; width: 100%; background: var(--bg); box-shadow: 0 8px 30px var(--shadow); }
.modal .auth-btns { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 1rem; }
.btn-oauth { display: flex; align-items: center; justify-content: center; gap: 0.5rem; padding: 0.6rem; }
.btn-google { background: #fff; color: #3c4043; border: 1px solid #747775; }
.btn-google:hover { background: #f7f8f8; color: #3c4043; border-color: #747775; }
.btn-discord { background: #5865f2; border-color: #5865f2; color: #fff; }
.btn-discord:hover { background: #4954d8; border-color: #4954d8; color: #fff; }
.divider { display: flex; align-items: center; gap: 0.7rem; color: var(--muted); margin: 1rem 0 0.4rem; font-size: 0.85rem; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border-light); }

/* Mode chooser (ranked/casual) */
.mode-choice { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 1rem; }
.mode-opt {
  display: flex; flex-direction: column; align-items: flex-start; gap: 0.15rem;
  text-align: left; padding: 0.7rem 0.9rem; background: var(--bg2); border: 1px solid var(--border);
}
.mode-opt:hover { border-color: var(--progressive); background: var(--bg3); }
.mode-opt-name { font-family: var(--font-serif); font-size: 1.1rem; font-weight: 700; }
.mode-opt-desc { font-size: 0.85rem; color: var(--muted); font-weight: 400; }

/* Multi-rating pill */
.pill-ratings { gap: 0.3rem; font-variant-numeric: tabular-nums; }
.pill-sep { color: var(--border); }

/* Leaderboard mode tabs */
.board-tabs { display: flex; gap: 0.4rem; margin-bottom: 0.7rem; flex-wrap: wrap; }
.board-tab { padding: 0.35rem 0.8rem; font-size: 0.85rem; background: var(--bg2); border: 1px solid var(--border-light); }
.board-tab.active { background: var(--progressive); border-color: var(--progressive); color: #fff; }

/* ── Legal pages (privacy, terms) ─────────────────────────────────────────────── */
.legal { line-height: 1.65; }
.legal h2 { font-size: 1.15rem; margin: 1.8rem 0 0.6rem; padding-top: 0.2rem; }
.legal h2:first-child { margin-top: 0; }
.legal h3 { font-size: 0.98rem; margin: 1.1rem 0 0.4rem; color: var(--muted); }
.legal p, .legal li { margin-bottom: 0.6rem; }
.legal ul, .legal ol { margin-left: 1.3rem; }
.legal table { width: 100%; border-collapse: collapse; margin: 0.8rem 0; font-size: 0.9rem; }
.legal th, .legal td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border-light); vertical-align: top; }
.legal th { color: var(--muted); font-weight: 600; }
.legal-meta { color: var(--muted); font-size: 0.85rem; margin-bottom: 1.4rem; }
.legal-toc { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; font-size: 0.9rem; margin-bottom: 0.4rem; }

/* Unfilled placeholders — deliberately loud so they can't ship by accident. */
.todo {
  background: #fde68a; color: #713f12; font-weight: 600;
  padding: 0.05rem 0.35rem; border-radius: 3px; border: 1px dashed #a16207;
}
:root[data-theme="dark"] .todo { background: #78350f; color: #fde68a; border-color: #fbbf24; }

/* ── Profile panel ────────────────────────────────────────────────────────────── */
/* Wider than the auth/mode modals: this one carries a match list, and the score
   and rating-delta columns need room to sit on one line on a phone. */
.profile-modal { max-width: 560px; max-height: 85vh; overflow-y: auto; }
.pill-profile { cursor: pointer; font-family: inherit; color: var(--text); }
.pill-profile:hover { border-color: var(--progressive); background: var(--bg3); }

.profile-head { display: flex; align-items: center; gap: 0.8rem; margin-bottom: 0.4rem; }
.profile-head h2 { margin: 0; }
.profile-head .avatar { width: 40px; height: 40px; }
.profile-head .avatar.mono { font-size: 1.1rem; }

.profile-section {
  font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--muted); margin: 1.4rem 0 0.6rem;
}
.profile-section.danger { color: var(--red); }

.profile-ladders { display: flex; flex-direction: column; gap: 0.5rem; }
.profile-ladder {
  display: grid; grid-template-columns: 1fr auto; gap: 0.1rem 0.8rem;
  background: var(--bg); border: 1px solid var(--border-light);
  border-radius: 2px; padding: 0.5rem 0.7rem;
}
.profile-ladder-name { font-weight: 600; }
.profile-ladder-rating { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.profile-ladder .credit { color: var(--muted); font-size: 0.8rem; }

.profile-matches { display: flex; flex-direction: column; gap: 0.5rem; }
.profile-matches .result-item { gap: 0.6rem; }
.profile-figures { flex: 0 0 auto; text-align: right; }
/* The W/L/D badge reuses .pts for sizing but carries its own colour. */
.result-win { color: var(--score); }
.result-loss { color: var(--red); }
.result-draw { color: var(--muted); }

/* Destructive action. Outlined until armed, solid once it means it. */
button.red { color: var(--red); border-color: var(--red); }
button.red:hover { background: var(--red); color: #fff; border-color: var(--red); }
.red-btn { background: var(--red); border-color: var(--red); color: #fff; }
.red-btn:hover { background: var(--red); border-color: var(--red); color: #fff; filter: brightness(1.1); }
.red-btn:disabled { opacity: 0.6; }

/* ── Category picker (private room settings) ─────────────────────────────── */
.cat-picker { margin-top: 0.9rem; }
.cat-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.cat-head label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; opacity: 0.7; }
.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: 0.4rem;
  margin-top: 0.45rem;
}
.cat-opt {
  display: flex; align-items: baseline; justify-content: space-between; gap: 0.4rem;
  padding: 0.42rem 0.6rem;
  border: 1px solid var(--line); border-radius: 8px;
  background: transparent; color: inherit; cursor: pointer;
  font-size: 0.85rem; text-align: left;
}
.cat-opt:hover:not(:disabled) { border-color: var(--accent); }
.cat-opt.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.cat-opt:disabled { opacity: 0.55; cursor: default; }
.cat-name { font-weight: 500; }
/* The count is the point of this control, so it stays legible rather than
   fading into decoration — but it must not outweigh the category name. */
.cat-count { font-variant-numeric: tabular-nums; font-size: 0.76rem; opacity: 0.65; }
.cat-opt.thin .cat-count { color: var(--warn, #c47b17); opacity: 1; }
#cat-note { margin-top: 0.5rem; }
#cat-note .warn { color: var(--warn, #c47b17); }

/* ── Chat header, mute and report ────────────────────────────────────────── */
.chat-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.4rem; }
.chat-title { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; opacity: 0.7; }
.chat-hint { margin-top: 0.35rem; opacity: 0.55; }
.msg .chat-report {
  border: none; background: transparent; cursor: pointer;
  opacity: 0; padding: 0 0.2rem; font-size: 0.8rem; color: inherit;
}
.msg:hover .chat-report, .msg .chat-report:focus-visible, .msg .chat-report.armed { opacity: 0.75; }
.msg .chat-report.armed { color: var(--warn, #c47b17); opacity: 1; font-size: 0.72rem; }
.msg.reported { opacity: 0.6; }
button.tiny { font-size: 0.72rem; padding: 0.15rem 0.45rem; }
/* Selected categories carry a check as well as the accent border, so the state
   does not depend on colour alone. */
.cat-opt.on .cat-name::before { content: "✓ "; }
