:root {
  color-scheme: dark;
  --brand: oklch(77% 0.14 151);
  --brand-hover: oklch(70% 0.15 151);
  --text-strong: oklch(97% 0.01 155);
  --text-weak: oklch(80% 0.025 155);
  --stroke-strong: oklch(61% 0.045 155);
  --stroke-weak: oklch(30% 0.035 155);
  --fill: oklch(20% 0.035 155 / 0.94);
  --fill-raised: oklch(25% 0.04 155 / 0.94);
  --background: oklch(13% 0.025 155);
  --error: oklch(74% 0.17 28);
  --success: oklch(77% 0.14 151);
  --space-xs: .5rem;
  --space-sm: 1rem;
  --space-md: 1.5rem;
  --space-lg: 2rem;
  --space-xl: 3rem;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-block-size: 100%; }
body {
  margin: 0;
  color: var(--text-strong);
  background:
    radial-gradient(circle at 75% -20%, oklch(35% 0.1 155 / .34), transparent 35rem),
    var(--background);
  font-size: 1rem;
  line-height: 1.5;
  overflow: hidden;
}
button, select, input { font: inherit; }
button, select { min-block-size: 3rem; }

.skip-link {
  position: fixed;
  inset-block-start: .5rem;
  inset-inline-start: .5rem;
  z-index: 100;
  padding: .75rem 1rem;
  color: oklch(18% 0.03 155);
  background: var(--brand);
  border-radius: .5rem;
  transform: translateY(-160%);
}
.skip-link:focus { transform: translateY(0); }

.app-shell { min-block-size: 100dvh; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: var(--space-lg);
  padding:
    max(var(--space-sm), env(safe-area-inset-top))
    max(var(--space-lg), env(safe-area-inset-right))
    var(--space-sm)
    max(var(--space-lg), env(safe-area-inset-left));
  border-block-end: 1px solid var(--stroke-weak);
  background: oklch(15% 0.028 155 / .9);
  backdrop-filter: blur(1rem);
}
.stack-xs > * + * { margin-block-start: var(--space-xs); }
.stack-sm > * + * { margin-block-start: var(--space-sm); }
.identity > * { margin-block: 0; }
.identity h1 { font-size: clamp(1.35rem, 2vw, 2rem); line-height: 1.2; letter-spacing: -.025em; }
.identity #map-summary { color: var(--text-weak); max-inline-size: 68ch; font-size: .875rem; }
.eyebrow, .section-kicker {
  color: var(--brand);
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.status-cluster { display: flex; align-items: center; gap: .5rem; color: var(--text-weak); font-size: .875rem; white-space: nowrap; }
.status-dot { inline-size: .625rem; block-size: .625rem; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 .25rem oklch(77% .14 151 / .13); }
.status-cluster[data-error="true"] .status-dot { background: var(--error); box-shadow: 0 0 0 .25rem oklch(74% .17 28 / .15); }

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 9fr) minmax(19rem, 3fr);
  flex: 1;
  min-block-size: 0;
}
.map-panel, .map-viewport { min-block-size: 0; }
.map-viewport {
  position: relative;
  block-size: 100%;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  background: oklch(18% .04 190);
  outline: none;
}
.map-viewport:active { cursor: grabbing; }
.map-viewport:focus-visible { box-shadow: inset 0 0 0 .25rem var(--brand); }
body[data-story-state="crisis"] .map-viewport::after,
body[data-story-state="postbattle"] .map-viewport::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 130;
}
body[data-story-state="crisis"] .map-viewport::after {
  background:
    repeating-linear-gradient(112deg, transparent 0 31px, rgb(185 225 245 / .12) 32px 34px, transparent 35px 62px),
    linear-gradient(165deg, rgb(9 48 70 / .06), rgb(7 27 43 / .12));
}
.map-scene {
  position: absolute;
  inset: auto;
  inline-size: 8192px;
  block-size: 4610px;
  transform-origin: 0 0;
  will-change: transform;
  user-select: none;
  contain: layout paint style;
}
.map-art, .route-overlay, .chunk-layer, .compositor-layer, .placement-layer, .npc-layer, .occlusion-layer {
  position: absolute;
  inset: 0;
  inline-size: 100%;
  block-size: 100%;
  object-fit: cover;
  pointer-events: none;
}
.chunk-layer { overflow: hidden; background: oklch(18% .04 190); z-index: 0; }
.compositor-layer[data-broad-state="crisis"] .stitched-chunk { filter: brightness(.86) saturate(.76) hue-rotate(-8deg); }
.compositor-layer[data-broad-state="postbattle"] .stitched-chunk { filter: brightness(1.035) saturate(1.06) sepia(.035); }
.compositor-layer { overflow: hidden; z-index: 1; }
.compositor-item { position: absolute; pointer-events: none; transform-origin: var(--pivot-x, 50%) var(--pivot-y, 50%); }
.stitched-chunk,
.compositor-item--regional {
  object-fit: fill;
  opacity: 1;
  isolation: isolate;
  -webkit-mask-image: none;
  mask-image: none;
  filter: saturate(.99) contrast(1.005);
}
.stitched-chunk.is-current {
  filter: saturate(1.035) contrast(1.01);
}
.compositor-layer[data-stitch-ready="true"]::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 89;
  background: linear-gradient(145deg, rgb(255 255 255 / .018), transparent 38%, rgb(16 89 82 / .025));
}
.compositor-item--state {
  object-fit: fill;
}
.chunk-boundary { position: absolute; overflow: hidden; border: 0; background: transparent; z-index: 90; }
.chunk-boundary > span { display: none; }
.chunk-boundary.is-current { border: 0; box-shadow: none; }
.placement-layer { pointer-events: none; z-index: 120; }
.npc-layer { pointer-events: none; z-index: 220; }
.route-overlay { overflow: visible; z-index: 110; }
.route-line { fill: none; stroke: oklch(98% .01 155 / .72); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; filter: drop-shadow(0 1px 1px oklch(10% .02 155 / .85)); }
.route-line[data-role="shortcut"] { stroke: oklch(83% .14 85 / .9); stroke-dasharray: 12 12; }
.route-line[data-role="branch"] { stroke: oklch(84% .12 210 / .9); }
.route-line.is-selected { stroke: var(--brand); stroke-width: 6; }
.portal-group circle { fill: oklch(77% .14 151 / .22); stroke: oklch(92% .08 151 / .85); stroke-width: 3; vector-effect: non-scaling-stroke; }
.routes-hidden .route-overlay,
.debug-hidden .route-overlay,
.debug-hidden .facility-marker,
.debug-hidden .placement-marker { display: none; }

.placement-marker { position: absolute; inline-size: 1.7rem; block-size: 1.7rem; min-block-size: 0; padding: 0; translate: -50% -50%; pointer-events: auto; border: 2px solid oklch(98% .01 155); border-radius: 50%; background: oklch(68% .16 220); box-shadow: 0 .2rem .65rem oklch(10% .03 155 / .75); cursor: pointer; }
.placement-marker { scale: var(--inverse-scale, 1); }
.placement-marker span { display: block; inline-size: .42rem; block-size: .42rem; margin: auto; border-radius: 50%; background: oklch(98% .01 155); }
.placement-marker.category-npc { background: oklch(70% .16 70); }
.placement-marker.category-exit, .placement-marker.category-entrance { background: oklch(70% .18 145); border-radius: .2rem; rotate: 45deg; }
.placement-marker.category-secret, .placement-marker.category-discovery { background: oklch(70% .18 315); }
.placement-marker.category-service, .placement-marker.category-camp { background: oklch(68% .17 30); }
.placement-marker.is-complete { opacity: .62; filter: saturate(.55); }
.placement-marker:focus-visible { outline: .2rem solid var(--brand); outline-offset: .2rem; }

.npc-actor {
  position: absolute;
  inline-size: 1.35rem;
  block-size: 1.35rem;
  min-block-size: 0;
  padding: 0;
  translate: -50% -50%;
  scale: var(--inverse-scale, 1);
  transform-origin: 50% 92%;
  pointer-events: none;
  border: 0;
  background: transparent;
  cursor: pointer;
  filter: none;
  opacity: 0;
  transition: opacity .12s ease;
}
.npc-actor::after {
  content: "";
  position: absolute;
  inset: 14%;
  border-radius: 50%;
  border: .12rem solid rgb(158 255 224 / .88);
  background: rgb(5 31 29 / .44);
  box-shadow: 0 0 .45rem rgb(74 255 200 / .48);
  z-index: 0;
}
.npc-figure { display: none; }
.npc-head {
  position: absolute;
  inset: .18rem auto auto 50%;
  inline-size: 1.32rem;
  block-size: 1.42rem;
  translate: -50% 0;
  border: .12rem solid rgb(35 27 34 / .92);
  border-radius: 48% 48% 44% 44%;
  background: hsl(calc(var(--npc-hue) + 24) 42% 76%);
  box-shadow: inset 0 .32rem 0 hsl(var(--npc-hue) 42% 26%);
}
.npc-head::before,
.npc-head::after {
  content: "";
  position: absolute;
  inset-block-start: .68rem;
  inline-size: .12rem;
  block-size: .16rem;
  border-radius: 50%;
  background: rgb(29 33 39 / .95);
}
.npc-head::before { inset-inline-start: .32rem; }
.npc-head::after { inset-inline-end: .32rem; }
.npc-body {
  position: absolute;
  inset: 1.38rem auto auto 50%;
  inline-size: 2rem;
  block-size: 2.04rem;
  translate: -50% 0;
  clip-path: polygon(28% 0,72% 0,94% 100%,6% 100%);
  border: .12rem solid rgb(28 31 36 / .9);
  background: linear-gradient(100deg, hsl(var(--npc-hue) 42% 34%), hsl(var(--npc-hue) 58% 54%) 58%, hsl(calc(var(--npc-hue) + 28) 52% 66%));
}
.npc-body::after {
  content: "";
  position: absolute;
  inset: .28rem .3rem auto;
  block-size: .18rem;
  border-block: .08rem solid rgb(255 239 186 / .76);
}
.npc-legs {
  position: absolute;
  inset: 3.22rem auto auto 50%;
  inline-size: 1.46rem;
  block-size: 1.1rem;
  translate: -50% 0;
  border-inline: .42rem solid hsl(calc(var(--npc-hue) + 18) 34% 24%);
}
.npc-name {
  position: absolute;
  inset: -.92rem auto auto 50%;
  translate: -50% 0;
  max-inline-size: 9rem;
  padding: .13rem .34rem;
  border: 1px solid rgb(221 255 240 / .82);
  border-radius: 999px;
  color: white;
  background: rgb(5 31 29 / .88);
  box-shadow: 0 .16rem .35rem rgb(0 0 0 / .35);
  font-size: .58rem;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
  opacity: 0;
  transform: translateY(.18rem);
  transition: opacity .13s ease, transform .13s ease;
}
.npc-actor:hover .npc-name,
.npc-actor:focus-visible .npc-name,
.npc-actor.is-nearby .npc-name { opacity: 1; transform: translateY(0); }
.npc-actor.is-nearby { opacity: 1; pointer-events: auto; }
.npc-actor:focus-visible { outline: .18rem solid var(--brand); outline-offset: .14rem; border-radius: 45%; }
.npc-actor[data-role-class="event"] .npc-body { background: linear-gradient(100deg, hsl(12 66% 36%), hsl(18 86% 58%), hsl(47 86% 67%)); }
@keyframes npc-idle { from { transform: translateY(0); } to { transform: translateY(-.1rem); } }

.facility-marker {
  position: absolute;
  min-inline-size: 2.9rem;
  min-block-size: 1.55rem;
  padding: .16rem .42rem;
  translate: -50% -50%;
  scale: var(--inverse-scale, 1);
  transform-origin: 50% 50%;
  pointer-events: auto;
  border: 1px solid rgb(255 255 255 / .9);
  border-radius: 999px;
  color: white;
  background: rgb(18 43 41 / .9);
  box-shadow: 0 .18rem .55rem rgb(7 16 19 / .62);
  font-size: .62rem;
  font-weight: 800;
  letter-spacing: .03em;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
}
.facility-marker--civilization { background: rgb(116 55 34 / .92); }
.facility-marker--foundation { background: rgb(21 86 77 / .92); }
.facility-marker:focus-visible { outline: .2rem solid var(--brand); outline-offset: .15rem; }

.player-marker {
  position: absolute;
  inline-size: 5.8rem;
  block-size: 5.8rem;
  transform: translate(-50%, -86%) scale(var(--inverse-scale, 1));
  z-index: 230;
  transform-origin: 50% 88%;
  pointer-events: none;
}
.player-guide-overlay {
  position: absolute;
  inline-size: 5.8rem;
  block-size: 5.8rem;
  transform: translate(-50%, -86%) scale(var(--inverse-scale, 1));
  transform-origin: 50% 88%;
  z-index: 270;
  pointer-events: none;
}
.player-locator-ring {
  position: absolute;
  inset: 44% auto auto 50%;
  inline-size: 3.8rem;
  block-size: 1.45rem;
  translate: -50% -50%;
  border: .13rem solid rgb(158 255 224 / .92);
  border-radius: 50%;
  box-shadow: 0 0 0 .16rem rgb(7 39 36 / .58), 0 0 .75rem rgb(74 255 200 / .72);
  animation: player-locator-pulse 1.35s ease-in-out infinite;
  pointer-events: none;
}
.player-nameplate {
  position: absolute;
  inset-block-start: -1.5rem;
  inset-inline-start: 50%;
  translate: -50% 0;
  padding: .16rem .38rem;
  color: white;
  background: rgb(6 28 27 / .86);
  border: 1px solid rgb(158 255 224 / .86);
  border-radius: 999px;
  box-shadow: 0 .12rem .35rem rgb(0 0 0 / .45);
  font-size: .62rem;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
}
.player-shadow {
  position: absolute;
  inset-inline-start: 50%;
  inset-block-end: .1rem;
  inline-size: 1.45rem;
  block-size: .36rem;
  translate: -50% 0;
  scale: var(--shadow-scale, 1) var(--shadow-squash, 1);
  border-radius: 50%;
  background: radial-gradient(ellipse, rgb(4 17 24 / .42) 0 36%, rgb(4 17 24 / .22) 58%, transparent 76%);
  filter: blur(.07rem);
  transform-origin: center;
  transition: scale 70ms linear, opacity 70ms linear;
  opacity: var(--shadow-opacity, .7);
}
.player-sprite {
  position: absolute;
  inset: 0;
  inline-size: 100%;
  block-size: 100%;
  overflow: hidden;
  transform: translateY(var(--sprite-lift, 0)) scaleX(var(--sprite-facing, 1));
  transform-origin: 50% 88%;
  filter: drop-shadow(0 .08rem .08rem rgb(5 18 25 / .35));
  image-rendering: auto;
  will-change: transform;
}
.player-sprite-sheet {
  display: block;
  inline-size: 800%;
  max-inline-size: none;
  block-size: 100%;
  object-fit: fill;
  transform: translateX(calc(var(--sprite-frame, 0) * -12.5%));
  will-change: transform;
}
.player-marker[data-moving="true"] .player-sprite {
  filter: drop-shadow(0 .08rem .08rem rgb(5 18 25 / .28));
}
.occlusion-layer { z-index: 260; pointer-events: none; overflow: hidden; }
.occlusion-item { position: absolute; object-fit: fill; opacity: 0; transition: opacity .16s ease; }
.occlusion-item.is-active { opacity: .25; }

.loading-panel, .error-banner, .map-hint {
  position: absolute;
  z-index: 20;
  color: var(--text-strong);
  background: oklch(16% .03 155 / .9);
  backdrop-filter: blur(.75rem);
  border: 1px solid var(--stroke-strong);
  border-radius: .75rem;
}
.loading-panel { inset: 50% auto auto 50%; translate: -50% -50%; display: flex; align-items: center; gap: .75rem; padding: 1rem 1.25rem; }
.loading-ring { inline-size: 1.25rem; block-size: 1.25rem; border: .15rem solid var(--stroke-strong); border-block-start-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
.error-banner { inset-block-start: 1rem; inset-inline: 1rem; padding: .75rem 1rem; border-color: var(--error); }
.map-hint { inset-inline-start: 1rem; inset-block-end: 1rem; padding: .5rem .75rem; color: var(--text-weak); font-size: .8rem; border-color: var(--stroke-weak); }
.player-presence-hud {
  position: absolute;
  z-index: 25;
  inset-block-start: 1rem;
  inset-inline-start: 1rem;
  display: flex;
  align-items: center;
  gap: .55rem;
  min-inline-size: 10.5rem;
  padding: .55rem .7rem;
  color: white;
  background: rgb(5 25 24 / .88);
  border: 1px solid rgb(158 255 224 / .48);
  border-radius: .7rem;
  box-shadow: 0 .35rem 1rem rgb(0 0 0 / .28);
  backdrop-filter: blur(.65rem);
  pointer-events: none;
}
.player-presence-hud > span:last-child { display: grid; line-height: 1.15; }
.player-presence-hud strong { font-size: .82rem; }
.player-presence-hud small { margin-block-start: .18rem; color: rgb(199 232 222); font-size: .66rem; }
.player-presence-dot { inline-size: .62rem; block-size: .62rem; border-radius: 50%; background: rgb(112 255 196); box-shadow: 0 0 0 .22rem rgb(112 255 196 / .14); }

.control-panel {
  overflow: auto;
  padding: var(--space-lg);
  padding-inline-end: max(var(--space-lg), env(safe-area-inset-right));
  padding-block-end: max(var(--space-lg), env(safe-area-inset-bottom));
  background: var(--fill);
  border-inline-start: 1px solid var(--stroke-weak);
}
.control-section { padding-block: var(--space-md); }
.control-section + .control-section { border-block-start: 1px solid var(--stroke-weak); }
.control-section h2, .control-section p { margin-block: 0; }
.control-section h2 { font-size: 1.15rem; line-height: 1.35; }
.supporting-copy { color: var(--text-weak); font-size: .9rem; }

.segmented-control { display: grid; grid-template-columns: repeat(3, 1fr); margin: 0; padding: .25rem; border: 1px solid var(--stroke-strong); border-radius: .75rem; }
.segmented-control label { min-inline-size: 0; }
.segmented-control input { position: absolute; opacity: 0; pointer-events: none; }
.segmented-control span { display: grid; place-items: center; min-block-size: 2.75rem; padding-inline: .5rem; border-radius: .5rem; color: var(--text-weak); cursor: pointer; }
.segmented-control input:checked + span { color: oklch(17% .03 155); background: var(--brand); font-weight: 700; }
.segmented-control input:focus-visible + span { outline: .2rem solid var(--text-strong); outline-offset: .15rem; }

.field-label { display: block; color: var(--text-weak); font-size: .875rem; font-weight: 700; }
select { inline-size: 100%; padding-inline: .875rem; color: var(--text-strong); background: var(--background); border: 1px solid var(--stroke-strong); border-radius: .65rem; }
.button-stack { display: grid; gap: .75rem; }
.button { min-block-size: 3rem; padding-inline: 1rem; border-radius: .65rem; font-weight: 700; cursor: pointer; }
.button--primary { color: oklch(17% .03 155); background: var(--brand); border: 1px solid var(--brand); }
.button--secondary { color: var(--brand); background: transparent; border: 1px solid var(--brand); }
.button:disabled { cursor: not-allowed; opacity: .45; }
.button:focus-visible, select:focus-visible, .switch-row:has(input:focus-visible) { outline: .2rem solid var(--text-strong); outline-offset: .2rem; }
.switch-row { display: flex; align-items: center; gap: .75rem; min-block-size: 3rem; color: var(--text-weak); cursor: pointer; }
.switch-row input { inline-size: 1.25rem; block-size: 1.25rem; accent-color: var(--brand); }

.facility-groups { display: grid; gap: 1rem; }
.facility-groups h3 { margin: 0 0 .45rem; color: var(--text-weak); font-size: .78rem; letter-spacing: .04em; }
.facility-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .42rem; margin: 0; padding: 0; list-style: none; }
.facility-list button {
  inline-size: 100%;
  min-block-size: 2.7rem;
  padding: .45rem .55rem;
  color: var(--text-strong);
  background: oklch(17% .028 155 / .86);
  border: 1px solid var(--stroke-weak);
  border-radius: .55rem;
  font-size: .72rem;
  line-height: 1.25;
  text-align: start;
  cursor: pointer;
}
.facility-list button span { display: block; color: var(--text-weak); font-size: .64rem; }
.facility-list button strong { font-weight: 750; }
.facility-list button:hover { border-color: var(--brand); background: oklch(23% .045 155 / .92); }
.facility-list button:focus-visible { outline: .18rem solid var(--brand); outline-offset: .12rem; }

.facts dl { margin: 0; }
.facts dl > div { display: flex; justify-content: space-between; gap: 1rem; padding-block: .7rem; border-block-end: 1px solid var(--stroke-weak); }
.facts dt { color: var(--text-weak); }
.facts dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 700; text-align: end; }
.runtime-message { padding: .75rem; color: var(--text-weak); background: oklch(14% .025 155 / .7); border: 1px solid var(--stroke-weak); border-radius: .6rem; }
.runtime-message[data-kind="success"] { color: oklch(88% .09 151); border-color: oklch(70% .11 151); }
.runtime-message[data-kind="blocked"] { color: oklch(88% .1 35); border-color: var(--error); }
.event-log { display: grid; gap: .4rem; margin: 0; padding: 0; list-style: none; color: var(--text-weak); font-size: .82rem; }
.event-log li { padding-inline-start: .75rem; border-inline-start: 2px solid var(--stroke-strong); }
.visually-hidden { position: absolute !important; inline-size: 1px !important; block-size: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }

@keyframes spin { to { rotate: 360deg; } }
@keyframes player-locator-pulse {
  0%, 100% { opacity: .72; scale: .9; }
  50% { opacity: 1; scale: 1.08; }
}
@media (hover: hover) and (pointer: fine) {
  .button--primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
  .button--secondary:hover { background: oklch(77% .14 151 / .12); }
  .segmented-control label:hover span { color: var(--text-strong); }
}
@media (max-width: 62rem) {
  body { overflow: auto; }
  .workspace { grid-template-columns: 1fr; grid-template-rows: minmax(29rem, 70dvh) auto; }
  .control-panel { border-inline-start: 0; border-block-start: 1px solid var(--stroke-weak); display: grid; grid-template-columns: repeat(auto-fit, minmax(min(17rem, 100%), 1fr)); gap: var(--space-lg); }
  .control-section + .control-section { border-block-start: 0; }
}
@media (max-width: 40rem) {
  .topbar { align-items: start; flex-direction: column; padding-inline: max(var(--space-sm), env(safe-area-inset-left)); }
  .workspace { grid-template-rows: minmax(24rem, 62dvh) auto; }
  .control-panel { padding: var(--space-sm); }
  .map-hint { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
