:root {
  --bg: #04121a;
  --surface: #0a2230;
  --ink: #eaf6f4;
  --ink-soft: #a6c4c4;
  --line: #2b5a63;
  --accent: #f2c55c;
  --accent-ink: #1a1305;
  --teal: #3fd6c8;
  --gold: #f2c55c;
  --font-display: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --dh: 11.5rem; /* space reserved for the dialogue box so it never covers the characters */
  --ah: min(max(calc(100vh - var(--dh) - 3.2rem), 15rem), 150vw);
}

html, body { height: 100%; overflow: hidden; }
body { display: block; background: var(--bg); color: var(--ink); font-family: var(--font-display); font-size: 1rem; }
p { max-width: none; }
button { cursor: pointer; }

#motes { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 5; pointer-events: none; }

.screen { position: fixed; inset: 0; display: none; }
.screen.show { display: block; }

/* ---------- Title ---------- */
.title-bg { position: absolute; inset: 0; background: url(../assets/bg/cave.webp) center/cover; filter: saturate(1.1); animation: drift 40s ease-in-out infinite alternate; }
.title-bg::after { content: ""; position: absolute; inset: 0; background: radial-gradient(ellipse at 30% 50%, rgba(4,18,26,.55), rgba(4,18,26,.92) 75%), linear-gradient(180deg, rgba(4,18,26,.2), rgba(4,18,26,.8)); }
@keyframes drift { from { transform: scale(1.05) translateX(-1%); } to { transform: scale(1.14) translateX(1%); } }
.title-box { position: relative; z-index: 2; height: 100%; max-width: 40rem; padding: clamp(1.2rem, 5vw, 4rem); display: flex; flex-direction: column; justify-content: center; gap: .6rem; overflow-y: auto; }
.eyebrow { margin: 0; letter-spacing: .35em; text-transform: uppercase; font-size: .8rem; color: var(--teal); }
.title-box h1 { margin: 0; font-size: clamp(2.6rem, 9vw, 5rem); letter-spacing: .04em; text-transform: uppercase; background: linear-gradient(180deg, #fff7d6, var(--gold) 55%, #b98a2b); -webkit-background-clip: text; background-clip: text; color: transparent; text-shadow: 0 0 40px rgba(242,197,92,.25); line-height: 1; }
.subtitle { margin: 0; font-size: clamp(1.2rem, 4vw, 1.8rem); font-style: italic; color: var(--teal); letter-spacing: .1em; }
.pitch { margin: .8rem 0 1rem; color: #cfe6e4; line-height: 1.6; max-width: 34rem; }
.menu-list { display: grid; gap: .55rem; max-width: 20rem; }
.fine { margin: .3rem 0 0; font-size: .8rem; color: var(--ink-soft); max-width: 34rem; }

.btn { background: rgba(10,34,48,.82); color: var(--ink); border: 1px solid var(--line); padding: .75rem 1.2rem; border-radius: 4px; font-size: 1.02rem; letter-spacing: .06em; text-align: left; transition: transform .15s, border-color .15s, background .15s; position: relative; }
.btn:hover, .btn:focus-visible { border-color: var(--gold); background: rgba(24,62,74,.95); transform: translateX(4px); }
.btn.primary { background: linear-gradient(90deg, #f2c55c, #d9a43a); color: #1a1305; border-color: #f2c55c; font-weight: 700; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn[hidden] { display: none; }

/* ---------- Stage ---------- */
#stage { position: absolute; inset: 0; overflow: hidden; background: #000; }
.bg { position: absolute; inset: -2%; background-size: cover; background-position: center; opacity: 0; transition: opacity 1.2s ease; animation: drift 45s ease-in-out infinite alternate; }
.bg.on { opacity: 1; }
#stage::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 45%, transparent 45%, rgba(0,8,14,.65)); z-index: 3; }
#stage.shake { animation: shake .6s; }
@keyframes shake { 10%,50%,90% { transform: translate(-8px, 3px); } 30%,70% { transform: translate(8px, -4px); } }

#actors { position: absolute; inset: 0; z-index: 2; }
.actor { position: absolute; bottom: calc(var(--dh) - .5rem); transform: translateX(-50%); transition: left .6s ease, opacity .5s, filter .4s, transform .5s; opacity: 0; pointer-events: none; }
.has-speaker .actor:not(.speaking) { filter: brightness(.55) saturate(.8); }
.actor.in { opacity: 1; }
.actor.speaking { filter: brightness(1.05) drop-shadow(0 0 22px var(--glow, #3fd6c8)); transform: translateX(-50%) translateY(-1.2vh); z-index: 2; }
.actor img { display: block; height: var(--ah); width: auto; max-width: none; }
.pos-l2 { left: 12%; } .pos-l { left: 27%; } .pos-c { left: 50%; } .pos-r { left: 73%; } .pos-r2 { left: 88%; }
.actors-many .actor img { height: calc(var(--ah) * .86); }

.sigil { width: calc(var(--ah) * .34); height: calc(var(--ah) * .74); border-radius: 999px 999px 18px 18px; background: linear-gradient(180deg, color-mix(in srgb, var(--glow) 45%, #06151d), #06151d 85%); border: 2px solid color-mix(in srgb, var(--glow) 70%, #fff 0%); box-shadow: inset 0 0 40px color-mix(in srgb, var(--glow) 40%, transparent), 0 0 30px color-mix(in srgb, var(--glow) 35%, transparent); display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding-top: 18%; gap: 6%; position: relative; overflow: hidden; }
.sigil::before { content: ""; position: absolute; inset: 8px; border: 1px solid color-mix(in srgb, var(--glow) 55%, transparent); border-radius: 999px 999px 10px 10px; }
.sigil svg { width: 52%; fill: var(--glow); filter: drop-shadow(0 0 12px var(--glow)); animation: pulse 3.5s ease-in-out infinite; }
.sigil .sname { font-size: clamp(.7rem, 1.6vw, 1.1rem); letter-spacing: .12em; text-transform: uppercase; color: #fff; text-align: center; padding: 0 8%; text-shadow: 0 0 8px var(--glow); }
@keyframes pulse { 50% { transform: scale(1.1); opacity: .85; } }

.slime { width: calc(var(--ah) * .34); height: calc(var(--ah) * .26); margin-bottom: 0; position: relative; border-radius: 52% 52% 46% 46% / 62% 62% 38% 38%; background: radial-gradient(circle at 35% 28%, #d9faff 0 8%, #7fe3f2 22%, #2fa7cf 62%, #1b6f9c); box-shadow: 0 0 40px rgba(63,214,200,.5), inset -12px -14px 30px rgba(8,50,90,.5); animation: squish 3s ease-in-out infinite; transform-origin: bottom; }
.slime::before, .slime::after { content: ""; position: absolute; top: 38%; width: 7%; height: 11%; border-radius: 50%; background: #0b2a40; }
.slime::before { left: 32%; } .slime::after { right: 32%; }
@keyframes squish { 50% { transform: scale(1.06, .93); } }

#fx { position: absolute; inset: 0; z-index: 4; pointer-events: none; }
.flash { position: absolute; inset: 0; background: #fff; animation: flash 1s ease-out forwards; }
.flash.teal { background: radial-gradient(circle, rgba(63,214,200,.9), transparent 70%); animation-duration: 1.6s; }
.flash.dark { background: radial-gradient(circle, transparent 20%, rgba(10,0,20,.92)); animation-duration: 2s; }
@keyframes flash { from { opacity: .95; } to { opacity: 0; } }

/* ---------- HUD ---------- */
.hud { position: absolute; top: 0; left: 0; right: 0; z-index: 8; display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; justify-content: space-between; padding: .6rem .8rem; background: linear-gradient(180deg, rgba(2,12,18,.85), transparent); }
.hud-chapter { font-size: .85rem; letter-spacing: .15em; text-transform: uppercase; color: var(--gold); }
.hud-stats { display: flex; gap: .5rem; }
.stat { display: flex; align-items: center; gap: .35rem; background: rgba(4,18,26,.7); border: 1px solid color-mix(in srgb, var(--c) 55%, transparent); padding: .15rem .55rem; border-radius: 999px; font-size: .85rem; transition: transform .3s, box-shadow .3s; }
.stat i { width: .7rem; height: .7rem; background: var(--c); transform: rotate(45deg); box-shadow: 0 0 8px var(--c); }
.stat.pop { transform: scale(1.25); box-shadow: 0 0 18px var(--c); }
.hud-btns { display: flex; gap: .35rem; }
.chip { background: rgba(4,18,26,.75); color: var(--ink); border: 1px solid var(--line); border-radius: 999px; padding: .25rem .8rem; font-size: .85rem; }
.chip:hover, .chip:focus-visible { border-color: var(--gold); color: var(--gold); }
.chip[aria-pressed="true"] { background: var(--gold); color: #1a1305; border-color: var(--gold); }

.gain-float { position: absolute; z-index: 9; left: 50%; top: 30%; font-size: 1.6rem; font-weight: 700; text-shadow: 0 0 14px currentColor; animation: floatup 1.8s ease-out forwards; pointer-events: none; transform: translateX(-50%); }
@keyframes floatup { from { opacity: 0; transform: translate(-50%, 20px); } 15% { opacity: 1; } to { opacity: 0; transform: translate(-50%, -60px); } }

/* ---------- Dialogue ---------- */
.dialog { position: absolute; z-index: 7; left: 50%; bottom: 2vh; transform: translateX(-50%); width: min(60rem, 96vw); min-height: 9.5rem; padding: 1.5rem 1.6rem 1.1rem; background: linear-gradient(180deg, rgba(6,28,40,.82), rgba(2,12,18,.88)); backdrop-filter: blur(4px); border: 1px solid rgba(242,197,92,.55); border-radius: 6px; box-shadow: 0 10px 40px rgba(0,0,0,.6), inset 0 0 40px rgba(63,214,200,.06); cursor: pointer; }
.dialog::before { content: ""; position: absolute; inset: 4px; border: 1px solid rgba(242,197,92,.18); border-radius: 3px; pointer-events: none; }
.plate { position: absolute; top: -1.1rem; left: 1.4rem; padding: .25rem 1.2rem; background: linear-gradient(90deg, #0d3b49, #0a2230); border: 1px solid var(--gold); color: var(--gold); letter-spacing: .14em; text-transform: uppercase; font-size: .9rem; clip-path: polygon(0 0, 100% 0, calc(100% - 12px) 100%, 0 100%); }
.plate:empty { display: none; }
.line { margin: 0; font-size: clamp(1.02rem, 2.4vw, 1.3rem); line-height: 1.65; min-height: 5rem; }
.line.narr { font-style: italic; color: #cfe9e6; }
.line.sage { color: #9ae6f2; font-style: italic; }
.more { position: absolute; right: 1.2rem; bottom: .5rem; width: .7rem; height: .7rem; border-right: 2px solid var(--gold); border-bottom: 2px solid var(--gold); transform: rotate(45deg); opacity: 0; }
.more.on { opacity: 1; animation: bob 1s ease-in-out infinite; }
@keyframes bob { 50% { transform: rotate(45deg) translate(3px, 3px); } }

/* ---------- Choices ---------- */
.choices { position: absolute; z-index: 9; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .7rem; padding: 4.5rem 1rem 3rem; background: rgba(2,10,16,.55); backdrop-filter: blur(3px); overflow-y: auto; }
.choices[hidden] { display: none; }
.choices .prompt { margin: 0 0 .5rem; font-size: clamp(1.1rem, 3vw, 1.6rem); color: var(--gold); text-align: center; letter-spacing: .06em; max-width: 44rem; }
.choice { width: min(44rem, 94vw); text-align: left; padding: .95rem 1.2rem; background: linear-gradient(90deg, rgba(8,40,54,.95), rgba(6,26,38,.92)); border: 1px solid var(--line); border-left: 4px solid var(--c, var(--teal)); border-radius: 4px; font-size: 1.08rem; display: flex; gap: .8rem; justify-content: space-between; align-items: center; transition: transform .15s, border-color .15s; animation: rise .5s both; }
.choice:nth-child(3) { animation-delay: .08s; } .choice:nth-child(4) { animation-delay: .16s; } .choice:nth-child(5) { animation-delay: .24s; } .choice:nth-child(6) { animation-delay: .3s; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
.choice:hover:not(:disabled), .choice:focus-visible { transform: translateX(6px); border-color: var(--gold); }
.choice .tag { flex: none; font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; color: var(--c, var(--teal)); border: 1px solid currentColor; padding: .1rem .5rem; border-radius: 999px; }
.choice:disabled { opacity: .5; cursor: not-allowed; border-left-color: #555; }

.banner { position: absolute; z-index: 11; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; background: radial-gradient(circle, rgba(4,18,26,.7), rgba(2,8,12,.96)); animation: fadein .8s; padding: 1rem; cursor: pointer; }
.banner[hidden] { display: none; }
@keyframes fadein { from { opacity: 0; } }
.banner .sub { letter-spacing: .5em; text-transform: uppercase; color: var(--teal); font-size: .9rem; }
.banner h2 { margin: .5rem 0; font-size: clamp(2rem, 7vw, 4rem); color: var(--gold); text-shadow: 0 0 40px rgba(242,197,92,.35); }
.banner .rule { width: min(22rem, 70vw); height: 1px; background: linear-gradient(90deg, transparent, var(--gold), transparent); margin: .8rem 0; }
.banner.check .result { font-size: 1.4rem; letter-spacing: .2em; text-transform: uppercase; }
.banner.check .ok { color: #8cf0a8; } .banner.check .no { color: #ff8f8f; }
.banner.check { background: rgba(2,10,16,.8); }
.banner.check h2 { font-size: clamp(1.4rem, 5vw, 2.4rem); }

/* ---------- Ending ---------- */
.ending { position: absolute; z-index: 12; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 1rem; background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--c) 28%, #04121a), #020a0f 75%); animation: fadein 1.5s; overflow-y: auto; }
.ending[hidden] { display: none; }
.ending .inner { max-width: 38rem; display: grid; gap: .8rem; }
.ending .k { letter-spacing: .5em; text-transform: uppercase; color: var(--ink-soft); font-size: .8rem; }
.ending h2 { margin: 0; font-size: clamp(2.2rem, 7vw, 4rem); color: var(--c); text-shadow: 0 0 40px var(--c); }
.ending p { margin: 0; line-height: 1.7; font-size: 1.1rem; }
.ending .tally { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; }
.ending .btns { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; margin-top: .6rem; }
.ending .btn { text-align: center; }

/* ---------- Overlays ---------- */
.overlay { position: fixed; inset: 0; z-index: 30; background: rgba(1,8,12,.86); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; padding: .8rem; }
.overlay[hidden] { display: none; }
.panel { width: min(70rem, 100%); max-height: 100%; display: flex; flex-direction: column; background: linear-gradient(180deg, #08202c, #04121a); border: 1px solid var(--gold); border-radius: 6px; box-shadow: 0 20px 80px #000; }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: .8rem 1.2rem; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font-size: 1.4rem; color: var(--gold); letter-spacing: .1em; text-transform: uppercase; }
.panel-body { padding: 1rem 1.2rem 1.4rem; overflow-y: auto; }

.codex { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; }
@media (min-width: 52rem) { .codex { grid-template-columns: 1fr 22rem; } }
.codex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(5.6rem, 1fr)); gap: .6rem; align-content: start; }
.cc { background: #06161e; border: 1px solid var(--line); border-radius: 6px; padding: 0; overflow: hidden; text-align: center; color: var(--ink); aspect-ratio: 3/4; display: flex; flex-direction: column; position: relative; }
.cc:hover:not(.locked), .cc:focus-visible, .cc.sel { border-color: var(--c); box-shadow: 0 0 16px color-mix(in srgb, var(--c) 50%, transparent); }
.cc .art { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; background: radial-gradient(circle at 50% 30%, color-mix(in srgb, var(--c) 30%, #06161e), #06161e 80%); overflow: hidden; }
.cc .art img { height: 130%; object-fit: cover; object-position: top; margin-top: 18%; }
.cc .art svg { width: 44%; fill: var(--c); filter: drop-shadow(0 0 8px var(--c)); }
.cc .nm { font-size: .72rem; padding: .3rem .2rem; letter-spacing: .04em; background: rgba(0,0,0,.45); }
.cc.locked { opacity: .5; }
.cc.locked .art svg { fill: #345; filter: none; }
.codex-detail { background: #06161e; border: 1px solid var(--line); border-radius: 6px; padding: 1rem; align-self: start; position: sticky; top: 0; }
.codex-detail h3 { margin: 0; color: var(--c); font-size: 1.5rem; }
.codex-detail .t { color: var(--gold); font-style: italic; margin: .2rem 0 .8rem; }
.codex-detail img { width: 100%; max-height: 22rem; object-fit: contain; filter: drop-shadow(0 0 18px var(--c)); }
.codex-detail .sig { width: 5rem; fill: var(--c); display: block; margin: 0 auto 1rem; filter: drop-shadow(0 0 12px var(--c)); }
.codex-detail p { line-height: 1.65; margin: 0; }

.list-btn { display: flex; width: 100%; justify-content: space-between; gap: 1rem; align-items: center; margin-bottom: .6rem; }
.list-btn small { color: var(--ink-soft); }
.list-btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.log-entry { margin: 0 0 1rem; line-height: 1.55; }
.log-entry b { color: var(--gold); display: block; letter-spacing: .1em; text-transform: uppercase; font-size: .8rem; }
.end-card { border: 1px solid var(--c); border-left-width: 6px; padding: .9rem 1rem; margin-bottom: .8rem; border-radius: 4px; background: #06161e; }
.end-card h3 { margin: 0 0 .3rem; color: var(--c); }
.end-card p { margin: 0; color: var(--ink-soft); }
.end-card.locked { border-color: var(--line); opacity: .7; }
.end-card.locked h3 { color: var(--ink-soft); }

@media (max-width: 40rem) {
  :root { --dh: 12.5rem; --ah: min(max(calc(100vh - var(--dh) - 4.5rem), 13rem), 130vw); }
  .dialog { min-height: 8.5rem; padding: 1.3rem 1rem .9rem; bottom: 1vh; }
  .line { min-height: 4.5rem; }
  .hud { padding: .4rem .5rem; gap: .3rem; }
  .hud-chapter { font-size: .7rem; width: 100%; }
  .stat { font-size: .75rem; padding: .1rem .4rem; }
  .chip { padding: .2rem .55rem; font-size: .78rem; }
  .pos-l2 { left: 14%; } .pos-l { left: 28%; } .pos-r { left: 72%; } .pos-r2 { left: 86%; }
}
