:root {
  --bg: #10161d;
  --panel: #1a232c;
  --panel-2: #223040;
  --text: #e7edf3;
  --muted: #93a4b4;
  --accent: #4aa3df;
  --good: #3fbf6f;
  --bad: #e05555;
  --border: #2e3f52;
  color-scheme: dark;
}

/* browser surfaces carry the design too: dark native controls and
 * scrollbars, gold-tinted selection, themed keyboard focus rings */
::selection { background: rgba(255, 210, 74, 0.35); }
* { scrollbar-color: #3a5270 transparent; scrollbar-width: thin; }

select:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 2px solid #ffd24a;
  outline-offset: 1px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  font-family: "Segoe UI", "Noto Sans", "Noto Sans SC", "Noto Sans TC", system-ui, sans-serif;
  display: flex;
  flex-direction: column;
}

#app-header {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.5rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

#app-header h1 {
  font-size: 1.5rem;
  margin: 0;
  color: var(--accent);
  text-wrap: balance;
}

.controls { display: flex; gap: 1rem; flex-wrap: wrap; min-width: 0; max-width: 100%; }

.controls label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--muted);
}

select, button, input {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.3rem 0.5rem;
  font-size: 0.85rem;
  min-width: 0;
}

select { max-width: 100%; }

.controls label { min-width: 0; }

/* keyboard focus: gold ring on sidebar entries; white ring drawn on
 * the stop dot itself (an outline on an SVG <g> renders unreliably) */
#country-list li:focus-visible {
  outline: 2px solid #ffd24a;
  outline-offset: -2px;
}
#map .stop-dot:focus-visible .dot-core {
  stroke: #ffffff;
  stroke-width: 3.5px;
}
#map .stop-dot:focus { outline: none; }
#stop-popover .stop-pop-item:focus-visible {
  outline: 2px solid #ffd24a;
  outline-offset: -2px;
}

button { cursor: pointer; }
button:hover { border-color: var(--accent); }

main { flex: 1; display: flex; min-height: 0; position: relative; }

#stage { flex: 1; position: relative; min-width: 0; }

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

#map .country {
  fill: #2c3d4f;
  stroke: #6f8ca8;
  stroke-width: 0.4;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
}

/* context countries: same map, outside the lesson — visible for
 * orientation but not clickable and dimmed */
#map .country.context {
  fill: #24303d;
  stroke: #43596f;
  cursor: default;
  pointer-events: none;
}

#map .country:hover { fill: #3a5270; }

#map .country.revealed { fill: #35618a; }
#map .country.current { fill: #4d86c4; }

#map .country.correct { fill: var(--good); }
#map .country.wrong { fill: var(--bad); }
#map .country.dimmed { opacity: 0.35; }
#map .country.highlighted { fill: var(--accent); }

#info-panel .emblems {
  display: flex;
  gap: 14px;
}
#info-panel .emblems figure {
  margin: 0;
  text-align: center;
}
#info-panel .emblems figcaption {
  font-size: 0.8em;
  opacity: 0.75;
  margin-top: 3px;
}
#info-panel .emblems img {
  vertical-align: middle;
  border: 1px solid var(--border, #43596f);
  background: #fff;
}
#info-panel .emblem-flag { width: 63px; }
#info-panel .emblem-arms { width: 80px; }
#info-panel dd div { margin-bottom: 2px; }

#reset-view-button {
  position: absolute;
  right: 12px;
  top: 12px;
  z-index: 5;
  width: 34px;
  height: 34px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
  border-radius: 6px;
}

#map .sphere {
  fill: #0d1420;
  stroke: #43596f;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

#map .graticule {
  fill: none;
  stroke: #22303f;
  stroke-width: 0.5;
  vector-effect: non-scaling-stroke;
}

#map path.arrow {
  fill: none;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
  marker-end: url(#arrowhead);
}

/* journey route legs */
#map path.arrow.route {
  stroke-width: 3;
  stroke-opacity: 0.85;
  marker-end: none;
  stroke-dasharray: none;
}

/* pointing arrow (reveal / sidebar) — thicker than route arrows */
#map path.point-arrow {
  stroke-width: 9;
  vector-effect: non-scaling-stroke;
  stroke: #ffd24a;
  /* butt cap: a round cap would extend past the line end and poke
     through the arrowhead's tip */
  stroke-linecap: butt;
}

#map .target-dot {
  fill: none;
  stroke: #ffd24a;
  stroke-width: 12px;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
  animation: target-pulse 1.2s ease-out infinite;
}

/* journey stop dots: static, clickable; focused one pulses.
 * A dot is TWO zero-length paths with round linecaps — the cap IS
 * the dot, so vector-effect: non-scaling-stroke keeps it a constant
 * SCREEN size at any zoom, with no JS rescaling. */
#map .stop-dot {
  cursor: pointer;
  pointer-events: stroke;
}
#map .stop-dot .dot-halo {
  fill: none;
  stroke: #1b2733;
  stroke-width: 8px;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
#map .stop-dot .dot-core {
  fill: none;
  stroke: #ffd24a;
  stroke-opacity: 0.9;
  stroke-width: 6px;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
#map .stop-dot:hover .dot-core { stroke: #ffe27a; }
#map .stop-dot.focused .dot-core { stroke: #ff9d3c; }
/* pulse animates the core itself (a g can't render a stroke; children
 * with their own stroke-width declarations would ignore an inherited
 * animated value) */
#map .stop-dot.focused .dot-core {
  animation: stop-pulse 1.2s ease-out infinite;
}

/* prefers-reduced-motion: stop the infinite attention pulses; the
 * state they mark stays visible (focused = orange stroke, located =
 * arrow + target dot) — fewer and gentler, not blind */
@media (prefers-reduced-motion: reduce) {
  #map .stop-dot.focused .dot-core,
  #map .target-dot {
    animation: none;
  }
}
#map .stop-dot.multi .dot-core { stroke-width: 7px; }
#map .stop-dot.multi .dot-halo { stroke-width: 9px; }
#stop-popover {
  position: absolute;
  z-index: 40;
  background: #1b2733;
  border: 1px solid rgba(255, 210, 74, 0.4);
  border-radius: 6px;
  padding: 0.3rem 0;
  min-width: 11rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
  font-size: 0.82rem;
}
#stop-popover .stop-pop-item {
  padding: 0.28rem 0.7rem;
  cursor: pointer;
  white-space: nowrap;
}
#stop-popover .stop-pop-item:hover {
  background: rgba(255, 210, 74, 0.15);
}

@keyframes stop-pulse {
  0%   { stroke-width: 6px; stroke-opacity: 0.9; }
  100% { stroke-width: 16px; stroke-opacity: 0; }
}

@keyframes target-pulse {
  0%   { stroke-width: 8px; stroke-opacity: 1; }
  100% { stroke-width: 24px; stroke-opacity: 0; }
}

/* Learn-mode country sidebar */
#country-list-panel {
  width: 220px;
  overflow-y: auto;
  border-right: 1px solid var(--border, #43596f);
  padding: 0.5rem 0.75rem;
  flex-shrink: 0;
}
#country-list-panel h2 {
  /* label-style panel heading: distinct from body via case, weight and
   * tracking instead of competing with the body size */
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 0 0 0.5rem;
  opacity: 0.7;
}
#country-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
#country-list li {
  padding: 4px 6px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.95em;
  line-height: 1.35;
}
#country-list li:hover {
  background: rgba(255, 210, 74, 0.15);
}
#country-list li.visited {
  text-decoration: line-through;
  opacity: 0.55;
}
#country-list li .stop-year {
  display: inline-block;
  min-width: 2.4em;
  margin-right: 0.4em;
  font-size: 0.8em;
  opacity: 0.6;
  font-variant-numeric: tabular-nums;
}
#country-list li .stop-no {
  opacity: 0.45;
  font-size: 0.78em;
  font-variant-numeric: tabular-nums;
}
#country-list li.active {
  background: rgba(255, 210, 74, 0.12);
  outline: 1px solid rgba(255, 210, 74, 0.35);
}
#journey-controls {
  display: inline-flex;
  gap: 0.5rem;
  align-items: center;
  margin-right: 1rem;
}
#journey-counter {
  font-variant-numeric: tabular-nums;
  opacity: 0.8;
}
#choices button .quiz-place {
  font-weight: 600;
}
#choices button .quiz-year {
  font-size: 0.85em;
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
}
#info-facts dd.narrative {
  max-width: 30rem;
  white-space: normal;
  line-height: 1.55;
  text-wrap: pretty;
}

#prompt-bar {
  position: absolute;
  top: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  max-width: min(92%, 42rem);
}

#prompt-text { font-size: 1rem; }
#score-display { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
#restart-button { margin-left: auto; white-space: nowrap; }

#answer-box {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  max-width: 92%;
}

#choices { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; }
#choices button { font-size: 0.95rem; padding: 0.45rem 0.9rem; }

#choices button.correct { border-color: var(--good); color: var(--good); }
#choices button.wrong { border-color: var(--bad); color: var(--bad); }

#text-form { display: flex; gap: 0.5rem; }
#text-input { min-width: 16rem; }
#text-form[hidden] { display: none; }

#info-panel {
  width: 20rem;
  background: var(--panel);
  border-left: 1px solid var(--border);
  padding: 1rem;
  overflow-y: auto;
}

#info-panel[hidden] { display: none; }

#info-close {
  float: right;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  padding: 0 0.3rem;
}

#info-name { margin: 0 0 0.75rem; font-size: 1.25rem; color: var(--accent); text-wrap: balance; }

#info-facts { display: grid; grid-template-columns: auto 1fr; gap: 0.35rem 0.75rem; font-size: 0.9375rem; }
#info-facts dt { color: var(--muted); }
#info-facts dd { margin: 0; }
/* journey stops: stack label above value so long narratives and place
   names get the full panel width instead of being squeezed beside dt */
#info-panel.journey #info-facts {
  grid-template-columns: 1fr;
  gap: 0.15rem 0;
}
#info-panel.journey #info-facts dt {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
#info-panel.journey #info-facts dt:first-child { margin-top: 0; }
#info-panel.journey #info-facts dd.narrative { max-width: none; }

#hint-bar {
  padding: 0.3rem 1rem;
  background: var(--panel);
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.8rem;
  min-height: 1.6rem;
}
