/* =====================================================================
 * styles.css — Estética cyberpunk/steampunk (verde oscuro · crema · cian)
 * ===================================================================== */

:root {
  --verde:      #2f6b3a;
  --verde-claro:#7dff9b;
  --verde-med:  #5fa35a;
  --negro:      #070a07;
  --negro-2:    #0d130e;
  --crema:      #efe6d0;
  --crema-dim:  #c9bb98;
  --cian:       #3fd0e0;
  --rojo:       #e0533a;
  --ambar:      #e0b23a;

  --font-mono: 'Courier New', 'Consolas', 'Roboto Mono', monospace;
  --font-sans: system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;

  --glow-green: 0 0 8px rgba(125, 255, 155, .55);
  --glow-cyan:  0 0 10px rgba(63, 208, 224, .55);
  --border: 1px solid rgba(125, 255, 155, .22);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--negro);
  color: var(--crema);
  font-family: var(--font-mono);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

body { position: relative; }

/* ===================== EFECTOS CRT / FONDO ===================== */
.fx { position: fixed; inset: 0; pointer-events: none; }
.fx-grid {
  background-image:
    linear-gradient(rgba(125,255,155,.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(125,255,155,.045) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse at center, #000 25%, transparent 85%);
  z-index: 0;
}
.fx-scanlines {
  background: repeating-linear-gradient(
    to bottom, rgba(0,0,0,0) 0px, rgba(0,0,0,0) 2px,
    rgba(0,0,0,.28) 3px, rgba(0,0,0,.28) 4px);
  z-index: 3; mix-blend-mode: multiply; opacity: .5;
}
.fx-vignette {
  background: radial-gradient(ellipse at center, transparent 45%, rgba(0,0,0,.85) 100%);
  z-index: 4;
}
.fx-flicker {
  background: rgba(125,255,155,.02);
  z-index: 5; animation: flicker 6s infinite steps(1);
}
@keyframes flicker {
  0%, 96%, 100% { opacity: 0; }
  97% { opacity: .5; }
  98% { opacity: 0; }
  99% { opacity: .35; }
}
.glitch-overlay { z-index: 40; opacity: 0; transition: opacity .12s; }
.glitch-overlay.flash-good {
  opacity: 1; animation: glitchFlash .9s steps(2);
  background: repeating-linear-gradient(0deg, rgba(125,255,155,.15) 0 3px, transparent 3px 7px);
}
.glitch-overlay.flash-bad {
  opacity: 1; animation: glitchFlash 1.2s steps(2);
  background: repeating-linear-gradient(0deg, rgba(224,83,58,.22) 0 3px, transparent 3px 8px);
}
@keyframes glitchFlash { 0%,100%{opacity:0} 30%{opacity:1} 60%{opacity:.2} 80%{opacity:.8} }

/* ===================== PANTALLAS ===================== */
.screen {
  position: fixed; inset: 0;
  display: none;
  flex-direction: column;
  z-index: 10;
  padding: clamp(12px, 2.4vw, 34px);
  overflow: auto;
}
.screen.active { display: flex; animation: fadeIn .4s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ===================== TIPOGRAFÍA / GLITCH ===================== */
.big-title {
  font-family: var(--font-sans);
  font-weight: 800;
  letter-spacing: .06em;
  font-size: clamp(1.7rem, 6vw, 4rem);
  line-height: 1;
  margin: .2em 0;
  color: var(--crema);
  text-transform: uppercase;
  position: relative;
}
.kicker {
  font-family: var(--font-sans);
  font-weight: 700;
  letter-spacing: .5em;
  color: var(--verde-claro);
  font-size: clamp(.7rem, 2.4vw, 1rem);
  text-transform: uppercase;
}
.glitch { position: relative; }
.glitch::before, .glitch::after {
  content: attr(data-text);
  position: absolute; left: 0; top: 0;
  width: 100%; overflow: hidden;
}
.glitch::before { color: var(--cian); clip-path: inset(0 0 55% 0); animation: gl1 3.4s infinite steps(2); }
.glitch::after  { color: var(--rojo); clip-path: inset(55% 0 0 0); animation: gl2 2.8s infinite steps(2); }
@keyframes gl1 { 0%,92%,100%{ transform: translate(0,0);} 93%{transform:translate(-3px,-2px);} 96%{transform:translate(3px,1px);} }
@keyframes gl2 { 0%,90%,100%{ transform: translate(0,0);} 91%{transform:translate(3px,2px);} 95%{transform:translate(-2px,-1px);} }

/* ===================== INTRO ===================== */
.intro-inner {
  margin: auto; max-width: 860px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  position: relative; z-index: 11;
}
.intro-face { width: clamp(160px, 30vw, 260px); filter: drop-shadow(0 0 24px rgba(125,255,155,.15)); }
.lead { color: var(--crema-dim); font-size: clamp(.9rem, 2.1vw, 1.05rem); line-height: 1.6; max-width: 640px; }
.lead strong { color: var(--verde-claro); }
.intro-actions { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }
.hint-tiny { color: rgba(201,187,152,.55); font-size: .72rem; letter-spacing: .12em; margin-top: 10px; }

/* ===================== BOTONES ===================== */
.btn {
  font-family: var(--font-mono);
  font-size: .9rem; letter-spacing: .08em;
  padding: 11px 20px; border-radius: 4px; cursor: pointer;
  border: 1px solid rgba(125,255,155,.35);
  background: rgba(125,255,155,.06);
  color: var(--crema); transition: all .15s ease;
  text-transform: uppercase;
}
.btn:hover { background: rgba(125,255,155,.16); box-shadow: var(--glow-green); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--verde); border-color: var(--verde-claro); color: #eaffef; font-weight: 700; }
.btn-primary:hover { background: #3d8a4c; box-shadow: 0 0 18px rgba(125,255,155,.5); }
.btn-danger { border-color: rgba(224,83,58,.5); background: rgba(224,83,58,.1); color: #ffd9d0; }
.btn-danger:hover { background: rgba(224,83,58,.22); box-shadow: 0 0 16px rgba(224,83,58,.45); }
.btn-ghost { background: transparent; color: var(--crema-dim); }
.btn-lg { font-size: 1.05rem; padding: 14px 34px; }
.btn-icon { padding: 8px 11px; font-size: 1rem; }

/* ===================== HUD ===================== */
.hud {
  display: flex; align-items: center; gap: 18px;
  padding: 8px 4px 14px; border-bottom: 1px solid rgba(125,255,155,.14);
  position: relative; z-index: 11; flex-wrap: wrap;
}
.hud-title { display: flex; align-items: baseline; gap: 8px; font-family: var(--font-sans); font-weight: 800; font-size: 1.15rem; letter-spacing: .1em; }
.hud-title .glitch { color: var(--crema); }
.hud-sub { color: var(--verde-claro); font-size: .7rem; letter-spacing: .25em; font-family: var(--font-mono); }
.dot-live { width: 9px; height: 9px; border-radius: 50%; background: var(--rojo); box-shadow: 0 0 10px var(--rojo); animation: blink 1s infinite; align-self: center; }
@keyframes blink { 50% { opacity: .25; } }

.hud-timer { flex: 1; min-width: 200px; }
.timer-label { display: flex; justify-content: space-between; font-size: .72rem; letter-spacing: .18em; color: var(--crema-dim); margin-bottom: 4px; }
.timer-bar { height: 8px; background: rgba(0,0,0,.5); border: 1px solid rgba(125,255,155,.2); border-radius: 5px; overflow: hidden; }
.timer-fill { height: 100%; width: 100%; background: linear-gradient(90deg, var(--verde-claro), var(--cian)); transition: background .3s; /* FIX: sin transición de width — el RAF ya anima cada frame; la transición congelaba la barra */ }
.timer-fill.low { background: linear-gradient(90deg, var(--ambar), var(--rojo)); animation: blink .6s infinite; }

.hud-controls { display: flex; gap: 8px; }

/* ===================== RECURSOS ===================== */
.resources { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; padding: 12px 0; position: relative; z-index: 11; }
.resource {
  display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
  background: rgba(13,19,14,.7); border: var(--border); border-radius: 6px;
  padding: 9px 12px; font-size: .82rem;
}
.res-icon { font-size: 1.05rem; }
.res-name { color: var(--crema-dim); letter-spacing: .05em; }
.res-val { margin-left: auto; color: var(--verde-claro); font-weight: 700; font-variant-numeric: tabular-nums; text-shadow: var(--glow-green); }
.res-unit { color: rgba(201,187,152,.55); font-size: .72rem; }

/* ===================== ESCENARIO ===================== */
.stage { flex: 1; display: grid; grid-template-columns: minmax(280px, 0.85fr) 1.15fr; gap: clamp(14px, 2vw, 28px); min-height: 0; position: relative; z-index: 11; padding-top: 14px; }
.stage-face { display: flex; flex-direction: column; align-items: center; gap: 14px; min-height: 0; }
.face-mount { width: clamp(200px, 26vw, 340px); max-height: 52vh; }
.face-mount.mini { width: clamp(140px, 22vw, 220px); }
.face-svg { width: 100%; height: auto; display: block; }
.face-mount.mini .face-svg { }

/* Animaciones de la cara */
.face-svg .face-mouth { transform-box: fill-box; transform-origin: center; transition: transform .12s ease; }
.face-svg.is-talking .face-mouth { animation: talk .28s infinite ease-in-out; }
@keyframes talk { 0%,100% { transform: scaleY(.45); } 50% { transform: scaleY(1.35); } }
.face-svg .face-sensor { animation: sensorPulse 2.4s infinite ease-in-out; }
@keyframes sensorPulse { 0%,100% { opacity: .5; } 50% { opacity: 1; } }
.face-svg .face-tear { animation: tearFall 3.6s infinite ease-in; transform-box: fill-box; transform-origin: top center; }
@keyframes tearFall { 0%,60% { transform: translateY(0); opacity: 1; } 100% { transform: translateY(30px); opacity: 0; } }
.face-svg .face-tear .tear-drop2 { animation: drop2 3.6s infinite ease-in; }
@keyframes drop2 { 0%,70% { opacity: 0; } 100% { opacity: 1; } }
.face-svg.is-angry { animation: angry .8s infinite steps(2); }
@keyframes angry { 0%,100% { filter: none; } 50% { filter: hue-rotate(-25deg) saturate(1.5) drop-shadow(0 0 16px rgba(224,83,58,.6)); } }
.face-svg.is-off { filter: grayscale(1) brightness(.55); transition: filter .6s; }
.face-svg.pulse-good { animation: pulseGood .7s; }
@keyframes pulseGood { 50% { filter: drop-shadow(0 0 26px rgba(125,255,155,.9)); } }
.face-svg.pulse-bad { animation: pulseBad .5s; }
@keyframes pulseBad { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-7px)} 75%{transform:translateX(7px)} }
.face-mount.mini .face-svg { animation: breathe 5s infinite ease-in-out; }
@keyframes breathe { 0%,100% { transform: scale(1); } 50% { transform: scale(1.03); } }

/* ===================== SUBTÍTULOS ===================== */
.speech-box {
  width: 100%; max-width: 460px; background: rgba(7,10,7,.72);
  border: var(--border); border-left: 3px solid var(--verde-claro);
  border-radius: 5px; padding: 12px 14px; min-height: 96px;
}
.speech-status { color: var(--rojo); font-size: .7rem; letter-spacing: .22em; margin-bottom: 6px; animation: blink 1.4s infinite; }
.speech-text { margin: 0; font-size: clamp(.82rem, 1.7vw, .95rem); line-height: 1.55; color: var(--crema); white-space: pre-line; min-height: 4.5em; }
.speech-text .line-dim { color: rgba(201,187,152,.4); display: block; }
.speech-text .line-cur { color: var(--crema); display: block; }
.speech-text .caret { color: var(--verde-claro); animation: blink .8s steps(2) infinite; }

/* ===================== ESCRITORIO ===================== */
.stage-desktop { display: flex; flex-direction: column; min-height: 0; gap: 12px; }
.desktop-bar { display: flex; justify-content: space-between; align-items: center; font-size: .74rem; letter-spacing: .12em; color: var(--crema-dim); border-bottom: 1px dashed rgba(125,255,155,.18); padding-bottom: 8px; }
.desktop-count { color: var(--verde-claro); }
.folders {
  flex: 1; display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 10px; overflow-y: auto; padding: 4px 6px 4px 0; align-content: start;
}
.folder {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: rgba(13,19,14,.7); border: var(--border); border-radius: 7px;
  padding: 13px 6px 10px; cursor: pointer; color: var(--crema);
  font-family: var(--font-mono); font-size: .74rem; text-align: center;
  transition: all .14s ease; position: relative; overflow: hidden;
}
.folder:hover { background: rgba(125,255,155,.1); box-shadow: var(--glow-green); transform: translateY(-2px); border-color: var(--verde-claro); }
.folder-icon { font-size: 1.9rem; line-height: 1; filter: drop-shadow(0 3px 4px rgba(0,0,0,.6)); }
.folder-name { word-break: break-word; color: var(--crema-dim); }
.folder-badge { font-size: .62rem; letter-spacing: .18em; color: var(--verde-claro); opacity: 0; transition: opacity .2s; }
.folder:hover .folder-badge { opacity: 1; }
.folder.is-open { opacity: .5; border-style: dashed; }
.folder.is-open::after { content: '✓ leída'; position: absolute; top: 4px; right: 6px; font-size: .58rem; color: var(--verde-claro); }

/* ===================== TERMINAL ===================== */
.terminal { background: rgba(0,0,0,.55); border: 1px solid rgba(224,83,58,.25); border-radius: 6px; padding: 11px 13px; }
.terminal-label { display: block; font-size: .72rem; color: var(--rojo); letter-spacing: .08em; margin-bottom: 7px; }
.terminal-row { display: flex; align-items: center; gap: 8px; }
.prompt { color: var(--verde-claro); font-weight: 700; }
.terminal-input {
  flex: 1; background: transparent; border: none; border-bottom: 1px solid rgba(125,255,155,.3);
  color: var(--crema); font-family: var(--font-mono); font-size: 1rem; letter-spacing: .14em;
  padding: 6px 2px; text-transform: uppercase; outline: none;
}
.terminal-input:focus { border-color: var(--verde-claro); box-shadow: 0 4px 12px -8px var(--verde-claro); }
.terminal-msg { margin: 8px 0 0; font-size: .76rem; min-height: 1em; letter-spacing: .05em; }
.terminal-msg.ok { color: var(--verde-claro); }
.terminal-msg.err { color: var(--rojo); }
.terminal-msg.warn { color: var(--ambar); }
.terminal.shake { animation: shake .38s; }
@keyframes shake { 10%,90%{transform:translateX(-2px)} 30%,70%{transform:translateX(4px)} 50%{transform:translateX(-5px)} }

/* ===================== MODAL ===================== */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 18px; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.78); backdrop-filter: blur(3px); opacity: 0; transition: opacity .2s; }
.modal.open .modal-backdrop { opacity: 1; }
.modal-card {
  position: relative; width: min(560px, 100%); background: #0e140f;
  border: 1px solid rgba(125,255,155,.3); border-radius: 8px; overflow: hidden;
  box-shadow: 0 0 40px rgba(0,0,0,.7), inset 0 0 40px rgba(125,255,155,.04);
  transform: translateY(14px) scale(.97); opacity: 0; transition: all .22s cubic-bezier(.2,.9,.3,1.2);
}
.modal.open .modal-card { transform: translateY(0) scale(1); opacity: 1; }
.modal-card.is-code { border-color: var(--verde-claro); box-shadow: 0 0 46px rgba(125,255,155,.35); }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; background: rgba(125,255,155,.06); border-bottom: 1px solid rgba(125,255,155,.16); }
.modal-icon { font-size: 1.5rem; }
.modal-title { flex: 1; font-family: var(--font-sans); font-weight: 700; letter-spacing: .1em; font-size: .95rem; }
.modal-close { background: none; border: none; color: var(--crema-dim); font-size: 1.1rem; cursor: pointer; padding: 4px 8px; }
.modal-close:hover { color: var(--rojo); }
.modal-body { padding: 20px 18px; min-height: 90px; display: flex; align-items: center; }
.modal-text { margin: 0; font-size: clamp(.95rem, 2.4vw, 1.15rem); line-height: 1.55; }
.modal-card.is-code .modal-text { line-height: 1.7; }
.code-lead { color: var(--crema-dim); font-size: .82rem; letter-spacing: .1em; }
.code-big { display: block; margin: 12px 0 4px; font-size: clamp(1.6rem, 6vw, 2.4rem); font-weight: 800; color: var(--verde-claro); text-shadow: var(--glow-green); letter-spacing: .18em; }
.code-note { display: block; color: var(--crema-dim); font-size: .82rem; margin-top: 6px; }
.modal-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border-top: 1px solid rgba(125,255,155,.14); }
.modal-tag { font-size: .68rem; letter-spacing: .16em; padding: 5px 10px; border-radius: 4px; }
.tag-eco { color: var(--ambar); background: rgba(224,178,58,.12); border: 1px solid rgba(224,178,58,.35); }
.tag-code { color: var(--verde-claro); background: rgba(125,255,155,.14); border: 1px solid var(--verde-claro); }

/* ===================== PANTALLA FINAL ===================== */
.ending { background: radial-gradient(ellipse at center, rgba(13,19,14,.9), rgba(0,0,0,.97)); }
.ending-inner { margin: auto; max-width: 760px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 16px; position: relative; z-index: 11; }
.big-title.win { color: var(--verde-claro); text-shadow: var(--glow-green); }
.big-title.lose { color: var(--rojo); text-shadow: 0 0 14px rgba(224,83,58,.6); }
.ending-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; width: 100%; margin-top: 6px; }
.stat { background: rgba(13,19,14,.8); border: var(--border); border-radius: 7px; padding: 14px 8px; display: flex; flex-direction: column; gap: 5px; }
.stat-num { font-size: clamp(1.2rem, 4vw, 1.8rem); font-weight: 800; color: var(--verde-claro); font-variant-numeric: tabular-nums; }
.stat-lbl { font-size: .66rem; letter-spacing: .12em; color: var(--crema-dim); }
.ending-actions { margin-top: 8px; }

/* ===================== RESPONSIVE ===================== */
@media (max-width: 860px) {
  html, body { overflow: auto; }
  .stage { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .face-mount { max-height: 34vh; }
  .resources { grid-template-columns: repeat(2, 1fr); }
  .ending-stats { grid-template-columns: repeat(2, 1fr); }
  .speech-box { max-width: 100%; }
}
@media (max-width: 520px) {
  .kicker { letter-spacing: .3em; }
  .hud { gap: 10px; }
  .hud-title { font-size: 1rem; }
}

/* Scrollbars temáticos */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: rgba(0,0,0,.4); }
::-webkit-scrollbar-thumb { background: rgba(125,255,155,.25); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: rgba(125,255,155,.45); }

/* Accesibilidad: respetar reduce-motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; }
}
