:root {
  --gold: #e0b45a;
  --gold-2: #a8772e;
  --gold-3: #5e3f14;
  --jade: #4fd1a5;
  --jade-2: #1f7a5e;
  --red: #b4462b;
  --ink: #120d09;
  --stone: #231b14;
  --text: #f3e6c8;
  --muted: #b9a47f;
  --bar-h: clamp(38px, 6vh, 54px);
  --inv-h: clamp(70px, 12.5vh, 112px);
  --fret-v: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='32' viewBox='0 0 12 32'%3E%3Cg transform='translate(12 0) rotate(90)'%3E%3Cpath d='M0 11h6V5h6v4H9v2h7V1H3v4' fill='none' stroke='%23e0b45a' stroke-width='1.6'/%3E%3Cpath d='M16 11h6V5h6v4h-3v2h7V1H19v4' fill='none' stroke='%23e0b45a' stroke-width='1.6'/%3E%3C/g%3E%3C/svg%3E");
  --fret: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='12' viewBox='0 0 32 12'%3E%3Cpath d='M0 11h6V5h6v4H9v2h7V1H3v4' fill='none' stroke='%23e0b45a' stroke-width='1.6'/%3E%3Cpath d='M16 11h6V5h6v4h-3v2h7V1H19v4' fill='none' stroke='%23e0b45a' stroke-width='1.6'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  width: 100%; height: 100%;
  background: #070504;
  overflow: hidden;
  color: var(--text);
  font-family: 'Spectral', Georgia, serif;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  touch-action: manipulation;
}
img { -webkit-user-drag: none; user-select: none; pointer-events: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
.hidden { display: none !important; }

/* ---------- FRAME : touches the left & right screen edges, always ---------- */
#frame {
  position: fixed; inset: 0;
  height: 100dvh;
  display: grid;
  grid-template-rows: var(--bar-h) 1fr var(--inv-h);
  grid-template-columns: minmax(0, 1fr);
  padding: 0 14px;
  background: radial-gradient(ellipse at 50% 40%, #2a1f15 0%, #0b0806 75%);
  overflow: hidden;
}
#frame::before, #frame::after {
  content: ""; position: absolute; left: 0; right: 0; height: 10px; z-index: 60; pointer-events: none;
  background: var(--fret) repeat-x center / auto 10px, linear-gradient(#3a2810, #1a1108);
  border-top: 2px solid var(--gold); border-bottom: 2px solid var(--gold);
  box-sizing: content-box;
}
#frame::before { top: 0; }
#frame::after { bottom: 0; }
.frame-side {
  position: absolute; top: 0; bottom: 0; width: 10px; z-index: 59; pointer-events: none;
  background: var(--fret-v) repeat-y center / 10px auto, linear-gradient(90deg, #3a2810, #1a1108);
  border-left: 2px solid var(--gold); border-right: 2px solid var(--gold);
  box-sizing: content-box;
}
.frame-side.left { left: 0; }
.frame-side.right { right: 0; }

/* ---------- TOP BAR ---------- */
#topbar {
  position: relative; z-index: 20;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  grid-row: 1; grid-column: 1; align-self: start;
  padding: 24px 22px 0;
  background: linear-gradient(rgba(12, 8, 4, .85), rgba(12, 8, 4, .35) 70%, transparent);
  pointer-events: none;
}
#sceneTitle {
  font-family: 'Cinzel', serif; font-weight: 700;
  font-size: clamp(12px, 2vw, 18px); letter-spacing: .12em;
  color: var(--gold); text-transform: uppercase; text-align: center;
  text-shadow: 0 0 12px rgba(224, 180, 90, .35);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 8px;
}
.top-right { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
#btnMenu { justify-self: start; }
#btnFull .fs-out, #btnFull.on .fs-in { display: none; }
#btnFull.on .fs-out { display: inline; }
#timer { font-variant-numeric: tabular-nums; font-family: 'Cinzel', serif; font-size: clamp(11px, 1.6vw, 15px); color: var(--muted); letter-spacing: .08em; }
.icon-btn {
  width: clamp(28px, 4.4vh, 38px); height: clamp(28px, 4.4vh, 38px);
  display: grid; place-items: center; border-radius: 50%;
  border: 1px solid rgba(224, 180, 90, .55);
  background: radial-gradient(circle at 40% 35%, #3b2a16, #160f08);
  transition: transform .15s, box-shadow .2s;
}
.icon-btn:hover { transform: scale(1.08); box-shadow: 0 0 14px rgba(224, 180, 90, .45); }
.icon-btn svg { width: 58%; height: 58%; fill: none; stroke: var(--gold); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#btnHint.pulse { animation: hintPulse 1.6s ease-in-out infinite; }
@keyframes hintPulse { 50% { box-shadow: 0 0 18px var(--gold); } }

/* ---------- STAGE ---------- */
#topbar > * { pointer-events: auto; }
#stageWrap { position: relative; overflow: hidden; grid-row: 1 / 3; grid-column: 1; }
#stageBlur {
  position: absolute; inset: -40px;
  background-size: cover; background-position: center;
  filter: blur(28px) brightness(.35) saturate(1.2);
  transition: background-image .6s;
}
#stage {
  position: absolute; left: 0; top: 0; width: 960px; height: 540px;
  overflow: hidden;
  cursor: default;
}
#bg { position: absolute; inset: 0; background-size: 100% 100%; transform-origin: 50% 60%; }
#stage.enter #bg, #stage.enter #objects { animation: bgIn 1.4s ease-out; }
@keyframes bgIn { from { transform: scale(1.06); filter: brightness(.3); } to { transform: none; filter: none; } }
#objects { position: absolute; inset: 0; transform-origin: 50% 60%; }
#fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 6; }
#dark {
  position: absolute; inset: 0; pointer-events: none; z-index: 5;
  opacity: 0; transition: opacity 1.6s ease;
}
#dark.on { opacity: 1; }
#dark.torch {
  background: radial-gradient(circle at var(--mx, 50%) var(--my, 50%), rgba(0,0,0,0) 0, rgba(0,0,0,.55) 7%, rgba(3,2,1,.96) 15%),
              radial-gradient(circle at 37% 58%, rgba(255,150,60,.12) 0, transparent 6%);
  background-blend-mode: normal;
}
#dark.dim { background: radial-gradient(ellipse at 50% 30%, rgba(5,10,25,.55), rgba(2,4,12,.88)); }

.obj {
  position: absolute; z-index: 2;
  cursor: url(../assets/hand.svg) 10 2, pointer;
  transition: filter .25s, opacity .6s, transform .6s;
}
.obj img { width: 100%; height: auto; display: block; filter: drop-shadow(0 6px 8px rgba(0,0,0,.55)); }
.obj.sprite:hover img, .obj.sprite.hl img { filter: drop-shadow(0 0 8px rgba(255, 220, 140, .9)) drop-shadow(0 6px 8px rgba(0,0,0,.5)) brightness(1.1); }
.obj.zone { border-radius: 10px; }
.obj.gone { opacity: 0; pointer-events: none; }
.obj.glow img { animation: glowPulse 2s ease-in-out infinite; }
@keyframes glowPulse { 50% { filter: drop-shadow(0 0 14px rgba(110, 255, 200, .95)) brightness(1.25); } }
.obj.noclick { pointer-events: none; }
.has-item #objects .obj { cursor: url(../assets/hand.svg) 10 2, pointer; }
.obj.noclick { cursor: default; }
.obj[data-id="pot7"] img { filter: none; } /* cut from the background: no shadow, it must blend in */

/* ---------- doors ---------- */
.door-clip { position: absolute; inset: 0; overflow: hidden; }
.passage {
  position: absolute; inset: 0; opacity: 0; transition: opacity 1.2s ease .3s;
  background:
    radial-gradient(ellipse 70% 38% at 50% 100%, rgba(255, 176, 84, .55), transparent 72%),
    radial-gradient(ellipse 30% 55% at 50% 62%, rgba(255, 214, 150, .18), transparent 70%),
    linear-gradient(#020101, #0b0603 45%, #2a180a);
  box-shadow: inset 0 16px 22px -6px #000, inset 12px 0 20px -8px #000, inset -12px 0 20px -8px #000;
}
.passage::after {
  content: ""; position: absolute; inset: 0;
  background: repeating-linear-gradient(100deg, transparent 0 14%, rgba(255, 220, 160, .07) 16% 20%, transparent 22% 34%);
  mix-blend-mode: screen; animation: passageRays 6s ease-in-out infinite alternate;
}
@keyframes passageRays { to { transform: translateX(8%); opacity: .5; } }
.door-sprite .passage {
  background: radial-gradient(ellipse 70% 40% at 50% 100%, rgba(255, 180, 90, .4), transparent 72%);
  box-shadow: inset 0 16px 22px -6px rgba(0, 0, 0, .85);
}
.open .passage { opacity: 1; }
.slab {
  position: absolute; inset: 0; background-repeat: no-repeat;
  transition: transform 3.2s cubic-bezier(.62, .02, .72, 1) .45s, filter 3.2s ease .45s;
  will-change: transform;
}
.slab::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(rgba(255, 232, 190, .16), transparent 5%, transparent 92%, rgba(0, 0, 0, .55));
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .45);
}
/* a closed slab door is just the wall: no edge or shading until it starts to move */
.door-slab .slab::after { transition: opacity .4s; }
.door-slab:not(.open) .slab::after { opacity: 0; }
.door-sprite .slab::after { box-shadow: inset 0 0 22px 8px rgba(0, 0, 0, .72), inset 0 0 0 1px rgba(0, 0, 0, .6); }
.slab img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; filter: brightness(.74) contrast(1.1) sepia(.18); }
.open .slab { transform: translateY(101%); filter: brightness(.55); }
.opening:not(.quad) .door-clip { animation: doorJolt .4s cubic-bezier(.3, 1.6, .5, 1), doorRumble .09s linear .45s 34; }
@keyframes doorJolt { 40% { transform: translateY(1.5%); } }
@keyframes doorRumble { 25% { transform: translate(-1px, .5px); } 75% { transform: translate(1px, -.5px); } }
.door-spill {
  position: absolute; left: -45%; right: -45%; top: 94%; height: 42%; pointer-events: none;
  background: radial-gradient(ellipse 45% 55% at 50% 0%, rgba(255, 190, 100, .5), rgba(255, 160, 70, .15) 50%, transparent 72%);
  mix-blend-mode: screen; filter: blur(5px); opacity: 0; transition: opacity 2.2s ease 2s;
}
.open .door-spill { opacity: 1; animation: spill 4s ease-in-out 4.2s infinite alternate; }
@keyframes spill { to { opacity: .7; } }

/* water filling (scene 4) */
.water {
  position: absolute; pointer-events: none; z-index: 1;
  background: linear-gradient(180deg, rgba(90, 220, 220, .55), rgba(20, 110, 130, .75));
  mix-blend-mode: screen; clip-path: polygon(8% 0, 92% 0, 100% 100%, 0 100%);
  transform-origin: 50% 100%; transform: scaleY(0); transition: transform 3s ease-out;
  overflow: hidden;
}
.water.full { transform: scaleY(1); }
.water::after {
  content: ""; position: absolute; inset: -50%;
  background: repeating-radial-gradient(circle at 30% 40%, rgba(255,255,255,.18) 0 2px, transparent 3px 14px);
  animation: ripple 6s linear infinite;
}
@keyframes ripple { to { transform: translate(10%, 6%) rotate(8deg); } }

.oculus-cover {
  position: absolute; z-index: 1; pointer-events: none; border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, #3a3a3e, #17171a 70%);
  box-shadow: inset 0 0 30px #000;
  transition: transform 3s ease-in-out, opacity 3s;
}
.oculus-cover.open { transform: translateX(-120%) rotate(-40deg); opacity: 0; }

.mural-placed { transition: filter 3s ease; }
.mural-placed.faded img { filter: grayscale(.85) sepia(.4) brightness(.8) contrast(.9); }

.beam {
  position: absolute; z-index: 3; pointer-events: none;
  background: linear-gradient(180deg, rgba(255, 250, 210, .0), rgba(255, 240, 180, .65), rgba(255, 220, 140, .0));
  filter: blur(6px); mix-blend-mode: screen; opacity: 0; transition: opacity 2s;
}
.beam.on { opacity: 1; animation: beamFlicker 3s ease-in-out infinite; }
@keyframes beamFlicker { 50% { opacity: .75; } }

.fire {
  position: absolute; z-index: 3; pointer-events: none; transform: translate(-50%, -100%);
  width: 6%; aspect-ratio: 1 / 1.5;
  background: radial-gradient(ellipse at 50% 85%, #fff6c0 0, #ffb13b 25%, rgba(255, 90, 20, .7) 45%, transparent 70%);
  filter: blur(2px); mix-blend-mode: screen;
  animation: flame .18s ease-in-out infinite alternate;
}
/* brazier: the flame is cut at the front rim so it rises from inside the bowl */
.bowl-fire { -webkit-mask-image: linear-gradient(#000 78%, transparent 88%); mask-image: linear-gradient(#000 78%, transparent 88%); }
.embers {
  position: absolute; left: 8%; width: 84%; top: 78%; height: 10%; pointer-events: none;
  background: radial-gradient(ellipse at 50% 60%, rgba(255,235,170,.95) 0, rgba(255,150,40,.75) 35%, rgba(200,60,10,.35) 60%, transparent 75%);
  mix-blend-mode: screen; filter: blur(1px); animation: embers .5s ease-in-out infinite alternate;
}
@keyframes embers { to { opacity: .75; transform: scaleX(.96); } }
@keyframes flame { to { transform: translate(-50%, -102%) scale(1.06, .94); opacity: .85; } }

.nav-arrow {
  position: absolute; left: 1.2%; top: 50%; z-index: 8;
  width: clamp(30px, 4vw, 48px); height: clamp(30px, 4vw, 48px);
  transform: translateY(-50%); border-radius: 50%;
  background: rgba(10, 6, 3, .55); border: 1px solid rgba(224, 180, 90, .6);
  display: grid; place-items: center; opacity: .65; transition: opacity .2s, transform .2s;
}
.nav-arrow:hover { opacity: 1; transform: translateY(-50%) scale(1.08); }
.nav-arrow svg { width: 55%; height: 55%; fill: none; stroke: var(--gold); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

#say {
  position: absolute; left: 50%; bottom: 3%; z-index: 9;
  transform: translate(-50%, 10px); opacity: 0;
  max-width: 82%; padding: .55em 1.2em;
  font-size: clamp(12px, 1.9vw, 19px); line-height: 1.35; text-align: center;
  background: linear-gradient(90deg, transparent, rgba(10, 6, 3, .86) 12%, rgba(10, 6, 3, .86) 88%, transparent);
  color: var(--text); text-shadow: 0 1px 2px #000;
  transition: opacity .35s, transform .35s; pointer-events: none;
}
#say.show { opacity: 1; transform: translate(-50%, 0); }
#say b { color: var(--gold); font-weight: 600; }

#flash { position: absolute; inset: 0; z-index: 12; pointer-events: none; background: #fff3cf; opacity: 0; }
#flash.go { animation: flash 1.2s ease-out; }
@keyframes flash { 0% { opacity: 0; } 15% { opacity: .85; } 100% { opacity: 0; } }

#sceneCard {
  position: absolute; inset: 0; z-index: 11; pointer-events: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  opacity: 0; background: radial-gradient(ellipse, rgba(0,0,0,.55), transparent 70%);
}
#sceneCard.show { animation: card 2.8s ease forwards; }
@keyframes card { 0% { opacity: 0; } 20%, 70% { opacity: 1; } 100% { opacity: 0; } }
#sceneCard .num { font-family: 'Cinzel', serif; color: var(--jade); letter-spacing: .4em; font-size: clamp(11px, 1.6vw, 16px); }
#sceneCard .name { font-family: 'Cinzel Decorative', serif; color: var(--gold); font-size: clamp(22px, 5vw, 56px); text-shadow: 0 0 24px rgba(224,180,90,.5), 0 3px 6px #000; text-align: center; }

.shake { animation: shake .6s cubic-bezier(.36,.07,.19,.97) both; }
.shake-long { animation: shake .6s cubic-bezier(.36,.07,.19,.97) 5 both; }
@keyframes shake {
  10%, 90% { transform: translate(-1px, 1px); } 20%, 80% { transform: translate(3px, -2px); }
  30%, 50%, 70% { transform: translate(-5px, 2px); } 40%, 60% { transform: translate(5px, -1px); }
}

/* ---------- INVENTORY ---------- */
#inventory {
  position: relative; z-index: 20; grid-row: 3;
  padding: 8px 12px 24px;
  background: linear-gradient(#120c07, #1d140b);
  border-top: 1px solid rgba(224, 180, 90, .35);
  display: flex; align-items: center; justify-content: center;
}
#invSlots {
  display: flex; align-items: center; gap: clamp(4px, 1vw, 10px); height: 100%;
  overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
  padding: 2px 4px; max-width: 100%; min-width: 0; flex: 0 1 auto;
  scroll-snap-type: x proximity;
}
.inv-arrow {
  display: none; flex: 0 0 auto; place-items: center;
  width: clamp(26px, 4vw, 36px); height: min(calc(var(--inv-h) - var(--inv-pad, 36px)), 84px);
  border-radius: 8px; background: rgba(10, 6, 3, .6); border: 1px solid rgba(224, 180, 90, .5);
  transition: opacity .2s;
}
#inventory.scrolls .inv-arrow { display: grid; }
.inv-arrow:disabled { opacity: .3; cursor: default; }
.inv-arrow svg { width: 70%; height: 70%; fill: none; stroke: var(--gold); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
#invSlots::-webkit-scrollbar { display: none; }
#invPrev { margin-right: 6px; }
#invNext { margin-left: 6px; }
.slot {
  position: relative; flex: 0 0 auto; scroll-snap-align: start;
  width: min(calc(var(--inv-h) - var(--inv-pad, 36px)), 84px); height: min(calc(var(--inv-h) - var(--inv-pad, 36px)), 84px);
  border-radius: 10px;
  background: radial-gradient(circle at 50% 40%, #3a2a18, #140d07 75%);
  border: 1px solid rgba(224, 180, 90, .4);
  box-shadow: inset 0 0 12px #000;
  display: grid; place-items: center; cursor: url(../assets/hand.svg) 10 2, pointer;
  transition: transform .15s, box-shadow .2s, border-color .2s;
}
.slot.empty { cursor: default; opacity: .45; }
.slot img { position: absolute; left: 10%; top: 10%; width: 80%; height: 80%; object-fit: contain; filter: drop-shadow(0 3px 4px rgba(0,0,0,.7)); }
.slot:not(.empty):hover { border-color: var(--gold); }
.slot.sel { border-color: var(--jade); box-shadow: 0 0 0 2px var(--jade), 0 0 18px rgba(79, 209, 165, .6), inset 0 0 12px #000; }
.slot.new { animation: slotNew 1s ease; }
@keyframes slotNew { 30% { box-shadow: 0 0 24px var(--gold), inset 0 0 12px #000; border-color: var(--gold); } }
.slot .tip {
  position: absolute; bottom: 104%; left: 50%; transform: translateX(-50%);
  white-space: nowrap; font-size: 12px; padding: 3px 8px; border-radius: 6px;
  background: rgba(10, 6, 3, .92); border: 1px solid rgba(224, 180, 90, .4); color: var(--gold);
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.slot:hover .tip { opacity: 1; }
.fly { position: fixed; z-index: 200; pointer-events: none; filter: drop-shadow(0 0 12px rgba(255, 220, 140, .9)); }

/* ---------- MODAL ---------- */
#modal {
  position: absolute; inset: 0; z-index: 40;
  display: grid; place-items: center;
  background: rgba(4, 3, 2, .72); backdrop-filter: blur(4px);
  animation: fadeIn .3s ease;
}
@keyframes fadeIn { from { opacity: 0; } }
.modal-panel {
  position: relative;
  width: min(94vw, 900px); max-height: calc(100dvh - 34px);
  overflow: auto; scrollbar-width: none;
  padding: clamp(14px, 3vw, 28px);
  background: radial-gradient(ellipse at 50% 0%, #3a2814, #17100a 70%);
  border: 2px solid var(--gold-2);
  border-radius: 14px;
  box-shadow: 0 0 0 4px #0e0905, 0 0 0 5px rgba(224, 180, 90, .4), 0 20px 60px #000;
  animation: popIn .35s cubic-bezier(.2, 1.3, .5, 1);
}
@keyframes popIn { from { transform: scale(.9); opacity: 0; } }
.modal-title {
  font-family: 'Cinzel', serif; color: var(--gold); text-align: center;
  font-size: clamp(16px, 2.6vw, 26px); letter-spacing: .1em; margin-bottom: 12px; padding: 0 32px;
}
.modal-close {
  position: absolute; top: 10px; right: 10px; width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid rgba(224, 180, 90, .5); display: grid; place-items: center; z-index: 3;
  background: rgba(0,0,0,.35);
}
.modal-close svg { width: 55%; height: 55%; stroke: var(--gold); stroke-width: 2.2; stroke-linecap: round; }
.modal-body { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.pz-note { font-style: italic; color: var(--muted); text-align: center; font-size: clamp(13px, 1.8vw, 16px); max-width: 640px; }
.pz-btn {
  font-family: 'Cinzel', serif; font-weight: 700; letter-spacing: .08em;
  padding: .6em 1.4em; border-radius: 30px; color: #1b1106;
  background: linear-gradient(#f4d488, #c8913c); border: 1px solid #fbe6b0;
  box-shadow: 0 3px 0 #6b4515, 0 6px 14px rgba(0,0,0,.5); font-size: clamp(12px, 1.7vw, 15px);
}
.pz-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #6b4515; }
.pz-btn.ghost { background: transparent; color: var(--gold); border-color: var(--gold-2); box-shadow: none; }
.pz-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.pz-solved .pz-area { animation: solvedGlow 1.6s ease; }
@keyframes solvedGlow { 30% { filter: drop-shadow(0 0 30px var(--gold)) brightness(1.3); } }

/* examine */
.examine { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; justify-content: center; }
.examine img { width: min(260px, 60vw); filter: drop-shadow(0 10px 20px #000); }
.examine p { max-width: 360px; font-size: clamp(14px, 2vw, 18px); line-height: 1.5; }
.page {
  width: min(620px, 86vw); min-height: 260px; padding: 26px 30px;
  background: linear-gradient(135deg, #e8d3a6, #cfb37c); color: #3a2612; border-radius: 4px;
  box-shadow: inset 0 0 40px rgba(110, 70, 20, .45), 0 10px 30px #000;
  font-size: clamp(14px, 2vw, 17px); line-height: 1.6;
  font-family: 'Spectral', serif;
}
.page h3 { font-family: 'Cinzel', serif; margin-bottom: 8px; font-size: 1.1em; color: #5a2e10; }
.page p + p { margin-top: 8px; }
.page .hand { font-style: italic; }
.cdx-date { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 12px 0; font-family: 'Cinzel', serif; font-size: 1.5em; color: #8d2f1c; }
.cdx-date .sep { opacity: .5; }
.page.codex { background: linear-gradient(135deg, #e9dcc0, #d2bf96); border: 6px double #8d2f1c; }
.pager { display: flex; gap: 16px; align-items: center; font-family: 'Cinzel', serif; color: var(--muted); }
.numerals { display: flex; gap: 18px; flex-wrap: wrap; justify-content: center; margin: 10px 0; }
.numerals div { text-align: center; font-size: .85em; }
.numerals svg { width: 48px; height: 48px; display: block; margin: 0 auto 2px; }

/* ---------- SCREENS ---------- */
.screen { position: absolute; inset: 0; z-index: 50; display: grid; place-items: center; }
#preloader { background: radial-gradient(ellipse at 50% 45%, #2a1d10, #070504 70%); flex-direction: column; display: flex; align-items: center; justify-content: center; gap: 20px; }
.pre-glyph { position: relative; width: clamp(120px, 22vmin, 200px); aspect-ratio: 1; }
.pre-glyph svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: rgba(224, 180, 90, .15); stroke-width: 4; }
.ring-fg { fill: none; stroke: var(--gold); stroke-width: 4; stroke-linecap: round; stroke-dasharray: 276.5; stroke-dashoffset: 276.5; transition: stroke-dashoffset .3s; filter: drop-shadow(0 0 6px var(--gold)); }
.sun { fill: none; stroke: var(--jade); stroke-width: 1.4; transform-origin: 50% 50%; animation: spin 12s linear infinite; opacity: .6; }
@keyframes spin { to { transform: rotate(360deg); } }
#prePct { position: absolute; inset: 0; display: grid; place-items: center; font-family: 'Cinzel', serif; font-size: clamp(20px, 4.4vmin, 36px); color: var(--gold); text-shadow: 0 0 14px rgba(224, 180, 90, .6); }
.pre-label { font-family: 'Cinzel', serif; color: var(--muted); letter-spacing: .3em; font-size: clamp(11px, 1.6vw, 14px); text-transform: uppercase; }

#menu, #ending { overflow: hidden; }
.menu-bg, .end-bg { position: absolute; inset: -4%; background-size: cover; background-position: center; animation: kenburns 30s ease-in-out infinite alternate; }
.menu-bg::after, .end-bg::after { content: ""; position: absolute; inset: 0; background: radial-gradient(ellipse at 50% 55%, rgba(0,0,0,.15), rgba(0,0,0,.75)); }
@keyframes kenburns { to { transform: scale(1.08) translate(-1.5%, 1%); } }
.menu-inner { position: relative; z-index: 2; display: flex; flex-direction: column; align-items: center; gap: clamp(16px, 4vh, 40px); padding: 20px; text-align: center; }
.logo {
  font-family: 'Cinzel Decorative', serif; font-weight: 900;
  font-size: clamp(38px, 9vw, 110px); line-height: 1;
  background: linear-gradient(180deg, #fff3c4 0%, #e8b65a 45%, #8a5a1c 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 0 #2a1804) drop-shadow(0 10px 30px rgba(0,0,0,.8));
  animation: logoIn 1.6s ease both;
}
.logo-sub { display: block; font-family: 'Cinzel', serif; font-size: .26em; letter-spacing: .5em; margin-bottom: .2em; }
@keyframes logoIn { from { opacity: 0; transform: translateY(-20px) scale(.96); letter-spacing: .1em; } }
.menu-buttons { display: flex; flex-direction: column; gap: 12px; align-items: center; animation: fadeIn 1.2s .6s both; }
.mbtn {
  min-width: clamp(200px, 30vw, 300px);
  font-family: 'Cinzel', serif; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
  font-size: clamp(13px, 1.9vw, 18px); padding: .8em 1.6em; color: #fbecc4;
  background: linear-gradient(180deg, rgba(70, 45, 18, .92), rgba(25, 15, 6, .92));
  border: 1px solid var(--gold); border-radius: 4px;
  clip-path: polygon(12px 0, calc(100% - 12px) 0, 100% 50%, calc(100% - 12px) 100%, 12px 100%, 0 50%);
  transition: transform .2s, background .2s, color .2s;
}
.mbtn:hover { transform: scale(1.05); background: linear-gradient(180deg, #e0b45a, #8a5a1c); color: #1a1005; }
.mbtn.small { font-size: clamp(11px, 1.5vw, 14px); min-width: clamp(160px, 22vw, 220px); padding: .6em 1.2em; }
#pause { background: rgba(5, 3, 2, .82); backdrop-filter: blur(6px); }
.pause-title { font-family: 'Cinzel Decorative', serif; color: var(--gold); font-size: clamp(30px, 6vw, 60px); }

@media (max-width: 700px) {
  #topbar { padding: 22px 18px 0; }
  #timer { display: none; }
}
@media (orientation: portrait) {
  :root { --inv-h: clamp(84px, 12vh, 112px); }
}
/* phones held sideways: little height, so a slimmer bar with bigger, finger-sized slots */
@media (orientation: landscape) and (max-height: 500px) {
  :root { --inv-h: 64px; --inv-pad: 20px; }
  #inventory { padding-top: 4px; padding-bottom: 16px; }
}

/* scene-specific object states */
.obj.moved { transform: translateX(-70%) rotate(-12deg); }
.obj.underwater img { opacity: .55; filter: blur(1.2px) hue-rotate(-20deg) brightness(.8); }
.obj.full .water { transform: scaleY(1); }
.obj.open .oculus-cover { transform: translateX(-120%) rotate(-40deg); opacity: 0; }
.sunglow { border-radius: 50%; background: radial-gradient(circle, rgba(255, 230, 150, .85), rgba(255, 170, 60, .35) 40%, transparent 70%); mix-blend-mode: screen; animation: sunPulse 3s ease-in-out infinite; }
@keyframes sunPulse { 50% { opacity: .6; transform: scale(1.06); } }
.seal { border-radius: 50%; background: radial-gradient(circle, rgba(140, 255, 210, .9), rgba(79, 209, 165, .35) 45%, transparent 70%); mix-blend-mode: screen; animation: sunPulse 1.8s ease-in-out infinite; }
.holder { border-radius: 50%; border: 3px solid #8a6a35; background: radial-gradient(circle, #15110c 55%, #3a2e20); box-shadow: 0 0 12px rgba(79, 209, 165, .4), inset 0 0 10px #000; }
.holder:not(.filled) { animation: holderPulse 2.2s ease-in-out infinite; }
@keyframes holderPulse { 50% { box-shadow: 0 0 22px rgba(79, 209, 165, .9), inset 0 0 10px #000; } }
.holder.filled { background: radial-gradient(circle at 35% 30%, #5b5b66 0, #0b0b0e 45%), #0b0b0e; border-color: #e0b45a; box-shadow: 0 0 18px rgba(255, 210, 110, .7), inset 0 0 6px #000; }
.obj.sprite::after { content: ""; position: absolute; inset: -10px; }

/* angled doors: the plane is warped, so shake the whole element instead */
.quad.opening { animation: doorRumble .09s linear .45s 34; }
.quad .slab::after { background: linear-gradient(90deg, rgba(0,0,0,.55), transparent 35%, transparent 80%, rgba(0,0,0,.35)), linear-gradient(rgba(255,232,190,.12), transparent 6%); }
.quad .door-spill { left: -20%; right: -60%; }
.quad > .passage { box-shadow: none; } /* the frame is cut by clip-path: a box shadow would darken the wrong edge */

/* ---------- FINALE ---------- */
.serpent-eyes { pointer-events: none; }
.serpent-eyes i {
  position: absolute; top: 50%; margin-top: -13%; width: 26%; aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle, #fff 0, #b6ffe4 22%, #2bff9f 45%, rgba(20,220,140,.5) 62%, transparent 72%);
  box-shadow: 0 0 1.2em .4em rgba(60,255,170,.75), 0 0 3em 1em rgba(40,230,150,.4);
  animation: eyeBurn 1.4s ease-in-out infinite alternate;
}
.serpent-eyes.blaze i { animation-duration: .5s; box-shadow: 0 0 2em .8em rgba(90,255,190,.9), 0 0 5em 2em rgba(40,230,150,.55); }
.serpent-eyes i:first-child { left: 9.5%; } .serpent-eyes i:last-child { right: 10.5%; }
@keyframes eyeBurn { from { transform: scale(.85); opacity: .8; } to { transform: scale(1.25); opacity: 1; } }

#whiteout {
  position: absolute; inset: 0; z-index: 80; pointer-events: none; opacity: 0;
  background: radial-gradient(circle at 50% 45%, #fffef6, #fff4d6 55%, #f6dba0);
  transition: opacity 2.2s ease;
}
#whiteout.on { opacity: 1; transition-duration: 1.7s; transition-timing-function: ease-in; }

#ending { cursor: default; }
#ending .end-bg { animation: endZoom 40s ease-out both; }
@keyframes endZoom { from { transform: scale(1.14) translate(2%, 2%); } to { transform: scale(1) translate(0, 0); } }
#ending .end-bg::after { background: radial-gradient(ellipse 70% 80% at 50% 55%, rgba(10,6,2,.62), rgba(10,6,2,.25) 70%, rgba(0,0,0,.55)); }
.end-rays {
  position: absolute; inset: -50%; pointer-events: none; mix-blend-mode: screen; opacity: .55;
  background: repeating-conic-gradient(from 0deg at 39% 30%, rgba(255,226,150,.16) 0 3deg, transparent 3deg 11deg);
  -webkit-mask-image: radial-gradient(circle at 39% 30%, #000 0, transparent 45%);
  mask-image: radial-gradient(circle at 39% 30%, #000 0, transparent 45%);
  animation: raysTurn 90s linear infinite;
}
@keyframes raysTurn { to { transform: rotate(360deg); } }
.end-motes { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

.end-inner {
  position: relative; z-index: 2; width: min(760px, 94%); max-height: 100%; overflow-y: auto; scrollbar-width: none;
  display: flex; flex-direction: column; align-items: center; gap: clamp(10px, 2.4vh, 26px);
  padding: clamp(16px, 4vh, 40px) 12px; text-align: center;
}
.rv { opacity: 0; transform: translateY(14px); filter: blur(6px); transition: opacity 1.6s ease, transform 1.6s cubic-bezier(.2,.7,.2,1), filter 1.6s ease; }
.rv.in { opacity: 1; transform: none; filter: none; }
.end-logo.rv { animation: none; transition-duration: 2.4s; }
.end-logo.rv.in { filter: drop-shadow(0 4px 0 #2a1804) drop-shadow(0 0 40px rgba(255,210,120,.55)) drop-shadow(0 10px 30px rgba(0,0,0,.8)); }
.end-kicker {
  font-family: 'Cinzel', serif; color: var(--jade); letter-spacing: .6em; text-transform: uppercase;
  font-size: clamp(11px, 1.5vw, 14px); text-shadow: 0 0 12px rgba(79,209,165,.6), 0 2px 4px #000;
  display: flex; align-items: center; gap: 1em;
}
.end-kicker::before, .end-kicker::after { content: ""; width: clamp(30px, 8vw, 80px); height: 1px; background: linear-gradient(90deg, transparent, var(--jade)); }
.end-kicker::after { transform: scaleX(-1); }
.end-story { display: flex; flex-direction: column; gap: .7em; max-width: 600px; }
.end-story p { margin: 0; font-size: clamp(14px, 2vw, 19px); line-height: 1.55; text-shadow: 0 2px 8px #000, 0 0 2px #000; }
.end-story em { color: var(--gold); }

.end-card {
  position: relative; width: min(520px, 100%); padding: clamp(14px, 2.6vh, 24px) clamp(14px, 3vw, 28px);
  background: linear-gradient(180deg, rgba(36,24,12,.82), rgba(16,10,5,.9));
  border: 1px solid var(--gold-2); border-radius: 6px;
  box-shadow: 0 0 0 4px rgba(16,10,5,.6), 0 0 0 5px rgba(224,180,90,.35), 0 20px 60px rgba(0,0,0,.6);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.end-card::before { content: ""; position: absolute; left: 12%; right: 12%; top: -1px; height: 1px; background: linear-gradient(90deg, transparent, #fff3c4, transparent); }
.end-stars { display: flex; justify-content: center; gap: clamp(8px, 2vw, 18px); margin-bottom: 6px; }
.end-stars span { width: clamp(30px, 5vw, 44px); opacity: .25; transform: scale(.4); }
.end-stars svg { width: 100%; display: block; fill: #3a2c1a; stroke: var(--gold-2); stroke-width: 1; }
.end-card.in .end-stars span { animation: starPop .6s cubic-bezier(.3,1.6,.5,1) calc(.5s + var(--i) * .35s) forwards; }
.end-card.in .end-stars span.on svg { fill: var(--jade); stroke: #c9ffe9; filter: drop-shadow(0 0 10px rgba(79,209,165,.9)); }
@keyframes starPop { to { opacity: 1; transform: scale(1); } }
.end-rank b { display: block; font-family: 'Cinzel Decorative', serif; color: var(--gold); font-size: clamp(17px, 2.8vw, 26px); text-shadow: 0 0 18px rgba(224,180,90,.45); }
.end-rank span { display: block; margin-top: 2px; font-style: italic; color: var(--muted); font-size: clamp(12px, 1.6vw, 15px); }
.end-stats { display: grid; grid-template-columns: repeat(3, 1fr); margin-top: clamp(10px, 2vh, 18px); border-top: 1px solid rgba(224,180,90,.25); padding-top: clamp(10px, 2vh, 16px); }
.end-stats div { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.end-stats div + div { border-left: 1px solid rgba(224,180,90,.18); }
.end-stats small { font-family: 'Cinzel', serif; color: var(--muted); letter-spacing: .25em; text-transform: uppercase; font-size: clamp(9px, 1.2vw, 11px); }
.end-stats strong { font-family: 'Cinzel', serif; color: var(--text); font-size: clamp(18px, 3vw, 28px); font-weight: 700; }
.end-stats i { font-style: normal; font-family: 'Cinzel', serif; font-size: 10px; letter-spacing: .2em; text-transform: uppercase; color: #10241c; background: var(--jade); padding: 1px 7px; border-radius: 10px; animation: hintPulse 2s infinite; }
.end-buttons { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 12px; }
#ending:not(.done) .end-buttons { pointer-events: none; }
.end-side { display: contents; }

/* wide screens: story on the left, results on the right — everything fits without scrolling */
@media (orientation: landscape) and (min-width: 900px) {
  .end-inner {
    width: min(1240px, 94%); height: 100%; overflow: hidden;
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: clamp(28px, 4vw, 64px);
    grid-template-rows: 1fr auto auto auto auto auto 1fr; align-items: center;
    padding: clamp(16px, 3vh, 36px) 12px;
  }
  .end-inner > * { grid-column: 1; }
  .end-kicker { grid-row: 2; }
  .end-logo { grid-row: 3; font-size: clamp(44px, min(6vw, 11vh), 100px); }
  .end-story { grid-row: 4; gap: .5em; }
  .end-story p { font-size: clamp(14px, min(1.35vw, 2.3vh), 18px); line-height: 1.5; }
  .end-buttons { grid-row: 5; margin-top: clamp(4px, 1.5vh, 14px); }
  .end-credit { grid-row: 6; justify-content: center; }
  .end-side {
    display: flex; flex-direction: column; align-items: center; gap: clamp(8px, 1.4vh, 18px);
    grid-column: 2; grid-row: 1 / -1; align-self: stretch; justify-content: center; min-height: 0;
    padding-bottom: clamp(56px, 10vh, 84px); /* keep clear of the WEG badge */
  }
  .end-side .end-card { padding: clamp(10px, 1.8vh, 18px) clamp(14px, 2vw, 24px); }
  .end-side .end-stats { margin-top: clamp(6px, 1.2vh, 12px); padding-top: clamp(6px, 1.2vh, 12px); }
  .end-side .end-card, .end-side .end-scores { width: 100%; max-width: 520px; flex: none; }
  .end-side .end-scores { flex: 0 1 auto; min-height: 0; gap: 8px; }
  .end-side .lb-board { min-height: 0; overflow-y: auto; scrollbar-width: none; }
  .end-side .lb-list { gap: 2px; margin-top: 4px; }
  .end-side .lb-row { padding: 0 12px; }
  .end-side .lb-rank { width: min(2.1em, 2.9vh); height: min(2.1em, 2.9vh); }
  .end-side .lb-rank b, .end-side .lb-who { font-size: clamp(12px, 1.9vh, 15px); }
  .end-side .lb-time { font-size: clamp(13px, 2vh, 17px); }
  .end-side .lb-who img { width: 20px; height: 20px; }
  .end-stars span { width: clamp(26px, 4.2vh, 42px); }
}

/* windows still scroll when they must, but never show a scrollbar */
* { scrollbar-width: none; }
*::-webkit-scrollbar { display: none; }
