:root {
  --night: #0b0908;
  --ember: #c9803a;
  --paper: #e9dcc0;
  --paper-edge: #b99c6b;
  --ink: #1d140c;
  --fresh-ink: #13294b;
  --monitor: #7dffb0;
  --monitor-dim: #1f4a33;
  --alive: 1;
  --warmth: 1;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--night); color: #d9ccb4; }
body {
  font-family: "IM Fell English", Georgia, serif;
  overflow-x: hidden;
}
.room {
  min-height: 100vh;
  padding: clamp(16px, 3vw, 40px) clamp(14px, 4vw, 56px) 24px;
  background:
    radial-gradient(1100px 700px at 30% 35%, rgba(201,128,58,calc(.16 * var(--warmth))), transparent 70%),
    radial-gradient(800px 500px at 85% 20%, rgba(125,255,176,.04), transparent 70%),
    var(--night);
  transition: background 2s ease;
  animation: candle 5s ease-in-out infinite;
}
@keyframes candle { 0%,100% { filter: brightness(1); } 45% { filter: brightness(.97); } 55% { filter: brightness(1.02); } }

.masthead { text-align: center; max-width: 900px; margin: 0 auto 22px; }
.kicker { font-family: "Special Elite", monospace; letter-spacing: .3em; text-transform: uppercase; font-size: 12px; color: var(--ember); margin: 0 0 6px; opacity: .8; }
h1 { font-family: "IM Fell English SC", serif; font-weight: 400; font-size: clamp(36px, 6vw, 72px); margin: 0; color: #efe3c8; letter-spacing: .02em; text-shadow: 0 0 30px rgba(201,128,58,.35); }
h1 span { font-family: "IM Fell English", serif; font-style: italic; font-size: .55em; color: #b9a684; }
.sub { font-size: clamp(16px, 1.6vw, 20px); line-height: 1.45; color: #bfae8f; margin: 8px auto 0; max-width: 760px; }
.sub b { color: #e8d8b5; font-weight: 400; }

.stage {
  display: grid; gap: clamp(16px, 2vw, 28px); max-width: 1560px; margin: 0 auto; align-items: start;
  grid-template-columns: minmax(0, 1.5fr) minmax(300px, .8fr) minmax(300px, .8fr);
  grid-template-areas: "book vitals lab";
}
.book { grid-area: book; } .vitals { grid-area: vitals; } .lab { grid-area: lab; }
@media (max-width: 1360px) {
  .stage { grid-template-columns: minmax(0, 1.55fr) minmax(300px, .85fr); grid-template-areas: "book vitals" "book lab"; }
  .lab { position: static; }
}
@media (max-width: 900px) {
  .stage { grid-template-columns: minmax(0, 1fr); grid-template-areas: "vitals" "book" "lab"; }
  .vitals { position: static !important; }
  .page { min-height: 60vh; max-height: 70vh; }
}

/* ---------------------------------------------------------------- the book */
.book { perspective: 1600px; }
.page {
  position: relative;
  min-height: 70vh;
  max-height: 76vh;
  overflow-y: auto;
  scroll-behavior: smooth;
  padding: clamp(22px, 3.5vw, 48px) clamp(22px, 4vw, 60px) 60px clamp(40px, 6vw, 84px);
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(120,70,30,.20) 0, rgba(120,70,30,0) 7%),
    radial-gradient(120% 90% at 50% 40%, #f1e6cc 0%, var(--paper) 55%, #cdb68a 100%);
  border-radius: 3px 10px 10px 3px;
  box-shadow: 0 30px 80px rgba(0,0,0,.65), inset 0 0 60px rgba(110,70,30,.35), inset 0 0 4px rgba(80,50,20,.6);
  scrollbar-width: thin; scrollbar-color: #a88a5c transparent;
}
.page::before { /* margin rule */
  content: ""; position: absolute; top: 0; bottom: 0; left: clamp(28px, 4.4vw, 62px); width: 1px; background: rgba(160,40,40,.35);
}
.page-grain { position: absolute; inset: 0; pointer-events: none; filter: url(#paper); background: #000; opacity: .9; mix-blend-mode: multiply; }

.intro { position: relative; text-align: center; padding: 8vh 0 4vh; }
.intro-line { font-size: clamp(19px, 2vw, 25px); line-height: 1.5; font-style: italic; margin: 0 0 28px; }
.pick { display: block; font-family: "Special Elite", monospace; font-size: 13px; letter-spacing: .1em; text-transform: uppercase; margin-bottom: 18px; color: #5a4329; }
.pick select { margin-left: 8px; font: inherit; background: transparent; border: 0; border-bottom: 1px solid #8a6b44; color: var(--ink); padding: 3px 4px; }
.hint { font-size: 15px; color: #6b5233; margin-top: 22px; }

.entries { list-style: none; margin: 0; padding: 0; position: relative; }
.entry { margin: 0 0 30px; position: relative; animation: arrive .9s ease both; }
@keyframes arrive { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.entry h3 {
  font-family: "Special Elite", monospace; font-weight: 400; font-size: 13px; letter-spacing: .12em; text-transform: uppercase;
  color: #6d4f2c; margin: 0 0 8px; display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap;
}
.entry h3 .dmg { color: #8a3a2a; letter-spacing: .05em; }
.entry h3 .dmg.ok { color: #3f6b3a; }
.entry .text { font-size: clamp(18px, 1.55vw, 22px); line-height: 1.55; margin: 0; overflow-wrap: anywhere; }
.entry .text .w { white-space: nowrap; }
.entry .text .c { display: inline; }
.entry .text.silent { font-style: italic; color: #8b7556; letter-spacing: .3em; }
.entry.revived .text { color: var(--fresh-ink); text-shadow: 0 0 .6px rgba(19,41,75,.6); }
.entry.revived h3 { color: var(--fresh-ink); }
.entry.revived::before { content: ""; position: absolute; left: -26px; top: 4px; bottom: 4px; width: 3px; background: var(--fresh-ink); opacity: .5; border-radius: 2px; }
.caret { display: inline-block; width: .5em; height: 1em; border-bottom: 2px solid currentColor; animation: blink 1s steps(1) infinite; vertical-align: -2px; }
@keyframes blink { 50% { opacity: 0; } }
.flatline-note { font-family: "Special Elite", monospace; text-align: center; letter-spacing: .4em; color: #7c2a1e; margin: 26px 0 34px; font-size: 14px; animation: arrive 2s ease both; }

/* --------------------------------------------------------------- the monitor */
.vitals {
  position: sticky; top: 20px;
  background: linear-gradient(180deg, #111512, #0a0d0b);
  border: 1px solid #243128; border-radius: 14px; padding: 18px 18px 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.6), inset 0 0 40px rgba(125,255,176,.04);
  font-family: "Special Elite", monospace; color: var(--monitor);
}
.vitals h2 { font-family: inherit; font-weight: 400; font-size: 12px; letter-spacing: .35em; text-transform: uppercase; margin: 0 0 10px; color: #64b989; }
#ekg { width: 100%; height: auto; display: block; background: #050806; border-radius: 8px; border: 1px solid #17221b; }
.readout { margin-top: 14px; }
.big { font-size: 48px; line-height: 1; text-shadow: 0 0 14px rgba(125,255,176,.45); }
.big small { font-size: 13px; margin-left: 8px; color: #6fbf92; text-shadow: none; letter-spacing: .05em; }
.bar { height: 8px; background: #0f1a13; border-radius: 4px; margin: 10px 0 12px; overflow: hidden; border: 1px solid #1d2c22; }
.fill { height: 100%; width: 100%; background: var(--monitor); }
dl { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; margin: 0; font-size: 14px; }
dt { color: #5e9f7a; } dd { margin: 0; text-align: right; color: #b9ffd4; }
.vitals.critical { color: #ff7a6a; border-color: #3b1f1c; }
.vitals.critical .big { text-shadow: 0 0 14px rgba(255,90,74,.5); }
.vitals.dead .big { color: #6a6a6a; text-shadow: none; }

.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-top: 16px; font-size: 13px; color: #78b894; }
.speed { display: flex; align-items: center; gap: 6px; }
.speed input { width: 90px; accent-color: var(--monitor); }
.sound input { accent-color: var(--monitor); vertical-align: -2px; }
.model { font-size: 11px; color: #4f7e63; margin: 14px 0 0; line-height: 1.5; }

.btn {
  font-family: "Special Elite", monospace; font-size: 14px; letter-spacing: .08em;
  border-radius: 999px; padding: 10px 18px; cursor: pointer; border: 1px solid #3c5a47;
  background: transparent; color: #a6f2c6; transition: all .25s;
}
.btn:hover:not(:disabled) { background: rgba(125,255,176,.08); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { border-color: #6b4a26; color: #3a2612; font-size: 16px; padding: 12px 26px; background: rgba(255,240,210,.35); }
.btn.primary:hover:not(:disabled) { background: rgba(255,240,210,.7); }
.btn.revive {
  display: block; width: 100%; margin-top: 16px; padding: 16px; font-size: 18px; letter-spacing: .25em; text-transform: uppercase;
  color: #0b1a10; background: var(--monitor); border: 0; box-shadow: 0 0 30px rgba(125,255,176,.55); animation: pulse 1.6s ease-in-out infinite;
}
.btn.revive:hover { background: #a9ffcb; }
@keyframes pulse { 50% { box-shadow: 0 0 60px rgba(125,255,176,.9); } }
#againBtn { display: block; width: 100%; margin-top: 12px; }
[hidden] { display: none !important; }

.colophon { max-width: 1320px; margin: 26px auto 0; font-size: 14.5px; line-height: 1.6; color: #8f7f63; }
.colophon b { color: #c8b48e; font-weight: 400; }
.colophon a { color: #d39a5c; }
.colophon code { font-family: "Special Elite", monospace; font-size: .92em; color: #b9a684; }

body.flat .room { --warmth: .15; }
body.revived .room { --warmth: 1.4; }
@media (prefers-reduced-motion: reduce) { .room { animation: none; } .entry { animation: none; } }

body.filming .controls { display: none; }

/* ------------------------------------------------------------ brain and memory */
.lab {
  position: sticky; top: 20px; display: grid; gap: 16px;
  font-family: "Special Elite", monospace; color: var(--monitor);
}
.lab section {
  background: linear-gradient(180deg, #111512, #0a0d0b); border: 1px solid #243128; border-radius: 14px;
  padding: 16px 18px; box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
.lab h2 { font-family: inherit; font-weight: 400; font-size: 12px; letter-spacing: .35em; text-transform: uppercase; margin: 0 0 10px; color: #64b989; }
#brain {
  width: 100%; height: auto; display: block; background: #050806; border-radius: 8px; border: 1px solid #17221b;
  image-rendering: auto;
}
.caption { font-family: "IM Fell English", serif; font-size: 14px; line-height: 1.4; color: #8fae9b; margin: 10px 0 0; }
.caption b { color: #b9ffd4; font-weight: 400; }
#memory { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
#memory li {
  font-size: 12.5px; padding: 4px 9px; border-radius: 999px; border: 1px solid #2f5a42; color: #b9ffd4;
  background: rgba(125,255,176,.08); transition: all .8s ease; cursor: help; display: inline-flex; gap: 6px; align-items: baseline;
}
#memory li em { font-style: normal; font-size: 10.5px; color: #a6574a; }
#memory li[data-state="slipping"] { opacity: .55; border-style: dashed; color: #9fcfb3; background: transparent; }
#memory li[data-state="gone"] { color: #5d4a44; border-color: #3a2420; background: transparent; text-decoration: line-through; text-decoration-color: #a6574a; }
#memory li.just { box-shadow: 0 0 16px rgba(255,90,60,.8); border-color: #ff6a5a; }

/* ------------------------------------------------------------------ autopsy */
.postmortem {
  max-width: 1560px; margin: 28px auto 0; padding: clamp(18px, 3vw, 34px);
  background: linear-gradient(180deg, #14110e, #0d0b09); border: 1px solid #2c241b; border-radius: 14px;
  animation: arrive 1.2s ease both;
}
.postmortem h2 { font-family: "IM Fell English SC", serif; font-weight: 400; font-size: clamp(28px, 3vw, 40px); margin: 0 0 6px; color: #efe3c8; }
.lede { margin: 0 0 18px; color: #bfae8f; font-size: 17px; max-width: 860px; line-height: 1.5; }
.timeline { font-family: "Special Elite", monospace; font-size: 12.5px; color: #cdbb98; overflow-x: auto; padding-bottom: 6px; }
.tl-row { display: grid; grid-template-columns: minmax(110px, 150px) repeat(var(--n, 15), minmax(16px, 1fr)) 76px; gap: 3px; align-items: center; margin-bottom: 3px; min-width: 560px; }
.tl-row > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: help; }
.tl-row .m { display: none; }
.tl-row > b { font-weight: 400; color: #c56a55; text-align: right; font-size: 11.5px; }
.tl-row i { height: 16px; border-radius: 3px; background: #1a1714; font-style: normal; }
.tl-row i.r0 { background: #7dffb0; box-shadow: 0 0 6px rgba(125,255,176,.5); }
.tl-row i.r1 { background: #2f6e4b; }
.tl-row i.r2 { background: #1d2420; }
.tl-row i.x { background: #241614; position: relative; }
.tl-row i.x::after { content: "×"; position: absolute; inset: 0; display: grid; place-items: center; color: #6b3a30; font-size: 13px; }
.tl-head i, .tl-alive i { background: none; height: auto; text-align: center; color: #8f7f63; font-size: 11px; box-shadow: none; }
.tl-alive i { color: #5e9f7a; }
.tl-alive span { color: #5e9f7a; }
.cert { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(220px, .6fr); gap: 22px; margin-top: 26px; align-items: start; }
#certificate { width: 100%; height: auto; display: block; border-radius: 4px; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.cert-side .btn { width: 100%; }
@media (max-width: 760px) { .cert { grid-template-columns: 1fr; } }

.entry.seance .text { color: #4a3a5c; font-style: italic; }
.entry.seance h3 { color: #4a3a5c; }
.seance-note { font-size: 15px; color: #6b5233; margin: 8px 0 0; font-style: normal; }

.titlecard {
  position: fixed; inset: 0; z-index: 10; display: grid; place-content: center; text-align: center; gap: 18px;
  background: #050403; color: #efe3c8; font-size: clamp(30px, 3.6vw, 58px); padding: 0 8vw; transition: opacity 1s ease;
}
.titlecard p { margin: 0; text-shadow: 0 0 40px rgba(201,128,58,.4); }
.titlecard .tc2 { font-style: italic; color: #c9a16a; }
.titlecard.out { opacity: 0; pointer-events: none; }

/* recording the film: everything has to fit one 1600 x 900 frame */
body.filming .masthead { margin-bottom: 12px; }
body.filming .masthead .sub { display: none; }
body.filming h1 { font-size: 50px; }
body.filming .lab { gap: 12px; }
body.filming .lab section { padding: 12px 14px; }
body.filming .lab .caption { font-size: 12.5px; margin-top: 7px; }
@media (max-width: 520px) {
  .timeline { font-size: 10.5px; }
  .tl-row { min-width: 0; gap: 2px; grid-template-columns: 84px repeat(var(--n, 15), minmax(11px, 1fr)) 28px; }
  .tl-row .w { display: none; }
  .tl-row .m { display: inline; }
  .tl-alive { display: none !important; }
  .tl-row > b { font-size: 9.5px; }
  .tl-row i { height: 13px; }
  .tl-row i.x::after { font-size: 10px; }
  .tl-head i, .tl-alive i { font-size: 8.5px; }
}
