/* ────────────────────────────────────────────────────────────────────────────
 * kalicki.sh — pure terminal aesthetic. Three phosphor themes, CRT overlay,
 * 1.06 s cursor blink (CRT-accurate), grey ghost completions.
 * ──────────────────────────────────────────────────────────────────────────── */

:root, body[data-theme="green"] {
  --bg: #060a07;
  --bg-deep: #030504;
  --fg: #37ff75;
  --bright: #b6ffc9;
  --dim: #1f9c50;
  --dimmer: rgba(55, 255, 117, 0.28);
  --err: #ff6b5e;
  --warn: #ffd166;
  --link: #7ad7ff;
  --glow: rgba(55, 255, 117, 0.35);
}
body[data-theme="amber"] {
  --bg: #0b0703;
  --bg-deep: #060402;
  --fg: #ffb000;
  --bright: #ffe0a3;
  --dim: #a06d00;
  --dimmer: rgba(255, 176, 0, 0.28);
  --err: #ff6b5e;
  --warn: #ffd166;
  --link: #ffd166;
  --glow: rgba(255, 176, 0, 0.32);
}
body[data-theme="ice"] {
  --bg: #050810;
  --bg-deep: #02040a;
  --fg: #cfe6ff;
  --bright: #ffffff;
  --dim: #5f7ea6;
  --dimmer: rgba(207, 230, 255, 0.25);
  --err: #ff6b5e;
  --warn: #ffd166;
  --link: #7ad7ff;
  --glow: rgba(160, 205, 255, 0.3);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg-deep);
}

body {
  font-family: "IBM Plex Mono", "JetBrains Mono", "Cascadia Code", ui-monospace,
               "Fira Code", Menlo, Consolas, "DejaVu Sans Mono", monospace;
  font-size: 15px;
  line-height: 1.5;
  color: var(--fg);
  background: radial-gradient(ellipse at 50% 0%, var(--bg) 55%, var(--bg-deep) 100%);
  text-shadow: 0 0 8px var(--glow);
  overflow: hidden;
}

::selection { background: var(--fg); color: var(--bg); text-shadow: none; }

a { color: var(--link); text-decoration: underline; text-underline-offset: 3px; }
a:hover { color: var(--bright); }

/* ── the screen ──────────────────────────────────────────────────────── */
.screen {
  position: relative;
  height: 100dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 22px 26px 2.5em; /* small gap below the prompt, like a real TTY */
  scrollbar-width: thin;
  scrollbar-color: var(--dim) transparent;
}
.screen::-webkit-scrollbar { width: 8px; }
.screen::-webkit-scrollbar-thumb { background: var(--dim); }
.output { max-width: 110ch; flex: 1 0 auto; } /* stretch → prompt stays glued to the bottom */

.line { white-space: pre-wrap; word-break: break-word; min-height: 1.5em; }
.dim   { color: var(--dim); }
.bright{ color: var(--bright); }
.err   { color: var(--err); }
.warn  { color: var(--warn); }
.ok    { color: var(--bright); font-weight: 700; }

/* "you didn't say the magic word" — jurassic denial, flashing like 1993 */
.jp-deny {
  color: var(--err);
  font-weight: 700;
  letter-spacing: 1px;
  animation: deny-flash 0.36s steps(2) 7;
}
@keyframes deny-flash {
  0%, 49%   { color: var(--err); }
  50%, 100% { color: var(--bright); }
}

/* CRT power-on: the tube ignites — thin bright line, then full frame */
.screen.power-on { animation: crt-on 0.5s ease-out; }
@keyframes crt-on {
  0%   { transform: scale(0.55, 0.004); filter: brightness(7); }
  38%  { transform: scale(1, 0.004);    filter: brightness(7); }
  62%  { transform: scale(1, 1);        filter: brightness(2.4); }
  100% { transform: scale(1, 1);        filter: brightness(1); }
}

/* CRT power-off: the frame collapses back into the line */
.screen.power-off { animation: crt-off 0.55s ease-in forwards; }
@keyframes crt-off {
  0%   { transform: scale(1, 1);        filter: brightness(1); }
  35%  { filter: brightness(2.4); }
  65%  { transform: scale(1, 0.005);    filter: brightness(7); }
  100% { transform: scale(0.35, 0.002); filter: brightness(9); opacity: 0; }
}
.tag   { color: var(--link); }
.dir   { color: var(--bright); font-weight: 700; }
.file  { color: var(--fg); }
.ls-row { white-space: pre-wrap; word-spacing: 1.2em; line-height: 1.9; }
.kv { margin: 2px 0; }

code {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--dimmer);
  padding: 0 4px;
  border-radius: 2px;
  text-shadow: none;
  color: var(--bright);
}

/* ── banner ──────────────────────────────────────────────────────────── */
.banner, .banner-sub {
  white-space: pre;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.25;
  color: var(--bright);
}
.banner-sub { margin: 4px 0 8px; letter-spacing: 0.5px; }

/* ── prompt line ─────────────────────────────────────────────────────── */
.prompt-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  opacity: 0.55;
  transition: opacity 0.15s;
}
.prompt-line.focused { opacity: 1; }
.prompt { color: var(--bright); font-weight: 700; white-space: pre; }
.echoed .prompt-dim { color: var(--dim); }
.echoed .cmd { color: var(--fg); }

#mirror { white-space: pre-wrap; word-break: break-word; }

/* CRT-accurate cursor: 1.06 s blink */
.cursor {
  display: inline-block;
  width: 0.62em;
  height: 1.15em;
  vertical-align: text-bottom;
  background: var(--fg);
  color: var(--bg);
  animation: blink 1.06s steps(1) infinite;
}
.cursor.steady { animation: none; }
.cursor.flash { animation: accept-flash 0.18s steps(2); }

@keyframes blink { 0%, 49.9% { opacity: 1; } 50%, 100% { opacity: 0; } }
@keyframes accept-flash {
  0% { background: var(--bright); }
  50% { background: var(--dim); }
  100% { background: var(--fg); }
}

/* grey ghost completion — flickers in like a dying fluorescent tube */
.ghost {
  color: var(--dim);
  opacity: 0.6;
  animation: ghost-in 0.28s steps(4);
}
@keyframes ghost-in {
  0%   { opacity: 0; }
  30%  { opacity: 0.9; }
  45%  { opacity: 0.15; }
  65%  { opacity: 0.75; }
  100% { opacity: 0.6; }
}

/* ── hidden keyboard capture input ───────────────────────────────────── */
#kbd {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 2px;
  height: 2px;
  opacity: 0;
  border: none;
  padding: 0;
  font-size: 16px; /* stops iOS from zooming */
  background: transparent;
  color: transparent;
  caret-color: transparent;
}

.tap-hint {
  position: fixed;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 14px;
  border: 1px solid var(--dim);
  background: var(--bg);
  color: var(--dim);
  font-size: 13px;
  z-index: 30;
  cursor: pointer;
  animation: blink 1.06s steps(1) infinite;
}

.noscript {
  padding: 2rem;
  max-width: 60ch;
  margin: 0 auto;
}

/* ── markdown documents ──────────────────────────────────────────────── */
.doc {
  max-width: 92ch;
  margin: 10px 0 14px;
  padding: 6px 0 6px 18px;
  border-left: 2px solid var(--dimmer);
  text-shadow: none;
}
.doc h1, .doc h2, .doc h3, .doc h4 {
  color: var(--bright);
  margin: 1.1em 0 0.4em;
  line-height: 1.3;
  text-shadow: 0 0 8px var(--glow);
}
.doc h1:first-child, .doc h2:first-child { margin-top: 0.2em; }
.doc h1 { font-size: 1.35em; border-bottom: 1px dashed var(--dimmer); padding-bottom: 0.25em; }
.doc h2 { font-size: 1.15em; }
.doc h3 { font-size: 1em; text-transform: uppercase; letter-spacing: 1px; }
.doc p { margin: 0.5em 0; }
.doc ul, .doc ol { margin: 0.5em 0; padding-left: 1.6em; }
.doc li { margin: 0.2em 0; }
.doc blockquote {
  margin: 0.7em 0;
  padding: 2px 12px;
  border-left: 3px solid var(--dim);
  color: var(--dim);
  font-style: italic;
}
.doc hr { border: none; border-top: 1px dashed var(--dimmer); margin: 1em 0; }
.doc img { max-width: 100%; border: 1px solid var(--dimmer); }
.doc strong { color: var(--bright); }

.doc pre.code {
  position: relative;
  margin: 0.8em 0;
  padding: 12px 14px;
  overflow-x: auto;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid var(--dimmer);
  line-height: 1.45;
}
.doc pre.code::before {
  content: "┌─ " attr(data-lang);
  display: block;
  color: var(--dim);
  font-size: 11px;
  margin: -12px -14px 8px;
  padding: 2px 10px;
  border-bottom: 1px solid var(--dimmer);
}
.doc pre.code code { background: none; border: none; padding: 0; color: var(--fg); }

.doc table { border-collapse: collapse; margin: 0.8em 0; font-size: 0.95em; }
.doc th, .doc td { border: 1px solid var(--dimmer); padding: 4px 12px; text-align: left; }
.doc th { color: var(--bright); background: rgba(255, 255, 255, 0.05); }

.post-head { margin: 6px 0; }
.post-title { color: var(--bright); font-size: 1.25em; font-weight: 700; }

/* ── pager (man pages) ───────────────────────────────────────────────── */
.pager {
  max-width: 100ch;
  margin: 10px 0;
  border: 1px solid var(--dim);
  background: rgba(0, 0, 0, 0.35);
}
.pager-title {
  padding: 3px 12px;
  background: var(--fg);
  color: var(--bg);
  font-weight: 700;
  text-shadow: none;
}
.pager-body {
  position: relative;
  overflow: hidden;
  max-height: 60vh;
  padding: 10px 16px;
  transition: transform 0.12s linear;
}
.pager-line { min-height: 1.4em; }
.pager-hint {
  padding: 3px 12px;
  color: var(--dim);
  border-top: 1px solid var(--dimmer);
  font-size: 0.85em;
}

/* ── CRT overlay: scanlines + rolling band + vignette ────────────────── */
.crt-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 20;
  display: none;
}
body.crt .crt-overlay { display: block; }

body.crt .crt-overlay::before {
  /* scanlines */
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.22) 0px,
    rgba(0, 0, 0, 0.22) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: multiply;
}
body.crt .crt-overlay::after {
  /* vignette + faint screen curvature shading */
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at center, transparent 58%, rgba(0, 0, 0, 0.42) 100%);
}
/* rolling refresh band */
body.crt::after {
  content: "";
  position: fixed;
  left: 0;
  right: 0;
  top: -20vh;
  height: 16vh;
  z-index: 21;
  pointer-events: none;
  background: linear-gradient(to bottom, transparent, var(--glow), transparent);
  opacity: 0.05;
  animation: roll 9s linear infinite;
}
@keyframes roll {
  0% { transform: translateY(0); }
  100% { transform: translateY(145vh); }
}
/* the whole screen breathes, very subtly */
body.crt .screen { animation: crt-breathe 4.2s ease-in-out infinite; }
@keyframes crt-breathe {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.965; }
}

/* ── responsive ──────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  body { font-size: 13px; }
  .screen { padding: 14px 12px 2.5em; }
  .banner { font-size: 9px; }
  .pager-body { max-height: 55vh; }
  .ls-row { word-spacing: 0.8em; }
}

@media (prefers-reduced-motion: reduce) {
  .cursor, .ghost, body.crt::after, body.crt .screen, .tap-hint,
  .screen.power-on, .screen.power-off, .jp-deny { animation: none !important; }
  .pager-body { transition: none; }
}
