/* ===== CSS VARIABLES & RESET ===== */
:root {
  --bg-primary: #050508;
  --bg-secondary: #0a0a12;
  --bg-card: #0f0f1a;
  --bg-choice: #111120;
  --color-red: #ff2244;
  --color-red-dim: #8b1a2a;
  --color-cyan: #00ffcc;
  --color-cyan-dim: #007755;
  --color-amber: #ffaa00;
  --color-amber-dim: #7a5200;
  --color-purple: #aa44ff;
  --color-purple-dim: #552288;
  --color-green: #44ff88;
  --color-green-dim: #1a6633;
  --color-text: #c8c8d8;
  --color-text-dim: #6a6a88;
  --color-border: rgba(0,255,204,0.12);
  --color-border-bright: rgba(0,255,204,0.35);
  --font-main: 'Courier New', monospace;
  --transition-fast: 0.2s ease;
  --transition-scene: 0.5s ease;
}

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

html, body {
  width: 100%; height: 100%;
  background: var(--bg-primary);
  color: var(--color-text);
  font-family: var(--font-main);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); border: 0;
}

/* ===== SCREENS ===== */
#app { width: 100vw; height: 100vh; position: relative; overflow: hidden; }

.screen { position: absolute; inset: 0; display: none; flex-direction: column; }
.screen.active { display: flex; }

/* ===== NAME SCREEN ===== */
#name-screen {
  align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, #0d0d20 0%, #050508 70%);
}

.name-container {
  display: flex; flex-direction: column; align-items: center;
  gap: 1.5rem; padding: 2rem; max-width: 500px; width: 100%;
  text-align: center;
}

.glitch-logo {
  font-size: clamp(2.5rem, 8vw, 4.5rem);
  font-weight: 700;
  color: var(--color-cyan);
  letter-spacing: 0.2em;
  text-shadow: 0 0 20px var(--color-cyan), 0 0 40px rgba(0,255,204,0.3);
  position: relative;
  animation: glitch-main 4s infinite;
}
.glitch-logo::before, .glitch-logo::after {
  content: attr(data-text);
  position: absolute; top: 0; left: 0; width: 100%;
}
.glitch-logo::before {
  color: var(--color-red);
  animation: glitch-1 4s infinite;
  clip-path: polygon(0 30%, 100% 30%, 100% 50%, 0 50%);
}
.glitch-logo::after {
  color: var(--color-purple);
  animation: glitch-2 4s infinite;
  clip-path: polygon(0 60%, 100% 60%, 100% 80%, 0 80%);
}

@keyframes glitch-main {
  0%, 90%, 100% { transform: none; }
  91% { transform: skewX(-2deg); }
  93% { transform: skewX(2deg); }
  95% { transform: none; }
}
@keyframes glitch-1 {
  0%, 90%, 100% { transform: none; opacity: 0; }
  91% { transform: translate(-3px, 1px); opacity: 0.8; }
  94% { transform: translate(3px, -1px); opacity: 0.6; }
  96% { opacity: 0; }
}
@keyframes glitch-2 {
  0%, 88%, 100% { transform: none; opacity: 0; }
  89% { transform: translate(3px, 2px); opacity: 0.7; }
  92% { transform: translate(-3px, -2px); opacity: 0.5; }
  95% { opacity: 0; }
}

.subtitle {
  font-size: 0.65rem; letter-spacing: 0.3em;
  color: var(--color-text-dim); text-transform: uppercase;
}

.intro-text {
  font-size: 0.9rem; line-height: 1.8;
  color: var(--color-text); max-width: 380px;
  border-left: 2px solid var(--color-red-dim);
  padding-left: 1rem; text-align: left;
}

.name-form {
  display: flex; flex-direction: column; gap: 1rem;
  width: 100%; max-width: 320px;
}

#player-name {
  background: transparent;
  border: 1px solid var(--color-border-bright);
  color: var(--color-cyan);
  font-family: var(--font-main);
  font-size: 1rem; letter-spacing: 0.15em;
  padding: 0.75rem 1rem; text-align: center;
  outline: none; text-transform: uppercase;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
#player-name:focus {
  border-color: var(--color-cyan);
  box-shadow: 0 0 12px rgba(0,255,204,0.2);
}
#player-name::placeholder { color: var(--color-text-dim); }

.btn-primary, .btn-secondary {
  font-family: var(--font-main);
  letter-spacing: 0.2em; text-transform: uppercase;
  border: none; cursor: pointer;
  transition: all var(--transition-fast);
  font-size: 0.85rem;
}
.btn-primary {
  background: var(--color-cyan); color: #050508;
  padding: 0.85rem 2rem; font-weight: 700;
}
.btn-primary:hover { background: #fff; transform: translateY(-2px); box-shadow: 0 0 20px var(--color-cyan); }
.btn-primary:active { transform: translateY(0); }

.resume-section { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; }
.resume-text { font-size: 0.65rem; letter-spacing: 0.3em; color: var(--color-amber); }
.btn-secondary {
  background: transparent;
  border: 1px solid var(--color-amber);
  color: var(--color-amber); padding: 0.6rem 1.5rem;
}
.btn-secondary:hover { background: rgba(255,170,0,0.1); box-shadow: 0 0 12px rgba(255,170,0,0.3); }
.hidden { display: none !important; }

/* ===== GAME SCREEN ===== */
#game-screen {
  flex-direction: column;
  background: var(--bg-primary);
}

/* TOP BAR */
.top-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.6rem 1rem; background: rgba(5,5,8,0.95);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0; gap: 1rem; z-index: 10;
}

.stats-group { display: flex; gap: 1rem; flex: 1; }

.stat-block {
  display: flex; align-items: center; gap: 6px;
  flex: 1; max-width: 160px;
}
.stat-label {
  font-size: 0.6rem; letter-spacing: 0.15em;
  color: var(--color-text-dim); min-width: 32px;
}
.stat-bar-wrap {
  flex: 1; height: 4px;
  background: rgba(255,255,255,0.08);
  position: relative; overflow: hidden;
}
.stat-bar {
  height: 100%; width: 50%;
  transition: width 0.6s ease;
}
.health-bar { background: var(--color-red); }
.intel-bar { background: var(--color-purple); }
.trust-bar { background: var(--color-cyan); }
.stat-num {
  font-size: 0.6rem; color: var(--color-text-dim);
  min-width: 24px; text-align: right;
}

.top-actions { display: flex; gap: 0.5rem; }
.btn-icon {
  background: transparent; border: 1px solid var(--color-border);
  color: var(--color-text-dim); font-size: 1rem;
  width: 32px; height: 32px; cursor: pointer;
  transition: all var(--transition-fast);
  display: flex; align-items: center; justify-content: center;
}
.btn-icon:hover { border-color: var(--color-cyan); color: var(--color-cyan); }

/* INVENTORY */
.inventory-bar {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.4rem 1rem; background: rgba(5,5,8,0.9);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0; min-height: 36px; flex-wrap: wrap;
}
.inv-label {
  font-size: 0.6rem; letter-spacing: 0.2em;
  color: var(--color-text-dim);
}
.inventory-slots { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.inv-item {
  background: var(--bg-choice);
  border: 1px solid var(--color-amber-dim);
  color: var(--color-amber);
  font-size: 0.65rem; letter-spacing: 0.1em;
  padding: 3px 8px; cursor: default;
  animation: itemAppear 0.3s ease;
}
@keyframes itemAppear {
  from { transform: scale(0.5); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* SCENE AREA */
.scene-area {
  flex: 1; position: relative;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; transition: background 0.8s ease;
  min-height: 0;
}
.scene-area.scene-dark { background: #030305; }
.scene-area.scene-lab { background: radial-gradient(ellipse, #050818 0%, #030305 100%); }
.scene-area.scene-corridor { background: radial-gradient(ellipse, #08040a 0%, #030305 100%); }
.scene-area.scene-danger { background: radial-gradient(ellipse, #150308 0%, #030305 100%); }
.scene-area.scene-escape { background: radial-gradient(ellipse, #030d0a 0%, #030305 100%); }
.scene-area.scene-end { background: radial-gradient(ellipse, #0a0510 0%, #030305 100%); }

.scene-overlay {
  position: absolute; inset: 0; pointer-events: none;
  animation: scanlines 8s linear infinite; opacity: 0.03;
  background: repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(255,255,255,0.5) 2px, rgba(255,255,255,0.5) 3px);
  background-size: 100% 3px;
}
@keyframes scanlines { from { background-position: 0 0; } to { background-position: 0 100px; } }

.scene-content {
  position: relative; z-index: 2;
  max-width: 720px; width: 100%;
  padding: 1.5rem 2rem;
  display: flex; flex-direction: column; gap: 1rem;
}

.scene-tag {
  font-size: 0.6rem; letter-spacing: 0.3em;
  color: var(--color-cyan-dim); text-transform: uppercase;
  min-height: 1em;
}

.story-text {
  font-size: clamp(0.85rem, 2vw, 1rem);
  line-height: 1.9; color: var(--color-text);
  min-height: 6em;
}

.story-text .cursor {
  display: inline-block; width: 2px; height: 1em;
  background: var(--color-cyan); margin-left: 2px;
  animation: blink 0.7s infinite;
  vertical-align: text-bottom;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

.story-text .highlight { color: var(--color-amber); }
.story-text .danger { color: var(--color-red); }

.npc-dialogue {
  border-left: 2px solid var(--color-purple-dim);
  padding: 0.75rem 1rem;
  background: rgba(170,68,255,0.05);
  font-size: 0.9rem; line-height: 1.7;
  color: rgba(170,68,255,0.9);
  min-height: 0; display: none;
}
.npc-dialogue.visible { display: block; }
.npc-name {
  font-size: 0.65rem; letter-spacing: 0.2em;
  color: var(--color-purple); margin-bottom: 0.3rem;
  text-transform: uppercase;
}

/* CHOICES */
.choices-section {
  flex-shrink: 0; padding: 1rem;
  background: rgba(5,5,8,0.95);
  border-top: 1px solid var(--color-border);
}

.choices-container {
  display: grid; gap: 0.6rem;
  grid-template-columns: 1fr 1fr;
  max-width: 720px; margin: 0 auto;
}

.choice-btn {
  background: var(--bg-choice);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  font-family: var(--font-main);
  font-size: 0.8rem; letter-spacing: 0.08em;
  padding: 0.8rem 1rem; cursor: pointer;
  text-align: left; line-height: 1.4;
  transition: all var(--transition-fast);
  position: relative; overflow: hidden;
}
.choice-btn::before {
  content: ''; position: absolute;
  left: 0; top: 0; bottom: 0; width: 0;
  background: var(--color-cyan); opacity: 0.08;
  transition: width 0.3s ease;
}
.choice-btn:hover::before { width: 100%; }
.choice-btn:hover {
  border-color: var(--color-cyan-dim);
  color: var(--color-cyan);
  transform: translateY(-1px);
}
.choice-btn:active { transform: translateY(0); }
.choice-btn:focus { outline: 1px solid var(--color-cyan); outline-offset: 2px; }
.choice-btn .choice-num {
  display: inline-block; margin-right: 8px;
  color: var(--color-cyan-dim); font-size: 0.7rem;
}
.choice-btn.unavailable {
  opacity: 0.35; cursor: not-allowed;
}
.choice-btn.unavailable:hover { transform: none; }

/* ENDING BOX */
.ending-box {
  max-width: 720px; margin: 0 auto;
  background: rgba(10,10,20,0.95);
  border: 1px solid var(--color-border-bright);
  padding: 1.5rem; text-align: center;
}
.ending-title {
  font-size: 1.2rem; letter-spacing: 0.3em;
  color: var(--color-cyan); margin-bottom: 0.5rem;
  text-transform: uppercase;
}
.ending-subtitle { color: var(--color-text-dim); font-size: 0.75rem; letter-spacing: 0.2em; margin-bottom: 1rem; }
.ending-stats {
  font-size: 0.75rem; color: var(--color-text-dim);
  margin-bottom: 1rem; line-height: 1.8;
}
.ending-actions { display: flex; justify-content: center; gap: 1rem; flex-wrap: wrap; }
.btn-ending {
  background: transparent; border: 1px solid var(--color-cyan);
  color: var(--color-cyan); font-family: var(--font-main);
  font-size: 0.75rem; letter-spacing: 0.15em;
  padding: 0.6rem 1.5rem; cursor: pointer;
  text-transform: uppercase; transition: all var(--transition-fast);
}
.btn-ending:hover { background: rgba(0,255,204,0.1); }

/* KEYBOARD HINT */
.kb-hint {
  text-align: center; font-size: 0.55rem;
  color: var(--color-text-dim); letter-spacing: 0.1em;
  padding: 0.3rem; background: rgba(5,5,8,0.9);
  border-top: 1px solid var(--color-border);
}

/* TRANSITION OVERLAY */
.transition-overlay {
  position: fixed; inset: 0; background: #000;
  opacity: 0; pointer-events: none;
  z-index: 1000;
  transition: opacity 0.4s ease;
}
.transition-overlay.fade-in { opacity: 1; pointer-events: all; }
.transition-overlay.fade-out { opacity: 0; pointer-events: none; }

/* NOTIFICATION */
.notification {
  position: fixed; bottom: 2rem; left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-card);
  border: 1px solid var(--color-cyan-dim);
  color: var(--color-cyan); font-size: 0.75rem;
  letter-spacing: 0.15em; padding: 0.6rem 1.5rem;
  z-index: 2000;
  transition: transform 0.3s ease;
}
.notification.visible { transform: translateX(-50%) translateY(0); }

/* ===== FLICKER ANIMATION ===== */
@keyframes flicker {
  0%, 100% { opacity: 1; }
  92% { opacity: 1; }
  93% { opacity: 0.4; }
  94% { opacity: 1; }
  96% { opacity: 0.6; }
  97% { opacity: 1; }
}
.scene-area.flicker { animation: flicker 3s infinite; }

/* ===== PULSE GLOW ===== */
@keyframes pulse-danger {
  0%, 100% { box-shadow: inset 0 0 30px rgba(255,34,68,0); }
  50% { box-shadow: inset 0 0 30px rgba(255,34,68,0.15); }
}
.scene-area.pulse-danger { animation: pulse-danger 2s ease-in-out infinite; }

/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
  .stats-group { gap: 0.5rem; }
  .stat-block { max-width: 100px; }
  .stat-label { font-size: 0.55rem; min-width: 24px; }
  .choices-container { grid-template-columns: 1fr; }
  .scene-content { padding: 1rem; }
  .story-text { font-size: 0.85rem; }
  .glitch-logo { font-size: 2.2rem; }
  .kb-hint { display: none; }
}

@media (max-width: 380px) {
  .top-bar { padding: 0.4rem 0.6rem; }
  .stats-group { gap: 0.3rem; }
  .stat-num { display: none; }
}

/* ===== CHOICE ITEM ANIMATIONS ===== */
.choice-btn {
  animation: choiceIn 0.3s ease backwards;
}
.choice-btn:nth-child(1) { animation-delay: 0.05s; }
.choice-btn:nth-child(2) { animation-delay: 0.1s; }
.choice-btn:nth-child(3) { animation-delay: 0.15s; }
.choice-btn:nth-child(4) { animation-delay: 0.2s; }

@keyframes choiceIn {
  from { transform: translateY(10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Scene fade */
.scene-content {
  animation: sceneFade 0.5s ease;
}
@keyframes sceneFade {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
