/**
 * Estilos canónicos para Tute contra la máquina en 3D | fijate.com
 * Total compatibilidad con tema claro y oscuro, controles táctiles móviles >= 40px y HUD inmersivo
 */

:root {
  --font-main: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-heading: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Colores temáticos */
  --tute-primary: #10b981;
  --tute-primary-hover: #059669;
  --tute-accent: #f59e0b;
  --tute-canto: #fbbf24;
  --tute-danger: #ef4444;

  --bg-felt-dark: #0f172a;
  --bg-felt-light: #f8fafc;
  --card-bg-dark: #1e293b;
  --card-bg-light: #ffffff;
  --text-main-dark: #f8fafc;
  --text-main-light: #0f172a;
  --text-muted-dark: #94a3b8;
  --text-muted-light: #64748b;
  --border-dark: #334155;
  --border-light: #e2e8f0;
}

/* Contención global canónica */
body {
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-main);
  background-color: var(--bg-felt-dark);
  color: var(--text-main-dark);
  margin: 0;
  padding: 0;
}

html[data-theme="light"] body {
  background-color: var(--bg-felt-light);
  color: var(--text-main-light);
}

.tool-layout {
  max-width: 1200px;
  width: 100%;
  margin: 1.5rem auto 3rem;
  padding: 0 1rem;
  box-sizing: border-box;
}

/* Layout con barra lateral de anuncios sticky (>= 1536px) */
.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%;
}

.tool-ad-sidebar {
  display: none;
  width: 300px;
  flex-shrink: 0;
  position: sticky;
  top: 1.5rem;
}

@media (min-width: 1536px) {
  .tool-ad-sidebar {
    display: block;
  }
}

/* Encabezado de la herramienta */
.tool-hero {
  margin-bottom: 1.5rem;
  text-align: left;
}

.tool-title {
  font-family: var(--font-heading);
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.2;
  margin: 0 0 0.5rem;
  letter-spacing: -0.02em;
}

.tool-subtitle {
  font-size: 1rem;
  color: var(--text-muted-dark);
  margin: 0;
  line-height: 1.5;
}

html[data-theme="light"] .tool-subtitle {
  color: var(--text-muted-light);
}

/* Contenedor del tapete 3D */
.tute-stage-wrapper {
  position: relative;
  width: 100%;
  border-radius: 16px;
  overflow: hidden;
  background: radial-gradient(circle at center, #064e3b 0%, #022c22 75%, #051614 100%);
  box-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.5), inset 0 0 0 1px rgba(255, 255, 255, 0.1);
  margin-bottom: 1.5rem;
}

#table-3d-container {
  width: 100%;
  height: 560px;
  display: block;
  cursor: default;
  touch-action: none;
}

@media (max-width: 768px) {
  #table-3d-container {
    height: 440px;
  }
}

/* HUD superior flotante */
.hud-top-bar {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  pointer-events: none;
  z-index: 10;
}

.hud-top-left,
.hud-top-right {
  display: flex;
  gap: 8px;
  align-items: center;
  pointer-events: auto;
}

.hud-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 9999px;
  font-size: 0.825rem;
  font-weight: 600;
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(15, 23, 42, 0.82);
  color: #f8fafc;
}

.badge-trump {
  border-left-width: 4px;
}

.badge-active-player {
  background: rgba(16, 185, 129, 0.9);
  color: #ffffff;
  border-color: #34d399;
  animation: pulse-border 2s infinite;
}

.badge-bot-turn {
  background: rgba(30, 41, 59, 0.88);
  color: #94a3b8;
}

@keyframes pulse-border {
  0%, 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.6); }
  50% { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
}

/* Marcador flotante */
.hud-scoreboard {
  display: flex;
  gap: 12px;
  background: rgba(15, 23, 42, 0.88);
  padding: 6px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(8px);
  pointer-events: auto;
}

.score-box {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.score-box .score-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: #94a3b8;
  font-weight: 600;
}

.score-box .score-val {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 700;
  color: #f8fafc;
}

.score-box-us .score-val {
  color: #34d399;
}

.score-box-them .score-val {
  color: #f87171;
}

/* Barra inferior de cantes flotante */
.cantes-bar {
  position: absolute;
  bottom: 135px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  z-index: 40;
  pointer-events: auto;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (max-width: 768px) {
  .cantes-bar {
    bottom: 110px;
  }
}

.cantes-bar.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(20px);
}

.cantes-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #fbbf24;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
  letter-spacing: 0.05em;
}

.cantes-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn-canto {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: #ffffff;
  border: 1px solid #fde68a;
  padding: 8px 18px;
  border-radius: 9999px;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(245, 158, 11, 0.45);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  min-height: 40px;
}

.btn-canto:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 8px 20px rgba(245, 158, 11, 0.6);
}

/* Abanico ergonómico frontal de cartas del jugador humano (Sur) */
.player-hand-dock {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 145px;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  padding-bottom: 8px;
  pointer-events: none;
  z-index: 30;
  overflow: visible;
}

@media (max-width: 768px) {
  .player-hand-dock {
    height: 120px;
    padding-bottom: 6px;
  }
}

.player-hand-cards {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  pointer-events: auto;
  max-width: 100%;
  padding: 0 12px 6px;
  height: 100%;
}

.hand-card {
  position: absolute;
  bottom: 6px;
  width: 76px;
  height: 118px;
  border-radius: 7px;
  border: 1px solid rgba(0, 0, 0, 0.25);
  background: #ffffff;
  padding: 0;
  margin: 0;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45), 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.22s ease, filter 0.22s ease, opacity 0.22s ease;
  will-change: transform;
  touch-action: manipulation;
  overflow: hidden;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.hand-card img {
  width: 100%;
  height: 100%;
  object-fit: fill;
  display: block;
  border-radius: 6px;
  pointer-events: none;
}

/* Estado de carta jugable legal */
.hand-card.is-legal {
  cursor: pointer;
  box-shadow: 0 0 0 2px #34d399, 0 8px 20px rgba(16, 185, 129, 0.45);
}

/* Estado de carta no permitida por regla (asistir / montar / fallar) */
.hand-card.is-illegal {
  cursor: not-allowed;
  opacity: 0.62;
  filter: brightness(0.65) grayscale(20%);
}

/* Interacción hover y focus para elevar la carta limpiamente */
.hand-card:hover,
.hand-card:focus-visible {
  transform: translateY(-28px) scale(1.14) !important;
  z-index: 120 !important;
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.75), 0 0 0 2px #fbbf24 !important;
  opacity: 1 !important;
  filter: none !important;
}

.hand-card.is-illegal:hover,
.hand-card.is-illegal:focus-visible {
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.7), 0 0 0 2px #ef4444 !important;
  opacity: 0.88 !important;
}

/* Animación de carta jugada hacia el tapete */
.hand-card.is-played {
  transform: translateY(-80px) scale(0.65) !important;
  opacity: 0 !important;
  pointer-events: none !important;
  transition: transform 0.3s cubic-bezier(0.2, 0.9, 0.2, 1), opacity 0.25s ease !important;
}

/* Adaptación responsive para pantallas intermedias y móviles */
@media (max-width: 768px) {
  .hand-card {
    width: 60px;
    height: 94px;
    border-radius: 6px;
  }
}

@media (max-width: 480px) {
  .hand-card {
    width: 48px;
    height: 76px;
    border-radius: 5px;
  }
}

/* Barra de controles y opciones táctiles */
.tute-controls-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  background: var(--card-bg-dark);
  border: 1px solid var(--border-dark);
  padding: 12px 16px;
  border-radius: 12px;
  margin-bottom: 1.5rem;
}

html[data-theme="light"] .tute-controls-panel {
  background: var(--card-bg-light);
  border-color: var(--border-light);
}

.controls-group-left,
.controls-group-right {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.btn-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 16px;
  height: 42px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border-dark);
  background: #334155;
  color: #ffffff;
  transition: background 0.15s ease, border-color 0.15s ease;
  min-width: 0;
}

html[data-theme="light"] .btn-action {
  background: #f1f5f9;
  color: #0f172a;
  border-color: var(--border-light);
}

.btn-action:hover {
  background: #475569;
}

html[data-theme="light"] .btn-action:hover {
  background: #e2e8f0;
}

.btn-primary-action {
  background: var(--tute-primary);
  border-color: #059669;
  color: #ffffff;
}

.btn-primary-action:hover {
  background: var(--tute-primary-hover);
}

/* Bitácora de jugadas */
.game-log-box {
  background: var(--card-bg-dark);
  border: 1px solid var(--border-dark);
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 1.5rem;
}

html[data-theme="light"] .game-log-box {
  background: var(--card-bg-light);
  border-color: var(--border-light);
}

.game-log-title {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted-dark);
  margin-bottom: 6px;
}

html[data-theme="light"] .game-log-title {
  color: var(--text-muted-light);
}

#game-log-content {
  max-height: 85px;
  overflow-y: auto;
  font-size: 0.85rem;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.log-line {
  padding: 2px 0;
}

.log-player { color: #34d399; font-weight: 600; }
.log-trick { color: #fbbf24; font-weight: 600; }
.log-canto { color: #f59e0b; font-weight: 700; }
.log-info { color: var(--text-muted-dark); }
html[data-theme="light"] .log-info { color: var(--text-muted-light); }

/* Banners flotantes de cantes */
.canto-floating-banner {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%) scale(1);
  background: rgba(15, 23, 42, 0.92);
  color: #fbbf24;
  border: 2px solid #f59e0b;
  padding: 12px 24px;
  border-radius: 9999px;
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 800;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 20px rgba(245, 158, 11, 0.4);
  z-index: 9999;
  backdrop-filter: blur(8px);
  animation: banner-enter 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
}

@keyframes banner-enter {
  0% { transform: translateX(-50%) scale(0.6); opacity: 0; }
  100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

.canto-floating-banner.fade-out {
  opacity: 0;
  transform: translateX(-50%) scale(0.9);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

/* Modales accesibles nativos */
.tute-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  display: none;
  justify-content: center;
  align-items: center;
  padding: 1rem;
  z-index: 10000;
  box-sizing: border-box;
}

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

.modal-dialog {
  background: var(--card-bg-dark);
  color: var(--text-main-dark);
  border: 1px solid var(--border-dark);
  border-radius: 16px;
  max-width: 520px;
  width: 100%;
  padding: 24px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.65);
  box-sizing: border-box;
  animation: modal-pop 0.25s ease-out;
}

html[data-theme="light"] .modal-dialog {
  background: var(--card-bg-light);
  color: var(--text-main-light);
  border-color: var(--border-light);
}

@keyframes modal-pop {
  0% { transform: scale(0.95); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.modal-title {
  font-family: var(--font-heading);
  font-size: 1.4rem;
  font-weight: 700;
  margin: 0;
}

.btn-close-icon {
  background: transparent;
  border: none;
  font-size: 1.4rem;
  color: var(--text-muted-dark);
  cursor: pointer;
  padding: 4px 8px;
}

.modal-body {
  font-size: 0.95rem;
  line-height: 1.5;
  margin-bottom: 1.5rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Desglose de puntuación final */
.score-breakdown-card {
  background: rgba(15, 23, 42, 0.4);
  border: 1px solid var(--border-dark);
  border-radius: 10px;
  padding: 12px 16px;
  margin-top: 12px;
}

html[data-theme="light"] .score-breakdown-card {
  background: #f8fafc;
  border-color: var(--border-light);
}

.score-card-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 0.9rem;
}

.score-total-row {
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--tute-primary);
  border-top: 1px dashed var(--border-dark);
  padding-top: 6px;
  margin-top: 4px;
}

.score-divider {
  border: 0;
  height: 1px;
  background: var(--border-dark);
  margin: 8px 0;
}

/* Desplegables <select> conforme a regla 10 */
.form-select-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-weight: 600;
  font-size: 0.875rem;
  margin-bottom: 6px;
}

.form-select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  height: 44px;
  padding: 0 40px 0 12px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
  border: 1px solid var(--border-dark);
  background-color: #1e293b;
  color: #f8fafc;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' 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 12px center;
  background-size: 16px;
}

html[data-theme="light"] .form-select {
  background-color: #ffffff;
  color: #0f172a;
  border-color: var(--border-light);
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' 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");
}

/* Responsividad en móvil */
@media (max-width: 640px) {
  .tool-title {
    font-size: 1.5rem;
  }
  .hud-top-bar {
    gap: 6px;
  }
  .hud-scoreboard {
    padding: 4px 8px;
    gap: 8px;
  }
  .score-box .score-val {
    font-size: 1.05rem;
  }
  .tute-controls-panel {
    flex-direction: column;
    align-items: stretch;
  }
  .controls-group-left,
  .controls-group-right {
    width: 100%;
  }
  .btn-action {
    width: 100%;
  }
}
