:root {
  --ink: #14262b;
  --glass: rgb(20 38 43 / .86);
  --glass-solid: rgb(20 38 43 / .97);
  --sand: #d5b777;
  --sand-bright: #ead39e;
  --sand-wash: rgb(213 183 119 / .18);
  --cream: #f7f4e9;
  --muted: #b9c8c4;
  --line: rgb(247 244 233 / .13);
  --line-warm: rgb(213 183 119 / .34);
  --sky: #b8c9cc;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 14px;
  --radius-inner: 9px;
  --hit: 38px;
  --edge: 16px;
  --top: max(var(--edge), env(safe-area-inset-top));
  --right: max(var(--edge), env(safe-area-inset-right));
  --bottom: max(var(--edge), env(safe-area-inset-bottom));
  --left: max(var(--edge), env(safe-area-inset-left));
  --dock-height: calc(var(--hit) + 10px);
  --below-dock: calc(var(--top) + var(--dock-height) + 8px);
  --shadow: 0 10px 30px rgb(6 16 18 / .28), 0 1px 3px rgb(6 16 18 / .32);
  --fade: .18s;
}

html, body { width: 100%; height: 100%; overflow: hidden; overscroll-behavior: none; }
body { margin: 0; background: var(--sky); color: var(--cream); font: 14px/1.4 var(--font); -webkit-font-smoothing: antialiased; }
body > canvas:not(#map) { display: block; position: fixed; inset: 0; touch-action: none; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--sand-bright); outline-offset: 2px; }
a { color: var(--sand-bright); text-underline-offset: 3px; }
kbd {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; box-sizing: border-box;
  border: 1px solid var(--line-warm); border-bottom-width: 2px; border-radius: 5px;
  font: 600 11px/1 var(--font); color: var(--cream); background: rgb(247 244 233 / .06);
}
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.eyebrow { margin: 0; font-size: 10.5px; font-weight: 650; letter-spacing: .09em; text-transform: uppercase; color: var(--sand); }

.surface {
  background: var(--glass); color: var(--cream);
  border: 1px solid var(--line); box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(14px) saturate(1.15); backdrop-filter: blur(14px) saturate(1.15);
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-width: var(--hit); min-height: var(--hit); padding: 0 12px; box-sizing: border-box;
  border: 0; border-radius: 999px; background: transparent;
  font-size: 13.5px; font-weight: 550; white-space: nowrap;
  transition: background-color var(--fade), color var(--fade);
}
.btn:hover { background: rgb(247 244 233 / .08); }
.btn[aria-pressed="true"], .btn[aria-expanded="true"] { background: var(--sand-wash); color: var(--sand-bright); }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn-icon { padding: 0; }
.btn-primary { background: var(--sand); color: var(--ink); padding: 0 16px; }
.btn-primary:hover { background: var(--sand-bright); }
.btn-row { justify-content: flex-start; width: 100%; border-radius: var(--radius-inner); padding: 0 10px; font-weight: 500; }

/* Dock: place picker, place details, overview, more */
#dock {
  position: fixed; z-index: 10; top: var(--top); left: var(--left);
  display: flex; align-items: center; gap: 2px; padding: 4px; border-radius: 999px;
}
#places-button {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto auto; column-gap: 10px; align-items: center;
  align-content: center; width: 250px; height: var(--hit); padding: 0 12px 0 16px; text-align: left; border-radius: 999px;
}
#places-button .eyebrow { grid-column: 1; font-size: 9.5px; line-height: 1.25; }
#place-name { grid-column: 1; font-size: 14px; font-weight: 600; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#places-button svg { grid-column: 2; grid-row: 1 / 3; width: 14px; height: 14px; color: var(--sand); transition: transform var(--fade); }
#places-button[aria-expanded="true"] svg { transform: rotate(180deg); }
#dock .divider { width: 1px; height: 22px; margin: 0 4px; background: var(--line); }

/* Panels that drop from the dock */
.panel {
  position: fixed; z-index: 11; top: var(--below-dock); left: var(--left);
  border-radius: var(--radius); box-sizing: border-box; background: var(--glass-solid);
}
#places {
  display: flex; flex-direction: column; width: 368px;
  max-height: min(600px, calc(100dvh - var(--below-dock) - var(--bottom)));
  overflow: hidden;
}
.search { position: relative; padding: 10px; border-bottom: 1px solid var(--line); }
.search svg { position: absolute; left: 22px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search kbd { position: absolute; right: 20px; top: 50%; transform: translateY(-50%); color: var(--muted); }
#place-search {
  width: 100%; height: 40px; box-sizing: border-box; padding: 0 40px 0 38px;
  border: 1px solid var(--line); border-radius: var(--radius-inner); background: rgb(4 12 14 / .32);
  font-size: 15px; caret-color: var(--sand);
}
#place-search::placeholder { color: var(--muted); opacity: .8; }
#place-search:focus-visible { outline: 0; border-color: var(--sand); box-shadow: 0 0 0 3px var(--sand-wash); }
#place-list { flex: 1 1 auto; overflow-y: auto; scrollbar-width: thin; scrollbar-color: rgb(247 244 233 / .22) transparent; overscroll-behavior: contain; padding: 0 6px 6px; scroll-padding: 34px 0 6px; }
.group-label {
  position: sticky; top: 0; z-index: 1; margin: 0 -6px; padding: 12px 16px 6px;
  background: var(--glass-solid); font-size: 10.5px; font-weight: 650; letter-spacing: .09em; text-transform: uppercase; color: var(--sand);
}
[role="option"] {
  display: grid; grid-template-columns: 8px minmax(0, 1fr) auto; align-items: center; column-gap: 8px;
  min-height: var(--hit); padding: 6px 10px 6px 8px; box-sizing: border-box; border-radius: var(--radius-inner);
  cursor: pointer; user-select: none;
}
[role="option"]:hover { background: rgb(247 244 233 / .06); }
[role="option"][aria-selected="true"] { background: var(--sand-wash); box-shadow: inset 2px 0 var(--sand); }
[role="option"] .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
[role="option"] .sub { font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
[role="option"]::before { content: ""; width: 6px; height: 6px; border-radius: 50%; }
[role="option"][aria-current]::before { background: var(--sand); }
[role="option"][aria-current] .title { color: var(--sand-bright); }
.empty { margin: 0; padding: 20px 16px; color: var(--muted); }
.panel-foot {
  display: flex; justify-content: space-between; margin: 0; padding: 8px 16px;
  border-top: 1px solid var(--line); font-size: 11.5px; color: var(--muted);
}

#more { width: 240px; padding: 6px; }
#more .eyebrow { padding: 8px 10px 4px; }
#more hr { margin: 6px 4px; border: 0; border-top: 1px solid var(--line); }
[role="switch"]::after {
  content: ""; margin-left: auto; width: 30px; height: 18px; border-radius: 999px; flex: none;
  background: radial-gradient(circle at 9px 50%, var(--cream) 6px, transparent 6.5px) rgb(247 244 233 / .18);
  transition: background-color var(--fade), background-position var(--fade);
}
[role="switch"][aria-checked="true"]::after {
  background: radial-gradient(circle at 21px 50%, var(--ink) 6px, transparent 6.5px) var(--sand);
}

/* Place caption: the #detail text, shown on arrival and dismissible */
#caption {
  position: fixed; z-index: 5; top: var(--below-dock); left: var(--left);
  width: min(368px, calc(100vw - var(--left) - var(--right))); box-sizing: border-box;
  margin: 0; padding: 12px 16px 14px; border-radius: var(--radius);
  transition: opacity var(--fade), transform var(--fade);
}
#detail { margin: 0; white-space: pre-line; font-size: 13.5px; line-height: 1.5; color: var(--muted); }
body.ui-ready #detail { display: none; }
#caption-title { margin: 0; padding-right: 28px; font-size: 15px; font-weight: 650; line-height: 1.3; color: var(--cream); }
#caption-meta { margin: 2px 0 0; font-size: 12.5px; color: var(--sand-bright); }
#caption-text { margin: 6px 0 0; white-space: pre-line; font-size: 13.5px; line-height: 1.5; color: var(--muted); }
#caption-text:empty, #caption-meta:empty { display: none; }
#caption-close { position: absolute; top: 6px; right: 6px; min-width: 32px; min-height: 32px; color: var(--muted); }
#caption-close svg { width: 14px; height: 14px; }
#touch-hint { display: none; margin: 10px 0 0; padding-top: 9px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }

/* Bottom centre: the start prompt, or a transient arrival label while walking */
#prompt, #toast {
  position: fixed; z-index: 4; left: 50%; bottom: calc(var(--bottom) + 4px); transform: translateX(-50%);
  display: flex; align-items: center; gap: 14px; border-radius: 999px; white-space: nowrap;
}
#prompt { padding: 5px 18px 5px 5px; }
#prompt .keys { margin: 0; display: flex; align-items: center; gap: 4px; font-size: 12.5px; color: var(--muted); }
#prompt .keys span { margin: 0 8px 0 4px; }
#prompt .keys span:last-child { margin-right: 0; }
#toast {
  display: block; max-width: calc(100vw - var(--left) - var(--right)); box-sizing: border-box; overflow: hidden; text-overflow: ellipsis;
  padding: 9px 16px; font-size: 13.5px; font-weight: 600; pointer-events: none;
  opacity: 0; transform: translate(-50%, 6px); transition: opacity .3s, transform .3s;
}
#toast.show { opacity: 1; transform: translateX(-50%); }

/* Walking HUD: where you are, how to move, how to get the menu back */
#hud {
  position: fixed; z-index: 4; left: 50%; bottom: calc(var(--bottom) + 4px); transform: translateX(-50%);
  display: flex; align-items: center; height: 36px; padding: 0 12px 0 16px; box-sizing: border-box;
  border-radius: 999px; white-space: nowrap; pointer-events: none; font-size: 12.5px;
  transition: opacity .6s, visibility 0s;
}
#hud-place { max-width: 260px; overflow: hidden; text-overflow: ellipsis; font-size: 13px; font-weight: 600; }
#hud > span + span { display: flex; align-items: center; gap: 4px; height: 20px; margin-left: 12px; padding-left: 12px; border-left: 1px solid var(--line); }
#hud .hud-keys span { margin: 0 8px 0 4px; color: var(--muted); }
#hud .hud-keys span:last-child { margin-right: 0; }
#hud .hud-exit span { margin-left: 4px; }
#hud.learned .hud-keys { display: none; }
#hud.quiet { opacity: .82; }
#hud.quiet .hud-keys span { color: var(--cream); }

/* Resident chip */
#resident-panel { position: fixed; z-index: 6; top: var(--top); right: var(--right); width: max-content; max-width: 320px; border-radius: 22px; }
#resident-panel summary {
  display: flex; align-items: center; gap: 9px; min-height: calc(var(--hit) + 8px); padding: 0 16px 0 14px; box-sizing: border-box;
  list-style: none; cursor: pointer; border-radius: 22px;
}
#resident-panel summary::-webkit-details-marker { display: none; }
#resident-panel summary::after { content: ""; width: 6px; height: 6px; margin-left: 2px; border: solid var(--sand); border-width: 0 1.5px 1.5px 0; transform: translateY(-2px) rotate(45deg); transition: transform var(--fade); }
#resident-panel[open] summary::after { transform: translateY(1px) rotate(-135deg); }
#resident-panel .pulse { width: 8px; height: 8px; border-radius: 50%; background: #8be1cf; box-shadow: 0 0 0 3px rgb(139 225 207 / .22); flex: none; }
#resident-panel .chip-label { font-weight: 600; }
#resident-status { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 13px; }
#resident-panel[open] { width: 300px; border-radius: var(--radius); }
#resident-panel[open] summary { flex-wrap: wrap; row-gap: 0; padding-top: 6px; }
#resident-panel[open] #resident-status { display: block; order: 3; flex-basis: 100%; max-width: none; padding: 0 0 6px 17px; white-space: normal; color: var(--cream); font-size: 14px; }
.resident-body { padding: 0 14px 14px; }
.resident-body .now { margin: 0; font-size: 14px; }
#resident-memory { margin: 6px 0 12px; font-size: 12.5px; line-height: 1.45; color: var(--muted); }
#resident-memory:empty { display: none; }
.resident-body .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.resident-body .actions .btn { flex: 1 1 auto; border: 1px solid var(--line-warm); }

/* Minimap: context.js draws 640x220, shown at the same ratio */
#map {
  position: fixed; z-index: 3; right: var(--right); bottom: var(--bottom);
  width: 288px; height: 99px; border: 1px solid var(--line-warm); border-radius: 10px;
  box-shadow: var(--shadow); pointer-events: none; transition: opacity var(--fade);
}

#cross { position: fixed; z-index: 3; left: 50%; top: 50%; width: 14px; height: 14px; margin: -7px 0 0 -7px; pointer-events: none; }
#cross::before, #cross::after { content: ""; position: absolute; background: var(--cream); box-shadow: 0 0 0 1px rgb(10 22 25 / .45); border-radius: 1px; }
#cross::before { left: 6px; top: 0; width: 2px; height: 14px; }
#cross::after { top: 6px; left: 0; width: 14px; height: 2px; }

#about {
  width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); box-sizing: border-box;
  padding: 26px 28px 24px; border-radius: 18px; background: var(--glass-solid); overflow: auto;
}
#about::backdrop { background: rgb(10 22 25 / .45); }
#about h2 { margin: 6px 0 4px; font-size: 24px; letter-spacing: -.01em; }
#about h3 { margin: 22px 0 8px; font-size: 10.5px; letter-spacing: .09em; text-transform: uppercase; color: var(--sand); }
#about p { margin: 0 0 8px; line-height: 1.55; color: var(--muted); }
#about .lede { color: var(--cream); }
#about .eyebrow { margin: 0; padding-right: 40px; color: var(--sand); }
#about form { position: absolute; top: 12px; right: 12px; margin: 0; }
#about .btn-icon { color: var(--muted); }
#about .btn-icon svg { width: 16px; height: 16px; }
.controls { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; align-items: center; margin: 0; }
.controls dt { display: flex; gap: 4px; }
.controls dd { margin: 0; color: var(--muted); }
.controls.touch { display: none; }
.links { display: flex; gap: 20px; margin-top: 4px; }

#touch-pad, #touch-knob { display: none; }

/* Interaction states. body[data-state] is set by ui.js. */
#dock, #resident-panel, #caption, #prompt, #map { transition: opacity var(--fade), visibility 0s; }
body[data-state="loading"] :is(#dock, #resident-panel, #prompt, #map, #cross),
body[data-state="walking"] :is(#resident-panel, #caption, #prompt, #toast),
body.pointer-locked #dock,
body:not([data-state="walking"]) #hud, body:not(.pointer-locked) #hud,
body:not([data-state="walking"]) #cross,
body:is([data-state="overview"], [data-state="loading"]) #toast,
body:not([data-state="entry"], [data-state="watching"], [data-state="overview"]) #prompt,
body.caption-closed #caption,
body:is(.places-open, .more-open) :is(#caption, #prompt) { opacity: 0; visibility: hidden; pointer-events: none; }
body[data-state="walking"] #map { opacity: .82; }
body[data-state="overview"] #caption-close { display: none; }
body[data-state="overview"] #prompt { padding-right: 5px; }
body[data-state="overview"] #prompt .keys { display: none; }

body[data-state="overview"] #touch-hint { display: none !important; }

@media (max-width: 1180px) { #map { width: 220px; height: 76px; } }
@media (max-width: 980px) {
  #prompt { padding-right: 5px; }
  #prompt .keys { display: none; }
  #resident-panel:not([open]) #resident-status { display: none; }
  #hud { bottom: auto; top: var(--top); }
}
@media (max-width: 520px) { #hud .hud-keys { display: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; }
  #toast, #toast.show { transform: translateX(-50%); }
}

/* Phones and touch screens */
@media (max-width: 760px), (pointer: coarse) {
  :root { --hit: 44px; --edge: 10px; }
  #places-button { width: auto; flex: 1 1 auto; min-width: 0; }
  #dock { right: var(--right); max-width: 440px; box-sizing: border-box; }
  #caption, #places { max-width: 440px; }
  #dock .label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  #places { left: var(--left); right: var(--right); width: auto; max-height: calc(100dvh - var(--below-dock) - var(--bottom)); }
  #place-search { font-size: 16px; height: 44px; }
  .search kbd { display: none; }
  #more { left: auto; right: var(--right); }
  #caption { width: auto; right: var(--right); }
  #touch-hint { display: block; }
  #caption-close { top: 0; right: 0; min-width: var(--hit); min-height: var(--hit); }
  #prompt, .controls.keys { display: none; }
  .controls.touch { display: grid; }
  #map { width: 132px; height: 46px; opacity: .9; }
  #resident-panel { top: auto; bottom: calc(var(--bottom) + 46px + 8px); max-width: calc(100vw - var(--right) - 160px); }
  #resident-panel[open] { width: calc(100vw - var(--right) - 160px); max-width: 300px; }
  #resident-status { display: none; }
  #resident-panel summary { padding: 0 14px 0 14px; }
  #toast { bottom: auto; top: var(--below-dock); }
  #dock, #resident-panel { transition-delay: .5s; }
  body.pointer-locked #dock { transition-delay: 0s; }
  #touch-pad {
    display: grid; place-items: center; position: fixed; z-index: 4;
    bottom: calc(22px + env(safe-area-inset-bottom)); left: calc(22px + env(safe-area-inset-left));
    width: 116px; height: 116px; border: 1px solid rgb(232 212 161 / .6); border-radius: 50%;
    background: rgb(20 38 43 / .5); touch-action: none; user-select: none; -webkit-user-select: none;
  }
  #touch-knob { display: block; width: 46px; height: 46px; border: 1px solid #fff8df; border-radius: 50%; background: rgb(213 183 119 / .78); pointer-events: none; }
  body.menu-open #touch-pad { visibility: hidden; }
}
@media (max-height: 450px) and (pointer: coarse) {
  #touch-pad { width: 96px; height: 96px; bottom: calc(14px + env(safe-area-inset-bottom)); }
}

#game-startup { width: min(380px, calc(100% - 64px)); padding: 20px; border-radius: var(--radius); }
#game-startup::backdrop { background: rgb(6 16 18 / .65); }
/* The game's loading screen says what is loading. The street's own loading line would show behind it. */
body:has(#game-startup[open]) #caption { display: none; }
#game-startup h1 { margin: 0; font-size: 23px; }
#game-startup .btn { border: 1px solid var(--line-warm); text-decoration: none; }
#game-startup .tip { margin: 14px 0 0; font-size: 13px; opacity: .75; }
:is(#chooser, #room-closed) { box-sizing: border-box; width: min(420px, calc(100% - 32px)); padding: 20px; border-radius: var(--radius); }
#chooser::backdrop { background: rgb(6 16 18 / .92); }
#room-closed::backdrop { background: rgb(6 16 18 / .8); }
:is(#chooser, #room-closed) h1 { margin: 0; font-size: 23px; }
:is(#chooser, #room-closed) nav { display: grid; gap: 10px; }
:is(#chooser, #room-closed) .btn { display: grid; justify-content: stretch; justify-items: start; gap: 2px; padding: 12px 14px; border: 1px solid var(--line-warm); border-radius: var(--radius-inner); text-align: left; text-decoration: none; white-space: normal; }
:is(#chooser, #room-closed) .btn span { font-weight: 400; opacity: .85; }
#room-closed .btn-primary { border-color: transparent; }
