/* =====================================================================
   GODLINE · crt.css
   =====================================================================
   Tokens, layout, the CRT layers, and the phosphor tiers.

   The phosphor is set by  data-tier  on <html>:
       0,1  P3 amber      2  P1 green      3  P4 white
   and  data-flash="red"  overrides everything for one reply (WRATHFUL,
   and the 666 egg). Nothing explains the colour to the visitor. That is
   the whole design of it.

   Everything animated is inside a prefers-reduced-motion guard at the
   bottom: the flicker, the tear and the cursor blink go, the scenes
   stay.
   ===================================================================== */

:root {
  --room:        #0A0908;
  --bezel:       #2A2622;
  --bezel-edge:  #3A352F;
  --screen:      #0C0A07;

  /* tier 0-1 · P3 amber */
  --phos:        #FFB000;
  --phos-dim:    #7A5200;
  --phos-glow:   rgba(255, 176, 0, 0.55);

  --scan-alpha:  0.28;
  --chat-size:   22px;
  --window-h:    55vh;
}

/* tier 2 · P1 green */
:root[data-tier="2"] {
  --phos:      #33FF66;
  --phos-dim:  #147A2E;
  --phos-glow: rgba(51, 255, 102, 0.5);
}
/* tier 3 · P4 white */
:root[data-tier="3"] {
  --phos:      #E8F0FF;
  --phos-dim:  #5E7290;
  --phos-glow: rgba(232, 240, 255, 0.5);
}
/* wrath, and the 666 egg · any tier, one reply */
:root[data-flash="red"] {
  --phos:      #FF3B1F;
  --phos-dim:  #7A1C0D;
  --phos-glow: rgba(255, 59, 31, 0.6);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--room);
  color: var(--phos);
  font-family: "VT323", "IBM Plex Mono", ui-monospace, monospace;
  overflow: hidden;
}

/* the room ---------------------------------------------------------- */
body {
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    radial-gradient(120% 90% at 50% 40%, #14120F 0%, var(--room) 70%);
}

/* the monitor -------------------------------------------------------- */
.monitor {
  width: min(1000px, 100%);
  height: min(94vh, 900px);
  background: var(--bezel);
  border-radius: 20px;
  padding: 20px;
  box-shadow:
    0 30px 70px rgba(0, 0, 0, 0.6),
    inset 0 0 0 2px var(--bezel-edge);
  display: flex;
}

.crt {
  position: relative;
  flex: 1;
  min-height: 0;
  background: var(--screen);
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.9);
}

/* --- the CRT layers, over everything, never interactive ------------- */
.crt::after {           /* scanlines */
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, var(--scan-alpha)) 0 1px,
    transparent 1px 3px
  );
  mix-blend-mode: multiply;
}
.crt::before {          /* vignette + fake curvature */
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  border-radius: 14px;
  box-shadow: inset 0 0 120px 30px rgba(0, 0, 0, 0.7);
}
/* the 0.5 Hz brightness flicker */
.crt > .glass {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 6;
  background: var(--phos);
  opacity: 0;
  animation: flicker 2s steps(30) infinite;
}
@keyframes flicker {
  0%, 100% { opacity: 0.008; }
  17%      { opacity: 0.022; }
  43%      { opacity: 0.004; }
  71%      { opacity: 0.018; }
}
/* the tear: one frame of horizontal displacement every 20-40 s */
.crt > .tear {
  position: absolute;
  left: 0; right: 0;
  height: 12%;
  pointer-events: none;
  z-index: 7;
  backdrop-filter: blur(0.4px);
  background: linear-gradient(var(--phos-glow), transparent);
  opacity: 0;
  animation: tear 29s linear infinite;
}
@keyframes tear {
  0%, 96.6%  { opacity: 0; top: 20%; transform: translateX(0); }
  96.8%      { opacity: 0.10; top: 42%; transform: translateX(6px); }
  97.1%      { opacity: 0.06; top: 46%; transform: translateX(-9px); }
  97.4%, 100%{ opacity: 0; top: 60%; transform: translateX(0); }
}

/* the title card ----------------------------------------------------- */
#title {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  white-space: pre;
  text-align: center;
  font-size: clamp(13px, 2.1vw, 20px);
  line-height: 1.7;
  color: var(--phos);
  text-shadow: 0 0 8px var(--phos-glow);
  background: var(--screen);
  padding: 20px;
}

/* `hidden` loses to a display rule, so both of these need the override
   or the title card never goes away. */
#title[hidden] { display: none !important; }
#row[hidden]   { display: none !important; }
#screen { display: contents; }
#screen[hidden] { display: none !important; }

/* the window --------------------------------------------------------- */
.window {
  position: relative;
  height: var(--window-h);
  max-height: 55%;
  flex: none;
  border-bottom: 1px dashed var(--phos-dim);
}
.window canvas {
  display: block;
  width: 100%;
  height: 100%;
}
.window .label {
  position: absolute;
  top: 8px;
  left: 12px;
  font-size: 16px;
  letter-spacing: 0.1em;
  color: var(--phos-dim);
  pointer-events: none;
}
#audioflag {
  position: absolute;
  top: 8px;
  right: 12px;
  font-size: 16px;
  letter-spacing: 0.1em;
  color: var(--phos-dim);
}

/* the line ----------------------------------------------------------- */
.chat {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 12px 18px 14px;
  font-size: var(--chat-size);
  line-height: 1.35;
  text-shadow: 0 0 6px var(--phos-glow);
}
#log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--phos-dim) transparent;
  overscroll-behavior: contain;
}
.line { white-space: pre-wrap; word-break: break-word; margin: 0 0 2px; }
.line.you   { color: var(--phos-dim); text-shadow: none; }
.line.boot  { color: var(--phos-dim); text-shadow: none; letter-spacing: 0.04em; }
.line.god   { color: var(--phos); }
.line.god .prefix { color: var(--phos-dim); }

/* COMMANDS · a block of plain speech. The first line keeps the prefix,
   the rest are indented under it by a prefix of spaces, so the whole
   thing reads as one printout rather than eight replies. */
.line.block { margin: 0; padding-left: 6ch; text-indent: -6ch; }   /* hanging indent: wrapped lines stay under the text, not the prefix */
.line.block .prefix { white-space: pre; display: inline-block; width: 6ch; text-indent: 0; }

/* NIGHTS.LOG · his voice, not God's. Lowercase is allowed here and
   nowhere else on the screen, and it is dimmer so the two registers
   never blur into one. */
.line.log {
  color: var(--phos-dim);
  text-shadow: none;
  text-transform: none;
  max-width: 74ch;
  margin: 0 0 2px;
}
.line.log.head { color: var(--phos); letter-spacing: 0.06em; margin-top: 10px; }

/* PASTORAL · out of character on purpose: no phosphor, no glow, mixed
   case, a readable face. The register break is the signal. */
.line.pastoral {
  color: #D9D4C8;
  text-shadow: none;
  font-family: ui-sans-serif, system-ui, "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  margin: 14px 0;
  padding: 12px 14px;
  border-left: 2px solid #6E675A;
  background: rgba(255, 255, 255, 0.035);
  max-width: 62ch;
}

/* the flicker payload (spec 5, stage 4) */
.flick {
  color: #fff;
  text-shadow: 0 0 10px var(--phos), 0 0 18px var(--phos);
  animation: burn 1.1s steps(2) infinite;
}
@keyframes burn { 50% { opacity: 0.55; } }

/* the prompt row ----------------------------------------------------- */
#row {
  display: flex;
  align-items: baseline;
  gap: 0;
  padding-top: 4px;
  cursor: text;
}
#row .prefix { color: var(--phos-dim); }
#input {
  flex: 1;
  min-width: 0;
  background: none;
  border: 0;
  outline: 0;
  color: var(--phos);
  font: inherit;
  text-shadow: inherit;
  caret-color: transparent;
  padding: 0;
}
/* the block cursor sits after the input and blinks */
#row .cursor {
  display: inline-block;
  width: 0.55em;
  height: 1em;
  background: var(--phos);
  transform: translateY(0.12em);
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* power down --------------------------------------------------------- */
:root[data-off="1"] .chat { opacity: 0; transition: opacity 0.6s 0.3s; }

/* mobile: a 16:9 band and the line takes the rest. The keyboard must
   never cover the last message, so the log is what shrinks. ---------- */
@media (max-width: 720px), (max-height: 560px) {
  body { padding: 0; }
  .monitor {
    height: 100dvh;
    width: 100%;
    border-radius: 0;
    padding: 8px;
  }
  .crt { border-radius: 8px; }
  .window { height: min(56.25vw, 34vh); max-height: 40%; }
  :root { --chat-size: 19px; }
  .chat { padding: 10px 12px 12px; }
  .line.boot { font-size: 0.85em; }   /* the boot block is 40 columns wide */
  .window .label { display: none; }   /* too little room; the scene needs it */
}

/* reduced motion ------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  .crt > .glass,
  .crt > .tear,
  #row .cursor,
  .flick { animation: none; }
  .crt > .tear { display: none; }
  .flick { opacity: 1; }
}
