/**
 * Dardos 3D - Estilos principales
 * Estética de salón de dardos vintage británico, pizarra de tiza, telemetría y controles táctiles
 */

:root {
  --font-main: 'Inter', system-ui, -apple-system, sans-serif;
  --font-heading: 'Outfit', 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Paleta cromática de pub tradicional */
  --pub-bg: #0c0a09;
  --pub-card: #171412;
  --pub-card-border: #29231e;
  --pub-amber: #d97706;
  --pub-amber-glow: rgba(217, 119, 6, 0.25);
  --pub-gold: #f59e0b;
  --pub-chalk-bg: #141a16;
  --pub-chalk-border: #2e3a32;
  --pub-chalk-white: #f1f5f9;
  --pub-chalk-green: #4ade80;
  --pub-chalk-red: #f87171;
  --text-muted: #a8a29e;
}

/* Reset y estructura canónica (Lección 342 y Lección 554) */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: var(--font-main);
  background-color: var(--pub-bg);
  color: #f5f5f4;
  line-height: 1.5;
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
}

body {
  display: flex;
  flex-direction: column;
}

/* Tipografía de encabezados y marcas */
h1,
h2,
h3,
h4,
h5,
h6,
.brand-title,
.section-title,
.hero-title,
.faq-section-title {
  font-family: var(--font-heading);
  letter-spacing: -0.02em;
}

/* Utilidades monoespaciadas para cifras y telemetría */
.text-mono,
.mono,
code,
pre,
kbd {
  font-family: var(--font-mono);
}

/* Herencia obligatoria en controles de formulario */
button,
input,
select,
textarea {
  font-family: inherit;
}

/* Contenedor principal de la herramienta */
.tool-layout {
  max-width: 1200px;
  margin: 1.5rem auto 3rem;
  padding: 0 1rem;
  box-sizing: border-box;
  flex: 1 0 auto;
}

.tool-with-sidebar {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  width: 100%;
}

.tool-main-content {
  flex: 1 1 0%;
  min-width: 0;
  width: 100%;
}

/* Tarjeta principal del simulador */
.darts-game-card {
  background: var(--pub-card);
  border: 1px solid var(--pub-card-border);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  margin-bottom: 2rem;
}

/* Barra superior de estado y modo */
.game-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: #110e0c;
  border-bottom: 1px solid var(--pub-card-border);
}

.mode-selectors {
  display: flex;
  gap: 0.65rem;
  align-items: center;
  flex-wrap: wrap;
}

.select-pub {
  background: #1e1916;
  color: #f5f5f4;
  border: 1px solid #3b312b;
  border-radius: 8px;
  padding: 0.5rem 2.1rem 0.5rem 0.75rem;
  font-family: var(--font-main);
  font-size: 0.88rem;
  cursor: pointer;
  height: 40px;
  box-sizing: border-box;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23d97706' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
}

.select-pub:focus {
  outline: none;
  border-color: var(--pub-amber);
}

.top-bar-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.btn-pub-icon {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: #1e1916;
  border: 1px solid #3b312b;
  color: #f5f5f4;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-pub-icon:hover {
  background: #2a221e;
  border-color: var(--pub-amber);
  color: var(--pub-amber);
}

.btn-pub-icon.active {
  background: var(--pub-amber);
  color: #0c0a09;
  border-color: var(--pub-amber);
}

.btn-pub-icon.muted {
  opacity: 0.5;
  color: #ef4444;
}

/* Área interactiva 3D */
.viewport-3d-wrapper {
  position: relative;
  width: 100%;
  height: clamp(640px, 74vh, 880px);
  min-height: 580px;
  background: #080605;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

@media (min-width: 1400px) {
  .viewport-3d-wrapper {
    height: clamp(700px, 78vh, 920px);
  }
}

#darts-3d-canvas-container {
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* Overlay de control por swipe */
#darts-swipe-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  cursor: crosshair;
  touch-action: none;
}

/* Canvas para el trazo visual del swipe */
#swipe-trail-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 11;
}

/* Telemetría de sector apuntado */
#hud-aim-telemetry {
  position: absolute;
  top: 1rem;
  left: 1rem;
  background: rgba(18, 14, 12, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid #3b312b;
  padding: 0.4rem 0.85rem;
  border-radius: 9999px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: #e7e5e4;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  pointer-events: none;
  z-index: 15;
}

.telemetry-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--pub-chalk-green);
  box-shadow: 0 0 8px var(--pub-chalk-green);
}

/* Retícula de apunte flotante */
#aim-reticle {
  position: absolute;
  width: 34px;
  height: 34px;
  margin-left: -17px;
  margin-top: -17px;
  top: 50%;
  left: 50%;
  pointer-events: none;
  border: 2px dashed rgba(245, 158, 11, 0.85);
  border-radius: 50%;
  opacity: 0.65;
  transition: opacity 0.15s ease, transform 0.1s ease;
  z-index: 12;
}

#aim-reticle.locked {
  border-style: solid;
  border-color: #4ade80;
  transform: scale(0.9);
  opacity: 1;
}

#aim-reticle::after {
  content: '';
  position: absolute;
  width: 6px;
  height: 6px;
  top: 12px;
  left: 12px;
  background: var(--pub-gold);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--pub-gold);
}

/* Indicador de gesto de swipe en móvil / escritorio */
.swipe-hint-pill {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(18, 14, 12, 0.88);
  backdrop-filter: blur(8px);
  border: 1px solid #3b312b;
  padding: 0.45rem 1rem;
  border-radius: 9999px;
  font-size: 0.82rem;
  color: #d6d3d1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  pointer-events: none;
  z-index: 14;
  white-space: nowrap;
  max-width: 92%;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Banner de rotura / Bust */
#hud-bust-banner {
  position: absolute;
  top: 2.2rem;
  left: 50%;
  transform: translateX(-50%) scale(0.8);
  background: #dc2626;
  color: #ffffff;
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 1.45rem;
  padding: 0.5rem 1.8rem;
  border-radius: 9999px;
  box-shadow: 0 4px 24px rgba(220, 38, 38, 0.7);
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 25;
}

#hud-bust-banner.active {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

/* Popup flotante de puntuación y llamadas del árbitro */
#hud-score-popup {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translateX(-50%) translateY(12px) scale(0.9);
  background: rgba(20, 26, 22, 0.92);
  border: 2px solid var(--pub-gold);
  color: #fef08a;
  font-family: var(--font-heading);
  font-weight: 900;
  font-size: 1.35rem;
  padding: 0.45rem 1.4rem;
  border-radius: 9999px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.65);
  opacity: 0;
  pointer-events: none;
  transition: all 0.22s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 24;
  letter-spacing: 0.02em;
}

#hud-score-popup.active {
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(1);
}

#hud-score-popup.max-180 {
  background: linear-gradient(135deg, #b91c1c, #d97706);
  color: #ffffff;
  font-size: 1.8rem;
  border-color: #fde047;
  box-shadow: 0 0 35px rgba(245, 158, 11, 0.8);
}

/* HUD Pizarra de Tiza */
.chalkboard-hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 1rem;
  align-items: center;
  padding: 1.25rem;
  background: var(--pub-chalk-bg);
  border-top: 1px solid var(--pub-chalk-border);
  position: relative;
}

.player-score-block {
  display: flex;
  flex-direction: column;
  padding: 0.65rem 0.9rem;
  border-radius: 12px;
  border: 1px solid transparent;
  transition: all 0.2s ease;
}

.player-score-block.active-turn {
  background: rgba(255, 255, 255, 0.03);
  border-color: rgba(74, 222, 128, 0.35);
}

.player-score-block.rival {
  text-align: right;
  align-items: flex-end;
}

.player-score-block.rival.active-turn {
  border-color: rgba(248, 113, 113, 0.35);
}

.player-header-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.player-header-row.rival-row {
  justify-content: flex-end;
}

.player-label {
  font-family: var(--font-heading);
  font-size: 0.98rem;
  font-weight: 700;
  color: #94a3b8;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.player-label.p1 {
  color: var(--pub-chalk-green);
}

.player-label.p2 {
  color: var(--pub-chalk-red);
}

.legs-pill {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  background: #1e293b;
  color: #f8fafc;
  padding: 0.15rem 0.55rem;
  border-radius: 9999px;
  border: 1px solid #334155;
}

.score-big {
  font-family: var(--font-mono);
  font-size: 2.8rem;
  font-weight: 800;
  color: var(--pub-chalk-white);
  line-height: 1.1;
  letter-spacing: -0.03em;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  margin: 0.15rem 0;
}

.stats-mini-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.player-avg {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: #94a3b8;
}

/* Centro del HUD: Turno, dardos y cierres */
.turn-center-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
}

.turn-badge {
  font-family: var(--font-heading);
  font-size: 0.85rem;
  font-weight: 700;
  padding: 0.3rem 0.9rem;
  border-radius: 9999px;
  background: #1e293b;
  color: #38bdf8;
  border: 1px solid #334155;
}

.turn-badge.ai-turn {
  background: #311515;
  color: #f87171;
  border-color: #552222;
}

.turn-darts-pills {
  display: flex;
  gap: 0.4rem;
}

.dart-pill {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  padding: 0.25rem 0.65rem;
  border-radius: 6px;
  background: #1e1916;
  border: 1px solid #3b312b;
  color: #78716c;
  transition: all 0.2s ease;
}

.dart-pill.active-dart {
  border-color: var(--pub-gold);
  color: #f5f5f4;
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.25);
}

.dart-pill.used {
  background: #2a221b;
  border-color: var(--pub-amber);
  color: #fef08a;
  font-weight: 700;
}

.visit-total-badge {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: #cbd5e1;
}

/* Badge de checkout recomendado */
.checkout-assistant {
  display: none;
  align-items: center;
  gap: 0.4rem;
  background: rgba(56, 189, 248, 0.14);
  border: 1px solid rgba(56, 189, 248, 0.4);
  padding: 0.3rem 0.75rem;
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: #7dd3fc;
}

/* Tabla de Cricket integrada */
#cricket-scoreboard-container {
  display: none;
  padding: 0.75rem 1.25rem;
  background: #0f1411;
  border-top: 1px solid var(--pub-chalk-border);
}

.cricket-table {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 0.9rem;
}

.cricket-table th {
  padding: 0.4rem;
  color: #94a3b8;
  border-bottom: 1px solid #2e3a32;
  text-align: center;
}

.cricket-table td {
  padding: 0.4rem;
  text-align: center;
  border-bottom: 1px solid #1c241e;
}

.cricket-row-closed {
  opacity: 0.45;
  text-decoration: line-through;
}

.cricket-sec {
  font-weight: 700;
  color: var(--pub-gold);
}

.cricket-mark {
  font-weight: 800;
  font-size: 1.1rem;
  color: #ffffff;
}

.cricket-mark.open-scoring {
  color: var(--pub-chalk-green);
}

/* Panel inferior de lanzamiento asistido */
.throw-controls-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: #110e0c;
  border-top: 1px solid var(--pub-card-border);
  flex-wrap: wrap;
}

.power-meter-container {
  flex: 1 1 240px;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.power-meter-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
}

.power-meter-track {
  flex: 1;
  height: 14px;
  background: #1e1916;
  border: 1px solid #3b312b;
  border-radius: 7px;
  overflow: hidden;
  position: relative;
}

/* Zona óptima (Sweet spot del 44% al 56%) */
.power-sweet-spot {
  position: absolute;
  left: 44%;
  width: 12%;
  top: 0;
  bottom: 0;
  background: rgba(74, 222, 128, 0.35);
  border-left: 2px solid #4ade80;
  border-right: 2px solid #4ade80;
  z-index: 2;
  pointer-events: none;
}

.power-meter-fill {
  height: 100%;
  width: 50%;
  background: linear-gradient(90deg, #3b82f6 0%, #10b981 50%, #f59e0b 80%, #ef4444 100%);
  border-radius: 5px;
  transition: width 0.03s linear;
  z-index: 1;
}

.btn-throw-action {
  background: var(--pub-amber);
  color: #0c0a09;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1rem;
  padding: 0.65rem 1.4rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 40px;
  transition: all 0.2s ease;
}

.btn-throw-action:hover {
  background: var(--pub-gold);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px var(--pub-amber-glow);
}

/* Modal de Victoria / Fin de partida */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal-overlay.active {
  display: flex;
}

.modal-dialog {
  background: var(--pub-card);
  border: 1px solid var(--pub-card-border);
  border-radius: 16px;
  width: 100%;
  max-width: 480px;
  padding: 2rem;
  box-sizing: border-box;
  text-align: center;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.7);
  animation: modalPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modalPop {
  from {
    transform: scale(0.85);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.modal-dialog h3 {
  font-family: var(--font-heading);
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--pub-gold);
  margin-bottom: 0.65rem;
}

.modal-dialog p {
  color: #d6d3d1;
  font-size: 0.95rem;
  line-height: 1.5;
  margin-bottom: 1.25rem;
}

.victory-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  margin-bottom: 1.5rem;
  text-align: left;
}

.victory-stat-card {
  background: #110e0c;
  border: 1px solid #29231e;
  border-radius: 10px;
  padding: 0.75rem;
}

.victory-stat-card span {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.victory-stat-card strong {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  color: #f5f5f4;
}

.btn-modal-primary {
  background: var(--pub-amber);
  color: #0c0a09;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1rem;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  min-height: 42px;
  width: 100%;
}

.btn-modal-primary:hover {
  background: var(--pub-gold);
}

/* Reglas y preguntas frecuentes (FAQ) */
.rules-guide-section {
  background: var(--pub-card);
  border: 1px solid var(--pub-card-border);
  border-radius: 16px;
  padding: 1.75rem;
  margin-top: 2rem;
  color: #d6d3d1;
}

.rules-guide-section h2 {
  font-family: var(--font-heading);
  font-size: 1.4rem;
  font-weight: 800;
  color: #f5f5f4;
  margin-bottom: 1rem;
}

.rules-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.25rem;
  margin-top: 1rem;
}

.rule-card {
  background: #110e0c;
  border: 1px solid #29231e;
  border-radius: 12px;
  padding: 1.2rem;
}

.rule-card h3 {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--pub-amber);
  margin-bottom: 0.5rem;
}

.rule-card p {
  font-size: 0.88rem;
  line-height: 1.5;
  color: #a8a29e;
}

/* Acordeón FAQ semántico */
.rules-guide-section.faq-section {
  margin-top: 1.5rem;
}

.faq-list {
  display: flex;
  flex-direction: column;
}

.faq-item {
  margin-bottom: 0.85rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--pub-card-border);
}

.faq-item:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.faq-summary {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
  color: var(--pub-gold);
  transition: color 0.15s ease;
  user-select: none;
}

.faq-summary:hover {
  color: #fde047;
}

.faq-answer {
  margin-top: 0.5rem;
  line-height: 1.6;
  font-size: 0.92rem;
  color: #d6d3d1;
}

/* Responsividad móvil */
@media (max-width: 768px) {
  .viewport-3d-wrapper {
    height: 480px;
    min-height: unset;
  }

  .chalkboard-hud {
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
  }

  .turn-center-block {
    grid-column: 1 / -1;
    order: -1;
  }

  .score-big {
    font-size: 2.2rem;
  }

  .throw-controls-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .power-meter-container {
    width: 100%;
  }

  .btn-throw-action {
    width: 100%;
    justify-content: center;
  }
}