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

/* ---------- Scene ---------- */
#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 5px rgba(255, 220, 120, .95)) drop-shadow(0 0 16px rgba(240, 138, 75, .55)); }
.decor { cursor: help; }
.flame { transform-box: fill-box; transform-origin: 50% 100%; animation: flame 0.18s infinite alternate ease-in-out; }
@keyframes flame { from { transform: scale(1, 1) skewX(-3deg); opacity: .92; } to { transform: scale(.92, 1.1) skewX(3deg); opacity: 1; } }
.twinkle { animation: twinkle 3s infinite ease-in-out; }
@keyframes twinkle { 50% { opacity: .1; } }
.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: .4; } 100% { transform: translateY(-120px) scale(1.8); opacity: 0; } }
.eyes-blink { animation: blink 5s infinite; transform-box: fill-box; transform-origin: center; }
@keyframes blink { 0%, 95%, 100% { transform: scaleY(1); } 97% { transform: scaleY(.1); } }
body.quake { animation: shake .6s; }

#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) 220px, rgba(10,6,14,.32) 520px, rgba(6,4,10,.58) 950px);
}

/* ---------- 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(14,10,7,.8), rgba(0,0,0,0));
  pointer-events: none;
}
#hud > * { pointer-events: auto; }
.hud-left { display: flex; align-items: baseline; gap: 14px; min-width: 0; }
#timer {
  font-family: var(--font-type); font-size: clamp(1.1rem, 3vw, 1.6rem); color: var(--brass);
  text-shadow: 0 0 10px rgba(214, 163, 74, .6); letter-spacing: .08em; white-space: nowrap;
}
#timer.penalty { animation: penalty 1s; }
@keyframes penalty { 0%, 100% { color: var(--brass); } 30% { color: #ff4b4b; transform: scale(1.15); } }
#guest { font-style: italic; color: var(--paper); font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-btn { background: rgba(42, 29, 20, .92); border: 1px solid #8a6a3a; border-radius: 50%; width: 42px; height: 42px; font-size: 1.15rem; margin-left: 6px; color: var(--cream); }
.hud-btn:hover { box-shadow: 0 0 12px rgba(240, 138, 75, .55); }

#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(58, 40, 26, .95), rgba(26, 18, 12, .97));
  border: 1px solid #8a6a3a; 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); white-space: nowrap; }
.inv-sep { width: 1px; align-self: stretch; background: #8a6a3a; }
#items, #runes { display: flex; gap: 5px; min-height: 40px; align-items: center; flex-wrap: nowrap; }
#items:empty::after, #runes:empty::after { content: '—'; color: #5a5054; }
.item { width: 40px; height: 40px; border-radius: 8px; background: #1a120c; border: 1px solid #8a6a3a; 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(--brass); transform: scale(1.15); } }
.rune { width: 30px; height: 40px; display: grid; place-items: center; font-family: var(--font-type); font-size: 1.6rem; color: #f7efe0; background: #141012; border: 1px solid #3a3436; border-radius: 4px; box-shadow: inset 0 0 0 2px #1e1a1c; }

#narration {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%) translateY(10px);
  z-index: 6; width: max-content; max-width: min(640px, 92vw);
  padding: 12px 20px; border-radius: 10px;
  background: rgba(30, 21, 14, .96); border: 1px solid #8a6a3a; color: var(--cream);
  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,.7);
}
#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(30,21,14,.94); color: var(--paper); font-size: .9rem; opacity: 0; transition: opacity .15s;
  border: 1px solid #8a6a3a; white-space: nowrap;
}
#tooltip.show { opacity: 1; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 10; display: grid; place-items: center;
  background: rgba(8, 4, 10, .74); 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(--brass); font-size: clamp(1.3rem, 4vw, 2rem); letter-spacing: .03em; text-shadow: 0 0 12px rgba(214, 163, 74, .45); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.modal-actions { display: flex; gap: 8px; flex-shrink: 0; }
#hint-box {
  max-width: min(920px, 96vw); padding: 10px 14px; border-radius: 8px;
  background: #22180f; border: 1px solid #8a6a3a; color: var(--paper); font-size: 1.05rem; line-height: 1.4;
  max-height: 30vh; overflow: auto;
}
#hint-box .hint-cost { color: #ff8a7a; font-size: .85rem; }
#hint-box .hint-actions { margin-top: 8px; display: flex; gap: 8px; align-items: center; }
.reward-card {
  position: absolute; inset: 0; z-index: 1000; display: grid; place-items: center;
  background: radial-gradient(circle, rgba(70, 44, 24, .98), rgba(16, 10, 6, .99));
  animation: fadeIn .5s; overflow: auto;
}
.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(--brass); text-shadow: 0 0 20px var(--dawn); }
.reward-card .big-rune { display: inline-grid; place-items: center; width: 100px; height: 130px; border-radius: 8px; background: repeating-linear-gradient(#141012 0 10px, #201a1c 10px 12px); border: 4px solid #5a3a24; font-family: var(--font-type); font-size: 5rem; color: #f7efe0; text-shadow: 0 2px 0 #000; animation: runeBurn 1.5s ease-out; }
@keyframes runeBurn { from { transform: translateY(-60px) rotate(-12deg); opacity: 0; } }
.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 #8a6a3a; border-radius: 10px; background: #22180f; }
.reward-card .got-item svg { width: 40px; height: 40px; }

/* ---------- Raft / journal (built-in panels) ---------- */
.door-panel { min-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(--paper); font-size: clamp(.95rem, 2.4vw, 1.15rem); line-height: 1.6; max-width: 640px; }
.door-panel .spoken { min-height: 70px; display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; padding: 10px 18px; border-bottom: 3px solid #6a4422; min-width: 60%; cursor: pointer; }
.door-panel .tiles { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.door-panel .tile { width: 44px; height: 70px; font-size: 2rem; 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-msg { min-height: 1.5em; font-style: italic; color: var(--sage); font-size: 1.1rem; }
.journal { padding: 22px 28px; font-size: 1.1rem; line-height: 1.55; color: var(--cream); }
.journal h3 { font-family: var(--font-display); font-weight: normal; color: var(--brass); margin: .2em 0 .4em; font-size: 1.7rem; }
.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: linear-gradient(#060918 0%, #141a2e 50%, #3a2a3a 78%, #0e0a07 100%); }
#waves { position: absolute; inset: 0; width: 100%; height: 100%; }
.intro-card { position: relative; text-align: center; padding: 24px; max-width: 680px; }
.title-big {
  font-family: var(--font-display); font-weight: normal; margin: 0;
  font-size: clamp(2.4rem, 10vw, 5.6rem); line-height: 1.05; position: relative; display: grid;
}
.title-big small { display: block; font-size: .38em; color: var(--paper); letter-spacing: .14em; }
.title-big .glow, .title-big .crisp { grid-area: 2 / 1; white-space: nowrap; }
.title-big .glow { color: #f08a4b; filter: blur(10px); opacity: .7; }
.title-big .crisp { color: #f6dca0; text-shadow: 0 4px 0 #3a1a0a; }
.tagline { font-style: italic; color: var(--sage); font-size: clamp(1.1rem, 3vw, 1.4rem); margin: .4em 0 1.2em; }
.story { font-size: clamp(1.05rem, 2.6vw, 1.22rem); line-height: 1.55; color: var(--cream); text-shadow: 0 1px 6px #000; }
.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(--paper); }
.guestbook input { width: min(320px, 80vw); text-align: center; font-size: 1.3rem; }
.fine { color: var(--paper); opacity: .8; 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); } }

/* ---------- Launch + victory ---------- */
#launch { position: fixed; inset: 0; z-index: 40; background: #000; }
#launch svg { width: 100%; height: 100%; }
#victory { background: radial-gradient(ellipse at 50% 0%, #f08a4b 0%, #8a4a4a 25%, #2a1d2a 55%, #0e0a07 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, 5.6rem); line-height: 1.05; color: #fff0c8;
  text-shadow: 0 5px 0 #3a1a0a, 0 0 30px rgba(0,0,0,.6);
  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: .3em; line-height: 1.35; color: var(--cream); text-shadow: 0 0 12px #000; margin-top: .3em; }
@keyframes bannerDrop { from { transform: translateY(-120%) rotate(-4deg); opacity: 0; } }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 31; }
.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(240, 138, 75, .35), 0 0 0 1px #5a3a1c; }
.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; }
  .rune { width: 22px; height: 32px; font-size: 1.2rem; }
  .item { width: 34px; height: 34px; } .item svg { width: 26px; height: 26px; }
  #narration { bottom: 70px; }
  .modal-bar h2 { font-size: 1.2rem; }
  #guest { display: none; }
}
@media (hover: none) { #darkness { background: radial-gradient(ellipse at 50% 50%, rgba(0,0,0,0) 35%, rgba(10,4,16,.5) 100%); } }

.pan-hint { position: fixed; top: 50%; z-index: 4; transform: translateY(-50%); width: 44px; height: 88px; border: 1px solid #8a6a3a; background: rgba(30, 21, 14, .85); color: var(--brass); 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; }


/* ---------- Main Street details ---------- */
.horse-tail { transform-box: fill-box; transform-origin: 0 0; animation: tail 4s infinite ease-in-out; }
@keyframes tail { 50% { transform: rotate(10deg); } }
.forge-flicker { animation: forge 1.4s infinite alternate ease-in-out; }
@keyframes forge { to { transform: scale(1.06); filter: brightness(1.2); } }
.forge-flicker { transform-box: fill-box; transform-origin: center; }
#tumble { transform: translate(-100px, 840px); }
#tumble.go { animation: tumbleRoll 9s linear forwards; }
#tumble.go .tumble-spin { animation: spin 1.2s linear infinite; }
@keyframes tumbleRoll { 0% { transform: translate(-100px, 840px); } 25% { transform: translate(300px, 800px); } 50% { transform: translate(800px, 850px); } 75% { transform: translate(1200px, 810px); } 100% { transform: translate(1720px, 845px); } }
@keyframes spin { to { transform: rotate(360deg); } }
#kid.playing .harmonica { animation: harp .25s infinite alternate; }
@keyframes harp { to { transform: translateX(4px); } }
.batwing { transform-box: fill-box; transform-origin: center; animation: swing 7s infinite ease-in-out; }
@keyframes swing { 0%, 80%, 100% { transform: scaleX(1); } 85% { transform: scaleX(.85); } 90% { transform: scaleX(1.03); } }

/* ---------- clue cards, case file ---------- */
.clue-chip { width: 32px; height: 40px; padding: 0; border: none; background: none; }
.clue-chip svg { width: 100%; height: 100%; }
.clue-chip.new { animation: newItem 1.2s ease-out 2; }
.clue-card { position: relative; background: #ecdcb4; color: #2a1a0c; border-radius: 3px; padding: 16px 18px 12px; text-align: left; max-width: 560px; margin: 10px auto; box-shadow: 0 6px 18px rgba(0,0,0,.5); font-size: 1.05rem; line-height: 1.45; transform: rotate(-.6deg); }
.clue-card .pin { position: absolute; top: 6px; left: 50%; width: 12px; height: 12px; border-radius: 50%; background: #b0472a; box-shadow: 0 2px 0 #5a1a0a; }
.clue-card .clue-title { font-family: var(--font-display); color: #7a1e10; font-size: 1.25rem; margin-bottom: 4px; }
.clue-card .clue-title small { font-family: var(--font-body); font-style: italic; color: #6a5030; font-size: .8rem; }
.clue-card p { margin: 0; font-size: 1.02rem; max-width: none; }
.clue-card.focus { outline: 3px solid var(--brass); }
.reward-card .clue-card { animation: runeBurn 1.2s ease-out; }
.clue-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.clue-grid .clue-card { margin: 0; }
.clue-grid .clue-card:nth-child(even) { transform: rotate(.7deg); }

/* ---------- the accusation board ---------- */
.board-panel { min-height: 100%; display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 16px; text-align: center; }
.board-intro { font-style: italic; color: var(--paper); max-width: 620px; margin: 0; }
.acc-cols { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; width: 100%; max-width: 860px; }
.acc-col { background: rgba(236, 220, 180, .08); border: 1px solid #8a6a3a; border-radius: 6px; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.acc-col h4 { margin: 0 0 2px; font-family: var(--font-display); font-weight: normal; color: var(--brass); font-size: 1.3rem; }
.acc-opt { background: #ecdcb4; color: #2a1a0c; border: 2px solid transparent; border-radius: 4px; padding: 6px 8px; text-align: left; font-size: .98rem; line-height: 1.15; min-height: 44px; display: flex; flex-direction: column; justify-content: center; }
.acc-opt small { color: #6a5030; font-style: italic; font-size: .8rem; }
.acc-opt.on { border-color: #b0472a; background: #f6e6b8; box-shadow: 0 0 0 2px #b0472a, 0 0 14px rgba(214,163,74,.7); }
.acc-opt.on span::before { content: '✔ '; color: #b0472a; }
.board-panel .row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
@media (max-width: 640px) {
  .acc-cols { grid-template-columns: 1fr; }
  .acc-opt { min-height: 40px; }
}

/* ---------- the showdown ---------- */
#launch svg { position: absolute; inset: 0; }
.sd-arm { transform-box: view-box; transform-origin: 440px 470px; transition: transform .35s ease-out; transform: rotate(40deg); }
.sd-arm.up { transform: rotate(0deg); }
.sd-derringer.fly { animation: gunFly 1.4s ease-out forwards; transform-box: view-box; }
@keyframes gunFly { to { transform: translate(-160px, 220px) rotate(-540deg); opacity: .8; } }
.sd-text { transition: opacity .3s; letter-spacing: .1em; }
.sd-caption { position: absolute; left: 50%; bottom: 6%; transform: translateX(-50%) translateY(10px); width: min(780px, 92vw); padding: 16px 22px; border-radius: 8px; background: rgba(20, 12, 8, .9); border: 1px solid #8a6a3a; font-size: clamp(1rem, 2.6vw, 1.25rem); line-height: 1.5; font-style: italic; color: var(--cream); opacity: 0; transition: opacity .5s, transform .5s; }
.sd-caption.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* keep the hint box on screen: shrink the panel while it is open */
.modal-shell:has(#hint-box:not([hidden])) .modal-panel { height: min(560px, calc(86vh - min(30vh, 200px))); }
#hint-box { max-height: min(30vh, 200px); }
.modal-shell { max-width: 96vw; }
.modal-bar h2 { min-width: 0; flex: 1 1 auto; }
@media (max-width: 640px) { #btn-hint { padding: .3em .6em; } }
#launch.portrait { background: linear-gradient(#1e2a50 0%, #3a4a7a 50%, #6a4a30 50%, #4a3220 100%); }
