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

  --bg-body: #0b0f17;
  --bg-card: #131b2e;
  --bg-elevated: #1c2539;
  --bg-input: #0f1626;
  --text-main: #f8fafc;
  --text-primary: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --border-color: #1e293b;
  --border-subtle: #1e293b;
  --accent-primary: #f59e0b;
  --accent-secondary: #3b82f6;
  --accent-hover: #d97706;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;

  --board-outer-border: #e2e8f0;
  --board-region-border: #090d16;
  --board-cell-border: rgba(15, 23, 42, 0.28);
  --x-mark-color: rgba(248, 250, 252, 0.78);
  --x-auto-color: rgba(248, 250, 252, 0.35);
}

[data-theme="light"] {
  --bg-body: #f8fafc;
  --bg-card: #ffffff;
  --bg-elevated: #f1f5f9;
  --bg-input: #f8fafc;
  --text-main: #0f172a;
  --text-primary: #0f172a;
  --text-muted: #475569;
  --text-dim: #64748b;
  --border-color: #e2e8f0;
  --border-subtle: #cbd5e1;
  --accent-primary: #d97706;
  --accent-secondary: #2563eb;
  --accent-hover: #b45309;

  --board-outer-border: #0f172a;
  --board-region-border: #0f172a;
  --board-cell-border: rgba(15, 23, 42, 0.16);
  --x-mark-color: rgba(15, 23, 42, 0.65);
  --x-auto-color: rgba(15, 23, 42, 0.28);
}

*, *::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;
  background-color: var(--bg-body);
  color: var(--text-main);
  font-family: var(--font-main);
  line-height: 1.5;
}

.tool-layout {
  max-width: 1200px;
  width: 100%;
  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%;
}

/* Quick bar custom adjustments */
.reinas-badge-daily {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.14);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.35);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 700;
}

[data-theme="light"] .reinas-badge-daily {
  color: #b45309;
  background: rgba(245, 158, 11, 0.15);
}

.reinas-timer-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.7rem;
  border-radius: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  font-family: var(--font-mono);
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-main);
}

.reinas-quick-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn-pill {
  min-height: 40px;
  padding: 0 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  transition: all 0.15s ease;
}

.btn-pill:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.btn-pill.active {
  background: rgba(245, 158, 11, 0.18);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.btn-icon-sq {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  color: var(--text-main);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.btn-icon-sq:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

/* Tarjeta principal de juego */
.reinas-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
}

[data-theme="light"] .reinas-card {
  box-shadow: 0 6px 24px rgba(15, 23, 42, 0.06);
}

.reinas-status-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.15rem;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--border-color);
}

.reinas-counters {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.reinas-counter-val {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--text-main);
}

.reinas-rules-hint {
  font-size: 0.83rem;
  color: var(--text-muted);
}

/* Selector de modo de interacción */
.reinas-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 1.1rem;
}

.reinas-mode-segment {
  display: inline-flex;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}

.mode-seg-btn {
  min-height: 36px;
  padding: 0 0.75rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-main);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.15s ease;
}

.mode-seg-btn.active {
  background: var(--bg-card);
  color: var(--text-main);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

[data-theme="light"] .mode-seg-btn.active {
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.1);
}

.reinas-toggle-auto {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 40px;
  padding: 0 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  color: var(--text-main);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

.reinas-toggle-auto input {
  accent-color: var(--accent-primary);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* Tablero N×N */
.reinas-board-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0.5rem auto 1.25rem;
  width: 100%;
}

.reinas-board {
  display: grid;
  width: min(100%, 460px);
  aspect-ratio: 1 / 1;
  border: 3px solid var(--board-outer-border);
  border-radius: 10px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  background: var(--board-region-border);
  box-shadow: 0 14px 35px rgba(0, 0, 0, 0.32);
}

.reinas-cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin: 0;
  border: none;
  border-top: 1px solid var(--board-cell-border);
  border-right: 1px solid var(--board-cell-border);
  border-bottom: 1px solid var(--board-cell-border);
  border-left: 1px solid var(--board-cell-border);
  cursor: pointer;
  transition: filter 0.12s ease, transform 0.1s ease;
  color: var(--text-main);
  outline: none;
}

.reinas-cell:focus-visible {
  box-shadow: inset 0 0 0 3px #ffffff, inset 0 0 0 5px #0f172a;
  z-index: 2;
}

.reinas-cell:hover {
  filter: brightness(1.08);
}

/* Bordes entre regiones distintas */
.reinas-cell.bt { border-top: 2.5px solid var(--board-region-border); }
.reinas-cell.br { border-right: 2.5px solid var(--board-region-border); }
.reinas-cell.bb { border-bottom: 2.5px solid var(--board-region-border); }
.reinas-cell.bl { border-left: 2.5px solid var(--board-region-border); }

/* Paleta de 9 regiones en tema oscuro (saturación media-luminosa equilibrada) */
.reinas-cell.reg-0 { background-color: #7c58a6; }
.reinas-cell.reg-1 { background-color: #b8783b; }
.reinas-cell.reg-2 { background-color: #3a7ca5; }
.reinas-cell.reg-3 { background-color: #468a63; }
.reinas-cell.reg-4 { background-color: #b55464; }
.reinas-cell.reg-5 { background-color: #9e8a3a; }
.reinas-cell.reg-6 { background-color: #3d8b8c; }
.reinas-cell.reg-7 { background-color: #8f5c78; }
.reinas-cell.reg-8 { background-color: #64748b; }

/* Paleta de 9 regiones en tema claro (pasteles nítidos de alto contraste) */
[data-theme="light"] .reinas-cell.reg-0 { background-color: #d8b4fe; }
[data-theme="light"] .reinas-cell.reg-1 { background-color: #fed7aa; }
[data-theme="light"] .reinas-cell.reg-2 { background-color: #bae6fd; }
[data-theme="light"] .reinas-cell.reg-3 { background-color: #bbf7d0; }
[data-theme="light"] .reinas-cell.reg-4 { background-color: #fecaca; }
[data-theme="light"] .reinas-cell.reg-5 { background-color: #fef08a; }
[data-theme="light"] .reinas-cell.reg-6 { background-color: #99f6e4; }
[data-theme="light"] .reinas-cell.reg-7 { background-color: #fbcfe8; }
[data-theme="light"] .reinas-cell.reg-8 { background-color: #cbd5e1; }

.reinas-cell .cell-x {
  width: 36%;
  height: 36%;
  color: var(--x-mark-color);
  pointer-events: none;
  transition: transform 0.12s ease;
}

.reinas-cell.is-auto-x .cell-x {
  color: var(--x-auto-color);
  width: 28%;
  height: 28%;
}

.reinas-cell .cell-crown {
  width: 62%;
  height: 62%;
  pointer-events: none;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.35));
  animation: crownPop 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes crownPop {
  0% { transform: scale(0.5); opacity: 0.4; }
  100% { transform: scale(1); opacity: 1; }
}

.reinas-cell.is-conflict::after {
  content: '';
  position: absolute;
  inset: 2px;
  border: 2.5px solid #ef4444;
  border-radius: 4px;
  background: repeating-linear-gradient(
    -45deg,
    rgba(239, 68, 68, 0.16),
    rgba(239, 68, 68, 0.16) 5px,
    transparent 5px,
    transparent 10px
  );
  pointer-events: none;
}

.reinas-cell.is-hint-pulse {
  animation: hintGlow 1.1s ease-in-out 2;
}

@keyframes hintGlow {
  0%, 100% { box-shadow: inset 0 0 0 0 rgba(255, 255, 255, 0); }
  50% { box-shadow: inset 0 0 0 4px #ffffff; }
}

.reinas-board.is-solved .reinas-cell.has-crown .cell-crown {
  animation: solvedBounce 0.5s ease both;
}

@keyframes solvedBounce {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.16); }
}

/* Barra de acciones bajo el tablero */
.reinas-bottom-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.reinas-action-btn {
  min-height: 42px;
  padding: 0 1rem;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  transition: all 0.15s ease;
}

.reinas-action-btn:hover:not(:disabled) {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.reinas-action-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.reinas-action-btn.primary {
  background: var(--accent-primary);
  color: #0f172a;
  border-color: var(--accent-primary);
  font-weight: 700;
}

.reinas-action-btn.primary:hover:not(:disabled) {
  background: var(--accent-hover);
  color: #ffffff;
}

.reinas-feedback-banner {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  font-size: 0.88rem;
  display: none;
  align-items: center;
  gap: 0.6rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

.reinas-feedback-banner.visible {
  display: flex;
}

.reinas-feedback-banner.error {
  border-color: rgba(239, 68, 68, 0.5);
  background: rgba(239, 68, 68, 0.12);
}

.reinas-feedback-banner.hint {
  border-color: rgba(59, 130, 246, 0.5);
  background: rgba(59, 130, 246, 0.12);
}

.reinas-feedback-banner.success {
  border-color: rgba(16, 185, 129, 0.5);
  background: rgba(16, 185, 129, 0.12);
}

/* Práctica panel */
.reinas-practice-bar {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  padding: 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 10px;
}

.reinas-practice-bar.visible {
  display: flex;
}

.reinas-select {
  min-height: 40px;
  max-width: 100%;
  padding: 0 38px 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-elevated);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 0.86rem;
  font-weight: 600;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='15' height='15' 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 10px center;
  background-size: 15px 15px;
  cursor: pointer;
}

[data-theme="light"] .reinas-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='%23475569' 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");
}

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

/* Modales accesibles */
.reinas-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(4px);
  z-index: 1200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.reinas-modal-backdrop.open {
  display: flex;
}

.reinas-modal {
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 1.5rem;
  color: var(--text-main);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.45);
  position: relative;
}

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

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

.reinas-modal-close {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  color: var(--text-main);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.reinas-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.65rem;
  margin: 1rem 0 1.25rem;
}

.reinas-stat-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 0.75rem 0.5rem;
  text-align: center;
}

.reinas-stat-val {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--accent-primary);
}

.reinas-stat-lbl {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.reinas-share-preview {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0.85rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  white-space: pre;
  overflow-x: auto;
  text-align: center;
  margin-bottom: 1rem;
  line-height: 1.25;
}

.reinas-modal-actions {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.reinas-modal-actions .reinas-action-btn {
  flex: 1 1 140px;
}

.reinas-countdown-box {
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.86rem;
  color: var(--text-muted);
}

.reinas-countdown-val {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--text-main);
}

/* Toast suave */
.reinas-toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #0f172a;
  color: #f8fafc;
  border: 1px solid var(--accent-primary);
  padding: 0.65rem 1.15rem;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  z-index: 1500;
  transition: all 0.2s ease;
}

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

.reinas-help-list {
  margin: 0.75rem 0 0;
  padding-left: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  font-size: 0.92rem;
  color: var(--text-muted);
}

.reinas-help-list strong {
  color: var(--text-main);
}

/* Responsive móvil */
@media (max-width: 768px) {
  .reinas-card {
    padding: 1rem;
  }

  .reinas-quick-actions {
    width: 100%;
    justify-content: space-between;
  }

  .reinas-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .reinas-action-btn {
    flex: 1 1 calc(50% - 0.35rem);
  }

  .reinas-mode-segment {
    width: 100%;
    justify-content: space-between;
  }

  .mode-seg-btn {
    flex: 1 1 0;
    justify-content: center;
    padding: 0 0.45rem;
    font-size: 0.78rem;
  }

  .reinas-practice-bar .reinas-select,
  .reinas-practice-bar .reinas-action-btn {
    width: 100%;
  }
}
