:root {
  --ink: #1b2a38;
  --ink-soft: #55677a;
  --bar: #14364f;
  --paper: #fbfaf4;
  --line: #d9d5c5;
  --mark: #ffd21f;
  --ok: #1a8f50;
  --bad: #d23f2a;
  --sea: #c9e2ee;
  --land: #ebe7d8;
  --land-de: #f6f0d8;
  --neighbour: #dfe3cf;
  --river: #2476b8;
  --range: #a06a35;
  --s1: #f5c7b6;
  --s2: #f8e29b;
  --s3: #c3dfb3;
  --s4: #d6c9ea;
  --bar-h: 56px;
  font-family: "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--paper); overscroll-behavior: none; }
/* Wie eine App: kein Doppeltipp-Zoom, kein Textmarkieren, kein Menü bei langem Druck */
body { touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--river); outline-offset: 2px; }
[hidden] { display: none !important; }

/* Leiste oben */
#bar {
  position: fixed; inset: 0 0 auto 0; z-index: 10;
  height: calc(var(--bar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--bar); color: #fff;
}
#bar h1 { margin: 0; font-size: 1.15rem; font-weight: 700; letter-spacing: 0.01em; white-space: nowrap; }
#bar nav { display: flex; gap: 4px; }
#bar nav button {
  display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px;
  border: 0; border-radius: 22px; background: none; font-weight: 600; font-size: 1rem;
}
#bar nav button[aria-current="page"] { background: var(--mark); color: var(--ink); }
svg[aria-hidden] { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* Aufteilung: Karte und Seitenfeld */
#shell {
  position: fixed; inset: 0; display: flex; flex-direction: column-reverse;
  height: 100dvh;
  padding: calc(var(--bar-h) + env(safe-area-inset-top)) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
#stage { position: relative; flex: 1; min-height: 0; background: var(--sea); }
#panel {
  flex: none; max-height: 46dvh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 18px 18px calc(1.5rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--paper);
}
@media (min-aspect-ratio: 1/1) and (min-width: 760px) {
  #shell { flex-direction: row; }
  #panel { width: 350px; max-height: none; border-top: 0; border-right: 1px solid var(--line); padding: 24px 22px calc(2.5rem + env(safe-area-inset-bottom)); }
}
@media (max-aspect-ratio: 1/1) { .toggles { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); } }
@media (max-width: 620px) {
  #bar h1 { display: none; }
  #bar nav { flex: 1; justify-content: space-between; }
}

/* Seitenfeld */
#panel h2.big { font-size: 2.2rem; }
.row.top { margin-bottom: 14px; flex-wrap: nowrap; }
.row.top > * { flex: 1; min-height: 48px; padding: 6px 14px; border-radius: 12px; font-size: 1rem; }
.stick { position: sticky; bottom: 0; padding: 10px 0 0; background: linear-gradient(transparent, var(--paper) 10px); }
#panel h2 { margin: 0 0 8px; font-size: 1.55rem; line-height: 1.2; font-weight: 700; text-wrap: balance; }
#panel p { margin: 0 0 16px; line-height: 1.45; color: var(--ink-soft); }
#panel .kind { margin: 0 0 4px; font-weight: 600; color: var(--river); }
.toggles { display: grid; gap: 8px; margin-bottom: 16px; }
.tg {
  display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 6px 14px; text-align: left;
  border: 2px solid var(--line); border-radius: 12px; background: #fff; font-weight: 600;
}
.tg[aria-pressed="true"] { border-color: var(--bar); background: #eaf2f7; }
.tg::after {
  content: ""; margin-left: auto; width: 22px; height: 22px; flex: none; border-radius: 50%; border: 2px solid var(--line);
}
.tg[aria-pressed="true"]::after {
  border-color: var(--bar);
  background: var(--bar) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 12.5 4 4 8-9'/%3E%3C/svg%3E") center / 16px no-repeat;
}
.sw { width: 20px; height: 20px; flex: none; border-radius: 5px; border: 2px solid var(--ink); }
.sw-states { background: linear-gradient(135deg, var(--s1) 50%, var(--s3) 50%); }
.sw-capitals { background: var(--ink); border-radius: 2px; box-shadow: inset 0 0 0 3px #fff; }
.sw-cities { background: #fff; border-radius: 50%; }
.sw-rivers { border: 0; border-radius: 0; height: 5px; background: var(--river); }
.sw-ranges { background: #e3c9a4; border-color: var(--range); border-radius: 50%; }
.sw-peaks { width: 0; height: 0; border: 0; border-left: 10px solid transparent; border-right: 10px solid transparent; border-bottom: 18px solid var(--range); border-radius: 0; }
.sw-waters { background: var(--sea); border-color: var(--river); border-radius: 50%; }
.sw-countries { background: var(--neighbour); }
.sw-countryCapitals { background: #fff; border-radius: 2px; box-shadow: inset 0 0 0 3px #fff, inset 0 0 0 20px var(--ink); }
.sw-extremes { background: var(--bad); border-color: var(--bad); transform: rotate(45deg) scale(0.75); border-radius: 2px; }
.sw-facts { border-radius: 50%; background: var(--mark); }

.row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  min-height: 52px; padding: 0 22px; border: 0; border-radius: 14px; background: var(--bar); color: #fff; font-weight: 700; font-size: 1.05rem;
}
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.quiet { background: none; color: var(--ink); border: 2px solid var(--line); font-weight: 600; }
.btn.wide { width: 100%; }

.choices { display: grid; gap: 10px; margin: 16px 0; }
.choice {
  min-height: 64px; padding: 8px 18px; text-align: left; border: 2px solid var(--line); border-radius: 14px; background: #fff; font-weight: 600; font-size: 1.25rem;
}
.choice:disabled { cursor: default; color: var(--ink-soft); }
.choice.ok { border-color: var(--ok); background: #dff3e7; color: var(--ink); }
.choice.bad { border-color: var(--bad); background: #fbe2dd; color: var(--ink); }

.steps { display: flex; gap: 5px; margin-bottom: 18px; }
.steps i { flex: 1; max-width: 28px; height: 6px; border-radius: 3px; background: var(--line); }
.steps i.ok { background: var(--ok); }
.steps i.bad { background: var(--bad); }
.steps i.now { background: var(--ink); }

.fb { margin: 16px 0; padding: 14px 16px; border-radius: 14px; line-height: 1.4; }
.fb { font-size: 1.15rem; }
.fb strong { display: block; font-size: 1.4rem; }
.fb.ok { background: #dff3e7; }
.fb.bad { background: #fbe2dd; }

.score { font-size: 3.2rem; font-weight: 700; line-height: 1; margin: 6px 0 4px; }
.todo { margin: 0 0 18px; padding-left: 1.2em; line-height: 1.5; }

.meter { margin-bottom: 14px; }
.meter div { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; margin-bottom: 5px; }
.meter div span { color: var(--ink-soft); font-weight: 500; white-space: nowrap; }
.meter b { display: block; height: 10px; border-radius: 5px; background: linear-gradient(to right, var(--ok) var(--done), #b9dcc7 var(--done) var(--seen), var(--line) var(--seen)); }

/* Karte */
#map { display: block; width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; }
#map path, #map ellipse { vector-effect: non-scaling-stroke; }
.inv { transform: scale(var(--inv, 1)); }
.land path { fill: var(--land); stroke: #fff; stroke-width: 1; }
.lakes { fill: var(--sea); stroke: var(--river); stroke-width: 0.6; pointer-events: none; }

/* Ausgeschaltete Ebenen verschwinden, außer was gerade aufgelöst wird */
.off > *:not(.reveal) { display: none; }
.shapes[data-cat="states"].off > path, .shapes[data-cat="countries"].off > path { display: inline; }

.shapes[data-cat="countries"] path { fill: var(--land); stroke: #fff; stroke-width: 1; }
.shapes[data-cat="countries"]:not(.off) path { fill: var(--neighbour); stroke: #8e9a80; }
.shapes[data-cat="states"] path { fill: var(--land-de); stroke: var(--land-de); stroke-width: 1; stroke-linejoin: round; }
.shapes[data-cat="states"]:not(.off) path { stroke: #7b6d5d; }
.shapes[data-cat="states"]:not(.off) path[data-c="1"] { fill: var(--s1); }
.shapes[data-cat="states"]:not(.off) path[data-c="2"] { fill: var(--s2); }
.shapes[data-cat="states"]:not(.off) path[data-c="3"] { fill: var(--s3); }
.shapes[data-cat="states"]:not(.off) path[data-c="4"] { fill: var(--s4); }
/* Im Quiz bleiben die Ländergrenzen als Orientierung, wie auf einer stummen Karte */
.quiz .shapes[data-cat="states"].off path { stroke: #cfc5a6; }
/* Ist im Quiz ein Land markiert oder aufgelöst, treten die anderen zurück */
.quiz .shapes[data-cat="states"]:has(.is-target, .is-ok, .is-bad):not(.off) path:not(.is-target, .is-ok, .is-bad) { fill: var(--land-de); stroke: #cfc5a6; }
.hitc { fill: transparent; stroke: none; }

.shapes[data-cat="ranges"] > * { fill: rgba(160, 106, 53, 0.3); stroke: var(--range); stroke-width: 1.2; stroke-dasharray: 4 3; }
.rv path { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.rv .line { stroke: var(--river); stroke-width: 2.2; }
.rv .hit { stroke: transparent; stroke-width: 26; }
.rv .glow { stroke: none; stroke-width: 9; }

.dot { stroke: #fff; stroke-width: 1.5; fill: var(--ink); }
[data-cat="cities"] .dot { fill: #fff; stroke: var(--ink); stroke-width: 2; }
[data-cat="countryCapitals"] .dot .ring { fill: none; stroke: var(--ink); stroke-width: 1.5; }
[data-cat="peaks"] .dot { fill: var(--range); }
[data-cat="waters"] .dot { fill: var(--river); }
[data-cat="extremes"] .dot { fill: var(--bad); }

.lbl { pointer-events: none; }
.lbl text { font-size: 15px; font-weight: 600; fill: var(--ink); paint-order: stroke; stroke: rgba(255, 255, 255, 0.85); stroke-width: 3.5px; stroke-linejoin: round; }
.lbl.a-r text { transform: translate(10px, 4.5px); }
.lbl.a-l text { transform: translate(-10px, 4.5px); text-anchor: end; }
.lbl.a-t text { transform: translate(0, -11px); text-anchor: middle; }
.lbl.a-b text { transform: translate(0, 20px); text-anchor: middle; }
.lbl.a-c text { transform: translate(0, 4.5px); text-anchor: middle; }
[data-cat="states"] .lbl text { font-size: 16px; font-weight: 700; }
[data-cat="countries"] .lbl text { font-size: 17px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; fill: #5f6b55; }
[data-cat="cities"] .lbl text { font-weight: 500; }
[data-cat="rivers"] .lbl text { font-style: italic; fill: #155a91; }
[data-cat="waters"] .lbl text { font-style: italic; fill: #155a91; }
[data-cat="ranges"] .lbl text { font-style: italic; fill: #6f4517; }
[data-cat="peaks"] .lbl text { font-size: 14px; fill: #6f4517; }
[data-cat="extremes"] .lbl text { fill: #a12a18; }

/* Stadtstaaten: steht die Hauptstadt schon da, braucht es den Ländernamen nicht doppelt */
.lbls[data-cat="capitals"]:not(.off) ~ .lbls[data-cat="states"] .small:not(.reveal) { display: none; }

/* Markiert, richtig, falsch */
#map path.is-target, #map ellipse.is-target { fill: var(--mark) !important; stroke: var(--ink) !important; stroke-dasharray: none; }
#map path.is-ok, #map ellipse.is-ok { fill: #7fd3a2 !important; stroke: var(--ok) !important; stroke-dasharray: none; }
#map path.is-bad, #map ellipse.is-bad { fill: #f2a498 !important; stroke: var(--bad) !important; stroke-dasharray: none; }
.rv.is-target .glow { stroke: var(--mark); }
.rv.is-ok .glow { stroke: #5fcf90; }
.rv.is-bad .glow { stroke: #f08f80; }
.rv.is-target .line, .rv.is-ok .line, .rv.is-bad .line { stroke-width: 3; }
.dot.is-target .halo { fill: var(--mark); stroke: var(--ink); stroke-width: 2; }
.dot.is-ok .halo { fill: #5fcf90; stroke: var(--ok); stroke-width: 2; }
.dot.is-bad .halo { fill: #f08f80; stroke: var(--bad); stroke-width: 2; }
.halo { fill: none; stroke: none; }
.lbl.is-ok text { fill: #0f6a39; font-weight: 700; }
.lbl.is-bad text { fill: var(--bad); font-weight: 700; }
@media (prefers-reduced-motion: no-preference) {
  .dot.is-target .halo { animation: pulse 1.2s ease-in-out infinite alternate; }
  @keyframes pulse { to { transform: scale(1.35); } }
}

#zoom { position: absolute; right: 14px; top: 14px; display: grid; gap: 10px; }
#zoom button {
  width: 52px; height: 52px; display: grid; place-items: center;
  border: 0; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(20, 54, 79, 0.35);
}
#card {
  position: absolute; left: 14px; right: 14px; bottom: calc(14px + env(safe-area-inset-bottom)); max-width: 420px;
  padding: 14px 18px; border-radius: 16px; background: #fff; box-shadow: 0 2px 10px rgba(20, 54, 79, 0.3);
  display: grid; gap: 2px; line-height: 1.4;
}
#card small { color: var(--river); font-weight: 600; font-size: 0.9rem; }
#card strong { font-size: 1.3rem; }
@media (min-aspect-ratio: 1/1) and (min-width: 760px) { #card { bottom: 20px; } }
