/* ══════════════════════════════════════
   NARRATIA — Estilos principales
   ══════════════════════════════════════ */

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

:root {
  --castillo-primary: #c8962a;
  --castillo-bg: #1a0f05;
  --cyber-primary: #ff3b3b;
  --cyber-bg: #020d1a;
  --estancia-primary: #c8a97a;
  --estancia-bg: #0d0a05;
  --surface: rgba(255,255,255,0.05);
  --border: rgba(255,255,255,0.08);
  --text: #e8e0d0;
  --text-dim: rgba(232,224,208,0.5);
}

html, body {
  height: 100%;
  overflow: hidden;
  background: #0a0a0f;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ── SCREENS ── */
.screen { position: fixed; inset: 0; display: none; flex-direction: column; overflow: hidden; }
.screen.active { display: flex; }

/* ══════════════════════════════════════
   PANTALLA SELECCIÓN DE MUNDO
   ══════════════════════════════════════ */
#screen-select { overflow-y: auto; background: #0a0a0f; }

.select-bg {
  position: fixed; inset: 0; z-index: 0;
  background:
    radial-gradient(ellipse at 20% 20%, rgba(100,60,20,0.3) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 80%, rgba(60,20,100,0.2) 0%, transparent 60%);
  pointer-events: none;
}

.select-content {
  position: relative; z-index: 1;
  padding: 2rem 1.5rem 3rem;
  max-width: 480px; margin: 0 auto;
  min-height: 100%;
  display: flex; flex-direction: column; gap: 2rem;
}

/* Logo */
.logo-wrap { text-align: center; padding-top: 1rem; }
.logo-icon { font-size: 2.5rem; margin-bottom: 0.5rem; }
.logo-title {
  font-family: 'Cinzel', serif;
  font-size: 2.4rem; font-weight: 900;
  letter-spacing: 0.15em;
  background: linear-gradient(135deg, #c8962a, #f0d080, #c8962a);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.logo-sub { font-size: 0.78rem; color: var(--text-dim); margin-top: 0.4rem; letter-spacing: 0.05em; margin-bottom: 1rem; }

.install-btn {
  background: rgba(200, 150, 42, 0.15);
  border: 1px solid var(--castillo-primary);
  color: var(--castillo-primary);
  padding: 0.6rem 1.2rem;
  border-radius: 20px;
  font-family: 'Cinzel', serif;
  font-size: 0.8rem;
  font-weight: bold;
  cursor: pointer;
  margin: 0 auto 1.5rem;
  display: none; /* Se activa por JS */
  align-items: center; justify-content: center;
  gap: 8px;
  transition: all 0.3s;
  animation: pulse-gold 2s infinite;
}
@keyframes pulse-gold {
  0% { box-shadow: 0 0 0 0 rgba(200, 150, 42, 0.4); }
  70% { box-shadow: 0 0 0 10px rgba(200, 150, 42, 0); }
  100% { box-shadow: 0 0 0 0 rgba(200, 150, 42, 0); }
}
.install-btn:active { transform: scale(0.95); }

/* World Cards */
.worlds-grid { display: flex; flex-direction: column; gap: 1rem; }

.world-card {
  position: relative; border-radius: 16px; overflow: hidden;
  height: 180px; cursor: pointer;
  border: 1px solid var(--border);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
.world-card:active { transform: scale(0.98); }
.world-card:hover { box-shadow: 0 8px 32px rgba(0,0,0,0.6); transform: translateY(-2px); }

.world-bg {
  position: absolute; inset: 0;
  background-size: cover; background-position: center;
  transition: transform 6s ease;
}
.world-card:hover .world-bg { transform: scale(1.05); }

.castillo-bg {
  background: linear-gradient(135deg, #1a0f05 0%, #3d2010 40%, #0f0803 100%);
  background-size: cover; background-position: center;
}
.cyber-bg {
  background: linear-gradient(135deg, #020d1a 0%, #0a0020 50%, #1a000a 100%);
  background-size: cover; background-position: center;
}
.estancia-bg {
  background: linear-gradient(135deg, #0d0a05 0%, #1a1208 50%, #0a0805 100%);
  background-size: cover; background-position: center;
}
.principito-bg {
  background: linear-gradient(135deg, #0a0a2e 0%, #1a1a4a 50%, #0a0a2e 100%);
  background-size: cover; background-position: center;
}


.world-overlay {
  position: absolute; inset: 0;
  background: linear-gradient(to right, rgba(0,0,0,0.2) 0%, rgba(0,0,0,0.5) 100%);
}

.world-content {
  position: relative; z-index: 1;
  padding: 1.2rem 1.4rem;
  height: 100%; display: flex; flex-direction: column; justify-content: flex-end;
  gap: 0.4rem;
}

.world-badge {
  position: absolute; top: 1rem; left: 1.4rem;
  font-size: 0.6rem; font-weight: 600; letter-spacing: 0.12em;
  padding: 3px 10px; border-radius: 20px;
  background: rgba(200,150,42,0.25); border: 1px solid rgba(200,150,42,0.4);
  color: #c8962a;
}
.cyber-badge { background: rgba(255,59,59,0.2); border-color: rgba(255,59,59,0.4); color: #ff6b6b; }
.terror-badge { background: rgba(150,100,50,0.2); border-color: rgba(150,100,50,0.4); color: #c8a97a; }
.poetry-badge { background: rgba(160,196,255,0.2); border-color: rgba(160,196,255,0.4); color: #a0c4ff; }

.world-emoji { font-size: 1.8rem; }
.world-name {
  font-family: 'Cinzel', serif; font-size: 1.25rem; font-weight: 600;
  color: #fff; line-height: 1.2;
}
.world-desc { font-size: 0.75rem; color: rgba(255,255,255,0.65); line-height: 1.5; }
.world-stats {
  display: flex; gap: 0.8rem; flex-wrap: wrap;
  font-size: 0.65rem; color: rgba(255,255,255,0.45); margin-top: 0.2rem;
}

/* ══════════════════════════════════════
   PANTALLA PREVIEW
   ══════════════════════════════════════ */
#screen-preview { 
  background: #000;
  justify-content: center; align-items: center;
}
.preview-bg {
  position: absolute; inset: 0;
  background-size: cover; background-position: center;
  filter: blur(20px) brightness(0.4);
  transform: scale(1.1);
}
.preview-overlay {
  position: absolute; inset: 0;
  background: radial-gradient(circle at center, transparent, rgba(0,0,0,0.8));
}
.preview-content {
  position: relative; z-index: 10;
  max-width: 400px; width: 90%;
  padding: 3rem 2rem 2rem;
  background: rgba(255,255,255,0.03);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 24px;
  text-align: center;
  animation: fadeInScale 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes fadeInScale {
  from { opacity: 0; transform: scale(0.9) translateY(20px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.btn-close-preview {
  position: absolute; top: 1.2rem; right: 1.2rem;
  background: none; border: none; color: var(--text-dim);
  font-size: 1.2rem; cursor: pointer;
}

.preview-emoji { font-size: 3.5rem; margin-bottom: 1rem; }
.preview-title { font-family: 'Cinzel', serif; font-size: 1.8rem; margin-bottom: 0.5rem; }
.preview-content .world-badge { position: static; display: inline-block; margin-bottom: 1.5rem; }

.preview-info { text-align: left; margin-bottom: 2rem; }
.preview-info h3 { font-size: 0.8rem; color: var(--castillo-primary); letter-spacing: 0.1em; text-transform: uppercase; margin-bottom: 0.6rem; margin-top: 1.2rem; }
.preview-info p { font-size: 0.9rem; color: var(--text); line-height: 1.6; }
.preview-info ul { list-style: none; padding-left: 0.2rem; }
.preview-info li { font-size: 0.85rem; color: var(--text-dim); margin-bottom: 0.4rem; display: flex; gap: 0.5rem; }
.preview-info li::before { content: '✦'; color: var(--castillo-primary); }

.btn-start-game {
  width: 100%; padding: 1rem; border-radius: 12px;
  background: linear-gradient(135deg, #c8962a, #a07020);
  border: none; color: #fff; font-family: 'Cinzel', serif;
  font-size: 1rem; font-weight: 700; letter-spacing: 0.1em;
  cursor: pointer; transition: transform 0.2s;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
.btn-start-game:active { transform: scale(0.96); }

/* ══════════════════════════════════════
   PANTALLA JUEGO
   ══════════════════════════════════════ */
#screen-game { background: #0a0a0f; }

/* Imagen cinematic */
.scene-image {
  position: relative;
  flex: 0 0 250px; /* Altura fija para que no se mueva con el teclado */
  width: 100%;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
}

/* En pantallas muy chicas (celulares en vertical) */
@media (max-height: 600px) {
  .scene-image { flex: 0 0 180px; }
}

.scene-bg {
  position: absolute; inset: 0;
  background-size: cover; background-position: center;
  animation: kenburns 20s ease-in-out infinite alternate;
}
@keyframes kenburns {
  from { transform: scale(1.0) translate(0, 0); }
  to   { transform: scale(1.12) translate(-2%, -1%); }
}

.castillo-scene {
  background: radial-gradient(ellipse at 30% 60%, rgba(200,150,42,0.3) 0%, transparent 60%),
              linear-gradient(160deg, #0f0803 0%, #2d1a08 40%, #1a0f05 100%);
}
.cyber-scene {
  background: radial-gradient(ellipse at 70% 30%, rgba(255,59,59,0.4) 0%, transparent 60%),
              radial-gradient(ellipse at 20% 80%, rgba(0,100,200,0.2) 0%, transparent 50%),
              linear-gradient(160deg, #020810 0%, #001428 60%, #020d1a 100%);
}
.estancia-scene {
  background: radial-gradient(ellipse at 50% 50%, rgba(150,100,50,0.2) 0%, transparent 60%),
              linear-gradient(160deg, #080604 0%, #14100a 50%, #0d0a05 100%);
}
.principito-scene {
  background: radial-gradient(ellipse at 50% 50%, rgba(160,196,255,0.15) 0%, transparent 60%),
              linear-gradient(160deg, #05051a 0%, #0a0a2e 50%, #05051a 100%);
}

/* Partículas de ambiente (CSS puro) */
.scene-bg::before {
  content: '';
  position: absolute; inset: 0;
  background-image:
    radial-gradient(1px 1px at 20% 30%, rgba(255,255,255,0.4) 0%, transparent 100%),
    radial-gradient(1px 1px at 60% 20%, rgba(255,255,255,0.3) 0%, transparent 100%),
    radial-gradient(1px 1px at 80% 60%, rgba(255,255,255,0.2) 0%, transparent 100%),
    radial-gradient(2px 2px at 40% 70%, rgba(255,200,100,0.3) 0%, transparent 100%);
  animation: particles 4s ease-in-out infinite alternate;
}
@keyframes particles {
  from { opacity: 0.5; }
  to   { opacity: 1; }
}

.scene-vignette {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, transparent 30%, rgba(0,0,0,0.7) 100%);
  pointer-events: none;
}
.scene-scanlines {
  position: absolute; inset: 0;
  background: repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0,0,0,0.05) 2px, rgba(0,0,0,0.05) 4px);
  pointer-events: none; opacity: 0.5;
}

/* HUD */
.hud-top {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.8rem 1rem;
  background: linear-gradient(to bottom, rgba(0,0,0,0.8) 0%, transparent 100%);
  z-index: 10;
}
.btn-back {
  background: rgba(0,0,0,0.4); border: 1px solid var(--border);
  color: var(--text-dim); font-size: 0.7rem; padding: 5px 10px;
  border-radius: 8px; cursor: pointer; font-family: 'Inter', sans-serif;
  transition: all 0.2s;
}
.btn-back:hover { color: var(--text); border-color: rgba(255,255,255,0.2); }

.hud-left { display: flex; align-items: center; gap: 0.8rem; }
.audio-controls { display: flex; align-items: center; gap: 0.4rem; }
.volume-slider-wrap {
  width: 0; overflow: hidden;
  transition: width 0.3s ease;
  display: flex; align-items: center;
}
.audio-controls:hover .volume-slider-wrap { width: 60px; margin: 0 5px; }

.voice-gender-wrap {
  width: 0; overflow: hidden;
  transition: width 0.3s ease;
  display: flex; align-items: center;
}
.audio-controls:hover .voice-gender-wrap { width: 95px; margin-left: 5px; }

.voice-gender-wrap select {
  background: rgba(0,0,0,0.6); border: 1px solid var(--border);
  color: #fff; font-size: 0.65rem; border-radius: 6px; padding: 2px 4px;
  outline: none; width: 100%;
}

input[type=range] {
  -webkit-appearance: none; width: 100%; height: 4px;
  background: rgba(255,255,255,0.1); border-radius: 2px; outline: none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 12px; height: 12px;
  background: var(--castillo-primary); border-radius: 50%; cursor: pointer;
}

.btn-icon {
  background: rgba(255,255,255,0.05); border: 1px solid var(--border);
  color: var(--text-dim); width: 32px; height: 32px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all 0.2s; font-size: 0.9rem;
}
.btn-icon:hover { background: rgba(255,255,255,0.1); color: #fff; border-color: rgba(255,255,255,0.2); }
.btn-icon.active { background: rgba(200,150,42,0.2); border-color: rgba(200,150,42,0.4); color: #fff; }

.world-label {
  font-family: 'Cinzel', serif; font-size: 0.75rem;
  letter-spacing: 0.1em; color: rgba(255,255,255,0.7);
}

.hud-hp { text-align: right; }
.hud-hp { font-size: 0.65rem; color: var(--text-dim); display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
#hp-value { color: #fff; font-weight: 600; font-size: 0.8rem; }
.hp-bar-wrap { width: 70px; height: 4px; background: rgba(255,255,255,0.1); border-radius: 2px; overflow: hidden; }
.hp-bar { height: 100%; background: linear-gradient(90deg, #ff4444, #ff8c00, #44ff88); border-radius: 2px; transition: width 0.5s ease; }

/* Inventario */
.inventory-panel {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 0.6rem 1rem 0.8rem;
  background: linear-gradient(to top, rgba(0,0,0,0.85) 0%, transparent 100%);
  z-index: 10;
}
.inv-label { font-size: 0.55rem; letter-spacing: 0.15em; color: var(--text-dim); display: block; margin-bottom: 0.3rem; }
.inventory-list { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.inv-item {
  font-size: 0.65rem; padding: 3px 8px;
  background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.12);
  border-radius: 20px; color: rgba(255,255,255,0.7);
}

/* Typing indicator */
.typing-indicator {
  position: absolute; bottom: 50px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 6px; align-items: center;
  background: rgba(0,0,0,0.6); border-radius: 20px; padding: 8px 14px;
  z-index: 20;
}
.typing-indicator span {
  width: 6px; height: 6px; border-radius: 50%; background: #c8962a;
  animation: bounce 1.2s ease infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30%            { transform: translateY(-6px); opacity: 1; }
}
.hidden { display: none !important; }

/* Panel narrativo */
.game-panel {
  flex: 1; display: flex; flex-direction: column;
  background: #0d0d12; overflow: hidden;
  border-top: 1px solid var(--border);
}

.narrative-area {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  scrollbar-width: thin;
  scrollbar-color: var(--castillo-primary) transparent;
  min-height: 0; /* Crucial para flexbox en móviles */
}
.narrative-area::-webkit-scrollbar { width: 3px; }
.narrative-area::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

/* Mensajes */
.msg-narrator, .msg-player, .msg-system {
  animation: fadeInUp 0.35s ease;
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-narrator .bubble {
  background: rgba(255,255,255,0.04); border: 1px solid var(--border);
  border-radius: 4px 14px 14px 14px;
  padding: 0.75rem 1rem;
  font-size: 0.85rem; line-height: 1.7; color: var(--text);
  font-style: italic;
}
.msg-narrator .sender {
  font-size: 0.6rem; letter-spacing: 0.12em; color: var(--text-dim);
  margin-bottom: 0.3rem; font-style: normal;
}
.msg-player { text-align: right; }
.msg-player .bubble {
  display: inline-block;
  background: rgba(200,150,42,0.15); border: 1px solid rgba(200,150,42,0.25);
  border-radius: 14px 4px 14px 14px;
  padding: 0.6rem 0.9rem;
  font-size: 0.82rem; line-height: 1.5; color: rgba(255,255,255,0.9);
}
.msg-system { text-align: center; }
.msg-system .bubble {
  display: inline-block;
  font-size: 0.65rem; color: var(--text-dim);
  letter-spacing: 0.05em; padding: 0.3rem 0;
}

/* Input */
.input-area {
  display: flex; align-items: flex-end; gap: 0.5rem;
  padding: 0.75rem 1rem 0.5rem;
  border-top: 1px solid var(--border);
}
.player-input {
  flex: 1; background: rgba(255,255,255,0.05); border: 1px solid var(--border);
  border-radius: 12px; padding: 0.6rem 0.9rem;
  color: var(--text); font-family: 'Inter', sans-serif; font-size: 0.85rem;
  resize: none; outline: none; line-height: 1.5; max-height: 100px;
  transition: border-color 0.2s;
}
.player-input:focus { border-color: rgba(200,150,42,0.4); }
.player-input::placeholder { color: var(--text-dim); }

.mic-btn {
  width: 40px; height: 40px; border-radius: 10px; flex-shrink: 0;
  background: rgba(255,255,255,0.05); border: 1px solid var(--border);
  color: var(--text-dim); font-size: 1.1rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.mic-btn.recording {
  background: rgba(255, 0, 0, 0.2);
  border-color: #ff4444;
  color: #ff4444;
  animation: pulse-mic 1.5s infinite;
}
@keyframes pulse-mic {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 68, 68, 0.4); }
  70% { transform: scale(1.1); box-shadow: 0 0 0 10px rgba(255, 68, 68, 0); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 68, 68, 0); }
}

.send-btn {
  width: 40px; height: 40px; border-radius: 10px; flex-shrink: 0;
  background: linear-gradient(135deg, #c8962a, #a07020);
  border: none; color: #fff; font-size: 1rem; cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
  display: flex; align-items: center; justify-content: center;
}
.send-btn:active { transform: scale(0.92); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.input-hint {
  font-size: 0.6rem; color: var(--text-dim);
  text-align: center; padding: 0.2rem 1rem 0.6rem;
}

/* Game Over */
.game-over {
  position: absolute; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.92);
  display: flex; align-items: center; justify-content: center;
  animation: fadeInUp 0.4s ease;
}
.game-over-content { text-align: center; padding: 2rem; }
.game-over-icon { font-size: 3rem; margin-bottom: 1rem; }
.game-over-content h2 {
  font-family: 'Cinzel', serif; font-size: 1.5rem; margin-bottom: 0.7rem;
  color: #fff;
}
.game-over-content p { color: var(--text-dim); font-size: 0.85rem; line-height: 1.6; margin-bottom: 1.5rem; }
.btn-restart, .btn-back-menu {
  display: block; width: 100%; padding: 0.8rem;
  border-radius: 10px; border: none; cursor: pointer;
  font-family: 'Inter', sans-serif; font-size: 0.9rem; font-weight: 500;
  margin-bottom: 0.7rem; transition: opacity 0.2s;
}
.btn-restart { background: linear-gradient(135deg, #c8962a, #a07020); color: #fff; }
.btn-back-menu { background: rgba(255,255,255,0.07); border: 1px solid var(--border); color: var(--text); }
.btn-restart:hover, .btn-back-menu:hover { opacity: 0.85; }

/* Preview Buttons & Memory System */
.preview-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  width: 100%;
  margin-top: 1rem;
}

.btn-start-game {
  width: 100%;
  padding: 1.1rem;
  border-radius: 12px;
  font-family: 'Cinzel', serif;
  font-weight: bold;
  font-size: 1rem;
  cursor: pointer;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.07);
  color: #fff;
  transition: all 0.2s;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.btn-continue {
  background: linear-gradient(135deg, #c8962a 0%, #a07820 100%) !important;
  border-color: #ffd700 !important;
  color: #0f0f15 !important;
  box-shadow: 0 4px 15px rgba(200, 150, 42, 0.3);
}

.btn-start-game:active { transform: scale(0.98); }
.btn-continue:hover { box-shadow: 0 6px 20px rgba(200, 150, 42, 0.5); }
