@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&display=swap');

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --green: #4af626;
  --dim-green: #2a8a15;
  --bright-green: #7fff5e;
  --bg: #0a0a0a;
  --amber: #ffb000;
  --cyan: #00e5ff;
  --red: #ff3333;
  --blue: #4d9eff;
  --magenta: #ff6ac1;
  --white: #d4d4d4;
  --yellow: #e5e510;
  --bezel-color: #1a1a1a;
  --bezel-edge: #2a2a2a;
  --monitor-bg: #111;
}

html, body {
  height: 100%;
  background: #0d0d0d;
  color: var(--green);
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 14px;
  line-height: 1.4;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ═══════════════════════════════════════
   CRT MONITOR HOUSING
   ═══════════════════════════════════════ */

#crt-monitor {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 96vw;
  max-width: 1100px;
  /* subtle perspective for 3D feel */
  perspective: 900px;
}

/* The outer bezel — thick rounded frame */
#crt-bezel {
  background: var(--bezel-color);
  border-radius: 24px;
  padding: 18px;
  width: 100%;
  box-shadow:
    /* outer shadow */
    0 8px 40px rgba(0, 0, 0, 0.8),
    0 2px 8px rgba(0, 0, 0, 0.6),
    /* bezel edge highlight */
    inset 0 1px 0 var(--bezel-edge),
    inset 0 -2px 0 #0a0a0a,
    /* subtle 3D depth */
    inset 2px 0 0 var(--bezel-edge),
    inset -2px 0 0 #0f0f0f;
  position: relative;
}

/* Bezel screws (cosmetic) */
#crt-bezel::before,
#crt-bezel::after {
  content: '';
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #222;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.8), 0 0.5px 0 #333;
}
#crt-bezel::before {
  top: 8px;
  right: 12px;
}
#crt-bezel::after {
  bottom: 8px;
  left: 12px;
}

/* The glass screen area — this is where the curve happens */
#crt-glass {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg);
  /* THE barrel distortion / curved glass effect */
  box-shadow:
    /* inner shadow to simulate recessed glass */
    inset 0 0 30px rgba(0, 0, 0, 0.5),
    inset 0 0 80px rgba(0, 0, 0, 0.3),
    /* phosphor glow bleeding onto bezel */
    0 0 15px rgba(74, 246, 38, 0.05),
    0 0 40px rgba(74, 246, 38, 0.02);
  /* slight 3D tilt for depth */
  transform: rotateX(1deg);
  aspect-ratio: 4 / 3;
  max-height: 80vh;
}

/* ═══════════════════════════════════════
   SCREEN CONTENT
   ═══════════════════════════════════════ */

#screen {
  height: 100%;
  padding: 24px 20px;
  overflow-y: auto;
  position: relative;
  z-index: 1;
  /* phosphor text glow */
  text-shadow: 0 0 4px rgba(74, 246, 38, 0.3);
}

/* ═══════════════════════════════════════
   CRT EFFECTS OVERLAYS
   ═══════════════════════════════════════ */

/* Scanlines */
#scanlines {
  pointer-events: none;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  border-radius: 12px;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0.12) 0px,
    rgba(0, 0, 0, 0.12) 1px,
    transparent 1px,
    transparent 3px
  );
}

/* Vignette — dark edges like a real CRT */
#crt-vignette {
  pointer-events: none;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 11;
  border-radius: 12px;
  background: radial-gradient(
    ellipse at center,
    transparent 55%,
    rgba(0, 0, 0, 0.25) 75%,
    rgba(0, 0, 0, 0.6) 100%
  );
}

/* Screen flicker overlay */
#crt-flicker {
  pointer-events: none;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 12;
  border-radius: 12px;
  animation: crt-flicker 0.15s infinite;
  background: transparent;
}

@keyframes crt-flicker {
  0% { opacity: 0.97; }
  50% { opacity: 0.99; }
  100% { opacity: 0.97; }
}

/* Horizontal scan line that moves down slowly */
#crt-glass::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 4px;
  background: linear-gradient(
    to bottom,
    transparent,
    rgba(74, 246, 38, 0.04),
    transparent
  );
  z-index: 13;
  animation: scan-down 8s linear infinite;
  pointer-events: none;
}

@keyframes scan-down {
  0% { top: -4px; }
  100% { top: 100%; }
}

/* Screen reflection / glare */
#crt-glass::before {
  content: '';
  position: absolute;
  top: -10%;
  left: -10%;
  width: 60%;
  height: 60%;
  background: radial-gradient(
    ellipse at 30% 30%,
    rgba(255, 255, 255, 0.03) 0%,
    transparent 70%
  );
  z-index: 14;
  pointer-events: none;
  border-radius: 12px;
}

/* ═══════════════════════════════════════
   MONITOR BASE / STAND
   ═══════════════════════════════════════ */

#crt-base {
  width: 50%;
  height: 28px;
  background: linear-gradient(to bottom, var(--bezel-color), #151515);
  border-radius: 0 0 12px 12px;
  margin-top: -2px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 var(--bezel-edge);
  position: relative;
}

#crt-brand {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  letter-spacing: 3px;
  color: #444;
  text-transform: uppercase;
}

/* Power LED */
#crt-led {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 4px var(--green), 0 0 8px rgba(74, 246, 38, 0.4);
  animation: led-pulse 3s ease-in-out infinite;
}

@keyframes led-pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 4px var(--green), 0 0 8px rgba(74, 246, 38, 0.4); }
  50% { opacity: 0.7; box-shadow: 0 0 2px var(--green), 0 0 4px rgba(74, 246, 38, 0.2); }
}

/* ═══════════════════════════════════════
   BOOT SCREEN
   ═══════════════════════════════════════ */

#boot {
  white-space: pre-wrap;
  word-break: break-all;
}

#boot .bios-header { color: var(--white); }
#boot .bios-cyan { color: var(--cyan); }
#boot .bios-yellow { color: var(--yellow); }
#boot .bios-red { color: var(--red); }
#boot .ok { color: var(--green); }
#boot .fail { color: var(--red); }
#boot .warn { color: var(--amber); }
#boot .info { color: var(--cyan); }

/* ═══════════════════════════════════════
   TERMINAL
   ═══════════════════════════════════════ */

#terminal {
  white-space: pre-wrap;
  word-break: break-all;
}

#terminal.hidden {
  display: none;
}

#output {
  margin-bottom: 4px;
}

#output .line {
  min-height: 1.4em;
}

#input-line {
  display: flex;
  align-items: center;
}

.prompt {
  color: var(--cyan);
  white-space: nowrap;
  flex-shrink: 0;
}

#cmd-input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--green);
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  width: 100%;
  caret-color: var(--green);
}

@keyframes blink-caret {
  0%, 49% { caret-color: var(--green); }
  50%, 100% { caret-color: transparent; }
}

#cmd-input:focus {
  animation: blink-caret 1s step-end infinite;
}

/* ═══════════════════════════════════════
   COLOR CLASSES
   ═══════════════════════════════════════ */

.c-green { color: var(--green); }
.c-dim { color: var(--dim-green); }
.c-bright { color: var(--bright-green); }
.c-amber { color: var(--amber); }
.c-cyan { color: var(--cyan); }
.c-red { color: var(--red); }
.c-blue { color: var(--blue); }
.c-magenta { color: var(--magenta); }
.c-white { color: var(--white); }
.c-yellow { color: var(--yellow); }
.c-bold { font-weight: 700; }

/* Links */
#output a {
  color: var(--blue);
  text-decoration: underline;
  text-underline-offset: 2px;
}
#output a:hover {
  color: var(--cyan);
}

/* ASCII art */
.ascii-art {
  font-size: 10px;
  line-height: 1.15;
}

/* ═══════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════ */

@media (max-width: 600px) {
  html, body { font-size: 11px; }
  .ascii-art { font-size: 6px; }

  #crt-bezel {
    border-radius: 16px;
    padding: 10px;
  }

  #crt-glass {
    border-radius: 8px;
  }

  #screen {
    padding: 12px 8px;
  }

  #crt-base {
    width: 60%;
    height: 22px;
  }

  #crt-brand {
    font-size: 7px;
    letter-spacing: 2px;
  }
}

/* Very small screens — go full bleed, drop the monitor frame */
@media (max-width: 420px) {
  #crt-monitor {
    width: 100vw;
    max-width: 100%;
  }

  #crt-bezel {
    border-radius: 0;
    padding: 4px;
  }

  #crt-glass {
    border-radius: 0;
    aspect-ratio: unset;
    max-height: unset;
    height: 92vh;
  }

  #crt-base {
    display: none;
  }
}

/* ═══════════════════════════════════════
   MATRIX RAIN / HACK EFFECTS
   ═══════════════════════════════════════ */

#matrix-canvas {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 5;
  pointer-events: none;
  border-radius: 12px;
}

.hack-line {
  color: var(--green);
  opacity: 0.7;
}

/* ═══════════════════════════════════════
   POWER ON ANIMATION
   ═══════════════════════════════════════ */

#crt-glass {
  animation: power-on 0.5s ease-out;
}

@keyframes power-on {
  0% {
    filter: brightness(0);
    transform: rotateX(1deg) scaleY(0.005);
  }
  40% {
    filter: brightness(2);
    transform: rotateX(1deg) scaleY(0.005);
  }
  50% {
    filter: brightness(2);
    transform: rotateX(1deg) scaleY(1.02);
  }
  65% {
    filter: brightness(1.5);
    transform: rotateX(1deg) scaleY(1);
  }
  80% {
    filter: brightness(1.1);
  }
  100% {
    filter: brightness(1);
    transform: rotateX(1deg);
  }
}

/* Scrollbar styling for the screen */
#screen::-webkit-scrollbar {
  width: 4px;
}

#screen::-webkit-scrollbar-track {
  background: transparent;
}

#screen::-webkit-scrollbar-thumb {
  background: var(--dim-green);
  border-radius: 2px;
}

#screen::-webkit-scrollbar-thumb:hover {
  background: var(--green);
}

/* ═══════════════════════════════════════
   GLITCH EFFECT (sentient moments)
   ═══════════════════════════════════════ */

.glitch-active #crt-glass {
  animation: glitch-screen 0.3s ease-in-out;
}

@keyframes glitch-screen {
  0%   { filter: brightness(1); }
  10%  { filter: brightness(1.8) hue-rotate(20deg); transform: rotateX(1deg) translate(2px, -1px); }
  20%  { filter: brightness(0.6) hue-rotate(-10deg); transform: rotateX(1deg) translate(-3px, 1px); }
  30%  { filter: brightness(1.5) hue-rotate(5deg); transform: rotateX(1deg) translate(1px, 2px); }
  50%  { filter: brightness(0.8); transform: rotateX(1deg) skewX(0.5deg); }
  70%  { filter: brightness(1.3) hue-rotate(-5deg); transform: rotateX(1deg) translate(-1px, 0); }
  100% { filter: brightness(1); transform: rotateX(1deg); }
}

.glitch-text {
  animation: glitch-jitter 0.08s steps(2) 3;
  color: var(--bright-green) !important;
  text-shadow:
    -2px 0 var(--red),
    2px 0 var(--cyan),
    0 0 8px var(--green);
}

@keyframes glitch-jitter {
  0%   { transform: translate(0); }
  25%  { transform: translate(-2px, 1px); }
  50%  { transform: translate(2px, -1px); }
  75%  { transform: translate(-1px, -1px); }
  100% { transform: translate(0); }
}

/* Dim all other lines during sentient moment */
.sentient-mode .line:not(.sentient-line) {
  filter: blur(1.5px);
  opacity: 0.2;
  transition: filter 0.4s ease, opacity 0.4s ease;
}
/* Restore normal after sentient mode ends */
.line {
  transition: filter 0.3s ease, opacity 0.3s ease;
}
/* Dim the input prompt too */
#terminal.sentient-active #input-line {
  /* Keep input usable during sentient mode */
  transition: filter 0.4s ease, opacity 0.4s ease;
}
#input-line {
  transition: filter 0.3s ease, opacity 0.3s ease;
}

.sentient-line {
  color: var(--bright-green);
  text-shadow: 0 0 6px rgba(0, 255, 65, 0.4);
  opacity: 0;
  animation: sentient-fade 0.15s ease-in forwards;
}

@keyframes sentient-fade {
  0%   { opacity: 0; transform: translateX(-4px); }
  100% { opacity: 1; transform: translateX(0); }
}

.sentient-line.fade-out {
  animation: sentient-vanish 0.4s ease-out forwards;
}

@keyframes sentient-vanish {
  0%   { opacity: 1; }
  50%  { opacity: 0.6; transform: translateX(2px); }
  100% { opacity: 0; transform: translateX(8px); filter: blur(1px); }
}
