@font-face {
  font-family: "Geist Pixel Square";
  src: url("./assets/geist-pixel-square.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Geist Sans";
  src: url("./assets/geist-sans-variable.woff2") format("woff2");
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --ink: #304136;
  --muted: #626e60;
  --paper: #fbf7ef;
  --paper-hover: #fffdf8;
  --line: #596650;
  --edge: #a4ad98;
  --accent: #e2ebd5;
  --space: #101b22;
  --pixel-font: "Geist Pixel Square", ui-monospace, monospace;
  --body-font: "Geist Sans", system-ui, -apple-system, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --ui-gap: 16px;
  color-scheme: light;
  background: var(--space);
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

*, *::before, *::after { box-sizing: border-box; }
html { height: 100%; overflow: hidden; -webkit-text-size-adjust: 100%; }
html, body { overscroll-behavior: none; touch-action: none; -webkit-touch-callout: none; }
#viewport, .dialog { -webkit-user-select: none; user-select: none; }
body {
  position: relative;
  width: 100vw;
  height: 100vh;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--space);
  font: 400 16px/1.5 var(--body-font);
}
button, input, textarea { font: inherit; }
button { touch-action: none; -webkit-tap-highlight-color: transparent; }
::selection { color: var(--ink); background: var(--accent); }
#viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background:
    url("./assets/stars.svg") 0 0 / 960px 960px repeat,
    radial-gradient(ellipse at 24% 28%, rgb(59 85 87 / 25%), transparent 65%),
    radial-gradient(ellipse at 78% 80%, rgb(43 59 80 / 22%), transparent 60%),
    var(--space);
}
canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
canvas.dragging { cursor: grabbing; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.map-header {
  position: fixed;
  top: calc(var(--ui-gap) + var(--safe-top));
  left: calc(var(--ui-gap) + var(--safe-left));
  right: calc(2 * var(--ui-gap) + var(--safe-right) + 44px);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  pointer-events: none;
}
.map-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.map-brand {
  display: flex;
  flex: none;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  margin: 0;
  padding: 4px 12px 4px 8px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 2px 0 var(--edge), 0 4px 8px rgb(37 48 33 / 12%);
  font: 400 22px/1 var(--pixel-font);
  -webkit-text-stroke: .3px currentColor;
  white-space: nowrap;
}
.map-brand h1 { margin: 0; font: inherit; }
.map-brand img { display: block; flex: none; }
.map-actions, .zoom { display: flex; gap: 10px; }
.map-actions { pointer-events: auto; }
.zoom { position: fixed; top: calc(var(--ui-gap) + var(--safe-top)); right: calc(var(--ui-gap) + var(--safe-right)); flex-direction: column; }
.zoom [data-sound] { margin-top: 6px; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  margin: 0;
  padding: 8px 12px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 2px 0 var(--edge), 0 4px 8px rgb(37 48 33 / 12%);
  font: 400 16px/1.25 var(--pixel-font);
  /* Geist Pixel Square has one weight; a light stroke thickens its letterforms. */
  -webkit-text-stroke: .3px currentColor;
  white-space: nowrap;
  -webkit-user-select: none;
  user-select: none;
  cursor: pointer;
}
.button img { display: block; flex: none; image-rendering: pixelated; }
.button.icon-button { flex: none; width: 44px; height: 44px; padding: 8px; }
.button-primary { background: var(--accent); }
.button-quiet { border-color: transparent; background: transparent; box-shadow: none; }
.button:disabled { opacity: .5; cursor: default; box-shadow: none; }
.button:active:not(:disabled) { transform: translateY(1px); box-shadow: 0 1px 0 var(--edge); background: #eee9de; }
.button-quiet:active:not(:disabled) { box-shadow: none; }
.button:focus-visible, .text-input:focus-visible, .place-card:focus-visible, .contact-topics input:focus-visible, .contact-notice a:focus-visible, canvas:focus-visible { outline: 3px solid #3e7358; outline-offset: 3px; }
canvas:focus-visible { outline-offset: -3px; }

.places-toggle, .contact-toggle {
  position: fixed;
  bottom: calc(var(--ui-gap) + var(--safe-bottom));
}
.places-toggle { left: 50%; transform: translateX(-50%); }
.places-toggle:active:not(:disabled) { transform: translateX(-50%) translateY(1px); }
.places-toggle[aria-expanded="true"] { background: var(--accent); }
.places-toggle[aria-expanded="true"] img { transform: rotate(180deg); }
.contact-toggle { right: calc(var(--ui-gap) + var(--safe-right)); }
.places-panel {
  position: fixed;
  bottom: calc(var(--ui-gap) + var(--safe-bottom) + 56px);
  left: 0;
  right: 0;
  width: min(1100px, 100%);
  margin-inline: auto;
}
.places-list {
  display: grid;
  grid-template-rows: repeat(2, minmax(60px, auto));
  grid-auto-flow: column;
  grid-auto-columns: 144px;
  gap: 10px;
  overflow-x: auto;
  padding: 5px calc(var(--ui-gap) + var(--safe-right)) 10px calc(var(--ui-gap) + var(--safe-left));
  scroll-padding-inline: calc(var(--ui-gap) + var(--safe-left)) calc(var(--ui-gap) + var(--safe-right));
  scroll-snap-type: x proximity;
  overscroll-behavior-x: contain;
  touch-action: pan-x pan-y;
  scrollbar-width: none;
}
.places-list::-webkit-scrollbar { display: none; }
.place-card:focus-visible { outline-offset: -4px; }
.place-card {
  display: flex;
  align-items: center;
  min-width: 0;
  padding: 10px;
  border: 2px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 2px 0 var(--edge), 0 4px 8px rgb(37 48 33 / 12%);
  text-align: left;
  font: 400 14px/1.25 var(--pixel-font);
  -webkit-text-stroke: .2px currentColor;
  cursor: pointer;
  scroll-snap-align: start;
  touch-action: pan-x pan-y;
}
.place-card:active { background: var(--accent); border-color: var(--ink); box-shadow: 0 1px 0 var(--edge); }

.message {
  position: fixed;
  left: calc(var(--ui-gap) + var(--safe-left));
  bottom: calc(var(--ui-gap) + var(--safe-bottom) + 56px);
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(540px, calc(100% - 2 * var(--ui-gap) - var(--safe-left) - var(--safe-right)));
  padding: 8px 12px;
  border: 1px solid #c6cbbb;
  border-radius: 6px;
  background: var(--paper);
  font-size: 12px;
}
.message .button { flex: none; font-size: 14px; }
.message #status:empty { display: none; }
.location-message {
  position: static;
  max-width: min(420px, 100%);
  z-index: 1;
  pointer-events: none;
}
#viewport:has(#places-controls:not([hidden]) #places-panel:not([hidden])) #map-message { bottom: calc(var(--ui-gap) + var(--safe-bottom) + 220px); }

.dialog {
  position: fixed;
  touch-action: pan-y;
  inset: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  width: min(480px, calc(100% - 40px - var(--safe-left) - var(--safe-right)));
  max-height: calc(100% - 48px - var(--safe-top) - var(--safe-bottom));
  margin: auto;
  padding: 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 2px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 4px 0 var(--edge), 0 16px 48px rgb(24 37 27 / 20%);
}
.dialog::backdrop { background: rgb(20 31 23 / 32%); }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.dialog-tools { display: flex; flex: none; gap: 4px; }
.dialog-heading h2 { min-width: 0; margin: 0; font: 400 22px/1.3 var(--pixel-font); text-wrap: balance; }
.dialog p { margin: 0 0 24px; color: var(--muted); text-wrap: pretty; }
.dialog label { display: block; margin: 0 0 8px; font: 600 14px/1.4 var(--body-font); }
.text-input {
  -webkit-user-select: text;
  user-select: text;
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 12px;
  border: 1px solid #a6ae9c;
  border-radius: 6px;
  background: #fffdf8;
  color: var(--ink);
  font: 400 16px/1.5 var(--body-font);
}
.dialog-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 16px; margin-top: 24px; }
.dialog-actions .button { flex: none; }
.dialog-action-buttons { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-left: auto; }
.dialog-action-buttons a { text-decoration: none; }
.contact-topics { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 20px; padding: 0; border: 0; }
.contact-topics legend { margin-bottom: 8px; font-size: 14px; font-weight: 600; }
.contact-topics label { display: flex; align-items: center; gap: 8px; min-height: 44px; margin: 0; padding: 8px 10px; border: 1px solid var(--edge); border-radius: 6px; font-weight: 400; cursor: pointer; }
.contact-topics label:has(input:checked) { background: var(--accent); border-color: var(--line); }
.contact-topics input { flex: none; width: 16px; height: 16px; margin: 0; accent-color: var(--ink); }
.contact-field { margin-bottom: 20px; }
.field-optional { font-weight: 400; color: var(--muted); }
#contact-message { display: block; min-height: 112px; resize: vertical; touch-action: pan-y; }
.contact-dialog .contact-notice { margin: 0 0 20px; font-size: 13px; }
.contact-notice a { color: var(--ink); text-underline-offset: 3px; }
.contact-submit { width: 100%; }
.contact-dialog #contact-status { margin: 0 0 16px; font-size: 14px; color: var(--ink); }
.contact-dialog #contact-status[data-state="error"] { color: #8b352c; }
.contact-submit:disabled { opacity: 1; color: var(--muted); background: #e9e9df; border-color: var(--edge); }
#share-status { font-size: 14px; }
.share-image-preview { display: block; width: 100%; height: clamp(96px, 20vh, 150px); object-fit: contain; background: var(--space); border: 2px solid var(--line); margin-bottom: 12px; }
.share-image-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.share-image-actions:has(#share-image-native[hidden]) { grid-template-columns: 1fr; }
.share-image-actions:has(.button:not([hidden])) { margin-bottom: 16px; }
.share-image-actions .button { min-width: 0; padding-inline: 8px; font-size: 14px; white-space: normal; text-align: center; }
.share-image-actions a { text-decoration: none; }
#share-dialog #share-description { margin-bottom: 12px; }
#share-dialog .dialog-actions { margin-top: 16px; gap: 8px; }
#share-dialog:has(#share-image-preview:not([hidden])) .dialog-action-buttons { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; gap: 8px; }
#share-dialog:has(#share-image-preview:not([hidden])) .dialog-action-buttons .button { min-width: 0; padding-inline: 8px; gap: 6px; font-size: 14px; }
#share-status:empty { display: none; }
[hidden] { display: none !important; }

@media (hover: hover) and (pointer: fine) {
  .button:hover:not(:disabled) { background: var(--paper-hover); border-color: var(--ink); }
  .button-primary:hover:not(:disabled) { background: #edf3e4; }
  .button-quiet:hover:not(:disabled) { background: #edece2; border-color: transparent; }
  .place-card:hover { background: var(--paper-hover); border-color: var(--ink); }
  .contact-topics label:hover { border-color: var(--ink); }
}
@media (prefers-reduced-motion: reduce) {
  .button:active:not(:disabled) { transform: none; }
  .places-toggle:active:not(:disabled) { transform: translateX(-50%); }
}
@media (max-width: 650px) {
  :root { --ui-gap: 12px; }
  .map-brand { font-size: 20px; }
  .map-actions, .zoom { gap: 8px; }
  .map-actions .button { padding-inline: 10px; gap: 6px; font-size: 14px; }
  .dialog { padding: 20px; }
  .dialog-heading h2 { font-size: 20px; }
  .contact-toggle { width: 44px; padding: 8px; }
  .contact-toggle span { display: none; }
}
@media (max-width: 380px) {
  .map-actions { flex-direction: column; align-items: flex-start; }
  .dialog-actions { flex-direction: column-reverse; align-items: flex-end; gap: 12px; }
  #share-dialog:has(#share-image-preview:not([hidden])) .dialog-action-buttons .button { padding-inline: 6px; gap: 5px; font-size: 12px; }
  #share-dialog:has(#share-image-preview:not([hidden])) .dialog-action-buttons img { width: 18px; height: 18px; }
  .message { flex-wrap: wrap; }
}
@media (max-height: 650px) {
  .share-image-preview { height: 80px; }
}

#viewport:has(#game-panel:not([hidden])) :is(.map-brand, #fit, #locate, #share, #contact) { display: none; }

.game-panel {
  position: fixed;
  left: calc(var(--ui-gap) + var(--safe-left));
  bottom: calc(var(--ui-gap) + var(--safe-bottom));
  width: min(360px, calc(100% - 2 * var(--ui-gap) - var(--safe-left) - var(--safe-right)));
  max-height: calc(100% - 88px - var(--safe-top) - var(--safe-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 20px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: 0 3px 0 var(--edge), 0 8px 24px rgb(0 0 0 / 16%);
}
.game-eyebrow { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 12px; font-weight: 650; font-variant-numeric: tabular-nums; }
.game-progress { display: flex; gap: 5px; margin: 12px 0 16px; }
.game-progress span { flex: 1; height: 4px; background: #d9ddce; }
.game-progress .done { background: #59836b; }
.game-progress .current { background: var(--ink); }
.game-panel h2 { margin: 0 0 8px; font: 400 22px/1.2 var(--pixel-font); text-wrap: balance; }
.game-panel h2:focus { outline: none; }
.game-panel p { margin: 0 0 16px; color: var(--muted); font-size: 14px; }
.game-panel-actions { display: grid; gap: 8px; }
.game-panel-actions .button { width: 100%; }
.game-panel #game-fact, .game-panel #game-hint { color: var(--ink); }
.game-panel #game-round-points { margin: -4px 0 12px; font-size: 12px; }
.game-score { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 12px 0; }
.game-score strong { font: 400 32px/1 var(--pixel-font); font-variant-numeric: tabular-nums; }
.game-score span { color: var(--muted); font-size: 13px; text-align: right; }
.game-panel .game-legend { display: flex; gap: 18px; margin: 0 0 16px; font-size: 12px; }
.game-legend span::before { content: ''; display: inline-block; width: 12px; height: 12px; margin-right: 6px; border: 2px solid #21392d; background: #f3bc7c; vertical-align: -1px; }
.game-legend .target-key::before { background: #b7efd0; }
.game-kicker { color: var(--muted); font: 650 12px/1.4 var(--body-font); }
.game-dialog h2 { margin: 0 0 12px; font: 400 30px/1.2 var(--pixel-font); text-wrap: balance; }
.game-dialog .game-date { margin-bottom: 24px; font-size: 13px; font-variant-numeric: tabular-nums; }
.game-rules { margin: 0 0 24px; padding-left: 22px; color: var(--ink); font-size: 14px; }
.game-rules li + li { margin-top: 8px; }
.game-intro-actions { display: grid; gap: 10px; margin-top: 24px; }
.game-intro-actions .button { width: 100%; white-space: normal; }
.game-dialog .game-complete-note { margin: 0 0 18px; color: var(--ink); font-weight: 500; }
.game-dialog #game-error { margin: 18px 0 0; color: #8b352c; font-size: 14px; }
.game-dialog .results-score { margin: 18px 0 8px; color: var(--ink); }
.results-score strong { font: 400 40px/1 var(--pixel-font); font-variant-numeric: tabular-nums; }
.results-score span { font-size: 14px; }
.game-dialog #results-hits { font-size: 14px; margin-bottom: 12px; }
.results-list { list-style: none; counter-reset: round; margin: 0; padding: 0; }
.results-list li { counter-increment: round; display: flex; gap: 12px; padding: 10px 0; border-top: 1px solid #d8dccf; align-items: baseline; font-size: 14px; }
.results-list li::before { content: counter(round, decimal-leading-zero); color: var(--muted); font: 400 14px var(--pixel-font); }
.results-list .result-name { flex: 1; min-width: 0; }
.results-list small { display: block; color: var(--muted); }
.results-list strong { font-variant-numeric: tabular-nums; white-space: nowrap; }
#share-result-text { resize: vertical; margin-top: 12px; min-height: 130px; font-size: 14px; touch-action: pan-y; }
canvas.picking { cursor: crosshair; }
canvas.picking.dragging { cursor: grabbing; }
#game-crosshair { position: absolute; left: 50%; top: 50%; width: 18px; height: 18px; margin: -9px; border: 2px solid var(--paper); box-shadow: 0 0 0 2px var(--ink); pointer-events: none; opacity: 0; }
canvas:focus-visible ~ #game-crosshair { opacity: 1; }
@media (max-width: 650px) {
  .map-actions #fit, .map-actions #locate, .map-actions #share { width: 44px; padding: 8px; }
  .map-actions #fit span, .map-actions #locate span, .map-actions #share span { display: none; }
  #viewport:has(#game-panel:not([hidden])) {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto;
    align-content: start;
    gap: 12px;
    padding: calc(var(--ui-gap) + var(--safe-top)) calc(var(--ui-gap) + var(--safe-right)) calc(var(--ui-gap) + var(--safe-bottom)) calc(var(--ui-gap) + var(--safe-left));
  }
  #viewport:has(#game-panel:not([hidden])) #map { position: absolute; inset: 0; }
  #viewport:has(#game-panel:not([hidden])) .map-header { position: relative; inset: auto; grid-area: 2 / 1; }
  #viewport:has(#game-panel:not([hidden])) .zoom { display: none; }
  .game-panel {
    position: relative;
    grid-area: 1 / 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
    inset: auto;
    width: 100%;
    max-height: min(50vh, calc(100vh - 88px - var(--safe-top) - var(--safe-bottom)));
    overflow: hidden;
    padding: 16px;
  }
  .game-panel-content { min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
  .game-panel #game-instruction, .game-panel #game-hint, .game-panel .game-legend { margin-bottom: 0; }
  .game-panel #game-feedback:not([hidden]), .game-panel #game-hint:not([hidden]) { margin-top: 12px; }
  .game-panel-actions:has(#use-hint:not([hidden])) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .game-panel-actions .button { min-width: 0; padding-inline: 8px; font-size: 14px; white-space: normal; }
  .game-panel-actions { flex: none; }
  .game-panel h2 { font-size: 20px; }
  .game-progress { margin: 10px 0 12px; }
  .game-dialog h2 { font-size: 27px; }
}
@media (max-width: 380px) {
  .map-actions { flex-direction: row; align-items: center; }
}
@media (max-height: 520px) and (min-width: 651px) {
  .game-panel { padding: 12px 16px; max-height: calc(100% - 88px - var(--safe-top) - var(--safe-bottom)); }
  .game-panel h2 { font-size: 18px; }
  .game-progress { margin: 8px 0; }
}

.game-stats { display: grid; grid-template-columns: 1fr 1fr 1.3fr; gap: 12px; padding: 16px 0; margin: 0 0 12px; border-top: 2px solid var(--edge); }
.game-stats div { display: grid; grid-template-rows: auto 1fr; gap: 6px; text-align: center; }
.game-stats dt { grid-row: 2; font-size: 12px; color: var(--muted); }
.game-stats dd { grid-row: 1; margin: 0; font: 400 22px/1.2 var(--pixel-font); font-variant-numeric: tabular-nums; }
.game-dialog .results-next { margin: 8px 0 0; padding-top: 16px; border-top: 2px solid var(--edge); font-size: 14px; text-align: center; }
