:root {
  color-scheme: dark;
  --bg: #090d0c;
  --panel: #111715;
  --surface: #18211e;
  --surface-2: #202b27;
  --ink: #f4f6ef;
  --muted: #a6b0a9;
  --soft: #77837b;
  --line: #2e3a35;
  --line-strong: #4d6057;
  --water-bg: #07191f;
  --land: #1d2a1f;
  --land-border: #6e8471;
  --accent: #48c8b8;
  --accent-strong: #7fe8d9;
  --accent-soft: rgba(72, 200, 184, 0.17);
  --focus: #f2b950;
  --good: #45d18d;
  --bad: #ff6b5f;
  --warn: #ffc75a;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.38);
  --label-halo: #08110f;
  --dot-country: #f4f6ef;
  --dot-city: #ffcf66;
  --dot-island: #81d7ff;
  --dot-region: #d7a5ff;
  --dot-mountain: #e4ad70;
  --dot-water: #61e2ee;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #edf3f0;
  --panel: #f8fbf7;
  --surface: #ffffff;
  --surface-2: #edf4f1;
  --ink: #17211e;
  --muted: #61716a;
  --soft: #7a8982;
  --line: #d9e2dd;
  --line-strong: #a9bbb3;
  --water-bg: #dceff4;
  --land: #e8eee4;
  --land-border: #748c7e;
  --accent: #187d78;
  --accent-strong: #095f5b;
  --accent-soft: rgba(24, 125, 120, 0.12);
  --focus: #c88415;
  --good: #16835b;
  --bad: #c94436;
  --warn: #a5670d;
  --shadow: 0 18px 52px rgba(21, 38, 33, 0.16);
  --label-halo: #f8fbf7;
  --dot-country: #21332e;
  --dot-city: #a66a00;
  --dot-island: #0f79a6;
  --dot-region: #7d3eb1;
  --dot-mountain: #8a5c24;
  --dot-water: #078693;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
button, input, summary, a, [tabindex] { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); }
.app-shell { display: grid; grid-template-columns: 400px minmax(0, 1fr); height: 100dvh; min-height: 520px; }
.side-panel { z-index: 2; overflow-y: auto; padding: 28px 24px; background: var(--panel); border-right: 1px solid var(--line); }
.setup-card, .game-card { display: grid; gap: 24px; }
.setup-title { display: grid; gap: 12px; }
.setup-title > span, .map-kicker { color: var(--accent-strong); font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
h1 { margin: 0; font-size: 32px; font-weight: 650; letter-spacing: -.025em; line-height: 1.15; }
.setup-title p, .mode-help { color: var(--muted); font-size: 14px; line-height: 1.6; margin: 0; }
.setup-section { display: grid; gap: 12px; padding-top: 20px; border-top: 1px solid var(--line); }
.section-title { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
h2 { margin: 0; font-size: 14px; font-weight: 650; }
.setup-actions { display: flex; gap: 4px; }
.type-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.type-toggle { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px; padding: 12px; border: 1px solid var(--line); border-radius: 6px; background: transparent; color: var(--muted); text-align: left; }
.type-toggle.active { color: var(--ink); background: var(--accent-soft); border-color: var(--accent); }
.type-toggle.active::before { content: '✓'; color: var(--accent-strong); }
.type-toggle span { flex: 1; overflow-wrap: anywhere; font-size: 13px; }
.type-toggle small { font-variant-numeric: tabular-nums; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; }
.mode-segmented { grid-template-columns: repeat(3, 1fr); }
.segmented button { min-height: 44px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); font-size: 12px; padding: 8px 4px; }
.segmented button.active { background: var(--surface-2); color: var(--ink); font-weight: 650; }
.primary-button, .secondary-button { min-height: 44px; padding: 12px 16px; border: 1px solid transparent; border-radius: 6px; font-weight: 650; font-size: 14px; }
.primary-button { background: var(--accent); color: #fff; }
:root:not([data-theme=light]) .primary-button { color: #071b17; }
.primary-button:hover:not(:disabled) { background: var(--accent-strong); }
.secondary-button { border-color: var(--line-strong); color: var(--ink); background: var(--surface); }
.secondary-button:hover { background: var(--surface-2); }
.mini-button { min-height: 36px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 4px; color: var(--muted); background: transparent; font-size: 12px; }
.mini-button:hover { color: var(--ink); border-color: var(--line-strong); }
.setup-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-top: 20px; border-top: 1px solid var(--line); }
.setup-footer strong { display: block; font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; }
.setup-footer span, .source-note { font-size: 12px; color: var(--muted); }
.source-details { color: var(--muted); font-size: 12px; line-height: 1.6; padding-top: 12px; border-top: 1px solid var(--line); }
summary { cursor: pointer; font-weight: 600; }
.source-details p { margin: 12px 0 0; overflow-wrap: anywhere; }
a { color: var(--accent-strong); text-underline-offset: 3px; }
.game-header { display: flex; justify-content: space-between; gap: 8px; }
.progress-wrap { display: grid; gap: 8px; }
.progress-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; }
.progress-bar { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.progress-bar span { display: block; height: 100%; background: var(--accent); }
.challenge-card { display: grid; gap: 20px; padding: 24px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.prompt-type { color: var(--accent-strong); font-size: 12px; font-weight: 650; letter-spacing: .03em; }
.prompt-main { display: grid; gap: 12px; font-size: 14px; font-weight: 400; color: var(--muted); letter-spacing: 0; line-height: 1.4; }
.prompt-main strong { color: var(--ink); font-size: 30px; font-weight: 650; line-height: 1.15; overflow-wrap: anywhere; }
.answer-form { display: grid; gap: 8px; }
.answer-form input { width: 100%; min-height: 44px; padding: 12px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); color: var(--ink); }
.answer-form input::placeholder { color: var(--muted); }
.feedback { padding: 12px; border-left: 3px solid currentColor; background: var(--surface); line-height: 1.5; font-size: 14px; }
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }
.feedback.warn { color: var(--warn); }
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { padding: 4px 0; }
.stat strong { display: block; font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 11px; }
.result-score { margin: 0; display: grid; gap: 8px; }
.result-score strong { font-size: 56px; font-weight: 600; letter-spacing: -.04em; }
.result-score span { color: var(--muted); font-size: 14px; }
.result-list { display: grid; gap: 16px; }
.result-list .section-title span { font-size: 12px; color: var(--muted); }
.miss-list { display: grid; gap: 8px; }
.miss-pill { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.miss-pill span:last-child { color: var(--muted); }
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.map-area { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: var(--water-bg); }
.map-svg { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; }
.map-svg.dragging { cursor: grabbing; }
.map-topbar { position: absolute; z-index: 1; top: 20px; left: 24px; right: 24px; display: flex; align-items: start; justify-content: space-between; gap: 12px; pointer-events: none; }
.map-topbar > * { pointer-events: auto; }
.map-topbar > div:first-child { padding: 12px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
#map-mode-label { display: block; margin-top: 4px; font-size: 14px; font-weight: 500; }
.map-actions { display: flex; gap: 4px; }
.icon-button { width: 44px; height: 44px; border: 1px solid var(--line-strong); border-radius: 4px; background: var(--panel); color: var(--ink); font-size: 18px; }
#zoom-reset { font-size: 12px; }
.map-help { position: absolute; bottom: 12px; left: 24px; max-width: calc(100% - 160px); padding: 8px; margin: 0; border-radius: 4px; background: var(--panel); color: var(--muted); font-size: 11px; line-height: 1.6; pointer-events: none; }
.map-legend { position: absolute; right: 24px; bottom: 20px; width: max-content; max-width: calc(100% - 48px); padding: 12px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; font-size: 12px; }
.legend-list { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.legend-item { display: flex; align-items: center; gap: 8px; }
.legend-icon { width: 20px; height: 20px; }
.legend-ring { fill: var(--surface); stroke: var(--line-strong); stroke-width: 1.8; }
.legend-shape { fill: currentColor; }
.legend-icon.marker-country { color: var(--dot-country); }
.legend-icon.marker-city { color: var(--dot-city); }
.legend-icon.marker-island, .legend-icon.marker-peninsula { color: var(--dot-island); }
.legend-icon.marker-region { color: var(--dot-region); }
.legend-icon.marker-mountain { color: var(--dot-mountain); }
.legend-icon.marker-water, .legend-icon.marker-lake, .legend-icon.marker-river { color: var(--dot-water); }

.base-country {
  fill: var(--land);
  stroke: var(--land-border);
  stroke-width: 0.75;
  vector-effect: non-scaling-stroke;
}

.study-feature {
  pointer-events: none;
  vector-effect: non-scaling-stroke;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.78;
}

.study-area {
  fill: color-mix(in srgb, var(--ink) 4%, transparent);
  stroke: color-mix(in srgb, var(--ink) 32%, transparent);
  stroke-width: 1.2;
}

.study-island {
  fill: color-mix(in srgb, var(--dot-island) 11%, transparent);
  stroke: color-mix(in srgb, var(--dot-island) 70%, transparent);
}

.study-region {
  fill: color-mix(in srgb, var(--dot-region) 9%, transparent);
  stroke: color-mix(in srgb, var(--dot-region) 58%, transparent);
  stroke-dasharray: 6 5;
}

.study-line {
  fill: none;
  stroke-width: 2.1;
}

.study-mountain {
  stroke: color-mix(in srgb, var(--dot-mountain) 76%, transparent);
  stroke-dasharray: 5 4;
}

.study-water {
  fill: color-mix(in srgb, var(--dot-water) 10%, transparent);
  stroke: color-mix(in srgb, var(--dot-water) 72%, transparent);
}

.study-water.study-line {
  fill: none;
  stroke-width: 2.4;
}

.map-marker {
  cursor: pointer;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.marker-ring {
  fill: var(--surface);
  stroke: var(--line-strong);
  stroke-width: 1.8;
  vector-effect: non-scaling-stroke;
}

.marker-symbol {
  fill: var(--ink);
  stroke: var(--bg);
  stroke-width: 1.4;
  vector-effect: non-scaling-stroke;
}

.marker-country .marker-symbol { fill: var(--dot-country); }
.marker-city .marker-symbol { fill: var(--dot-city); }
.marker-island .marker-symbol { fill: var(--dot-island); }
.marker-region .marker-symbol { fill: var(--dot-region); }
.marker-mountain .marker-symbol { fill: var(--dot-mountain); }
.marker-water .marker-symbol, .marker-lake .marker-symbol { fill: var(--dot-water); }

.map-marker.hovered .marker-ring,
.map-marker.current .marker-ring {
  fill: var(--accent-soft);
  stroke: var(--accent-strong);
}

.hover-box {
  fill: color-mix(in srgb, var(--focus) 10%, transparent);
  stroke: var(--focus);
  stroke-width: 2.5;
  stroke-dasharray: 7 5;
  pointer-events: none;
  vector-effect: non-scaling-stroke;
  stroke-linecap: round;
  stroke-linejoin: round;
  animation: box-in 160ms ease both;
}

.hover-box.highlight-line {
  fill: none;
}

.current-box {
  fill: color-mix(in srgb, var(--accent) 11%, transparent);
  stroke: var(--accent-strong);
}

.good-box {
  fill: color-mix(in srgb, var(--good) 11%, transparent);
  stroke: var(--good);
}

.bad-box {
  fill: color-mix(in srgb, var(--bad) 11%, transparent);
  stroke: var(--bad);
}

.highlight {
  fill: color-mix(in srgb, var(--focus) 24%, transparent);
  stroke: var(--focus);
  stroke-width: 4;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
  animation: pulse-stroke 1250ms ease-in-out infinite;
}

.highlight.good {
  fill: color-mix(in srgb, var(--good) 22%, transparent);
  stroke: var(--good);
}

.highlight.bad {
  fill: color-mix(in srgb, var(--bad) 20%, transparent);
  stroke: var(--bad);
}

.highlight.practice-revealed {
  fill: color-mix(in srgb, var(--accent) 16%, transparent);
  stroke: var(--accent-strong);
  animation: box-in 160ms ease both;
}

.highlight-line {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.highlight-point {
  filter: drop-shadow(0 8px 20px rgba(0, 0, 0, 0.32));
}

.map-label {
  fill: var(--ink);
  stroke: var(--label-halo);
  stroke-width: 4;
  paint-order: stroke fill;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0;
  text-anchor: middle;
  pointer-events: none;
}

.marker-peninsula .marker-symbol { fill: var(--dot-island); }
.marker-river .marker-symbol { fill: var(--dot-water); }
.study-peninsula { fill: color-mix(in srgb, var(--dot-island) 8%, transparent); stroke: var(--dot-island); }
.study-river { fill: none; stroke: var(--dot-water); }
.map-marker:focus-visible .marker-ring { stroke: var(--focus); stroke-width: 4; }
.toast { position: absolute; z-index: 3; bottom: 80px; left: 50%; transform: translateX(-50%); width: max-content; max-width: calc(100% - 32px); background: var(--panel); color: var(--ink); border: 1px solid var(--line-strong); border-radius: 6px; padding: 12px 16px; font-size: 13px; line-height: 1.5; pointer-events: none; }
@media (max-width: 980px) {
  .app-shell { grid-template-columns: 340px minmax(0,1fr); }
  .side-panel { padding: 24px 20px; }
  .map-topbar { left: 12px; right: 12px; }
  .map-help { left: 12px; }
}
@media (max-width: 720px) {
  .app-shell { grid-template-columns: 1fr; min-height: 0; }
  .setup-layout { height: auto; min-height: 100dvh; }
  .setup-layout .side-panel { width: min(100%, 540px); margin: auto; border: 0; padding: 28px 20px; }
  .setup-layout .map-area { display: none; }
  .game-layout { grid-template-rows: auto minmax(0,1fr); height: 100dvh; overflow: hidden; }
  .game-layout .side-panel { max-height: 48dvh; padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .game-card { gap: 12px; }
  .challenge-card { gap: 12px; padding: 12px 0; }
  .prompt-main { gap: 8px; }
  .prompt-main strong { font-size: 24px; }
  .stats-grid { gap: 8px; }
  .stat strong { font-size: 18px; }
  .stat { padding: 0; }
  .map-topbar { top: 12px; gap: 8px; }
  .map-topbar > div:first-child { padding: 8px; }
  .map-kicker { font-size: 10px; }
  #map-mode-label { font-size: 12px; }
  .icon-button { width: 40px; height: 40px; }
  .map-help { bottom: 8px; font-size: 10px; max-width: calc(100% - 112px); }
  .keyboard-help { display: none; }
  .map-legend { bottom: 12px; right: 12px; padding: 10px; }
  .legend-list { max-height: 24dvh; overflow-y: auto; grid-template-columns: 1fr 1fr; }
  .toast { bottom: 64px; }
}
@media (max-width: 360px) {
  .setup-layout .side-panel { padding: 24px 16px; }
  .type-toggle { padding: 8px; }
  .type-toggle span { font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
