:root {
  --ink: #f4efe4;
  --muted: #c8bfb0;
  --bg: #141218;
  --panel: #241f2a;
  --line: #3e3648;
  --wall: #f4efe6;
  --floor: #e7c99a;
  --lamp: #f0c14a;
  --miss: #e07a5f;
  --shadow: 0 16px 0 #0d0e12;
  --display: "Pixelify Sans", "Arial Rounded MT Bold", sans-serif;
  --body: "Atkinson Hyperlegible", "Trebuchet MS", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(180deg, #2a2233 0%, var(--bg) 28%);
  font-family: var(--body);
}

.top, main {
  width: min(1080px, calc(100% - 32px));
  margin: 0 auto;
}

.top {
  position: relative;
  z-index: 21;
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  padding: 28px 0 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--lamp);
  font-family: var(--display);
  font-size: 16px;
  letter-spacing: 0.04em;
}

h1, h2, #next, #again, #open-file, #exit-room {
  font-family: var(--display);
}

h1 {
  margin: 0;
  font-size: clamp(42px, 6vw, 64px);
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 0.9;
}

h2 { margin: 0; font-size: 26px; font-weight: 700; }

.scoreboard {
  display: flex;
  gap: 16px;
  margin: 0;
}

.scoreboard dt {
  color: var(--muted);
  font-size: 13px;
}

.scoreboard dd, .gain, #ending-score, #intro-best {
  margin: 0;
  font-family: var(--body);
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums lining-nums;
  letter-spacing: 0;
}

main {
  display: grid;
  grid-template-columns: 1.4fr 0.8fr;
  gap: 18px;
  padding-bottom: 48px;
}

.stage, .sheet, .ending-card {
  background: var(--panel);
  border: 3px solid #0d0e12;
  box-shadow: var(--shadow);
}

.stage-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 12px;
  align-items: center;
  padding: 14px 14px 0;
}

.stage-bar p, .gain, .ending-card p {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
}

.agent-line {
  box-sizing: border-box;
  width: 100%;
  height: calc(1.35em * 5);
  margin: 10px 0 0;
  padding: 0 14px;
  overflow: hidden;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.35;
  text-align: left;
  contain: strict;
}
.spoken .word { opacity: 0; }
.spoken .word.on { opacity: 1; }
.who { color: var(--lamp); font-family: var(--display); margin-right: 6px; }
.intro-rule { font-size: 15px; }

.viewport {
  position: relative;
  height: min(520px, 62vh);
  margin: 14px;
  overflow: hidden;
  border: 3px solid #10141c;
  background: var(--wall);
  touch-action: none;
  cursor: grab;
  user-select: none;
}

.viewport.camera-shut { cursor: default; }
.viewport:active:not(.camera-shut) { cursor: grabbing; }

.gimbal {
  position: absolute;
  z-index: 3;
  left: 8px;
  bottom: 8px;
  width: 36px;
  height: 36px;
  opacity: 0.9;
  pointer-events: none;
}

.viewport::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0.18;
  background-image: radial-gradient(rgba(247, 241, 230, 0.45) 0.5px, transparent 0.7px);
  background-size: 3px 3px;
  mix-blend-mode: overlay;
}

.viewport.camera-shut .gimbal { visibility: hidden; }
.viewport.drift .gimbal { opacity: 0.55; }

#frame {
  margin: 0;
  padding: 4px 8px;
  border: 3px solid #0d0e12;
  background: #1b1408;
  color: var(--lamp);
  font: 700 14px/1 var(--display);
  cursor: pointer;
  flex: 0 0 auto;
}

.room {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 12px;
  position: absolute;
  left: 0;
  top: 0;
  width: 104%;
  height: 104%;
  margin: 0;
  padding: 5% 6% 4%;
  background: var(--wall);
  transform: translate(var(--aim-x, 0px), var(--aim-y, 0px));
}

.room::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 34%;
  bottom: 0;
  height: auto;
  background-image:
    linear-gradient(#8a5a3c, #8a5a3c),
    linear-gradient(180deg, rgba(255, 248, 236, 0.22), rgba(120, 78, 40, 0.08)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='36' height='64' viewBox='0 0 36 64'%3E%3Crect width='17' height='64' fill='%23f3ddb4'/%3E%3Crect x='18' width='18' height='64' fill='%23e4c48f'/%3E%3Crect width='1' height='64' fill='%23b08455'/%3E%3Crect x='17' width='1' height='64' fill='%23b08455'/%3E%3Crect y='63' width='17' height='1' fill='%23a97848'/%3E%3Crect x='18' y='31' width='18' height='1' fill='%23a97848'/%3E%3C/svg%3E");
  background-size: 100% 6px, 100% 100%, 36px 64px;
  background-repeat: no-repeat, no-repeat, repeat;
  background-position: top left, 0 0, 0 6px;
  pointer-events: none;
  z-index: 0;
}

.decor { position: absolute; inset: 0; pointer-events: none; z-index: 0; }
.garland { position: absolute; left: 2%; top: 5%; width: 94%; height: auto; aspect-ratio: 1000 / 100; overflow: visible; }
.garland .glow { opacity: 0.72; }
.garland .lamp-bulb { filter: drop-shadow(0 0 2px currentColor) drop-shadow(0 0 6px currentColor); }
.room.lamp-lit .garland .glow { opacity: 0.5; }
.room:not(.lamp-lit) .garland .glow { opacity: 0.95; }
.room:not(.lamp-lit) .garland .lamp-bulb { filter: drop-shadow(0 0 3px #fff8ee) drop-shadow(0 0 8px currentColor) drop-shadow(0 0 16px currentColor); }
.candle { position: absolute; z-index: 2; left: 9%; top: 76%; width: 26px; height: 44px; pointer-events: none; }
.candle svg { width: 100%; height: 100%; display: block; }
.candle .flame { transform-box: fill-box; transform-origin: center bottom; }
@media (prefers-reduced-motion: no-preference) {
  .candle .flame { animation: flame 1.4s ease-in-out infinite; }
  .room:not(.lamp-lit) .garland .glow { animation: bulb 1.8s ease-in-out infinite; }
}
@keyframes bulb {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}
@keyframes flame {
  0%, 100% { opacity: 1; transform: scaleY(1); }
  50% { opacity: 0.65; transform: scaleY(0.8); }
}
.pumpkin { position: absolute; left: 70%; top: 56%; width: 46px; height: 42px; }
.door-stand {
  position: absolute;
  z-index: 1;
  bottom: 66%;
  width: 7%;
  height: 88px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.door-stand.left { left: 18%; }
.door-stand.right { right: 28%; }
.door-stand svg { width: 100%; height: 88px; }
.room.mood-dim { filter: brightness(0.9); }
.room.mood-warm::after { opacity: 1; }
.outliner.holding .object { cursor: progress; }
.outliner.holding .object[data-id="key"] { cursor: pointer; }

.room::after {
  content: "";
  position: absolute;
  width: 52px;
  height: 52px;
  right: 16%;
  top: 24%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(240, 193, 74, 0.34), transparent 70%);
  filter: blur(1px);
  pointer-events: none;
  transform-origin: center center;
  transition: width 700ms ease, height 700ms ease, right 700ms ease, top 700ms ease, opacity 700ms ease;
}

.room.lamp-lit { background: #fff8ee; }

.room.lamp-lit::after {
  width: 168px;
  height: 168px;
  right: calc(16% - 58px);
  top: calc(24% - 58px);
  opacity: 1;
  background: radial-gradient(circle, rgba(244, 212, 138, 0.72), transparent 68%);
}

.sconce {
  position: absolute;
  z-index: 1;
  right: 16%;
  top: 20%;
  width: 44px;
  height: 48px;
  pointer-events: none;
}

.sconce svg { width: 100%; height: 100%; overflow: visible; }
.room.lamp-lit .sconce .shade { fill: #f4d48a; }
.room.lamp-lit .sconce { filter: drop-shadow(0 0 10px rgba(244, 212, 138, 0.85)); }

.room.mood-late { filter: brightness(0.94); }
.room.mood-dark { filter: brightness(0.82); }

.room.mood-dark::after { opacity: 0.55; }
.room.key-off::after { opacity: 0; }

.room.agent-touch::after { animation: key-pulse 520ms ease-out; }

@keyframes key-pulse {
  from { transform: scale(1.35); opacity: 1; }
  to { transform: none; opacity: 1; }
}

.cell {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: center;
  min-height: 100px;
}
.cell.hang { align-items: center; }
.cell.ground { align-items: flex-end; }
.cell.front { align-items: flex-start; }

.prop { position: relative; z-index: 1; width: 48px; height: 48px; display: grid; place-items: center; }
.prop svg { width: 100%; height: 100%; overflow: visible; }
.prop[data-id="bed"] { width: min(128px, 100%); height: 46px; }
.prop[data-id="crate"] { width: 42px; height: 36px; }
.prop[data-id="rug"] { width: min(108px, 100%); height: 30px; }
.prop[data-id="chair"] { width: 50px; height: 66px; }
.prop[data-id="clock"] { width: 40px; height: 40px; }
.prop[data-id="mirror"] { width: 36px; height: 60px; }
.prop[data-id="frame"] { width: 46px; height: 54px; }
.prop[data-id="vase"] { width: 32px; height: 50px; }
.prop[data-id="stool"] { width: 44px; height: 42px; }
.prop[data-id="plant"] { width: 48px; height: 58px; }
.prop[data-id="lamp"] { width: 44px; height: 52px; }
.prop[data-id="key"] { width: 36px; height: 24px; }

.prop.arrive, .prop.shifted { animation: arrive 420ms ease-out; filter: drop-shadow(0 0 8px var(--lamp)); }

@keyframes arrive {
  from { transform: translateY(12px) scale(0.8); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.outliner, .outliner ul { list-style: none; margin: 0; padding: 0; }

.outliner { margin: 8px 8px 0; }

.outliner ul {
  margin-left: 18px;
  padding-left: 8px;
  border-left: 1px solid #4a4e5c;
}

.outliner button {
  width: 100%;
  padding: 3px 8px;
  border: 0;
  background: transparent;
  color: inherit;
  font: 400 15px/1.3 var(--body);
  text-align: left;
  cursor: pointer;
}

.outliner button.branch {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.outliner li.entry {
  display: grid;
  grid-template-columns: 1fr 28px;
  align-items: center;
}

.outliner button.object,
.outliner button.rig {
  display: grid;
  grid-template-columns: 10px 14px 1fr;
  align-items: center;
  gap: 8px;
}

.eye-btn {
  width: 28px;
  height: 22px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.eye-btn.shut { color: #6a6458; }
.eye-btn .eye { width: 16px; height: 10px; }

.twisty {
  width: 0;
  height: 0;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 6px solid var(--muted);
}

.branch[aria-expanded="true"] .twisty { transform: rotate(90deg); }

.kind { width: 10px; height: 10px; justify-self: center; }
.kind-svg { width: 14px; height: 10px; color: var(--ink); justify-self: center; }
.kind.mesh { background: var(--ink); border-radius: 1px; }
.kind.light { width: 8px; height: 8px; background: var(--lamp); transform: rotate(45deg); }
.kind.camera { box-sizing: border-box; border: 1.5px solid var(--ink); border-radius: 2px; }
.kind.agent { box-sizing: border-box; border: 1.5px solid var(--lamp); border-radius: 50%; background: transparent; }

.eye { width: 16px; height: 10px; color: var(--muted); }
.eye-slot { width: 16px; height: 10px; }

.outliner button:hover { background: rgba(240, 193, 74, 0.12); }
.outliner button:focus-visible,
#next:focus-visible,
#again:focus-visible,
#exit-room:focus-visible,
#open-file:focus-visible,
#settings-open:focus-visible,
#frame:focus-visible,
#settings button:focus-visible,
.eye-btn:focus-visible {
  outline: 3px solid var(--lamp);
  outline-offset: -3px;
}

.outliner button[disabled] { cursor: default; }
.outliner button.miss { color: var(--miss); }
.outliner button.miss .name { text-decoration: line-through; }
.outliner button.found { background: rgba(240, 193, 74, 0.16); }

.rig-cam {
  position: absolute;
  z-index: 2;
  left: 8px;
  bottom: 8px;
  width: 36px;
  height: 36px;
  opacity: 0.85;
  pointer-events: none;
}

.rig-cam.drift { left: 22px; bottom: 18px; opacity: 0.55; }

.gain { min-height: 24px; padding: 12px 14px 0; color: var(--lamp); font-size: 22px; }
.gain.down { color: var(--miss); }

#settings-open {
  margin-top: 10px;
  padding: 6px 10px;
  border: 3px solid #0d0e12;
  background: transparent;
  color: var(--ink);
  font: 700 16px/1 var(--display);
  cursor: pointer;
}

dialog#settings {
  width: min(420px, calc(100% - 32px));
  padding: 22px;
  color: var(--ink);
  background: var(--panel);
  border: 3px solid #0d0e12;
  box-shadow: var(--shadow);
}

dialog#settings::backdrop { background: rgba(13, 14, 18, 0.72); }

.toggle {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 14px;
  font-size: 18px;
}

.set-note { margin-top: 14px; }

.slider {
  display: grid;
  gap: 6px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 15px;
}

.slider input {
  width: 100%;
  accent-color: var(--lamp);
}

#next, #again, #exit-room, #open-file, #settings button {
  margin: 14px;
  padding: 10px 14px;
  border: 3px solid #0d0e12;
  background: var(--lamp);
  color: #1b1408;
  font: 700 18px/1 var(--display);
  cursor: pointer;
  box-shadow: 0 4px 0 #0d0e12;
}

.ending {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(13, 14, 18, 0.72);
  padding: 24px;
}

.ending[hidden] { display: none; }

.ending-card {
  width: min(440px, 100%);
  padding: 22px;
}

.ending-card h2 { font-size: 36px; }
.ending-card p { margin-top: 10px; }
.intro-card { width: min(520px, 100%); }
.intro-card .eyebrow { margin-bottom: 8px; }
.end-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
#open-file, #again, #exit-room, #settings button { margin: 18px 0 0; }
#open-sweep, #again-sweep {
  margin: 18px 0 0;
  padding: 10px 14px;
  border: 3px solid #0d0e12;
  background: transparent;
  color: var(--ink);
  font: 700 18px/1 var(--display);
  cursor: pointer;
}
#ending-score { color: var(--ink); font-size: 22px; }
.reward { display: grid; justify-items: center; margin-top: 14px; }
.reward[hidden] { display: none; }
.reward svg { width: 84px; height: 84px; filter: drop-shadow(0 0 8px var(--lamp)); }
.reward p { margin: 4px 0 0; color: var(--ink); font-family: var(--display); font-size: 22px; }

@media (max-width: 800px) {
  main { grid-template-columns: 1fr; }
  .top { align-items: start; flex-direction: column; }
  .viewport { height: 360px; }
}

@media (prefers-reduced-motion: reduce) {
  .prop.arrive, .prop.shifted, .room.agent-touch::after { animation: none; }
}
