:root {
  --paper: #fffaf3;
  --paper-2: #f6f0e6;
  --ink: #1c2421;
  --muted: #5e6a64;
  --line: #e4d9c8;
  --teal: #1f5c57;
  --teal-deep: #143f3b;
  --ocean: #c5d7db;
  --land: #f4ecde;
  --land-edge: #8d8170;
  --dim: #e3d9c8;
  --amber: #e39a45;
  --good: #2f7d4a;
  --good-bg: #e7f5ec;
  --bad: #a33b32;
  --bad-bg: #fdeceb;
  --shadow: 0 22px 60px rgba(28, 40, 38, 0.16);
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Outfit", "Avenir Next", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  color: var(--ink);
  font-family: var(--sans);
  background: var(--ocean);
  overflow: hidden;
}

button, input { font: inherit; color: inherit; }

#app { height: 100%; position: relative; }

#map {
  width: 100%;
  height: 100%;
  display: block;
  background: #d5e4e6;
  touch-action: none;
  cursor: default;
}

.sphere { fill: #c5d8dc; stroke: #9eb8be; stroke-width: 1; }

.graticule {
  fill: none;
  stroke: rgba(255, 255, 255, 0.55);
  stroke-width: 0.6;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.land {
  fill: #c9d4d2;
  stroke: #b4c2c0;
  stroke-width: 0.7;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.land.in-scope {
  fill: var(--land);
  stroke: var(--land-edge);
}

.land.is-target {
  fill: var(--amber);
  stroke: #8a4b12;
  stroke-width: 1.6;
  animation: pulse 1.6s ease-in-out infinite;
}

.land.is-correct {
  fill: #74c48c;
  stroke: #1d6434;
  stroke-width: 1.6;
}

.land.is-wrong {
  fill: #e59a94;
  stroke: #8d2f28;
  stroke-width: 1.5;
}

.land.is-selected {
  fill: #e7b15a;
  stroke: #7a4e16;
  stroke-width: 1.7;
}

@keyframes pulse {
  0%, 100% { fill: #e39a45; }
  50% { fill: #f6c888; }
}

.map-chrome {
  position: absolute;
  top: max(18px, env(safe-area-inset-top));
  right: max(18px, env(safe-area-inset-right));
  display: flex;
  gap: 8px;
  align-items: center;
  z-index: 2;
}

#focus-label, #reset-view, #map-prompt {
  background: rgba(255, 250, 243, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.7);
  box-shadow: 0 8px 24px rgba(28, 40, 38, 0.08);
  backdrop-filter: blur(8px);
}

#focus-label {
  margin: 0;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.92rem;
  font-weight: 500;
}

#reset-view {
  border-radius: 999px;
  padding: 8px 12px;
  cursor: default;
}

#reset-view:hover { background: white; }

#quiz-bar {
  display: flex;
  gap: 8px;
  align-items: center;
}

#quiz-bar[hidden] { display: none !important; }

.score-pill,
.continue-pill,
.text-pill {
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(255, 250, 243, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.7);
  box-shadow: 0 8px 24px rgba(28, 40, 38, 0.08);
}

.continue-pill {
  background: var(--teal);
  color: white;
  border-color: var(--teal);
  font-weight: 600;
  cursor: default;
}

.text-pill {
  color: var(--teal);
  font-weight: 600;
  cursor: default;
}

#map-prompt {
  position: absolute;
  top: max(18px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  right: max(16px, env(safe-area-inset-right));
  z-index: 2;
  display: flex;
  justify-content: center;
  pointer-events: none;
  background: transparent;
  border: 0;
  box-shadow: none;
  backdrop-filter: none;
}

#map-prompt span,
#map-prompt {
  text-align: center;
}

#map-prompt span {
  font-family: var(--serif);
  font-size: 1.35rem;
  letter-spacing: -0.03em;
  background: rgba(255, 250, 243, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 8px 24px rgba(28, 40, 38, 0.08);
  border-radius: 999px;
  padding: 8px 16px;
}

#map-prompt:not([hidden]) {
  display: flex;
}

#tooltip {
  position: fixed;
  z-index: 5;
  transform: translate(-50%, calc(-100% - 12px));
  background: var(--ink);
  color: white;
  padding: 6px 9px;
  border-radius: 8px;
  font-size: 0.85rem;
  pointer-events: none;
  white-space: nowrap;
}

#panel {
  position: absolute;
  z-index: 3;
  top: max(16px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  bottom: max(16px, env(safe-area-inset-bottom));
  width: min(400px, calc(100vw - 32px));
  overflow: auto;
  background: rgba(255, 250, 243, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  padding: 22px 20px 28px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.mark {
  width: 46px;
  height: 46px;
  flex: none;
  color: var(--teal);
}

.wordmark {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.7rem;
  letter-spacing: -0.04em;
  line-height: 1;
}

.tag, .lede, .help, .note, .score-line, .progress-label, .place-kicker, .kicker {
  color: var(--muted);
}

.tag { margin: 4px 0 0; font-size: 0.95rem; }

.modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 18px 0;
  padding: 4px;
  background: var(--paper-2);
  border-radius: 14px;
}

.modes button, .lengths button, .choice, .primary, .text, .ghost, .switch, .type, .chip, .group-toggle, .place {
  border: 0;
  background: transparent;
  cursor: default;
}

.modes.tiers { grid-template-columns: repeat(3, 1fr); }

.modes button {
  border-radius: 11px;
  padding: 9px 10px;
  font-weight: 600;
}

.modes button.is-on {
  background: white;
  box-shadow: 0 1px 4px rgba(28, 40, 38, 0.08);
  color: var(--teal-deep);
}

.section-head, .row-between {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

h2, h3, p { margin-top: 0; }

h2 {
  font-family: var(--serif);
  font-weight: 560;
  letter-spacing: -0.03em;
  font-size: 1.55rem;
  margin-bottom: 8px;
}

h3 {
  margin: 16px 0 8px;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.pool {
  margin: 0 0 8px;
  font-weight: 600;
}

.region-tools { display: flex; gap: 8px; }

.ghost, .text {
  color: var(--teal);
  font-weight: 600;
  padding: 0;
}

.group { margin-top: 14px; }

.group-toggle {
  display: flex;
  width: 100%;
  justify-content: space-between;
  align-items: center;
  padding: 0 0 8px;
  font-weight: 650;
  font-size: 1rem;
}

.group-toggle .tick {
  width: 18px;
  height: 18px;
  border-radius: 6px;
  border: 1.5px solid #c9bfb0;
  display: inline-grid;
  place-items: center;
  color: white;
  font-size: 0.75rem;
}

.group-toggle.is-on .tick, .chip.is-on {
  background: var(--teal);
  color: white;
  border-color: var(--teal);
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  border: 1px solid var(--line);
  background: white;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.92rem;
}

.chip.is-on { border-color: var(--teal); }

.region-note {
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.region-note summary { cursor: default; }

.continent-list {
  display: grid;
  gap: 8px;
}

.continent-card {
  display: flex;
  width: 100%;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  text-align: left;
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: white;
  cursor: default;
}

.continent-card strong {
  display: block;
  font-family: var(--serif);
  font-size: 1.45rem;
  font-weight: 560;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.continent-card small,
.continent-card .go {
  color: var(--muted);
}

.continent-card .go {
  font-weight: 600;
  color: var(--teal);
}

.continent-card:hover {
  border-color: var(--teal);
  background: #f3faf8;
}

.type, .switch {
  display: flex;
  width: 100%;
  text-align: left;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: white;
}

.type { align-items: flex-start; }

.type.is-on, .switch.is-on { border-color: #b7d0cb; background: #f3faf8; }

.type-name, .switch strong { display: block; font-weight: 600; }

.type-copy, .switch small, .help, .note, .lede {
  display: block;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.4;
}

.lengths { display: flex; gap: 6px; }

.lengths button {
  flex: 1;
  border-radius: 12px;
  padding: 10px 0;
  border: 1px solid var(--line);
  background: white;
  font-weight: 600;
}

.lengths button.is-on {
  background: var(--teal);
  color: white;
  border-color: var(--teal);
}

.switch { justify-content: space-between; margin-top: 8px; }

.knob {
  width: 42px;
  height: 26px;
  border-radius: 999px;
  background: #ddd4c8;
  position: relative;
  flex: none;
}

.knob::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: white;
  transition: transform 0.15s ease;
}

.switch.is-on .knob { background: var(--teal); }
.switch.is-on .knob::after { transform: translateX(16px); }

.start-bar { margin-top: 16px; }

.primary {
  width: 100%;
  margin-top: 16px;
  background: var(--teal);
  color: white;
  border-radius: 999px;
  padding: 14px 16px;
  font-weight: 600;
}

.start-bar .primary { margin-top: 0; }

.primary:hover { background: var(--teal-deep); }

.primary.home {
  background: transparent;
  color: var(--teal);
  border: 1px solid var(--line);
}

.primary.home:hover { background: white; }

.primary.alt { background: var(--teal-deep); }

.primary:disabled {
  background: #c9c2b6;
  cursor: default;
}

.quiz-top { margin-bottom: 16px; }

.bar {
  height: 6px;
  background: #efe6d8;
  border-radius: 99px;
  overflow: hidden;
  margin-top: 8px;
}

.bar span {
  display: block;
  height: 100%;
  background: var(--teal);
}

.prompt h2 {
  font-family: var(--serif);
  font-size: clamp(2rem, 5vw, 2.7rem);
  line-height: 1.02;
  letter-spacing: -0.04em;
  margin: 4px 0 8px;
  text-wrap: balance;
}

.kicker {
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
}

.choices { display: grid; gap: 8px; margin-top: 14px; }

.choice {
  text-align: left;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: white;
  font-weight: 550;
}

.choice:hover:not(:disabled) { border-color: var(--teal); }

.choice.is-correct {
  background: var(--good-bg);
  border-color: var(--good);
  color: #145231;
}

.choice.is-wrong {
  background: var(--bad-bg);
  border-color: var(--bad);
  color: #7a241e;
}

.choice:disabled { cursor: default; }

.key-hint { margin: 8px 0 0; }

.result {
  margin-top: 16px;
  padding: 14px;
  border-radius: 16px;
}

.result.is-good { background: var(--good-bg); }
.result.is-bad { background: var(--bad-bg); }

.result p { margin: 0 0 12px; line-height: 1.45; }

.actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
}

.score-hero {
  font-family: var(--serif);
  font-size: 3.2rem;
  letter-spacing: -0.04em;
  margin: 0;
  line-height: 0.95;
}

.misses { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }

.misses button, .place {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 12px;
  background: white;
  border: 1px solid var(--line);
}

.misses button small, .place small { color: var(--muted); display: block; }

.search {
  width: 100%;
  border: 1px solid var(--line);
  background: white;
  border-radius: 12px;
  padding: 11px 12px;
  margin: 8px 0 12px;
}

.place-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  max-height: 280px;
  overflow: auto;
}

.place { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }

.place.is-on { border-color: var(--teal); background: #f3faf8; }

.capital { margin: 0 0 6px; font-weight: 600; }

.detail { margin-bottom: 8px; }

.loading { color: var(--muted); }

button:focus-visible, input:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

@media (max-width: 860px) {
  #panel {
    top: auto;
    height: min(48vh, 460px);
    width: auto;
    right: max(10px, env(safe-area-inset-right));
    left: max(10px, env(safe-area-inset-left));
    bottom: max(10px, env(safe-area-inset-bottom));
  }

  #panel.is-results {
    height: auto;
  }

  #map-prompt {
    top: calc(52px + env(safe-area-inset-top));
    font-size: 1.15rem;
  }

  .map-chrome {
    top: max(8px, env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
    right: max(12px, env(safe-area-inset-right));
    justify-content: space-between;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
