:root {
  --ink: #0d1520;
  --ink-2: #16222f;
  --paper: #eef3f8;
  --muted: #9fb2c6;
  --ice: #8fd3ff;
  --ember: #ff7a2f;
  --blood: #d8364a;
  --ok: #6fdc9b;
  --octo: #b25bd6;
  --glass: rgba(10, 18, 28, 0.82);
  --line: rgba(160, 200, 235, 0.22);
  --type: 'Special Elite', 'Courier New', monospace;
  --sans: 'Inter', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #cfdcea; color: var(--paper); font-family: var(--sans); }
canvas#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; transition: filter 3.5s ease-out; }
button { font: inherit; color: inherit; cursor: pointer; }
kbd { font-family: var(--sans); font-size: 0.75em; padding: 1px 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; background: rgba(255,255,255,0.06); }
[hidden] { display: none !important; }

/* ---------------------------------------------------------- eyelids */
#lids { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.lid { position: absolute; left: -10%; width: 120%; height: 52%; background: #000; transition: transform 1.2s; }
.lid.top { top: 0; border-radius: 0 0 50% 50% / 0 0 30% 30%; transform: translateY(-110%); }
.lid.bottom { bottom: 0; border-radius: 50% 50% 0 0 / 30% 30% 0 0; transform: translateY(110%); }
body.waking #lids { background: #000; }
body.waking .lid.top { transform: translateY(0); transition: none; }
body.waking .lid.bottom { transform: translateY(0); transition: none; }
body.waking canvas#c, body.opening canvas#c { filter: blur(14px) brightness(1.3); }
body.opening canvas#c { filter: blur(0) brightness(1); }
body.opening .lid.top { animation: lidTop 3.6s ease-in-out forwards; }
body.opening .lid.bottom { animation: lidBottom 3.6s ease-in-out forwards; }
@keyframes lidTop { 0% { transform: translateY(0); } 30% { transform: translateY(-55%); } 42% { transform: translateY(-5%); } 55% { transform: translateY(-50%); } 100% { transform: translateY(-110%); } }
@keyframes lidBottom { 0% { transform: translateY(0); } 30% { transform: translateY(55%); } 42% { transform: translateY(5%); } 55% { transform: translateY(50%); } 100% { transform: translateY(110%); } }

#vignette { position: fixed; inset: 0; pointer-events: none; z-index: 4; background: radial-gradient(ellipse at center, transparent 55%, rgba(10, 25, 45, 0.45) 100%); transition: background 1s; }
#vignette.psychic { background: radial-gradient(ellipse at center, rgba(120, 40, 160, 0.05) 30%, rgba(110, 20, 140, 0.7) 100%); animation: throb 0.9s ease-in-out infinite alternate; }
@keyframes throb { to { opacity: 0.6; } }
#flash { position: fixed; inset: 0; pointer-events: none; z-index: 6; opacity: 0; }

#narration { position: fixed; inset: 0; display: grid; place-items: center; z-index: 7; pointer-events: none; font-family: var(--type); font-size: clamp(22px, 4vw, 40px); color: #dfe8f2; opacity: 0; transition: opacity 0.6s; text-align: center; padding: 0 16px; }
#narration.show { opacity: 1; }

/* ---------------------------------------------------------- screens */
.screen { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; overflow-y: auto; }
#title { background: linear-gradient(180deg, rgba(8, 16, 26, 0.15), rgba(8, 16, 26, 0.75)); }
#ending { background: rgba(5, 10, 16, 0.86); backdrop-filter: blur(4px); }
.card { max-width: 620px; width: 100%; text-align: center; }
.kicker { font-size: 13px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); margin: 0 0 12px; }
h1 { font-family: var(--type); font-weight: 400; font-size: clamp(42px, 9vw, 86px); line-height: 0.95; margin: 0; color: #fff; text-shadow: 0 2px 30px rgba(0, 20, 40, 0.6); text-transform: uppercase; }
.quote { font-family: var(--type); font-size: clamp(16px, 2.4vw, 20px); color: #e9f1f8; margin: 22px auto 30px; max-width: 30ch; }
.hint, #wakecount { font-size: 13px; color: var(--muted); margin: 16px 0 0; }
#wakecount { font-family: var(--type); color: #c6b8e0; }
#start, .actions button { background: var(--paper); color: var(--ink); border: 0; border-radius: 999px; padding: 14px 34px; font-weight: 700; font-size: 17px; letter-spacing: 0.02em; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35); transition: transform 0.15s; }
#start:hover, .actions button:hover { transform: translateY(-2px); }
.actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 26px; }
.actions .ghost { background: transparent; color: var(--paper); border: 1px solid var(--line); box-shadow: none; }
#ending h2 { font-family: var(--type); font-weight: 400; font-size: clamp(30px, 6vw, 52px); margin: 0 0 18px; }
#ending .text { text-align: left; font-size: 16px; line-height: 1.6; color: #dfe8f2; }
#ending .who, #ending .standing, #ending .secret { font-size: 15px; color: var(--muted); margin: 10px 0 0; }
#ending .who b, #ending .standing b, #ending .secret b { color: #fff; }
code { font-family: ui-monospace, monospace; font-size: 0.9em; background: rgba(255,255,255,0.08); padding: 1px 6px; border-radius: 4px; }

/* ---------------------------------------------------------- HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#crosshair { position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px 0 0 -3px; border-radius: 50%; background: rgba(255,255,255,0.85); box-shadow: 0 0 0 2px rgba(0,0,0,0.25); }
@media (pointer: coarse) { #crosshair { display: none; } }
#prompt { position: absolute; left: 50%; top: calc(50% + 28px); transform: translateX(-50%); background: var(--glass); padding: 7px 14px; border-radius: 8px; font-size: 14px; white-space: nowrap; }
#status { position: absolute; top: max(16px, env(safe-area-inset-top)); left: 16px; background: var(--glass); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; min-width: 170px; }
#status .name { font-family: var(--type); font-size: 17px; letter-spacing: 0.04em; }
#status .hp { display: flex; gap: 3px; margin: 7px 0 6px; flex-wrap: wrap; max-width: 200px; }
#status .hp i { width: 11px; height: 11px; border-radius: 3px; background: var(--blood); }
#status .hp i.lost { background: rgba(255,255,255,0.12); }
#status .factions { font-size: 13px; color: var(--muted); }
#buttons { position: absolute; top: max(16px, env(safe-area-inset-top)); right: 16px; display: flex; gap: 8px; pointer-events: auto; flex-wrap: wrap; justify-content: flex-end; }
#buttons button { background: var(--glass); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; font-size: 14px; }
@media (pointer: coarse) { #buttons kbd { display: none; } }
#toasts { position: absolute; left: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--glass); border: 1px solid var(--line); border-left: 3px solid var(--ice); border-radius: 10px; padding: 10px 14px; font-size: 14px; line-height: 1.45; animation: toastIn 0.35s ease-out; transition: opacity 0.6s, transform 0.6s; }
.toast.out { opacity: 0; transform: translateX(-12px); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }
body:has(#dialogue:not([hidden])) #toasts { bottom: auto; top: 140px; }

#memory { position: fixed; left: 50%; top: 14%; transform: translateX(-50%); z-index: 25; width: min(560px, calc(100vw - 32px)); text-align: center; pointer-events: none; background: rgba(22, 10, 38, 0.9); border: 1px solid rgba(198, 184, 224, 0.45); border-radius: 16px; padding: 16px 20px 18px; box-shadow: 0 20px 60px rgba(20, 0, 40, 0.5); }
#memory span { font-size: 12px; letter-spacing: 0.18em; text-transform: uppercase; color: #c6b8e0; }
#memory p { font-family: var(--type); font-size: clamp(17px, 2.4vw, 21px); line-height: 1.5; color: #fff; margin: 8px 0 0; }
#memory.show { animation: memory 7.5s ease-in-out forwards; }
@keyframes memory { 0% { opacity: 0; filter: blur(8px); } 12% { opacity: 1; filter: blur(0); } 82% { opacity: 1; } 100% { opacity: 0; filter: blur(6px); } }

/* ---------------------------------------------------------- panels */
.panel { position: fixed; z-index: 18; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(720px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow-y: auto; background: rgba(9, 16, 25, 0.94); border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px 22px; box-shadow: 0 30px 80px rgba(0,0,0,0.5); }
.panel header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel h2 { font-family: var(--type); font-weight: 400; font-size: 26px; margin: 0; }
.panel .close { background: none; border: 1px solid var(--line); border-radius: 8px; width: 34px; height: 34px; }
.panel .sub { color: var(--muted); font-size: 14px; margin: 6px 0 14px; }
#inventory .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.item { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: left; background: rgba(255,255,255,0.04); border: 1px solid var(--line); border-radius: 12px; padding: 12px; transition: background 0.15s, border-color 0.15s; }
.item:hover { background: rgba(143, 211, 255, 0.08); border-color: rgba(143, 211, 255, 0.45); }
.item.identity { border-color: rgba(198, 184, 224, 0.5); }
.item .icon { font-size: 28px; }
.item .nm { font-weight: 600; font-size: 14px; }
.item .cat { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; }
#detail { display: flex; gap: 14px; margin-top: 14px; padding: 14px; border-radius: 12px; background: rgba(143, 211, 255, 0.06); border: 1px solid rgba(143, 211, 255, 0.3); }
#detail .icon { font-size: 40px; }
#detail h3 { margin: 0 0 6px; font-size: 16px; }
#detail p { margin: 0; line-height: 1.5; color: #dce6f0; font-size: 14.5px; }

#sheet { font-family: var(--type); background: #f1ece0; color: #1d1a16; }
#sheet h2 { text-transform: uppercase; letter-spacing: 0.04em; }
#sheet .close { border-color: rgba(0,0,0,0.25); color: #1d1a16; }
#sheet h4 { margin: 18px 0 8px; font-weight: 400; font-size: 17px; border-bottom: 2px solid #1d1a16; padding-bottom: 3px; text-align: center; letter-spacing: 0.06em; }
#sheet label { display: block; font-size: 14px; }
#sheet label span { display: block; border-bottom: 1px solid rgba(0,0,0,0.35); min-height: 24px; font-size: 16px; padding: 2px 0; }
#sheet .row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 18px; margin-top: 10px; }
#sheet .wide { margin-top: 10px; }
#sheet .attrs, #sheet .skills { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px 18px; }
#sheet .attrs div, #sheet .skills div, #sheet .equip div, #sheet .factions div { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; border-bottom: 1px dotted rgba(0,0,0,0.35); padding: 3px 0; font-size: 14.5px; }
#sheet .equip em { font-style: normal; text-align: right; font-size: 13px; }
#sheet .factions div { align-items: center; }
#sheet .factions span { width: 80px; }
.meter { flex: 1; height: 10px; border: 1px solid #1d1a16; border-radius: 2px; overflow: hidden; }
.meter i { display: block; height: 100%; background: #1d1a16; }
.meter i.neg { background: var(--blood); }
#sheet [data-f=desc] { font-size: 14.5px; line-height: 1.5; }
#sheet [data-f=desc] ul { padding-left: 18px; margin: 8px 0; }
#sheet [data-f=desc] li { margin-bottom: 6px; }
#sheet .traits { font-size: 13px; }
#sheet .faint { color: #6c655a; }
#sheet .seed { font-size: 12px; color: #6c655a; }
#sheet code { background: rgba(0,0,0,0.07); }
@media (max-width: 520px) {
  #sheet .attrs, #sheet .skills { grid-template-columns: repeat(2, 1fr); }
  #sheet .row.two { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------- dialogue */
#dialogue { position: fixed; z-index: 14; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(760px, calc(100vw - 32px)); max-height: min(58dvh, 560px); display: flex; flex-direction: column; background: rgba(8, 14, 22, 0.84); border: 1px solid var(--line); border-radius: 16px; padding: 16px 18px; box-shadow: 0 20px 60px rgba(0,0,0,0.45); backdrop-filter: blur(6px); }
#dialogue .speaker { font-family: var(--type); color: var(--ember); font-size: 15px; letter-spacing: 0.08em; text-transform: uppercase; min-height: 4px; }
#dialogue .text { overflow-y: auto; min-height: 3em; font-size: 15.5px; line-height: 1.55; color: #e6eef6; padding-right: 4px; }
#dialogue .text p { margin: 8px 0; white-space: pre-line; opacity: 0; animation: para 0.5s ease-out forwards; }
@keyframes para { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
#dialogue.shout .text p:nth-child(2) { font-weight: 700; }
#dialogue.shout { animation: shout 0.5s ease-out; border-color: var(--octo); }
@keyframes shout { 0%, 100% { transform: translateX(-50%); } 20% { transform: translate(calc(-50% - 8px), 2px); } 40% { transform: translate(calc(-50% + 7px), -2px); } 60% { transform: translate(calc(-50% - 5px), 1px); } 80% { transform: translate(calc(-50% + 3px), 0); } }
#dialogue .choices { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; overflow-y: auto; flex: none; max-height: 55%; }
#dialogue .choices button { display: flex; align-items: center; gap: 10px; text-align: left; width: 100%; background: rgba(255,255,255,0.05); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: 14.5px; transition: background 0.12s, border-color 0.12s; }
#dialogue .choices button:hover:not(:disabled) { background: rgba(143, 211, 255, 0.1); border-color: rgba(143, 211, 255, 0.5); }
#dialogue .choices button:disabled { opacity: 0.5; cursor: default; }
#dialogue .num { font-family: var(--type); color: var(--muted); width: 16px; flex: none; }
#dialogue .lbl { flex: 1; }
#dialogue .tag { flex: none; font-size: 11.5px; padding: 3px 8px; border-radius: 999px; background: rgba(255, 122, 47, 0.16); color: #ffc29e; letter-spacing: 0.03em; }
#dialogue .tag.roll { background: rgba(143, 211, 255, 0.14); color: #bfe6ff; }

#dice { position: fixed; z-index: 16; left: 50%; top: 32%; transform: translate(-50%, -50%); text-align: center; background: rgba(8, 14, 22, 0.94); border: 1px solid var(--line); border-radius: 18px; padding: 18px 26px; width: min(460px, calc(100vw - 32px)); }
#dice .versus { color: var(--muted); font-size: 14px; margin: 0 0 8px; }
#dice .faces { font-size: 64px; line-height: 1; letter-spacing: 6px; }
#dice .outcome { font-family: var(--type); font-size: 17px; margin: 10px 0 0; min-height: 22px; }
#dice .outcome.ok { color: var(--ok); }
#dice .outcome.bad { color: var(--blood); }

@media (max-width: 560px) {
  #buttons .word { display: none; }
  #buttons button { padding: 9px 11px; font-size: 17px; }
  #status { min-width: 0; max-width: calc(100vw - 32px - 150px); padding: 8px 12px; }
  #status .name { font-size: 15px; }
  #dialogue { max-height: 68dvh; padding: 14px; }
  #dialogue .text { min-height: 5.5em; }
  #dialogue .choices { max-height: 50%; }
}

#dice .luck { display: flex; gap: 8px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
#dice .luck button { border-radius: 999px; padding: 9px 16px; font-weight: 600; font-size: 14px; border: 1px solid var(--line); background: rgba(255,255,255,0.06); }
#dice .luck .push { background: #2f6b45; border-color: #4fae74; }

/* ---------------------------------------------------------- chapter two */
body.ch2 { font-family: var(--sans); }
body.ch2 canvas#c { image-rendering: auto; }
#c2-fade { position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; transition: opacity 0.55s; z-index: 30; }
#c2-fade.on { opacity: 1; }
#c2-start, #c2-pause, #c2-end { background: rgba(5, 10, 16, 0.82); }
#c2-start h1 { font-family: 'Luckiest Guy', var(--type); letter-spacing: 0.04em; }
#c2-pause h2, #c2-end h2 { font-family: 'Luckiest Guy', var(--type); font-weight: 400; font-size: clamp(30px, 6vw, 50px); margin: 0 0 12px; }
#c2-end .text { text-align: left; line-height: 1.6; color: #dfe8f2; }
#c2-hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; font-family: 'Luckiest Guy', var(--sans); }
.c2-left { position: absolute; top: max(14px, env(safe-area-inset-top)); left: 16px; display: flex; gap: 10px; align-items: center; }
#c2-badge { width: 62px; height: 62px; filter: drop-shadow(0 3px 6px rgba(0,0,0,0.5)); }
#c2-pie { width: 58px; height: 58px; filter: drop-shadow(0 3px 6px rgba(0,0,0,0.5)); }
.c2-right { position: absolute; top: max(14px, env(safe-area-inset-top)); right: 16px; display: flex; gap: 12px; align-items: center; font-size: 30px; color: #fff; text-shadow: 3px 3px 0 #000; }
#c2-pause-btn { pointer-events: auto; font-size: 18px; width: 40px; height: 40px; border-radius: 10px; border: 2px solid #fff; background: rgba(0,0,0,0.4); color: #fff; }
#c2-prompt { position: absolute; left: 50%; bottom: 120px; transform: translateX(-50%); background: rgba(0,0,0,0.65); color: #fff; padding: 8px 16px; border-radius: 10px; font-family: var(--sans); font-size: 15px; }
#c2-toasts { position: absolute; left: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; max-width: min(440px, calc(100vw - 32px)); font-family: var(--sans); }
#c2-shout { position: absolute; left: 50%; top: 30%; transform: translateX(-50%); font-size: clamp(28px, 6vw, 60px); color: #ffe066; text-shadow: 4px 4px 0 #7b2d5b, -2px -2px 0 #000; white-space: nowrap; text-align: center; }
#c2-shout.go { animation: c2pop 2.6s ease-out forwards; }
@keyframes c2pop { 0% { transform: translateX(-50%) scale(0.3); opacity: 0; } 12% { transform: translateX(-50%) scale(1.1); opacity: 1; } 20% { transform: translateX(-50%) scale(1); } 85% { opacity: 1; } 100% { opacity: 0; } }
#c2-banner { position: absolute; left: 50%; top: 18%; transform: translateX(-50%); text-align: center; color: #fff; text-shadow: 3px 3px 0 #000; animation: toastIn 0.5s; }
#c2-banner h3 { font-size: clamp(26px, 5vw, 46px); margin: 0 0 10px; font-weight: 400; color: #ffe066; }
#c2-banner p { margin: 4px 0; font-size: 20px; }
#c2-text { position: fixed; z-index: 14; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(720px, calc(100vw - 32px)); background: rgba(10, 14, 30, 0.92); border: 3px solid #e8e2d0; border-radius: 14px; padding: 14px 18px; color: #fff; box-shadow: 0 10px 40px rgba(0,0,0,0.5); cursor: pointer; }
#c2-text .who { font-family: 'Luckiest Guy', var(--type); color: #ffe066; font-size: 18px; letter-spacing: 0.04em; }
#c2-text .body { font-size: 17px; line-height: 1.5; margin-top: 4px; white-space: pre-line; }
#c2-text .body:empty { display: none; }
#c2-text .opts { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
#c2-text .opts button { text-align: left; background: rgba(255,255,255,0.06); border: 2px solid transparent; border-radius: 10px; padding: 9px 12px; font-size: 15.5px; line-height: 1.4; }
#c2-text .opts button.sel, #c2-text .opts button:hover { border-color: #ffe066; background: rgba(255, 224, 102, 0.12); }
#c2-text .more { text-align: right; color: #ffe066; animation: throb 0.7s infinite alternate; }
#c2-touch { position: fixed; inset: auto 0 0 0; height: 200px; z-index: 12; pointer-events: none; }
#c2-stick { position: absolute; left: 24px; bottom: 28px; width: 120px; height: 120px; border-radius: 50%; background: rgba(255,255,255,0.12); border: 2px solid rgba(255,255,255,0.35); pointer-events: auto; touch-action: none; }
#c2-stick i { position: absolute; left: 35px; top: 35px; width: 50px; height: 50px; border-radius: 50%; background: rgba(255,255,255,0.55); }
#c2-a, #c2-b { position: absolute; pointer-events: auto; touch-action: none; width: 72px; height: 72px; border-radius: 50%; font-family: 'Luckiest Guy', var(--sans); font-size: 28px; color: #fff; border: 3px solid #fff; }
#c2-a { right: 24px; bottom: 40px; background: #2e7dd6; }
#c2-b { right: 110px; bottom: 20px; background: #3aa65a; }
body:has(#c2-touch:not([hidden])) #c2-toasts { bottom: 210px; }
body:has(#c2-touch:not([hidden])) #c2-prompt { bottom: 220px; }
.ghost-link { background: none; border: 0; color: #c6b8e0; text-decoration: underline; font-size: 15px; margin-top: 8px; }
#descend { background: #ffe066; }
.pad-sel { outline: 3px solid #ffe066 !important; outline-offset: 2px; }
