:root {
  color-scheme: dark;
  --ink: #ffb000;
  --glow: rgba(255, 176, 0, 0.65);
  --bg: #000;
}

html[data-hue="amber"] {
  --ink: #ffb000;
  --glow: rgba(255, 176, 0, 0.65);
}

html[data-hue="green"] {
  --ink: #9ae6a0;
  --glow: rgba(154, 230, 160, 0.55);
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100dvh;
  font-family: "Courier New", Courier, "Lucida Console", ui-monospace, monospace;
  font-size: clamp(13px, 3.5vw, 18px);
  line-height: 1.45;
  text-shadow: 0 0 8px var(--glow);
  user-select: none;
}

button,
input,
a {
  font: inherit;
  color: inherit;
  text-shadow: inherit;
}

.crt {
  min-height: 100dvh;
  position: relative;
  background: #000;
  box-shadow: inset 0 0 22vw 7vw rgba(0, 0, 0, 0.9);
}

.crt::before,
.beam,
.vignette {
  pointer-events: none;
}

.crt::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 4;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.22) 0 1px,
    transparent 1px 3px
  );
  animation: flicker 0.12s infinite;
}

.beam {
  position: fixed;
  left: 0;
  right: 0;
  height: 22vh;
  z-index: 3;
  background: linear-gradient(
    to bottom,
    transparent,
    rgba(255, 255, 255, 0.035),
    transparent
  );
  animation: beam 7.5s linear infinite;
}

.vignette {
  position: fixed;
  inset: 0;
  z-index: 5;
  background: radial-gradient(ellipse at center, transparent 58%, rgba(0, 0, 0, 0.5) 100%);
}

#memory-glitch {
  position: fixed;
  inset: 0;
  z-index: 30;
  pointer-events: none;
  mix-blend-mode: screen;
  overflow: hidden;
}

#memory-glitch.hidden {
  display: none;
}

#memory-glitch .burst,
#memory-glitch video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#memory-glitch .burst {
  background:
    repeating-linear-gradient(
      90deg,
      transparent 0 6px,
      rgba(255, 255, 255, 0.45) 6px 8px
    ),
    repeating-linear-gradient(
      0deg,
      #ffb000 0 2px,
      #1a1a1a 2px 5px,
      #9ae6a0 5px 7px,
      #000 7px 11px
    );
  animation: tear 0.07s steps(2, end) infinite;
}

body.is-memory-glitch .crt {
  opacity: 0;
}

.screen {
  position: relative;
  z-index: 6;
  min-height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
  padding:
    max(18px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(18px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

.screen[data-view="gate"] {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

h1.line {
  margin: 0 0 0.55em;
  font-size: inherit;
  font-weight: normal;
}

.line {
  margin: 0 0 0.55em;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.rule {
  overflow-wrap: anywhere;
}

.nowrap {
  white-space: pre;
  overflow-x: auto;
  overflow-wrap: normal;
}

.blink {
  animation: blink 1.05s steps(1, end) infinite;
}

.caret {
  display: inline-block;
  margin-left: 0.15em;
  animation: powerfail 2.6s linear infinite;
}

.term-btn {
  display: block;
  width: 100%;
  margin: 0.35em 0;
  padding: 0.55em 0;
  min-height: 44px;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 0;
  cursor: pointer;
  text-decoration: none;
  touch-action: manipulation;
}

.term-btn:focus-visible,
.term-input:focus-visible,
.gate-btn:focus-visible {
  outline: 1px solid var(--ink);
  outline-offset: 3px;
}

.gate-btn {
  background: transparent;
  border: 0;
  border-radius: 0;
  cursor: pointer;
  padding: 0.6em 0.2em;
  min-height: 44px;
  touch-action: manipulation;
}

.field {
  display: flex;
  flex-wrap: nowrap;
  align-items: baseline;
  gap: 0.35em 0.7em;
  margin: 0.85em 0;
}

.field-label {
  white-space: nowrap;
}

.entry {
  display: flex;
  align-items: baseline;
  flex: 1 1 16ch;
  min-width: 10ch;
  max-width: 36ch;
  gap: 0.15em;
}

.term-input,
textarea {
  user-select: text;
}

.file-cmd {
  position: relative;
  cursor: pointer;
}

.file-native {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.term-input {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  max-width: none;
  caret-color: transparent;
  margin: 0;
  padding: 0.2em 0.15em;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--ink);
  border-radius: 0;
  appearance: none;
}

.secret {
  -webkit-text-security: disc;
}

body[data-state="error"] .screen {
  animation: jitter 0.09s linear infinite;
}

body[data-state="scan"] .screen {
  animation: tremor 0.11s linear infinite;
}

body.is-denied {
  color: #ff2a2a;
  --ink: #ff2a2a;
  --glow: rgba(255, 40, 40, 0.85);
}

body.is-denied::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: #ff0000;
  animation: redflash 0.16s steps(2, end) 4;
}

.noscript {
  padding: 24px;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

@keyframes powerfail {
  0% { opacity: 0.15; }
  7% { opacity: 1; }
  13% { opacity: 0.2; }
  21% { opacity: 0.85; }
  29% { opacity: 0.04; }
  36% { opacity: 0.7; }
  48% { opacity: 0.18; }
  57% { opacity: 1; }
  64% { opacity: 0.28; }
  73% { opacity: 0.06; }
  82% { opacity: 0.92; }
  90% { opacity: 0.35; }
  100% { opacity: 0.15; }
}

@keyframes flicker {
  0% {
    opacity: 0.72;
  }
  40% {
    opacity: 0.9;
  }
  100% {
    opacity: 0.64;
  }
}

@keyframes beam {
  from {
    top: -24vh;
  }
  to {
    top: 100vh;
  }
}

@keyframes jitter {
  0% {
    transform: translate(0, 0);
  }
  20% {
    transform: translate(-1px, 0);
  }
  40% {
    transform: translate(1px, 1px);
  }
  60% {
    transform: translate(-1px, -1px);
  }
  80% {
    transform: translate(1px, 0);
  }
  100% {
    transform: translate(0, 0);
  }
}

@keyframes tremor {
  0% {
    transform: translate(0, 0);
  }
  50% {
    transform: translate(0, 1px);
  }
  100% {
    transform: translate(0, -1px);
  }
}

@keyframes tear {
  0% {
    transform: translate(0, 0);
  }
  50% {
    transform: translate(-8px, 3px);
  }
  100% {
    transform: translate(6px, -2px);
  }
}

@keyframes redflash {
  0% {
    opacity: 0.45;
  }
  100% {
    opacity: 0;
  }
}

@media (max-width: 520px) {
  .field {
    flex-direction: column;
    align-items: stretch;
  }

  .field-label {
    white-space: normal;
  }

  .entry {
    max-width: none;
    width: 100%;
  }

  .term-input {
    width: 100%;
    max-width: none;
    min-height: 44px;
    font-size: 16px;
  }
}

body.is-poweroff .crt {
  transform-origin: center center;
  animation: crtOff 1.15s ease-in forwards;
}

@keyframes crtOff {
  0% {
    transform: scale(1, 1);
    filter: brightness(1);
  }
  30% {
    transform: scale(1, 0.18);
    filter: brightness(1.5);
  }
  55% {
    transform: scale(1, 0.015);
    filter: brightness(2.4);
  }
  100% {
    transform: scale(1, 0);
    filter: brightness(0);
    opacity: 0;
  }
}

body.is-snow {
  background-image: repeating-linear-gradient(
    0deg,
    rgba(255, 255, 255, 0.05) 0 1px,
    transparent 1px 3px
  );
  animation: snowshift 0.08s steps(2, end) infinite;
}

@keyframes snowshift {
  50% {
    background-position: 0 2px;
  }
}

.smoke {
  position: fixed;
  inset: -20%;
  z-index: 11;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 20% 80%, rgba(210, 210, 210, 0.28), transparent 42%),
    radial-gradient(ellipse at 70% 90%, rgba(160, 160, 160, 0.22), transparent 46%),
    radial-gradient(ellipse at 50% 70%, rgba(255, 255, 255, 0.12), transparent 40%);
  filter: blur(10px);
  animation: smoke 9s linear infinite;
}

@keyframes smoke {
  from {
    transform: translateY(12%);
  }
  to {
    transform: translateY(-18%);
  }
}

.broadcast {
  position: fixed;
  inset: 0;
  z-index: 7;
  overflow: hidden;
  background: #000;
  pointer-events: none;
  animation: signalLock 0.7s ease;
}

.broadcast-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  pointer-events: none;
}

iframe.broadcast-frame {
  top: -12%;
  height: 124%;
}

video.broadcast-frame {
  object-fit: cover;
  background: #000;
}

.future-still {
  position: fixed;
  inset: 0;
  z-index: 7;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
  animation: signalLock 1.1s ease;
}

body.is-future .screen {
  z-index: 12;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  pointer-events: none;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent 42%);
}

body.is-blackout,
body.is-blackout .crt {
  background: #000;
}

body.is-blackout .crt {
  opacity: 0;
}

.choice-title {
  font-size: 1.35em;
}

.broadcast::before {
  content: "";
  position: absolute;
  z-index: 2;
  top: 0;
  left: 0;
  right: 0;
  height: 76px;
  background: linear-gradient(to bottom, #000 18%, transparent);
}

.broadcast::after {
  content: "";
  position: absolute;
  z-index: 2;
  right: 0;
  bottom: 0;
  width: 148px;
  height: 64px;
  background: linear-gradient(to top left, #000 36%, transparent);
}

@keyframes signalLock {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

body.is-broadcast .crt::before,
body.is-broadcast .beam,
body.is-broadcast .vignette {
  z-index: 8;
}

body.is-broadcast .screen {
  z-index: 12;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  pointer-events: none;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.78), transparent 46%);
}

body.is-broadcast .screen .line {
  pointer-events: none;
}

body.is-broadcast .screen .term-btn {
  pointer-events: auto;
}

body.is-broadcast .term-btn {
  width: auto;
  align-self: flex-start;
  margin-top: 0.2em;
  text-shadow: 0 0 8px var(--glow), 0 1px 2px #000;
}

.typed {
  white-space: pre-wrap;
  max-width: 40rem;
}

.winbox {
  position: fixed;
  z-index: 20;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(440px, calc(100vw - 32px));
  background: #f3f3f3;
  color: #1b1b1b;
  text-shadow: none;
  font-family: "Segoe UI", Tahoma, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  border: 1px solid #d6d6d6;
  border-radius: 8px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  user-select: text;
}

.winbar {
  padding: 12px 16px 0;
  font-size: 12px;
  color: #5c5c5c;
}

.winbody {
  padding: 10px 16px 8px;
}

.winbody p {
  margin: 0 0 10px;
}

.wincite {
  color: #5c5c5c;
  font-size: 12px;
}

.winactions {
  display: flex;
  justify-content: flex-end;
  padding: 8px 16px 16px;
}

.winok {
  min-width: 88px;
  min-height: 32px;
  border: 0;
  border-radius: 4px;
  background: #0067c0;
  color: #fff;
  font: inherit;
  text-shadow: none;
  cursor: pointer;
}

.winok:focus-visible {
  outline: 2px solid #000;
  outline-offset: 2px;
}

.lock-screen {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 40;
  background: #000;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

html.is-locked .lock-screen {
  display: flex;
}

html.is-locked .crt,
html.is-locked #memory-glitch {
  display: none;
}

.memoria {
  position: fixed;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.38;
  pointer-events: none;
}

.memoria.hidden {
  display: none;
}

.clock {
  margin-top: 0.4em;
  font-size: clamp(28px, 8vw, 64px);
  letter-spacing: 0.08em;
  animation: clockpulse 1.2s ease-in-out infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .blink,
  .caret,
  .clock,
  body.is-poweroff .crt,
  body.is-snow,
  .broadcast,
  .smoke,
  #memory-glitch .burst,
  .crt::before,
  .beam,
  body[data-state="error"] .screen,
  body[data-state="scan"] .screen,
  body.is-denied::after {
    animation: none;
  }

  .crt::before {
    opacity: 0.45;
  }
}
