:root {
  --paper: #f6f8f3;
  --paper-raised: #ffffff;
  --ink: #1e2925;
  --muted: #5f6d67;
  --line: #d7ddd5;
  --course: #a8226f;          /* orienteering overprint */
  --course-soft: #a8226f1a;
  --on-course: #ffffff;
  --contour: #c4925f;
  --found: #2c7a4b;
  --missed: #9b3b2a;
  --focus: #1f6fa8;
  --font: "Familjen Grotesk", ui-sans-serif, system-ui, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #141a18;
    --paper-raised: #1c2421;
    --ink: #e3e9e5;
    --muted: #97a39e;
    --line: #2d3733;
    --course: #e46ab1;
    --course-soft: #e46ab121;
    --on-course: #141a18;
    --contour: #7d6248;
    --found: #5fbf85;
    --missed: #e07b67;
    --focus: #6cb4e6;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #141a18;
  --paper-raised: #1c2421;
  --ink: #e3e9e5;
  --muted: #97a39e;
  --line: #2d3733;
  --course: #e46ab1;
  --course-soft: #e46ab121;
  --on-course: #141a18;
  --contour: #7d6248;
  --found: #5fbf85;
  --missed: #e07b67;
  --focus: #6cb4e6;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
}

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

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.shell {
  max-width: 480px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

/* Header */
.top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 0 8px;
}
.wordmark {
  margin: 0;
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-right: auto;
}
.modes {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px;
}
.mode {
  border: 0;
  background: none;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
}
.mode[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.icon-btn {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 32px; height: 32px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: none;
  font-weight: 600;
  cursor: pointer;
}
.icon-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.status {
  display: flex;
  align-items: center;
  gap: 12px;
}
.puzzle-title {
  margin: 0 auto 0 0;
  color: var(--muted);
  font-size: 0.9375rem;
}

/* Lives: full hearts in the course colour, spent ones as an ink outline. */
.lives { display: flex; gap: 2px; margin: 0; }
.heart { width: 18px; height: 18px; fill: var(--course); stroke: var(--course); stroke-width: 1.5; stroke-linejoin: round; }
.heart.spent { fill: none; stroke: var(--muted); opacity: 0.6; }
.heart.pop { animation: heart-pop 0.4s ease-out; transform-origin: center; }
@keyframes heart-pop { 0% { transform: scale(1.5); } 100% { transform: scale(1); } }

/* Dial */
.dial-wrap { margin: 4px 0 0; }
.dial { display: block; width: 100%; height: auto; overflow: visible; }
.dial-note {
  margin: 2px 0 0;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--muted);
}

.ring { fill: none; stroke: var(--contour); stroke-width: 1; opacity: 0.55; }
.tick { stroke: var(--contour); stroke-width: 1; opacity: 0.7; }
.north { fill: var(--contour); font-size: 11px; font-weight: 600; text-anchor: middle; }

/* The hidden city: an orienteering control circle on a needle, leaning a little
   and casting a shadow. Drawn in the palette's ink, with the course magenta for
   the "?", so it stands apart from the magenta arrows without adding a colour.
   Partly see-through, so arrows behind it stay visible. */
.pin { opacity: 0.9; }
.pin-needle { fill: var(--ink); }
.pin-eye { fill: var(--paper); fill-opacity: 0.82; stroke: var(--ink); stroke-width: 2.75; }
.pin-shine { fill: none; stroke: var(--paper); stroke-opacity: 0.6; stroke-width: 1.25; stroke-linecap: round; }
.pin-mark { fill: var(--course); font-weight: 700; text-anchor: middle; dominant-baseline: central; }
.pin-tick { fill: none; stroke: var(--paper); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.solved .pin-eye { fill: var(--course); fill-opacity: 1; stroke: var(--ink); }
.pin-shadow { fill: var(--ink); opacity: 0.18; }
.pin-ground { fill: none; stroke: var(--ink); stroke-width: 1.25; }
.pin, .pin-ground, .pin-shadow { transform-box: view-box; transform-origin: 0px 0px; }
.pin.drop { animation: pin-drop 0.45s cubic-bezier(0.3, 1.4, 0.6, 1) both; }
.pin-shadow.drop { animation: pin-shadow 0.45s ease-out both; }
.pin-ground.drop { animation: pin-land 0.35s 0.2s ease-out both; }
@keyframes pin-drop { from { transform: translateY(-24px); opacity: 0; } to { transform: none; opacity: 0.9; } }
@keyframes pin-shadow { from { transform: scale(1.6); opacity: 0; } to { transform: none; opacity: 0.18; } }
@keyframes pin-land { from { transform: scale(0); } to { transform: scale(1); } }

.leg { stroke: var(--course); stroke-width: 2; stroke-linecap: round; }
.leg-head { fill: var(--course); }
.clue-name { fill: var(--ink); font-size: 14px; font-weight: 600; }
.clue-country { fill: var(--muted); font-size: 12px; }
.clue-distance { fill: var(--course); font-size: 12px; font-weight: 700; }
.clue-hit { fill: transparent; }

.clue { transition: opacity 0.2s; }
.clue.extra { opacity: 0.45; }
.leg-hit { stroke: transparent; stroke-width: 18; stroke-linecap: round; }
.arrow, .head { transform-box: view-box; }
.leg { transition: stroke-width 0.15s; }
.head { transition: transform 0.15s; }
.clue-name { transition: fill 0.15s; }

/* A new arrow grows out from the centre in its own direction, then its label appears. */
.clue.new .arrow { animation: grow 0.55s cubic-bezier(0.2, 0.8, 0.2, 1) var(--delay) both; }
.clue.new .clue-label { opacity: 0; animation: appear 0.3s calc(var(--delay) + 0.4s) forwards; }
@keyframes grow { from { transform: scale(0); } to { transform: scale(1); } }
@keyframes appear { to { opacity: 1; } }

/* Highlight: hover on devices that have it, a tap on phones, and keyboard focus. */
@media (hover: hover) {
  .clue:hover .leg { stroke-width: 4; }
  .clue:hover .head { transform: scale(1.6); }
  .clue:hover .clue-name { fill: var(--course); }
  .clue:hover { opacity: 1; }
  .dial:not(.measuring):has(.clue:hover) .clue:not(:hover) { opacity: 0.35; }
}
.clue.active .leg, .clue:focus-visible .leg { stroke-width: 4; }
.clue.active .head, .clue:focus-visible .head { transform: scale(1.6); }
.clue.active .clue-name, .clue:focus-visible .clue-name { fill: var(--course); }
.clue.active { opacity: 1; }
.dial.has-active:not(.measuring) .clue:not(.active) { opacity: 0.35; }

.measuring .clue.measurable { cursor: pointer; }
.measuring .clue.measurable .clue-hit { fill: var(--course-soft); stroke: var(--course); stroke-dasharray: 3 3; }
.measuring .clue:not(.measurable) { opacity: 0.4; }
.clue:focus { outline: none; }  /* the label box below shows keyboard focus instead */
.clue:focus-visible .clue-hit { stroke: var(--focus); stroke-width: 2; stroke-dasharray: none; }

/* Hints */
.hints {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 16px;
}
.hint-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper-raised);
  text-align: left;
  cursor: pointer;
}
.hint-btn:hover:not(:disabled) { border-color: var(--course); }
.hint-btn:disabled { cursor: default; opacity: 0.5; }
.hint-btn[aria-pressed="true"] { border-color: var(--course); background: var(--course-soft); }
.hint-label { font-weight: 600; font-size: 0.9375rem; }
.hint-count { font-size: 0.8125rem; color: var(--muted); }

/* Guess form */
.play { margin-top: 16px; }
.guess-form { display: flex; gap: 8px; }
.combo { position: relative; flex: 1; }
#guess-input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  background: var(--paper-raised);
  font-size: 1rem;
}
#guess-input::placeholder { color: var(--muted); }
.guess-btn {
  height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 10px;
  background: var(--course);
  color: var(--on-course);
  font-weight: 700;
  cursor: pointer;
}
.suggestions {
  position: absolute;
  left: 0; right: 0; bottom: calc(100% + 6px);
  margin: 0; padding: 4px;
  list-style: none;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgb(20 30 26 / 0.12);
  z-index: 5;
}
.suggestions li {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.suggestions li[aria-selected="true"] { background: var(--course-soft); }
.sug-name { font-weight: 600; }
.sug-place { color: var(--muted); font-size: 0.875rem; margin-left: 6px; }
.form-msg { min-height: 1.4em; margin: 6px 0 0; font-size: 0.875rem; color: var(--missed); }
.skip-btn {
  display: block;
  margin: 0 auto;
  padding: 6px 10px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 0.875rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.skip-btn:hover, .skip-btn.armed { color: var(--course); }

/* Guesses */
.guesses {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  display: grid;
  gap: 6px;
}
.guess {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
}
.guess-name { font-weight: 600; }
.guess-place { color: var(--muted); font-size: 0.875rem; }
.guess-info { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 0.875rem; color: var(--muted); }
.guess-arrow { width: 16px; height: 16px; color: var(--course); }
.guess.wrong .guess-mark { color: var(--missed); }
.guess.right { border-color: var(--found); }
.guess.right .guess-mark { color: var(--found); }
.guess-mark { font-weight: 700; }

/* Result */
.result {
  margin-top: 16px;
  padding: 16px;
  border-radius: 12px;
  background: var(--paper-raised);
  border: 1px solid var(--line);
}
.result h2 { margin: 0; font-size: 1.5rem; line-height: 1.2; }
.result .verdict { margin: 0 0 2px; font-weight: 600; }
.result.won .verdict { color: var(--found); }
.result.lost .verdict { color: var(--missed); }
.result .note { margin: 8px 0 0; color: var(--muted); }
.round-score { margin: 12px 0 0; color: var(--muted); }
.round-score strong { color: var(--ink); font-size: 1.25rem; }
.final { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.final-label { margin: 0; font-weight: 600; }
.final-score { margin: 0; color: var(--muted); font-size: 1.125rem; }
.final-score strong { color: var(--course); font-size: 2rem; }
.breakdown { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 4px; }
.breakdown li { display: flex; align-items: baseline; gap: 10px; font-size: 0.9375rem; }
.bd-round { width: 1.25em; color: var(--muted); font-variant-numeric: tabular-nums; }
.bd-city { font-weight: 600; }
.bd-country { margin-left: 6px; font-weight: 400; color: var(--muted); font-size: 0.875rem; }
.bd-score { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; }
.breakdown .missed .bd-city, .breakdown .missed .bd-score { color: var(--muted); }
.stats { display: flex; flex-wrap: wrap; gap: 8px 24px; margin: 16px 0 0; padding: 0; }
.stats div { display: flex; flex-direction: column; }
.stats dt { order: 2; font-size: 0.8125rem; color: var(--muted); }
.stats dd { margin: 0; font-size: 1.25rem; font-weight: 700; }
.result-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.secondary-btn {
  height: 48px;
  padding: 0 18px;
  border-radius: 10px;
  border: 1.5px solid var(--ink);
  background: none;
  font-weight: 600;
  cursor: pointer;
}

.credit { margin-top: 32px; font-size: 0.75rem; color: var(--muted); text-align: center; }
.credit a { color: inherit; }

/* Help */
.help {
  max-width: min(400px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper-raised);
  color: var(--ink);
  padding: 20px;
}
.help::backdrop { background: rgb(10 16 14 / 0.45); }
.help h2 { margin: 0 0 8px; font-size: 1.25rem; }
.help p { margin: 0 0 10px; }
.help-small { color: var(--muted); font-size: 0.875rem; }
.help form { margin-top: 16px; }

@media (prefers-reduced-motion: reduce) {
  .clue.new .arrow, .clue.new .clue-label, .pin-ground.drop { animation: none; opacity: 1; }
  .pin-shadow.drop { animation: none; }
  .pin.drop { animation: none; }
  .heart.pop { animation: none; }
  .leg, .head, .clue, .clue-name { transition: none; }
}
