/* ============================================================
   jonathantinnes.com — brutalist terminal, amber phosphor CRT
   No webfonts, no external requests. Everything below is CSS.
   ============================================================ */

:root {
  --amber:       #ffb000;
  --amber-hot:   #ffd479;
  --amber-dim:   #b87c12;
  --amber-ghost: #6b4708;
  --bg:          #0b0906;
  --bg-screen:   #100c07;
  --bezel:       #17140f;
  --glow:        0 0 1px currentColor, 0 0 6px rgba(255, 176, 0, .38);
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Monaco,
          "Cascadia Mono", "Roboto Mono", Consolas, "Liberation Mono", monospace;
  --pad: clamp(16px, 3.5vw, 44px);
  --caret-glow: rgba(255,176,0,.6);
}

/* `theme green` / `theme white`. Only the phosphor changes; warn and err
   stay hot so they still read as warnings on any tube. */
:root[data-phosphor="green"] {
  --amber:       #41ff7d;
  --amber-hot:   #b8ffcc;
  --amber-dim:   #22a54c;
  --amber-ghost: #11592a;
  --bg-screen:   #07100a;
  --glow:        0 0 1px currentColor, 0 0 6px rgba(65, 255, 125, .34);
  --caret-glow:  rgba(65,255,125,.6);
}
:root[data-phosphor="white"] {
  --amber:       #e8e4d8;
  --amber-hot:   #ffffff;
  --amber-dim:   #9a958a;
  --amber-ghost: #56534c;
  --bg-screen:   #0d0d0c;
  --glow:        0 0 1px currentColor, 0 0 6px rgba(232, 228, 216, .28);
  --caret-glow:  rgba(232,228,216,.55);
}

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

html { height: 100%; }

body {
  /* --vvh tracks visualViewport; the keyboard shrinks it on iOS */
  height: var(--vvh, 100%);
  margin: 0;
  background: var(--bg);
  color: var(--amber);
  font-family: var(--mono);
  font-size: clamp(12.5px, 1.05vw + 8px, 16px);
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeSpeed;
}

body {
  display: grid;
  place-items: stretch;
  padding: clamp(0px, 2vw, 28px);
  /* faint room light behind the monitor */
  background-image: radial-gradient(120% 90% at 50% 40%, #171009 0%, #0b0906 60%, #060504 100%);
}

/* ---------- bezel + screen -------------------------------- */

.bezel {
  position: relative;
  min-height: 0;
  border-radius: clamp(8px, 1.4vw, 20px);
  background: var(--bezel);
  box-shadow:
    0 0 0 1px #241f16,
    0 24px 70px -20px rgba(0,0,0,.9),
    inset 0 1px 0 rgba(255,255,255,.04);
  padding: clamp(6px, 1vw, 14px);
  overflow: hidden;
}

.screen {
  position: relative;
  height: 100%;
  min-height: 0;
  border-radius: clamp(6px, 1.1vw, 14px);
  background:
    radial-gradient(130% 120% at 50% 50%, #14100a 0%, #0c0906 70%, #080605 100%);
  overflow: hidden;
  /* the illusion of glass curvature */
  box-shadow:
    inset 0 0 60px rgba(0,0,0,.95),
    inset 0 0 160px rgba(0,0,0,.6),
    inset 0 0 2px rgba(255,176,0,.10);
  transform-origin: center center;
  will-change: transform, filter;
}

.crt-content {
  position: absolute;
  inset: 0;
  padding: var(--pad);
  display: flex;
  flex-direction: column;
  gap: .35em;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--amber-ghost) transparent;
  overscroll-behavior: contain;
}
.crt-content::-webkit-scrollbar { width: 8px; }
.crt-content::-webkit-scrollbar-thumb {
  background: var(--amber-ghost);
  border-radius: 0;
}

/* ---------- typography ------------------------------------ */

.output { white-space: pre-wrap; word-break: break-word; }

.line {
  margin: 0;
  min-height: 1.5em;
  text-shadow: var(--glow);
  /* chromatic fringing, barely there */
  filter: drop-shadow(.6px 0 0 rgba(255, 60, 0, .22))
          drop-shadow(-.6px 0 0 rgba(0, 190, 255, .10));
}
.line.blank { min-height: .75em; }

/* box-drawing rows must touch, or the frame has holes in it */
.line.boxline {
  line-height: 1;
  min-height: 1em;
  letter-spacing: 0;
}

.dim     { color: var(--amber-dim); }
.ghost   { color: var(--amber-ghost); }
.hot     { color: var(--amber-hot); font-weight: 600; }
.warn    { color: #ff7a2f; }
.echo    { color: var(--amber-dim); }
.err     { color: #ff5a3c; }
.key     { color: var(--amber-hot); }

.line a, .crt-content a {
  color: var(--amber-hot);
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}
.line a:hover { background: var(--amber); color: #0b0906; text-decoration: none; }

/* the hidden entry in `ls -a` — present, but unwell */
button.runnable {
  appearance: none;
  border: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
button.runnable:active,
button.runnable:focus-visible { background: var(--amber); color: var(--bg); outline: none; }

.corrupt {
  color: var(--amber-hot);
  animation: corrupt 5.5s steps(1, end) infinite;
}
@keyframes corrupt {
  0%, 92%, 100% { opacity: 1; letter-spacing: 0; }
  93%  { opacity: .35; letter-spacing: .5px; }
  95%  { opacity: 1; }
  96%  { opacity: .55; letter-spacing: -.4px; }
  97%  { opacity: 1; }
}

/* ordinary tappable tokens: help rows, files, projects */
button.tap {
  color: var(--amber-hot);
  text-shadow: inherit;
  text-decoration: underline dotted;
  text-decoration-color: var(--amber-ghost);
  text-underline-offset: 3px;
}
button.tap.dir { color: var(--amber-dim); }
button.tap:hover { background: var(--amber); color: var(--bg); text-decoration: none; }

/* the konami code */
body.overclock .screen { filter: brightness(1.3) saturate(1.5) contrast(1.1); transition: filter .4s; }
body.overclock .line { text-shadow: 0 0 2px currentColor, 0 0 14px currentColor; }

/* ---------- prompt ---------------------------------------- */

.prompt-line {
  display: flex;
  align-items: baseline;
  gap: .65ch;
  margin-top: .2em;
  padding-bottom: 2em;
}
.prompt-line[hidden] { display: none; }

.ps1 {
  flex: none;
  color: var(--amber-dim);
  text-shadow: var(--glow);
  user-select: none;
}

.input-wrap { position: relative; flex: 1 1 auto; display: flex; min-width: 0; }

#input {
  flex: 1 1 auto;
  min-width: 0;
  background: transparent;
  border: 0;
  outline: 0;
  padding: 0;
  margin: 0;
  color: var(--amber);
  font: inherit;
  letter-spacing: inherit;
  caret-color: transparent;
  text-shadow: var(--glow);
}
#input::selection { background: var(--amber); color: #0b0906; }

.caret {
  position: absolute;
  top: .1em;
  left: 0;
  width: .62ch;
  height: 1.15em;
  background: var(--amber);
  box-shadow: 0 0 8px var(--caret-glow);
  pointer-events: none;
  animation: blink 1.06s steps(1, end) infinite;
}
.caret.typing { animation: none; opacity: 1; }
@keyframes blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }

/* ---------- CRT overlays ---------------------------------- */

.scanlines, .flicker, .vignette, .glare {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.scanlines {
  background: repeating-linear-gradient(
    to bottom,
    rgba(0,0,0,0) 0px,
    rgba(0,0,0,0) 1.5px,
    rgba(0,0,0,.30) 2px,
    rgba(0,0,0,.30) 3px
  );
  mix-blend-mode: multiply;
  opacity: .8;
}

/* slow rolling refresh band */
.flicker {
  background: linear-gradient(
    to bottom,
    rgba(255,220,150,0) 0%,
    rgba(255,220,150,.035) 45%,
    rgba(255,220,150,.055) 50%,
    rgba(255,220,150,.035) 55%,
    rgba(255,220,150,0) 100%
  );
  height: 40%;
  inset: auto 0 auto 0;
  animation: roll 7.5s linear infinite, mains 4.1s ease-in-out infinite;
}
@keyframes roll { from { transform: translateY(-110%); } to { transform: translateY(360%); } }
@keyframes mains { 0%,100% { opacity: .85; } 43% { opacity: 1; } 47% { opacity: .55; } 51% { opacity: .95; } }

.vignette {
  background:
    radial-gradient(118% 108% at 50% 50%,
      rgba(0,0,0,0) 46%,
      rgba(0,0,0,.42) 78%,
      rgba(0,0,0,.88) 100%);
}

/* glass reflection, upper-left */
.glare {
  background: linear-gradient(148deg,
    rgba(255,255,255,.055) 0%,
    rgba(255,255,255,.018) 16%,
    rgba(255,255,255,0) 38%);
}

/* ---------- the degauss ----------------------------------- */

.whiteout {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 50;
}

.bezel.degauss .screen {
  animation: degauss 1500ms cubic-bezier(.7,0,.2,1) forwards;
}
.bezel.degauss .scanlines { animation: scan-panic 1500ms steps(2, end) forwards; }
.bezel.degauss .whiteout  { animation: blowout 1500ms ease-in forwards; }

@keyframes degauss {
  0%   { transform: none; filter: none; }
  12%  { transform: translate(-5px, 2px) skewX(-2.2deg); filter: hue-rotate(-28deg) saturate(2.4) brightness(1.25); }
  20%  { transform: translate(6px, -3px) skewX(3deg);    filter: hue-rotate(34deg) saturate(3) brightness(1.1); }
  30%  { transform: translate(-3px, 1px) skewX(-1deg);   filter: hue-rotate(-12deg) saturate(1.6) brightness(1.5); }
  42%  { transform: none; filter: brightness(2.2) contrast(1.4); }
  62%  { transform: scale(1.02, .28); filter: brightness(4) contrast(2); }
  78%  { transform: scale(1.06, .012); filter: brightness(9) contrast(3); }
  88%  { transform: scale(1.12, .004); filter: brightness(14); }
  100% { transform: scale(1.2, .002);  filter: brightness(18); opacity: .9; }
}
@keyframes scan-panic {
  0% { opacity: .8; }
  40% { opacity: .2; transform: translateY(-6px); }
  70% { opacity: .9; transform: translateY(5px); }
  100% { opacity: 0; }
}
@keyframes blowout {
  0%, 68%  { opacity: 0; }
  84%      { opacity: .5; }
  100%     { opacity: 1; }
}

/* ---------- noscript -------------------------------------- */

.noscript {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 1em;
  padding: 2rem;
  text-align: center;
  background: var(--bg);
}
.noscript h1 { font-size: 1.25rem; font-weight: 600; margin: 0; }
.noscript a { color: var(--amber-hot); }

/* ---------- reduced motion -------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .flicker { display: none; }
  .caret { animation: none; }
  .corrupt { animation: none; }
  .scanlines { opacity: .45; }
  .bezel.degauss .screen { animation-duration: 420ms; }
  .bezel.degauss .whiteout { animation-duration: 420ms; }
  .bezel.degauss .scanlines { animation-duration: 420ms; }
}

/* ---------- small screens --------------------------------- */

@media (max-width: 640px) {
  body { padding: 0; }
  .bezel { border-radius: 0; padding: 0; }
  .screen { border-radius: 0; }
  :root { --pad: 16px; }
  /* 16px is the floor that stops iOS zooming on input focus.
     Content above is wrapped to the ~34 columns this leaves. */
  html, body { font-size: 16px; }
  .scanlines { background-size: 100% 3px; opacity: .55; }
}

/* ---------- quick commands (touch only) -------------------- */

.chips {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: none;
  gap: 8px;
  padding: 10px var(--pad) calc(10px + env(safe-area-inset-bottom));
  overflow-x: auto;
  scrollbar-width: none;
  background: linear-gradient(to top,
    rgba(11,9,6,.97) 0%, rgba(11,9,6,.92) 62%, rgba(11,9,6,0) 100%);
}
.chips::-webkit-scrollbar { display: none; }
.chips[hidden] { display: none; }

.chip {
  flex: none;
  appearance: none;
  padding: 8px 13px;
  border: 1px solid var(--amber-ghost);
  background: transparent;
  color: var(--amber-dim);
  font: inherit;
  font-size: 13px;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.chip:active { background: var(--amber); border-color: var(--amber); color: var(--bg); }

@media (hover: none) and (pointer: coarse) {
  .chips:not([hidden]) { display: flex; }
  /* keep the prompt clear of the chip bar */
  .crt-content { padding-bottom: 68px; }
  .prompt-line { padding-bottom: .5em; }
}
