:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --cell: #273449;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #22c55e;
  --accent-dark: #15803d;
  --danger: #ef4444;
  --gold: #facc15;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
[hidden] { display: none !important; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--panel);
}
header h1 { margin: 0; font-size: 1.3rem; }
.header-right { display: flex; align-items: center; gap: 12px; }
#leave { padding: 6px 12px; font-size: 0.85rem; }
.conn { font-size: 0.8rem; color: var(--muted); }
.conn.ok::before { content: '●  '; color: var(--accent); }
.conn.bad::before { content: '●  '; color: var(--danger); }

main { padding: 20px; max-width: 1400px; margin: 0 auto; }
main:has(#game:not([hidden])) { max-width: 2000px; padding: 12px 16px; }

.card { background: var(--panel); border-radius: 12px; padding: 20px; }
.screen.card { max-width: 480px; margin: 40px auto; display: flex; flex-direction: column; gap: 12px; }
h2, h3 { margin: 0; }
.muted { color: var(--muted); margin: 0; }
.error { color: var(--danger); margin: 0; min-height: 1.2em; }
.or { text-align: center; color: var(--muted); font-size: 0.9rem; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row input { flex: 1; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; color: var(--muted); }

input, select, button {
  font: inherit;
  border-radius: 8px;
  border: 1px solid #334155;
  padding: 10px 12px;
  background: var(--bg);
  color: var(--text);
}
input:focus, select:focus { outline: 2px solid var(--accent); border-color: transparent; }
button { background: var(--accent); border: 1px solid transparent; color: #052e16; font-weight: 600; cursor: pointer; }
button:hover { background: var(--accent-dark); color: white; }
button.secondary { background: #334155; color: var(--text); }
button.secondary:hover { background: #475569; }
button:disabled { opacity: 0.5; cursor: default; }

.lobby { display: grid; grid-template-columns: minmax(0, 480px) minmax(0, 420px); gap: 16px; justify-content: center; align-items: start; margin: 40px auto; }
.lobby > .card { display: flex; flex-direction: column; gap: 12px; }
.mode-preview { position: sticky; top: 20px; }
.preview-demo { display: flex; flex-direction: column; justify-content: center; min-height: 220px; padding: 14px; border-radius: 10px; background: var(--bg); }
#previewDemo { display: flex; flex-direction: column; align-items: center; gap: 10px; }
#previewDemo img { width: 180px; aspect-ratio: 4 / 3; object-fit: contain; border-radius: 6px; background: var(--panel); }
#previewDemo img.small { width: 96px; }
#previewDemo img.shape { padding: 10px; }
#previewDemo .blur-loop { animation: unblur 5s linear infinite; clip-path: inset(0 round 6px); }
@keyframes unblur { 0% { filter: blur(14px); } 70%, 100% { filter: blur(0); } }
.mini-options { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.mini-options span { padding: 6px 10px; border-radius: 6px; border: 1px solid #334155; background: var(--panel); font-size: 0.85rem; white-space: pre; }
.mini-options span.right { border-color: var(--accent); background: var(--accent-dark); color: white; }
.mini-prompt { text-align: center; font-size: 1.05rem; }
.mini-prompt b { color: var(--gold); }
.mini-input { width: min(100%, 260px); padding: 8px 12px; border-radius: 8px; border: 1px solid #334155; }
.mini-input .ok, .mini-points { color: var(--accent); font-weight: 600; }
.mini-fact { width: 100%; padding: 10px 12px; border-radius: 8px; background: var(--panel); }
.mini-fact b { display: block; color: var(--gold); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
.preview-map .map { pointer-events: none; cursor: default; }
.preview-map .map-controls { display: none; }
@media (max-width: 900px) {
  .lobby { grid-template-columns: minmax(0, 480px); }
  .mode-preview { position: static; }
}

#home.invite #join { flex: 1; }
#hostControls { align-items: flex-end; }
#start { flex: 1; }

#code { text-transform: uppercase; letter-spacing: 0.3em; font-weight: 700; }
.code { font-family: ui-monospace, monospace; letter-spacing: 0.15em; color: var(--accent); }

.players { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.players li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: 8px;
}
.players li.me { outline: 1px solid var(--accent); }
.players li.offline { opacity: 0.45; }
.players .tag { font-size: 0.75rem; color: var(--muted); margin-left: 6px; }
.players .pts { font-weight: 700; font-variant-numeric: tabular-nums; }
ol.players { counter-reset: rank; }
ol.players li .who::before { counter-increment: rank; content: counter(rank) '. '; color: var(--muted); }
ol.players li:first-child .who::before { color: var(--gold); }

.bar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  background: var(--bg);
}
.guess-wrap { position: relative; flex: 1; display: flex; }
#guess { flex: 1; font-size: 1.2rem; padding: 12px 16px; }
.suggestion {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
}
.suggestion b { color: var(--text); }
.suggestion.taken { color: var(--danger); cursor: default; }
.players .swatch { display: inline-block; width: 10px; height: 10px; margin-right: 6px; border-radius: 3px; }
.suggestion kbd { font-family: inherit; font-size: 0.75rem; border: 1px solid #475569; border-radius: 4px; padding: 0 4px; margin-right: 6px; }
#guess.shake { animation: shake 0.3s; border-color: var(--danger); }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.stat { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
#timer.low { color: var(--danger); }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 240px; gap: 12px; align-items: start; }
.layout aside { position: sticky; top: 80px; display: flex; flex-direction: column; gap: 12px; }

.board { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.continent { background: var(--panel); border-radius: 10px; padding: 10px; }
.continent h4 { margin: 0 0 8px; display: flex; justify-content: space-between; font-size: 0.9rem; }
.continent h4 span { color: var(--muted); font-weight: 400; }
.cells { display: flex; flex-direction: column; gap: 3px; }
.cell {
  height: 22px;
  line-height: 22px;
  padding: 0 8px;
  font-size: 0.8rem;
  border-radius: 4px;
  background: var(--cell);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  justify-content: space-between;
}
.cell.found { background: var(--accent-dark); color: white; }
.cell.found.fresh { animation: pop 0.6s; }
.cell.missed { background: #450a0a; color: #fca5a5; }
.cell small { opacity: 0.7; }
@keyframes pop { 0% { background: var(--gold); color: black; } }

.toggle { display: flex; }
.toggle button { background: #334155; color: var(--text); border-radius: 0; }
.toggle button:first-child { border-radius: 8px 0 0 8px; }
.toggle button:last-child { border-radius: 0 8px 8px 0; }
.toggle button.active { background: var(--accent); color: #052e16; }

.map-view { display: flex; flex-direction: column; gap: 10px; }
/* Widest size that still fits the viewport height; --map-ratio is set from JS. */
.map-host {
  position: relative;
  --map-chrome: 190px;
  width: min(100%, calc((100vh - var(--map-chrome)) * var(--map-ratio)));
  margin: 0 auto;
}
.map {
  display: block;
  width: 100%;
  height: auto;
  background: #0b1220;
  border-radius: 10px;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

#game.fullscreen {
  position: fixed;
  inset: 0;
  z-index: 10;
  overflow: auto;
  padding: 0 12px 12px;
  background: var(--bg);
}
#game.fullscreen .map-host { --map-chrome: 80px; }
#game.fullscreen .layout { grid-template-columns: minmax(0, 1fr); }
#game.fullscreen .toggle,
#game.fullscreen #giveUp,
#game.fullscreen .continent-summary,
#game.fullscreen:not(.ended) .layout aside { display: none; }
#game.fullscreen .layout aside {
  position: fixed;
  top: 84px;
  right: 24px;
  width: 210px;
  max-height: 45vh;
  overflow: auto;
  padding: 12px;
  background: rgba(30, 41, 59, 0.85);
  backdrop-filter: blur(4px);
  z-index: 1;
}
#game.fullscreen .players li { padding: 4px 8px; }
.map.dragging { cursor: grabbing; }
.map path { vector-effect: non-scaling-stroke; stroke-width: 0.6; stroke-linejoin: round; }
.map .land { fill: #1e293b; stroke: #334155; }
.map .country { fill: #475569; stroke: #0b1220; transition: fill 0.3s; }
.map .found { fill: var(--accent); }
.map .missed { fill: var(--danger); }
.map .fresh { animation: map-pop 0.8s; }
@keyframes map-pop { 0% { fill: var(--gold); } }
.map .labels { display: none; pointer-events: none; }
.map.show-labels .labels { display: inline; }
.map .labels text {
  fill: #f8fafc;
  stroke: #0b1220;
  stroke-width: 0.22em;
  stroke-linejoin: round;
  paint-order: stroke;
  font-weight: 600;
}
.map-controls { position: absolute; right: 10px; bottom: 10px; display: flex; gap: 4px; }
.map-controls button { padding: 4px 10px; min-width: 32px; }
.continent-summary { display: flex; flex-wrap: wrap; gap: 6px; }
.continent-summary span { background: var(--panel); border-radius: 999px; padding: 4px 10px; font-size: 0.8rem; color: var(--muted); }

.players .status { margin-left: auto; font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.players .status.correct { color: var(--accent); }
.players .status.wrong { color: var(--danger); }

.quiz-time { flex: 1; height: 8px; border-radius: 999px; background: var(--panel); overflow: hidden; }
#quizTimeFill { height: 100%; background: var(--accent); transition: width 0.25s linear; }
#quizTimer.low { color: var(--danger); }
#quizWorth { color: var(--gold); }
.quiz-main { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.flag {
  width: min(100%, 480px, calc((100vh - 360px) * 4 / 3));
  aspect-ratio: 4 / 3;
  object-fit: contain;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}
.options { width: min(100%, 720px); display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.options button {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  min-height: 64px;
  padding: 12px 14px;
  text-align: left;
  font-size: 1.05rem;
  background: var(--panel);
  color: var(--text);
  border: 2px solid #334155;
}
.options button:hover:not(:disabled) { background: #334155; color: var(--text); border-color: var(--accent); }
.options button:disabled { opacity: 1; }
.options .letter {
  flex: none;
  width: 28px;
  height: 28px;
  line-height: 28px;
  text-align: center;
  border-radius: 6px;
  background: #334155;
  font-weight: 700;
}
.options .name { flex: 1; }
.options .picks { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 4px; }
.options .picks span { font-size: 0.75rem; font-weight: 500; padding: 2px 8px; border-radius: 999px; background: rgba(15, 23, 42, 0.6); }
.options button.chosen { border-color: var(--gold); }
.options button.chosen .letter { background: var(--gold); color: black; }
.options.revealed button { opacity: 0.55; }
.options.revealed button.correct { opacity: 1; background: var(--accent-dark); border-color: var(--accent); color: white; }
.options.revealed button.correct .letter { background: var(--accent); color: #052e16; }
.options.revealed button.wrong { opacity: 1; background: #450a0a; border-color: var(--danger); }
.options.revealed button.wrong .letter { background: var(--danger); color: white; }
.quiz-prompt { font-size: 1.6rem; text-align: center; }
.quiz-prompt b { color: var(--gold); }
.flag.small { width: min(40%, 200px); }
.flag.shape { padding: 16px; }
/* Clip so the blur doesn't bleed past the flag's box. */
.flag.blurry { transition: filter 0.25s linear; clip-path: inset(0 round 8px); }
.facts { width: min(100%, 720px); list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.facts li { padding: 12px 16px; border-radius: 8px; background: var(--panel); font-size: 1.1rem; line-height: 1.4; }
.facts b { display: block; color: var(--gold); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
.capital-form { width: min(100%, 560px); display: flex; gap: 8px; }
#capitalInput { flex: 1; font-size: 1.2rem; padding: 12px 16px; }
.capital-answers { width: min(100%, 560px); list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.capital-answers li { display: flex; gap: 10px; align-items: center; padding: 8px 12px; border-radius: 8px; background: var(--panel); border-left: 4px solid #334155; }
.capital-answers li.correct { border-left-color: var(--accent); }
.capital-answers li.wrong { border-left-color: var(--danger); }
.capital-answers .who { font-weight: 600; }
.capital-answers .typed { flex: 1; overflow-wrap: anywhere; }
.capital-answers li.wrong .typed { color: #fca5a5; text-decoration: line-through; }
.capital-answers .ms { color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.quiz-status { margin: 0; min-height: 1.4em; font-size: 1.1rem; color: var(--muted); text-align: center; }
.quiz-status.correct { color: var(--accent); font-weight: 600; }
.quiz-status.wrong { color: var(--danger); font-weight: 600; }

@media (max-width: 800px) {
  .options { grid-template-columns: 1fr; }
  .layout { grid-template-columns: 1fr; }
  .layout aside { position: static; order: -1; }
  .bar { flex-wrap: wrap; }
  .guess-wrap { flex-basis: 100%; }
}
