:root {
  color-scheme: dark;
  --bg-1: #0b0f14;
  --bg-2: #0a0a0a;
  --glass: rgba(255, 255, 255, 0.045);
  --glass-border: rgba(255, 255, 255, 0.15);
  --text: #d7e1e6;
  --accent: #5eead4;
  --danger: #ff5555;
  --warning: #f59e0b;
  --muted: #8a969c;
  --phosphor: #b6f7c3;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  padding: clamp(12px, 3vw, 28px);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color: var(--text);
  background:
    radial-gradient(1200px 800px at 20% 10%, #0e171d 0%, transparent 60%),
    radial-gradient(1000px 700px at 80% 90%, #11151a 0%, transparent 65%),
    linear-gradient(135deg, var(--bg-1), var(--bg-2));
  display: grid;
  place-items: center;
  overflow: hidden;
}

.bg-grain {
  position: fixed;
  inset: -2vmax;
  z-index: 5;
  pointer-events: none;
  opacity: 0.18;
  background-image: url("../grainbg.gif");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  mix-blend-mode: overlay;
  filter: contrast(110%) brightness(100%);
}

.noise {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  opacity: 0.14;
  mix-blend-mode: soft-light;
  background-image: url('data:image/svg+xml;utf8,\
    <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"160\" height=\"160\" viewBox=\"0 0 160 160\">\
      <filter id=\"n\">\
        <feTurbulence type=\"fractalNoise\" baseFrequency=\"0.85\" numOctaves=\"2\" stitchTiles=\"stitch\"/>\
        <feColorMatrix type=\"saturate\" values=\"0\"/>\
      </filter>\
      <rect width=\"100%\" height=\"100%\" filter=\"url(%23n)\" opacity=\"0.85\"/>\
    </svg>');
  background-size: 160px 160px;
  animation: noise 1.2s steps(4) infinite;
}

@keyframes noise {
  to {
    transform: translate3d(0, 0, 0);
  }
}

.bg-grit {
  position: fixed;
  inset: -2vmax;
  z-index: 10;
  pointer-events: none;
  opacity: 0.9;
  background:
    radial-gradient(120% 80% at 10% 0%, rgba(0, 0, 0, 0.45), transparent 60%),
    radial-gradient(100% 70% at 90% 100%, rgba(0, 0, 0, 0.38), transparent 62%),
    radial-gradient(70% 50% at 50% 40%, rgba(30, 40, 50, 0.25), transparent 65%),
    repeating-linear-gradient(to bottom, rgba(255, 255, 255, 0.02) 0 2px, rgba(0, 0, 0, 0.02) 2px 4px),
    url('data:image/svg+xml;utf8,\
      <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"180\" height=\"180\" viewBox=\"0 0 180 180\">\
        <filter id=\"f\"><feTurbulence type=\"fractalNoise\" baseFrequency=\"0.9\" numOctaves=\"2\" stitchTiles=\"stitch\"/></filter>\
        <rect width=\"100%\" height=\"100%\" filter=\"url(%23f)\" opacity=\"0.18\"/>\
      </svg>');
  background-size: cover, cover, cover, auto, 180px 180px;
}

.grunge {
  position: fixed;
  inset: 0;
  z-index: 95;
  pointer-events: none;
  opacity: 0.12;
  mix-blend-mode: multiply;
  background:
    radial-gradient(60% 25% at 18% 12%, rgba(0, 0, 0, 0.22), transparent 65%),
    radial-gradient(40% 20% at 78% 22%, rgba(0, 0, 0, 0.18), transparent 70%),
    radial-gradient(55% 18% at 42% 80%, rgba(0, 0, 0, 0.20), transparent 70%),
    radial-gradient(35% 15% at 66% 65%, rgba(0, 0, 0, 0.14), transparent 75%);
}

.grunge::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 160px rgba(0, 0, 0, 0.5), inset 0 0 380px rgba(0, 0, 0, 0.45);
}

.bg-vignette {
  position: fixed;
  inset: -2vmax;
  z-index: 20;
  pointer-events: none;
  background:
    radial-gradient(60% 45% at 50% 45%, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0) 60%),
    radial-gradient(120% 85% at 50% 50%, rgba(0, 0, 0, 0) 55%, rgba(0, 0, 0, 0.55) 100%);
}

.crt-flicker {
  position: fixed;
  inset: 0;
  z-index: 54;
  pointer-events: none;
  background: #fff;
  mix-blend-mode: overlay;
  opacity: 0;
  animation: globalFlicker 3.2s steps(90) infinite;
}

@keyframes globalFlicker {
  0% { opacity: 0.015; }
  8% { opacity: 0.03; }
  9% { opacity: 0.012; }
  20% { opacity: 0.022; }
  21% { opacity: 0.038; }
  22% { opacity: 0.012; }
  45% { opacity: 0.02; }
  46% { opacity: 0.042; }
  47% { opacity: 0.013; }
  70% { opacity: 0.025; }
  71% { opacity: 0.035; }
  72% { opacity: 0.014; }
  100% { opacity: 0.018; }
}

.scanlines {
  position: fixed;
  inset: 0;
  z-index: 55;
  pointer-events: none;
}

.scanlines::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: -20vh;
  height: 20vh;
  background: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.06) 55%,
    rgba(255, 255, 255, 0.12) 80%,
    rgba(255, 255, 255, 0.18) 100%
  );
  mix-blend-mode: overlay;
  filter: blur(0.4px);
  animation: singleSweep 7.5s linear infinite;
  will-change: transform, opacity;
}

.terminal {
  position: relative;
  width: min(900px, 100%);
  height: min(540px, 72vh);
  height: min(540px, 72dvh);
  background: linear-gradient(180deg, rgba(20, 28, 34, 0.55), rgba(10, 14, 17, 0.35));
  background-color: var(--glass);
  backdrop-filter: blur(16px) saturate(130%);
  -webkit-backdrop-filter: blur(16px) saturate(130%);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  box-shadow:
    0 30px 80px rgba(0, 0, 0, 0.75),
    0 8px 24px rgba(0, 0, 0, 0.6),
    inset 0 0 0 1px rgba(255, 255, 255, 0.03),
    inset 0 40px 120px rgba(255, 255, 255, 0.04);
  overflow: hidden;
}

.terminal::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(255, 255, 255, 0.12), transparent 60%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0) 12%);
  mix-blend-mode: soft-light;
}

.terminal::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.6), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.term-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.02));
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  box-shadow: 0 0 12px rgba(0, 0, 0, 0.6) inset;
}

.dot.red {
  background: #ff5f56;
}

.dot.yellow {
  background: #ffbd2e;
}

.dot.green {
  background: #27c93f;
}

.term-title {
  margin-left: auto;
  font-size: 0.85rem;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.screen {
  position: relative;
  height: calc(100% - 42px);
  padding: 18px;
  overflow: auto;
  color: var(--phosphor);
  text-shadow:
    0 0 10px rgba(53, 255, 153, 0.35),
    0 0 26px rgba(53, 255, 153, 0.2),
    0 0 2px rgba(53, 255, 153, 0.6);
  background: radial-gradient(120% 100% at 50% 0%, rgba(0, 0, 0, 0.2), transparent 55%);
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.screen::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.06;
  background-image: url('data:image/svg+xml;utf8,\
    <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"160\" height=\"160\" viewBox=\"0 0 160 160\">\
      <filter id=\"g\"><feTurbulence type=\"fractalNoise\" baseFrequency=\"1.2\" numOctaves=\"1\"/></filter>\
      <rect width=\"100%\" height=\"100%\" filter=\"url(%23g)\"/>\
    </svg>');
}

pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.blink {
  animation: blink 1s step-end infinite;
}

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

.text-danger {
  color: var(--danger);
  text-shadow: 0 0 8px rgba(255, 85, 85, 0.35), 0 0 18px rgba(255, 85, 85, 0.2);
}

.banner {
  display: block;
  max-width: 100%;
  margin: 0 0 1rem;
  white-space: pre;
  word-break: normal;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  font-size: clamp(0.52rem, 1.6vw, 1rem);
  line-height: 0.88;
  letter-spacing: -0.03em;
}

.banner::-webkit-scrollbar {
  display: none;
}

@keyframes singleSweep {
  0% {
    transform: translateY(0);
  }

  100% {
    transform: translateY(120vh);
  }
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  place-items: center;
  padding: 24px;
  background: radial-gradient(800px 500px at 50% 30%, rgba(255, 85, 85, 0.25), transparent 70%), rgba(0, 0, 0, 0.7);
}

.modal {
  width: min(980px, 96vw);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02));
  background-color: var(--glass);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  box-shadow: 0 30px 100px rgba(0, 0, 0, 0.75), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  overflow: hidden;
}

.modal-header {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 16px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02));
}

.badge {
  padding: 0.2rem 0.5rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--danger);
  background: rgba(255, 85, 85, 0.15);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.modal-body {
  padding: 18px 18px 22px;
}

.ascii {
  color: var(--danger);
  text-shadow: 0 0 8px rgba(255, 85, 85, 0.35);
  font-weight: 700;
  line-height: 1;
  overflow: auto;
}

.gov {
  margin-top: 12px;
  line-height: 1.55;
}

.gov strong {
  color: #ffd2d2;
}

.fineprint {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.86rem;
}

.actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 18px;
}

.btn {
  cursor: pointer;
  padding: 0.7rem 1rem;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  font-weight: 600;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.55);
}

.btn.danger {
  background: rgba(255, 85, 85, 0.12);
  border-color: rgba(255, 85, 85, 0.35);
}

.kbd-input {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

#out {
  display: block;
  min-height: 100%;
  text-shadow:
    0 0 10px rgba(53, 255, 153, 0.35),
    0 0 26px rgba(53, 255, 153, 0.2),
    0 0 2px rgba(53, 255, 153, 0.6);
}

@supports not ((backdrop-filter: blur(2px)) or (-webkit-backdrop-filter: blur(2px))) {
  .terminal,
  .modal {
    background: rgba(11, 15, 20, 0.94);
  }

  .term-topbar,
  .modal-header {
    background: rgba(255, 255, 255, 0.06);
  }
}

@media (prefers-reduced-motion: reduce) {
  .bg-grain {
    display: none;
  }

  .noise,
  .crt-flicker {
    animation: none;
  }

  .scanlines::before {
    animation: none;
    opacity: 0.08;
  }

  .btn:hover {
    transform: none;
  }

  .blink {
    animation: none;
  }
}

@media (max-width: 720px) {
  .banner {
    font-size: clamp(0.42rem, 1.8vw, 0.82rem);
    margin-bottom: 0.85rem;
  }

  .modal {
    width: min(100%, 96vw);
  }

  .ascii {
    font-size: clamp(0.54rem, 1.65vw, 0.8rem);
  }
}

@media (max-width: 480px) {
  body {
    padding: 12px;
  }

  .terminal {
    height: min(540px, 68vh);
    height: min(540px, 68dvh);
    border-radius: 12px;
  }

  .screen {
    padding: 12px;
    font-size: 13px;
  }

  .term-topbar {
    gap: 8px;
    padding: 8px 10px;
  }

  .dot {
    width: 8px;
    height: 8px;
  }

  .term-title {
    font-size: 0.62rem;
    letter-spacing: 0.08em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .banner {
    font-size: clamp(0.26rem, 1.72vw, 0.5rem);
    margin-bottom: 0.7rem;
  }

  .overlay {
    padding: 12px;
  }

  .modal {
    border-radius: 16px;
  }

  .modal-header {
    padding: 14px;
  }

  .modal-body {
    padding: 14px 14px 18px;
  }

  .ascii {
    font-size: clamp(0.38rem, 2.05vw, 0.6rem);
  }

  .fineprint {
    font-size: 0.8rem;
    line-height: 1.5;
  }

  .actions {
    flex-direction: column-reverse;
  }

  .btn {
    width: 100%;
  }
}

@media (max-width: 360px) {
  .screen {
    padding: 10px;
    font-size: 12px;
  }

  .banner {
    font-size: clamp(0.22rem, 1.6vw, 0.42rem);
  }
}
