/**
 * Estilos canónicos para Cinquillo (Baraja española tradicional de 40 cartas)
 * Con integración de los activos de naipes oficiales de Chinchón
 * Soporte completo para tema claro y oscuro, responsive y accesibilidad
 */

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

  --bg-body: #0f172a;
  --bg-card: #1e293b;
  --bg-card-secondary: #334155;
  --bg-input: #0f172a;
  --bg-pill: rgba(15, 23, 42, 0.6);
  --border-color: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent-text: #38bdf8;
  --btn-hover-bg: #475569;

  --felt-light: #16532d;
  --felt-dark: #0f361d;
  --table-border: #522e15;
}

[data-theme="light"] {
  --bg-body: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-secondary: #f1f5f9;
  --bg-input: #ffffff;
  --bg-pill: #f1f5f9;
  --border-color: #cbd5e1;
  --text-main: #0f172a;
  --text-muted: #475569;
  --accent-text: #0284c7;
  --btn-hover-bg: #e2e8f0;

  --felt-light: #15803d;
  --felt-dark: #166534;
  --table-border: #693b1b;
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  background-color: var(--bg-body);
  color: var(--text-main);
  font-family: var(--font-main);
  -webkit-font-smoothing: antialiased;
}

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

.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%;
}

/* Barra de mandos superior */
.cinquillo-controls-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 0.85rem 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}

.controls-group {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.controls-group label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}

.game-select {
  background: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.45rem 2rem 0.45rem 0.75rem;
  font-size: 0.85rem;
  font-family: var(--font-main);
  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 0.55rem center;
  background-size: 0.9rem;
}

.game-select option {
  background: var(--bg-input);
  color: var(--text-main);
}

.stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg-pill);
  padding: 0.35rem 0.8rem;
  border-radius: 20px;
  border: 1px solid var(--border-color);
  font-size: 0.85rem;
}

.stat-label { color: var(--text-muted); }
.stat-value { font-family: var(--font-mono); font-weight: 700; color: var(--accent-text); }

.btn-game-action {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--bg-card-secondary);
  color: var(--text-main);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 40px;
}

.btn-game-action:hover:not(:disabled) {
  background: var(--btn-hover-bg);
}

.btn-game-action:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-game-action.btn-primary-action {
  background: #0284c7;
  border-color: #0369a1;
  color: #ffffff;
}

.btn-game-action.btn-warning-action {
  background: #d97706;
  border-color: #b45309;
  color: #ffffff;
}

/* Tapete verde de cartas estilo casino / club tradicional */
.cinquillo-table {
  background: radial-gradient(circle at 50% 30%, var(--felt-light) 0%, var(--felt-dark) 100%);
  border: 6px solid var(--table-border);
  border-radius: 20px;
  padding: 1.25rem;
  box-shadow: inset 0 0 50px rgba(0, 0, 0, 0.6), 0 14px 32px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  color: #f8fafc;
  position: relative;
}

.status-bar {
  width: 100%;
  background: rgba(15, 23, 42, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  padding: 0.65rem 1rem;
  text-align: center;
  font-size: 0.95rem;
  color: #7dd3fc;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

/* Barra de oponentes */
.opponents-bar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  width: 100%;
}

.opponent-chip {
  background: rgba(15, 23, 42, 0.68);
  border: 1.5px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 0.6rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  transition: all 0.2s ease;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
  min-width: 0;
  overflow: hidden;
}

.opponent-chip.is-turn {
  border-color: #facc15;
  background: rgba(250, 204, 21, 0.12);
  box-shadow: 0 0 16px rgba(250, 204, 21, 0.45);
  transform: translateY(-2px);
}

.opp-info-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  width: 100%;
  gap: 0.25rem;
}

.opp-name {
  font-weight: 700;
  font-size: 0.86rem;
  color: #f8fafc;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.opp-turn-badge {
  font-size: 0.7rem;
  font-weight: 700;
  background: #facc15;
  color: #1e293b;
  padding: 0.1rem 0.45rem;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.opp-visual-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  min-width: 0;
  width: 100%;
}

.opp-cards-stack {
  position: relative;
  width: 44px;
  height: 32px;
  flex-shrink: 0;
}

.opp-card-back {
  position: absolute;
  top: 0;
  width: 22px;
  height: 32px;
  border-radius: 3px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.25);
  object-fit: cover;
}

.opp-stats {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  min-width: 0;
  flex-shrink: 1;
}

.opp-cards-count {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: #cbd5e1;
  font-weight: 600;
}

.opp-score {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: #38bdf8;
  font-weight: 700;
}

/* Calles del tablero (Mesa de escaleras por palo) */
.board-lanes {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 0.95rem;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.4);
}

.suit-lane {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.suit-lane-badge {
  width: 86px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  font-weight: 700;
}

.suit-svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.lane-slots {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 5px;
}

/* Casillas de cartas en el tablero */
.board-card-slot {
  aspect-ratio: 1 / 1.52;
  max-height: 68px;
  min-height: 38px;
  border-radius: 5px;
  border: 1px dashed rgba(255, 255, 255, 0.22);
  background: rgba(0, 0, 0, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: all 0.2s ease;
  overflow: hidden;
}

.slot-ghost-rank {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.76rem;
  color: rgba(255, 255, 255, 0.32);
  user-select: none;
}

.board-card-slot.is-five-anchor:not(.is-played) {
  border-color: rgba(250, 204, 21, 0.55);
  background: rgba(250, 204, 21, 0.08);
}

.board-card-slot.is-five-anchor:not(.is-played) .slot-ghost-rank {
  color: #facc15;
  font-weight: 800;
}

.board-card-slot.is-played {
  border: 1px solid rgba(255, 255, 255, 0.45);
  background: #ffffff;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.45);
  animation: cardDropIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes cardDropIn {
  from {
    transform: scale(1.15) translateY(-4px);
    opacity: 0.4;
  }
  to {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

.slot-card-img {
  width: 100%;
  height: 100%;
  object-fit: fill;
  display: block;
  border-radius: 4px;
}

/* Mano del jugador humano */
.player-hand-section {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 0.85rem;
}

.player-hand-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
}

.player-hand-title {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0;
  color: #f8fafc;
}

.player-hand-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-end;
  gap: 0.65rem;
  min-height: 120px;
}

/* Botón de carta de baraja española en la mano */
.spanish-card {
  width: 74px;
  aspect-ratio: 1 / 1.54;
  background: none;
  border: none;
  padding: 0;
  position: relative;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), filter 0.18s ease;
  user-select: none;
}

.card-img-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 7px;
  overflow: visible;
}

.hand-card-img {
  width: 100%;
  height: 100%;
  object-fit: fill;
  border-radius: 6px;
  display: block;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.42);
  transition: box-shadow 0.18s ease, border-color 0.18s ease;
  border: 1.5px solid rgba(255, 255, 255, 0.3);
}

.spanish-card.is-playable {
  cursor: pointer;
  transform: translateY(-4px);
}

.spanish-card.is-playable .hand-card-img {
  border: 2px solid #38bdf8;
  box-shadow: 0 0 16px rgba(56, 189, 248, 0.85), 0 8px 18px rgba(0, 0, 0, 0.45);
}

.spanish-card.is-playable:hover {
  transform: translateY(-10px) scale(1.05);
  z-index: 10;
}

.spanish-card.is-playable:hover .hand-card-img {
  border-color: #facc15;
  box-shadow: 0 0 20px rgba(250, 204, 21, 0.9), 0 12px 24px rgba(0, 0, 0, 0.5);
}

.spanish-card.is-playable .playable-glow-ring {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 12px;
  height: 12px;
  background: #38bdf8;
  border: 2px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 0 8px #38bdf8;
  animation: pulseGlow 1.5s infinite;
}

@keyframes pulseGlow {
  0% { transform: scale(0.9); opacity: 0.8; }
  50% { transform: scale(1.25); opacity: 1; box-shadow: 0 0 12px #38bdf8; }
  100% { transform: scale(0.9); opacity: 0.8; }
}

.spanish-card.is-locked {
  cursor: not-allowed;
  opacity: 0.55;
  filter: grayscale(20%) brightness(0.85);
}

.spanish-card.is-locked .hand-card-img {
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* Modal fin de ronda / partida */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(4px);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-card {
  background: var(--bg-card);
  border: 2px solid var(--accent-text);
  border-radius: 16px;
  padding: 2rem;
  max-width: 420px;
  width: 92%;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.45);
}

.modal-card h2 {
  font-family: var(--font-heading);
  font-size: 1.55rem;
  margin: 0 0 0.5rem;
  color: var(--accent-text);
}

.modal-card p {
  color: var(--text-muted);
  margin: 0 0 1rem;
  line-height: 1.5;
}

.scoreboard-list {
  list-style: none;
  padding: 0;
  margin: 0 0 1.25rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 10px;
}

.scoreboard-list li {
  display: flex;
  justify-content: space-between;
  padding: 0.55rem 0.9rem;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.9rem;
}

.scoreboard-list li:last-child {
  border-bottom: none;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

/* Sección de guía y reglas */
.game-guide-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 1.75rem;
  margin-top: 2rem;
}

.game-guide-section h2 {
  font-family: var(--font-heading);
  font-size: 1.35rem;
  margin-top: 0;
  margin-bottom: 1rem;
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.5rem;
}

.guide-item h3 {
  font-size: 1.05rem;
  margin-top: 0;
  margin-bottom: 0.4rem;
  color: var(--accent-text);
}

.guide-item p {
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text-muted);
  margin: 0;
}

/* Adaptación responsive */
@media (max-width: 820px) {
  .cinquillo-table {
    padding: 0.85rem;
    gap: 0.75rem;
  }
  .suit-lane {
    gap: 0.5rem;
  }
  .suit-lane-badge {
    width: 72px;
    font-size: 0.78rem;
  }
  .lane-slots {
    gap: 3px;
  }
  .board-card-slot {
    max-height: 52px;
  }
  .spanish-card {
    width: 60px;
  }
  .player-hand-row {
    gap: 0.45rem;
  }
}

@media (max-width: 580px) {
  .opponents-bar {
    gap: 0.35rem;
  }
  .opponent-chip {
    padding: 0.35rem 0.35rem;
    border-radius: 8px;
    gap: 0.25rem;
  }
  .opp-name {
    font-size: 0.72rem;
  }
  .opp-turn-badge {
    font-size: 0.58rem;
    padding: 0.05rem 0.25rem;
  }
  .opp-cards-stack {
    width: 24px;
    height: 24px;
  }
  .opp-card-back {
    width: 16px;
    height: 24px;
  }
  .opp-cards-count {
    font-size: 0.68rem;
    white-space: nowrap;
  }
  .opp-score {
    font-size: 0.64rem;
  }
  .suit-lane {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
  }
  .suit-lane-badge {
    width: auto;
  }
  .lane-slots {
    width: 100%;
    gap: 2px;
  }
  .board-card-slot {
    max-height: 44px;
  }
  .slot-ghost-rank {
    font-size: 0.68rem;
  }
  .spanish-card {
    width: 48px;
  }
  .player-hand-row {
    gap: 0.35rem;
  }
}

@media (max-width: 380px) {
  .spanish-card {
    width: 42px;
  }
  .board-card-slot {
    max-height: 38px;
  }
  .slot-ghost-rank {
    font-size: 0.62rem;
  }
}
