:root {
  --bg: #0b0d12;
  --ink: #f3f1ea;
  --muted: #a9adb8;
  --accent: #f4cf1f;
  --card: rgba(14, 17, 24, 0.78);
  --line: rgba(255, 255, 255, 0.12);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

body:not(.plain) { overflow: hidden; overscroll-behavior: none; }

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

.ui { position: fixed; inset: 0; pointer-events: none; }
.ui > * { pointer-events: auto; }

/* Story panel */
.panel {
  position: absolute;
  left: clamp(16px, 3vw, 40px);
  top: clamp(16px, 4vh, 40px);
  width: min(400px, 34vw);
  max-height: calc(100% - 110px);
  overflow-y: auto;
  padding: 26px 26px 22px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  scrollbar-width: thin;
}
.panel.swap { animation: swap 0.45s ease both; }
@keyframes swap {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.me {
  width: 84px; height: 84px;
  border-radius: 14px;
  object-fit: cover;
  object-position: 50% 30%;
  border: 2px solid var(--accent);
  display: block;
  margin-bottom: 16px;
}
.name { margin: 0 0 6px; color: var(--accent); font-weight: 700; letter-spacing: 0.02em; }
.eyebrow {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}
.panel h1 { margin: 0 0 14px; font-size: clamp(30px, 3.4vw, 44px); line-height: 1.02; font-weight: 900; letter-spacing: -0.02em; }
.panel h2 { margin: 0 0 14px; font-size: clamp(26px, 2.8vw, 36px); line-height: 1.05; font-weight: 900; letter-spacing: -0.02em; }
.panel p { margin: 0 0 14px; line-height: 1.55; color: var(--muted); font-size: 15.5px; }
.panel p.problem { color: var(--ink); font-size: 17px; }
.panel .status { font-size: 13.5px; color: var(--ink); opacity: 0.85; }
.panel .credit { font-size: 11.5px; color: var(--ink); opacity: 0.55; margin-top: 18px; line-height: 1.45; }
.panel .credit a { color: inherit; }
.panel a { color: var(--ink); text-decoration-color: var(--accent); text-underline-offset: 3px; }
.panel ul { margin: 0 0 14px; padding-left: 18px; color: var(--muted); line-height: 1.55; font-size: 15.5px; }
.panel h3 { margin: 14px 0 2px; font-size: 16px; }
.panel .degree { color: var(--ink); margin-bottom: 6px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 14px; }
.btn {
  font: inherit; font-size: 14px; font-weight: 700;
  color: #14161b; background: var(--accent);
  border: 0; border-radius: 999px; padding: 9px 16px; cursor: pointer;
}
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn:hover { filter: brightness(1.08); }
.btn:focus-visible, .chip:focus-visible, .dots button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.media { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 14px; }
.media button { padding: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #000; cursor: zoom-in; width: 96px; height: 72px; position: relative; }
.media img, .media video { width: 100%; height: 100%; object-fit: cover; display: block; }
.media .play::after { content: "▶"; position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 20px; text-shadow: 0 1px 6px #000; }

.step { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 6px; padding-top: 14px; border-top: 1px solid var(--line); }
.step button { font: inherit; font-size: 14px; color: var(--ink); background: none; border: 0; cursor: pointer; padding: 6px 0; }
.step button:hover { color: var(--accent); }
.step button[disabled] { opacity: 0.3; cursor: default; }

/* Nav dots */
.dots {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  display: flex; gap: 6px; padding: 6px 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  max-width: calc(100% - 24px); overflow-x: auto;
}
.dots button {
  font: inherit; font-size: 13px; font-weight: 600; white-space: nowrap;
  color: var(--muted); background: none; border: 0; border-radius: 999px;
  padding: 7px 12px; cursor: pointer;
}
.dots button:hover { color: var(--ink); }
.dots button[aria-current="true"] { color: #14161b; background: var(--accent); }

.corner { position: absolute; right: clamp(12px, 2vw, 28px); top: clamp(12px, 3vh, 28px); display: flex; gap: 8px; }
.chip {
  font: inherit; font-size: 13px; color: var(--muted); text-decoration: none;
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 12px; cursor: pointer;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.chip:hover { color: var(--ink); }
kbd { font: inherit; font-size: 11px; border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; margin-left: 4px; }

.hint {
  position: absolute; right: clamp(12px, 2vw, 28px); bottom: 70px; margin: 0;
  font-size: 13px; color: var(--muted); transition: opacity 0.6s;
  pointer-events: none;
}
.hint.gone { opacity: 0; }

.tip {
  position: fixed; z-index: 5; pointer-events: none;
  background: #14161b; color: var(--ink); border: 1px solid var(--line);
  font-size: 13px; font-weight: 600; padding: 5px 10px; border-radius: 8px;
  transform: translate(14px, 14px); white-space: nowrap;
}
.toast {
  position: absolute; left: 50%; top: 22px; transform: translateX(-50%);
  background: var(--accent); color: #14161b; font-weight: 700; font-size: 14px;
  padding: 8px 16px; border-radius: 999px;
}

/* Jump palette */
.palette { position: fixed; inset: 0; z-index: 20; background: rgba(4, 6, 10, 0.55); display: grid; place-items: start center; padding-top: 16vh; }
.palette[hidden], .lightbox[hidden] { display: none; }
.palette-box { width: min(480px, calc(100% - 32px)); background: #12151c; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6); }
.palette input { width: 100%; font: inherit; font-size: 17px; color: var(--ink); background: none; border: 0; border-bottom: 1px solid var(--line); padding: 16px 18px; outline: none; }
.palette ul { list-style: none; margin: 0; padding: 6px; max-height: 46vh; overflow-y: auto; }
.palette li { padding: 10px 12px; border-radius: 8px; cursor: pointer; display: flex; justify-content: space-between; color: var(--ink); font-size: 15px; }
.palette li small { color: var(--muted); }
.palette li.on { background: rgba(244, 207, 31, 0.16); }

.lightbox { position: fixed; inset: 0; z-index: 30; background: rgba(4, 6, 10, 0.9); display: grid; place-items: center; padding: 24px; }
.lightbox img, .lightbox video { max-width: 100%; max-height: calc(100vh - 80px); border-radius: 10px; display: block; }
.lightbox button { position: absolute; top: 14px; right: 18px; font-size: 30px; color: var(--ink); background: none; border: 0; cursor: pointer; }

/* Plain version */
.plain-doc { display: none; max-width: 720px; margin: 0 auto; padding: 48px 20px 80px; }
body.plain #scene, body.plain .ui { display: none; }
body.plain .plain-doc { display: block; }
.plain-doc h1 { font-size: 40px; line-height: 1.05; margin: 0 0 12px; letter-spacing: -0.02em; }
.plain-doc h2 { font-size: 26px; margin: 44px 0 8px; }
.plain-doc h3 { margin: 18px 0 2px; }
.plain-doc p, .plain-doc li { color: var(--muted); line-height: 1.6; font-size: 16.5px; }
.plain-doc p.problem { color: var(--ink); }
.plain-doc a { color: var(--ink); text-decoration-color: var(--accent); text-underline-offset: 3px; }
.plain-doc img.shot { max-width: 100%; border-radius: 12px; border: 1px solid var(--line); margin: 6px 0; }

/* Phones and narrow windows: the panel becomes a bottom sheet */
@media (max-width: 820px) {
  .panel {
    left: 10px; right: 10px; top: auto; bottom: 64px; width: auto;
    max-height: 46vh; padding: 18px 18px 14px; border-radius: 16px;
  }
  .me { width: 56px; height: 56px; margin-bottom: 10px; }
  .dots { bottom: 10px; }
  .hint { display: none; }
  .corner { top: 10px; right: 10px; }
  #open-palette kbd { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .panel.swap { animation: none; }
}

/* walk-around mode: the story panel and stop dots step aside for a free camera */
body.walking .panel, body.walking .dots, body.walking .corner, body.walking .hint { display: none; }
.walkbar {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 14px; padding: 8px 8px 8px 18px;
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  font-size: 14px; color: var(--ink); max-width: calc(100vw - 32px); box-sizing: border-box;
}
.walkbar[hidden] { display: none; }
.walkbar .btn { margin: 0; }
@media (max-width: 600px) { .walkbar span { font-size: 12.5px; } }

/* garage-door intro: plays once per visit, then fades into the live scene */
.intro { position: fixed; inset: 0; z-index: 40; background: #05070b; transition: opacity 0.9s ease; }
.intro video { width: 100%; height: 100%; object-fit: cover; display: block; }
.intro.out { opacity: 0; pointer-events: none; }
.intro .chip { position: absolute; right: 20px; bottom: 20px; }
body.intro-on .ui { opacity: 0; }
.ui { transition: opacity 0.6s ease; }
