:root {
  color-scheme: dark;
  --ink: #e7eadf;
  --muted-ink: #b6c1b2;
  --deep-green: #173737;
  --night-green: #0c2426;
  --sand: #d6bb83;
  --sand-dark: #a17e48;
  --water: #81d9d3;
  --leaf: #a5ce6a;
  --coral: #ee8b63;
  --glass: rgba(10, 33, 34, 0.74);
  --glass-border: rgba(229, 234, 221, 0.18);
  --mono: "Cascadia Mono", Consolas, monospace;
  --body: Aptos, "Segoe UI", sans-serif;
  --display: Bahnschrift, "Arial Narrow", sans-serif;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; margin: 0; }

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 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;
}

body {
  overflow: hidden;
  background: var(--night-green);
  color: var(--ink);
  font-family: var(--body);
}

button, a { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.52; }

:where(button, a, [tabindex]):focus-visible {
  outline: 2px solid #f3e6c9;
  outline-offset: 3px;
  box-shadow: 0 0 0 5px rgba(129, 217, 211, 0.22);
}

.experience-shell {
  position: relative;
  min-height: 100svh;
  isolation: isolate;
  overflow: hidden;
}

#world {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.experience-shell.is-exploring:not(.is-pointer-locked):not(.is-touch) #world { cursor: grab; }
.experience-shell.is-exploring:not(.is-pointer-locked):not(.is-touch) #world:active { cursor: grabbing; }

#world:focus-visible {
  outline: 0;
  box-shadow: none;
}

#world:focus-visible ~ .navigation-hint {
  padding: 6px 9px;
  border: 1px solid rgba(243, 230, 201, 0.48);
  background: rgba(6, 30, 31, 0.7);
}

.experience-shell::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(5, 19, 20, 0.26), transparent 31%, rgba(5, 20, 19, 0.19)),
    radial-gradient(circle at 50% 47%, transparent 35%, rgba(4, 21, 21, 0.26) 100%);
  z-index: 1;
}

.topbar, .field-notebook, .mobile-notebook-toggle, .welcome-panel, .station-panel, .navigation-hint, .scene-caption, .touch-controls, .marker-layer, .reticle { position: absolute; }
.marker-layer, .reticle { z-index: 2; }
.field-notebook, .welcome-panel, .navigation-hint, .scene-caption, .touch-controls { z-index: 3; }
.topbar, .station-panel, .mobile-notebook-toggle { z-index: 4; }

.topbar {
  top: 0;
  left: 0;
  right: 0;
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px clamp(18px, 3vw, 48px);
  border-bottom: 1px solid rgba(231, 234, 223, 0.14);
  background: linear-gradient(180deg, rgba(6, 29, 30, 0.74), rgba(6, 29, 30, 0));
}

.wordmark {
  display: inline-flex;
  gap: 11px;
  align-items: center;
  min-height: 48px;
  margin: -6px;
  padding: 6px;
  color: var(--ink);
  text-decoration: none;
}

.wordmark-mark {
  display: grid;
  place-items: center;
  width: 35px;
  height: 35px;
  border: 1px solid var(--sand);
  color: var(--sand);
  font-family: var(--display);
  font-size: 16px;
}

.wordmark strong, .wordmark small { display: block; }
.wordmark strong { font-family: var(--display); font-size: 11px; letter-spacing: 0.08em; font-weight: 500; }
.wordmark small { margin-top: 3px; color: var(--muted-ink); font-family: var(--mono); font-size: 9px; letter-spacing: 0.05em; }

.world-status {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--muted-ink);
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.status-dot { width: 8px; height: 8px; background: var(--water); border-radius: 50%; box-shadow: 0 0 0 4px rgba(129, 217, 211, 0.12); }

.mobile-notebook-toggle { display: none; }

.field-notebook {
  top: 100px;
  right: clamp(18px, 3vw, 48px);
  width: 260px;
  max-height: calc(100svh - 124px);
  padding: 18px;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  backdrop-filter: blur(13px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(129, 217, 211, 0.42) transparent;
}

.notebook-heading { display: flex; justify-content: space-between; color: var(--sand); font-family: var(--mono); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; }
.progress-track { height: 2px; margin: 15px 0 12px; background: rgba(231, 234, 223, 0.15); }
.progress-track span { display: block; width: 0; height: 100%; background: var(--water); transition: width 320ms ease; }
.route-list { margin: 0; padding: 0; list-style: none; }
.route-list li { border-top: 1px solid rgba(231, 234, 223, 0.1); }
.route-list button { width: 100%; min-height: 44px; display: flex; gap: 10px; align-items: center; padding: 10px 0; border: 0; background: transparent; color: var(--muted-ink); text-align: left; font-family: var(--mono); font-size: 10px; }
.route-list button span { color: var(--ink); font-family: var(--body); font-size: 11px; }
.route-list li.is-visited button { color: var(--water); }
.route-list li.is-active button { color: var(--coral); }
.route-list button[aria-current="step"], .route-list button[aria-pressed="true"] { color: var(--coral); }
.next-stop { display: flex; justify-content: space-between; align-items: center; width: 100%; min-height: 44px; margin-top: 5px; padding: 10px 0 0; border: 0; border-top: 1px solid rgba(231, 234, 223, 0.16); background: transparent; color: var(--sand); font-size: 11px; text-align: left; }

.movement-modes {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid rgba(231, 234, 223, 0.16);
}

.mode-toggle {
  min-width: 0;
  min-height: 48px;
  display: grid;
  place-items: center;
  gap: 3px;
  padding: 6px 2px;
  border: 1px solid rgba(231, 234, 223, 0.2);
  background: rgba(7, 32, 33, 0.48);
  color: var(--muted-ink);
  font-family: var(--mono);
  font-size: 8px;
}

.mode-toggle kbd { color: var(--sand); font: inherit; font-size: 10px; }
.mode-toggle[aria-pressed="true"] { border-color: rgba(129, 217, 211, 0.78); background: rgba(129, 217, 211, 0.15); color: var(--ink); }
.mode-toggle[aria-pressed="true"] kbd { color: var(--water); }

.dimension-sheet {
  position: relative;
  margin-top: 16px;
  padding-top: 17px;
  border-top: 1px solid rgba(231, 234, 223, 0.16);
}

.dimension-sheet::before {
  content: "";
  position: absolute;
  top: -1px;
  right: 0;
  left: 0;
  height: 5px;
  background: repeating-linear-gradient(90deg, rgba(214, 187, 131, 0.62) 0 1px, transparent 1px 12px);
  pointer-events: none;
}

.dimension-sheet h2 {
  margin: 0 0 10px;
  color: var(--sand);
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 400;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.dimension-sheet dl {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px 12px;
  margin: 0;
}

.dimension-sheet dl div { min-width: 0; }
.dimension-sheet dt { color: var(--muted-ink); font-size: 9px; line-height: 1.25; }
.dimension-sheet dd { margin: 3px 0 0; color: var(--ink); font-family: var(--mono); font-size: 10px; line-height: 1.25; }

.welcome-panel { left: clamp(18px, 7vw, 104px); top: 50%; width: min(550px, calc(100% - 36px)); transform: translateY(-46%); transition: opacity 480ms ease, transform 480ms ease, visibility 480ms ease; }
.welcome-panel.is-hidden { opacity: 0; transform: translateY(-40%); visibility: hidden; pointer-events: none; }
.eyebrow, .station-kicker span { margin: 0 0 14px; color: var(--water); font-family: var(--mono); font-size: 10px; letter-spacing: 0.15em; }
.welcome-panel h1 { max-width: 630px; margin: 0; color: #f3e6c9; font-family: var(--display); font-size: clamp(30px, 4.3vw, 62px); font-weight: 500; line-height: 1.14; letter-spacing: -0.055em; }
.welcome-panel > p:not(.eyebrow) { max-width: 455px; margin: 22px 0 28px; color: var(--ink); font-size: clamp(14px, 1.25vw, 17px); line-height: 1.7; }
.welcome-actions { display: flex; align-items: center; gap: 17px; flex-wrap: wrap; }
.start-button { display: inline-flex; min-height: 48px; gap: 20px; align-items: center; padding: 12px 18px; border: 1px solid rgba(243, 230, 201, 0.5); background: var(--sand); color: var(--night-green); font-weight: 700; font-size: 13px; }
.start-button:hover { background: #ead2a1; }
.entry-note { color: var(--muted-ink); font-family: var(--mono); font-size: 10px; }

.station-panel { left: clamp(18px, 3vw, 48px); bottom: 84px; width: min(385px, calc(100% - 36px)); max-height: calc(100svh - 184px); padding: 20px; border-left: 3px solid var(--coral); background: rgba(7, 31, 31, 0.91); box-shadow: 0 16px 45px rgba(0, 0, 0, 0.25); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: rgba(238, 139, 99, 0.5) transparent; transition: opacity 220ms ease, transform 220ms ease; }
.station-panel.is-hidden { opacity: 0; transform: translateY(10px); pointer-events: none; visibility: hidden; }
.station-kicker { display: flex; justify-content: space-between; align-items: start; }
.station-kicker span { color: var(--coral); }
.station-kicker button { flex: 0 0 44px; width: 44px; height: 44px; margin: -11px -11px 0 0; border: 0; background: transparent; color: var(--ink); font-size: 24px; line-height: 1; }
.station-panel h2 { margin: 2px 0 9px; font-family: var(--display); font-size: 19px; font-weight: 500; letter-spacing: -0.04em; }
.station-panel p { margin: 0; color: var(--muted-ink); font-size: 13px; line-height: 1.6; }
.station-panel .station-prompt { margin-top: 12px; color: var(--sand); font-family: var(--mono); font-size: 10px; line-height: 1.5; }

.marker-layer { inset: 0; pointer-events: none; }
.world-marker[hidden] { display: none; }
.world-marker { position: absolute; transform: translate(-50%, -50%); display: grid; place-items: center; width: 48px; height: 48px; border: 1px solid rgba(241, 230, 205, 0.85); border-radius: 50%; background: rgba(16, 58, 57, 0.9); color: #fff4db; box-shadow: 0 0 0 7px rgba(129, 217, 211, 0.11); font-family: var(--mono); font-size: 10px; pointer-events: auto; transition: transform 160ms ease, background 160ms ease; }
.world-marker:hover, .world-marker.is-active { transform: translate(-50%, -50%) scale(1.12); background: var(--coral); }

.reticle { top: 50%; left: 50%; width: 8px; height: 8px; transform: translate(-50%, -50%); border: 1px solid rgba(243, 230, 201, 0.82); border-radius: 50%; opacity: 0; transition: opacity 200ms ease; pointer-events: none; }
.experience-shell.is-pointer-locked .reticle,
.experience-shell.is-exploring.is-touch .reticle { opacity: 1; }

.navigation-hint { left: 50%; bottom: 28px; display: flex; align-items: center; gap: 8px; transform: translateX(-50%); color: rgba(233, 236, 220, 0.74); font-family: var(--mono); font-size: 9px; letter-spacing: 0.03em; white-space: nowrap; }
.key-group { display: flex; gap: 2px; }
.key-group kbd, .escape-key, .mode-shortcuts kbd { display: inline-grid; place-items: center; min-width: 19px; height: 19px; padding: 0 3px; border: 1px solid rgba(233, 236, 220, 0.44); background: transparent; color: inherit; font: inherit; font-weight: 400; }
.escape-key { margin-left: 7px; min-width: 30px; }
.mode-shortcuts { display: inline-flex; align-items: center; gap: 4px; color: rgba(233, 236, 220, 0.86); }
.mouse-icon { color: var(--water); margin-left: 6px; font-size: 17px; }
.scene-caption { right: clamp(18px, 3vw, 48px); bottom: 28px; color: rgba(242, 230, 204, 0.72); font-family: var(--mono); font-size: 9px; letter-spacing: 0.14em; writing-mode: vertical-rl; }
.touch-controls { display: none; }
.experience-shell.is-exploring.is-touch .touch-controls {
  right: max(16px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  left: max(16px, env(safe-area-inset-left));
  display: flex;
  gap: 12px;
  align-items: end;
  justify-content: space-between;
  pointer-events: none;
}
.touch-direction-pad,
.touch-mode-pad { display: grid; grid-template-columns: repeat(3, 48px); gap: 5px; pointer-events: auto; }
.touch-direction-pad { grid-template-areas: ". forward ." "left backward right"; }
.touch-mode-pad { grid-template-areas: "up down ." "flight crouch run"; }
.touch-controls button { width: 48px; height: 48px; border: 1px solid rgba(231, 234, 223, 0.27); background: rgba(6, 30, 31, 0.77); color: var(--ink); font-size: 18px; backdrop-filter: blur(7px); touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
.touch-controls button[data-move="forward"] { grid-area: forward; }
.touch-controls button[data-move="left"] { grid-area: left; }
.touch-controls button[data-move="backward"] { grid-area: backward; }
.touch-controls button[data-move="right"] { grid-area: right; }
.touch-controls button[data-move="up"] { grid-area: up; }
.touch-controls button[data-move="down"] { grid-area: down; }
.touch-controls button[data-action="toggle-flight"] { grid-area: flight; }
.touch-controls button[data-action="toggle-crouch"] { grid-area: crouch; }
.touch-controls button[data-action="toggle-run"] { grid-area: run; }
.touch-controls .touch-mode { display: grid; place-items: center; align-content: center; gap: 1px; font-family: var(--mono); font-size: 10px; line-height: 1; }
.touch-controls .touch-mode [data-mode-label] { color: var(--muted-ink); font-size: 7px; text-transform: uppercase; }
.touch-controls .touch-mode[aria-pressed="true"] [data-mode-label] { color: var(--night-green); }
.touch-controls button[aria-pressed="true"] { border-color: var(--water); background: var(--sand); color: var(--night-green); }
.touch-controls [data-flight-only] { visibility: hidden; pointer-events: none; }
.experience-shell.is-flying .touch-controls [data-flight-only] { visibility: visible; pointer-events: auto; }
.experience-shell.is-touch .field-notebook .movement-modes { display: none; }
.experience-shell.is-touch .station-panel { bottom: 142px; max-height: calc(100svh - 242px); }
.experience-shell.is-touch .navigation-hint,
.experience-shell.is-touch .scene-caption { display: none; }

@media (max-width: 720px) {
  .topbar { min-height: 64px; padding: 13px 16px; }
  .wordmark { gap: 8px; }
  .wordmark strong { font-size: 10px; }
  .world-status { max-width: 110px; justify-content: flex-end; font-size: 8px; line-height: 1.35; text-align: right; }
  .mobile-notebook-toggle {
    top: 76px;
    right: max(12px, env(safe-area-inset-right));
    min-width: 132px;
    min-height: 44px;
    grid-template-columns: 1fr auto 22px;
    gap: 8px;
    align-items: center;
    padding: 7px 9px 7px 12px;
    border: 1px solid rgba(214, 187, 131, 0.52);
    background: rgba(7, 31, 31, 0.88);
    color: var(--sand);
    font-family: var(--mono);
    font-size: 9px;
    letter-spacing: 0.08em;
    text-align: left;
    text-transform: uppercase;
    backdrop-filter: blur(12px);
  }
  .mobile-notebook-toggle::before {
    content: "";
    position: absolute;
    right: 9px;
    bottom: -1px;
    left: 12px;
    height: 4px;
    background: repeating-linear-gradient(90deg, rgba(214, 187, 131, 0.66) 0 1px, transparent 1px 10px);
    pointer-events: none;
  }
  .experience-shell.is-exploring:not(.has-open-station) .mobile-notebook-toggle { display: grid; }
  .mobile-notebook-toggle #mobileProgressText { color: var(--muted-ink); font-size: 8px; }
  .mobile-notebook-icon { display: grid; place-items: center; width: 22px; height: 22px; border: 1px solid rgba(129, 217, 211, 0.32); color: var(--water); font-size: 14px; transition: transform 180ms ease, background 180ms ease; }
  .mobile-notebook-toggle[aria-expanded="true"] { border-color: rgba(129, 217, 211, 0.62); color: var(--water); }
  .mobile-notebook-toggle[aria-expanded="true"] .mobile-notebook-icon { transform: rotate(45deg); background: rgba(129, 217, 211, 0.12); }
  .field-notebook {
    top: 128px;
    right: 12px;
    left: 12px;
    width: auto;
    max-height: calc(100svh - 250px);
    padding: 12px;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-8px);
    transition: opacity 180ms ease, transform 180ms ease, visibility 180ms ease;
  }
  .experience-shell.is-exploring.is-mobile-notebook-open:not(.has-open-station) .field-notebook {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
  }
  .experience-shell.has-open-station .field-notebook,
  .experience-shell:has(.station-panel:not(.is-hidden)) .field-notebook { opacity: 0; visibility: hidden; pointer-events: none; }
  .route-list button { padding: 7px 0; }
  .route-list button span { font-size: 10px; }
  .next-stop { font-size: 10px; }
  .dimension-sheet { margin-top: 12px; padding-top: 14px; }
  .dimension-sheet dl { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; }
  .dimension-sheet dt { min-height: 23px; font-size: 8px; }
  .dimension-sheet dd { font-size: 9px; }
  .welcome-panel { top: clamp(88px, 18svh, 150px); right: 16px; left: 16px; width: auto; max-height: calc(100svh - 104px); padding-bottom: 12px; overflow-y: auto; transform: none; }
  .welcome-panel.is-hidden { transform: translateY(-10px); }
  .welcome-panel h1 { font-size: clamp(30px, 10.4vw, 44px); }
  .welcome-panel > p:not(.eyebrow) { max-width: 340px; margin: 17px 0 21px; font-size: 13px; }
  .station-panel { bottom: 126px; left: 12px; width: calc(100% - 24px); max-height: calc(100svh - 202px); padding: 16px; }
  .experience-shell.is-touch .station-panel { bottom: 126px; max-height: calc(100svh - 202px); }
  #world:focus-visible { outline: 2px solid rgba(243, 230, 201, 0.82); outline-offset: -3px; }
  .navigation-hint, .scene-caption { display: none; }
  .experience-shell.is-exploring.is-touch .touch-controls {
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    left: max(12px, env(safe-area-inset-left));
  }
}

@media (max-width: 360px) {
  .topbar { padding-inline: 12px; }
  .wordmark small { display: none; }
  .world-status { max-width: 96px; }
  .welcome-panel { right: 12px; left: 12px; }
  .welcome-panel h1 { font-size: 30px; }
  .welcome-actions { gap: 11px; }
  .dimension-sheet dl { grid-template-columns: 1fr 1fr; }
  .dimension-sheet dt { min-height: 0; }
  .touch-direction-pad,
  .touch-mode-pad { grid-template-columns: repeat(3, 44px); gap: 4px; }
  .touch-controls button { width: 44px; height: 44px; }
}

@media (max-height: 620px) and (max-width: 720px) {
  .welcome-panel { top: 82px; }
  .welcome-panel > p:not(.eyebrow) { line-height: 1.5; }
  .entry-note { max-width: 120px; }
}

@media (pointer: coarse) {
  .experience-shell.is-touch .navigation-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
