html, body { margin: 0; height: 100%; overflow: hidden; }
body { background: #000; -webkit-tap-highlight-color: transparent; user-select: none; }
[hidden] { display: none !important; }

/* ---------- Room ---------- */
#room-wrap {
  position: fixed; inset: 0;
  overflow-x: auto; overflow-y: hidden;
  scrollbar-width: none;
  background: #000;
}
#room-wrap::-webkit-scrollbar { display: none; }
#room-wrap svg.room {
  display: block;
  height: 100vh; height: 100dvh;
  width: max(100vw, 177.78vh);
}
.obj { cursor: pointer; transition: filter .25s; }
.obj:hover, .obj.focus { filter: drop-shadow(0 0 6px rgba(255, 170, 60, .9)) drop-shadow(0 0 18px rgba(255, 120, 20, .45)); }
.obj.locked:hover { filter: drop-shadow(0 0 6px rgba(160, 160, 255, .7)); }
.decor { cursor: help; }
.flame { transform-box: fill-box; transform-origin: 50% 100%; animation: flame 0.18s infinite alternate ease-in-out; }
.flame:nth-child(2n) { animation-duration: .23s; animation-delay: -.1s; }
.flame:nth-child(3n) { animation-duration: .27s; }
@keyframes flame { from { transform: scale(1, 1) skewX(-3deg); opacity: .92; } to { transform: scale(.92, 1.1) skewX(3deg); opacity: 1; } }
.glow-pulse { animation: glowPulse 3s infinite ease-in-out; }
@keyframes glowPulse { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }
.pendulum { transform-origin: 980px 470px; animation: swing 2s infinite ease-in-out; }
@keyframes swing { 0%, 100% { transform: rotate(9deg); } 50% { transform: rotate(-9deg); } }
.cloud { animation: drift 60s linear infinite; }
.cloud.c2 { animation-duration: 90s; animation-delay: -40s; }
@keyframes drift { from { transform: translateX(-260px); } to { transform: translateX(320px); } }
.bubble { animation: bubble 2.2s infinite ease-in; transform-box: fill-box; }
.bubble:nth-of-type(2) { animation-delay: -.7s; } .bubble:nth-of-type(3) { animation-delay: -1.4s; } .bubble:nth-of-type(4) { animation-delay: -1.9s; }
@keyframes bubble { 0% { transform: translateY(0) scale(.4); opacity: 0; } 30% { opacity: 1; } 100% { transform: translateY(-40px) scale(1.2); opacity: 0; } }
.steam { animation: steam 5s infinite ease-out; transform-box: fill-box; transform-origin: 50% 100%; }
.steam.s2 { animation-delay: -2.5s; }
@keyframes steam { 0% { transform: translateY(0) scale(.6); opacity: 0; } 30% { opacity: .35; } 100% { transform: translateY(-120px) scale(1.8); opacity: 0; } }
.eyes-blink { animation: blink 7s infinite; transform-box: fill-box; transform-origin: center; }
@keyframes blink { 0%, 96%, 100% { transform: scaleY(1); } 98% { transform: scaleY(.1); } }
.rune-letter { font-family: var(--font-display); fill: #ff9a3c; filter: url(#runeGlow); animation: runeIn 1.6s ease-out both; }
@keyframes runeIn { from { opacity: 0; } to { opacity: 1; } }
.web { stroke: rgba(220, 220, 230, .25); fill: none; stroke-width: 1; }
.spider { animation: spider 9s infinite ease-in-out; }
@keyframes spider { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(60px); } }

#darkness {
  position: fixed; inset: 0; pointer-events: none; z-index: 2;
  background: radial-gradient(circle at var(--mx, 50%) var(--my, 50%), rgba(0,0,0,0) 0, rgba(0,0,0,0) 170px, rgba(3,0,8,.62) 480px, rgba(0,0,0,.82) 900px);
  transition: background .1s;
}
#flash { position: fixed; inset: 0; background: #dfe8ff; opacity: 0; pointer-events: none; z-index: 3; mix-blend-mode: screen; }
#flash.on { animation: lightning 1.1s ease-out; }
@keyframes lightning { 0% { opacity: 0; } 5% { opacity: .75; } 10% { opacity: .1; } 16% { opacity: .55; } 40% { opacity: 0; } 100% { opacity: 0; } }

#bats { position: fixed; inset: 0; pointer-events: none; z-index: 2; overflow: hidden; }
.bat { position: absolute; width: 46px; animation: batfly linear forwards; }
.bat svg { width: 100%; animation: flap .16s infinite alternate; }
@keyframes flap { from { transform: scaleY(1); } to { transform: scaleY(.45); } }
@keyframes batfly { from { transform: translate(-10vw, 0); } to { transform: translate(115vw, var(--dy, -20vh)); } }

/* ---------- HUD ---------- */
#hud {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: linear-gradient(rgba(0,0,0,.75), rgba(0,0,0,0));
  pointer-events: none;
}
#hud > * { pointer-events: auto; }
.hud-left { display: flex; align-items: baseline; gap: 14px; }
#timer {
  font-family: var(--font-type); font-size: clamp(1.1rem, 3vw, 1.6rem); color: var(--ember);
  text-shadow: 0 0 10px rgba(255, 138, 31, .6); letter-spacing: .08em;
}
#timer.penalty { animation: penalty 1s; }
@keyframes penalty { 0%, 100% { color: var(--ember); } 30% { color: #ff2b2b; transform: scale(1.15); } }
#guest { font-style: italic; color: var(--muted); font-size: .95rem; }
.hud-btn { background: rgba(20, 14, 28, .8); border: 1px solid #3c2d48; border-radius: 50%; width: 42px; height: 42px; font-size: 1.15rem; margin-left: 6px; color: var(--bone); }
.hud-btn:hover { box-shadow: 0 0 12px rgba(255, 138, 31, .5); }

#inventory {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
  background: linear-gradient(rgba(20, 13, 26, .88), rgba(8, 5, 12, .95));
  border: 1px solid #3a2c45; border-bottom: none; border-radius: 14px 14px 0 0;
  max-width: calc(100vw - 16px);
}
.inv-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .15em; color: var(--muted); }
.inv-sep { width: 1px; align-self: stretch; background: #3a2c45; }
#items, #runes { display: flex; gap: 6px; min-height: 40px; align-items: center; }
#items:empty::after, #runes:empty::after { content: '—'; color: #4a3d55; }
.item { width: 40px; height: 40px; border-radius: 8px; background: #120d18; border: 1px solid #4a3a55; display: grid; place-items: center; }
.item svg { width: 30px; height: 30px; }
.item.new, .rune.new { animation: newItem 1.2s ease-out 2; }
@keyframes newItem { 50% { box-shadow: 0 0 18px var(--ember); transform: scale(1.15); } }
.rune { width: 30px; height: 40px; display: grid; place-items: center; font-family: var(--font-display); font-size: 1.5rem; color: #ffb35c; text-shadow: 0 0 8px #ff6a00, 0 0 18px #ff3c00; background: #160b0a; border: 1px solid #5a2c1a; border-radius: 6px; }

#narration {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%) translateY(10px);
  z-index: 6; max-width: min(640px, 92vw);
  padding: 12px 20px; border-radius: 10px;
  background: rgba(10, 6, 14, .92); border: 1px solid #4a3a55; color: var(--bone);
  font-size: clamp(1rem, 2.4vw, 1.2rem); font-style: italic; text-align: center; line-height: 1.4;
  opacity: 0; transition: opacity .35s, transform .35s; pointer-events: none;
  box-shadow: 0 0 30px rgba(0,0,0,.8);
}
#narration.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#tooltip {
  position: fixed; z-index: 6; pointer-events: none; padding: 4px 10px; border-radius: 6px;
  background: rgba(0,0,0,.85); color: var(--parchment); font-size: .9rem; opacity: 0; transition: opacity .15s;
  border: 1px solid #5a4630; white-space: nowrap;
}
#tooltip.show { opacity: 1; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 10; display: grid; place-items: center;
  background: rgba(0, 0, 0, .78); backdrop-filter: blur(3px);
  animation: fadeIn .3s;
}
@keyframes fadeIn { from { opacity: 0; } }
.modal-shell { position: relative; display: flex; flex-direction: column; gap: 8px; animation: rise .35s ease-out; }
@keyframes rise { from { transform: translateY(20px) scale(.97); opacity: 0; } }
.modal-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 0 4px; }
.modal-bar h2 { margin: 0; font-family: var(--font-display); font-weight: normal; color: var(--ember); font-size: clamp(1.3rem, 4vw, 2rem); letter-spacing: .04em; text-shadow: 0 0 12px rgba(255, 90, 0, .5); }
.modal-actions { display: flex; gap: 8px; flex-shrink: 0; }
.spooky-btn.small { padding: .3em .8em; font-size: .95rem; }
.spooky-btn.big { font-size: 1.3rem; padding: .6em 1.6em; }
#hint-box {
  max-width: min(920px, 96vw); padding: 10px 14px; border-radius: 8px;
  background: #1a1408; border: 1px solid #6b5326; color: var(--parchment); font-size: 1.05rem; line-height: 1.4;
}
#hint-box .hint-cost { color: #ff6b6b; font-size: .85rem; }
#hint-box .hint-actions { margin-top: 8px; display: flex; gap: 8px; }
.reward-card {
  position: absolute; inset: 0; z-index: 20; display: grid; place-items: center;
  background: radial-gradient(circle, rgba(40, 20, 0, .97), rgba(0, 0, 0, .99));
  animation: fadeIn .5s;
}
.reward-card .inner { text-align: center; padding: 20px; }
.reward-card h3 { font-family: var(--font-display); font-weight: normal; font-size: clamp(2rem, 7vw, 3.4rem); margin: 0 0 .2em; color: var(--ember); text-shadow: 0 0 20px #ff5a00; }
.reward-card .big-rune { font-family: var(--font-display); font-size: 6rem; color: #ffb35c; text-shadow: 0 0 20px #ff6a00, 0 0 60px #ff3c00; animation: runeBurn 1.5s ease-out; }
@keyframes runeBurn { from { transform: scale(2.5); opacity: 0; filter: blur(8px); } }
.reward-card p { font-size: 1.2rem; max-width: 480px; margin: .5em auto; }
.reward-card .got-item { display: inline-flex; gap: 10px; align-items: center; padding: 8px 16px; border: 1px solid #6b5326; border-radius: 10px; background: #1a1408; }
.reward-card .got-item svg { width: 40px; height: 40px; }

/* ---------- Door / journal (built-in panels) ---------- */
.door-panel { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 20px; text-align: center; }
.door-panel .inscription { font-family: var(--font-type); color: var(--parchment); font-size: clamp(.95rem, 2.4vw, 1.2rem); line-height: 1.6; max-width: 640px; }
.door-panel .spoken { min-height: 70px; display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; padding: 10px 18px; border-bottom: 2px solid #5a2c1a; min-width: 60%; }
.door-panel .tiles { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.door-panel .tile { width: 54px; height: 66px; font-size: 2.1rem; cursor: pointer; transition: transform .1s, opacity .2s; }
.door-panel .tile:hover { transform: translateY(-3px); }
.door-panel .tile.used { opacity: .2; pointer-events: none; }
.door-panel .row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.door-art { width: min(260px, 50vw); }
.door-msg { min-height: 1.5em; font-style: italic; color: var(--ghost); font-size: 1.1rem; }
.journal { padding: 22px 28px; font-size: 1.1rem; line-height: 1.55; color: var(--bone); }
.journal h3 { font-family: var(--font-display); font-weight: normal; color: var(--ember); margin: .2em 0 .4em; font-size: 1.6rem; }
.journal ul { padding-left: 1.2em; }
.journal li { margin: .3em 0; }
.journal .muted { color: var(--muted); font-size: .95rem; }
.link-btn { background: none; border: none; color: var(--muted); text-decoration: underline; font-size: .95rem; margin-top: 10px; }

/* ---------- Intro ---------- */
.screen { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; overflow: auto; }
#intro { background: radial-gradient(ellipse at 50% 35%, #2a1636 0%, #0c0711 60%, #000 100%); }
#fog { position: absolute; inset: 0; width: 100%; height: 100%; }
.intro-card { position: relative; text-align: center; padding: 24px; max-width: 680px; }
.title-drip {
  font-family: var(--font-display); font-weight: normal; margin: 0;
  font-size: clamp(3rem, 12vw, 7rem); line-height: 1;
  color: var(--pumpkin);
  text-shadow: 0 0 20px rgba(255, 90, 0, .55), 0 6px 0 #3a0a00, 0 0 70px rgba(255, 60, 0, .4);
  animation: titleFlicker 6s infinite;
}
@keyframes titleFlicker { 0%, 19%, 21%, 62%, 64%, 100% { opacity: 1; } 20%, 63% { opacity: .35; } }
.tagline { font-style: italic; color: var(--ghost); font-size: clamp(1.1rem, 3vw, 1.4rem); margin: .4em 0 1.2em; }
.story { font-size: clamp(1.05rem, 2.6vw, 1.25rem); line-height: 1.55; color: var(--bone); }
.guestbook { display: flex; flex-direction: column; gap: 6px; align-items: center; margin: 1.4em 0 1em; }
.guestbook span { font-size: .85rem; text-transform: uppercase; letter-spacing: .2em; color: var(--muted); }
.guestbook input { width: min(320px, 80vw); text-align: center; font-size: 1.3rem; }
.fine { color: var(--muted); font-size: .9rem; margin-top: 1.4em; line-height: 1.5; }
.intro-card.leaving { animation: leave 1.2s forwards; }
@keyframes leave { to { opacity: 0; transform: scale(1.1); filter: blur(6px); } }

/* ---------- Scare + victory ---------- */
#scare { position: fixed; inset: 0; z-index: 40; background: #000; display: grid; place-items: center; }
#scare svg { width: min(90vw, 90vh); animation: scareZoom .9s cubic-bezier(.2, 1.6, .4, 1) forwards; }
@keyframes scareZoom { from { transform: scale(.2); opacity: 0; } 30% { opacity: 1; } to { transform: scale(1.35); } }
#scare.shake { animation: shake .12s infinite; }
#victory { background: radial-gradient(ellipse at 50% 20%, #3a1500 0%, #120606 55%, #000 100%); align-content: start; padding: 16px; overflow-y: auto; }
.banner {
  margin: 10px auto 18px; text-align: center; font-family: var(--font-display);
  font-size: clamp(2.2rem, 9vw, 6rem); line-height: 1.05; color: #ff3b1f;
  text-shadow: 0 0 20px #ff2a00, 0 0 60px #a30000, 0 5px 0 #2a0000;
  animation: bannerDrop 1.1s cubic-bezier(.3, 1.5, .5, 1) both;
}
.banner small { display: block; font-family: var(--font-body); font-style: italic; font-size: .32em; line-height: 1.3; color: var(--parchment); text-shadow: 0 0 12px #000; margin-top: .3em; }
@keyframes bannerDrop { from { transform: translateY(-120%) rotate(-4deg); opacity: 0; } }
.award-wrap { display: flex; flex-direction: column; align-items: center; gap: 12px; animation: fadeIn 1.5s .8s both; }
#award { width: min(1000px, 94vw); height: auto; border-radius: 6px; box-shadow: 0 0 60px rgba(255, 60, 0, .35), 0 0 0 1px #3a1a0a; }
.award-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
#award-note { text-align: center; max-width: 640px; }

@media (max-width: 640px) {
  .inv-label { display: none; }
  #narration { bottom: 70px; }
  .modal-bar h2 { font-size: 1.25rem; }
}
@media (hover: none) { #darkness { background: radial-gradient(ellipse at 50% 50%, rgba(0,0,0,0) 30%, rgba(0,0,0,.7) 100%); } }

.pan-hint { position: fixed; top: 50%; z-index: 4; transform: translateY(-50%); width: 44px; height: 88px; border: 1px solid #3a2c45; background: rgba(10, 6, 14, .7); color: var(--ember); font-size: 1.6rem; display: grid; place-items: center; cursor: pointer; transition: opacity .3s; }
.pan-hint.left { left: 0; border-radius: 0 10px 10px 0; } .pan-hint.right { right: 0; border-radius: 10px 0 0 10px; }
.pan-hint.off { opacity: 0; pointer-events: none; }

/* ---------- Keeper's Dark: grid room ---------- */
#room-wrap { overflow: hidden; touch-action: none; }
#room-wrap svg.room { width: 100vw; height: 100vh; height: 100dvh; cursor: pointer; }
.lens-glass.spin { transform-box: fill-box; transform-origin: center; animation: lensSpin 12s linear infinite; }
@keyframes lensSpin { to { transform: rotate(360deg); } }
.lamp-pulse { animation: glowPulse 2.4s infinite ease-in-out; }
.rain line { animation: rainFall .6s linear infinite; }
@keyframes rainFall { from { transform: translateY(-8px); } to { transform: translateY(10px); } }
#darkness { transition: opacity .05s; }
.rune-letter { fill: #ffc25a; filter: drop-shadow(0 0 4px #ff9a2a); }
#flash { background: #cfe3ff; }

#prompt {
  position: fixed; left: 50%; bottom: 150px; transform: translateX(-50%) translateY(6px); z-index: 6;
  padding: 6px 14px; border-radius: 20px; background: rgba(6, 12, 18, .88); border: 1px solid #5a4630;
  color: var(--parchment); font-size: 1rem; white-space: nowrap; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none;
}
#prompt.show { opacity: 1; transform: translateX(-50%); }
#prompt kbd { font-family: var(--font-type); background: #2a2014; border: 1px solid #8a6a32; border-radius: 4px; padding: 0 6px; margin-right: 6px; color: var(--ember); }
#narration { bottom: auto; top: 64px; }

#controls { position: fixed; inset: auto 0 76px 0; z-index: 5; pointer-events: none; display: none; justify-content: space-between; align-items: flex-end; padding: 0 16px; }
@media (pointer: coarse) { #controls:not([hidden]) { display: flex; } #prompt kbd { display: none; } }
#dpad { pointer-events: auto; display: grid; grid-template-columns: repeat(3, 52px); grid-template-rows: repeat(3, 52px); }
#dpad button, #btn-act { background: rgba(14, 24, 35, .7); border: 1px solid #2e4458; color: var(--ember); font-size: 1.2rem; border-radius: 12px; touch-action: none; }
#dpad button:active, #btn-act:active { background: rgba(60, 46, 20, .9); }
#dpad [data-dir="0"] { grid-column: 2; grid-row: 1; } #dpad [data-dir="3"] { grid-column: 1; grid-row: 2; }
#dpad [data-dir="1"] { grid-column: 3; grid-row: 2; } #dpad [data-dir="2"] { grid-column: 2; grid-row: 3; }
#btn-act { pointer-events: auto; width: 76px; height: 76px; border-radius: 50%; font-size: 1.8rem; opacity: .45; transition: opacity .2s, box-shadow .2s; }
#btn-act.ready { opacity: 1; box-shadow: 0 0 18px rgba(255, 194, 90, .55); }
@media (pointer: coarse) { #prompt { bottom: 250px; } }

.title-drip { color: var(--ember); text-shadow: 0 0 24px rgba(255, 194, 90, .55), 0 5px 0 #2a1a04, 0 0 70px rgba(255, 160, 40, .35); letter-spacing: .02em; }
#intro { background: radial-gradient(ellipse at 50% 25%, #14283a 0%, #050b12 60%, #000 100%); }
#victory { background: radial-gradient(ellipse at 50% 20%, #3a2a0a 0%, #0a1018 55%, #000 100%); }
.banner { color: var(--ember); text-shadow: 0 0 20px #ff9a2a, 0 0 60px #a36000, 0 5px 0 #2a1a00; }
.reward-card { background: radial-gradient(circle, rgba(36, 28, 8, .98), rgba(0, 4, 8, .99)); }
.reward-card h3, .modal-bar h2, .journal h3 { color: var(--ember); text-shadow: 0 0 14px rgba(255, 170, 60, .5); }
.rune { color: #ffd27a; text-shadow: 0 0 8px #ffa020, 0 0 18px #ff8000; background: #120e06; border-color: #5a4220; }
#award { box-shadow: 0 0 60px rgba(255, 194, 90, .3), 0 0 0 1px #3a2a0a; }

/* reveal */
#scare.reveal { background: #000; overflow: hidden; flex-direction: column; }
#scare.reveal .beam { position: absolute; left: 50%; top: 50%; width: 220vmax; height: 40vmin; transform-origin: 0 50%; background: linear-gradient(90deg, rgba(255,240,190,.95), rgba(255,210,120,.4) 40%, rgba(255,210,120,0)); animation: sweep 2.3s linear forwards; }
@keyframes sweep { from { transform: translateY(-50%) rotate(-30deg); } to { transform: translateY(-50%) rotate(330deg); } }
#scare.reveal svg { width: min(80vw, 70vh); }
.keeper-line { font-style: italic; color: var(--ghost); font-size: clamp(1.1rem, 3vw, 1.6rem); text-align: center; animation: fadeIn 1s .4s both; margin: 0; }

/* signal card */
.signal-card { padding: 18px 22px; max-width: 760px; margin: 0 auto; background: #d8c9a3; color: #2a1e10; min-height: 100%; font-family: var(--font-type); }
.sc-head { text-align: center; font-size: 1.25rem; margin: 0 0 12px; }
.sc-head small { font-size: .85rem; color: #5a4a30; }
.sc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px 14px; }
.sc-grid div { display: flex; align-items: center; gap: 10px; border-bottom: 1px dashed #a08a60; padding: 3px 0; }
.sc-grid b { font-size: 1.3rem; width: 1.2em; }
.sc-grid span { display: flex; gap: 4px; align-items: center; }
.sc-grid .dot { width: 8px; height: 8px; border-radius: 50%; background: #2a1e10; display: inline-block; }
.sc-grid .dash { width: 22px; height: 7px; border-radius: 3px; background: #2a1e10; display: inline-block; }
.sc-foot { font-family: var(--font-body); font-style: italic; margin-top: 14px; color: #5a4a30; }
