/* n4st34.com — monochrome phosphor CRT theme.
   Amber default; add body.green for green phosphor. No external requests. */

/* Self-hosted terminal webfont — loads ONLY if the file is present; if absent
   the browser silently falls back down the monospace stack below. */
:root {
  /* amber phosphor */
  --phos:    #ffb000;
  --phos-hi: #ffd27f;
  --phos-lo: #a6660b;
  --bg:      #0a0700;
  --bg2:     #050300;
  --fontstack: "Cascadia Mono", "DejaVu Sans Mono",
               "Liberation Mono", Consolas, "Courier New", monospace;
  --fs: clamp(9px, 2.15vw, 18px);
  --lh: 1.18;
  --cols: 80;
}

body.green {
  --phos:    #33ff33;
  --phos-hi: #b6ffb6;
  --phos-lo: #1a8a1a;
  --bg:      #020a02;
  --bg2:     #000500;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #000;
  color: var(--phos);
  font-family: var(--fontstack);
  font-size: var(--fs);
  line-height: var(--lh);
  overflow: hidden;
}

/* ---- CRT shell ------------------------------------------------------- */
#crt {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at center, var(--bg) 0%, var(--bg2) 70%, #000 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 1.2em 0.6em;
}

#stagewrap {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: stretch;
  justify-content: center;
  overflow-x: auto;   /* never break the 80-col grid: scroll if too narrow */
  overflow-y: hidden;
}

/* 80-column centered stage */
#stage {
  width: calc(var(--cols) * 1ch);
  min-width: calc(var(--cols) * 1ch);
  max-width: calc(var(--cols) * 1ch);
  height: 100%;
  display: flex;
  flex-direction: column;
  color: var(--phos);
  text-shadow:
    0 0 1px var(--phos),
    0 0 6px rgba(255, 176, 0, 0.35),
    0 0 12px rgba(255, 176, 0, 0.18);
}
body.green #stage {
  text-shadow:
    0 0 1px var(--phos),
    0 0 6px rgba(51, 255, 51, 0.35),
    0 0 12px rgba(51, 255, 51, 0.18);
}

/* ---- terminal output ------------------------------------------------- */
#screen {
  flex: 1 1 auto;
  min-height: calc(25 * var(--lh) * 1em);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.2em 0;
  scrollbar-width: thin;
  scrollbar-color: var(--phos-lo) transparent;
}
#screen::-webkit-scrollbar { width: 6px; }
#screen::-webkit-scrollbar-thumb { background: var(--phos-lo); }
#screen::-webkit-scrollbar-track { background: transparent; }

.row {
  white-space: pre;
  min-height: calc(var(--lh) * 1em);
}

/* SGR intensity / attributes (monochrome) */
.b   { color: var(--phos-hi); font-weight: 700; }
.d   { color: var(--phos-lo); }
.inv { background: var(--phos); color: var(--bg); text-shadow: none; }
.bl  { animation: blink 1.1s steps(1) infinite; }

/* ---- prompt / input line -------------------------------------------- */
#promptline {
  flex: 0 0 auto;
  white-space: pre-wrap;
  word-break: break-all;
  padding: 0.1em 0;
  min-height: calc(var(--lh) * 1em);
}
#promptline.hidden { display: none; }
#pl-prompt { color: var(--phos-hi); }

/* block cursor */
.cursor {
  display: inline-block;
  width: 1ch;
  height: 1em;
  vertical-align: text-bottom;
  background: var(--phos);
  color: transparent;
  animation: cursorblink 1s steps(1) infinite;
}
.cursor.hidden { visibility: hidden; }

/* ---- status line ----------------------------------------------------- */
#statusline {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  gap: 1ch;
  border-top: 1px solid var(--phos-lo);
  padding: 0.15em 0;
  color: var(--phos-lo);
  white-space: nowrap;
  overflow: hidden;
}
#st-left  { color: var(--phos); overflow: hidden; text-overflow: ellipsis; }
#st-right { color: var(--phos-lo); flex: 0 0 auto; }

/* ---- CRT overlays ---------------------------------------------------- */
#scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 20;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0)    0px,
    rgba(0, 0, 0, 0)    2px,
    rgba(0, 0, 0, 0.28) 3px,
    rgba(0, 0, 0, 0.28) 4px
  );
  background-size: 100% 4px;
  mix-blend-mode: multiply;
}

#vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 21;
  background: radial-gradient(
    ellipse at center,
    rgba(0, 0, 0, 0) 55%,
    rgba(0, 0, 0, 0.55) 88%,
    rgba(0, 0, 0, 0.85) 100%
  );
}

#flicker {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 19;
  background: var(--phos);
  opacity: 0.012;
  mix-blend-mode: screen;
  animation: flicker 6s steps(60) infinite;
}

/* ---- keyframes ------------------------------------------------------- */
@keyframes blink {
  0%, 49%  { opacity: 1; }
  50%, 100% { opacity: 0; }
}
@keyframes cursorblink {
  0%, 49%   { opacity: 1; }
  50%, 100% { opacity: 0; }
}
@keyframes flicker {
  0%   { opacity: 0.010; }
  10%  { opacity: 0.022; }
  20%  { opacity: 0.008; }
  30%  { opacity: 0.030; }
  45%  { opacity: 0.012; }
  55%  { opacity: 0.020; }
  70%  { opacity: 0.006; }
  85%  { opacity: 0.026; }
  100% { opacity: 0.014; }
}

/* ---- responsive ------------------------------------------------------ */
@media (max-width: 640px) {
  /* The terminal is a fixed 80-column grid: width = 80ch, and 1ch is ~0.6em in
     every font in --fontstack (Android falls back to generic monospace, same
     ratio). So the grid needs 80 * 0.6 * font-size px of room.
     The old clamp(7px, 2.6vw, 13px) gave ~10.7px on a 412px-wide phone, making
     the grid ~515px - about 100px wider than the viewport, so the left edge was
     clipped and the page opened mid-scroll.
     100vw/52 keeps 80 columns inside the viewport with ~8% headroom for #crt
     padding: 412px -> 7.9px -> ~380px grid. Floor of 6px keeps 320px phones
     legible (295px grid). */
  :root { --fs: clamp(6px, calc(100vw / 52), 13px); }
  #crt  { padding: 0.4em 0.2em; }
}

/* ---- reduced motion -------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  #flicker { animation: none; opacity: 0.008; }
  .bl { animation: none; }
  .cursor { animation: none; }
  #scanlines { background-size: 100% 6px; }
}
