:root {
  color-scheme: light;
  --paper: #faf6ed;
  --ink: #102348;
  --muted: #485976;
  --blue: #064dc6;
  --line: #d6d6cc;
  --serif: Georgia, "Times New Roman", serif;
  font: 100%/1.45 system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100svh; display: flex; flex-direction: column; }
a { color: inherit; }
button { font: inherit; }
button:not(:disabled) { cursor: pointer; }
button:focus-visible, a:focus-visible, #map:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 3px;
}
[hidden] { display: none !important; }

.masthead {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: .15rem .65rem;
  padding: .3rem max(1rem, env(safe-area-inset-right)) .35rem max(1rem, env(safe-area-inset-left));
  border-bottom: 1px solid #b7c0c8;
}
.identity {
  display: flex;
  align-items: center;
  gap: .6rem;
  min-height: 2.75rem;
  font: bold 1.3rem/1.12 var(--serif);
  letter-spacing: -.035em;
}
.identity-full { display: none; }
.identity svg {
  width: 1.6rem;
  height: 1.65rem;
  flex: none;
  fill: none;
  stroke: var(--blue);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.4;
}
.game-status {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: auto minmax(1rem, 1fr) auto;
  align-items: center;
  gap: .65rem;
  padding: 0 0 .25rem;
  font-size: .75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.menu-link {
  grid-column: 2;
  grid-row: 1;
  min-height: 2.75rem;
  padding: 0 .65rem;
  border: 0;
  border-radius: .28rem;
  background: #e9edf0;
  color: var(--blue);
  font-size: .77rem;
  font-weight: 700;
}
.menu-link:hover { background: #dbe6f3; }
.wallet {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .45rem;
  color: var(--muted);
  font-size: .74rem;
}
.wallet strong {
  border: 1px solid #a7bdd4;
  border-radius: 999px;
  padding: .33rem .72rem;
  background: #e1ebf5;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
progress {
  appearance: none;
  width: 100%;
  height: .38rem;
  border: 0;
  border-radius: 1rem;
  background: #d3e0e8;
  accent-color: var(--blue);
  overflow: hidden;
}
progress::-webkit-progress-bar { background: #d3e0e8; }
progress::-webkit-progress-value { background: var(--blue); border-radius: 1rem; }
progress::-moz-progress-bar { background: var(--blue); border-radius: 1rem; }

.game {
  display: grid;
  flex: 1;
  grid-template-rows: auto minmax(14rem, 1fr) auto;
}
.question { min-width: 0; padding: .66rem 1rem .75rem; }
.mode {
  margin: 0 0 .3rem;
  color: #21416d;
  font: italic .97rem/1.3 var(--serif);
}
.mode::after {
  display: block;
  width: 1.7rem;
  height: 2px;
  margin-top: .25rem;
  background: var(--blue);
  content: "";
}
h1, h2 {
  margin: 0;
  font: bold clamp(1.8rem, 7.6vw, 3.25rem)/1.04 var(--serif);
  letter-spacing: -.055em;
  overflow-wrap: anywhere;
}
#instruction {
  margin: .36rem 0 0;
  color: var(--muted);
  font-size: .91rem;
}
.map-area {
  position: relative;
  isolation: isolate;
  min-width: 0;
  min-height: 14rem;
  background: #eae6db;
  border-block: 1px solid var(--line);
}
#map { position: absolute; inset: 0; background: #eae6db; }
#map:focus-visible { outline-offset: -4px; }
.game[data-mode="find"] #map:focus-visible::after {
  content: "+";
  position: absolute;
  z-index: 450;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--ink);
  text-shadow: 0 0 3px white, 0 0 5px white;
  font: bold 1.75rem/1 system-ui, sans-serif;
  pointer-events: none;
}
.map-caption {
  display: none;
  position: absolute;
  z-index: 500;
  top: .65rem;
  left: .65rem;
  padding: .27rem .5rem;
  border: 1px solid #d5d5ca;
  border-radius: .2rem;
  background: var(--paper);
  font: italic .8rem var(--serif);
  pointer-events: none;
}
.map-controls {
  position: absolute;
  z-index: 500;
  right: .65rem;
  bottom: 1.55rem;
  display: grid;
  grid-auto-flow: column;
  overflow: hidden;
  border: 1px solid #68758b;
  border-radius: .45rem;
  background: var(--paper);
  box-shadow: 0 2px 8px #1023481c;
}
.map-controls button {
  width: 2.75rem;
  height: 2.75rem;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 1.5rem;
  line-height: 1;
}
.map-controls button + button { border-left: 1px solid var(--line); }
.map-controls button:focus-visible { outline-offset: -4px; }
.map-controls button:hover { background: #e5eefa; }
.map-controls button:disabled { color: #76849a; }
.map-credit {
  position: absolute;
  z-index: 500;
  bottom: 0;
  right: 0;
  padding: .15rem .35rem;
  background: var(--paper);
  font-size: .66rem;
}
.leaflet-bottom.leaflet-left { bottom: .65rem; left: .45rem; }
.leaflet-control-scale-line { background: var(--paper); color: var(--ink); }
.guess-pin { overflow: visible !important; }
.guess-pin svg { display: block; filter: drop-shadow(0 2px 2px #10234855); }

.actions {
  min-width: 0;
  padding: .64rem max(1rem, env(safe-area-inset-right)) max(.72rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}
.game[data-mode="menu"] {
  position: relative;
  grid-template: "atlas" minmax(24rem, 1fr) / minmax(0, 1fr);
}
.game[data-mode="menu"] .question {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.game[data-mode="menu"] .map-area { grid-area: atlas; min-height: 0; border: 0; }
.game[data-mode="menu"] .map-caption { display: block; top: .65rem; left: .75rem; }
.game[data-mode="menu"] .map-credit { bottom: var(--dock-height, 5rem); right: .75rem; }
.game[data-mode="menu"] .map-controls {
  top: .75rem;
  bottom: auto;
  right: .75rem;
  grid-auto-flow: row;
  border-radius: .6rem;
}
.game[data-mode="menu"] .map-controls button + button { border-left: 0; border-top: 1px solid var(--line); }
.game[data-mode="menu"] .leaflet-bottom.leaflet-left { top: 2.45rem; bottom: auto; }
.game[data-mode="menu"] .actions {
  grid-area: atlas;
  align-self: end;
  justify-self: center;
  width: 100%;
  padding: 0;
  z-index: 600;
  pointer-events: none;
}
.menu-dock {
  padding: .8rem max(1rem, env(safe-area-inset-right)) max(.9rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  border-top: 1px solid #b5bfca;
  border-radius: 1.15rem 1.15rem 0 0;
  background: var(--paper);
  box-shadow: 0 4px 20px #10234829;
  pointer-events: auto;
}
#district-panel { display: grid; gap: .5rem; margin-bottom: .6rem; }
.district-heading { display: flex; align-items: center; justify-content: space-between; gap: .65rem; }
.district-heading h2 { font-size: clamp(1.65rem, 7vw, 2.1rem); letter-spacing: -.043em; }
.district-state {
  justify-self: start;
  padding: .2rem .55rem;
  margin: 0;
  border-radius: 999px;
  background: #e9e4d9;
  font-size: .78rem;
  font-weight: 700;
}
#training-lock { margin: 0 0 .1rem; }
#close-district {
  flex: none;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 0;
  border-radius: .4rem;
  background: transparent;
  color: var(--ink);
  font-size: 1.5rem;
  line-height: 1;
}
#close-district:hover { background: #dbe6f3; }
.district-shape { cursor: pointer; }
.leaflet-tooltip.district-label {
  width: max-content;
  max-width: 4.9rem;
  padding: .13rem .24rem;
  border: 0;
  border-radius: .2rem;
  background: #fffdf3ed;
  box-shadow: 0 1px 2px #10234826;
  color: var(--ink);
  text-align: center;
  white-space: normal;
  font: 650 .63rem/1.07 system-ui, sans-serif;
  pointer-events: auto;
}
.leaflet-tooltip.district-label:has(button[data-locked="false"]) { background: #e2eef9; }
.leaflet-tooltip.district-label:has(button[aria-pressed="true"]) { background: var(--ink); color: white; }
.leaflet-tooltip.district-reveal { pointer-events: none; }
.leaflet-tooltip.district-reveal.is-answer { background: var(--blue); color: white; }
.district-label-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .3em;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: center;
}
.district-label-button[data-locked="true"]::before {
  display: inline-block;
  flex: none;
  width: .48em;
  height: .36em;
  border: 1px solid currentColor;
  border-radius: 1px;
  box-shadow: 0 -.24em 0 -.085em currentColor;
  content: "";
}
.stats-line { color: var(--muted); font-size: .82rem; margin: .42rem 0 0; }
.stats-line:empty { display: none; }
.district-stats { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); margin: .2rem 0; gap: .4rem .7rem; }
.district-stats div { display: grid; grid-template-columns: 1fr auto; gap: .3rem; align-items: baseline; border-top: 1px solid var(--line); padding-top: .35rem; }
.district-stats dt { color: var(--muted); font-size: .75rem; }
.district-stats dd { margin: 0; font-size: .85rem; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
#storage-note { margin-top: .75rem; }
.feedback {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .6rem;
  margin-bottom: .48rem;
  padding: .48rem .65rem;
  border-radius: .4rem;
  background: #ebeff1;
  font-size: .83rem;
}
.feedback:empty { display: none; }
.feedback span { flex: none; font-weight: 750; font-variant-numeric: tabular-nums; }
.feedback[data-outcome="correct"] { background: #e5f1e5; color: #075a40; }
.feedback[data-outcome="wrong"] { background: #f7ece5; color: #852e29; }
.choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .42rem; margin-bottom: .52rem; }
.choice {
  min-height: 2.75rem;
  padding: .45rem .5rem;
  border: 1px solid #a7b1c0;
  border-radius: .35rem;
  background: #fffdf7;
  color: var(--ink);
  font-weight: 650;
  font-size: .89rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
  hyphens: auto;
}
.choice:hover:not(:disabled) { background: #e5eefa; }
.choice[data-result="correct"] { border-color: #086749; box-shadow: inset 0 0 0 1px #086749; background: #e5f1e5; }
.choice[data-result="wrong"] { border-color: #9b3431; box-shadow: inset 0 0 0 1px #9b3431; background: #f9e9e5; }
.choice[data-result]::after { margin-left: .35em; }
.choice[data-result="correct"]::after { content: "✓" / ""; }
.choice[data-result="wrong"]::after { content: "×" / ""; }
.primary {
  display: block;
  width: 100%;
  min-height: 3rem;
  padding: .55rem .85rem;
  border: 1px solid var(--blue);
  border-radius: .45rem;
  background: var(--blue);
  color: white;
  font: bold 1.18rem/1.2 var(--serif);
}
.primary:hover:not(:disabled) { background: #063b98; }
.primary.secondary { border-color: var(--ink); background: transparent; color: var(--ink); }
.primary.secondary:hover { background: #e6edf4; }
.primary:disabled { border-color: #c9d7e6; background: #dbe4ed; color: #32496a; }

.summary { grid-row: 1 / -1; width: min(100%, 38rem); padding: 1.75rem 1rem; margin: 0 auto; }
.total { margin: .78rem 0 .28rem; color: #093c91; font: bold 1.65rem var(--serif); }
#summary-best { margin-top: 0; }
#summary-wallet { margin-bottom: 1.25rem; }
#results-title { margin: 1.35rem 0 .48rem; font: bold 1.2rem var(--serif); }
#results { list-style: none; padding: 0; margin: 0 0 1.4rem; }
#results li {
  display: flex;
  justify-content: space-between;
  gap: .75rem;
  padding: .55rem 0;
  border-top: 1px solid var(--line);
}
#results span:last-child { flex: none; color: var(--muted); font-size: .85rem; }

@media (max-width: 55.999rem) {
  body.is-playing {
    position: relative;
    --hud-surface: #faf6ed;
    --hud-outline: #aebaca;
    --hud-shadow: 0 3px 12px #10234826;
  }
  .is-playing .masthead {
    position: absolute;
    z-index: 700;
    inset: max(.6rem, env(safe-area-inset-top)) max(.65rem, env(safe-area-inset-right)) auto max(.65rem, env(safe-area-inset-left));
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: .5rem;
    padding: .12rem .45rem;
    border: 1px solid var(--hud-outline);
    border-radius: .72rem;
    background: var(--hud-surface);
    box-shadow: var(--hud-shadow);
  }
  .is-playing .identity-short { display: none; }
  .is-playing .identity { padding-inline: .25rem; }
  .is-playing .identity svg { width: 1.25rem; }
  .is-playing .game-status {
    grid-area: 1 / 2;
    grid-template-columns: auto minmax(.55rem, 1fr) auto;
    gap: .4rem;
    padding: 0;
    font-size: .74rem;
    white-space: nowrap;
  }
  .is-playing .menu-link {
    grid-column: 3;
    padding-inline: .4rem;
    background: transparent;
  }
  .is-playing .menu-link:hover { background: #e6edf4; }
  .is-playing .game {
    grid-template: "play-map" minmax(24rem, 1fr) / minmax(0, 1fr);
  }
  .is-playing .map-area, .is-playing .question, .is-playing .actions { grid-area: play-map; }
  .is-playing .map-area { min-height: 0; border: 0; }
  .is-playing .question {
    z-index: 600;
    align-self: start;
    justify-self: start;
    max-width: min(calc(100% - 1.3rem), 29rem);
    margin: calc(var(--hud-height, 3rem) + max(.6rem, env(safe-area-inset-top)) + .45rem) .65rem 0;
    padding: .55rem .7rem .62rem;
    border: 1px solid var(--hud-outline);
    border-radius: .65rem;
    background: var(--hud-surface);
    box-shadow: var(--hud-shadow);
  }
  .is-playing .mode { margin-bottom: .2rem; font: 700 .76rem/1.25 system-ui, sans-serif; }
  .is-playing .mode::after { display: none; }
  .is-playing #instruction { margin-top: .27rem; font-size: .78rem; }
  .is-playing .map-controls {
    right: .65rem;
    bottom: max(calc(var(--play-dock-height, 0px) + 1.55rem), 39%);
    grid-auto-flow: row;
    border-radius: .55rem;
  }
  .is-playing .map-controls button + button { border-left: 0; border-top: 1px solid var(--line); }
  .is-playing .map-credit { bottom: calc(var(--play-dock-height, 0px) + .3rem); right: .65rem; }
  .is-playing .leaflet-bottom.leaflet-left { bottom: calc(var(--play-dock-height, 0px) + .65rem); }
  .is-playing .actions {
    align-self: end;
    z-index: 600;
    padding: .65rem max(1rem, env(safe-area-inset-right)) max(.8rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
    border: 1px solid var(--hud-outline);
    border-bottom: 0;
    border-radius: 1rem 1rem 0 0;
    background: var(--hud-surface);
    box-shadow: var(--hud-shadow);
  }
  .is-playing .choices { margin-bottom: 0; }
  .is-playing .choices:not([hidden]) + #action { margin-top: .55rem; }
}

@media (max-width: 22rem) {
  .game[data-mode="name"] h1 { font-size: 1.54rem; }
  #instruction { font-size: .83rem; }
  .menu-link { padding-inline: .52rem; }
}

@media (min-width: 56rem) {
  .masthead { grid-template-columns: auto minmax(0, 1fr) auto; gap: 1.15rem; min-height: 4.75rem; padding-inline: clamp(1rem, 3.2vw, 3rem); border-color: var(--ink); }
  .identity { gap: .85rem; font-size: clamp(1.55rem, 2.7vw, 2rem); }
  .identity-full { display: inline; }
  .identity-short { display: none; }
  .identity svg { width: 2rem; height: 2.1rem; }
  .game-status { grid-column: 2; grid-row: 1; justify-self: end; width: min(100%, 31rem); gap: 1rem; padding: 0; font-size: .94rem; }
  .menu-link { grid-column: 3; font-size: .9rem; }
  .wallet { grid-column: 2 / -1; justify-content: flex-end; font-size: .94rem; }
  .game[data-mode="menu"] .actions { width: min(100%, 29rem); padding: .75rem; }
  .menu-dock { border: 1px solid #b5bfca; border-radius: .9rem; }
  .game {
    grid-template-columns: minmax(19rem, 34%) minmax(0, 1fr);
    grid-template-rows: 1fr 1fr;
  }
  .question, .actions { grid-column: 1; padding-inline: clamp(1.5rem, 3vw, 3.5rem); }
  .question { align-self: end; padding-bottom: 1.05rem; }
  .mode { font-size: 1.35rem; margin-bottom: 1.9rem; }
  .mode::after { width: 3.5rem; margin-top: .6rem; }
  h1 { font-size: clamp(2.2rem, 3.75vw, 4.4rem); }
  #instruction { font: 1.22rem/1.45 var(--serif); margin-top: 1rem; max-width: 25ch; }
  .actions { grid-row: 2; padding-top: .65rem; }
  .choice { min-height: 3rem; }
  .primary { min-height: 3.5rem; }
  .map-area { grid-column: 2; grid-row: 1 / 3; min-height: 30rem; border: 0; border-left: 1px solid var(--line); }
  .leaflet-tooltip.district-label { max-width: none; font-size: .85rem; padding: .22rem .35rem; }
  .map-caption { display: block; }
  .map-controls { right: 1rem; bottom: 1.65rem; grid-auto-flow: row; }
  .map-controls button + button { border-left: 0; border-top: 1px solid var(--line); }
  .summary { grid-column: 1 / -1; grid-row: 1 / -1; padding-top: 3rem; }
}
