:root {
  color-scheme: dark;
  --ink: #102423;
  --panel: #172e2d;
  --deep: #091a1a;
  --paper: #f3f6ec;
  --muted: #b8cbc5;
  --accent: #c0edaa;
  --line: #47635e;
  --edge: clamp(1rem, 4vw, 4rem);
  --type: 'Avenir Next', 'Segoe UI', Arial, sans-serif;
  --code: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
  font: 100%/1.5 var(--type);
  background: var(--deep);
  color: var(--paper);
}

*, *::before, *::after { box-sizing: border-box; }
body { min-width: 280px; margin: 0; }
html.walking { overflow: hidden; }
[hidden] { display: none !important; }
button { color: inherit; font: inherit; cursor: pointer; }
button:disabled { cursor: wait; opacity: .62; }
button:focus-visible, canvas:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; }
.svg-defs { position: absolute; pointer-events: none; }
.icon { flex: none; width: 1.2em; height: 1.2em; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.title-screen { position: relative; isolation: isolate; background: var(--ink); }
.title-inner {
  position: relative; display: grid; grid-template-rows: auto 1fr auto; gap: 1.5rem;
  max-width: 98rem; min-height: 100vh; min-height: 100svh; margin: auto;
  padding: max(1.4rem, env(safe-area-inset-top)) max(var(--edge), env(safe-area-inset-right)) max(1.4rem, env(safe-area-inset-bottom)) max(var(--edge), env(safe-area-inset-left));
}
.cover { position: absolute; inset: 0 0 0 26%; z-index: -1; margin: 0; overflow: hidden; background: #273b38; }
.cover img { width: 100%; height: 100%; object-fit: cover; object-position: 56% center; }
.cover::after {
  position: absolute; inset: 0; content: ''; pointer-events: none;
  background: linear-gradient(90deg, var(--ink) 0%, #102423ed 13%, #10242369 43%, transparent 77%), linear-gradient(0deg, #091a1a 0%, transparent 35%, transparent 75%, #091a1a85 100%);
}
.cover figcaption {
  position: absolute; z-index: 1; right: max(var(--edge), env(safe-area-inset-right)); bottom: max(6.5rem, 13vh);
  display: grid; min-width: 10rem; gap: .15rem; padding: .6rem .85rem;
  border-left: 2px solid var(--accent); background: #0d2122ed; color: var(--muted); font-size: .78rem;
}
.cover figcaption strong { color: var(--paper); font: 650 .9rem var(--code); }
.title-header, .title-footer { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.title-header { padding-bottom: 1.15rem; border-bottom: 1px solid #d6efdf50; }
.brand { display: inline-flex; align-items: center; gap: .65rem; font-size: .86rem; font-weight: 700; }
.brand .icon { width: 1.45rem; height: 1.45rem; color: var(--accent); }
.sheet-number { display: inline-flex; align-items: center; gap: .55rem; color: var(--paper); font: 700 .78rem var(--code); white-space: nowrap; }
.sheet-number span { width: 1.15rem; height: 1px; background: var(--accent); }
.title-content { align-self: center; padding-block: clamp(1.25rem, 6vh, 4rem); }
.revision { display: flex; align-items: center; gap: .85rem; margin-bottom: 1.1rem; color: var(--accent); font: 700 clamp(.95rem, 1.35vw, 1.2rem) var(--code); }
.revision span { width: 2.6rem; height: .5rem; background: repeating-linear-gradient(125deg, transparent 0 5px, currentColor 5px 7px); }
.title-content h1 { margin: 0; font-size: clamp(3.15rem, 9.4vw, 9.1rem); font-weight: 780; letter-spacing: -.075em; line-height: .85; text-shadow: 0 3px 24px #10242340; }
.title-content > p:not(.load-status) { max-width: 29rem; margin: 1.7rem 0; color: #dde8df; font-size: clamp(1rem, 1.55vw, 1.21rem); line-height: 1.55; }
.title-actions { display: flex; flex-wrap: wrap; gap: .6rem; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: .65rem; min-height: 46px; padding: .65rem 1rem; border: 1px solid transparent; border-radius: .15rem; font-size: .91rem; font-weight: 730; }
.primary { justify-content: space-between; min-width: 13.75rem; border-color: var(--accent); background: var(--accent); color: #13251d; }
.primary:hover:not(:disabled) { background: #d8fac9; }
.secondary { border-color: #80988c; background: #132827e8; }
.secondary:hover:not(:disabled), .icon-button:hover, .hud-button:hover { border-color: var(--accent); background: #28453c; }
.load-status { min-height: 1.5em; margin: .6rem 0 0; color: var(--muted); font-size: .82rem; }
.load-status[data-state='error'] { color: #ffcbaf; }
#reload-button { margin-top: .55rem; }
.title-footer { border-top: 1px solid #d6efdf50; padding-top: .8rem; }
.text-button { display: inline-flex; align-items: center; gap: .48rem; min-height: 44px; padding: .2rem .4rem .2rem 0; border: 0; background: none; color: var(--paper); font-size: .88rem; font-weight: 650; text-align: left; }
.text-button:hover { color: var(--accent); }
.site-dimensions { flex: none; color: var(--paper); font: 640 .86rem var(--code); text-align: right; }
.site-dimensions span { display: block; margin-top: .2rem; color: var(--muted); font: .76rem var(--type); }

.walkthrough { position: fixed; inset: 0; overflow: hidden; background: #b5c4be; isolation: isolate; }
.walkthrough canvas { display: block; position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; }
.walkthrough canvas:focus-visible { outline-offset: -3px; }
.walkthrough canvas[data-dragging] { cursor: grabbing; }
.hud-top, .hud-bottom { position: absolute; display: flex; gap: .7rem; justify-content: space-between; pointer-events: none; }
.hud-top { top: max(1rem, env(safe-area-inset-top)); left: max(1rem, env(safe-area-inset-left)); right: max(1rem, env(safe-area-inset-right)); align-items: flex-start; }
.hud-bottom { bottom: max(1rem, env(safe-area-inset-bottom)); left: max(1rem, env(safe-area-inset-left)); right: max(1rem, env(safe-area-inset-right)); align-items: flex-end; }
.location, .hud-button, .control-guide, .telemetry { border: 1px solid #a1b5ab6b; background: #102423f2; box-shadow: 0 2px 8px #091a1a35; }
.location { width: min(18rem, 100%); min-width: 0; padding: .75rem .85rem; border-top: 2px solid var(--accent); }
.location .brand { font-size: .83rem; gap: .45rem; }
.location .brand .icon { width: 1.12rem; height: 1.12rem; }
.brand-rev { color: var(--muted); white-space: nowrap; }
.location-line { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-top: .5rem; border-top: 1px solid var(--line); padding-top: .55rem; }
.location strong { display: block; font-size: clamp(.94rem, 1.6vw, 1.25rem); line-height: 1.2; overflow-wrap: anywhere; }
.eyeline { display: block; color: var(--accent); font-size: .75rem; font-weight: 650; }
.compass { display: grid; flex: none; place-items: center; width: 2rem; height: 2rem; border: 1px solid var(--line); border-radius: 50%; color: var(--accent); font: 700 .75rem var(--code); }
.hud-tools { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .35rem; }
.hud-button { display: inline-flex; align-items: center; justify-content: center; gap: .38rem; min-width: 44px; min-height: 44px; padding: .42rem .65rem; border-radius: .15rem; pointer-events: auto; font-size: .81rem; font-weight: 700; white-space: nowrap; }
.hud-button .icon, .text-button .icon { color: var(--accent); }
.hud-button[aria-pressed='true'] { border-color: var(--accent); background: var(--accent); color: var(--ink); }
.hud-button[aria-pressed='true'] .icon { color: var(--ink); }
.hud-button[aria-pressed='true'] kbd { border-color: #517445; }
#view-button { border-color: var(--accent); }
.hud-button[aria-disabled='true'] { cursor: default; opacity: .8; }
kbd { display: inline-grid; place-items: center; min-width: 1.25rem; min-height: 1.25rem; padding: 0 .22rem; border: 1px solid #738f82; border-radius: .15rem; font: 700 .73rem/1 var(--code); vertical-align: baseline; }
kbd + kbd { margin-left: .15rem; }
.telemetry, .control-guide { padding: .5rem .75rem; color: var(--muted); font-size: .77rem; line-height: 1.35; }
.telemetry { display: grid; gap: .1rem; min-width: 9.2rem; text-align: right; }
#view-label { color: var(--accent); font-weight: 700; }
#coordinates { font: .76rem var(--code); white-space: nowrap; }
.guide-gap { margin-left: .6rem; }
.reticle { position: absolute; top: 50%; left: 50%; width: .45rem; height: .45rem; border: 1px solid #ffffffe6; border-radius: 50%; box-shadow: 0 0 0 1px #102423b0; transform: translate(-50%, -50%); pointer-events: none; }
.scene-feedback { position: absolute; z-index: 2; top: clamp(7.3rem, 19%, 10rem); left: 50%; width: max-content; max-width: calc(100% - 2rem); margin: 0; padding: .42rem .8rem; border-left: 2px solid var(--accent); background: #102423f5; transform: translateX(-50%); color: var(--paper); font-size: .85rem; text-align: center; pointer-events: none; }
.scene-feedback:empty { display: none; }
.touch-pad, .touch-guide { display: none; }

.dialog { width: min(63rem, calc(100% - 2rem)); max-width: none; max-height: calc(100% - 2rem); margin: auto; padding: 0; border: 1px solid #79968a; border-top: 3px solid var(--accent); border-radius: .2rem; background: var(--ink); color: var(--paper); overscroll-behavior: contain; }
.dialog::backdrop { background: #071615c9; }
.dialog-shell { padding: clamp(.9rem, 3vw, 1.7rem); }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: .7rem; }
.dialog-header h2 { margin: .15rem 0 0; font-size: clamp(1.55rem, 3.3vw, 2.25rem); line-height: 1.15; }
.dialog-shell > p { margin: .65rem 0 1rem; color: var(--muted); font-size: .91rem; }
.icon-button { flex: none; width: 44px; min-height: 44px; padding: 0; border-color: var(--line); background: var(--panel); }
.map-layout { display: grid; grid-template-columns: minmax(0, 1fr) clamp(12rem, 28%, 17rem); gap: 1.05rem; align-items: start; }
.map-paper { border: 1px solid var(--line); background: var(--panel); }
.map-caption { display: flex; justify-content: space-between; gap: .5rem; padding: .5rem .7rem; color: var(--muted); font: .77rem var(--code); }
.map-caption strong { color: var(--accent); }
.plan-stage { position: relative; width: 100%; aspect-ratio: 122.5 / 80; background: #eef0ed; }
.plan-stage > img { display: block; width: 100%; height: 100%; user-select: none; }
.map-pins { position: absolute; inset: 0; pointer-events: none; }
.map-pin { position: absolute; display: grid; place-items: center; width: clamp(1.22rem, 3vw, 1.75rem); aspect-ratio: 1; padding: 0; transform: translate(-50%, -50%); border: 1px solid #fff; border-radius: 50%; background: #1a3d3a; box-shadow: 0 1px 4px #1024238c; color: #fff; pointer-events: auto; font: 700 .68rem var(--code); }
.map-pin:hover, .map-pin:focus-visible, .map-pin[aria-current='location'] { z-index: 2; border-color: var(--ink); background: var(--accent); color: var(--ink); }
.map-player { position: absolute; z-index: 3; display: grid; place-items: center; width: 1rem; height: 1rem; transform: translate(-50%, -50%); border: 2px solid #fff; border-radius: 50%; background: #a72825; box-shadow: 0 0 0 1px #491213; pointer-events: none; }
.map-player span { position: absolute; inset: -6px; }
.map-player span::after { position: absolute; top: -2px; left: calc(50% - 5px); content: ''; border-right: 5px solid transparent; border-bottom: 7px solid #a72825; border-left: 5px solid transparent; }
.map-key { display: flex; align-items: center; gap: .48rem; min-height: 2.1rem; margin: 0; padding: .35rem .7rem; color: var(--muted); font-size: .76rem; }
.map-key i { flex: none; width: .68rem; height: .68rem; border: 1px solid white; border-radius: 50%; background: #a72825; }
.map-index h3 { margin: 0; font-size: 1.1rem; }
.map-index p { margin: .2rem 0 .55rem; color: var(--muted); font-size: .76rem; }
.zone-list { display: grid; gap: .33rem; max-height: min(52vh, 30rem); margin: 0; padding: 0 .32rem .32rem; overflow: auto; list-style: none; }
.zone-button { display: flex; align-items: center; gap: .52rem; width: 100%; min-height: 44px; padding: .38rem .5rem; border: 1px solid var(--line); border-radius: .15rem; background: var(--panel); color: var(--paper); font-size: .81rem; line-height: 1.3; text-align: left; }
.zone-button:hover, .zone-button[aria-current='location'] { border-color: var(--accent); background: #294338; }
.zone-button b { display: grid; flex: none; place-items: center; width: 1.55rem; height: 1.48rem; border: 1px solid #638476; color: var(--accent); font: 700 .72rem var(--code); }
.help-dialog { width: min(38rem, calc(100% - 2rem)); }
.help-keys { display: grid; margin: 0; }
.help-keys > div { display: grid; grid-template-columns: minmax(7rem, 1fr) 2.2fr; gap: .6rem; padding: .55rem .1rem; border-top: 1px solid var(--line); }
.help-keys dt { color: var(--paper); font-size: .83rem; font-weight: 720; }
.help-keys dd { margin: 0; color: var(--muted); font-size: .85rem; }
.dialog-shell .help-note { margin: .9rem 0 0; padding-left: .65rem; border-left: 2px solid var(--accent); font-size: .8rem; }

@media (max-width: 850px) {
  .hud-button kbd { display: none; }
  .hud-tools .hud-button { flex: none; }
  .drag-guide { display: none; }
}
@media (max-width: 660px) {
  .cover { inset: 0 0 0 0; }
  .cover img { object-position: 62% 28%; }
  .cover::after { background: linear-gradient(0deg, #102423 0%, #102423f2 33%, #10242369 74%, #10242390 100%), linear-gradient(90deg, #10242391, transparent); }
  .cover figcaption { display: none; }
  .title-inner { gap: .8rem; }
  .title-content { align-self: end; }
  .title-content h1 { font-size: clamp(3.05rem, 12.2vw, 6.5rem); }
  .title-content > p:not(.load-status) { margin: 1.25rem 0; }
  .hud-top { flex-direction: column; gap: .45rem; }
  .hud-tools { justify-content: flex-start; }
  .location { width: auto; max-width: 100%; padding: .5rem .65rem; }
  .location-line { margin-top: .32rem; padding-top: .32rem; }
  .scene-feedback { top: 10.6rem; }
  .control-guide { display: none; }
  .map-layout { grid-template-columns: 1fr; gap: .8rem; }
  .zone-list { grid-template-columns: repeat(2, minmax(0, 1fr)); max-height: none; }
}
@media (max-width: 410px) {
  .title-footer .site-dimensions span { display: none; }
  .hud-tools { gap: .22rem; }
  .hud-tools .hud-button { padding-inline: .4rem; }
  #roof-button .icon, #reset-button .icon { display: none; }
  .zone-list { grid-template-columns: 1fr; }
}
@media (pointer: coarse) {
  .touch-pad {
    position: absolute; left: max(1rem, env(safe-area-inset-left)); bottom: calc(max(1rem, env(safe-area-inset-bottom)) + 3.4rem);
    display: grid; grid-template: repeat(2, 48px) / repeat(3, 48px); gap: .3rem; touch-action: none;
  }
  .touch-pad button { border: 1px solid #a1b5ab; border-radius: .2rem; background: #102423f2; font: 700 1.4rem var(--code); touch-action: none; user-select: none; }
  .touch-pad button:first-child { grid-column: 2; }
  .touch-pad button:nth-child(2) { grid-column: 1; }
  .touch-pad button[data-held] { border-color: var(--ink); background: var(--accent); color: var(--ink); }
  .control-guide { display: block; }
  .control-guide > :not(.touch-guide) { display: none; }
  .touch-guide { display: inline; }
  .map-pin { min-width: 24px; }
}
@media (pointer: coarse) and (max-width: 660px) {
  .control-guide { display: none; }
}
@media (pointer: coarse) and (max-height: 480px) {
  .touch-pad { left: auto; right: max(1rem, env(safe-area-inset-right)); }
}
