:root {
  --ink: #05080b;
  --amber: #f2c979;
  --amber-dim: rgba(242, 201, 121, .32);
  --teal: #8fdcd4;
  --paper: #f3efe6;
  --serif: "Cormorant Garamond", "Iowan Old Style", Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--ink); overflow: hidden; overscroll-behavior: none; }
body { color: #e9e4d8; font-family: var(--serif); transition: background 3s ease; user-select: none; -webkit-user-select: none; }
body.awake { background: var(--paper); }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
[hidden] { display: none !important; }

#app {
  position: fixed; inset: 0; height: 100dvh; overflow: hidden; background: var(--ink);
  transition: transform 3.6s cubic-bezier(.6, 0, .2, 1), border-radius 3.6s, box-shadow 3.6s;
  transform-origin: 50% 50%;
}
#app.shrunk {
  transform: translateY(-21dvh) scale(.27); border-radius: 64px;
  box-shadow: 0 0 0 14px #16181b, 0 60px 120px rgba(40, 30, 10, .45);
  pointer-events: none;
}

/* ---------- world & scenes ---------- */
#world { position: absolute; inset: 0; will-change: transform; }
.scene { position: absolute; inset: 0; overflow: hidden; touch-action: none; }
.cam { position: absolute; inset: 0; will-change: transform, opacity; }
.stage { position: absolute; left: 0; top: 0; background-size: 100% 100%; background-repeat: no-repeat; will-change: transform; }
.scene.fadein { animation: fadein 2.4s ease both; }
@keyframes fadein { from { opacity: 0; filter: blur(12px) brightness(1.6); } to { opacity: 1; filter: none; } }

#vignette { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse at center, transparent 45%, rgba(0, 0, 0, .62) 100%); }
#grain {
  position: absolute; inset: -100px; pointer-events: none; opacity: .11; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  animation: grain .9s steps(6) infinite;
}
@keyframes grain { 0% { transform: translate(0, 0); } 25% { transform: translate(-40px, 30px); } 50% { transform: translate(30px, -50px); } 75% { transform: translate(-20px, -30px); } 100% { transform: translate(40px, 40px); } }

/* ---------- HUD ---------- */
#hud { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center; padding: max(14px, env(safe-area-inset-top)) 18px 0; z-index: 30; pointer-events: none; }
#hud > * { pointer-events: auto; }
#depth { display: flex; align-items: center; gap: 10px; font: 500 11px/1 var(--mono); letter-spacing: .22em; color: var(--amber); text-shadow: 0 1px 6px #000; }
#depth-glyph { width: 34px; height: 34px; }
#depth-glyph rect { fill: none; stroke: rgba(242, 201, 121, .28); stroke-width: 1; transition: all 1.2s; }
#depth-glyph rect.past { stroke: rgba(242, 201, 121, .12); }
#depth-glyph rect.now { stroke: var(--amber); stroke-width: 1.8; filter: drop-shadow(0 0 3px var(--amber)); }
#tools { display: flex; gap: 8px; }
#tools button { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--amber-dim); font: 500 12px/1 var(--mono); color: var(--amber); background: rgba(5, 8, 11, .45); backdrop-filter: blur(6px); transition: opacity .6s, transform .2s, background .2s; }
#tools button:hover { background: rgba(242, 201, 121, .16); }
#tools button.off { opacity: .4; text-decoration: line-through; }
#btn-hint { opacity: 0; pointer-events: none; }
#btn-hint.ready { opacity: 1; pointer-events: auto; animation: pulse 2.6s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(242, 201, 121, .12); } }
#hint-card { position: absolute; top: 62px; right: 18px; max-width: min(340px, 84vw); z-index: 31; padding: 14px 16px; font: 400 13px/1.55 var(--mono); color: #d9f3ef; background: rgba(8, 20, 22, .86); border: 1px solid rgba(143, 220, 212, .4); border-radius: 4px; backdrop-filter: blur(8px); }
#hint-card small { display: block; margin-bottom: 6px; color: var(--teal); letter-spacing: .2em; font-size: 10px; }
#fake-back { position: absolute; top: 60px; left: 16px; z-index: 31; width: 44px; height: 44px; border-radius: 50%; border: 1px solid rgba(143, 220, 212, .5); color: var(--teal); font: 20px var(--mono); background: rgba(8, 20, 22, .7); animation: pulse 2s infinite; }

/* ---------- totem ---------- */
#totem { position: absolute; left: 16px; bottom: max(16px, env(safe-area-inset-bottom)); width: 40px; z-index: 30; opacity: .9; filter: drop-shadow(0 6px 8px rgba(0, 0, 0, .7)); }
.top { display: block; width: 100%; overflow: visible; }
.top-body { transform-box: view-box; transform-origin: 50px 116px; }
.top.fallen .top-body { transition: transform 1.4s cubic-bezier(.5, 0, .9, .5); transform: rotate(76deg) !important; }
.bigtop { position: absolute; z-index: 3; pointer-events: none; filter: drop-shadow(0 12px 18px rgba(0, 0, 0, .8)); }
.bigtop::after { content: ""; position: absolute; left: 10%; right: 10%; bottom: -3%; height: 9%; border-radius: 50%; background: radial-gradient(ellipse, rgba(0, 0, 0, .7), transparent 70%); z-index: -1; }

/* ---------- Halcyon's voice ---------- */
#voice {
  position: absolute; left: 50%; bottom: max(5dvh, 24px); width: min(620px, calc(100vw - 108px)); margin-left: calc(min(620px, calc(100vw - 108px)) / -2);
  z-index: 20; padding: 16px 22px 18px; min-height: 92px;
  background: rgba(6, 10, 13, .66); border: 1px solid var(--amber-dim); border-radius: 3px; backdrop-filter: blur(10px);
  transition: opacity .8s; box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}
#voice.gone { opacity: 0; pointer-events: none; }
#voice .who { font: 500 10px/1 var(--mono); letter-spacing: .34em; color: var(--amber); margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
#voice .who::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 10px var(--amber); animation: breathe 3.2s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: .35; transform: scale(.7); } }
#voice-text { margin: 0; font-size: clamp(18px, 2.4vw, 23px); line-height: 1.35; font-style: italic; min-height: 1.35em; }
#voice-choices { display: flex; gap: 10px; margin-top: 12px; }
#voice-choices:empty { display: none; }
#voice-choices button, .btn {
  font: 500 12px/1 var(--mono); letter-spacing: .18em; text-transform: uppercase; color: var(--amber);
  padding: 12px 18px; border: 1px solid var(--amber-dim); border-radius: 2px; background: rgba(242, 201, 121, .06); transition: background .2s, transform .2s;
}
#voice-choices button:hover, .btn:hover { background: rgba(242, 201, 121, .18); }
#voice.solid { background: #080c10; backdrop-filter: none; cursor: grab; touch-action: none; }
#voice.solid.dragging { cursor: grabbing; transition: none; }
#voice.solid::before { content: ""; position: absolute; inset: -5px; z-index: -1; border-radius: 8px; background: radial-gradient(ellipse, rgba(190, 235, 255, .9), transparent 72%); filter: blur(9px); opacity: .25; animation: leak 3.4s ease-in-out infinite; }
@keyframes leak { 50% { opacity: .7; } }

/* ---------- intro ---------- */
#intro { position: absolute; inset: 0; z-index: 50; display: grid; place-items: center; background: radial-gradient(ellipse at 50% 40%, #0d1a1e 0%, var(--ink) 70%); transition: opacity 2.2s ease; text-align: center; padding: 24px; }
#intro.gone { opacity: 0; pointer-events: none; }
.intro-inner { max-width: 560px; display: flex; flex-direction: column; align-items: center; }
#intro-top { width: 58px; margin-bottom: 22px; filter: drop-shadow(0 10px 14px rgba(0, 0, 0, .8)); }
#intro h1 { margin: 0 0 26px; font: 500 clamp(26px, 6.2vw, 50px)/1 var(--mono); letter-spacing: .3em; margin-right: -.3em; color: #f4efe2; }
#intro h1 span { color: var(--amber); font-size: .42em; vertical-align: middle; margin: 0 .5em 0 .2em; letter-spacing: .3em; }
#intro-sub { font-size: clamp(19px, 2.8vw, 24px); line-height: 1.5; font-style: italic; margin: 0 0 16px; white-space: pre-line; }
#intro-note { font: 400 12px/1.7 var(--mono); color: var(--teal); letter-spacing: .04em; margin: 0 0 34px; white-space: pre-line; opacity: .85; }
#btn-start { font: 500 13px/1 var(--mono); letter-spacing: .26em; text-transform: uppercase; color: var(--ink); background: var(--amber); padding: 18px 30px; border-radius: 2px; transition: transform .2s, box-shadow .3s, opacity .4s; box-shadow: 0 0 40px rgba(242, 201, 121, .25); }
#btn-start:hover { transform: translateY(-2px); box-shadow: 0 0 60px rgba(242, 201, 121, .5); }
#btn-start:disabled { opacity: .35; cursor: progress; }
.intro-foot { margin-top: 26px; display: flex; gap: 18px; align-items: center; font: 400 11px/1 var(--mono); letter-spacing: .14em; color: rgba(233, 228, 216, .55); }
.intro-foot button { color: var(--amber); letter-spacing: .14em; text-decoration: underline; text-underline-offset: 4px; }

/* ---------- world 1: mirrored garden ---------- */
.mirror { position: absolute; inset: 0; clip-path: inset(0 50% 0 0); }
.mirror.flip { transform: scaleX(-1); }
.mirror.true { transition: clip-path 2.2s cubic-bezier(.7, 0, .2, 1); z-index: 1; }
.unmirror .mirror.true { clip-path: inset(0 0 0 0); }
.seam { position: absolute; z-index: 2; top: 0; bottom: 0; left: 50%; width: 1px; background: linear-gradient(transparent, rgba(255, 255, 255, .22), transparent); }
.unmirror .seam { animation: seam 2.2s ease-out forwards; }
@keyframes seam { 0% { width: 3px; box-shadow: 0 0 60px 20px #fff; opacity: 1; } 100% { left: 100%; opacity: 0; } }
.scene canvas { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 3; cursor: crosshair; }

/* ---------- world 2: the hole behind the words ---------- */
.hole { position: absolute; z-index: 2; border-radius: 46% 54% 52% 48% / 58% 44% 56% 42%; background-size: cover; background-position: 50% 42%; box-shadow: inset 0 0 26px 10px rgba(0, 0, 0, .85), 0 0 34px 6px rgba(190, 235, 255, .55); cursor: pointer; animation: holeb 5s ease-in-out infinite; }
@keyframes holeb { 50% { border-radius: 52% 48% 46% 54% / 46% 56% 44% 58%; } }
.hole.locked { pointer-events: none; }

/* ---------- world 3: the sky has an edge ---------- */
.scene-sky { cursor: ns-resize; }
.hatch { position: absolute; border-radius: 50%; transform: translate(-50%, -50%); pointer-events: none; opacity: 0; transition: opacity 1s; }
.hatch.open { pointer-events: auto; opacity: 1; cursor: pointer; box-shadow: 0 0 0 2px rgba(255, 255, 255, .7), 0 0 50px 14px rgba(255, 255, 255, .55); animation: hatch 2s ease-in-out infinite; }
@keyframes hatch { 50% { box-shadow: 0 0 0 2px rgba(255, 255, 255, .9), 0 0 90px 30px rgba(255, 255, 255, .75); } }

/* ---------- world 4: the corridor ---------- */
.corridor-ui { position: absolute; left: 0; right: 0; top: 50%; z-index: 5; display: flex; flex-direction: column; align-items: center; gap: 14px; transform: translateY(40px); }
.corridor-ui .btn { background: rgba(5, 8, 11, .72); backdrop-filter: blur(6px); padding: 18px 34px; font-size: 13px; }
.corridor-ui .count { font: 400 11px/1 var(--mono); letter-spacing: .3em; color: rgba(242, 201, 121, .8); text-shadow: 0 1px 6px #000; }

/* ---------- world 5: attention ---------- */
.meter { position: absolute; top: 74px; left: 50%; width: min(360px, 64vw); transform: translateX(-50%); z-index: 5; font: 500 10px/1 var(--mono); letter-spacing: .34em; color: var(--amber); text-align: center; text-shadow: 0 1px 6px #000; }
.meter i { display: block; margin-top: 9px; height: 3px; background: rgba(242, 201, 121, .16); position: relative; overflow: hidden; }
.meter i b { position: absolute; inset: 0; background: var(--amber); transform-origin: 0 50%; box-shadow: 0 0 12px var(--amber); }
.ripple { position: absolute; z-index: 4; width: 10px; height: 10px; margin: -5px; border-radius: 50%; border: 1px solid var(--amber); pointer-events: none; animation: ripple .9s ease-out forwards; }
@keyframes ripple { to { transform: scale(14); opacity: 0; } }

/* ---------- outro ---------- */
#outro { position: fixed; left: 0; right: 0; top: 50dvh; bottom: 0; z-index: 60; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 0 26px 20px; color: #1c1a16; animation: outro 3s 3.2s ease both; }
@keyframes outro { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
#outro p { margin: 0 0 14px; max-width: 620px; }
#outro-1 { font-size: clamp(20px, 3vw, 28px); line-height: 1.35; }
#outro-2 { font-size: clamp(17px, 2.3vw, 21px); font-style: italic; color: #4c463b; }
#outro-stats { font: 400 11px/1 var(--mono); letter-spacing: .2em; color: #8a8273; margin-top: 8px !important; }
#btn-replay { font: 500 12px/1 var(--mono); letter-spacing: .22em; text-transform: uppercase; padding: 14px 22px; border: 1px solid #1c1a16; border-radius: 2px; margin: 8px 0 14px; }
#btn-replay:hover { background: #1c1a16; color: var(--paper); }
#outro-close { font: 400 11px/1.5 var(--mono); color: #8a8273; letter-spacing: .06em; }

@media (max-width: 560px) {
  #voice { padding: 13px 16px 15px; min-height: 80px; }
  #totem { width: 32px; left: 12px; }
  #fake-back { top: 34%; }
  #app.shrunk { transform: translateY(-23dvh) scale(.4); }
  #outro { top: 46dvh; }
}
@media (prefers-reduced-motion: reduce) { #grain { animation: none; } }
