/* PHORDEINSAYN V4 - global tokens and shared components (brief 3.3, 3.4, 4.6, 15) */

/* font-display: block (Sam, 2026-11-11: "no flash of an unstyled page"): scratch words are never shown first in another font and then swapped. The file is 20KB and preloaded. */
@font-face { font-family: "Scratch"; src: url("../fonts/Scratch-Regular.ttf") format("truetype"); font-display: block; }
/* FONTS ARE SETTLED (Sam, 2026-10-28): the scratch font, plus Comic Sans as the readable font with Comic Neue (open licence)
   bundled as its fallback for devices without Comic Sans (Android). It downloads only when "Comic Sans MS" is missing.
   No change pending; keep the readable font as the one variable --font-read below. */
@font-face { font-family: "Comic Neue"; src: url("../fonts/ComicNeue-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Comic Neue"; src: url("../fonts/ComicNeue-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }

:root {
  /* three blacks for depth (master 1) */
  --void: #000000;
  --paper: #0a0a0a;
  --depth: #161616;
  --ink: #f5f3ee;
  --ink-dim: #b9b6b0;
  --line: #f5f3ee;

  /* THE ONE VARIABLE for the readable font (brief 3.4) */
  --font-read: "Comic Sans MS", "Comic Neue", "Chalkboard SE", cursive, sans-serif;
  --font-scratch: "Scratch", var(--font-read);

  --space: clamp(1rem, 3vw, 2.5rem);
  --gutter: 16px;
  --touch: 44px;
  --return-band: calc(var(--touch) + 1.5rem);   /* the Return control's own safe area at the top of internal pages */
}

*, *::before, *::after { box-sizing: border-box; }

html { background: var(--void); color: var(--ink); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;                 /* svh, never dvh, on scrolling pages: a moving mobile browser bar must not relayout the page */
  background: var(--void);
  color: var(--ink);
  font-family: var(--font-read);
  line-height: 1.6;
  overflow-x: clip;                   /* no sideways drift, ever (brief 16.2) */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

img { max-width: 100%; height: auto; display: block; }

/* no browser-blue links, no off-palette focus (brief 3.3 HARD RULE) */
a { color: var(--ink); text-decoration: none; }
a:visited { color: var(--ink); }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

.scratch { font-family: var(--font-scratch); letter-spacing: 0.02em; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* labeled placeholder for missing art (brief 5.3): hidden on the live site, shown with ?dev=1 */
.ph { display: none; }
html[data-dev="1"] .ph {
  display: grid; place-items: center; text-align: center;
  border: 1px dashed var(--ink-dim); color: var(--ink-dim);
  font: 12px/1.3 monospace; padding: 0.5rem; background: var(--depth);
}

/* ---------- Return control (brief 15.1, corrected 2026-10-26) ----------
   TOP-RIGHT everywhere, except Memory detail pages, which use .left (composed with the eye icon).
   It sits in its own band, so it never overlaps artwork: pages add .has-return to reserve --return-band. */
.has-return { padding-top: var(--return-band); }
.return-bar {
  position: fixed; top: max(0.75rem, env(safe-area-inset-top)); right: max(0.75rem, env(safe-area-inset-right));
  z-index: 50; display: flex; gap: 0.5rem; align-items: center;
}
.return-bar.left { right: auto; left: max(0.75rem, env(safe-area-inset-left)); }
.return-btn, .settings-btn {
  min-height: var(--touch); min-width: var(--touch);
  padding: 0 1rem; background: var(--void); border: 2px solid var(--line);
  border-radius: 2px 6px 3px 5px;                 /* slightly uneven, hand-drawn */
  font-family: var(--font-scratch); font-size: 1.1rem;
  display: inline-flex; align-items: center; justify-content: center;
}
.return-btn:hover, .settings-btn:hover { background: var(--depth); }

/* ---------- Settings panel (brief 4.6) ---------- */
.settings-panel {
  position: fixed; top: 4rem; right: 0.75rem; z-index: 60;
  width: min(20rem, calc(100vw - 1.5rem));
  background: var(--paper); border: 2px solid var(--line); padding: 1rem;
}
.settings-panel[hidden] { display: none; }
.settings-panel h2 { margin: 0 0 0.75rem; font: 1.4rem var(--font-scratch); }
.settings-panel label { display: flex; align-items: center; gap: 0.75rem; min-height: var(--touch); cursor: pointer; }
.settings-panel input { width: 1.25rem; height: 1.25rem; accent-color: var(--ink); }
.settings-panel .note { color: var(--ink-dim); font-size: 0.85rem; margin: 0.25rem 0 0; }

/* ---------- Page fade through the Void (master 1.2) ----------
   Leaving: #phd-veil fades in over everything. Arriving: html.veil-in holds black, then lifts. No camera moves. */
#phd-veil {
  position: fixed; inset: 0; z-index: 2147483000; background: #000; opacity: 0; pointer-events: none;
  transition: opacity var(--leave-ms, 320ms) ease-in;
}
#phd-veil.on { opacity: 1; }
@keyframes veilout { to { opacity: 0; } }
html.veil-in::after {
  content: ""; position: fixed; inset: 0; z-index: 2147483000; background: #000; pointer-events: none;
  animation: veilout var(--arrive-ms, 480ms) ease-out both;
}

/* Arriving through the TV (js/enter.js, Sam 2026-10-30): black until the arrival static is drawn over it. The animation is a failsafe only: if the script never runs, this lets go after 3s. */
html.enter-in::before { content: ""; position: fixed; inset: 0; z-index: 2147482500; background: #000; pointer-events: none; animation: enter-in-off 0s 3s forwards; }
@keyframes enter-in-off { to { visibility: hidden; } }

/* ---------- User preferences ---------- */
html[data-contrast="high"] { --ink: #fff; --ink-dim: #e0e0e0; --depth: #222; --line: #fff; }
html[data-contrast="high"] .return-btn,
html[data-contrast="high"] .settings-btn,
html[data-contrast="high"] .settings-panel { border-width: 3px; }

html[data-pause="1"] .ambient { animation-play-state: paused !important; }

html[data-motion="reduced"] *, html[data-motion="reduced"] *::before, html[data-motion="reduced"] *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
  scroll-behavior: auto !important;
}
