/* Victoria Avenue diorama — interface chrome.
   Shares the structure of the CBD model stylesheet, warmed up to match the
   toy-diorama palette. */

:root {
  --ink: #1c1f24;
  --ink-soft: #5b6270;
  --paper: rgba(252, 251, 249, 0.92);
  --line: rgba(28, 31, 36, 0.12);
  --accent: #d96e56;
  --radius: 12px;
  --shadow: 0 2px 4px rgba(20, 24, 30, 0.06), 0 8px 24px rgba(20, 24, 30, 0.12);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

/* The browser's own [hidden] rule lives in the UA stylesheet, so ANY author
   `display` declaration silently beats it. `.fallback { display: grid }` did
   exactly that and left the error panel painted over a perfectly good model.
   Assert it once, globally, rather than per element. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  color: var(--ink);
  background: #e8dcc6;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

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

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- loading ---------- */
#loading {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  background: linear-gradient(170deg, #f4e9d6 0%, #e0d0b4 100%);
  transition: opacity .6s ease, visibility .6s;
}
#loading.done { opacity: 0; visibility: hidden; }
.load-inner { text-align: center; width: min(280px, 70vw); }
.load-title { font-size: 1.35rem; font-weight: 600; letter-spacing: -0.02em; }
.load-sub { margin: .4rem 0 1rem; font-size: .8rem; color: var(--ink-soft); }
.load-bar { height: 2px; background: rgba(28,31,36,.12); border-radius: 2px; overflow: hidden; }
.load-fill { height: 100%; width: 0; background: var(--accent); transition: width .3s ease; }

.fallback {
  position: fixed; inset: 0; z-index: 200;
  display: grid; place-items: center; padding: 2rem;
  text-align: center; background: #e8eaec; font-size: .95rem;
}
.fallback > div { max-width: 30rem; }
.fallback h2 { margin: 0 0 .6rem; font-size: 1.1rem; font-weight: 600; }
.fallback p { margin: 0 0 .7rem; line-height: 1.55; color: var(--ink-soft); }
.fallback .reason:empty { display: none; }
.fallback .reason {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .78rem; color: var(--ink);
  background: rgba(28,31,36,.06); border-radius: 6px;
  padding: .5rem .7rem; word-break: break-word;
}
.fallback .hint { font-size: .82rem; }
.fallback button {
  margin: .2rem 0 1rem; padding: .4rem .85rem; cursor: pointer;
  border: 1px solid rgba(28,31,36,.22); border-radius: 8px;
  background: #fff; font: inherit; font-size: .8rem; color: inherit;
}
.fallback .reason { text-align: left; white-space: pre-wrap; }
.fallback code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .82em; background: rgba(28,31,36,.06);
  padding: .1rem .35rem; border-radius: 4px;
}
.fallback #page-url { word-break: break-all; }

/* ---------- header ---------- */
#hud {
  position: fixed; top: 0; left: 0; z-index: 10;
  padding: max(1rem, env(safe-area-inset-top)) 1.25rem 1rem;
  pointer-events: none;
  text-shadow: 0 1px 6px rgba(255,255,255,.9), 0 1px 2px rgba(255,255,255,.9);
}
#hud h1 {
  margin: 0; font-size: 1.1rem; font-weight: 650;
  letter-spacing: -0.015em; line-height: 1.1;
}
#hud h1 span { font-weight: 400; color: var(--ink-soft); }
#hud p { margin: .2rem 0 0; font-size: .72rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

body.night #hud { text-shadow: 0 1px 4px rgba(0,0,0,.6); }
body.night #hud h1 { color: #f2f4f7; }
body.night #hud h1 span,
body.night #hud p { color: #a8b2c0; }

body.walking #hud { opacity: 0; pointer-events: none; transition: opacity .25s ease; }

/* ---------- compass ---------- */
#compass {
  position: fixed; z-index: 10;
  top: max(1rem, env(safe-area-inset-top)); right: 1rem;
  width: 44px; height: 44px; padding: 0;
  border: none; border-radius: 50%;
  background: var(--paper); box-shadow: var(--shadow);
  cursor: pointer; backdrop-filter: blur(8px);
}
#compass svg { width: 100%; height: 100%; }
.c-ring { fill: none; stroke: var(--line); stroke-width: 1.5; }
.c-n { fill: var(--accent); }
.c-s { fill: #9aa3af; }
.c-label { font: 600 9px var(--font); fill: var(--ink-soft); text-anchor: middle; }

/* ---------- info panel ---------- */
#panel {
  position: fixed; z-index: 20;
  top: 4.75rem; right: 1rem; width: min(280px, calc(100vw - 2rem));
  padding: 1rem 1.1rem 1.1rem;
  background: var(--paper); backdrop-filter: blur(10px);
  border-radius: var(--radius); box-shadow: var(--shadow);
  animation: rise .22s cubic-bezier(.2,.7,.3,1);
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
#panel[hidden] { display: none; }
#panel-close {
  position: absolute; top: .4rem; right: .5rem;
  border: 0; background: none; font-size: 1.3rem; line-height: 1;
  color: var(--ink-soft); cursor: pointer; padding: .2rem .4rem;
}
#panel h2 {
  margin: 0 1.2rem .15rem 0; font-size: 1rem;
  font-weight: 600; letter-spacing: -0.01em;
}
.p-type {
  font-size: .72rem; color: var(--ink-soft);
  text-transform: capitalize; margin-bottom: .75rem;
}
#p-facts { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: .3rem .9rem; }
#p-facts dt { font-size: .72rem; color: var(--ink-soft); }
#p-facts dd {
  margin: 0; font-size: .8rem; font-weight: 550;
  font-variant-numeric: tabular-nums; text-align: right;
}
.p-note {
  margin: .8rem 0 0; padding-top: .7rem; border-top: 1px solid var(--line);
  font-size: .7rem; line-height: 1.45; color: var(--ink-soft);
}

/* ---------- dock ---------- */
#dock {
  position: fixed; z-index: 20;
  left: 50%; transform: translateX(-50%);
  bottom: max(1rem, env(safe-area-inset-bottom));
  width: min(430px, calc(100vw - 2rem));
  padding: .6rem .7rem;
  background: var(--paper); backdrop-filter: blur(10px);
  border-radius: var(--radius); box-shadow: var(--shadow);
  display: grid; gap: .5rem;
}
.dock-row { display: flex; align-items: center; gap: .5rem; }

.seg { display: flex; background: rgba(28,31,36,.06); border-radius: 8px; padding: 2px; }
.seg button {
  border: 0; background: none; cursor: pointer;
  padding: .35rem .85rem; border-radius: 6px;
  font: 500 .78rem var(--font); color: var(--ink-soft);
}
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(20,24,30,.12); }

.icon-btn {
  margin-left: auto; border: 1px solid var(--line); background: none;
  border-radius: 8px; padding: .35rem .7rem; cursor: pointer;
  font: 500 .78rem var(--font); color: var(--ink-soft);
}
.icon-btn[aria-expanded="true"] { background: rgba(28,31,36,.06); color: var(--ink); }

.time-row { gap: .7rem; }
#time-label {
  font: 550 .78rem/1 var(--font); font-variant-numeric: tabular-nums;
  min-width: 4.6rem; color: var(--ink);
}
#time {
  flex: 1; -webkit-appearance: none; appearance: none;
  height: 3px; border-radius: 3px; background: rgba(28,31,36,.15); outline: none;
}
#time::-webkit-slider-thumb {
  -webkit-appearance: none; width: 15px; height: 15px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(20,24,30,.3);
}
#time::-moz-range-thumb {
  width: 15px; height: 15px; border-radius: 50%; background: var(--accent);
  cursor: pointer; border: 2px solid #fff;
}

#layers {
  display: grid; gap: .35rem; padding-top: .5rem;
  border-top: 1px solid var(--line);
}
#layers[hidden] { display: none; }
#layers label {
  display: flex; align-items: center; gap: .5rem;
  font-size: .76rem; color: var(--ink-soft); cursor: pointer;
}
#layers input { accent-color: var(--accent); }

/* ---------- walk mode ---------- */
#street-help {
  position: fixed; z-index: 25; left: 50%; transform: translateX(-50%);
  top: max(1rem, env(safe-area-inset-top));
  display: flex; align-items: center; gap: .7rem; flex-wrap: wrap;
  justify-content: center;
  padding: .5rem .8rem; max-width: calc(100vw - 2rem);
  background: var(--paper); backdrop-filter: blur(10px);
  border-radius: 999px; box-shadow: var(--shadow); font-size: .74rem;
}
#street-help[hidden] { display: none; }
#street-help strong { font-weight: 600; }
#street-help kbd {
  display: inline-block; padding: .05rem .3rem; margin: 0 1px;
  border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 4px; font: 500 .68rem var(--font); background: #fff;
}
#street-exit {
  border: 0; background: var(--ink); color: #fff; cursor: pointer;
  border-radius: 999px; padding: .25rem .7rem; font: 500 .72rem var(--font);
}
.sh-touch { display: none; }
body.touch .sh-desktop { display: none; }
body.touch .sh-touch { display: inline; }

#joystick {
  position: fixed; z-index: 25;
  left: 1.5rem; bottom: max(5.5rem, calc(env(safe-area-inset-bottom) + 5.5rem));
  width: 108px; height: 108px; border-radius: 50%;
  background: rgba(252,251,249,.35); border: 1px solid rgba(255,255,255,.5);
  backdrop-filter: blur(6px); touch-action: none;
}
#joystick[hidden] { display: none; }
#joy-knob {
  position: absolute; left: 50%; top: 50%; width: 44px; height: 44px;
  margin: -22px 0 0 -22px; border-radius: 50%;
  background: var(--paper); box-shadow: var(--shadow);
}

/* ---------- attribution ---------- */
#attribution {
  padding-top: .45rem;
  border-top: 1px solid var(--line);
  font-size: .6rem; line-height: 1.45;
  color: var(--ink-soft); opacity: .85;
}
#attribution a { color: inherit; }

/* ---------- responsive ---------- */
@media (max-width: 640px) {
  #panel {
    top: auto; right: .75rem; left: .75rem; width: auto;
    bottom: calc(env(safe-area-inset-bottom) + 10.5rem);
  }
  #hud { padding-right: 4rem; }
  #dock { width: calc(100vw - 1.5rem); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}


/* ---------- diorama extras ---------- */
#cbd-link {
  position: fixed; z-index: 12;
  top: max(1rem, env(safe-area-inset-top)); right: 1rem;
  padding: .42rem .8rem; border-radius: 999px;
  background: var(--paper); box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  font: 500 .76rem var(--font); color: var(--ink-soft);
  text-decoration: none;
}
#cbd-link:hover { color: var(--ink); }

#street-exit { background: var(--accent); }

@media (max-width: 640px) {
  #cbd-link { font-size: .7rem; padding: .35rem .6rem; }
}
