:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  line-height: 1.4;
}

body { margin: 0; background: #181818; }
.stage, .stage *, .stage *::before { box-sizing: border-box; }
.stage { -webkit-tap-highlight-color: transparent; }
.stage :is(button, input, select) { color: inherit; font: inherit; }
.stage :is(button, a, summary) { touch-action: manipulation; }
.stage :is(button, summary) { cursor: pointer; }
.stage a { color: inherit; text-decoration: none; }
.stage :focus-visible { outline: 2px solid #e4e4e4; outline-offset: 3px; }

.stage {
  --surface: rgb(22 22 22 / 94%);
  --solid: #202020;
  --border: #646464;
  --text: #f6f6f6;
  --soft-text: #ccc;
  --accent: #ddd;
  --highlight: #dadada;
  --edge: 1.25rem;
  --gap: 0.5rem;
  --target: 48px;
  --atlas-size: 8.5rem;
  --left: max(var(--edge), env(safe-area-inset-left, 0px) + 0.375rem);
  --right: max(var(--edge), env(safe-area-inset-right, 0px) + 0.375rem);
  --top: max(var(--edge), env(safe-area-inset-top, 0px) + 0.375rem);
  --pause-bottom: max(var(--edge), env(safe-area-inset-bottom, 0px) + 0.375rem);
  position: relative;
  content-visibility: auto;
  contain-intrinsic-block-size: auto 100dvh;
  isolation: isolate;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  block-size: 100vh;
  block-size: 100dvh;
  background: #292929;
  color: var(--text);
}

.game-scene { position: relative; min-inline-size: 0; }

#city {
  position: absolute;
  inset: 0;
  display: block;
  inline-size: 100%;
  block-size: 100%;
}

#city { pointer-events: none; }
.stage[data-session="playing"][data-state="ready"] #city { pointer-events: auto; touch-action: none; }
#city:focus { outline: none; }
.stage:is([data-state="error"], [data-graphics="lost"], [data-state="loading"]) #city { visibility: hidden; }

.sr-only {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.glass { border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }

.action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-block-size: var(--target);
  min-inline-size: var(--target);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 650;
  line-height: 1.2;
  text-align: center;
}

.stage button.action { font-size: 0.875rem; font-weight: 650; line-height: 1.2; }
.action .ui-icon { inline-size: 1.125rem; block-size: 1.125rem; flex: none; }
.action.primary {
  border: 1px solid #eee;
  border-radius: 6px;
  background: var(--highlight);
  color: #222;
}

@media (hover: hover) {
  .action.glass:hover:not(:disabled) { background: #383838; }
  .action.primary:hover { background: #e8e8e8; }
}

.action.glass:active:not(:disabled) { background: #525252; }
.action.primary:active { background: #bcbcbc; }

.title-screen {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  grid-template-rows: auto minmax(min-content, 1fr);
  gap: 1.5rem;
  overflow: auto;
  overscroll-behavior: contain;
  padding: var(--top) var(--right) var(--edge) var(--left);
  place-items: center;
  grid-template-rows: 1fr;
}

.stage:not([data-session="title"], [data-state="error"]) .title-screen { opacity: 0; visibility: hidden; pointer-events: none; }
@media (prefers-reduced-motion: no-preference) {
  .title-screen { transition: opacity 180ms ease-out, visibility 180ms; }
}
.site-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.375rem;
}

.site-links .action { overflow-wrap: break-word; }

.title-panel {
  align-self: center;
  justify-self: center;
  min-inline-size: 0;
  inline-size: min(100%, 32rem);
  text-align: center;
  padding-block-end: 1rem;
}

.brand {
  margin: 0 0 1rem;
  color: #f5f5f5;
  font: 600 5.5rem/0.98 Georgia, "Noto Serif SC", "Songti SC", SimSun, serif;
  text-shadow: 0 2px 18px #171717;
  text-wrap: balance;
}

.brand:lang(zh-CN) { max-inline-size: 7em; line-height: 1.15; }
.brand::before {
  display: block;
  inline-size: 3.25rem;
  block-size: 3px;
  margin-block-end: 1.375rem;
  display: none;
  content: "";
}

.start-actions { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 0.625rem; }
.stage #start-game { min-block-size: 3.5rem; padding-inline: 1.25rem; font-size: 1rem; }
.start-actions summary { min-block-size: 3.5rem; }
.stage:not([data-state="ready"]) #start-game, .stage[data-state="ready"] .notice { display: none; }
.notice { flex: 0 0 100%; max-inline-size: 25rem; color: var(--soft-text); }
.notice p { margin: 0; text-wrap: pretty; }
.notice:has(noscript > p) #status { display: none; }
.notice #retry { margin-block-start: 0.75rem; }
.notice #retry[hidden] { display: none; }

.seed-options { max-inline-size: 100%; }
.seed-options summary { inline-size: fit-content; list-style: none; }
.seed-options summary::-webkit-details-marker { display: none; }
.seed-options summary .ui-icon { inline-size: 0.875rem; block-size: 0.875rem; }
.seed-options[open] summary .ui-icon { transform: rotate(180deg); }
.seed-form { inline-size: min(19rem, 100%); margin-block-start: 0.5rem; padding: 0.75rem; }
.seed-form label { display: block; margin-block-end: 0.5rem; font-size: 0.875rem; }
.seed-row { display: flex; flex-wrap: wrap; gap: var(--gap); }
.seed-row input, #map-layer {
  min-block-size: var(--target);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.4375rem 0.625rem;
  background: #161616;
}
.seed-row input { flex: 1 1 6rem; inline-size: 0; min-inline-size: min(100%, 5rem); }

.hud {
  position: absolute;
  inset: var(--top) var(--right) var(--edge) var(--left);
  z-index: 2;
  display: none;
  grid-template: auto minmax(0, 1fr) auto / minmax(0, 1fr) auto;
  align-items: start;
  gap: var(--gap);
  pointer-events: none;
}
.stage[data-session="playing"][data-state="ready"] .hud { display: grid; }
.hud button { pointer-events: auto; }
.hud-actions { grid-area: 1 / 2; display: flex; gap: var(--gap); }
.hud-left {
  grid-area: 1 / 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--gap);
  min-inline-size: 0;
}
.render-perf {
  contain: layout style paint;
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  column-gap: .5rem;
  inline-size: min(100%, 10rem);
  margin: 0;
  padding: .3rem .5rem;
  color: var(--soft-text);
  font-size: .75rem;
  line-height: 1.4;
}
.render-perf dd { margin: 0; color: var(--text); text-align: end; font-variant-numeric: tabular-nums; }
.atlas {
  inline-size: min(var(--atlas-size), 100%);
  min-inline-size: 0;
  padding: 0.375rem;
}
.stage[data-touch="true"] .atlas { pointer-events: auto; }
.atlas-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0 0.25rem;
  margin-block-end: 0.25rem;
  color: var(--soft-text);
  font-size: 0.75rem;
  font-weight: 640;
}
.atlas-head h2 { margin: 0; font: inherit; }
.bearing { color: var(--accent); font-variant-numeric: tabular-nums; }
#map {
  display: block;
  inline-size: 100%;
  block-size: auto;
  aspect-ratio: 1;
  border-radius: 3px;
  outline: 1px solid var(--border);
  outline-offset: -1px;
  background: #172b32;
}
.location { margin: 0.25rem 0 0; font-size: 0.75rem; overflow-wrap: break-word; }
.location dd { margin: 0; }
.atlas[hidden], .game-debug[hidden] { display: none; }
.game-debug {
  grid-area: 2 / 1;
  align-self: end;
  justify-self: start;
  max-inline-size: 100%;
  margin: 0 0 .4rem;
  padding: .5rem;
  overflow: hidden;
  font-size: .75rem;
  white-space: pre-wrap;
}
#altitude { color: var(--soft-text); font-variant-numeric: tabular-nums; }

.control-hint {
  grid-area: 2 / 1 / 3 / 3;
  align-self: end;
  justify-self: center;
  max-inline-size: min(24rem, 100%);
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  font-size: 0.875rem;
  text-align: center;
  text-wrap: pretty;
}
.control-hint:empty { padding: 0; border: 0; }
.touch-actions { grid-area: 3 / 1 / 4 / 3; justify-self: end; display: none; gap: var(--gap); }
.stage[data-touch="true"] .walk-actions { display: flex; }
.stage .touch-actions button { padding-inline: 0.625rem; touch-action: none; }
.walk-actions :is(#sprint, #crouch)[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: #172a22;
  box-shadow: inset 0 -3px #567763;
}

.reticle, .stick { display: none; position: absolute; z-index: 1; pointer-events: none; }
.stage[data-session="playing"][data-state="ready"]:is([data-locked="true"], [data-touch="true"]) .reticle {
  inset: 50% auto auto 50%;
  display: block;
  inline-size: 6px;
  block-size: 6px;
  border: 1px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px #14231d;
  transform: translate(-50%, -50%);
}
.stage[data-session="playing"][data-state="ready"][data-touch="true"] .stick.drag {
  inset: clamp(2.125rem, var(--stick-y, 75%), 100% - 2.125rem) auto auto clamp(2.125rem, var(--stick-x, 25%), 100% - 2.125rem);
  display: grid;
  place-items: center;
  inline-size: 4.25rem;
  aspect-ratio: 1;
  border: 1px solid #dae8de;
  border-radius: 50%;
  background: rgb(19 28 27 / 55%);
  transform: translate(-50%, -50%);
}
.stick span {
  inline-size: 1.5rem;
  aspect-ratio: 1;
  border: 1px solid #fff;
  border-radius: 50%;
  background: var(--accent);
}

#pause-menu {
  inset: var(--top) var(--right) var(--pause-bottom) var(--left);
  inline-size: min(24rem, 100% - var(--left) - var(--right));
  max-block-size: calc(100vh - var(--top) - var(--pause-bottom));
  max-block-size: calc(100dvh - var(--top) - var(--pause-bottom));
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  background: var(--solid);
  color: var(--text);
  box-shadow: 0 14px 48px rgb(7 15 13 / 34%);
}
#pause-menu:modal { overscroll-behavior: contain; }
#pause-menu::backdrop { overflow: hidden; overscroll-behavior: contain; background: rgb(8 16 15 / 58%); }
#pause-title {
  margin: 0 0 1rem;
  color: #f5f5f5;
  font: 600 2.125rem/1.1 Georgia, "Noto Serif SC", "Songti SC", SimSun, serif;
  text-wrap: balance;
}
#resume-game { inline-size: 100%; }
.pause-actions { display: grid; gap: var(--gap); margin-block: var(--gap) 0.875rem; }
.pause-actions .action { justify-content: flex-start; }
.plan-setting { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--gap); font-size: 0.875rem; }
#map-layer { inline-size: min(8.5rem, 100%); }
.inspect-setting { display: flex; align-items: center; gap: .625rem; min-block-size: 44px; cursor: pointer; font-size: .875rem; }
.inspect-setting input { accent-color: var(--highlight); inline-size: 1.125em; block-size: 1.125em; margin: 0; cursor: inherit; }
.inspect-setting:has(:disabled) { opacity: .6; cursor: not-allowed; }

@media (max-width: 46rem) {
  .stage { --edge: 0.75rem; --atlas-size: 6.5rem; }
  .title-panel { margin-inline-start: 0; }
  .brand { font-size: 4rem; }
  .site-links .action { gap: 0.375rem; }
}

@media (max-width: 34rem) {
  .title-panel { align-self: end; }
  .brand { font-size: 3rem; }
  .site-links { justify-content: flex-start; }
  .site-links .action { padding-inline: 0.625rem; }
  .atlas-head, .location { font-size: 0.6875rem; }
  #pause-menu { padding: 0.875rem; }
  #pause-title { margin-block-end: 0.625rem; }
}

@media (max-height: 30rem) {
  .stage { --edge: 0.5rem; --atlas-size: 5.5rem; }
  .title-screen { gap: 0.625rem; }
  .title-panel { align-self: center; padding-block-end: 0.375rem; }
  .brand { max-inline-size: none; margin-block-end: 0.875rem; font-size: 2.625rem; }
  .brand::before { margin-block-end: 0.625rem; }
  #pause-menu { padding: 0.875rem; }
  #pause-title { margin-block-end: 0.625rem; }
  .pause-actions { grid-template-columns: repeat(auto-fit, minmax(min(100%, 8rem), 1fr)); }
}

@media (max-height: 18rem) {
  .stage { --atlas-size: 4.25rem; }
  .atlas-head, .location { line-height: 1.15; }
  .control-hint {
    justify-self: end;
    max-inline-size: min(24rem, 100% - var(--atlas-size) - var(--gap));
  }
  .brand { font-size: 2.25rem; }
  #pause-menu {
    inline-size: min(31rem, 100% - var(--left) - var(--right));
    padding-block: 0.625rem;
  }
  #pause-title { margin-block-end: 0.5rem; font-size: 1.5rem; }
  .pause-actions { margin-block: var(--gap); }
}

/* The title button takes over the live canvas without opening a menu. */
.enter-scene {
  position: absolute;
  inset: 0;
  inline-size: 100%;
  block-size: 100%;
  border: 0;
  background: transparent;
}
.enter-scene:focus-visible { outline-offset: -6px; }
.stage:not([data-debug]) :is(.hud-left, #toggle-map, .plan-setting, .control-hint, .walk-actions, .stick) {
  display: none;
}
/* Escape and controller Start pause anywhere. Touch also has a top-right target. */
.stage:not([data-debug]) #pause-game:not(:focus-visible) { opacity: 0; }
.stage:not([data-debug])[data-touch="false"] #pause-game:not(:focus-visible) { pointer-events: none; }
