: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;
}

/* Tries left: filled pips in the course colour, spent ones as an outline. */
.tries { display: flex; gap: 4px; margin: 0; }
.pip { width: 10px; height: 10px; border-radius: 50%; background: var(--course); border: 1.5px solid var(--course); }
.pip.spent { background: none; border-color: var(--muted); opacity: 0.6; }

.task { margin: 14px 0 8px; font-size: 1.375rem; line-height: 1.2; letter-spacing: -0.01em; }

/* Board: fixed slot numbers on the left, the cities move between them. */
.rule { margin: -4px 0 12px; color: var(--muted); font-size: 0.9375rem; }
.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.cards li { display: flex; align-items: center; gap: 10px; }
.slot {
  flex-shrink: 0;
  width: 1.5em;
  text-align: center;
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--contour);
}
.cards li.locked .slot { color: var(--found); }
.card {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  flex: 1; min-width: 0; min-height: 56px;
  padding: 8px 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--paper-raised);
  text-align: left;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: border-color 0.15s, background-color 0.15s;
}
.card-flag { font-size: 1.375rem; line-height: 1; }
.card-text { display: flex; flex-direction: column; min-width: 0; }
.card-name { font-weight: 600; }
.card-place { color: var(--muted); font-size: 0.8125rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-side { margin-left: auto; display: flex; align-items: center; gap: 6px; font-size: 0.875rem; font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.card-mark { font-weight: 700; color: var(--found); }

@media (hover: hover) { .card:not(.locked):hover { border-color: var(--course); } }
.card.selected { border-color: var(--course); background: var(--course-soft); }
.card.dragging { z-index: 3; cursor: grabbing; box-shadow: 0 12px 28px rgb(20 30 26 / 0.2); border-color: var(--course); transition: none; }
/* While dragging, the other cards glide out of the way to show where it will land. */
.cards.sorting .card:not(.dragging) { transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1); }
.card.locked { cursor: default; border-color: var(--found); }
.card.wrong { animation: nudge 0.35s ease-out; }
@keyframes nudge { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.card.missed { border-color: var(--line); }
.card.missed .card-name { color: var(--muted); }

/* After the game each card shows where its city sits along today's axis. */
.card-ruler { position: absolute; left: 12px; right: 12px; bottom: 5px; height: 2px; background: var(--line); border-radius: 1px; }
.card-ruler i { position: absolute; top: -3px; width: 8px; height: 8px; margin-left: -4px; border-radius: 50%; background: var(--course); }
.done .card { padding-bottom: 14px; cursor: default; }

.how { margin: 8px 0 0; font-size: 0.8125rem; color: var(--muted); text-align: center; }

.play { margin-top: 14px; }
.check-btn {
  width: 100%;
  height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 10px;
  background: var(--course);
  color: var(--on-course);
  font-weight: 700;
  cursor: pointer;
}
.help .check-btn { width: auto; }
.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 { color: var(--course); }
.skip-btn[hidden] { display: none; }
.form-msg { min-height: 1.4em; margin: 6px 0 0; font-size: 0.875rem; color: var(--muted); text-align: center; }

/* Result */
.result {
  margin-top: 16px;
  padding: 16px;
  border-radius: 12px;
  background: var(--paper-raised);
  border: 1px solid var(--line);
}
.result .verdict { margin: 0 0 2px; font-weight: 600; }
.result.won .verdict { color: var(--found); }
.result.lost .verdict { color: var(--missed); }
.result h2 { margin: 0; font-size: 1.5rem; line-height: 1.2; }
.result .note { margin: 8px 0 0; }
.grid { margin: 12px 0 0; font-size: 1.125rem; line-height: 1.25; letter-spacing: 0.05em; }
.result-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.result-actions .check-btn { width: auto; }
.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) {
  .card.wrong { animation: none; }
  .cards.sorting .card:not(.dragging) { transition: none; }
}
