/* ==========================================================================
   Backgammon de lujo (Tablas reales) 3D - Estilos Oficiales Fijate Tools
   ========================================================================== */

:root {
  /* Variables de diseño y paleta cromática (Tema Oscuro por defecto) */
  --bg-primary: #0a0d14;
  --bg-secondary: #121722;
  --bg-tertiary: #1a2233;
  --bg-elevated: #222d42;
  --border-color: #27344d;
  --border-subtle: #1c273a;
  
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --accent-gold: #d4af37;
  --accent-gold-hover: #e5be49;
  --accent-gold-glow: rgba(212, 175, 55, 0.28);
  
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-success: #10b981;
  --color-danger: #ef4444;
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 24px rgba(212, 175, 55, 0.2);

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f5f9;
  --bg-elevated: #e2e8f0;
  --border-color: #cbd5e1;
  --border-subtle: #e2e8f0;
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  
  --accent-gold: #b8860b;
  --accent-gold-hover: #996f08;
  --accent-gold-glow: rgba(184, 134, 11, 0.2);
  
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.12);
}

/* Reset y estructura base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3, h4, h5, h6, .brand-title, .modal-title, .game-title {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.02em;
}

button, input, select, textarea {
  font-family: inherit;
}

.mono-num, code, pre {
  font-family: var(--font-mono);
}

/* Layout y cuadrícula principal */
.tool-layout {
  width: 100%;
  max-width: 1380px;
  margin: 1.2rem auto 3rem;
  padding: 0 1.2rem;
  flex: 1 0 auto;
}

.tool-with-sidebar {
  display: flex;
  gap: 1.8rem;
  align-items: flex-start;
}

.tool-main-content {
  flex: 1 1 0%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Publicidad horizontal superior */
.tools-ad-banner-section {
  width: 100%;
  margin-bottom: 0.5rem;
}

.ad-banner-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.ad-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.ad-banner-card {
  width: 100%;
  min-height: 90px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

/* Tarjeta principal del juego 3D */
.game-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Barra superior HUD (Telemetría de la partida) */
.game-hud-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.85rem;
  padding: 1rem 1.4rem;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-color);
}

.hud-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.hud-metric-box {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.35rem 0.7rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.hud-metric-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
}

.hud-metric-val {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* Badges de jugador y turno */
.badge-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.pill-white {
  background: #f8fafc;
  color: #0f172a;
  border: 1px solid #cbd5e1;
}

.pill-black {
  background: #18181b;
  color: #fafafa;
  border: 1px solid #3f3f46;
}

.turn-player-tag {
  font-size: 0.82rem;
  color: var(--text-secondary);
  font-weight: 500;
}

/* Contenedor del lienzo 3D Three.js */
.canvas-wrapper {
  position: relative;
  width: 100%;
  height: 560px;
  min-height: 480px;
  background: #0b0e14;
  overflow: hidden;
}

@media (min-width: 1024px) {
  .canvas-wrapper {
    height: 640px;
  }
}

#canvas-3d-container {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}

#canvas-3d-container:active {
  cursor: grabbing;
}

/* Controles de cámara flotantes */
.canvas-top-overlay {
  position: absolute;
  top: 1rem;
  left: 1rem;
  right: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
  z-index: 10;
}

.overlay-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.85rem;
  background: rgba(18, 23, 34, 0.82);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.camera-controls-group {
  display: flex;
  gap: 0.4rem;
  pointer-events: auto;
}

.btn-cam {
  padding: 0.4rem 0.75rem;
  background: rgba(18, 23, 34, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--text-secondary);
  border-radius: var(--radius-md);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.btn-cam:hover {
  background: rgba(34, 45, 66, 0.95);
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.28);
}

.btn-cam.active {
  background: var(--accent-gold);
  color: #1a1202;
  border-color: var(--accent-gold-hover);
  box-shadow: 0 0 12px var(--accent-gold-glow);
}

/* Barra inferior del juego (Dados, acciones y controles) */
.game-bottom-bar {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  padding: 1.2rem 1.4rem;
  background: var(--bg-tertiary);
  border-top: 1px solid var(--border-color);
}

/* Área central de dados */
.dice-action-area {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 0.8rem 1.1rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
}

.dice-display-box {
  display: flex;
  align-items: center;
  min-height: 48px;
}

.dice-placeholder {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: italic;
}

.dice-pills-row {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}

.hud-die-card {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.65rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  transition: all 0.25s ease;
}

.hud-die-card.die-active {
  border-color: var(--accent-gold);
  box-shadow: 0 0 10px var(--accent-gold-glow);
}

.hud-die-card.die-spent {
  opacity: 0.38;
  filter: grayscale(0.8);
}

.die-val-badge {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent-gold);
}

.die-multi-tag {
  font-size: 0.72rem;
  padding: 0.15rem 0.35rem;
  background: rgba(212, 175, 55, 0.2);
  color: var(--accent-gold);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-weight: 600;
}

/* Fila de botones principales de acción */
.action-buttons-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
}

.btn-action {
  flex: 1 1 130px;
  min-height: 44px;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-sm);
  user-select: none;
}

.btn-action:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.btn-primary-gold {
  background: linear-gradient(135deg, var(--accent-gold), #b89326);
  color: #1a1202;
  box-shadow: 0 4px 12px var(--accent-gold-glow);
}

.btn-primary-gold:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--accent-gold-hover), #c9a32c);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(212, 175, 55, 0.4);
}

.btn-secondary {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--border-color);
  transform: translateY(-1px);
}

.btn-amber {
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: #f59e0b;
}

.btn-amber:hover:not(:disabled) {
  background: rgba(245, 158, 11, 0.25);
  transform: translateY(-1px);
}

/* Cuadrícula de opciones y desplegables */
.customization-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.85rem;
  margin-top: 0.2rem;
}

.control-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.control-label {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Desplegables según norma canónica Lección 208 */
.form-select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 0.55rem 40px 0.55rem 0.85rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  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='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  background-size: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  cursor: pointer;
  color-scheme: dark;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

[data-theme="light"] .form-select {
  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='%23475569' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  color-scheme: light;
}

.form-select:focus {
  outline: none;
  border-color: var(--accent-gold);
  box-shadow: 0 0 0 3px var(--accent-gold-glow);
}

.form-select option,
.form-select optgroup {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  padding: 0.5rem;
  color-scheme: dark;
}

[data-theme="light"] .form-select option,
[data-theme="light"] .form-select optgroup {
  color-scheme: light;
}

/* Modales canónicos accesibles */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 13, 20, 0.78);
  backdrop-filter: blur(6px);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1.2rem;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-container {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 620px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.95);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-backdrop.active .modal-container {
  transform: scale(1);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.2rem 1.5rem;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-color);
}

.modal-title {
  font-size: 1.15rem;
  color: var(--text-primary);
}

.btn-close-modal {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.4rem;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, background-color 0.2s;
}

.btn-close-modal:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  color: var(--text-secondary);
  font-size: 0.92rem;
}

.modal-body h4 {
  color: var(--text-primary);
  font-size: 1.02rem;
  margin-top: 0.4rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  background: var(--bg-tertiary);
  border-top: 1px solid var(--border-color);
}

/* Toast de notificación rápida */
.game-toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(18, 23, 34, 0.95);
  color: #f8fafc;
  padding: 0.7rem 1.4rem;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 500;
  border: 1px solid rgba(212, 175, 55, 0.4);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  opacity: 0;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 1100;
}

.game-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Sección didáctica inferior (Reglas e historia de las Tablas reales) */
.tool-info-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
}

.tool-info-title {
  font-size: 1.4rem;
  color: var(--text-primary);
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.4rem;
}

.info-card {
  padding: 1.2rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.info-card h3 {
  font-size: 1.05rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.info-card p, .info-card ul {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.info-card ul {
  padding-left: 1.2rem;
}

/* Responsividad en dispositivos móviles */
@media (max-width: 768px) {
  .tool-layout {
    padding: 0 0.6rem;
    margin-top: 0.8rem;
  }

  .game-hud-bar {
    padding: 0.8rem 1rem;
  }

  .canvas-wrapper {
    height: 420px;
    min-height: 380px;
  }

  .action-buttons-row {
    flex-direction: column;
  }

  .btn-action {
    width: 100%;
    min-height: 44px;
  }

  .dice-action-area {
    flex-direction: column;
    align-items: stretch;
  }
}
