/* ============================================================
   engine.css  (STABLE — layout and panel mechanics)
   The look of a deck belongs in theme.css: override the
   variables below and restyle .frame-* / #hud / #console there.
   Stage is authored at 1280x720 and scaled to the window.
   ============================================================ */

@font-face { font-family: 'Press Start 2P'; src: url('../fonts/PressStart2P.woff2') format('woff2'); font-display: block; }
@font-face { font-family: 'VT323'; src: url('../fonts/VT323.woff2') format('woff2'); font-display: block; }
@font-face { font-family: 'Silkscreen'; src: url('../fonts/Silkscreen.woff2') format('woff2'); font-display: block; }
@font-face { font-family: 'Pixelify Sans'; src: url('../fonts/PixelifySans.woff2') format('woff2'); font-display: block; }

:root {
  --vp-h: 560px;
  --bg: #000;
  --ink: #f2eee0;
  --dim: #a59fb8;
  --accent: #ffcc44;
  --accent-2: #66e0ff;
  --accent-3: #ff5f8f;
  --warn: #ff7a3a;
  --font-display: 'Press Start 2P', monospace;
  --font-body: 'VT323', monospace;
  --fs: 28px;
  --panel-bg: rgba(10, 8, 24, 0.9);
  --panel-edge: #6a5fa0;
  --panel-radius: 0px;
  --console-bg: #0a0816;
  --console-edge: #3c3460;
  --hud-bg: rgba(0, 0, 0, 0.72);
  --hud-ink: #cfc8ea;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; background: var(--bg); overflow: hidden; color: var(--ink); font-family: var(--font-body); }
/* pixel fonts: no ligatures (Pixelify Sans turns fi/fl into an 'A') */
#stage, #stage * { font-variant-ligatures: none; font-feature-settings: 'liga' 0, 'calt' 0; }
.hidden { display: none !important; }

#stage { position: absolute; width: 1280px; height: 720px; transform-origin: 0 0; background: #000; overflow: hidden; }

/* ---------- viewport: the p5 world + overlays ---------- */
#viewport { position: absolute; left: 0; top: 0; width: 1280px; height: var(--vp-h); overflow: hidden; cursor: pointer; }
#world { position: absolute; left: 0; top: 0; z-index: 0; image-rendering: pixelated; image-rendering: crisp-edges; }
#crt { position: absolute; inset: 0; z-index: 5; pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(0,0,0,0) 0 2px, rgba(0,0,0,0.14) 2px 4px); }

#hud { position: absolute; left: 0; top: 0; right: 0; height: 32px; z-index: 20; cursor: default;
  display: flex; align-items: center; justify-content: space-between; padding: 0 14px;
  background: var(--hud-bg); color: var(--hud-ink); font-family: var(--font-display); font-size: 10px; letter-spacing: 1px; }
#hud-left, #hud-right { display: flex; gap: 10px; align-items: center; min-width: 300px; white-space: nowrap; }
#hud-right { justify-content: flex-end; }
#hud-mark { color: var(--accent-3); animation: blink 2.4s steps(2) infinite; }
#section-nav { display: flex; gap: 6px; }
#section-nav button { font-family: var(--font-display); font-size: 8px; background: transparent; color: var(--dim);
  border: 1px solid currentColor; padding: 5px 7px; cursor: pointer; }
#section-nav button.active { color: #000; background: var(--accent); border-color: var(--accent); }

#panels { position: absolute; inset: 0; z-index: 10; pointer-events: none; }
#panels > * { pointer-events: auto; }
#hover-line { position: absolute; left: 0; right: 0; bottom: 6px; z-index: 15; text-align: center; pointer-events: none;
  font-family: var(--font-display); font-size: 11px; color: var(--accent); text-shadow: 2px 2px 0 #000; }

#badge { position: absolute; right: 18px; top: 44px; z-index: 30; font-family: var(--font-display); font-size: 14px;
  color: #000; background: var(--accent); padding: 10px 14px; box-shadow: 4px 4px 0 #000; }
#badge.show { animation: badge 3.2s steps(8) both; }

/* ---------- console: narration bar (+ optional verbs) ---------- */
#console { position: absolute; left: 0; top: var(--vp-h); width: 1280px; height: calc(720px - var(--vp-h));
  background: var(--console-bg); border-top: 3px solid var(--console-edge);
  display: grid; grid-template-columns: 150px 1fr 110px; grid-template-rows: 1fr auto; padding: 14px 18px 10px; gap: 4px 16px; }
#speaker { font-family: var(--font-display); font-size: 10px; color: var(--accent-3); padding-top: 6px; letter-spacing: 1px; }
#dialogue-text { font-size: calc(var(--dialogue-fs, 30px) * var(--dfit, 1)); line-height: 1.06; color: var(--ink); overflow: hidden; }
#dialogue-text.typing::after { content: '\2588'; color: var(--accent); animation: blink 0.6s steps(2) infinite; margin-left: 2px; }
#dialogue-text a { color: var(--accent-2); }
#controls { display: flex; gap: 8px; justify-content: flex-end; align-items: flex-start; }
#controls button { width: 40px; height: 34px; font-size: 14px; cursor: pointer; background: transparent; color: var(--accent-2); border: 2px solid currentColor; }
#verbs { grid-column: 1 / -1; display: flex; gap: 24px; justify-content: center; font-family: var(--font-display); font-size: 11px; }
#verbs button { background: none; border: none; color: var(--dim); font: inherit; cursor: pointer; padding: 4px 2px; }
#verbs button.active, #verbs button:hover { color: var(--accent); }

/* ---------- narration layouts (DECK.layout.narration) ---------- */
/* window: a dialogue window floating inside the world (JRPG, visual novel) */
body.narration-window #console, body.fullbleed.narration-console #console {
  top: auto; bottom: 18px; left: 24px; width: 1232px; height: 150px; z-index: 30;
  border: 3px solid var(--console-edge); box-shadow: 4px 4px 0 rgba(0,0,0,0.6); }
/* caption: subtitles over the bottom of the world (film, cutscenes) */
body.narration-caption #console { top: auto; bottom: 14px; left: 120px; width: 1040px; height: auto; min-height: 0; max-height: 130px; z-index: 30;
  background: none; border: 0; grid-template-columns: 1fr; padding: 0; }
body.narration-caption #speaker, body.narration-caption #controls, body.narration-caption #verbs { display: none; }
body.narration-caption #dialogue-text { text-align: center; max-height: 120px; text-shadow: 3px 3px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000; }
/* overhead: lines appear over the speaker's head in their color (classic adventure speech) */
body.narration-overhead #speaker, body.narration-overhead #dialogue-text { display: none; }
body.narration-overhead #console { grid-template-columns: 1fr 110px; }
/* notes: narration only in the presenter window (N); the console keeps any verbs or menus */
body.narration-notes #speaker, body.narration-notes #dialogue-text { display: none; }
body.narration-notes #console { grid-template-columns: 1fr 110px; }
#overhead { position: absolute; z-index: 16; max-width: 700px; pointer-events: none; text-align: center; color: var(--accent); }
#overhead-text { font-size: calc(var(--overhead-fs, 30px) * var(--dfit, 1)); line-height: 1.05; max-height: 220px; overflow: hidden;
  text-shadow: 2px 2px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 0 2px 0 #000, 2px 0 0 #000, 0 -2px 0 #000, -2px 0 0 #000; }
#overhead-text.typing::after { content: '\2588'; animation: blink 0.6s steps(2) infinite; }

/* ---------- panels: common ---------- */
.panel { position: absolute; overflow: hidden; cursor: default;
  font-size: calc(var(--fs) * var(--fit, 1)); line-height: 1.12; color: var(--ink);
  background: var(--panel-bg); border: 2px solid var(--panel-edge); border-radius: var(--panel-radius);
  padding: 0.7em 0.9em 0.65em; animation: materialize 0.42s steps(7) both; }
.panel.out { animation: dematerialize 0.16s steps(3) both !important; }
.panel.shown { animation: none; }
.panel li.fresh { animation: materialize 0.35s steps(6) both; }
.panel.zoomfrom { animation: zoomfrom 0.5s steps(8) both; }
.panel .tag { font-family: var(--font-display); font-size: 0.32em; letter-spacing: 1px; color: var(--accent-3);
  margin-bottom: 1.1em; display: flex; justify-content: space-between; gap: 1em; }
.panel .tag .right { color: var(--dim); }
.panel h2 { font-family: var(--font-display); font-size: 0.66em; line-height: 1.45; color: var(--accent); margin-bottom: 0.6em; }
.panel p + p { margin-top: 0.4em; }
.panel em { color: var(--accent); font-style: normal; }
.panel strong { color: var(--accent-2); font-weight: normal; }
.panel a { color: var(--accent-2); }
.panel .small, .panel .note { font-size: 0.8em; color: var(--dim); }
.panel.overflow { outline: 3px dashed var(--warn); }

/* title + sign */
.panel.title { padding: 1.1em 1.2em; }
.panel.title .kicker, .panel.sign .kicker { font-family: var(--font-display); font-size: 0.4em; color: var(--accent-3); letter-spacing: 2px; }
.panel.title h1 { font-family: var(--font-display); font-size: 1.1em; line-height: 1.4; margin: 0.6em 0 0.4em; color: var(--ink); text-shadow: 3px 3px 0 rgba(0,0,0,0.6); }
.panel.title .sub { font-size: 1.05em; color: var(--accent-2); }
.panel.title .byline { margin-top: 0.7em; font-size: 0.9em; color: var(--dim); line-height: 1.12; }
.panel.title .byline strong { color: var(--ink); }
.panel.title .start, .panel.sign .sub { margin-top: 1em; font-family: var(--font-display); font-size: 0.38em; color: var(--accent); }
.panel.title .start { animation: blink 1.2s steps(2) infinite; }
.panel.sign { text-align: center; }
.panel.sign .sign-text { font-family: var(--font-display); font-size: 1.15em; line-height: 1.4; margin-top: 0.4em; color: var(--accent); text-shadow: 3px 3px 0 #000; }

/* quote */
.panel.quote blockquote { font-size: 1.15em; line-height: 1.1; }
.panel.quote blockquote::before { content: '\201C'; color: var(--accent-3); }
.panel.quote.marked blockquote::before, .panel.quote.marked blockquote::after { content: none; }
.panel.quote blockquote::after { content: '\201D'; color: var(--accent-3); }
.panel cite { display: block; margin-top: 0.55em; font-style: normal; font-size: 0.8em; color: var(--dim); }
.panel.quote .note { margin-top: 0.6em; }

/* lists */
.panel ul { list-style: none; }
.panel ul li { position: relative; padding-left: 1em; margin: 0.25em 0; }
.panel ul li::before { content: '\25B8'; position: absolute; left: 0.05em; color: var(--accent-2); }
.panel ol { list-style: none; counter-reset: n; }
.panel ol li { counter-increment: n; position: relative; padding-left: 1.7em; margin: 0.3em 0; }
.panel ol li::before { content: counter(n, decimal-leading-zero); position: absolute; left: 0; top: 0.2em;
  font-family: var(--font-display); font-size: 0.45em; color: var(--accent-3); }

/* media: image / embed / video */
.panel.media { display: flex; flex-direction: column; padding: 0; }
.panel .bar { flex: 0 0 auto; display: flex; justify-content: space-between; align-items: center; gap: 12px;
  font-family: var(--font-display); font-size: 10px; letter-spacing: 1px; padding: 7px 10px; color: var(--hud-ink); background: rgba(0,0,0,0.5); }
.panel .bar a { color: var(--accent-2); text-decoration: none; }
.panel .screen { flex: 1 1 auto; min-height: 0; position: relative; overflow: hidden; background: #000; display: flex; align-items: center; justify-content: center; }
.panel .screen img, .panel .screen video { width: 100%; height: 100%; object-fit: contain; display: block; }
.panel .screen.fit-cover img { object-fit: cover; }
.panel .screen.fit-pixel img { image-rendering: pixelated; }
.panel.onebit .screen img, .tile.onebit img { filter: grayscale(1) contrast(4) brightness(1.15); image-rendering: pixelated; }
.panel .caption { flex: 0 0 auto; font-size: 22px; line-height: 1.1; padding: 8px 12px; color: var(--dim); background: rgba(0,0,0,0.55); }
.panel .live { color: var(--accent-3); animation: blink 1.4s steps(2) infinite; }
.panel.embed .screen { display: block; background: #fff; }
.panel.embed iframe { border: 0; transform-origin: 0 0; display: block; }
body.embed-full #panels { z-index: 45; }
.panel.embed.growing { transition: left 0.8s steps(10), top 0.8s steps(10), width 0.8s steps(10), height 0.8s steps(10), border-width 0.8s; }
.panel.embed.fullscreen .bar, .panel.embed.fullscreen .caption { display: none; }
.panel.embed.fullscreen { left: 0 !important; top: 0 !important; width: 1280px !important; height: var(--vp-h) !important; border: 0; z-index: 25; }
.panel.embed.fullscreen .screen { position: absolute; inset: 0; background: #000; }

/* gallery: 2-3 images side by side, each with its own frame */
.panel.gallery { background: none; border: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.panel.gallery .tiles { flex: 1 1 auto; min-height: 0; display: grid; gap: 16px; }
.panel.gallery .tile { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }

/* speech bubble anchored above a character */
.panel.speech { max-width: 1240px; padding: 0.55em 0.8em 0.6em; overflow: visible; }
.panel.speech .who { font-family: var(--font-display); font-size: 0.34em; color: var(--accent-3); margin-bottom: 0.6em; letter-spacing: 1px; }
.panel.speech blockquote { font-size: 1em; line-height: 1.1; }
.panel.speech .tail { position: absolute; bottom: -14px; width: 0; height: 0;
  border-left: 9px solid transparent; border-right: 9px solid transparent; border-top: 14px solid var(--panel-edge); }
.panel.speech.cramped { font-size: calc(var(--fs) * 0.8); }

/* stats / cards / compare / links */
.stats { display: grid; gap: 0.5em 0.8em; }
.stat { border-left: 3px solid var(--accent-2); padding: 0.15em 0 0.15em 0.5em; }
.stat .k { font-family: var(--font-display); font-size: 0.32em; color: var(--accent-3); letter-spacing: 1px; margin-bottom: 0.4em; }
.stat .v { font-size: 0.95em; line-height: 1.05; }
.stat.flag { border-left-color: var(--warn); } .stat.flag .v { color: var(--warn); }
.cards { display: grid; gap: 0.45em; }
.card { border: 2px solid var(--panel-edge); padding: 0.45em 0.55em; background: rgba(0,0,0,0.3); }
.card .name { font-family: var(--font-display); font-size: 0.42em; color: var(--accent); margin-bottom: 0.3em; }
.card .meta { font-family: var(--font-display); font-size: 0.3em; color: var(--dim); margin-bottom: 0.45em; }
.card p { font-size: 0.85em; line-height: 1.05; }
.compare { display: grid; grid-template-columns: auto 1fr 1fr; gap: 0.25em 0.7em; font-size: 0.9em; }
.compare .h { font-family: var(--font-display); font-size: 0.4em; color: var(--accent-3); padding-bottom: 0.3em; }
.compare .k { color: var(--dim); } .compare .b { color: var(--accent); }
.panel.links li { margin: 0.35em 0; }

/* broken image stand-in */
.missing { width: 100%; height: 100%; min-height: 120px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--font-display); font-size: 12px; color: var(--warn); text-align: center;
  background: repeating-linear-gradient(45deg, #1a1018 0 10px, #24141e 10px 20px); }
.missing span { font-family: var(--font-body); font-size: 20px; color: var(--dim); }

/* ---------- frames (theme.css restyles these freely) ---------- */
.frame-none { background: none; border: 0; box-shadow: none; }
.frame-panel { box-shadow: 4px 4px 0 rgba(0,0,0,0.55); }
.frame-title { box-shadow: 6px 6px 0 rgba(0,0,0,0.6); }
.frame-sign { box-shadow: 6px 6px 0 rgba(0,0,0,0.6); }
.frame-monitor { border: 10px solid #3a3a46; border-radius: 6px; box-shadow: inset 0 0 0 2px #15151c, 0 0 0 2px #0c0c12, 6px 6px 0 rgba(0,0,0,0.55); background: #111; }
.frame-poster { border: 8px solid #e8dcc0; background: #e8dcc0; box-shadow: 5px 5px 0 rgba(0,0,0,0.45); }
.frame-poster .bar { color: #3a2a1a; background: transparent; }
.frame-poster .caption { color: #3a2a1a; background: transparent; }
.frame-window { border: 2px solid #fff; border-right-color: #404040; border-bottom-color: #404040; background: #c0c0c0; box-shadow: 1px 1px 0 #000; padding: 3px; }
.frame-window .bar { background: linear-gradient(90deg, #000080, #1084d0); color: #fff; font-size: 9px; }
.frame-window .caption { background: #c0c0c0; color: #000; }
.frame-plaque { border: 6px double #b08a3a; background: #2a1e10; box-shadow: 4px 4px 0 rgba(0,0,0,0.55); }
.frame-bubble { background: var(--panel-bg); border: 3px solid var(--panel-edge); box-shadow: 4px 4px 0 rgba(0,0,0,0.5); }

/* ---------- overlays ---------- */
#preloader { position: absolute; inset: 0; z-index: 90; background: #000; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; font-family: var(--font-display); color: var(--accent); }
#preloader .pl-title { font-size: 18px; animation: blink 1s steps(2) infinite; }
#preloader .pl-outer { width: 420px; height: 22px; border: 3px solid var(--accent); padding: 3px; }
#preload-bar { height: 100%; width: 0; background: var(--accent); transition: width 0.15s steps(4); }
#preload-status { font-size: 10px; color: var(--dim); }
#blackout { position: absolute; inset: 0; z-index: 100; background: #000; cursor: none; }
#debug { position: absolute; left: 8px; bottom: 8px; z-index: 110; max-width: 1260px; font-family: monospace; font-size: 12px; color: #0f0; background: rgba(0,0,0,0.8); padding: 4px 8px; }
body.debug .panel { outline: 1px dashed #f0f; }

@keyframes blink { 50% { opacity: 0; } }
@keyframes materialize { 0% { opacity: 0; clip-path: inset(48% 0 48% 0); } 60% { opacity: 1; clip-path: inset(8% 0 8% 0); } 100% { opacity: 1; clip-path: inset(-20px -20px -20px -20px); } }
@keyframes zoomfrom { 0% { opacity: 0; transform: scale(0.06); } 30% { opacity: 1; } 100% { opacity: 1; transform: scale(1); } }
@keyframes dematerialize { to { opacity: 0; clip-path: inset(50% 0 50% 0); } }
@keyframes badge { 0% { transform: translateX(140%); } 15%, 85% { transform: translateX(0); } 100% { transform: translateX(140%); } }

@media (prefers-reduced-motion: reduce) {
  .panel, .panel.out, #badge.show { animation: none !important; }
  #hud-mark, .panel.title .start, #dialogue-text.typing::after { animation: none; }
}
