:root {
  --bg: #050505;
  --panel: #0a0a0a;
  --text: #a1a1aa;
  --text-bright: #e4e4e7;
  --accent: #4ade80;
  --accent-dim: rgba(74, 222, 128, 0.2);
  --border: #27272a;
  --hp: #ef4444;
  --font-mono: 'JetBrains Mono', 'Courier New', monospace;
  --frame-border: 2px solid #3f3f46;
}

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

body {
  background: #000;
  color: var(--text);
  font-family: var(--font-mono);
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  transition: background 0.5s;
}

pre {
  font-family: var(--font-mono); /* ya lo tienes definido */
  margin: 0.5em 0;
}

.ascii-art,
.separator,
.quote {
  text-align: center;
}

/* --- Artifact Container (Grid Layout) --- */
#artifact-container {
  width: 98%;
  max-width: 1400px; /* Slightly reduced for compactness */
  height: 90vh;      /* Reduced to prevent edge touching */
  display: grid;
  grid-template-columns: 1fr 300px; /* Scene | HUD */
  grid-template-rows: 1fr 200px;    /* Scene | Console (Fixed height for stability) */
  gap: 0; /* GAPLESS DESIGN for solid artifact feel */
  background: var(--bg);
  padding: 0; /* Content fills the frame */
  border: 2px solid #3f3f46; /* Outer frame */
  box-shadow: 
    0 0 0 4px #000, /* Inner black spacing */
    0 0 0 6px #27272a, /* Second outer ring */
    0 0 40px rgba(0,0,0,0.9);
  overflow: hidden; /* Contain everything */
}

/* --- Main View (ASCII Scene) --- */
#main-view {
  grid-column: 1 / 2;
  grid-row: 1 / 2;
  background: #000;
  position: relative;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  box-shadow: inset 0 0 60px rgba(0,0,0,0.8);
}

#scene-frame {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 2rem;
}

#ascii-scene {
  font-family: var(--font-mono);
  font-size: 13px; /* Optimized for density */
  line-height: 1.1; 
  white-space: pre;
  color: var(--accent);
  text-shadow: 0 0 6px var(--accent-dim);
  transition: opacity 0.5s, color 0.5s;
  font-weight: bold;
  transform: scale(1); 
  max-width: 100%;
  max-height: 100%;
  overflow: hidden; /* Prevent spill */
  display: block;
}

/* --- HUD Panel --- */
#hud-panel {
  grid-column: 2 / 3;
  grid-row: 1 / 3; /* Full Height */
  display: flex;
  flex-direction: column;
  background: #0a0a0a;
  border-left: 1px solid var(--border);
  overflow: hidden;
}

.hud-module {
  background: transparent;
  border-bottom: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  box-shadow: none; /* Flat style */
}

.module-header {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 2px;
  color: #52525b;
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-transform: uppercase;
}

/* Vitals (Top) */
#vitals-module { flex: 0 0 auto; background: rgba(255,255,255,0.02); }
.stat-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 0.85rem;
  font-weight: bold;
}
.stat-label { color: #71717a; font-size: 0.75rem; letter-spacing: 1px; }
#hud-hp { color: var(--hp); }

.bar-track {
  width: 100%;
  height: 8px; /* Slimmer bar */
  background: #18181b;
  border: 1px solid #3f3f46;
  margin-bottom: 0;
  position: relative;
  overflow: hidden;
}
#hp-bar {
  height: 100%;
  background: var(--hp);
  width: 100%;
  transition: width 0.4s ease;
  box-shadow: 0 0 8px var(--hp);
}

/* Minimap (Center) */
#minimap-module { flex: 0 0 auto; padding-bottom: 20px; }
#minimap-wrapper {
  display: flex;
  justify-content: center;
  background: #000;
  padding: 12px;
  border: 1px solid #27272a;
  margin-bottom: 12px;
  min-height: 100px;
  align-items: center;
}
#minimap {
  font-size: 11px;
  line-height: 11px;
  color: #52525b;
  font-weight: bold;
}
.loc-info {
  text-align: center;
  border-top: 1px solid #27272a;
  padding-top: 10px;
}
#hud-loc { 
  color: var(--accent); 
  font-weight: bold; 
  font-size: 0.85rem; 
  margin-bottom: 4px; 
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
#hud-exits {
  font-size: 0.7rem;
  color: #52525b;
  font-family: var(--font-mono);
}

/* Inventory (Bottom - Fills remaining space) */
#inventory-module { 
  flex: 1 1 auto; 
  overflow: hidden; 
  border-bottom: none; 
  display: flex; 
  flex-direction: column; 
}
.equipment-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 12px;
  flex: 0 0 auto;
}
.eq-slot {
  background: rgba(255,255,255,0.03);
  padding: 8px 12px;
  border: 1px solid #27272a;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.eq-label {
  font-size: 0.65rem;
  color: #52525b;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.eq-val {
  font-size: 0.8rem;
  color: #d4d4d8;
  font-weight: bold;
}

.inv-separator {
  height: 1px;
  background: #27272a;
  margin-bottom: 8px;
  flex: 0 0 auto;
}
#inv-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  font-size: 0.8rem;
  padding-right: 4px;
}
#inv-list li {
  padding: 6px 8px;
  border-bottom: 1px solid #18181b;
  color: #a1a1aa;
  transition: background 0.2s;
}
#inv-list li:hover {
  background: rgba(255,255,255,0.05);
  color: #fff;
}

/* --- Terminal Panel --- */
#terminal-panel {
  grid-column: 1 / 2;
  grid-row: 2 / 3;
  background: #050505;
  display: flex;
  flex-direction: column;
  font-family: var(--font-mono);
  position: relative;
  border-right: 1px solid var(--border);
  /* No border-top needed as main-view has border-bottom */
}

#output {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  font-size: 0.95rem;
  line-height: 1.5;
  color: #d4d4d8;
  /* Scrollbar inside */
}

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #09090b; }
::-webkit-scrollbar-thumb { background: #3f3f46; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #52525b; }

.log { margin-bottom: 8px; animation: fadeIn 0.2s ease-out; }
.log-cmd { 
  color: #71717a; 
  font-size: 0.8em; 
  margin-top: 12px; 
  border-top: 1px solid #18181b; 
  padding-top: 6px; 
  font-style: italic;
}
.log-narrative { color: #e4e4e7; }
.log-success { color: #60a5fa; border-left: 2px solid #60a5fa; padding-left: 10px; }
.log-error { color: #f87171; border-left: 2px solid #f87171; padding-left: 10px; }

/* Input Form - Integrated at bottom */
#input-form {
  flex: 0 0 auto; /* Fixed height */
  display: flex;
  align-items: center;
  background: #000;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  width: 100%;
  box-sizing: border-box; /* Critical for containment */
}
#prompt {
  color: var(--accent);
  font-weight: bold;
  margin-right: 12px;
  font-size: 1.1rem;
  text-shadow: 0 0 5px var(--accent-dim);
}
#cmd-input {
  flex: 1;
  background: transparent;
  border: none;
  color: #fff;
  font-family: var(--font-mono);
  font-size: 1rem;
  outline: none;
  letter-spacing: 0.5px;
  min-width: 0; /* Prevent flex overflow */
}

/* --- Intro Overlay --- */
#intro-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #000;
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  padding: 2rem;
  transition: opacity 1s ease;
}
#intro-overlay.hidden { opacity: 0; pointer-events: none; }
#intro-content { max-width: 800px; text-align: center; }
#intro-ascii {
  font-size: 14px;
  color: var(--accent);
  margin-bottom: 2rem;
  animation: pulse 3s infinite;
  white-space: pre;
}
#intro-text {
  font-size: 1.2rem;
  line-height: 1.6;
  color: #e2e8f0;
  margin-bottom: 2rem;
  min-height: 100px;
}
#skip-hint {
  position: absolute;
  top: 2rem;
  right: 2rem;
  font-size: 0.8rem;
  color: #64748b;
  border: 1px solid #334155;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  opacity: 0.7;
}

/* --- Animations --- */
@keyframes pulse {
  0% { opacity: 0.7; text-shadow: 0 0 5px var(--accent); }
  50% { opacity: 1; text-shadow: 0 0 15px var(--accent); }
  100% { opacity: 0.7; text-shadow: 0 0 5px var(--accent); }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes flicker { 
  0% { opacity: 0.9; } 
  25% { opacity: 1; } 
  50% { opacity: 0.85; } 
  75% { opacity: 1; } 
  100% { opacity: 0.9; } 
}
@keyframes float { 
  0% { transform: translateY(0); } 
  50% { transform: translateY(-3px); } 
  100% { transform: translateY(0); } 
}
@keyframes shake { 
  0% { transform: translate(0.5px, 0.5px); } 
  25% { transform: translate(-0.5px, -0.5px); } 
  50% { transform: translate(-0.5px, 0.5px); } 
  75% { transform: translate(0.5px, -0.5px); } 
  100% { transform: translate(0.5px, 0.5px); } 
}

.anim-float { animation: float 4s ease-in-out infinite; }
.anim-pulse { animation: pulse 2s ease-in-out infinite; }
.anim-shake { animation: shake 0.2s linear infinite; }
.anim-flicker { animation: flicker 0.15s infinite; }

/* --- Theme Overrides --- */
body.theme-bosque { --accent: #4ade80; --bg: #020602; }
body.theme-cueva { --accent: #a78bfa; --bg: #05020a; }
body.theme-ruinas { --accent: #fbbf24; --bg: #0a0802; }
body.theme-templo { --accent: #38bdf8; --bg: #02080a; }
body.theme-volcan { --accent: #f87171; --bg: #0a0202; }

/* Minimap Colors */
.map-cell { color: #3f3f46; }
.map-cell.discovered { color: #71717a; }
.map-cell.current { color: var(--accent); font-weight: 900; text-shadow: 0 0 8px var(--accent); }
.map-cell.enemy { color: #ef4444; animation: pulse 1s infinite; }

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
}
.btn-icon:hover { background: var(--border); color: #fff; }

@media (max-width: 1024px) {
  #artifact-container {
    grid-template-columns: 1fr;
    grid-template-rows: 40vh auto 1fr;
  }
  #main-view { grid-column: 1 / 2; grid-row: 1 / 2; }
  #hud-panel { grid-column: 1 / 2; grid-row: 2 / 3; flex-direction: row; flex-wrap: wrap; }
  .hud-module { flex: 1; min-width: 200px; }
  #terminal-panel { grid-column: 1 / 2; grid-row: 3 / 4; }
}
