@import url('https://fonts.googleapis.com/css2?family=VT323&display=swap');

:root {
  --bg-color: #1a1100;
  --text-color: #ffb000;
  --glow-color: rgba(255, 176, 0, 0.4);
  --crt-scanline: rgba(0, 0, 0, 0.15);
  --phosphor-bloom: rgba(255, 176, 0, 0.25);
}

body, html {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background-color: var(--bg-color);
  color: var(--text-color);
  font-family: 'VT323', monospace;
  font-size: 22px;
  overflow-x: hidden;
  background-image: 
    repeating-linear-gradient(
      0deg,
      rgba(0, 0, 0, 0.03),
      rgba(0, 0, 0, 0.03) 1px,
      transparent 1px,
      transparent 2px
    );
  background-size: 100% 2px;
}

body {
  text-shadow: 
    0 0 1px var(--glow-color),
    0 0 2px rgba(255, 176, 0, 0.2);
}

h1, h2, h3, h4, h5, h6, a {
  text-shadow:
    0 0 2px var(--glow-color),
    0 0 5px rgba(255, 176, 0, 0.4),
    0 0 8px rgba(255, 176, 0, 0.2);
}

/* CRT Scanlines and Screen Flicker */
body::before {
  content: " ";
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background: 
    linear-gradient(
      to bottom,
      var(--crt-scanline) 50%,
      transparent 50%
    ),
    radial-gradient(
      ellipse at center,
      transparent 0%,
      rgba(0, 0, 0, 0.15) 100%
    );
  background-size: 100% 3px, 100% 100%;
  z-index: 50;
  pointer-events: none;
}

body::after {
  content: " ";
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background: rgba(18, 16, 16, 0.08);
  opacity: 0;
  z-index: 50;
  pointer-events: none;
  animation: flicker 0.08s cubic-bezier(0.5, 0, 1, 1) infinite;
}

@keyframes flicker {
  0% { opacity: 0.015; }
  14% { opacity: 0.03; }
  15% { opacity: 0.015; }
  49% { opacity: 0.02; }
  60% { opacity: 0.025; }
  99% { opacity: 0.015; }
  100% { opacity: 0.02; }
}

/* Typography & Phosphor Glow */
/* Glow inherited from body, but ensure it's applied to all text containers */
.content, .page-content, .cli,
    0 0 2px rgba(255, 176, 0, 0.2)-output, .home-intro, .terminal-content, article {
  text-shadow: 
    0 0 1px var(--glow-color);
}

a {
  color: var(--text-color);
  text-decoration: none;
}

/* Layout Elements */
#terminal-wrapper {
  position: relative;
  z-index: 10;
  padding: 2rem;
  max-width: 900px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
}

.terminal-header {
  border-bottom: 2px dashed var(--text-color);
  padding-bottom: 1rem;
  margin-bottom: 2rem;
  display: flex;
  justify-content: space-between;
  flex-shrink: 0;
}

.terminal-content {
  flex-grow: 1;
  overflow-y: auto;
  padding-right: 1rem;
}

/* Custom Scrollbar for Terminal */
::-webkit-scrollbar {
  width: 8px;
}
::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
}
::-webkit-scrollbar-thumb {
  background: var(--text-color);
}

#cli-container {
  margin-top: 2rem;
  border-top: 2px dashed var(--text-color);
  padding-top: 1rem;
  flex-shrink: 0;
}

.cli-input-wrapper {
  display: flex;
  align-items: center;
}

.prompt {
  margin-right: 10px;
}

#cli-input {
  background: transparent;
  border: none;
  color: var(--text-color);
  font-family: 'VT323', monospace;
  font-size: 22px;
  flex-grow: 1;
  outline: none;
  text-shadow: 
    0 0 1px var(--glow-color),
    0 0 2px rgba(255, 176, 0, 0.2);
  letter-spacing: 0.05em;
}

#cli-output {
  margin-bottom: 1rem;
}

.page-content-wrapper {
  white-space: normal;
  margin-bottom: 2rem;
}

/* Remove default browser margins from first elements to prevent "weird spacing" */
.page-content-wrapper > *:first-child,
.page-content-wrapper article > *:first-child,
.page-content-wrapper div > *:first-child,
.home-intro {
  margin-top: 0 !important;
  padding-top: 0 !important;
}

.initial-cmd {
  margin-bottom: 0;
}

/* Fake BIOS Boot Sequence */
#bios-boot {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: var(--bg-color);
  z-index: 9999;
  padding: 2rem;
  font-family: 'VT323', monospace;
  color: var(--text-color);
  overflow: hidden;
  text-shadow: 
    0 0 1px var(--glow-color),
    0 0 3px rgba(255, 176, 0, 0.3);
}

#bios-content {
  white-space: pre-wrap;
}

/* Mouse Grid Ripple Canvas */
#grid-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

/* Directory Listing Table */
.ls-la {
  width: 100%;
  text-align: left;
  border-collapse: collapse;
  margin-top: 2rem;
}

.ls-la th, .ls-la td {
  padding: 0.5rem;
}

/* Typewriter cursor */
.cursor {
  display: inline-block;
  width: 10px;
  height: 1.2em;
  background-color: var(--text-color);
  animation: blink 1s step-end infinite;
  vertical-align: text-bottom;
}

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

.home-intro {
  white-space: pre-wrap;
  line-height: 1.5;
}

/* Glitch Hover Effect */
.glitch-hover {
  position: relative;
  display: inline-block;
}

.glitch-hover:hover {
  animation: glitch-skew 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94) both infinite;
}

.glitch-hover:hover::before,
.glitch-hover:hover::after {
  content: attr(data-text);
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.glitch-hover:hover::before {
  left: 2px;
  text-shadow: -2px 0 #ff0000;
  clip: rect(44px, 450px, 56px, 0);
  animation: glitch-anim 5s infinite linear alternate-reverse;
}

.glitch-hover:hover::after {
  left: -2px;
  text-shadow: -2px 0 #00ffff;
  clip: rect(44px, 450px, 56px, 0);
  animation: glitch-anim2 5s infinite linear alternate-reverse;
}

@keyframes glitch-anim {
  0% { clip: rect(10px, 9999px, 86px, 0); }
  20% { clip: rect(69px, 9999px, 12px, 0); }
  40% { clip: rect(98px, 9999px, 45px, 0); }
  60% { clip: rect(3px, 9999px, 99px, 0); }
  80% { clip: rect(45px, 9999px, 23px, 0); }
  100% { clip: rect(78px, 9999px, 56px, 0); }
}

@keyframes glitch-anim2 {
  0% { clip: rect(65px, 9999px, 100px, 0); }
  20% { clip: rect(10px, 9999px, 54px, 0); }
  40% { clip: rect(89px, 9999px, 23px, 0); }
  60% { clip: rect(45px, 9999px, 78px, 0); }
  80% { clip: rect(12px, 9999px, 45px, 0); }
  100% { clip: rect(98px, 9999px, 12px, 0); }
}

@keyframes glitch-skew {
  0% { transform: skew(0deg); }
  20% { transform: skew(-5deg); }
  40% { transform: skew(5deg); }
  60% { transform: skew(-2deg); }
  80% { transform: skew(2deg); }
  100% { transform: skew(0deg); }
}

/* Random kernel panic easter egg */
body.glitch-active {
  --text-color: #ff4d2d;
  --glow-color: rgba(255, 77, 45, 0.55);
  overflow: hidden;
}

body.glitch-active #terminal-wrapper,
body.glitch-active #grid-canvas {
  animation: terminal-hijack-jitter 0.11s steps(2, end) infinite;
}

body.glitch-active #terminal-wrapper {
  filter: contrast(1.45) saturate(1.35);
}

body.glitch-recovering #terminal-wrapper,
body.glitch-recovering #grid-canvas {
  animation: terminal-recover 0.35s ease-out 2;
}

body.glitch-denied #glitch-overlay {
  animation:
    overlay-pulse 0.16s steps(2, end) infinite,
    denied-flash 0.22s steps(2, end) 1;
}

#glitch-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  padding: 2rem;
  color: #ff4d2d;
  background:
    repeating-linear-gradient(
      0deg,
      rgba(0, 0, 0, 0.5),
      rgba(0, 0, 0, 0.5) 1px,
      rgba(255, 77, 45, 0.07) 1px,
      rgba(255, 77, 45, 0.07) 3px
    ),
    rgba(12, 0, 0, 0.94);
  pointer-events: all;
  text-shadow:
    0 0 2px rgba(255, 77, 45, 0.9),
    0 0 8px rgba(255, 77, 45, 0.45);
  animation: overlay-pulse 0.16s steps(2, end) infinite;
}

#glitch-overlay::before,
#glitch-overlay::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#glitch-overlay::before {
  background:
    linear-gradient(
      90deg,
      transparent 0%,
      rgba(0, 255, 255, 0.13) 48%,
      transparent 52%
    );
  mix-blend-mode: screen;
  animation: glitch-scan 0.8s linear infinite;
}

#glitch-overlay::after {
  background:
    radial-gradient(
      ellipse at center,
      transparent 0%,
      rgba(0, 0, 0, 0.28) 70%,
      rgba(0, 0, 0, 0.65) 100%
    );
}

.glitch-frame {
  position: relative;
  z-index: 1;
  width: min(760px, 100%);
  min-height: 320px;
  box-sizing: border-box;
  border: 2px solid currentColor;
  padding: 1.25rem;
  background: rgba(14, 0, 0, 0.88);
  box-shadow:
    0 0 18px rgba(255, 77, 45, 0.35),
    inset 0 0 18px rgba(255, 77, 45, 0.12);
  animation: glitch-frame-shift 0.32s steps(2, end) infinite;
}

.glitch-title {
  margin-bottom: 1rem;
  border-bottom: 2px dashed currentColor;
  padding-bottom: 0.6rem;
  color: #ffb000;
  font-size: 1.35rem;
  text-transform: uppercase;
}

.glitch-log {
  max-height: 52vh;
  overflow: hidden;
  line-height: 1.35;
  white-space: pre-wrap;
}

.glitch-log div::before {
  content: "> ";
}

.glitch-recovery {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
  border-top: 2px dashed rgba(255, 77, 45, 0.75);
  padding-top: 0.75rem;
}

.glitch-recovery-prompt {
  flex-shrink: 0;
  color: #ffb000;
}

.glitch-recovery-input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: #77ff77;
  font-family: 'VT323', monospace;
  font-size: 1rem;
  text-shadow:
    0 0 2px rgba(119, 255, 119, 0.9),
    0 0 8px rgba(119, 255, 119, 0.35);
}

.glitch-recovery-input:disabled {
  opacity: 0.45;
}

.glitch-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.glitch-actions button {
  border: 1px solid currentColor;
  border-radius: 0;
  padding: 0.25rem 0.65rem;
  background: rgba(255, 77, 45, 0.12);
  color: #ffb000;
  font: inherit;
  text-transform: uppercase;
  cursor: pointer;
  text-shadow: inherit;
}

.glitch-actions button:hover,
.glitch-actions button:focus-visible {
  background: rgba(255, 176, 0, 0.18);
  color: #77ff77;
  outline: 1px dashed currentColor;
  outline-offset: 2px;
}

.glitch-actions button:disabled {
  cursor: default;
  opacity: 0.45;
}

.glitch-error {
  color: #ff4d2d;
}

.glitch-warning {
  color: #ffb000;
}

.glitch-ok {
  color: #77ff77;
}

@keyframes terminal-hijack-jitter {
  0% { transform: translate(0, 0) skew(0deg); }
  20% { transform: translate(-2px, 1px) skew(-0.4deg); }
  40% { transform: translate(3px, -1px) skew(0.5deg); }
  60% { transform: translate(-1px, 2px) skew(-0.2deg); }
  80% { transform: translate(2px, 0) skew(0.3deg); }
  100% { transform: translate(0, -1px) skew(0deg); }
}

@keyframes terminal-recover {
  0% { transform: translateX(-4px); filter: brightness(1.7); }
  100% { transform: translateX(0); filter: brightness(1); }
}

@keyframes overlay-pulse {
  0% { opacity: 0.92; }
  50% { opacity: 1; }
  100% { opacity: 0.96; }
}

@keyframes glitch-scan {
  0% { transform: translateX(-70%); }
  100% { transform: translateX(70%); }
}

@keyframes glitch-frame-shift {
  0% { transform: translate(0, 0); }
  30% { transform: translate(2px, -1px); }
  60% { transform: translate(-1px, 1px); }
  100% { transform: translate(0, 0); }
}

@keyframes denied-flash {
  0% { filter: invert(0); }
  50% { filter: invert(1) contrast(2); }
  100% { filter: invert(0); }
}

/* Matrix Canvas */
#matrix-canvas {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 9000;
  pointer-events: none;
  background-color: rgba(0, 0, 0, 0.8);
}

@media (prefers-reduced-motion: reduce) {
  body.glitch-active #terminal-wrapper,
  body.glitch-active #grid-canvas,
  body.glitch-recovering #terminal-wrapper,
  body.glitch-recovering #grid-canvas,
  #glitch-overlay,
  #glitch-overlay::before,
  .glitch-frame {
    animation: none;
  }

  body.glitch-denied #glitch-overlay {
    animation: none;
  }
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
  #terminal-wrapper {
    padding: 1rem;
  }

  .terminal-header {
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
  }

  body, html, #cli-input {
    font-size: 18px;
  }

  .cli-input-wrapper {
    flex-wrap: wrap;
  }

  .prompt {
    width: 100%;
    margin-bottom: 0.25rem;
  }

  #bios-boot {
    padding: 1rem;
  }

  #glitch-overlay {
    align-items: flex-start;
    padding: 1rem;
  }

  .glitch-frame {
    min-height: 260px;
    padding: 1rem;
  }

  .glitch-title {
    font-size: 1.1rem;
  }

  .glitch-recovery {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.25rem;
  }

  .glitch-recovery-input {
    font-size: 1rem;
  }
}
