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);
}
#room-wrap.quake svg.room { animation: quake .9s ease-out; }
@keyframes quake { 10%, 50% { transform: translate(-4px, 2px); } 30%, 70% { transform: translate(4px, -2px); } 90% { transform: translate(-1px, 1px); } }
.obj { cursor: pointer; transition: filter .25s; }
.obj:hover, .obj.focus { filter: drop-shadow(0 0 6px rgba(62, 232, 255, .9)) drop-shadow(0 0 18px rgba(62, 232, 255, .4)); }
.decor { cursor: help; }
.stencil { font-family: var(--font-display); font-weight: 700; fill: #c9d6df; letter-spacing: 1.5px; }
.lcd { font-family: var(--font-type); fill: #4dffa6; letter-spacing: 2px; }
.glow-pulse { animation: glowPulse 3s infinite ease-in-out; }
@keyframes glowPulse { 0%, 100% { opacity: .6; } 50% { opacity: 1; } }
.blink { animation: blink 1s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }
.beacon-beam { transform-origin: 800px 30px; animation: beacon 2.4s linear infinite; }
@keyframes beacon { 0% { opacity: 0; } 25% { opacity: 1; } 50% { opacity: 0; } 100% { opacity: 0; } }
.sweep { transform-origin: 905px 478px; animation: sweep 3s linear infinite; }
@keyframes sweep { to { transform: rotate(360deg); } }
.snow { animation: snow 18s linear infinite; }
@keyframes snow { from { transform: translateY(0); } to { transform: translateY(-60px); } }
.fish { animation: swim 22s linear infinite; }
.fish.f2 { animation-duration: 30s; animation-delay: -12s; }
@keyframes swim { from { transform: translateX(-80px); } to { transform: translateX(330px); } }
.angler { animation: lurk 16s ease-in-out infinite; }
@keyframes lurk { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(-40px, -14px); } }
.spray { transform-box: fill-box; transform-origin: 0 50%; animation: spray .25s infinite alternate ease-in-out; }
.spray.s2 { animation-duration: .31s; }
@keyframes spray { from { transform: scale(1, 1); opacity: .45; } to { transform: scale(1.08, .9); opacity: .65; } }
.mist { animation: glowPulse 1.4s infinite; }
.sparkle { animation: sparkle 1.7s steps(1) infinite; }
.sparkle.sp2 { animation-delay: -.8s; }
@keyframes sparkle { 0%, 70% { opacity: 0; } 72%, 78% { opacity: 1; } 80%, 100% { opacity: 0; } }
.drip { animation: drip 2.6s infinite ease-in; }
.drip.d2 { animation-delay: -1.3s; }
@keyframes drip { 0% { transform: translateY(0); opacity: 0; } 15% { opacity: 1; } 100% { transform: translateY(600px); opacity: .3; } }
.needle { transform-origin: 830px 186px; animation: needle 4s ease-in-out infinite; }
@keyframes needle { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(3deg); } 52% { transform: rotate(-1deg); } }
.hatch-wheel:not(.sealed) { transform-origin: 120px 432px; animation: strain 3s ease-in-out infinite; }
@keyframes strain { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(4deg); } }
.bob { animation: bob 4s ease-in-out infinite; }
.bob.b2 { animation-duration: 5.3s; animation-delay: -2s; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
#water { transition: transform 3s ease-in-out; }
.wave { animation: wave 6s linear infinite; }
.wave.w2 { animation-duration: 4s; }
@keyframes wave { from { transform: translateX(0); } to { transform: translateX(200px); } }
.rune-letter { font-family: var(--font-display); font-weight: 900; fill: #4dffa6; filter: url(#runeGlow); animation: runeIn 1.6s ease-out both; }
@keyframes runeIn { from { opacity: 0; } to { opacity: 1; } }

#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) 190px, rgba(0,6,16,.5) 520px, rgba(0,2,8,.75) 950px);
}
#flash { position: fixed; inset: 0; background: #ff2020; opacity: 0; pointer-events: none; z-index: 3; mix-blend-mode: screen; }
#flash.on { animation: redflash 1.4s ease-out; }
@keyframes redflash { 0% { opacity: 0; } 8% { opacity: .35; } 20% { opacity: .05; } 32% { opacity: .25; } 60%, 100% { opacity: 0; } }

#bubbles { position: fixed; inset: 0; pointer-events: none; z-index: 2; overflow: hidden; }
.bub { position: absolute; bottom: -20px; border-radius: 50%; border: 1.5px solid rgba(190, 240, 255, .6); background: radial-gradient(circle at 35% 30%, rgba(255,255,255,.5), rgba(160,230,255,.05) 60%); animation: rise linear forwards; }
@keyframes rise { from { transform: translate(0, 0); opacity: 0; } 10% { opacity: 1; } to { transform: translate(3vw, -110vh); opacity: .4; } }

/* ---------- 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(--sonar);
  text-shadow: 0 0 10px rgba(77, 255, 166, .55); letter-spacing: .1em;
}
#timer.penalty { animation: penalty 1s; }
@keyframes penalty { 0%, 100% { color: var(--sonar); } 30% { color: var(--alarm); transform: scale(1.15); } }
#guest { font-style: italic; color: var(--muted); font-size: .95rem; }
.hud-btn { background: rgba(8, 18, 28, .85); border: 1px solid #2a4258; border-radius: 50%; width: 42px; height: 42px; font-size: 1.1rem; margin-left: 6px; color: var(--foam); }
.hud-btn:hover { box-shadow: 0 0 12px rgba(62, 232, 255, .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(10, 24, 36, .9), rgba(3, 9, 15, .96));
  border: 1px solid #2a4258; border-bottom: none; border-radius: 14px 14px 0 0;
  max-width: calc(100vw - 16px);
}
.inv-label { font-family: var(--font-display); font-size: .62rem; text-transform: uppercase; letter-spacing: .15em; color: var(--muted); white-space: nowrap; }
.inv-sep { width: 1px; align-self: stretch; background: #2a4258; }
#items, #runes { display: flex; gap: 6px; min-height: 40px; align-items: center; }
#items:empty::after, #runes:empty::after { content: '—'; color: #33495a; }
.item { width: 40px; height: 40px; border-radius: 8px; background: #06121c; border: 1px solid #2f4c62; 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(--biolum); transform: scale(1.15); } }
.rune { width: 30px; height: 40px; display: grid; place-items: center; font-family: var(--font-display); font-weight: 900; font-size: 1.3rem; color: #b8ffd8; text-shadow: 0 0 8px #4dffa6, 0 0 18px #1aff80; background: #03140c; border: 1px solid #1f5a3c; 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(3, 12, 20, .95); border: 1px solid #2a4a5e; color: var(--foam);
  font-size: clamp(1rem, 2.4vw, 1.15rem); font-style: italic; text-align: center; line-height: 1.45;
  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(--biolum); font-family: var(--font-type); font-size: .9rem; opacity: 0; transition: opacity .15s;
  border: 1px solid #2a4a5e; white-space: nowrap;
}
#tooltip.show { opacity: 1; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 10; display: grid; place-items: center;
  background: rgba(0, 4, 10, .8); backdrop-filter: blur(3px);
  animation: fadeIn .3s;
}
@keyframes fadeIn { from { opacity: 0; } }
.modal-shell { position: relative; display: flex; flex-direction: column; gap: 8px; animation: rise2 .35s ease-out; }
@keyframes rise2 { 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: 700; color: var(--biolum); font-size: clamp(1.05rem, 3.4vw, 1.6rem); letter-spacing: .08em; text-transform: uppercase; text-shadow: 0 0 12px rgba(62, 232, 255, .45); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.modal-actions { display: flex; gap: 8px; flex-shrink: 0; }
.hull-btn.small { padding: .3em .8em; font-size: .92rem; }
.hull-btn.big { font-size: 1.2rem; padding: .65em 1.7em; font-family: var(--font-display); letter-spacing: .1em; text-transform: uppercase; }
#hint-box {
  max-width: min(920px, 96vw); padding: 10px 14px; border-radius: 8px;
  background: #0c1a12; border: 1px solid #2a6a48; color: #d8f6e6; font-size: 1.02rem; line-height: 1.45;
  max-height: 30vh; overflow: auto;
}
#hint-box .hint-cost { color: #ff8a8a; font-size: .85rem; }
#hint-box .hint-actions { margin-top: 8px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.reward-card {
  position: absolute; inset: 0; z-index: 20; display: grid; place-items: center;
  background: radial-gradient(circle, rgba(4, 34, 30, .98), rgba(0, 4, 8, 1));
  animation: fadeIn .5s;
}
.reward-card .inner { text-align: center; padding: 20px; }
.reward-card h3 { font-family: var(--font-display); font-weight: 900; font-size: clamp(1.6rem, 6vw, 3rem); margin: 0 0 .2em; color: var(--sonar); text-transform: uppercase; letter-spacing: .08em; text-shadow: 0 0 20px rgba(77, 255, 166, .6); }
.reward-card .big-rune { font-family: var(--font-display); font-weight: 900; font-size: 6rem; color: #c8ffe0; text-shadow: 0 0 20px #4dffa6, 0 0 60px #00ff80; animation: runeBurn 1.5s ease-out; }
@keyframes runeBurn { from { transform: scale(2.5); opacity: 0; filter: blur(8px); } }
.reward-card p { font-size: 1.15rem; max-width: 480px; margin: .5em auto; }
.reward-card .got-item { display: inline-flex; gap: 10px; align-items: center; padding: 8px 16px; border: 1px solid #2a4a5e; border-radius: 10px; background: #06121c; }
.reward-card .got-item svg { width: 40px; height: 40px; }

/* ---------- Pod hatch / journal ---------- */
.door-panel { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 20px; text-align: center;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,.18) 0 2px, transparent 2px 4px); }
.door-panel .inscription { font-family: var(--font-type); color: var(--sonar); font-size: clamp(.9rem, 2.3vw, 1.1rem); line-height: 1.7; max-width: 660px; text-shadow: 0 0 6px rgba(77,255,166,.4); }
.door-panel .spoken { min-height: 70px; display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; padding: 10px 18px; border-bottom: 2px solid #1f5a3c; min-width: 60%; cursor: pointer; }
.door-panel .tiles { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.door-panel .tile { width: 54px; height: 66px; font-size: 1.9rem; 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-family: var(--font-type); color: var(--warn); font-size: 1.02rem; }
.journal { padding: 22px 28px; font-size: 1.05rem; line-height: 1.6; color: var(--foam); }
.journal h3 { font-family: var(--font-display); font-weight: 700; color: var(--biolum); margin: .2em 0 .4em; font-size: 1.2rem; letter-spacing: .08em; text-transform: uppercase; }
.journal ul { padding-left: 1.2em; }
.journal li { margin: .3em 0; }
.journal .muted, .muted { color: var(--muted); font-size: .95rem; }
.link-btn { display: block; margin: 12px auto 0; background: none; border: none; color: var(--muted); text-decoration: underline; font-size: .95rem; }

/* ---------- Intro ---------- */
.screen { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; overflow: auto; }
#intro { background: radial-gradient(ellipse at 50% 10%, #0d3a58 0%, #041424 50%, #000 100%); }
#fog { position: absolute; inset: 0; width: 100%; height: 100%; }
.intro-card { position: relative; text-align: center; padding: 24px 16px; max-width: 700px; }
.kicker { font-family: var(--font-type); color: var(--warn); letter-spacing: .2em; font-size: clamp(.7rem, 2.2vw, .9rem); text-transform: uppercase; margin-bottom: 14px; }
.title-main {
  font-family: var(--font-display); font-weight: 900; margin: 0; text-transform: uppercase;
  font-size: clamp(2rem, 8.5vw, 4.6rem); line-height: 1.05; letter-spacing: .04em;
  color: #dff8ff;
  text-shadow: 0 0 18px rgba(62, 232, 255, .55), 0 0 60px rgba(62, 232, 255, .3);
  animation: titleFlicker 7s infinite;
}
@keyframes titleFlicker { 0%, 41%, 43%, 77%, 79%, 100% { opacity: 1; } 42%, 78% { opacity: .45; } }
.tagline { font-style: italic; color: var(--biolum); font-size: clamp(1.02rem, 3vw, 1.3rem); margin: .6em 0 1.2em; }
.story { font-size: clamp(1rem, 2.5vw, 1.15rem); line-height: 1.6; color: var(--foam); }
.guestbook { display: flex; flex-direction: column; gap: 6px; align-items: center; margin: 1.4em 0 1em; }
.guestbook span { font-family: var(--font-display); font-size: .75rem; text-transform: uppercase; letter-spacing: .25em; color: var(--muted); }
.guestbook input { width: min(320px, 80vw); text-align: center; font-size: 1.25rem; }
.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); } }

/* ---------- Ascent reveal + victory ---------- */
#scare { position: fixed; inset: 0; z-index: 40; background: #000; display: grid; place-items: center; overflow: hidden; }
#scare.ascent { background: linear-gradient(#01060d, #000); transition: background 1.5s; }
#scare.ascent.light { background: linear-gradient(#2a8ab8, #0a3a5a 60%, #041a2a); }
#scare.ascent.breach { background: #fff; }
#scare.shake { animation: shake .12s infinite; }
.asc-bubbles { position: absolute; inset: 0; }
.asc-bubbles i { position: absolute; bottom: -30px; border-radius: 50%; border: 2px solid rgba(200, 245, 255, .7); animation: ascB 1.2s linear infinite; }
@keyframes ascB { to { transform: translateY(-115vh); } }
.asc-text { position: relative; font-family: var(--font-type); color: var(--sonar); font-size: clamp(1rem, 4vw, 1.8rem); letter-spacing: .15em; text-shadow: 0 0 10px #4dffa6; text-align: center; padding: 0 16px; }
#scare.breach .asc-text, #scare.breach .asc-bubbles { opacity: 0; }
.asc-eye { position: absolute; inset: 0; display: grid; place-items: center; animation: eyeIn .5s cubic-bezier(.2, 1.6, .4, 1) both; }
.asc-eye svg { width: min(110vw, 150vh); }
.asc-eye.gone { animation: eyeOut .8s forwards; }
@keyframes eyeIn { from { transform: scale(.3); opacity: 0; } }
@keyframes eyeOut { to { transform: translateY(40vh) scale(.6); opacity: 0; } }
#victory { grid-template-columns: minmax(0, 1fr); background: radial-gradient(ellipse at 50% 0%, #7ad0f0 0%, #1a6a98 30%, #062a44 70%, #021220 100%); align-content: start; padding: 16px; overflow-y: auto; }
.banner {
  margin: 10px auto 18px; text-align: center; font-family: var(--font-display); font-weight: 900; text-transform: uppercase;
  font-size: clamp(1.4rem, 6.4vw, 5rem); line-height: 1.1; color: #fff; letter-spacing: .02em; overflow-wrap: anywhere;
  text-shadow: 0 0 20px rgba(255,255,255,.7), 0 0 60px #3ee8ff, 0 4px 0 #0a3a5a;
  animation: bannerDrop 1.1s cubic-bezier(.3, 1.5, .5, 1) both;
}
.banner small { display: block; font-size: max(.3em, .95rem) !important; font-family: var(--font-body); font-weight: 400; text-transform: none; letter-spacing: 0; font-style: italic; font-size: .3em; line-height: 1.35; color: #e8f8ff; text-shadow: 0 0 12px #000; margin-top: .4em; }
@keyframes bannerDrop { from { transform: translateY(80%); 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(62, 232, 255, .35), 0 0 0 1px #2a4a5e; }
.award-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
#award-note { text-align: center; max-width: min(640px, 100%); color: #cfe6f2; padding: 0 4px; }

@media (max-width: 640px) {
  .inv-label { display: none; }
  #narration { bottom: 70px; }
}
@media (hover: none) { #darkness { background: radial-gradient(ellipse at 50% 50%, rgba(0,0,0,0) 30%, rgba(0,4,10,.65) 100%); } }

.pan-hint { position: fixed; top: 50%; z-index: 4; transform: translateY(-50%); width: 44px; height: 88px; border: 1px solid #2a4258; background: rgba(3, 10, 18, .75); color: var(--biolum); 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; }
