:root {
  --bg: #f4f6f9; --surface: #fff; --text: #17202a; --muted: #5f6b7a; --border: #dde3ea;
  --accent: #2f6fdb; --accent-text: #fff; --ok: #1e8e4f; --ok-bg: #e5f6ec; --bad: #c63d3d; --bad-bg: #fbe9e9;
  --warn: #c98a12; --stage: #e9edf2; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 14px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151b; --surface: #1a2029; --text: #e6eaf0; --muted: #9aa5b4; --border: #2c3542;
    --accent: #5b93f0; --accent-text: #0c1320; --ok: #4cc782; --ok-bg: #173325; --bad: #f07a7a; --bad-bg: #3a1d1f;
    --warn: #e0a83a; --stage: #232b36; --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
main { max-width: 960px; margin: 0 auto; padding: 24px 16px 64px; }
h1 { font-size: 1.6rem; margin: 0 0 4px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
.muted { color: var(--muted); }
.lead { margin: 0 0 20px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
[hidden] { display: none !important; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { color: var(--muted); text-decoration: none; padding: 6px 12px; border-radius: 8px; }
.topbar nav a:hover { background: var(--bg); color: var(--text); }
.topbar nav a.active { color: var(--accent); background: var(--bg); font-weight: 600; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h1, .card-head h2 { margin: 0; }

.btn { font: inherit; padding: 9px 16px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); cursor: pointer; font-weight: 500; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: default; }
.link-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; text-decoration: underline; }
select, input[type="text"], input[type="search"] { font: inherit; padding: 9px 12px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }

/* ----- home ----- */
.settings { display: flex; flex-wrap: wrap; gap: 16px 24px; align-items: end; }
.settings label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); font-weight: 600; }
.settings label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; color: var(--text); font-size: .95rem; padding-bottom: 8px; }
.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; margin-bottom: 16px; }
.mode { display: flex; flex-direction: column; gap: 6px; text-align: left; font: inherit; color: inherit; cursor: pointer;
  margin: 0; transition: transform .12s, border-color .12s; }
.mode:hover { transform: translateY(-2px); border-color: var(--accent); }
.mode-art { display: flex; align-items: center; gap: 12px; height: 84px; margin-bottom: 8px; padding: 0 12px; background: var(--stage); border-radius: 10px; }
.mode-art img { height: 44px; border-radius: 3px; box-shadow: 0 0 0 1px rgba(0,0,0,.12); }
.mode-arrow { color: var(--muted); font-size: 1.3rem; }
.mode-input { background: var(--surface); border: 1px solid var(--border); border-radius: 7px; padding: 4px 10px; font-weight: 600; min-width: 90px; }
.mode-word { font-weight: 700; font-size: 1.15rem; }
.mode-grid { display: grid; grid-template-columns: repeat(2, auto); gap: 5px; }
.mode-grid img { height: 26px; width: 39px; object-fit: cover; }
.mode-options { display: flex; flex-direction: column; gap: 3px; font-size: .78rem; font-weight: 600; }
.mode-options span { background: var(--surface); border: 1px solid var(--border); border-radius: 5px; padding: 0 8px; }
.mode-options .pick { border-color: var(--ok); background: var(--ok-bg); }
.group-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 8px 0 10px; }
#trouble-card h3 { font-size: .9rem; margin: 4px 0 8px; color: var(--muted); }
#trouble-flags-wrap:not([hidden]) + #trouble-capitals-wrap { margin-top: 14px; }
.mode-title { font-size: 1.2rem; font-weight: 700; }
.mode-desc { color: var(--muted); }
.mode-stats { font-size: .85rem; color: var(--accent); font-weight: 600; margin-top: 4px; }

.flag-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.flag-list li { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 9px; background: var(--bg); }
.flag-list img { width: 42px; height: 28px; object-fit: contain; flex: none; }
.fl-name { font-weight: 600; flex: 1; min-width: 0; }
.fl-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.fl-text .fl-note { white-space: normal; }
.fl-note { font-size: .8rem; white-space: nowrap; }

/* ----- game ----- */
.game-head { display: flex; justify-content: space-between; align-items: end; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.eyebrow { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.progress-text { font-size: 1.05rem; }
.scoreboard { display: flex; gap: 16px; align-items: center; font-size: 1.05rem; }
.progress { height: 6px; background: var(--border); border-radius: 99px; overflow: hidden; margin-bottom: 16px; }
.progress-fill { height: 100%; background: var(--accent); width: 0; transition: width .25s; }

.q-card { padding: 24px; }
.flag-stage { height: clamp(180px, 38vw, 300px); display: flex; align-items: center; justify-content: center;
  background: var(--stage); border-radius: 12px; padding: 20px; margin-bottom: 20px; }
.flag-stage img { max-width: 100%; max-height: 100%; width: auto; height: auto; border-radius: 4px;
  box-shadow: 0 0 0 1px rgba(0,0,0,.12), 0 6px 18px rgba(0,0,0,.12); }
.answer-row { display: flex; gap: 8px; flex-wrap: wrap; }
.answer-row input { flex: 1 1 220px; font-size: 1.1rem; padding: 11px 14px; }

.q-country { font-size: clamp(1.5rem, 4vw, 2.1rem); text-align: center; margin: 4px 0 20px; }
.flag-choices { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.flag-choices:has(li:nth-child(5)) { grid-template-columns: repeat(3, 1fr); }
.flag-choice { position: relative; width: 100%; height: 150px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 14px; background: var(--stage); border: 2px solid transparent; border-radius: 12px; cursor: pointer; color: var(--text); font: inherit; }
.flag-choice:hover:not(:disabled) { border-color: var(--accent); }
.flag-choice img { width: 100%; min-height: 0; flex: 1 1 0; object-fit: contain;
  border-radius: 3px; filter: drop-shadow(0 0 1px rgba(0,0,0,.35)); }
.flag-choice .key { position: absolute; top: 6px; left: 8px; font-size: .75rem; font-weight: 700; color: var(--muted); }
.choice-label { font-size: .85rem; font-weight: 600; display: none; }
.revealed .choice-label { display: block; }
.revealed .flag-choice { height: 172px; cursor: default; }
.flag-choice.correct { border-color: var(--ok); background: var(--ok-bg); }
.flag-choice.incorrect { border-color: var(--bad); background: var(--bad-bg); }
.revealed .flag-choice:not(.correct):not(.incorrect) { opacity: .55; }

.cap-choices { list-style: none; margin: 0 0 4px; padding: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.cap-choices:has(li:nth-child(5)) { grid-template-columns: repeat(3, 1fr); }
.cap-choice { position: relative; width: 100%; min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 10px 14px 10px 30px; background: var(--stage); border: 2px solid transparent; border-radius: 10px; cursor: pointer;
  color: var(--text); font: inherit; font-weight: 600; font-size: 1.05rem; text-align: center; }
.cap-choice:hover:not(:disabled) { border-color: var(--accent); }
.cap-choice .key { position: absolute; top: 50%; left: 10px; transform: translateY(-50%); font-size: .75rem; font-weight: 700; color: var(--muted); }
.cap-choice .choice-label { font-weight: 500; font-size: .8rem; color: var(--muted); }
.cap-choice.correct { border-color: var(--ok); background: var(--ok-bg); }
.cap-choice.incorrect { border-color: var(--bad); background: var(--bad-bg); }
.revealed .cap-choice { cursor: default; }
.revealed .cap-choice:not(.correct):not(.incorrect) { opacity: .6; }
.fb-note { margin-top: 6px; font-size: .9rem; color: var(--muted); }
.feedback { margin-top: 18px; padding: 12px 16px; border-radius: 10px; border-left: 4px solid; }
.feedback.ok { background: var(--ok-bg); border-color: var(--ok); }
.feedback.wrong { background: var(--bad-bg); border-color: var(--bad); }
.compare { display: inline-flex; align-items: center; gap: 6px; margin-left: 4px; }
.compare img { width: 48px; height: 32px; object-fit: contain; vertical-align: middle; }
.q-nav { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 16px; min-height: 42px; }
.kbd-hint { font-size: .85rem; }

/* ----- results ----- */
.results-card { display: flex; gap: 28px; align-items: center; flex-wrap: wrap; }
.ring { --pct: 0; --c: var(--accent); width: 132px; height: 132px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: radial-gradient(closest-side, var(--surface) 78%, transparent 80%), conic-gradient(var(--c) calc(var(--pct) * 1%), var(--border) 0); }
.ring span { font-size: 1.9rem; font-weight: 800; }
.ring.good { --c: var(--ok); } .ring.ok { --c: var(--warn); } .ring.low { --c: var(--bad); }
.results-card p { margin: 4px 0 16px; }

/* ----- gallery ----- */
.gallery { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.gallery li { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 2px; }
.gal-flag { height: 90px; display: flex; align-items: center; justify-content: center; background: var(--stage); border-radius: 8px; padding: 8px; margin-bottom: 6px; }
.gal-flag img { max-width: 100%; max-height: 100%; width: auto; height: auto; box-shadow: 0 0 0 1px rgba(0,0,0,.12); }
#gal-search { width: 200px; }

/* ----- maps ----- */
:root { --map-space: #e9eef4; --map-ocean: #cfe3f3; --map-land: #f3f1ea; --map-border: #b9b4a6; --map-hit: #e8590c; --map-grid: rgba(60, 90, 120, .12); }
@media (prefers-color-scheme: dark) {
  :root { --map-space: #151a21; --map-ocean: #1b2b3c; --map-land: #2d3440; --map-border: #4a5363; --map-hit: #ff8a3d; --map-grid: rgba(160, 190, 220, .08); }
}
.map-panel { margin: 0; }
.q-main { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; margin-bottom: 16px; }
.q-main .flag-stage { height: 280px; margin: 0; }
.q-main .map-box { height: 280px; }
.q-main .flag-choices, .q-main .flag-choices:has(li:nth-child(5)) { grid-template-columns: repeat(2, 1fr); }
.q-main .flag-choice { height: 128px; }
.q-main .revealed .flag-choice { height: 146px; }
.map-placeholder { height: 100%; display: grid; place-items: center; padding: 16px; text-align: center; line-height: 1.4;
  background: var(--map-space); color: var(--muted); font-size: .9rem; }
.map-box { border-radius: 12px; overflow: hidden; border: 1px solid var(--border); line-height: 0; }
.map { width: 100%; height: auto; display: block; }
.map-panel figcaption { margin-top: 6px; font-size: .85rem; }
.map-space { fill: var(--map-space); }
.map-ocean { fill: var(--map-ocean); }
.map-grid { fill: none; stroke: var(--map-grid); stroke-width: 1; }
.map-land { fill: var(--map-land); stroke: var(--map-border); stroke-width: .6; stroke-linejoin: round; }
.map-hit { fill: var(--map-hit); stroke: #fff; stroke-width: 1; stroke-linejoin: round; }
.map-ring { fill: none; stroke: var(--map-hit); stroke-width: 3; animation: ring 1.6s ease-out infinite; transform-box: fill-box; transform-origin: center; }
.map-dot { fill: var(--map-hit); stroke: #fff; stroke-width: 1.5; }
@keyframes ring { 0% { transform: scale(.5); opacity: 1; } 100% { transform: scale(1.4); opacity: .15; } }
@media (prefers-reduced-motion: reduce) { .map-ring { animation: none; } }
.map-cap { fill: #1d2433; stroke: #fff; stroke-width: 2.5; }
.map-cap-label { font: 700 14px system-ui, -apple-system, "Segoe UI", sans-serif; fill: #1d2433;
  stroke: rgba(255, 255, 255, .9); stroke-width: 4px; paint-order: stroke; stroke-linejoin: round; }
.map-inset-bg { fill: var(--surface); stroke: var(--border); opacity: .92; }
.map-inset-ocean { fill: var(--map-ocean); }
.map-inset-land { fill: var(--map-border); }
.map-inset-dot { fill: var(--map-hit); stroke: #fff; stroke-width: 1.5; }

/* ----- country dialog (gallery) ----- */
.gal-item { all: unset; display: flex; flex-direction: column; gap: 2px; cursor: pointer; width: 100%; }
.gallery li:has(.gal-item:hover) { border-color: var(--accent); }
.gallery li:has(.gal-item:focus-visible) { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); }
.dialog { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text);
  padding: 20px; width: min(760px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.dialog::backdrop { background: rgba(10, 15, 25, .5); }
.cd-body { display: grid; grid-template-columns: 200px 1fr; gap: 16px; align-items: center; }
.cd-flag { display: flex; align-items: center; justify-content: center; }
.cd-flag img { max-width: 100%; max-height: 160px; box-shadow: 0 0 0 1px rgba(0,0,0,.12); border-radius: 3px; }
.dialog p { margin: 12px 0 0; }

@media (max-width: 700px) {
  .q-main { grid-template-columns: 1fr; }
  .q-main .flag-stage { height: 190px; }
  .q-main .map-box { height: 200px; }
}

@media (max-width: 600px) {
  .cap-choices, .cap-choices:has(li:nth-child(5)) { grid-template-columns: repeat(2, 1fr); }
  .cap-choice { font-size: .95rem; }
  .q-main .flag-choice { height: 104px; }
  .q-main .revealed .flag-choice { height: 124px; }
  .cd-body { grid-template-columns: 1fr; }
  .cd-flag img { max-height: 110px; }
  .flag-choices, .flag-choices:has(li:nth-child(5)) { grid-template-columns: repeat(2, 1fr); }
  .flag-choice { height: 110px; }
  .revealed .flag-choice { height: 132px; }
  .scoreboard { gap: 10px; }
  #gal-search { width: 100%; }
}
