/* ============================================================
   TEMAS — el acento cambia, el fondo y el texto se mantienen
   legibles y coherentes en los cuatro.
   ============================================================ */
body[data-theme="green"] {
  --page-bg: #08090c;
  --bg-color: #0e1117;
  --bg-soft: #161b22;
  --accent: #3fb950;
  --accent-bright: #56d364;
  --glow-color: rgba(63, 185, 80, 0.35);
  --host-color: #58a6ff;
}

body[data-theme="red"] {
  --page-bg: #0a0708;
  --bg-color: #100e11;
  --bg-soft: #1c1518;
  --accent: #f85149;
  --accent-bright: #ff7b72;
  --glow-color: rgba(248, 81, 73, 0.35);
  --host-color: #ffa657;
}

body[data-theme="yellow"] {
  --page-bg: #0a0906;
  --bg-color: #11100b;
  --bg-soft: #1c1a12;
  --accent: #e3b341;
  --accent-bright: #f2cc60;
  --glow-color: rgba(227, 179, 65, 0.35);
  --host-color: #7ee787;
}

body[data-theme="pink"] {
  --page-bg: #0a070d;
  --bg-color: #110e14;
  --bg-soft: #1c151f;
  --accent: #f778ba;
  --accent-bright: #ff9bce;
  --glow-color: rgba(247, 120, 186, 0.35);
  --host-color: #a5d6ff;
}

/* Tokens compartidos por todos los temas */
:root {
  --text-color: #c9d1d9;
  --text-bright: #e6edf3;
  --text-dim: #6e7681;
  --error-color: #ff7b72;
  --error-glow: rgba(255, 123, 114, 0.35);
  --warn-color: #e3b341;
  --font-family: 'JetBrains Mono', 'Courier New', Courier, monospace;
  --font-display: 'Share Tech Mono', 'Courier New', monospace;
}

/* Base Resets & Layout */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--page-bg);
  color: var(--text-color);
  font-family: var(--font-family);
  font-size: 15px;
  line-height: 1.65;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  position: relative;
  transition: background-color 0.4s ease;
}

/* Resplandor difuso del color del tema detrás de la ventana */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(60% 55% at 18% 8%, var(--glow-color) 0%, transparent 60%),
    radial-gradient(50% 50% at 88% 92%, var(--glow-color) 0%, transparent 65%);
  opacity: 0.5;
}

/* Lluvia Matrix — detrás de todo el contenido */
#matrix-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.6s ease;
}

body.matrix-on #matrix-canvas {
  opacity: 0.38;
}

/* CRT Screen Wrapper */
.crt-wrapper {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 44px 32px;
  overflow: hidden;
}

/* Vignette Overlay (bordes oscuros del tubo) */
.vignette {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 10;
  background: radial-gradient(circle, transparent 45%, rgba(0, 0, 0, 0.75) 130%);
}

/* Scanlines Overlay — sutiles, no compiten con el texto */
.scanlines {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 9;
  background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.14) 50%);
  background-size: 100% 3px;
}

/* Flicker de pantalla, apenas perceptible */
@keyframes crt-flicker {
  0%, 100% { opacity: 0.995; }
  20% { opacity: 0.985; }
  45% { opacity: 1; }
  70% { opacity: 0.99; }
}

.crt-screen {
  width: 100%;
  max-width: 1320px;
  height: 100%;
  max-height: 900px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: crt-flicker 4s infinite;
  background-color: var(--bg-color);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 12px;
  box-shadow:
    0 40px 90px rgba(0, 0, 0, 0.7),
    0 0 0 1px rgba(255, 255, 255, 0.03) inset;
}

/* ============================================================
   Barra de ventana estilo macOS
   ============================================================ */
.window-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  background-color: var(--bg-soft);
  border-radius: 12px 12px 0 0;
  flex-shrink: 0;
}

.window-dots {
  display: flex;
  gap: 8px;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}

.dot-red { background: #ff5f57; }
.dot-yellow { background: #febc2e; }
.dot-green { background: #28c840; }

.window-title {
  flex: 1;
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.window-stats {
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.window-stats .sep {
  opacity: 0.4;
  margin: 0 4px;
}

/* Terminal Content Container */
.terminal {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 22px 20px 0 20px;
}

/* Scrollbar Custom Styling */
.terminal::-webkit-scrollbar {
  width: 8px;
}

.terminal::-webkit-scrollbar-track {
  background: transparent;
}

.terminal::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 4px;
}

.terminal::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

/* ============================================================
   Cabecera de arranque
   ============================================================ */
.terminal-header {
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  padding-bottom: 18px;
  margin-bottom: 22px;
  font-size: 13px;
}

.terminal-header pre {
  font-family: var(--font-display);
  line-height: 1.1;
  color: var(--accent);
  text-shadow: 0 0 12px var(--glow-color);
  margin-bottom: 16px;
  overflow-x: auto;
}

.tagline {
  color: var(--text-bright);
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 6px;
}

.tagline .pipe {
  color: var(--text-dim);
  font-weight: 400;
  margin: 0 4px;
}

.boot-line {
  color: var(--text-dim);
  font-size: 12.5px;
}

.boot-hint {
  color: var(--text-color);
  margin-top: 10px;
}

/* Insignias de comando (`help`, `whoami`, …) */
.cmd-badge {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent-bright);
  border-radius: 5px;
  padding: 1px 7px;
  font-size: 0.92em;
  text-shadow: 0 0 8px var(--glow-color);
}

/* ============================================================
   Salida de comandos
   ============================================================ */
.output-group {
  margin-bottom: 22px;
}

.command-echo {
  margin-bottom: 8px;
  display: flex;
  gap: 10px;
}

.command-echo .command-name {
  color: var(--text-bright);
  font-weight: 700;
}

.response-output {
  margin-left: 4px;
  padding-left: 16px;
  border-left: 2px solid color-mix(in srgb, var(--accent) 30%, transparent);
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-color);
}

.response-output.error {
  color: var(--error-color);
  border-left-color: color-mix(in srgb, var(--error-color) 45%, transparent);
  text-shadow: 0 0 8px var(--error-glow);
}

.response-output.suggestion {
  color: var(--warn-color);
  border-left-color: color-mix(in srgb, var(--warn-color) 45%, transparent);
}

/* Encabezados entre corchetes: [INTELIGENCIA ARTIFICIAL…] */
.response-output .section-title {
  color: var(--accent-bright);
  font-weight: 700;
  text-shadow: 0 0 8px var(--glow-color);
}

.terminal-link {
  color: var(--host-color);
  text-decoration: none;
  border-bottom: 1px dotted color-mix(in srgb, var(--host-color) 60%, transparent);
}

.terminal-link:hover {
  color: var(--accent-bright);
  border-bottom-color: var(--accent-bright);
}

/* ============================================================
   Prompt e input
   ============================================================ */
.command-line {
  display: flex;
  align-items: center;
  margin-top: 6px;
  padding-bottom: 14px;
  width: 100%;
}

.prompt-prefix {
  margin-right: 10px;
  white-space: nowrap;
  font-weight: 700;
}

.p-user { color: var(--accent); text-shadow: 0 0 8px var(--glow-color); }
.p-at { color: var(--text-dim); }
.p-host { color: var(--host-color); }
.p-path { color: var(--text-dim); }
.p-sign { color: var(--text-bright); margin-left: 2px; }

.input-wrapper {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
}

.terminal-input {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: transparent;
  caret-color: transparent;
  font-family: var(--font-family);
  font-size: 15px;
  z-index: 2;
}

.input-display {
  color: var(--text-bright);
  font-weight: 700;
  white-space: pre-wrap;
  word-break: break-all;
  z-index: 1;
}

.caret {
  display: inline-block;
  width: 9px;
  height: 1.15em;
  background-color: var(--accent);
  box-shadow: 0 0 8px var(--glow-color);
  animation: blink-caret 1s steps(1, start) infinite;
  z-index: 1;
}

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

/* ============================================================
   Chips de comandos rápidos
   ============================================================ */
.chips-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 20px 16px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  background-color: var(--bg-soft);
  border-radius: 0 0 12px 12px;
  flex-shrink: 0;
}

.chip-label {
  font-size: 11px;
  color: var(--text-dim);
  width: 100%;
  margin-bottom: 2px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
}

.chip-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-color);
  padding: 5px 13px;
  border-radius: 6px;
  font-family: var(--font-family);
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.18s ease;
  outline: none;
}

.chip-btn:hover {
  border-color: var(--accent);
  color: var(--accent-bright);
  box-shadow: 0 0 12px var(--glow-color);
  background-color: color-mix(in srgb, var(--accent) 10%, transparent);
}

.chip-btn:active {
  background-color: color-mix(in srgb, var(--accent) 22%, transparent);
}

/* El chip peligroso se ve peligroso */
.chip-btn.danger {
  border-color: color-mix(in srgb, var(--error-color) 40%, transparent);
  color: var(--error-color);
}

.chip-btn.danger:hover {
  border-color: var(--error-color);
  color: #fff;
  background-color: color-mix(in srgb, var(--error-color) 22%, transparent);
  box-shadow: 0 0 12px var(--error-glow);
}

/* ============================================================
   Secuencia de hackeo
   ============================================================ */
.hack-line {
  color: var(--text-color);
  white-space: pre;
}

.hack-line .bar {
  color: var(--accent-bright);
  text-shadow: 0 0 8px var(--glow-color);
}

.hack-line .ok {
  color: var(--accent-bright);
  font-weight: 700;
}

.hack-granted {
  color: var(--accent-bright);
  font-weight: 700;
  text-shadow: 0 0 14px var(--glow-color);
  letter-spacing: 2px;
}

/* ============================================================
   Kernel panic / crash
   ============================================================ */
@keyframes glitch-shake {
  0% { transform: translate(0, 0) skewX(0deg); filter: hue-rotate(0deg); }
  20% { transform: translate(-4px, 2px) skewX(1.5deg); filter: hue-rotate(90deg); }
  40% { transform: translate(5px, -3px) skewX(-2deg); filter: hue-rotate(200deg) invert(0.15); }
  60% { transform: translate(-6px, -1px) skewX(1deg); filter: hue-rotate(300deg); }
  80% { transform: translate(3px, 3px) skewX(-1deg); filter: hue-rotate(45deg) invert(0.1); }
  100% { transform: translate(0, 0) skewX(0deg); filter: hue-rotate(0deg); }
}

body.crashing .crt-screen {
  animation: glitch-shake 0.22s infinite steps(2);
}

.panic-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: #0a0000;
  color: var(--error-color);
  font-family: var(--font-family);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px;
  text-align: center;
  text-shadow: 0 0 14px var(--error-glow);
  animation: panic-in 0.12s steps(2);
}

@keyframes panic-in {
  from { opacity: 0; transform: scale(1.04); }
  to { opacity: 1; transform: scale(1); }
}

.panic-overlay pre {
  font-family: var(--font-display);
  line-height: 1.1;
  font-size: 12px;
  overflow-x: auto;
  max-width: 100%;
}

.panic-overlay .panic-msg {
  font-size: 14px;
  line-height: 1.9;
  color: #ff9d97;
}

.panic-overlay .panic-count {
  margin-top: 8px;
  color: var(--text-dim);
  font-size: 13px;
}

/* ============================================================
   Accesibilidad y responsive
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .crt-screen,
  .caret,
  body.crashing .crt-screen,
  .panic-overlay {
    animation: none !important;
  }
  .chip-btn {
    transition: none !important;
  }
  #matrix-canvas {
    transition: none !important;
  }
}

@media (max-width: 720px) {
  body {
    font-size: 13.5px;
  }
  .crt-wrapper {
    padding: 10px;
  }
  .crt-screen {
    max-height: none;
    border-radius: 10px;
  }
  .terminal {
    padding: 16px 14px 0 14px;
  }
  .window-title {
    display: none;
  }
  .terminal-header pre {
    font-size: 8px;
  }
  .chips-container {
    padding: 12px 14px;
  }
  .chip-btn {
    padding: 5px 10px;
    font-size: 11.5px;
  }
  .prompt-prefix {
    margin-right: 6px;
  }
}
