/* Copa de las Casas — estilos. Fuente de diseño: DESIGN.md */

/* ------------------------------------------------------------ Fuentes (§3) */
@font-face { font-family: "Cinzel"; font-weight: 600; font-style: normal; font-display: swap;
  src: url("../fonts/v1/cinzel-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Cinzel"; font-weight: 700; font-style: normal; font-display: swap;
  src: url("../fonts/v1/cinzel-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "Cinzel Decorative"; font-weight: 700; font-style: normal; font-display: swap;
  src: url("../fonts/v1/cinzel-decorative-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "EB Garamond"; font-weight: 400; font-style: normal; font-display: swap;
  src: url("../fonts/v1/eb-garamond-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "EB Garamond"; font-weight: 500; font-style: normal; font-display: swap;
  src: url("../fonts/v1/eb-garamond-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "EB Garamond"; font-weight: 400; font-style: italic; font-display: swap;
  src: url("../fonts/v1/eb-garamond-latin-400-italic.woff2") format("woff2"); }

/* ------------------------------------------------------------ Tokens (§2.4) */
:root {
  --bg: #100E12; --surface: #1C1820; --surface-2: #26212B; --border: #3A3340;
  --text: #EDE4D0; --text-muted: #A89F8E; --arcane: #A58BEA;
  --gain: #5FC98A; --loss: #EF6F6C; --error: #EF6F6C;

  --piassentini-fill: #F4F1EA; --piassentini-ink: #F4F1EA;
  --piassentini-trim: #7A2232; --piassentini-on-fill: #7A2232;
  --curima-fill: #E3AE3B; --curima-ink: #E3AE3B;
  --curima-trim: #7A4A1E; --curima-on-fill: #2A1B08;
  --angelico-fill: #1B2F5E; --angelico-ink: #86A8E8;
  --angelico-trim: #A9B1BA; --angelico-on-fill: #EDE4D0;

  /* Por defecto; cada tarjeta los sobreescribe con los colores de copa.json */
  --casa-fill: var(--surface-2); --casa-ink: var(--text); --casa-trim: var(--border); --casa-on-fill: var(--text);

  --f-titulo: "Cinzel Decorative", "Cinzel", Georgia, serif;
  --f-cinzel: "Cinzel", Georgia, serif;
  --f-texto: "EB Garamond", Georgia, serif;

  --e-1: 4px; --e-2: 8px; --e-3: 12px; --e-4: 16px; --e-5: 24px; --e-6: 32px; --e-7: 48px;
  --radio: 12px;
  --sombra: 0 4px 16px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

/* ------------------------------------------------------------ Base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  background-image: radial-gradient(ellipse 120% 60% at 50% 0%, #1d1822 0%, var(--bg) 70%);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--f-texto);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}
img { display: block; max-width: 100%; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
p { margin: 0; }
ol { margin: 0; padding: 0; list-style: none; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.sr-solo {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

:focus-visible { outline: 2px solid var(--arcane); outline-offset: 2px; border-radius: 4px; }

.saltar {
  position: absolute; left: var(--e-4); top: -100px; z-index: 10;
  background: var(--surface); color: var(--arcane); padding: var(--e-2) var(--e-4); border-radius: var(--radio);
}
.saltar:focus { top: var(--e-4); }

/* ------------------------------------------------------------ Layout (§5) */
.encabezado, .contenido, .pie {
  width: 100%;
  max-width: 1100px;
  margin-inline: auto;
  padding-inline: var(--e-4);
}
.encabezado { padding-top: var(--e-6); padding-bottom: var(--e-4); text-align: center; }
.encabezado__antetitulo {
  font-family: var(--f-cinzel); font-weight: 600; font-size: 12px;
  letter-spacing: 0.25em; text-transform: uppercase; color: var(--text-muted);
}
.titulo {
  font-family: var(--f-titulo); font-weight: 700; font-size: 28px;
  letter-spacing: 0.02em; margin-block: var(--e-2);
  text-shadow: 0 0 24px rgba(165, 139, 234, 0.25);
}
.encabezado__actualizado { color: var(--text-muted); font-size: 15px; }

.contenido { display: flex; flex-direction: column; gap: var(--e-5); padding-bottom: var(--e-7); }
.tablero { display: grid; gap: var(--e-6); }

.seccion__titulo {
  font-family: var(--f-cinzel); font-weight: 700; font-size: 20px; letter-spacing: 0.04em;
  margin-bottom: var(--e-4);
}

.pie {
  padding-block: var(--e-6) var(--e-7);
  color: var(--text-muted); font-size: 14px; text-align: center; font-style: italic;
  border-top: 1px solid var(--border);
}

/* ------------------------------------------------------------ Escena (§6.2, §8) */
.escena {
  position: relative;
  height: min(55vh, 480px);
  min-height: 260px;
  border-radius: var(--radio);
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 30%, #1f1a25 0%, var(--bg) 75%);
  border: 1px solid var(--border);
}
.escena__canvas {
  display: block; width: 100%; height: 100%;
  touch-action: pan-y;            /* vertical = scroll de la página (R4) */
  cursor: grab;
}
.escena__canvas:active { cursor: grabbing; }
.escena__pista {
  position: absolute; left: 50%; bottom: var(--e-3); transform: translateX(-50%);
  font-size: 13px; color: var(--text-muted); background: rgba(16, 14, 18, 0.7);
  padding: 2px var(--e-3); border-radius: 999px; pointer-events: none;
  transition: opacity 0.6s ease;
}
.escena__pista--oculta { opacity: 0; }

/* Fallback plano: escudos + barras */
.fallback {
  height: 100%; display: flex; flex-direction: column; justify-content: center;
  gap: var(--e-4); padding: var(--e-5) var(--e-4);
}
.fallback__fila { display: grid; grid-template-columns: 48px 1fr; gap: var(--e-3); align-items: center; }
.fallback__escudo { width: 48px; height: 48px; }
.fallback__info { display: flex; flex-direction: column; gap: var(--e-1); min-width: 0; }
.fallback__texto {
  display: flex; justify-content: space-between; gap: var(--e-2);
  font-family: var(--f-cinzel); font-weight: 600; font-size: 15px;
}
.fallback__nombre { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fallback__total { font-variant-numeric: tabular-nums; color: var(--casa-ink); }
.fallback__barra {
  height: 12px; border-radius: 999px; background: var(--surface-2);
  border: 1px solid var(--casa-ink); overflow: hidden;
}
.fallback__relleno {
  height: 100%; background: var(--casa-fill); border-radius: 999px;
  transition: width 1.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* ------------------------------------------------------------ Estados (§4.6) */
.estado:empty { display: none; }
.estado {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radio);
  padding: var(--e-5) var(--e-4); text-align: center; font-size: 18px;
}
.estado--vacio { border-color: var(--arcane); font-family: var(--f-cinzel); font-weight: 600; }
.estado--error { border-color: var(--error); color: var(--text); }
.estado--error strong { color: var(--error); display: block; font-family: var(--f-cinzel); margin-bottom: var(--e-1); }
.estado__siluetas { display: flex; justify-content: center; gap: var(--e-4); margin-bottom: var(--e-3); }
.estado__silueta {
  width: 36px; height: 42px; background: var(--surface-2);
  clip-path: polygon(0 0, 100% 0, 100% 55%, 50% 100%, 0 55%);
  animation: pulso 1.6s ease-in-out infinite;
}
.estado__silueta:nth-child(2) { animation-delay: 0.2s; }
.estado__silueta:nth-child(3) { animation-delay: 0.4s; }
@keyframes pulso { 50% { background: #3a3340; } }

/* ------------------------------------------------------------ Tarjeta de casa (§4.2) */
.ranking__lista { display: flex; flex-direction: column; gap: var(--e-4); }
.casa {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 6px solid var(--casa-ink);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  padding: var(--e-4);
  scroll-margin-top: var(--e-4);
}
.casa--angelico { border-color: color-mix(in srgb, var(--casa-ink) 45%, var(--border)); border-left-color: var(--casa-ink); }
.casa.es-lider {
  border: 2px solid var(--casa-ink);
  border-left-width: 6px;
  box-shadow: var(--sombra), 0 0 24px color-mix(in srgb, var(--casa-ink) 35%, transparent);
}
.casa__cabecera {
  display: grid;
  grid-template-columns: auto 56px minmax(0, 1fr) auto;
  gap: var(--e-3);
  align-items: center;
}
.casa__posicion {
  font-family: var(--f-cinzel); font-weight: 700; font-size: 18px; color: var(--text-muted);
  min-width: 2ch; text-align: center;
}
.es-lider .casa__posicion { color: var(--casa-ink); }
.casa__escudo { width: 56px; height: 56px; filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.5)); }
.casa__nombres { min-width: 0; }
.casa__nombre {
  font-family: var(--f-cinzel); font-weight: 700; font-size: 20px; letter-spacing: 0.04em;
  color: var(--casa-ink);
  overflow-wrap: anywhere;
}
.casa__lema { font-style: italic; font-size: 15px; color: var(--text-muted); }
@media (max-width: 399px) {
  .casa { padding: var(--e-3); }
  .casa__cabecera { gap: var(--e-2); }
  .casa__nombre { font-size: 17px; letter-spacing: 0.02em; }
}
@media (max-width: 599px) {
  .escena { height: clamp(260px, 95vw, 480px); }
}
.casa__total { text-align: right; }
.casa__puntos {
  display: block; font-family: var(--f-cinzel); font-weight: 700; font-size: 36px; line-height: 1;
  font-variant-numeric: tabular-nums; color: var(--text);
}
.casa__unidad { font-size: 13px; color: var(--text-muted); }
.casa__insignia {
  display: inline-block; margin-top: var(--e-3);
  font-family: var(--f-cinzel); font-weight: 700; font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--casa-on-fill); background: var(--casa-fill);
  border: 1px solid var(--casa-trim); border-radius: 999px; padding: 2px var(--e-3);
}

/* ------------------------------------------------------------ Jugadores (§4.3) */
.casa__integrantes { margin-top: var(--e-3); border-top: 1px solid var(--border); }
.casa__integrantes > summary {
  min-height: 44px; display: flex; align-items: center; gap: var(--e-2);
  cursor: pointer; list-style: none; color: var(--text-muted);
  font-family: var(--f-cinzel); font-weight: 600; font-size: 14px; letter-spacing: 0.06em;
}
.casa__integrantes > summary::-webkit-details-marker { display: none; }
.casa__integrantes > summary::before {
  content: "▸"; color: var(--casa-ink); transition: transform 0.2s ease; display: inline-block;
}
.casa__integrantes[open] > summary::before { transform: rotate(90deg); }
.jugadores { counter-reset: jugador; }
.jugador {
  display: flex; justify-content: space-between; align-items: center; gap: var(--e-3);
  min-height: 44px; border-top: 1px solid var(--border); padding-inline: var(--e-1);
}
.jugador__nombre { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 17px; }
.jugador__puntos {
  font-family: var(--f-cinzel); font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums;
}
.jugador__puntos.negativo { color: var(--loss); }
.casa__sin-integrantes { color: var(--text-muted); font-style: italic; padding-block: var(--e-2); }

/* ------------------------------------------------------------ Historial (§4.4) */
.historial__lista { display: flex; flex-direction: column; }
.evento {
  display: grid;
  grid-template-columns: 3.4em 24px minmax(0, 1fr) auto;
  gap: var(--e-3); align-items: center;
  min-height: 48px; padding-block: var(--e-2);
  border-top: 1px solid var(--border);
}
.evento:last-child { border-bottom: 1px solid var(--border); }
.evento__fecha { color: var(--text-muted); font-size: 14px; white-space: nowrap; }
.evento__escudo { width: 20px; height: 20px; display: none; }
.evento__inicial {
  width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--f-cinzel); font-weight: 700; font-size: 13px;
  color: var(--casa-ink); border: 1px solid var(--casa-ink);
}
.evento__texto { min-width: 0; }
.evento__jugador { font-weight: 500; }
.evento__motivo { color: var(--text-muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.evento__monto { font-family: var(--f-cinzel); font-weight: 600; font-size: 17px; font-variant-numeric: tabular-nums; }
.evento__monto.gana { color: var(--gain); }
.evento__monto.pierde { color: var(--loss); }

.boton-fantasma {
  margin-top: var(--e-4); min-height: 44px; padding: var(--e-2) var(--e-5);
  background: transparent; color: var(--arcane);
  border: 1px solid color-mix(in srgb, var(--arcane) 50%, transparent); border-radius: 999px;
  cursor: pointer; font-family: var(--f-cinzel); font-weight: 600; font-size: 14px; letter-spacing: 0.04em;
}
.boton-fantasma:hover { background: color-mix(in srgb, var(--arcane) 12%, transparent); }

/* ------------------------------------------------------------ Responsive (§8) */
@media (min-width: 600px) {
  .titulo { font-size: 36px; }
  .escena { height: 55vh; max-height: 560px; }
  .casa__cabecera { grid-template-columns: auto 72px minmax(0, 1fr) auto; }
  .casa__escudo { width: 72px; height: 72px; }
  .casa__puntos { font-size: 44px; }
  .evento__escudo { display: block; }
  .evento__inicial { display: none; }
  .evento { grid-template-columns: 3.6em 20px minmax(0, 1fr) auto; }
  .evento__motivo { display: inline; white-space: normal; }
  .evento__motivo::before { content: " · "; }
}
@media (min-width: 900px) {
  .titulo { font-size: 44px; }
  .seccion__titulo { font-size: 28px; }
  .casa__nombre { font-size: 26px; }
  .casa__cabecera { grid-template-columns: auto 96px minmax(0, 1fr) auto; }
  .casa__escudo { width: 96px; height: 96px; }
  .casa__puntos { font-size: 56px; }
  .tablero { grid-template-columns: 3fr 2fr; align-items: start; }
  .escena { height: 60vh; max-height: 620px; }
  .fallback { padding-inline: var(--e-7); }
}
@media (max-width: 899px) and (orientation: landscape) and (max-height: 500px) {
  .escena { height: 70vh; min-height: 220px; }
}

/* ------------------------------------------------------------ Movimiento reducido (§7) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
