:root {
  --sea: #0a1424;
  --land: #15233a;
  --park: #1a2c42;
  --road-minor: #2a3b56;
  --road-mid: #364a69;
  --road-major: #475f84;
  --ink: #c9d6ea;
  --ink-dim: #7f93b2;
  --panel: #0f1b30;
  --panel-edge: #1e2f4a;
  --accent: #6fa3e8;
  --accent-ink: #08111f;
  --good: #3fa88a;
  --bad: #c75b6c;
}

html, body {
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, Arial, sans-serif;
  background: var(--sea);
  color: var(--ink);
}

/* Floating control card (top-left) */
#hud {
  position: fixed;
  top: 18px;
  left: 18px;
  z-index: 1100;
  width: 196px;
  padding: 16px;
  box-sizing: border-box;
  border-radius: 18px;
  /* no backdrop-filter: re-blurring the moving map every frame made zoom/pan stutter */
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid color-mix(in srgb, var(--panel-edge) 80%, transparent);
  box-shadow: 0 10px 34px rgba(0,0,0,0.28);
  transition: background-color .5s, border-color .5s;
}
#hud .brand {
  margin: 0 0 14px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
#start-game {
  display: block;
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: filter .15s, transform .15s, background-color .5s;
}
#names-toggle {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; margin-top: 10px; padding: 9px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--panel-edge) 90%, transparent);
  background: color-mix(in srgb, var(--ink) 9%, transparent);
  color: var(--ink-dim);
  font: inherit; font-size: 12px; font-weight: 600; letter-spacing: 0.04em;
  cursor: pointer;
  transition: color .25s, background-color .25s, border-color .25s;
}
#names-toggle:hover { color: var(--ink); }
#names-toggle.on { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
#names-toggle svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
body.in-game #names-toggle { display: none; }
#start-game:hover { filter: brightness(1.1); transform: translateY(-1px); }
#start-game:active { transform: translateY(0); }
body.in-game #start-game { display: none; }

/* Two-way switches (theme: moon/sun, language: flags): icon-only, sliding thumb */
.switch.seg { margin-top: 10px; height: 40px; }
.switch.seg button { font: inherit; font-size: 12.5px; font-weight: 650; letter-spacing: .02em; }
body.in-game .switch.seg { display: none; }
.hud-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}
.switch {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: 40px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--ink) 9%, transparent);
  border: 1px solid color-mix(in srgb, var(--panel-edge) 90%, transparent);
  overflow: hidden;
}
.switch .thumb {
  position: absolute;
  top: 3px; bottom: 3px; left: 3px;
  width: calc(50% - 3px);
  border-radius: 9px;
  background: var(--accent);
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  transition: transform .38s cubic-bezier(.65,0,.25,1), background-color .5s;
}
.switch[data-kind="theme"].is-day .thumb,
.switch[data-kind="lang"].is-en .thumb,
.switch[data-kind="mode"].is-kvarterer .thumb { transform: translateX(100%); }
.switch button {
  position: relative;
  z-index: 1;
  display: flex; align-items: center; justify-content: center;
  margin: 0; padding: 0;
  border: none; background: transparent;
  color: var(--ink-dim);
  cursor: pointer;
  transition: color .3s, opacity .3s;
}
.switch button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.switch[data-kind="theme"] button.active,
.switch[data-kind="mode"] button.active { color: var(--accent-ink); }
.switch[data-kind="lang"] .flag { width: 22px; height: auto; max-height: 16px; border-radius: 3px; stroke: none; box-shadow: 0 0 0 1px rgba(0,0,0,0.25); opacity: .55; transition: opacity .3s, transform .3s; }
.switch[data-kind="lang"] button.active .flag { opacity: 1; transform: scale(1.06); }
.switch[data-kind="lang"] .thumb { background: color-mix(in srgb, var(--accent) 38%, transparent); box-shadow: inset 0 0 0 1.5px var(--accent); }

/* About button: a plain link to about.html (fades to the page, see nav.js) */
.hud-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; box-sizing: border-box; margin-top: 10px; padding: 9px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--panel-edge) 90%, transparent);
  background: color-mix(in srgb, var(--ink) 9%, transparent);
  color: var(--ink-dim);
  font: inherit; font-size: 12px; font-weight: 600; letter-spacing: 0.04em;
  text-decoration: none;
  cursor: pointer;
  transition: color .25s, background-color .25s;
}
.hud-btn:hover { color: var(--ink); }
.hud-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
body.in-game .hud-btn { display: none; }

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

/* No focus box around clicked districts */
.leaflet-container .leaflet-interactive,
.leaflet-container .leaflet-interactive:focus,
.leaflet-container .leaflet-interactive:focus-visible,
.leaflet-container path:focus { outline: none !important; -webkit-tap-highlight-color: transparent; }

/* District name labels: sit inside each district, scale with zoom */
.dlabel { pointer-events: none; }
.dlabel span {
  position: absolute;
  left: 0; top: 0;
  transform: translate(-50%, -50%);
  white-space: nowrap;
  text-align: center;
  font-weight: 650;
  line-height: 1.08;
  letter-spacing: 0.01em;
  color: var(--ink);
  text-shadow: 0 0 3px var(--land), 0 0 6px var(--land);
  opacity: 0;
  will-change: transform, opacity;
  transition: opacity .2s ease, color .2s ease;
}
.dlabel.show span { opacity: 0.95; }
.dlabel.hover span {
  opacity: 1;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 0.02em;
  text-shadow: 0 0 3px var(--land), 0 0 7px var(--land), 0 0 11px var(--land);
}
body.in-game .dlabel span { opacity: 0 !important; }

/* Map: the sea colour is the page background, everything else is drawn on top */
#map {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: var(--sea);
  outline: none;
}
.leaflet-container { background: var(--sea); font-family: inherit; }
.leaflet-control-attribution { background: color-mix(in srgb, var(--sea) 70%, transparent) !important; color: var(--ink-dim) !important; font-size: 10px; }
.leaflet-control-attribution a { color: var(--ink-dim) !important; }
.leaflet-bar a { background: var(--panel); color: var(--ink); border-bottom-color: var(--panel-edge); }
.leaflet-bar a:hover { background: var(--panel-edge); }

.leaflet-tooltip, .leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--panel-edge);
  box-shadow: 0 4px 14px rgba(0,0,0,0.45);
}
.leaflet-tooltip { font-size: 12px; }
.leaflet-tooltip-top:before { border-top-color: var(--panel-edge); }
.leaflet-tooltip-bottom:before { border-bottom-color: var(--panel-edge); }
.leaflet-tooltip-left:before { border-left-color: var(--panel-edge); }
.leaflet-tooltip-right:before { border-right-color: var(--panel-edge); }
.leaflet-popup-content { margin: 8px 12px; font-size: 12px; }

/* Top-center game UI overlay */
#game-ui {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid var(--panel-edge);
  padding: 12px 22px;
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.5);
  display: none;
  text-align: center;
  width: 420px;
  max-width: calc(100vw - 480px);
  pointer-events: none;
}
#game-ui * { pointer-events: auto; }

#game-target { font-size: 22px; font-weight: 600; margin: 0 0 6px; color: var(--ink); }
#previous-region { font-size: 12px; margin: 0 0 6px; color: var(--ink-dim); }
#score-field { font-size: 12px; margin: 0; color: var(--ink-dim); display: none; letter-spacing: 0.04em; }

#game-complete { display: none; margin-top: 6px; }
#final-result-msg { font-size: 16px; font-weight: 600; margin: 0 0 12px; }
#btn-end-late, #btn-play-again {
  border-radius: 6px;
  padding: 8px 16px;
  cursor: pointer;
  margin: 0 4px;
  font-size: 13px;
  border: 1px solid var(--panel-edge);
  background: transparent;
  color: var(--ink);
}
#btn-play-again { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }

#end-game-top {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--panel-edge);
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
  display: none;
}
#end-game-top:hover { background: var(--panel-edge); }

/* Touch: no double-tap zoom / 300ms delay on controls */
button, .switch, .hud-btn { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

/* ---------------------------------------------------------------
   Phones: controls become a bottom bar inside the thumb zone, the
   game banner spans the top, everything respects the notch/home bar.
   --------------------------------------------------------------- */
@media (max-width: 640px), (max-height: 520px) {
  #hud {
    top: auto;
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    width: auto;
    padding: 8px;
    border-radius: 20px;
    display: grid;
    grid-template-columns: 48px 48px 1fr 1fr;
    gap: 8px;
    align-items: center;
  }
  #hud .brand { display: none; }
  #start-game { height: 48px; padding: 0; border-radius: 14px; font-size: 15px; }
  #start-game { grid-column: 1 / -1; }
  .switch.seg { grid-column: 1 / -1; margin: 0; height: 44px; }
  .switch.seg button { font-size: 14px; }
  #names-toggle, .hud-btn { margin: 0; width: 48px; height: 48px; padding: 0; border-radius: 14px; }
  #names-toggle span, .hud-btn span { display: none; }
  #names-toggle svg, .hud-btn svg { width: 20px; height: 20px; }
  .hud-row { display: contents; }
  .switch { margin: 0; height: 48px; border-radius: 14px; }
  .switch .thumb { border-radius: 11px; }
  .switch button svg { width: 20px; height: 20px; }
  .switch[data-kind="lang"] .flag { width: 26px; max-height: 19px; }

  /* in a game the bar gives way to the End game button */
  body.in-game #hud { display: none; }
  #end-game-top {
    top: auto; right: auto;
    left: 50%;
    bottom: calc(14px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    padding: 13px 28px;
    border-radius: 16px;
    font-size: 15px;
    font-weight: 600;
    box-shadow: 0 8px 26px rgba(0,0,0,0.4);
  }

  #game-ui {
    top: calc(10px + env(safe-area-inset-top));
    width: calc(100vw - 24px);
    max-width: none;
    box-sizing: border-box;
    padding: 10px 14px;
    border-radius: 16px;
  }
  #game-target { font-size: 20px; }
  #btn-end-late, #btn-play-again { padding: 12px 20px; font-size: 15px; border-radius: 12px; }

  /* pinch to zoom; keep attribution clear of the bottom bar */
  .leaflet-control-zoom { display: none; }
  .leaflet-bottom.leaflet-right { margin-bottom: calc(192px + env(safe-area-inset-bottom)); }
  .leaflet-control-attribution { font-size: 9px; }
}

/* Short landscape phones: keep the game banner compact */
@media (max-height: 520px) and (min-width: 641px) {
  #hud { left: 50%; right: auto; width: 360px; transform: translateX(-50%); }
  #game-ui { width: 460px; padding: 6px 12px; }
  #game-target { font-size: 17px; margin-bottom: 2px; }
  #previous-region { display: none; }
}

/* Page change (game <-> About): fade in on load, fade out when leaving a link marked data-fade */
@keyframes page-in { from { opacity: 0; } to { opacity: 1; } }
body { animation: page-in .45s ease backwards; }
body.leaving { opacity: 0; transition: opacity .28s ease; pointer-events: none; }
@media (prefers-reduced-motion: reduce) { body { animation: none; } body.leaving { transition: none; } }
