:root {
  --green: #39ff14;
  --green-soft: #19d80f;
  --green-dim: #0a6d08;
  --black: #010301;
  --panel: rgba(0, 10, 2, 0.86);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--black);
  color: var(--green);
  font-family: "Courier New", Courier, monospace;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
  display: grid;
  place-items: center;
  padding: 28px;
}

#matrix {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0.22;
  z-index: 0;
}

.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255,255,255,0.025) 0,
    rgba(255,255,255,0.025) 1px,
    transparent 2px,
    transparent 4px
  );
  mix-blend-mode: overlay;
}

.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  background: radial-gradient(circle at center, transparent 42%, rgba(0,0,0,.82) 100%);
}

.terminal-shell {
  position: relative;
  z-index: 4;
  width: min(1100px, 100%);
  min-height: min(820px, 88vh);
  background: var(--panel);
  border: 1px solid rgba(57, 255, 20, 0.45);
  box-shadow:
    0 0 18px rgba(57, 255, 20, 0.2),
    inset 0 0 30px rgba(57, 255, 20, 0.05);
  backdrop-filter: blur(3px);
}

.terminal-header,
.terminal-footer {
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 42px;
  padding: 8px 14px;
  border-bottom: 1px solid rgba(57, 255, 20, 0.25);
  background: rgba(4, 24, 5, 0.88);
  font-size: 12px;
  letter-spacing: 0.08em;
}

.terminal-footer {
  border-bottom: 0;
  border-top: 1px solid rgba(57, 255, 20, 0.25);
  justify-content: space-between;
  color: var(--green-soft);
}

.lights { display: flex; gap: 7px; }
.lights span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--green-dim);
  box-shadow: 0 0 7px rgba(57, 255, 20, .5);
}

.terminal-title {
  flex: 1;
  text-align: center;
  text-shadow: 0 0 8px rgba(57,255,20,.75);
}

.sound-toggle {
  border: 1px solid rgba(57, 255, 20, 0.4);
  background: transparent;
  color: var(--green);
  padding: 6px 9px;
  font: inherit;
  font-size: 11px;
  cursor: pointer;
}

.sound-toggle:hover,
.sound-toggle:focus-visible {
  background: rgba(57,255,20,.12);
  outline: none;
}

.terminal {
  min-height: calc(min(820px, 88vh) - 86px);
  padding: clamp(18px, 4vw, 44px);
  overflow: auto;
}

.status-line {
  margin-bottom: 20px;
  color: var(--green-soft);
  text-shadow: 0 0 8px rgba(57,255,20,.5);
}

.prompt { color: #b8ffac; }

#output {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: inherit;
  font-size: clamp(13px, 1.65vw, 18px);
  line-height: 1.52;
  letter-spacing: 0.015em;
  text-shadow:
    0 0 5px rgba(57,255,20,.85),
    0 0 14px rgba(57,255,20,.35);
}

.cursor {
  display: inline-block;
  width: 0.62em;
  height: 1.1em;
  margin-left: 3px;
  vertical-align: -0.15em;
  background: var(--green);
  box-shadow: 0 0 9px var(--green);
  animation: blink 0.85s steps(1) infinite;
}

.glitch {
  animation: glitch 0.16s linear 2;
}

.noscript {
  position: fixed;
  inset: 20px;
  z-index: 10;
  color: var(--green);
  background: #000;
  border: 1px solid var(--green);
  padding: 20px;
}

@keyframes blink { 50% { opacity: 0; } }
@keyframes glitch {
  0% { transform: translate(0); filter: none; }
  25% { transform: translate(1px, -1px); filter: contrast(1.8); }
  50% { transform: translate(-2px, 1px); }
  75% { transform: translate(2px, 0); }
  100% { transform: translate(0); filter: none; }
}

@media (max-width: 700px) {
  body { padding: 10px; align-items: start; }
  .terminal-shell { min-height: calc(100vh - 20px); }
  .terminal-header { gap: 8px; }
  .terminal-title { text-align: left; font-size: 10px; }
  .sound-toggle { font-size: 9px; }
  .terminal { min-height: calc(100vh - 106px); padding: 18px 14px; }
  .terminal-footer { font-size: 9px; gap: 7px; flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  .cursor { animation: none; }
  .scanlines { display: none; }
}

/* Worm margin reveal */
.worm-field {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  overflow: hidden;
}

.worm {
  --delay: 0s;
  --duration: 5s;
  --scale: 1;
  position: absolute;
  width: 54px;
  height: 18px;
  opacity: 0;
  transform: translateY(18px) scale(var(--scale));
  filter: drop-shadow(0 0 5px rgba(255, 115, 155, .85));
  animation: worm-arrive .8s ease-out var(--delay) forwards,
             worm-wiggle var(--duration) ease-in-out calc(var(--delay) + .8s) infinite;
}

.worm::before {
  content: "";
  position: absolute;
  inset: 3px 0;
  border-radius: 999px;
  background:
    repeating-linear-gradient(
      90deg,
      #d65a82 0 6px,
      #f28dae 6px 11px
    );
  box-shadow:
    inset 0 2px 2px rgba(255,255,255,.22),
    inset 0 -2px 3px rgba(70,0,20,.35);
}

.worm::after {
  content: "";
  position: absolute;
  right: 4px;
  top: 7px;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: #240008;
  box-shadow: 0 0 2px rgba(255,255,255,.55);
}

.worm.left { left: 6px; }
.worm.right { right: 6px; transform-origin: center; }

@keyframes worm-arrive {
  from { opacity: 0; transform: translateY(24px) scale(var(--scale)); }
  to { opacity: .92; transform: translateY(0) scale(var(--scale)); }
}

@keyframes worm-wiggle {
  0%, 100% { margin-top: 0; rotate: -6deg; }
  25% { margin-top: -7px; rotate: 8deg; }
  50% { margin-top: 3px; rotate: -10deg; }
  75% { margin-top: -4px; rotate: 7deg; }
}

@media (max-width: 900px) {
  .worm { width: 38px; height: 14px; opacity: .72; }
  .worm.left { left: 1px; }
  .worm.right { right: 1px; }
}

@media (prefers-reduced-motion: reduce) {
  .worm { animation: worm-arrive .01s linear forwards; }
}
