:root {
  --paper: #f3f0e8;
  --ink: #141414;
  --muted: #6f6a5f;
  --line: #d9d3c5;
  --accent: #c8102e;
  --accent-ink: #fff;
  --map-bg: #d0cfd4;
  --chip-green: #2f8f4e;
  --chip-yellow: #c99a00;
  --chip-orange: #dd6a1b;
  --chip-red: #c8102e;
  --font-serif: "Instrument Serif", Georgia, "Times New Roman", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #101010;
    --ink: #f0ece2;
    --muted: #948e80;
    --line: #2a2a2a;
    --accent: #ff3b4e;
    --accent-ink: #101010;
    --map-bg: #232227;
    --chip-green: #4caf6d;
    --chip-yellow: #e0b428;
    --chip-orange: #f07f2e;
    --chip-red: #ff3b4e;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
}

::selection {
  background: var(--accent);
  color: var(--accent-ink);
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.noscript {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 24px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 12px;
  text-align: center;
  z-index: 9999;
}

/* ---------- shell ---------- */

.screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.eyebrow {
  margin: 0 0 18px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.note {
  margin: 18px 0 0;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  line-height: 1.6;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- buttons ---------- */

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 52px;
  padding: 0 22px;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}

.btn--primary {
  background: var(--ink);
  color: var(--paper);
}

@media (hover: hover) and (pointer: fine) {
  .btn--primary:hover:not(:disabled) {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
  }

  .btn--ghost:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
  }
}

.btn:disabled {
  opacity: 0.28;
  cursor: not-allowed;
}

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

/* ---------- intro ---------- */

.screen--intro {
  justify-content: space-between;
  padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  background: var(--paper);
  overflow-y: auto;
}

.intro__main {
  width: 100%;
  max-width: 620px;
  margin: auto 0;
  padding: 6vh 0;
}

.hero {
  margin: 0 0 18px;
  font-family: var(--font-serif);
  font-size: clamp(52px, 15vw, 112px);
  font-weight: 400;
  line-height: 0.86;
  letter-spacing: -0.035em;
}

.hero__dot {
  color: var(--accent);
}

.tagline {
  margin: 0 0 26px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.blurb {
  margin: 0 0 38px;
  max-width: 36ch;
  font-size: 16px;
  line-height: 1.55;
  color: var(--muted);
}

.intro__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.intro__footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px 24px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

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

/* ---------- topbar ---------- */

.topbar {
  position: relative;
  z-index: 600;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: calc(54px + env(safe-area-inset-top));
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.wordmark {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.round-counter {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.progress {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.progress__label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink);
  white-space: nowrap;
}

.progress__dots {
  display: flex;
  align-items: center;
  gap: 5px;
}

.progress__dot {
  width: 8px;
  height: 8px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

.progress__dot.is-done {
  border-color: var(--ink);
  background: var(--ink);
}

.progress__dot.is-current {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
  transform: scale(1.15);
}

/* ---------- game ---------- */

.map {
  flex: 1 1 auto;
  min-height: 0;
  background: var(--map-bg);
  transition: opacity 0.16s ease;
  z-index: 0;
}

.map.is-fading {
  opacity: 0;
}

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

.controls {
  position: relative;
  z-index: 600;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px max(16px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  background: var(--paper);
}

.controls__text {
  min-width: 0;
}

.prompt {
  margin: 0 0 6px;
  font-family: var(--font-serif);
  font-size: 26px;
  font-weight: 400;
  line-height: 1;
  letter-spacing: -0.01em;
}

.hint {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.btn--lock {
  flex: 0 0 auto;
  min-width: 152px;
}

/* ---------- results ---------- */

.screen--results {
  background: var(--paper);
}

.results__body {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(380px, 0.85fr);
  min-height: 0;
}

.map--results {
  height: 100%;
  min-height: 0;
}

.results__panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 32px clamp(24px, 3.4vw, 48px) 0;
  border-left: 1px solid var(--line);
  overflow: hidden;
}

.results__scroll {
  flex: 1 1 auto;
  min-height: 0;
  padding-bottom: 8px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.results__score {
  margin: 0 0 6px;
  font-family: var(--font-serif);
  font-size: clamp(56px, 7vw, 88px);
  font-weight: 400;
  line-height: 0.88;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.results__max {
  margin-left: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--muted);
  white-space: nowrap;
}

.results__tier {
  margin: 0 0 30px;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 23px;
  line-height: 1.2;
}

.results__legend {
  display: grid;
  grid-template-columns: 12px 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.results__list {
  margin: 0 0 30px;
  padding: 0;
  list-style: none;
}

.results__list li {
  display: grid;
  grid-template-columns: 12px 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.02em;
  animation: rise 0.35s ease both;
  animation-delay: calc(var(--i, 0) * 55ms);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}

.row__chip {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.row__chip--green {
  background: var(--chip-green);
}

.row__chip--yellow {
  background: var(--chip-yellow);
}

.row__chip--orange {
  background: var(--chip-orange);
}

.row__chip--red {
  background: var(--chip-red);
}

.row__chip--black {
  background: var(--ink);
}

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

.row__dist {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row__score {
  font-variant-numeric: tabular-nums;
}

.results__actions {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 0 max(24px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--paper);
}

.results__actions .btn {
  flex: 1 1 auto;
}

.results__panel .note {
  margin-top: 16px;
}

/* ---------- map furniture ---------- */

.leaflet-container {
  background: var(--map-bg);
  font-family: var(--font-sans);
}

.leaflet-bar {
  border: 1px solid var(--line) !important;
  border-radius: 0 !important;
  box-shadow: none !important;
}

.leaflet-bar a,
.leaflet-bar a:hover {
  width: 40px !important;
  height: 40px !important;
  line-height: 40px !important;
  border-bottom: 1px solid var(--line) !important;
  border-radius: 0 !important;
  background: var(--paper) !important;
  color: var(--ink) !important;
  font-size: 17px !important;
}

.leaflet-bar a:last-child {
  border-bottom: 0 !important;
}

@media (hover: hover) and (pointer: fine) {
  .leaflet-bar a:hover {
    background: var(--ink) !important;
    color: var(--paper) !important;
  }
}

.leaflet-control-attribution {
  padding: 2px 6px !important;
  background: color-mix(in srgb, var(--paper) 84%, transparent) !important;
  color: var(--muted) !important;
  font-family: var(--font-mono) !important;
  font-size: 9px !important;
  letter-spacing: 0.02em;
}

.leaflet-control-attribution a {
  color: var(--muted) !important;
}

/* ---------- markers ---------- */

.pin,
.target,
.guess {
  background: transparent;
  border: 0;
}

.pin__ring {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: color-mix(in srgb, var(--paper) 78%, transparent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--paper) 70%, transparent);
}

.pin__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.target__dot {
  display: block;
  width: 18px;
  height: 18px;
  border: 3px solid var(--paper);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.target__label {
  position: absolute;
  top: 50%;
  left: 22px;
  transform: translateY(-50%);
  padding: 3px 6px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
}

.guess {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 2px solid var(--paper);
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper);
  box-shadow: 0 0 0 1px var(--ink);
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
}

/* ---------- responsive ---------- */

@media (max-width: 800px) {
  .results__body {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 40dvh minmax(0, 1fr);
  }

  .map--results {
    height: 100%;
  }

  .results__panel {
    border-left: 0;
    border-top: 1px solid var(--line);
    padding: 22px 20px 0;
  }

  .results__tier {
    margin-bottom: 22px;
  }

  .results__list {
    margin-bottom: 22px;
  }
}

@media (max-width: 520px) {
  .controls {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .btn--lock {
    width: 100%;
  }

  .intro__actions {
    flex-direction: column;
  }

  .intro__actions .btn {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.01ms !important;
  }
}
