:root {
  color-scheme: dark;

  --p:        #48ff7a;
  --p-mid:    #27c254;
  --p-dim:    #147a31;
  --p-glow:   rgba(72, 255, 122, 0.42);
  --p-wash:   rgba(72, 255, 122, 0.06);

  --warn:     #ffb02e;
  --warn-dim: rgba(255, 176, 46, 0.5);

  --bg:       #000803;
  --bg-deep:  #000000;

  --mono: "SF Mono", ui-monospace, SFMono-Regular, "JetBrains Mono",
          "Cascadia Mono", Menlo, Consolas, "DejaVu Sans Mono",
          "Liberation Mono", monospace;

  --fs: clamp(0.8rem, 0.62rem + 0.72vw, 0.96rem);
  --lh: 1.65;
  --pad: clamp(1rem, 3.5vw, 2.75rem);
}

:root[data-phosphor="amber"] {
  --p:      #ffb638;
  --p-mid:  #d98a15;
  --p-dim:  #8a560b;
  --p-glow: rgba(255, 182, 56, 0.45);
  --p-wash: rgba(255, 182, 56, 0.06);
  --bg:     #0a0600;

  --warn:     #ff6a45;
  --warn-dim: rgba(255, 106, 69, 0.5);
}

:root[data-phosphor="red"] {
  --p:      #ff2b2b;
  --p-mid:  #c81d1d;
  --p-dim:  #7a1414;
  --p-glow: rgba(255, 43, 43, 0.45);
  --p-wash: rgba(255, 43, 43, 0.06);
  --bg:     #080000;
}

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

html, body { height: 100%; }

body {
  background: var(--bg-deep);
  color: var(--p-mid);
  font-family: var(--mono);
  font-size: var(--fs);
  line-height: var(--lh);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--p); text-decoration: underline; text-underline-offset: 3px; }
a:hover { text-shadow: 0 0 8px var(--p-glow); }

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

::selection { background: var(--p-mid); color: var(--bg-deep); }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.crt {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;

  height: var(--vh, 100%);
  background:
    radial-gradient(ellipse 120% 100% at 50% 50%, var(--p-wash), transparent 62%),
    var(--bg);
  overflow: hidden;
}

.crt__scanlines {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  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
  );
  opacity: 0.55;
  animation: flicker 4.2s steps(1) infinite;
}

.crt__vignette {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: radial-gradient(ellipse 96% 92% at 50% 50%, transparent 52%, rgba(0, 0, 0, 0.85) 100%);
}

.crt::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 22vh;
  z-index: 4;
  pointer-events: none;
  background: linear-gradient(to bottom, transparent, rgba(255, 255, 255, 0.022), transparent);
  animation: roll 7.5s linear infinite;
}

:root[data-crt="off"] .crt__scanlines,
:root[data-crt="off"] .crt::after { display: none; }

@keyframes flicker {
  0%, 100%     { opacity: 0.55; }
  48%          { opacity: 0.55; }
  49%          { opacity: 0.42; }
  50%          { opacity: 0.6; }
  51%          { opacity: 0.5; }
  82%          { opacity: 0.55; }
  83%          { opacity: 0.38; }
  84%          { opacity: 0.55; }
}

@keyframes roll {
  from { transform: translateY(-25vh); }
  to   { transform: translateY(105vh); }
}

.term {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
}

.term__scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--pad) var(--pad) calc(var(--pad) + 2.5rem);
  scrollbar-width: thin;
  scrollbar-color: var(--p-dim) transparent;
}
.term__scroll::-webkit-scrollbar { width: 8px; }
.term__scroll::-webkit-scrollbar-thumb { background: var(--p-dim); }

.term__out { white-space: pre-wrap; word-break: break-word; }
.term__out--static { white-space: normal; }

.line { text-shadow: 0 0 6px var(--p-glow); min-height: 1lh; }
.line--dim  { color: var(--p-dim); text-shadow: none; }
.line--hot  { color: var(--p); text-shadow: 0 0 10px var(--p-glow), 0 0 22px var(--p-glow); }
.line--warn { color: var(--warn); text-shadow: 0 0 8px var(--warn-dim); }
.line--echo { color: var(--p); text-shadow: 0 0 8px var(--p-glow); }
.line--err  { color: var(--warn); text-shadow: 0 0 8px var(--warn-dim); }
.line--gap  { min-height: 1lh; }

.line--board {
  color: var(--p);
  text-shadow: 0 0 10px var(--p-glow);
  letter-spacing: 0.06em;
}

.term__input {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0 0.6ch;
  position: relative;
}
.term__input[hidden] { display: none; }

.term__prompt {
  color: var(--p);
  text-shadow: 0 0 8px var(--p-glow);
  white-space: nowrap;
  flex: none;
}

.term__typed {
  color: var(--p);
  text-shadow: 0 0 8px var(--p-glow);
  white-space: pre-wrap;
  word-break: break-word;
}

.term__caret {
  display: inline-block;
  width: 1ch;
  height: 1lh;
  vertical-align: text-bottom;
  background: var(--p);
  box-shadow: 0 0 10px var(--p-glow);
  animation: blink 1.05s steps(2, start) infinite;
}
.term__caret--off { animation: none; opacity: 0.35; }

@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

.term__field {
  position: absolute;
  inset: 0;
  width: 100%;
  opacity: 0;
  border: 0;
  padding: 0;
  font: inherit;
  color: transparent;
  background: transparent;
  caret-color: transparent;
}
.term__field:focus { outline: none; }

.noscript {
  padding: var(--pad);
  color: var(--p-mid);
}
.noscript p { margin-bottom: 0.8rem; }

.pi {
  position: absolute;
  right: clamp(0.75rem, 2.2vw, 1.5rem);
  bottom: clamp(0.75rem, 2.2vw, 1.5rem);
  z-index: 5;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 0;
  background: none;
  color: var(--p-mid);
  font-size: 1.7rem;
  line-height: 1;

  text-decoration: none;
  text-shadow: 0 0 10px var(--p-glow);
  transition: color 0.2s ease, text-shadow 0.2s ease, transform 0.2s ease;
  animation: breathe 3.4s ease-in-out infinite;
}
.pi:hover, .pi:focus-visible {
  color: var(--p);
  text-shadow: 0 0 14px var(--p-glow), 0 0 28px var(--p-glow);
  transform: scale(1.12);
  animation: none;
}
.pi:active { transform: scale(0.96); }

@keyframes breathe {
  0%, 100% { opacity: 0.5; }
  50%      { opacity: 1; }
}

@media (max-width: 520px) {
  .pi { width: 44px; height: 44px; font-size: 1.5rem; }
}

.screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: clamp(1rem, 4vw, 3rem);
}

.screen--in {
  animation: screen-in 0.45s ease;
}
.screen[hidden] { display: none; }

@keyframes screen-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.screen__backdrop {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.86), #000 78%);
}

.screen__frame {
  position: relative;
  width: min(960px, 100%);
}

.screen--in .screen__frame {
  animation: screen-on 0.6s cubic-bezier(0.2, 0.9, 0.3, 1);
}

@keyframes screen-on {
  0%   { transform: scaleY(0.004) scaleX(0.7); filter: brightness(6); }
  45%  { transform: scaleY(0.004) scaleX(1);   filter: brightness(6); }
  100% { transform: scaleY(1) scaleX(1);       filter: brightness(1); }
}

.screen__tube {
  position: relative;
  aspect-ratio: 16 / 9;
  max-height: 74vh;
  margin-inline: auto;
  overflow: hidden;
  border-radius: 10px;
  background: #000;
  border: 1px solid var(--p-dim);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.9),
    0 0 42px var(--p-wash),
    0 30px 90px -30px #000;
}

.screen__video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

.screen__grain {
  position: absolute;
  inset: -50%;
  z-index: 2;
  pointer-events: none;
  opacity: 0.32;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='220' height='220' filter='url(%23n)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  animation: grain 0.7s steps(1) infinite;
  will-change: transform;
}

@keyframes grain {
  0%   { transform: translate(0, 0); }
  12%  { transform: translate(-6%, -4%); }
  25%  { transform: translate(4%, -7%); }
  37%  { transform: translate(-3%, 5%); }
  50%  { transform: translate(7%, 2%); }
  62%  { transform: translate(-7%, -2%); }
  75%  { transform: translate(2%, 6%); }
  87%  { transform: translate(-4%, -6%); }
  100% { transform: translate(0, 0); }
}

.screen__scan {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  opacity: 0.5;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0)    0px,
    rgba(0, 0, 0, 0)    2px,
    rgba(0, 0, 0, 0.35) 3px,
    rgba(0, 0, 0, 0.35) 4px
  );
}

.screen__glass {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background:
    linear-gradient(118deg, rgba(255, 255, 255, 0.07) 0%, transparent 34%),
    radial-gradient(ellipse 92% 88% at 50% 50%, transparent 54%, rgba(0, 0, 0, 0.78) 100%);
}

.screen__caption {
  position: relative;
  z-index: 5;
  margin-top: 1rem;
  text-align: center;
  color: var(--p-dim);
  font-size: 0.78rem;
}

.screen__close {
  position: absolute;
  top: -0.5rem;
  right: -0.5rem;
  z-index: 6;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--p-dim);
  background: #000;
  color: var(--p-mid);
  font-size: 1.5rem;
  line-height: 1;
  transition: color 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}
.screen__close:hover,
.screen__close:focus-visible {
  color: var(--p);
  border-color: var(--p);
  transform: scale(1.08);
}

@media (max-width: 560px) {
  .screen__close { top: -0.25rem; right: -0.25rem; width: 36px; height: 36px; }
  .screen__caption { font-size: 0.72rem; }
}

:focus-visible { outline: 2px solid var(--p); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .crt__scanlines { animation: none; }
  .crt::after { display: none; }
  .pi { animation: none; opacity: 0.85; }
  .term__caret { animation: none; }
  .screen__grain { animation: none; opacity: 0.14; }
  .screen--in,
  .screen--in .screen__frame { animation: none; }
  * { transition-duration: 0.001ms !important; }
}
