: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: #516553;
  --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: #aebcb2;
  --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;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-shell {
  min-height: 100vh;
}

.setup-layout {
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    radial-gradient(circle at 78% 16%, var(--accent-soft), transparent 30%),
    var(--bg);
}

.setup-layout .map-area {
  display: none;
}

.setup-layout .side-panel {
  width: min(760px, 100%);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  height: 100vh;
}

.side-panel {
  position: relative;
  z-index: 4;
  overflow-y: auto;
  padding: 20px;
  border-right: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.setup-card,
.game-card {
  display: grid;
  gap: 18px;
}

.setup-title {
  display: grid;
  gap: 8px;
}

.setup-title > span,
.map-kicker {
  color: var(--accent-strong);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.setup-title h1 {
  margin: 0;
  font-size: clamp(34px, 7vw, 66px);
  line-height: 0.98;
  letter-spacing: 0;
}

.setup-title p {
  max-width: 58ch;
  margin: 0;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.5;
}

.setup-title .site-byline {
  color: var(--accent-strong);
  font-size: 14px;
  font-weight: 800;
}

.setup-title .site-disclaimer {
  width: fit-content;
  max-width: 100%;
  padding: 8px 10px;
  border: 1px solid color-mix(in srgb, var(--warn) 42%, transparent);
  border-radius: 8px;
  background: color-mix(in srgb, var(--warn) 10%, transparent);
  color: var(--warn);
  font-size: 12px;
  font-weight: 900;
  line-height: 1.35;
}

.setup-section,
.setup-footer,
.challenge-card,
.result-list {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.setup-section {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.access-card {
  width: min(560px, 100%);
}

.access-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.access-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.access-row input {
  width: 100%;
  min-height: 48px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  background: var(--bg);
  color: var(--ink);
}

.access-row input::placeholder {
  color: var(--soft);
}

.access-row input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.access-row .primary-button {
  min-width: 120px;
  padding: 0 18px;
}

.setup-footer {
  display: grid;
  grid-template-columns: minmax(120px, auto) 1fr;
  align-items: center;
  gap: 14px;
  padding: 16px;
}

.setup-footer strong {
  display: block;
  font-size: 28px;
  line-height: 1;
}

.setup-footer span {
  color: var(--muted);
  font-size: 13px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-title h2 {
  margin: 0;
  font-size: 14px;
}

.section-title span,
.source-note {
  color: var(--muted);
  font-size: 12px;
}

.setup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.type-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.type-toggle {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 54px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  text-align: left;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, color 160ms ease;
}

.type-toggle:hover,
.segmented button:hover,
.primary-button:hover,
.secondary-button:hover,
.mini-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.type-toggle.active {
  border-color: color-mix(in srgb, var(--accent) 64%, transparent);
  background: var(--accent-soft);
  color: var(--ink);
}

.type-toggle small {
  color: var(--soft);
}

.type-toggle.active small {
  color: var(--accent-strong);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}

.segmented button {
  min-height: 44px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, color 160ms ease;
}

.segmented button.active {
  background: var(--surface-2);
  color: var(--ink);
}

.primary-button,
.secondary-button {
  min-height: 48px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.primary-button {
  background: linear-gradient(180deg, var(--accent-strong), var(--accent));
  color: var(--bg);
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.secondary-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
}

.mini-button {
  min-height: 32px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--accent-strong);
  cursor: pointer;
  font-size: 12px;
  font-weight: 900;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.mini-button:hover {
  border-color: color-mix(in srgb, var(--accent) 50%, var(--line));
  background: var(--surface-2);
}

.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: 10px;
  overflow: hidden;
  border-radius: 8px;
  background: color-mix(in srgb, var(--bg) 82%, var(--surface));
}

.progress-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--focus));
  transition: width 260ms ease;
}

.challenge-card {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.prompt-type {
  width: fit-content;
  padding: 5px 9px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 900;
}

.prompt-main {
  display: grid;
  gap: 5px;
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}

.prompt-main strong {
  color: var(--ink);
  font-size: 30px;
  line-height: 1.05;
}

.answer-form {
  display: grid;
  gap: 8px;
}

.answer-form input {
  width: 100%;
  min-height: 48px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  background: var(--bg);
  color: var(--ink);
}

.answer-form input::placeholder {
  color: var(--soft);
}

.answer-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.feedback {
  padding: 12px;
  border-radius: 8px;
  line-height: 1.45;
  animation: pop-in 180ms ease both;
}

.feedback.good {
  border: 1px solid color-mix(in srgb, var(--good) 42%, transparent);
  background: color-mix(in srgb, var(--good) 14%, transparent);
  color: var(--good);
}

.feedback.bad {
  border: 1px solid color-mix(in srgb, var(--bad) 42%, transparent);
  background: color-mix(in srgb, var(--bad) 14%, transparent);
  color: var(--bad);
}

.feedback.warn {
  border: 1px solid color-mix(in srgb, var(--warn) 42%, transparent);
  background: color-mix(in srgb, var(--warn) 14%, transparent);
  color: var(--warn);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat {
  padding: 12px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.stat strong {
  display: block;
  font-size: 25px;
  line-height: 1;
}

.stat span {
  color: var(--muted);
  font-size: 12px;
}

.result-score {
  display: grid;
  gap: 3px;
  margin: 0;
}

.result-score strong {
  font-size: 52px;
  line-height: 0.95;
}

.result-score span {
  color: var(--muted);
}

.result-list {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.miss-list {
  display: grid;
  gap: 6px;
  max-height: 210px;
  overflow: auto;
}

.miss-pill {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  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;
  overflow: hidden;
  background:
    radial-gradient(circle at 76% 14%, var(--accent-soft), transparent 28%),
    var(--water-bg);
}

.map-topbar {
  position: absolute;
  top: 18px;
  left: 18px;
  right: 18px;
  z-index: 3;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.map-topbar > * {
  pointer-events: auto;
}

.map-topbar > div:first-child {
  min-width: min(420px, calc(100% - 170px));
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.map-legend {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 3;
  width: min(330px, calc(100% - 36px));
  padding: 12px;
  border: 1px solid color-mix(in srgb, var(--line) 76%, transparent);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 89%, transparent);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  pointer-events: none;
}

.map-legend strong {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.legend-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px 10px;
}

.legend-item {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 7px;
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 750;
  line-height: 1.15;
}

.legend-item span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.legend-icon {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
}

.legend-ring {
  fill: var(--surface);
  stroke: var(--line-strong);
  stroke-width: 1.8;
}

.legend-shape {
  fill: currentColor;
  stroke: var(--bg);
  stroke-width: 1.5;
}

.legend-icon.marker-country { color: var(--dot-country); }
.legend-icon.marker-city { color: var(--dot-city); }
.legend-icon.marker-island { color: var(--dot-island); }
.legend-icon.marker-region { color: var(--dot-region); }
.legend-icon.marker-mountain { color: var(--dot-mountain); }
.legend-icon.marker-water { color: var(--dot-water); }

#map-mode-label {
  display: block;
  margin-top: 3px;
  font-size: 17px;
}

.map-actions {
  display: flex;
  gap: 7px;
}

.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 86%, transparent);
  color: var(--ink);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
  backdrop-filter: blur(12px);
}

.map-svg {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

.map-svg.dragging {
  cursor: grabbing;
}

.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 { 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-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;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 22px;
  z-index: 5;
  max-width: min(620px, calc(100% - 44px));
  transform: translateX(-50%);
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  box-shadow: var(--shadow);
  color: var(--ink);
  animation: toast-in 180ms ease both;
  backdrop-filter: blur(12px);
}

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: scale(0.98);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes box-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

@keyframes pulse-stroke {
  0%,
  100% {
    stroke-opacity: 1;
    stroke-width: 3.5;
  }
  50% {
    stroke-opacity: 0.56;
    stroke-width: 7;
  }
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .setup-layout {
    padding: 18px;
  }

  .game-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(560px, 72vh);
    height: auto;
  }

  .side-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .type-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 620px) {
  .access-row,
  .type-grid,
  .setup-footer {
    grid-template-columns: 1fr;
  }

  .map-topbar {
    top: 12px;
    left: 12px;
    right: 12px;
  }

  .map-topbar > div:first-child {
    min-width: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}
