/* General Knowledge, shell + shared components. Dark, mobile first, no grey body text. */
:root {
  --bg: #0B1020;
  --bg2: #0F1629;
  --panel: #161E33;
  --panel2: #1D2742;
  --line: #2A3555;
  --text: #FFFFFF;
  --text2: #E7ECF2;
  --accent: #6C8CFF;
  --accent2: #9DB1FF;
  --good: #35D07F;
  --bad: #FF5C6C;
  --warn: #FFB020;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
  --font: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text2); font-family: var(--font); font-size: 16px; line-height: 1.4; min-height: 100%; }
body { overscroll-behavior-y: contain; }
a { color: var(--accent2); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { color: var(--text); margin: 0 0 .4em; line-height: 1.15; }
h1 { font-size: 1.7rem; letter-spacing: -.01em; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .8em; }
.muted { color: var(--text2); opacity: .85; }
.accent { color: var(--accent2); }
.good { color: var(--good); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

#app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.screen { flex: 1; display: flex; flex-direction: column; width: 100%; max-width: 980px; margin: 0 auto; padding: 16px 16px calc(24px + var(--safe-b)); }
.screen.wide { max-width: 1200px; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 4px 0 14px; }
.topbar .brand { font-weight: 800; color: var(--text); text-decoration: none; font-size: 1.05rem; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; }
.topbar .brand svg { width: 26px; height: 26px; }
.topbar .spacer { flex: 1; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); font-weight: 600; text-decoration: none; transition: transform .06s ease, background .15s ease, border-color .15s ease; user-select: none; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0B1020; }
.btn.primary:hover { background: var(--accent2); }
.btn.good { background: var(--good); border-color: var(--good); color: #05261A; }
.btn.bad { background: transparent; border-color: var(--bad); color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: .9rem; border-radius: 10px; }
.btn.block { width: 100%; }
.btn.big { min-height: 56px; font-size: 1.1rem; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row.right { justify-content: flex-end; }
.btn-row.stack > .btn { flex: 1 1 160px; }

/* inputs */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 600; color: var(--text); font-size: .95rem; }
.input, select.input { width: 100%; min-height: 46px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg2); color: var(--text); outline: none; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(108,140,255,.25); }
.input.big { min-height: 56px; font-size: 1.25rem; }
select.input { appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text2) 50%), linear-gradient(135deg, var(--text2) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px, 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--bg2); }
.seg button { min-height: 42px; padding: 0 14px; border: 0; background: transparent; color: var(--text2); font-weight: 600; }
.seg button.on { background: var(--accent); color: #0B1020; }
.toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.toggle input { width: 44px; height: 26px; appearance: none; -webkit-appearance: none; border-radius: 13px; background: var(--line); position: relative; outline: none; transition: background .15s; }
.toggle input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: left .15s; }
.toggle input:checked { background: var(--accent); }
.toggle input:checked::after { left: 21px; }
.combo { position: relative; }
.combo .list { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); max-height: 260px; overflow-y: auto; }
.combo .list button { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 10px 14px; border: 0; background: transparent; color: var(--text); }
.combo .list button:hover, .combo .list button.on { background: var(--panel2); }
.combo .list img, .flag-sm { width: 28px; height: 21px; border-radius: 3px; object-fit: cover; box-shadow: 0 0 0 1px rgba(255,255,255,.15); }

/* cards / panels */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.panel + .panel { margin-top: 12px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.game-card { display: flex; flex-direction: column; gap: 8px; text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; color: var(--text); transition: border-color .15s, transform .06s; }
.game-card:hover { border-color: var(--accent); }
.game-card:active { transform: scale(.99); }
.game-card .cat { font-size: .78rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--accent2); }
.game-card .title { font-size: 1.15rem; font-weight: 700; }
.game-card .blurb { color: var(--text2); font-size: .95rem; }
.game-card.on { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(108,140,255,.35) inset; }
.section-title { display: flex; align-items: baseline; gap: 10px; margin: 18px 0 10px; }
.section-title h2 { margin: 0; }
.section-title .count { color: var(--accent2); font-weight: 600; font-size: .9rem; }
.hero { padding: 26px 0 8px; }
.hero h1 { font-size: 2rem; }
.hero p { font-size: 1.05rem; max-width: 60ch; }

/* game frame */
.game-frame { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.game-head { display: flex; align-items: center; gap: 10px; padding: 6px 0 12px; }
.game-head .title { font-weight: 800; color: var(--text); font-size: 1.05rem; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game-head .score { font-family: var(--mono); font-weight: 700; color: var(--accent2); font-size: 1.05rem; }
.game-head .timer { font-family: var(--mono); font-weight: 700; color: var(--text); min-width: 52px; text-align: center; }
.game-head .timer.low { color: var(--bad); }
.game-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); font-size: .85rem; font-weight: 600; color: var(--text); }
.pill.good { border-color: var(--good); color: var(--good); }
.pill.bad { border-color: var(--bad); color: var(--bad); }

/* progress bars */
.bar { height: 14px; border-radius: 999px; background: var(--bg2); border: 1px solid var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: 999px; transition: width .35s ease; }
.bar.thin { height: 8px; }
.bar.good > i { background: linear-gradient(90deg, #22B36A, var(--good)); }
.bar-row { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.bar-row .lbl { width: 90px; font-size: .9rem; color: var(--text); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row .bar { flex: 1; }
.bar-row .val { font-family: var(--mono); font-size: .9rem; color: var(--accent2); min-width: 64px; text-align: right; }
.bignum { font-size: 2.6rem; font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; letter-spacing: -.02em; line-height: 1; }
.bignum small { font-size: 1.1rem; color: var(--text2); font-weight: 600; }

/* lists */
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.list-plain li:last-child { border-bottom: 0; }
.list-plain .grow { flex: 1; min-width: 0; }
.list-plain .num { font-family: var(--mono); color: var(--accent2); }
.list-plain li.missed { color: var(--bad); }
.list-plain li.new { animation: pop .35s ease; }
@keyframes pop { 0% { background: rgba(53,208,127,.35); } 100% { background: transparent; } }
@keyframes shake { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-6px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(4px); } }
.shake { animation: shake .35s ease; }

/* choice buttons (quiz) */
.choices { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 720px) { .choices { grid-template-columns: 1fr 1fr; } }
.choice { text-align: left; padding: 14px 16px; min-height: 54px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font-weight: 500; line-height: 1.3; }
.choice:hover { border-color: var(--accent); }
.choice.good { border-color: var(--good); background: rgba(53,208,127,.15); }
.choice.bad { border-color: var(--bad); background: rgba(255,92,108,.15); }
.choice:disabled { cursor: default; }
.prompt { font-size: 1.6rem; font-weight: 800; color: var(--text); text-align: center; margin: 12px 0 18px; }
.prompt.small { font-size: 1.15rem; font-weight: 600; }

/* match grid */
.match { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.match .tile { min-height: 60px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); color: var(--text); text-align: left; font-size: .95rem; line-height: 1.25; }
.match .tile.word { font-weight: 700; font-size: 1.05rem; }
.match .tile.sel { border-color: var(--accent); background: rgba(108,140,255,.15); }
.match .tile.done { border-color: var(--good); background: rgba(53,208,127,.12); opacity: .75; pointer-events: none; }
.match .tile.wrong { border-color: var(--bad); }

/* flashcard */
.flash { perspective: 1200px; }
.flash .card { position: relative; min-height: 240px; transform-style: preserve-3d; transition: transform .45s cubic-bezier(.4,.2,.2,1); cursor: pointer; }
.flash .card.flipped { transform: rotateY(180deg); }
.flash .face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 22px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); }
.flash .face.back { transform: rotateY(180deg); background: var(--panel2); justify-content: flex-start; text-align: left; align-items: stretch; overflow: auto; }
.flash .word { font-size: 2rem; font-weight: 800; color: var(--text); }
.flash .pos { color: var(--accent2); font-weight: 600; margin-top: 4px; }

/* scoreboard drawer */
.scoreboard { margin-top: 12px; }
.scoreboard .row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.scoreboard .row:last-child { border-bottom: 0; }
.scoreboard .name { flex: 1; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scoreboard .name.me::after { content: " (you)"; color: var(--accent2); font-weight: 500; }
.scoreboard .rank { font-family: var(--mono); color: var(--accent2); width: 24px; }
.scoreboard .sc { font-family: var(--mono); font-weight: 700; color: var(--text); }
.scoreboard .st { font-size: .8rem; color: var(--good); }
.scoreboard .st.off { color: var(--warn); }
.scoreboard .mini { width: 90px; }
.drawer-toggle { position: fixed; right: 12px; bottom: calc(12px + var(--safe-b)); z-index: 30; box-shadow: var(--shadow); }
.drawer { position: fixed; left: 0; right: 0; bottom: 0; z-index: 29; background: var(--panel); border-top: 1px solid var(--line); border-radius: 18px 18px 0 0; padding: 14px 16px calc(64px + var(--safe-b)); max-height: 60vh; overflow: auto; transform: translateY(100%); transition: transform .25s ease; box-shadow: var(--shadow); }
.drawer.open { transform: translateY(0); }
@media (min-width: 980px) {
  .game-frame.multi { display: grid; grid-template-columns: 1fr 280px; grid-template-rows: auto 1fr; gap: 0 20px; }
  .game-frame.multi .game-head { grid-column: 1 / -1; }
  .game-frame.multi .game-body { grid-column: 1; }
  .game-frame.multi .drawer { position: static; transform: none; grid-column: 2; grid-row: 2; align-self: start; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); max-height: none; box-shadow: none; }
  .game-frame.multi .drawer-toggle { display: none; }
}

/* results */
.results .score-hero { text-align: center; padding: 18px 0 8px; }
.results .score-hero .bignum { font-size: 3.4rem; }
.summary { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); margin: 12px 0; }
.summary .stat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; text-align: center; }
.summary .stat .v { font-family: var(--mono); font-weight: 800; font-size: 1.3rem; color: var(--text); }
.summary .stat .l { font-size: .85rem; color: var(--text2); }

/* toasts */
.toasts { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px; box-shadow: var(--shadow); font-weight: 600; animation: fadein .2s ease; }
.toast.good { border-color: var(--good); }
.toast.bad { border-color: var(--bad); }
@keyframes fadein { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 90; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; max-width: 420px; width: 100%; box-shadow: var(--shadow); }

/* map */
.map-wrap { position: relative; flex: 1; min-height: 52vh; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); background: #0A1428; }
.map-wrap .leaflet-container { background: #0A1428; width: 100%; height: 100%; position: absolute; inset: 0; font: inherit; }
.map-wrap { touch-action: none; }
.map-wrap .leaflet-container a { color: var(--accent2); }
.map-prompt { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 8px 0 12px; min-height: 64px; }
.map-prompt img { height: 54px; width: 72px; object-fit: cover; border-radius: 6px; box-shadow: 0 0 0 1px rgba(255,255,255,.2), var(--shadow); }
.map-prompt .name { font-size: 1.5rem; font-weight: 800; color: var(--text); }
.leaflet-interactive.country { fill: #2B3B66; fill-opacity: 1; stroke: #5468A0; stroke-width: 0.7; }
.leaflet-interactive.country:hover { fill: #3E528C; }
.leaflet-interactive.country.good { fill: var(--good); fill-opacity: .85; }
.leaflet-interactive.country.bad { fill: var(--bad); fill-opacity: .85; }
.leaflet-interactive.country.dim { fill: #182342; }
.leaflet-interactive.small-marker { fill: #2B3B66; fill-opacity: .9; stroke: #6C8CFF; stroke-width: 1.4; stroke-opacity: .75; }
.leaflet-interactive.small-marker.good { fill: var(--good); stroke: var(--good); }
.leaflet-interactive.small-marker.bad { fill: var(--bad); stroke: var(--bad); }

/* keyboard-safe input area on phones */
.sticky-input { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 6px 0 10px; }
.found-count { display: flex; align-items: baseline; gap: 12px; margin: 6px 0 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 5px 10px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); font-size: .9rem; color: var(--text); font-weight: 600; }
.chip.missed { border-color: var(--bad); color: var(--bad); }
.chip.new { animation: pop .5s ease; }
.continent { margin: 10px 0; }
.continent h3 { display: flex; justify-content: space-between; margin: 0 0 6px; }
.continent h3 span { font-family: var(--mono); color: var(--accent2); font-weight: 600; font-size: .95rem; }
