:root {
  --bg: #0b0a10; --ink: #e9e4f0; --muted: #9a92a8; --blood: #b3122e; --ecto: #7cff9b; --pumpkin: #ff8a1f;
  --l1: #b3122e; --l2: #ff5a1f; --l3: #f2c230; --l4: #3fb27f; --l5: #4a7bd6;
  --candle: #ffcf6b; --clot: #6d0a1c;
  /* Under-triage effect (task 13): screen vignette, dried stains, glowing eyes. */
  --vignette: #5c0a18; --stain: #5a0a18; --eye-glow: #ff3030;
  /* Accessibility pass (task 11), WCAG 2.2 AA. Contrast ratios measured on --btn-bg #1a1424.
     --l1 is 2.6:1 there, so level-1 outlines use --l1-line (5.6:1); --l2..--l5 are >= 4.3:1.
     Badge text: black on --l2..--l5 (>= 5.1:1), white on --l1 (6.9:1; black was 3.0:1). */
  --btn-bg: #1a1424; --l1-line: #ff4d6a; --focus: var(--ecto);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 50% -20%, #2a1838, var(--bg) 60%); color: var(--ink);
  font: 16px/1.5 Georgia, 'Times New Roman', serif; }
.fog { position: fixed; inset: 0; pointer-events: none; opacity: .18;
  background: repeating-radial-gradient(circle at 30% 70%, #fff0 0 40px, #ffffff22 60px, #fff0 120px);
  animation: drift 40s linear infinite; }
@keyframes drift { to { transform: translateX(-120px); } }
@media (prefers-reduced-motion: reduce) { .fog { animation: none; } }
header, main, footer { max-width: 860px; margin: 0 auto; padding: 1rem; position: relative; }
h1 { font-size: 2.2rem; margin: .5rem 0 0; color: var(--pumpkin); text-shadow: 0 0 12px #ff8a1f88; }
h1 .h1-sub { color: var(--ecto); font-size: 1rem; letter-spacing: .2em; text-transform: uppercase; }
.tag { color: var(--muted); margin-top: .25rem; }
nav { display: flex; gap: .5rem; flex-wrap: wrap; }
button { font: inherit; cursor: pointer; border: 1px solid #ffffff33; background: var(--btn-bg); color: var(--ink);
  padding: .6rem 1rem; border-radius: 10px; }
button:hover { border-color: var(--ecto); box-shadow: 0 0 10px #7cff9b55; }
/* One visible focus ring for every focusable element: 3px ectoplasm green, >= 12:1 on the dark theme
   (WCAG 2.4.7 / 2.4.11). Mouse clicks on buttons do not show it; keyboard focus always does. */
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
:focus:not(:focus-visible) { outline: none; }
.skip-link { position: absolute; left: 1rem; top: -3rem; z-index: 10; padding: .5rem 1rem; border-radius: 8px;
  background: var(--btn-bg); color: var(--ecto); }
.skip-link:focus { top: .5rem; }
/* Pressed state is not colour alone (WCAG 1.4.1 / 1.4.11): blood fill plus an ink underline bar. */
nav button.active, .lang-toggle button[aria-pressed="true"], .sound-toggle[aria-pressed="true"] { background: var(--blood); border-color: var(--blood);
  box-shadow: inset 0 -3px 0 var(--ink); }
/* English / 中文 toggle: the pressed language uses the same blood-red state as the active mode */
.tools { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: .5rem; }
.lang-toggle { display: flex; gap: .35rem; }
.lang-toggle button, .sound-toggle { padding: .3rem .75rem; font-size: .9rem; }
/* Sound toggle (task 13): off by default; the icon is decoration (empty alt text after the slash),
   the state is announced through aria-pressed. */
.sound-toggle::before { content: '🔇 ' / ''; }
.sound-toggle[aria-pressed="true"]::before { content: '🔊 ' / ''; }
/* Chinese text: Georgia has no CJK glyphs, so name serif CJK fonts before the generic fallback */
body:lang(zh-CN) { font-family: Georgia, 'Songti SC', 'Noto Serif CJK SC', 'Source Han Serif SC', 'SimSun', 'PingFang SC', 'Microsoft YaHei', 'Noto Sans CJK SC', serif; }
.vitals div:lang(zh-CN) { font-family: ui-monospace, monospace, 'Noto Sans CJK SC', 'PingFang SC', 'Microsoft YaHei', sans-serif; }
h1 .h1-sub:lang(zh-CN) { letter-spacing: .3em; }
.panel { background: #120e1acc; border: 1px solid #ffffff1a; border-radius: 16px; padding: 1.25rem; }
.hud { display: flex; justify-content: space-between; color: var(--muted); }
.card { margin: 1rem 0; }
.card .who { font-size: 1.4rem; }
.card .emoji { font-size: 3rem; display: block; }
.card-head { display: flex; align-items: center; gap: 1rem; }
/* Candle-lit frame for the SVG monster portraits (src/portraits.js) */
.portrait { flex: none; width: 96px; height: 96px; border-radius: 50%; display: grid; place-items: center; overflow: hidden;
  background: radial-gradient(circle at 50% 70%, #ffcf6b2e, #2a1838 72%);
  border: 2px solid #ff8a1f55; box-shadow: 0 0 18px #ff8a1f33, inset 0 0 14px #000000aa; }
.portrait-art { width: 84px; height: 84px; display: block; }
.vitals { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .5rem; margin-top: .75rem; }
.vitals div { background: #00000055; border-radius: 8px; padding: .4rem .6rem; font-family: ui-monospace, monospace; }
.vitals .danger { color: #ff6b81; border: 1px solid #ff6b8166; }
.levels { display: grid; grid-template-columns: repeat(5, 1fr); gap: .5rem; }
.levels button { padding: .8rem .3rem; border-width: 2px; }
.levels button[aria-disabled="true"] { cursor: not-allowed; }
.levels button[data-level="1"] { border-color: var(--l1-line); } .levels button[data-level="2"] { border-color: var(--l2); }
.levels button[data-level="3"] { border-color: var(--l3); } .levels button[data-level="4"] { border-color: var(--l4); }
.levels button[data-level="5"] { border-color: var(--l5); }
.feedback { margin-top: 1rem; min-height: 2rem; }
.badge { display: inline-block; padding: .2rem .7rem; border-radius: 999px; font-weight: bold; color: #000; }
.badge.lv1 { background: var(--l1); color: #fff; } .badge.lv2 { background: var(--l2); } .badge.lv3 { background: var(--l3); }
.badge.lv4 { background: var(--l4); } .badge.lv5 { background: var(--l5); }
.ghost { margin-top: .5rem; background: transparent; border-color: var(--ecto); color: var(--ecto); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .75rem; }
label { display: flex; flex-direction: column; gap: .25rem; color: var(--muted); }
label.chk { flex-direction: row; align-items: center; gap: .5rem; }
/* Triage Desk inline help (task 16). The ⓘ button sits beside the label; an open panel spans the
   whole form row underneath. No animation or transition. */
.field { display: grid; grid-template-columns: 1fr auto; align-items: start; column-gap: .4rem; }
.field > label { grid-column: 1; }
.field.help-open { grid-column: 1 / -1; }
.help-btn { grid-column: 2; min-width: 44px; min-height: 44px; padding: 0; border-radius: 50%; font-size: 1.15rem; line-height: 1;
  color: var(--ecto); background: var(--btn-bg); }
.help-btn[aria-expanded="true"] { border-color: var(--ecto); box-shadow: inset 0 0 0 1px var(--ecto); }
.help-panel { grid-column: 1 / -1; margin-top: .5rem; padding: .6rem .8rem; background: var(--btn-bg); border: 1px solid #ffffff26;
  border-radius: 10px; color: var(--ink); overflow-wrap: anywhere; }
.help-panel h3 { margin: 0 0 .4rem; font-size: 1rem; color: var(--pumpkin); }
.help-panel h4 { margin: .6rem 0 .2rem; font-size: .95rem; color: var(--ecto); }
.help-panel p { margin: .3rem 0; }
.help-panel ul { margin: .2rem 0; padding-left: 1.2rem; }
.help-panel .help-rule, .help-panel .help-esi { color: var(--candle); }
.resource-check { border: 1px solid #ffffff26; border-radius: 8px; margin: .4rem 0; padding: .3rem .6rem; }
.resource-check legend { color: var(--ecto); padding: 0 .3rem; }
.resource-check ul { list-style: none; padding-left: 0; }
.resource-check label.chk { color: var(--ink); align-items: flex-start; min-height: 32px; }
.resource-check input { margin-top: .25rem; flex: none; width: 1.1rem; height: 1.1rem; }
.resource-total { font-weight: bold; }
/* Incomplete vital signs (task 17): optional vitals with a "why not measured" select, the warning
   and the provisional tag in the result. Text, not colour alone, carries each state. No animation. */
.vitals-note { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: .9rem; }
.vital { display: flex; flex-direction: column; gap: .3rem; }
.vital label.reason { font-size: .85rem; }
.vital label.reason select { font-size: .85rem; padding: .3rem; max-width: 100%; }
.missing-warning { margin: .6rem 0 0; padding: .5rem .7rem; border: 1px solid var(--pumpkin); border-left-width: 4px; border-radius: 8px;
  background: var(--btn-bg); color: var(--ink); }
.missing-warning strong { color: var(--candle); }
.missing-warning .infant-temp { display: block; margin-top: .4rem; font-weight: bold; color: var(--ink); }
.provisional-tag { display: inline-block; margin-left: .4rem; padding: 0 .55rem; border: 1px dashed var(--candle); border-radius: 999px;
  color: var(--candle); font-weight: bold; font-size: .9rem; }
.help-missing, .lesson-missing { color: var(--candle); }
input, select { font: inherit; background: #00000066; color: var(--ink); border: 1px solid #ffffff33; border-radius: 8px; padding: .45rem; }
.report h2 { color: var(--pumpkin); margin: .25rem 0; }
.report h3 { color: var(--ecto); margin-bottom: .5rem; }
.report .final { font-size: 1.25rem; }
.tally { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .5rem; margin: 0; }
.tally div { background: #00000055; border-radius: 8px; padding: .5rem .75rem; }
.tally dt { color: var(--muted); }
.tally dd { margin: 0; font-size: 1.6rem; font-weight: bold; }
.missed-list { list-style: none; padding: 0; display: grid; gap: .6rem; }
.missed { background: #00000055; border-radius: 8px; padding: .6rem .8rem; border-left: 4px solid var(--l3); }
.missed.under { border-left-color: var(--blood); }
.missed .teach { margin: .4rem 0 0; color: var(--ink); }
/* Vitals the player saw for a missed case (task 14): they vary each appearance. */
.missed .seen { margin: .4rem 0 0; color: var(--muted); font-size: .9rem; }
.missed .vitals { margin-top: .3rem; }
/* Decision point that decided a missed case's level (task 15). Text, not colour, carries the step. */
.step-tag { display: inline-block; margin-left: .35rem; padding: 0 .5rem; border: 1px solid var(--ecto); border-radius: 999px;
  color: var(--ecto); font-size: .85rem; white-space: nowrap; }

/* Storylines (task 21). Static: no animation or transition. The badge text says the link in words,
   so colour is never the only signal; --candle on --btn-bg is AA (test/a11y.test.js). */
.storyline-badge { display: inline-block; margin: .6rem 0 0; padding: .15rem .6rem; border: 1px solid var(--candle);
  border-radius: 999px; background: var(--btn-bg); color: var(--candle); font-size: .9rem; }
/* Opaque like the lesson, so the haunting stains never sit under its text. */
.storyline-report { margin: 1.25rem 0 .5rem; padding: .25rem 1rem .75rem; background: var(--btn-bg);
  border: 1px solid #ffffff26; border-left: 4px solid var(--candle); border-radius: 12px; }
.storyline-report h3 { margin-top: .6rem; }
.storyline-patients { margin: .25rem 0; padding-left: 1.4rem; }
.storyline-under { color: var(--l1-line); font-weight: bold; white-space: nowrap; }
.storyline-rule { color: var(--muted); font-size: .9rem; }

/* "ESI v4 in 2 minutes" (task 15). An opaque card inside .report (z-index 2, above the stains at 1),
   so the haunting stains never sit under or over its text. No animation or transition at all. */
.lesson { margin: 1.25rem 0 .5rem; background: var(--btn-bg); border: 1px solid #ffffff26; border-radius: 12px; }
.lesson > summary { cursor: pointer; padding: .75rem 1rem; color: var(--pumpkin); font-weight: bold; font-size: 1.1rem; }
.lesson[open] > summary { border-bottom: 1px solid #ffffff1a; }
.lesson-body { padding: .25rem 1rem 1rem; }
.lesson h3 { color: var(--ecto); margin: 1rem 0 .4rem; font-size: 1.05rem; }
.lesson h4 { color: var(--ink); margin: .5rem 0 .25rem; font-size: 1rem; }
.lesson ul, .lesson ol { margin: .25rem 0; padding-left: 1.4rem; }
.lesson li { margin: .2rem 0; }
.lesson-steps li { margin: .5rem 0; }
.lesson-steps .step-label { display: block; color: var(--pumpkin); font-weight: bold; }
.lesson-steps .step-a { display: block; color: var(--candle); }
.resource-lists { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: .25rem 1rem; }
.danger-table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.danger-table caption { text-align: left; color: var(--muted); padding-bottom: .4rem; caption-side: top; }
.danger-table th, .danger-table td { border: 1px solid #ffffff26; padding: .35rem .5rem; text-align: left; vertical-align: top; }
.danger-table thead th { color: var(--ecto); }
.danger-table td { font-family: ui-monospace, monospace; white-space: nowrap; }
.wrong-count { font-weight: bold; }
.lesson-note, .lesson-source { color: var(--muted); font-size: .9rem; }
.lesson-note { margin-top: 1rem; }
@media (max-width: 400px) {
  .lesson-body { padding: .25rem .6rem .75rem; }
  .danger-table { font-size: .85rem; }
  .danger-table th, .danger-table td { padding: .3rem .35rem; }
}
footer { color: var(--muted); font-size: .85rem; text-align: center; }

/* Optional accounts (task 22): header button, dialogs, save line, Progress and Leaderboard.
   Hidden unless src/config.js is set. Static: no animation or transition. Text uses --ink, --muted,
   --ecto and --candle on --btn-bg, all AA (test/a11y.test.js); the danger button is ink on blood. */
.account-slot { display: flex; }
.account-btn { padding: .3rem .75rem; font-size: .9rem; max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-notice { margin: .4rem 0 0; color: var(--candle); font-size: .9rem; }
.account-dialog { width: min(28rem, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); overflow: auto; padding: 1rem 1.25rem;
  background: var(--btn-bg); color: var(--ink); border: 1px solid #ffffff33; border-radius: 14px; overflow-wrap: anywhere; }
.account-dialog::backdrop { background: #0b0a10d9; }
.account-dialog h2 { margin: .2rem 0 .6rem; color: var(--pumpkin); font-size: 1.25rem; }
.account-dialog h3 { margin: .4rem 0; color: var(--ecto); font-size: 1rem; }
.account-dialog label { color: var(--ink); }
.account-dialog input { width: 100%; }
.provider-list { display: grid; gap: .5rem; margin: .75rem 0; }
.provider { min-height: 44px; text-align: left; }
.account-note { color: var(--muted); font-size: .9rem; margin: .4rem 0; }
.account-msg { margin: .5rem 0; padding: .4rem .6rem; border: 1px solid var(--ecto); border-radius: 8px; color: var(--ink); }
.account-msg.error { border-color: var(--pumpkin); border-left-width: 4px; }
.name-form { display: grid; gap: .4rem; margin: .5rem 0 1rem; }
.name-form button { justify-self: start; }
.account-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-start; }
.account-actions .danger-zone { flex-basis: 100%; padding: .5rem .75rem; border: 1px solid var(--l1-line); border-radius: 10px; }
button.danger { background: var(--blood); border-color: var(--blood); color: var(--ink); }
button.danger-outline { margin-top: 0; border-color: var(--l1-line); color: var(--ink); }
.dialog-close { display: block; margin-top: 1rem; }
.save-status { margin: .25rem 0 .75rem; color: var(--muted); }
.save-status.saved { color: var(--ecto); }
.save-status.queued, .save-status.rejected { color: var(--candle); }
.account-panel h2 { color: var(--pumpkin); margin: .25rem 0 .75rem; }
.account-panel h3 { color: var(--ecto); margin: 1rem 0 .4rem; }
.sparkline { display: block; width: 100%; max-width: 360px; height: auto; }
.sparkline polyline { fill: none; stroke: var(--ecto); stroke-width: 2; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.sparkline circle { fill: var(--candle); }
.sparkline .axis { stroke: var(--muted); stroke-width: 1; vector-effect: non-scaling-stroke; }
.board-wrap { overflow-x: auto; }
.board-table { width: 100%; border-collapse: collapse; }
.board-table caption { text-align: left; color: var(--muted); padding-bottom: .4rem; }
.board-table th, .board-table td { border-bottom: 1px solid #ffffff1a; padding: .35rem .5rem; text-align: left; }
.board-table thead th { color: var(--ecto); }
.board-table tbody th { font-weight: normal; overflow-wrap: anywhere; }
.board-table tr.me { background: #00000055; box-shadow: inset 4px 0 0 var(--candle); }
.board-table .you, .board-me { color: var(--candle); font-weight: bold; }

/* ---- Haunting effects (tasks 7 and 13) ----
   app.js adds .fx-under or .fx-correct to #game after an answer and removes it on the next case;
   .haunted on <body> drives the full-screen vignette. Everything below is decoration (aria-hidden).

   Layers, bottom to top. #game is deliberately NOT a stacking context (no filter, opacity or
   transform on .panel), so the z-indexes below all compete in one context:
     1  .stains     dried stains that persist through the night (one per under-triage)
     2  .hud .card .report
     3  .fx-layer   dim overlay, drips, pool, handprint; .ecg across the top of the card
     5  .vignette   fixed, full screen
     6  .levels .feedback #nextCase   always above every effect, so feedback text stays readable

   Flash safety (WCAG 2.3.1): only two animations change the brightness of a large area: the panel
   flicker (2 dims, both before 0.75 s) and the vignette heartbeat (1 pulse per second, 3 times,
   starting at 1.1 s, after the flicker has ended, peak opacity .55). In any 1 s window that is at
   most 2 flashes, below the limit of 3, because red flashes are the riskiest kind;
   test/haunt.test.js checks it from this file.
   The vignette red is dark and not a "saturated red" (R / (R+G+B) < 0.8). */
#game { position: relative; }
#play { position: relative; }
.stains, .fx-layer { position: absolute; inset: 0; overflow: hidden; border-radius: inherit; pointer-events: none; }
.stains { z-index: 1; }
.hud, .card, .report { position: relative; z-index: 2; }
.fx-layer { z-index: 3; container-type: size; visibility: hidden; }
.fx-under .fx-layer { visibility: visible; }
.levels, .feedback, #nextCase { position: relative; z-index: 6; }
.fx-under .feedback { background: #120e1af2; border: 1px solid var(--blood); border-radius: 10px; padding: .6rem .8rem; }
.fx-under #nextCase { background: var(--btn-bg); }

/* Persistent stains: positions and sizes come from stainLayout() in src/haunt.js. */
.stain { position: absolute; width: var(--size); height: calc(var(--size) * .8); translate: -50% -50%; rotate: var(--rot);
  background: radial-gradient(closest-side, var(--stain) 68%, #5a0a18b3 86%, #5a0a1800); opacity: .9;
  transition: width .8s ease-out, height .8s ease-out; }

/* Flicker: a dark red overlay instead of a filter on the panel (a filter would make #game a
   stacking context and trap the feedback under the vignette). */
.fx-dim { position: absolute; inset: 0; background: #1a0306; opacity: 0; }
.fx-under .fx-dim { animation: flicker 1s ease-in-out 1; }
@keyframes flicker { 0%, 30%, 75%, 100% { opacity: 0; } 15% { opacity: .6; } 55% { opacity: .5; } }

/* Drips: 12 streaks (src/haunt.js DRIPS, 4 to 14 px wide) with a glossy highlight. Each streak
   grows from the top, then its drop falls to the bottom edge and the pool there rises. */
.drips span { position: absolute; top: 0; left: var(--x); width: var(--w); height: 0;
  border-radius: 0 0 calc(var(--w) / 2) calc(var(--w) / 2);
  background: linear-gradient(90deg, var(--clot), var(--blood) 40%, #d21a3a 55%, var(--clot)); }
.drips span::before { content: ''; position: absolute; top: 0; bottom: 3px; left: 22%; width: max(1px, 18%); border-radius: 2px;
  background: linear-gradient(#ffffff00, #ffffff66 40%, #ffffff26); }
.drips span::after { content: ''; position: absolute; left: 50%; bottom: calc(var(--w) * -.6); width: calc(var(--w) * 1.5);
  height: calc(var(--w) * 1.7); translate: -50% 0; border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: radial-gradient(circle at 35% 30%, #ffffff8c 0 12%, #ffffff00 24%),
    radial-gradient(circle at 50% 60%, #d21a3a, var(--blood) 55%, var(--clot)); }
.fx-under .drips span { animation: drip 1.6s ease-in var(--d) forwards; }
.fx-under .drips span::after { animation: drop-fall .7s ease-in calc(var(--d) + 1.6s) forwards; }
@keyframes drip { from { height: 0; } to { height: var(--len); } }
@keyframes drop-fall {
  0% { transform: translateY(0); opacity: 1; }
  90% { opacity: 1; }
  100% { transform: translateY(calc(100cqh - var(--len))); opacity: 0; }
}

/* Pool along the bottom edge: a scalloped band with a glossy line, rising as the drops land. */
.pool { position: absolute; left: 0; right: 0; bottom: 0; height: 22px; transform: scaleY(0); transform-origin: 50% 100%;
  background: linear-gradient(#d21a3a, var(--blood) 35%, var(--clot));
  mask: radial-gradient(14px 8px at 50% 8px, #000 98%, #0000) 0 0 / 46px 16px repeat-x,
    linear-gradient(#000 0 0) 0 8px / 100% 100% no-repeat; }
.pool::before { content: ''; position: absolute; left: 3%; right: 3%; top: 9px; height: 2px; border-radius: 2px;
  background: linear-gradient(90deg, #fff0, #ffffff55 20%, #fff0 45%, #ffffff40 70%, #fff0); }
.fx-under .pool { animation: pool 1.4s ease-out 2s forwards; }
@keyframes pool { to { transform: scaleY(1); } }

/* Handprint (inline SVG in index.html) slapped on the right side, then dragged down. */
.handprint { position: absolute; right: 2.5%; top: 4%; width: 52px; height: 174px; color: var(--blood); opacity: .85; }
.handprint .hand { opacity: 0; }
.handprint .smear path { stroke-dasharray: 100; stroke-dashoffset: 100; }
.fx-under .handprint .hand { animation: hand-drag 2.2s cubic-bezier(.3, 0, .6, 1) .5s forwards; }
.fx-under .handprint .smear path { animation: smear 2.2s cubic-bezier(.3, 0, .6, 1) .5s forwards; }
/* After about 4 s the drips and handprint recede to 25% so the story and vitals are readable
   while the player studies the feedback. The pool and the stains stay at full strength. */
.fx-under .drips, .fx-under .handprint { animation: recede .8s ease-in-out 4s forwards; }
@keyframes recede { to { opacity: .25; } }
@keyframes hand-drag {
  0% { opacity: 0; transform: translateY(0); }
  6% { opacity: 1; transform: translateY(0); }
  100% { opacity: 1; transform: translateY(132px); }
}
@keyframes smear { 0%, 6% { stroke-dashoffset: 100; } 100% { stroke-dashoffset: 0; } }

/* Dark red vignette around the whole screen: one slow heartbeat per second for 3 seconds,
   starting after the flicker. The ECG beats and the optional sound use the same timing. */
.vignette { position: fixed; inset: 0; z-index: 5; pointer-events: none; opacity: 0;
  background: radial-gradient(ellipse at center, #0000 50%, var(--vignette) 100%); }
.haunted .vignette { animation: heartbeat 1s ease-out 1.1s 3; }
@keyframes heartbeat { 0%, 100% { opacity: 0; } 15% { opacity: .55; } 55% { opacity: .18; } }

/* ECG trace across the top of the card: three beats, the last one weak, then flat. */
.ecg { position: absolute; left: 0; top: .1rem; width: 100%; height: 36px; z-index: 3; pointer-events: none;
  overflow: visible; visibility: hidden; filter: drop-shadow(0 0 3px var(--ecto)); }
.ecg path { fill: none; stroke: var(--ecto); stroke-width: 2; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
/* Revealed left to right with a clip (dash offsets break on a stretched, non-scaling stroke). */
.fx-under .ecg { visibility: visible; clip-path: inset(0 100% 0 0); animation: ecg-trace 3.6s linear 1.1s forwards; }
@keyframes ecg-trace { to { clip-path: inset(0 0 0 0); } }

/* Portrait: drains to grey while the eyes glow red (eyeGlowSvg() in src/portraits.js). */
.portrait > svg { grid-area: 1 / 1; }
.eye-glow { width: 84px; height: 84px; display: block; opacity: 0; filter: drop-shadow(0 0 3px var(--eye-glow)); }
.eye-glow .glow-halo { fill: var(--eye-glow); opacity: .5; }
.eye-glow .glow-core { fill: #ffd6d6; }
.fx-under .portrait { border-color: var(--blood); }
.fx-under .portrait-art { animation: desaturate 3s ease-in-out forwards; }
.fx-under .eye-glow { animation: eyes-glow 3s ease-in-out forwards; }
@keyframes desaturate { 0%, 100% { filter: none; } 20%, 75% { filter: grayscale(1) brightness(.7) contrast(1.1); } }
@keyframes eyes-glow { 0%, 100% { opacity: 0; } 20%, 75% { opacity: 1; } }

.panel.fx-under { border-color: var(--blood); }

.panel.fx-correct { border-color: var(--pumpkin); animation: flare 1.4s ease-out 1; }
.fx-correct .portrait { animation: candle 1.4s ease-out 1; }
@keyframes flare {
  0% { box-shadow: 0 0 0 0 #ff8a1f00; }
  30% { box-shadow: 0 0 42px 6px #ff8a1f77, inset 0 0 60px #ffcf6b26; }
  100% { box-shadow: 0 0 0 0 #ff8a1f00; }
}
@keyframes candle {
  0% { box-shadow: 0 0 18px #ff8a1f33, inset 0 0 14px #000000aa; }
  30% { box-shadow: 0 0 34px 8px #ffcf6b99, inset 0 0 10px #ffcf6b55; border-color: var(--candle); }
  100% { box-shadow: 0 0 18px #ff8a1f33, inset 0 0 14px #000000aa; }
}

/* The text note only shows when motion is reduced; otherwise the animation carries the message
   and the verdict text already states the outcome. */
.fx-note { display: none; margin: .5rem 0 0; font-style: italic; }

/* Reduced motion: only the static stains, the panel tint and the text note. */
@media (prefers-reduced-motion: reduce) {
  .panel.fx-correct, .fx-correct .portrait, .fx-under .portrait-art { animation: none; }
  .fx-layer, .vignette, .ecg, .eye-glow { display: none; }
  .stain { transition: none; }
  .panel.fx-under { background: #2a0a12e6; border-color: var(--blood); box-shadow: inset 0 0 0 2px var(--blood); }
  .panel.fx-correct { background: #24160ae6; border-color: var(--pumpkin); box-shadow: inset 0 0 0 2px var(--pumpkin); }
  .fx-correct .portrait { border-color: var(--candle); }
  .fx-note { display: block; }
}
@media (max-width: 560px) { .levels { grid-template-columns: repeat(3, 1fr); } h1 { font-size: 1.6rem; } }
