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

html, body {
  height: 100%; overflow: hidden;
  background: #0f0b08; color: #e8dcc8;
  font-family: 'Georgia', serif;
  user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none; overscroll-behavior: none;
}

canvas { display: block; position: absolute; top: 0; left: 0; touch-action: none; }

.fa-solid, .fa-regular, .fa-brands { font-size: 0.95em; line-height: 1; }
.hud-btn i { pointer-events: none; }
.tbtn i { pointer-events: none; font-size: 22px; }
#tSalto i { font-size: 28px; }
#inicio .controles i { color: #d4a857; margin: 0 4px; }
#rotar .icono i { font-size: 48px; color: #d4a857; }
#ficha .acciones button i { margin-right: 4px; }
#btnAcunar i { margin-right: 4px; }
#espectador .saltar i { margin-right: 4px; }
#hud i { color: #8a7a60; margin-right: 4px; }

/* ============================================================
   HUD IZQUIERDO
   ============================================================ */
#hud {
  position: absolute; top: 16px; left: 16px;
  font-size: 12px; color: #b8a888;
  line-height: 1.9; letter-spacing: 1px;
  pointer-events: none; z-index: 10;
  text-shadow: 0 2px 8px rgba(0,0,0,0.9);
}
#hud span { color: #d4a857; font-weight: bold; }

/* ============================================================
   HUD DERECHO + BOTONES (agrupados para no solaparse)
   ============================================================ */
#hud-der-wrap {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  z-index: 30;
}

#hud-botones {
  display: flex;
  gap: 8px;
}

#hud-der {
  position: static;
  text-align: right;
  font-size: 11px;
  color: #8a7a60;
  line-height: 1.9;
  letter-spacing: 1px;
  pointer-events: none;
  text-shadow: 0 2px 8px rgba(0,0,0,0.9);
  padding-right: 0;
}
#hud-der span { color: #d4a857; }

.hud-btn {
  width: 40px; height: 40px;
  border-radius: 6px;
  background: rgba(42, 32, 24, 0.75);
  border: 1px solid #5a4a35;
  color: #d4a857; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  padding: 0; letter-spacing: 0;
  touch-action: manipulation;
  transition: background 0.15s, transform 0.1s;
}
.hud-btn:hover { background: rgba(212, 168, 87, 0.25); }
.hud-btn:active { transform: scale(0.92); }

/* ============================================================
   PANTALLA DE INICIO
   ============================================================ */
#inicio {
  position: absolute; inset: 0;
  background:
    linear-gradient(rgba(10, 7, 5, 0.72), rgba(10, 7, 5, 0.90)),
    url('fondointro.jpeg') center center / cover no-repeat,
    #0a0705;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 100; text-align: center;
  padding: 40px 20px; transition: opacity 0.5s;
  overflow-y: auto;
}
#inicio.hidden { opacity: 0; pointer-events: none; }
#inicio h1 {
  font-size: clamp(28px, 7vw, 42px);
  letter-spacing: clamp(8px, 3vw, 16px);
  color: #d4a857; margin-bottom: 8px; font-weight: normal;
}
#inicio .sub {
  font-size: clamp(10px, 2.5vw, 13px);
  color: #8a7a60; letter-spacing: 3px; margin-bottom: 32px;
}
#inicio .lema {
  font-size: clamp(13px, 3.2vw, 15px);
  color: #b8a888; font-style: italic;
  max-width: 520px; line-height: 1.8; margin-bottom: 28px;
}
#inicio .controles {
  font-size: clamp(11px, 2.8vw, 12px);
  color: #8a7a60; line-height: 2.2;
  margin-bottom: 24px; letter-spacing: 1px;
}
#inicio .mejor {
  font-size: 11px; color: #d4a857;
  letter-spacing: 3px; margin-bottom: 20px;
  min-height: 14px;
}
#inicio .mejor .etq { color: #8a7a60; }

button {
  padding: 14px 36px;
  background: #d4a857; color: #1a1410;
  border: none; font-family: inherit;
  font-size: 13px; font-weight: bold;
  letter-spacing: 4px; cursor: pointer;
  border-radius: 3px; transition: all 0.2s;
  touch-action: manipulation;
}
button:hover { background: #e8c070; transform: translateY(-1px); }

/* ============================================================
   PAUSA
   ============================================================ */
#pausa {
  position: absolute; inset: 0;
  background:
    linear-gradient(rgba(10, 7, 5, 0.82), rgba(10, 7, 5, 0.94)),
    url('fondointro.jpeg') center center / cover no-repeat,
    #0a0705;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 150; text-align: center;
  padding: 40px 20px; opacity: 0;
  pointer-events: none; transition: opacity 0.25s;
}
#pausa.visible { opacity: 1; pointer-events: auto; }
#pausa h2 {
  font-size: clamp(18px, 5vw, 26px);
  letter-spacing: clamp(6px, 2.5vw, 12px);
  color: #d4a857; margin-bottom: 24px; font-weight: normal;
}
#pausa .stats {
  font-size: 12px; color: #b8a888;
  line-height: 2; letter-spacing: 1px;
  margin-bottom: 32px; font-family: monospace;
}
#pausa .stats span { color: #d4a857; }
#pausa .stats i { color: #8a7a60; margin-right: 6px; }
#pausa .botones {
  display: flex; gap: 12px;
  flex-wrap: wrap; justify-content: center;
}
#pausa .botones .secondary {
  background: transparent;
  border: 1px solid #5a4a35;
  color: #b8a888;
  padding: 14px 26px; font-size: 12px;
}

/* ============================================================
   ROTAR DISPOSITIVO
   ============================================================ */
#rotar {
  position: absolute; inset: 0;
  background: rgba(10, 7, 5, 0.98);
  display: none; align-items: center;
  justify-content: center; flex-direction: column;
  z-index: 300; text-align: center; padding: 40px;
}
#rotar.visible { display: flex; }
#rotar .icono {
  margin-bottom: 20px;
  animation: rotar 2s ease-in-out infinite;
}
@keyframes rotar {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(90deg); }
}
#rotar p {
  color: #d4a857; letter-spacing: 4px;
  font-size: 13px; line-height: 1.8;
}
#rotar .sub {
  color: #8a7a60; font-size: 11px;
  letter-spacing: 2px; margin-top: 12px;
  font-style: italic;
}

/* ============================================================
   ESPECTADOR
   ============================================================ */
#espectador {
  position: absolute; inset: 0;
  background: rgba(5, 3, 2, 0.5);
  z-index: 120; opacity: 0;
  pointer-events: none; transition: opacity 0.6s;
  display: flex; align-items: flex-end;
  justify-content: center;
  padding-bottom: 60px;
}
#espectador.visible { opacity: 1; pointer-events: auto; }
#espectador .texto {
  font-size: 11px; letter-spacing: 6px;
  color: #d4a857; text-align: center;
  text-shadow: 0 2px 12px rgba(0,0,0,1);
}
#espectador .texto .sub {
  font-size: 10px; color: #8a7a60;
  letter-spacing: 3px; margin-top: 8px;
  font-style: italic;
}
#espectador .saltar {
  position: absolute; bottom: 20px; right: 20px;
  font-size: 10px; color: #5a4a35;
  letter-spacing: 2px;
}

/* ============================================================
   TALLER
   ============================================================ */
#taller {
  position: absolute; inset: 0;
  background: rgba(5, 3, 2, 0.96);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 180; opacity: 0;
  pointer-events: none; transition: opacity 0.5s;
  gap: 18px;
}
#taller.visible { opacity: 1; pointer-events: auto; }
#taller .tallerTitulo {
  font-size: clamp(14px, 4vw, 20px);
  letter-spacing: clamp(5px, 2vw, 10px);
  color: #d4a857;
}
#taller .tallerFrase {
  font-size: clamp(11px, 2.8vw, 13px);
  font-style: italic;
  color: #b8a888;
  letter-spacing: 2px;
  min-height: 18px;
  text-align: center;
  padding: 0 20px;
}
#tallerCanvas {
  display: block;
  width: min(600px, 90vw);
  height: auto;
  border: 1px solid rgba(212,168,87,0.4);
  border-radius: 4px;
  background: #0a0705;
}
#taller .tallerSaltar {
  font-size: 10px;
  letter-spacing: 3px;
  color: #5a4a35;
  margin-top: 8px;
}
#taller .tallerSaltar i { margin-left: 4px; color: #8a7a60; }

/* ============================================================
   FICHA (CONTRATO)
   ============================================================ */
#ficha {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(0.92);
  width: min(1200px, 96vw);
  max-height: 94vh; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background:
    linear-gradient(rgba(15, 11, 8, 0.94), rgba(15, 11, 8, 0.985)),
    url('fondointro.jpeg') center center / cover no-repeat,
    rgba(15, 11, 8, 0.98);
  border: 1px solid #d4a857;
  border-radius: 6px;
  padding: clamp(16px, 3vw, 28px);
  z-index: 200; opacity: 0;
  pointer-events: none; transition: all 0.4s;
}
#ficha.visible {
  opacity: 1; pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
}
#ficha h2 {
  font-size: clamp(13px, 3.5vw, 16px);
  letter-spacing: clamp(3px, 1.5vw, 6px);
  color: #d4a857; margin-bottom: 6px;
  font-weight: normal; text-align: center;
}
#ficha .subt {
  font-size: 10px; color: #8a7a60;
  letter-spacing: 2px; text-align: center;
  margin-bottom: 16px; font-style: italic;
}

/* Layout de la ficha: dos columnas, ambas al mismo alto */
#fichaLayout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: stretch;
  min-height: 0;
}

/* ============================================================
   COLUMNA IZQUIERDA: OBRA (preview + panel unificados)
   ============================================================ */
#previewCol {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#obraWrap {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  border: 1px solid #2a2018;
  border-radius: 4px;
  background: rgba(20, 15, 10, 0.5);
  overflow: hidden;
}

#obraHeader {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 14px;
  border-bottom: 1px solid #2a2018;
  background: rgba(15, 11, 8, 0.6);
}
#obraHeader .etq {
  font-size: 10px;
  letter-spacing: 3px;
  color: #d4a857;
}
#obraHeader .subEtq {
  font-size: 9px;
  letter-spacing: 2px;
  color: #5a4a35;
  font-family: monospace;
}

/* Preview: cuadrada, con límites para que no crezca demasiado */
#previewWrap {
  aspect-ratio: 1 / 1;
  width: 100%;
  max-width: min(100%, 420px);
  max-height: 420px;
  margin: 0 auto;
  background: #0a0705;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid #2a2018;
}
#previewWrap svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Panel de estilo: crece con el contenido y hace scroll si hace falta */
#panelEstilo {
  flex: 1;
  min-height: 0;
  padding: 12px 14px;
  overflow-y: auto;
  background: transparent;
  border: none;
}
#panelEstilo::-webkit-scrollbar { width: 4px; }
#panelEstilo::-webkit-scrollbar-track { background: #1a1410; }
#panelEstilo::-webkit-scrollbar-thumb { background: #5a4a35; }

.panelEstiloHeader {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
  gap: 6px;
}
.panelEstiloHeader .etq {
  font-size: 10px;
  letter-spacing: 3px;
  color: #8a7a60;
}
.panelEstiloHeader .miniAcciones {
  display: flex;
  gap: 4px;
}
.miniBtn {
  background: transparent;
  border: 1px solid #3a2f22;
  color: #8a7a60;
  font-family: monospace;
  font-size: 9px;
  letter-spacing: 1px;
  padding: 4px 9px;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.15s;
  text-transform: uppercase;
}
.miniBtn:hover {
  border-color: #d4a857; color: #d4a857;
}
.miniBtn i { font-size: 11px; }

.panelSubseccion {
  margin-bottom: 10px;
}
.panelSubseccion:last-child {
  margin-bottom: 0;
}
.panelSubseccion .subEtq {
  display: block;
  font-size: 9px;
  letter-spacing: 2px;
  color: #5a4a35;
  margin-bottom: 6px;
  font-family: monospace;
}

.filtrosEstilo {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.filtroMini {
  background: transparent;
  border: 1px solid #2a2018;
  color: #5a4a35;
  font-family: monospace;
  font-size: 9px;
  letter-spacing: 1px;
  padding: 3px 7px;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.15s;
}
.filtroMini:hover { border-color: #5a4a35; color: #b8a888; }
.filtroMini.activo {
  border-color: #d4a857; color: #d4a857;
  background: rgba(212, 168, 87, 0.1);
}

.chipsEstilo {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}
.chipEstilo {
  background: transparent;
  border: 1px solid #3a2f22;
  color: #8a7a60;
  font-family: monospace;
  font-size: 9px;
  letter-spacing: 1px;
  padding: 4px 7px;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
  position: relative;
}
.chipEstilo:hover {
  border-color: #5a4a35;
  color: #b8a888;
}
.chipEstilo.activo {
  border-color: #d4a857;
  color: #d4a857;
  background: rgba(212, 168, 87, 0.1);
}
.chipEstilo .orden {
  display: inline-block;
  background: #d4a857;
  color: #1a1410;
  font-weight: bold;
  font-size: 8px;
  width: 12px; height: 12px;
  line-height: 12px;
  text-align: center;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}
.chipEstilo .cat {
  display: block;
  font-size: 7px;
  color: #5a4a35;
  letter-spacing: 1px;
  margin-top: 1px;
}
.chipEstilo.activo .cat { color: #8a6a40; }

.chipDescripcion {
  margin-top: 8px;
  padding: 8px 10px;
  border-left: 2px solid #d4a857;
  background: rgba(212,168,87,0.06);
  font-family: monospace;
  font-size: 10px;
  line-height: 1.5;
  color: #b8a888;
  letter-spacing: 1px;
  min-height: 20px;
}
.chipDescripcion strong { color: #d4a857; }

/* ============================================================
   COLUMNA DERECHA: DATOS
   ============================================================ */
#datosCol {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}
#ficha .seccion {
  font-size: 10px; letter-spacing: 3px;
  color: #8a7a60; margin-top: 6px;
  margin-bottom: 6px;
  border-bottom: 1px solid #2a2018;
  padding-bottom: 4px;
}
#ficha .seccion:first-child { margin-top: 0; }
#ficha table { width: 100%; font-size: 11px; border-collapse: collapse; }
#ficha td {
  padding: 4px 0; color: #b8a888;
  letter-spacing: 1px;
  border-bottom: 1px solid #1a1410;
}
#ficha td:first-child { color: #8a7a60; width: 55%; }
#ficha td:last-child {
  color: #d4a857; text-align: right;
  font-family: monospace;
}
#ficha .rareza {
  text-align: center;
  font-size: clamp(14px, 4vw, 18px);
  letter-spacing: clamp(4px, 2vw, 8px);
  margin: 12px 0 8px 0; color: #d4a857;
}

#ficha .acciones {
  display: flex; gap: 6px;
  margin-top: 12px; flex-wrap: wrap;
}
#ficha .acciones button {
  flex: 1; padding: 10px 6px;
  font-size: 10px; letter-spacing: 1.5px;
  min-width: 90px;
}
#ficha .acciones .secondary {
  background: transparent;
  border: 1px solid #5a4a35;
  color: #b8a888;
}
#ficha .acciones .secondary:hover {
  border-color: #d4a857; color: #d4a857;
  background: transparent;
}
#ficha .acciones .compartir {
  background: transparent;
  border: 1px solid #d4a857;
  color: #d4a857;
}
#ficha .acciones .compartir:hover {
  background: rgba(212, 168, 87, 0.15);
}
#ficha::-webkit-scrollbar { width: 4px; }
#ficha::-webkit-scrollbar-track { background: #1a1410; }
#ficha::-webkit-scrollbar-thumb { background: #5a4a35; }

/* ============================================================
   RESPONSIVE
   ============================================================
   El juego bloquea el vertical (pantalla #rotar), así que la ficha
   solo se ve en horizontal. Eso significa que NO podemos usar
   breakpoints por ancho (en móvil horizontal el ancho es grande),
   sino por ALTO disponible.
   
   - max-height: 800px → móvil horizontal, tablet, ventana pequeña
   - max-width: 700px  → móvil vertical (por si acaso, aunque el
                          juego lo bloquee)
   ============================================================ */

/* Móvil en vertical: una sola columna (por si acaso) */
@media (max-width: 700px) {
  #fichaLayout {
    grid-template-columns: 1fr;
  }
}

/* Ficha con poco alto: móvil horizontal, tablet, ventana pequeña.
   La preview se hace sticky y más pequeña para que quepa junto al
   panel de personalización sin desplazarse fuera de la vista. */
@media (max-height: 800px) {
  #previewCol {
    flex: none;
  }

  /* Obligatorio para que funcione position: sticky en #previewWrap */
  #obraWrap {
    flex: none;
    overflow: visible;
  }

  /* Ocultamos el header en pantallas bajas para ganar espacio vertical */
  #obraHeader {
    display: none;
  }

  /* Preview sticky estilo YouTube: se queda pegada arriba mientras
     scrolleas por el panel de estilos */
  #previewWrap {
    position: sticky;
    top: 0;
    z-index: 5;
    max-width: min(100%, 260px);
    max-height: 38vh;
    aspect-ratio: 1 / 1;
    width: auto;
    margin: 0 auto;
    background: #0a0705;
    border-bottom: 1px solid #2a2018;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.7);
  }

  /* El panel de estilos ya no scrollea internamente: scrollea la ficha entera */
  #panelEstilo {
    overflow: visible;
    max-height: none;
  }
}

/* Móvil horizontal muy pequeño (ej: 667x375): apretamos un poco más */
@media (max-height: 500px) {
  #previewWrap {
    max-width: min(100%, 200px);
    max-height: 42vh;
  }
  #ficha {
    padding: 12px 16px;
  }
  #ficha h2 {
    margin-bottom: 4px;
  }
  #ficha .subt {
    margin-bottom: 10px;
  }
}

/* ============================================================
   MENSAJES
   ============================================================ */
#msg {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(16px, 4.5vw, 22px);
  letter-spacing: clamp(3px, 1.5vw, 6px);
  color: #d4a857; text-align: center;
  pointer-events: none; z-index: 50;
  opacity: 0; transition: opacity 0.4s;
  text-shadow: 0 4px 20px rgba(0,0,0,0.9);
  padding: 0 20px;
  max-width: 90vw;
}
#msg.visible { opacity: 1; }
#msg .small {
  font-size: 12px; letter-spacing: 2px;
  color: #8a7a60; margin-top: 10px;
  font-style: italic;
}

/* ============================================================
   CONTROLES TÁCTILES
   ============================================================ */
#tactil {
  position: absolute; inset: 0;
  pointer-events: none; z-index: 40;
  display: none;
}
#tactil.activo { display: block; }
.tbtn {
  position: absolute;
  bottom: max(24px, env(safe-area-inset-bottom));
  width: 76px; height: 76px;
  border-radius: 50%;
  background: rgba(42, 32, 24, 0.65);
  border: 2px solid #5a4a35;
  color: #d4a857;
  font-size: 24px; font-weight: bold;
  display: flex; align-items: center; justify-content: center;
  pointer-events: auto; touch-action: none;
  -webkit-user-select: none; user-select: none;
  transition: background 0.1s, transform 0.1s;
  padding: 0; letter-spacing: 0;
}
.tbtn.pulsado {
  background: rgba(212, 168, 87, 0.35);
  transform: scale(0.94);
}
#tIzq { left: max(20px, env(safe-area-inset-left)); }
#tDer { left: calc(max(20px, env(safe-area-inset-left)) + 92px); }
#tSalto {
  right: max(20px, env(safe-area-inset-right));
  width: 96px; height: 96px;
  border-width: 3px;
}
@media (max-height: 500px) {
  .tbtn { width: 62px; height: 62px; }
  .tbtn i { font-size: 18px; }
  #tSalto i { font-size: 22px; }
  #tDer { left: calc(max(16px, env(safe-area-inset-left)) + 74px); }
  #tIzq { left: max(16px, env(safe-area-inset-left)); }
  #tSalto { width: 78px; height: 78px; }
}

/* ============================================================
   FPS Y DEBUG
   ============================================================ */
#fps {
  position: absolute; bottom: 8px; left: 8px;
  font-family: monospace; font-size: 10px;
  color: #5a4a35; z-index: 20;
  pointer-events: none; display: none;
}
#fps.visible { display: block; }

#debug {
  position: absolute; bottom: 0; right: 0;
  max-width: 45vw; max-height: 30vh; overflow: auto;
  background: rgba(0,0,0,0.85);
  color: #8a7a60; font-family: monospace;
  font-size: 10px; padding: 6px 8px;
  z-index: 999; white-space: pre-wrap;
  display: none; line-height: 1.4;
  pointer-events: none;
}
#debug.visible { display: block; }
