/* ==========================================================================
   Variables de Diseño y Temas
   ========================================================================== */
:root {
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --bg-gradient: linear-gradient(135deg, #0F172A 0%, #1E1B4B 50%, #0F172A 100%);
  --surface-card: rgba(30, 41, 59, 0.7);
  --surface-border: rgba(255, 255, 255, 0.1);
  --surface-accent: #6366F1;
  --surface-accent-hover: #4F46E5;
  --text-main: #F8FAFC;
  --text-muted: #94A3B8;

  /* Colores de Sudoku */
  --board-bg: #1E293B;
  --board-border: #334155;
  --board-border-thick: #818CF8;
  --cell-bg: #0F172A;
  --cell-text: #60A5FA;
  --cell-initial-text: #F8FAFC;
  --cell-selected: #4338CA;
  --cell-highlight-area: rgba(99, 102, 241, 0.18);
  --cell-highlight-same: rgba(129, 140, 248, 0.35);
  --cell-conflict-bg: rgba(239, 68, 68, 0.25);
  --cell-conflict-text: #F87171;
  --note-text: #A5B4FC;

  --btn-bg: #334155;
  --btn-bg-hover: #475569;
  --btn-text: #F8FAFC;
}

[data-theme="light"] {
  --bg-gradient: linear-gradient(135deg, #F1F5F9 0%, #E2E8F0 50%, #EEF2F6 100%);
  --surface-card: rgba(255, 255, 255, 0.85);
  --surface-border: rgba(0, 0, 0, 0.08);
  --surface-accent: #4F46E5;
  --surface-accent-hover: #4338CA;
  --text-main: #0F172A;
  --text-muted: #64748B;

  /* Colores Sudoku Claro */
  --board-bg: #FFFFFF;
  --board-border: #CBD5E1;
  --board-border-thick: #4F46E5;
  --cell-bg: #FFFFFF;
  --cell-text: #2563EB;
  --cell-initial-text: #0F172A;
  --cell-selected: #C7D2FE;
  --cell-highlight-area: #EEF2FF;
  --cell-highlight-same: #E0E7FF;
  --cell-conflict-bg: #FEE2E2;
  --cell-conflict-text: #DC2626;
  --note-text: #6366F1;

  --btn-bg: #E2E8F0;
  --btn-bg-hover: #CBD5E1;
  --btn-text: #1E293B;
}

/* ==========================================================================
   Reset y Layout Base (Optimizado TWA / Mobile first)
   ========================================================================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  font-family: var(--font-family);
  background: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text-main);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
}

.app-container {
  width: 100%;
  max-width: 480px;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   VISTA MENÚ / PORTADA
   ========================================================================== */
.menu-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 24px 20px 30px 20px;
  text-align: center;
  position: relative;
  min-height: 100%;
}

.menu-header {
  margin-top: 10px;
}

.brand-title {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #818CF8, #C084FC);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 6px;
}

.brand-subtitle {
  font-size: 0.95rem;
  color: var(--text-muted);
}

.menu-mascot-container {
  margin: 20px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.menu-options {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.btn-primary {
  width: 100%;
  padding: 16px;
  border-radius: 16px;
  border: none;
  background: linear-gradient(135deg, #6366F1, #8B5CF6);
  color: #FFFFFF;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 20px -5px rgba(99, 102, 241, 0.4);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.btn-primary:active {
  transform: scale(0.97);
}

.btn-secondary {
  width: 100%;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--surface-border);
  background: var(--surface-card);
  backdrop-filter: blur(10px);
  color: var(--text-main);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-secondary:active {
  transform: scale(0.97);
  background: var(--btn-bg-hover);
}

.infinite-level-badge {
  display: inline-block;
  margin-top: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 20px;
  background: rgba(139, 92, 246, 0.2);
  color: #C084FC;
  border: 1px solid rgba(139, 92, 246, 0.3);
}

/* ==========================================================================
   FIRMA CORPORATIVA LIBRE SERBERUS GAMES (Tal cual proyecto Arquerix)
   ========================================================================== */
.company-signature {
  position: absolute;
  bottom: 14px;
  right: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  padding: 0;
  box-shadow: none;
  backdrop-filter: none;
  z-index: 105;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.company-signature:hover {
  transform: scale(1.08) translateY(-2px);
}

.company-signature:active {
  transform: scale(0.95);
}

.signature-logo {
  height: clamp(48px, 7vh, 64px);
  width: auto;
  max-width: 180px;
  display: block;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.45));
  transition: filter 0.25s ease;
}

.company-signature:hover .signature-logo {
  filter: drop-shadow(0 8px 18px rgba(56, 189, 248, 0.7));
}

/* ==========================================================================
   VISTA JUEGO
   ========================================================================== */
.game-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 12px 14px;
  gap: 8px;
}

.game-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding-bottom: 4px;
}

.top-bar-left, .top-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--surface-border);
  background: var(--surface-card);
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  transition: all 0.15s ease;
}

.icon-btn:active {
  transform: scale(0.92);
}

.game-info {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.game-level-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
}

.game-rank-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.game-timer-badge {
  font-size: 0.85rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 4px 10px;
  border-radius: 10px;
  background: rgba(99, 102, 241, 0.15);
  color: #818CF8;
  border: 1px solid rgba(99, 102, 241, 0.25);
}

/* ==========================================================================
   MASCOTA BARNABY EN EL JUEGO
   ========================================================================== */
.game-mascot-row {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 85px;
  position: relative;
}

.mascot-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  transition: opacity 0.3s ease;
}

.mascot-wrapper.hidden-mascot {
  display: none !important;
}

.mascot-speech-bubble {
  position: absolute;
  top: -26px;
  background: var(--surface-card);
  backdrop-filter: blur(8px);
  color: var(--text-main);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid var(--surface-border);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  white-space: nowrap;
  z-index: 20;
}

.mascot-speech-bubble.visible {
  opacity: 1;
  transform: translateY(0);
}

.mascot-speech-bubble::after {
  content: '';
  position: absolute;
  bottom: -5px;
  left: 50%;
  transform: translateX(-50%);
  border-width: 5px 5px 0 5px;
  border-style: solid;
  border-color: var(--surface-card) transparent transparent transparent;
}

.owl-svg {
  filter: drop-shadow(0 6px 12px rgba(139, 92, 246, 0.35));
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  animation: kawaiiFloat 3s ease-in-out infinite alternate;
}

@keyframes kawaiiFloat {
  0% { transform: translateY(0px) rotate(0deg); }
  50% { transform: translateY(-4px) rotate(1.5deg); }
  100% { transform: translateY(0px) rotate(0deg); }
}

.owl-head-body {
  transform-origin: 80px 100px;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.owl-eyelid {
  opacity: 0;
  transition: opacity 0.1s ease;
}

.owl-eyelid.blink {
  opacity: 1;
}

/* Animaciones del Búho Barnaby */
.anim-head-tilt-left {
  transform: rotate(-25deg);
}

.anim-head-tilt-right {
  transform: rotate(25deg);
}

.anim-glasses-push {
  transform: translateY(-4px) scale(1.05);
}

/* Alas de Barnaby: origen de rotación en los hombros */
.owl-wing.wing-left {
  transform-origin: 52px 76px;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.owl-wing.wing-right {
  transform-origin: 108px 76px;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.anim-flap .wing-left {
  animation: flapLeft 0.28s ease-in-out infinite alternate !important;
}

.anim-flap .wing-right {
  animation: flapRight 0.28s ease-in-out infinite alternate !important;
}

@keyframes flapLeft {
  0% { transform: rotate(0deg) scaleX(1); }
  100% { transform: rotate(-55deg) scaleX(1.15) translateY(-6px); }
}

@keyframes flapRight {
  0% { transform: rotate(0deg) scaleX(1); }
  100% { transform: rotate(55deg) scaleX(1.15) translateY(-6px); }
}

.anim-stare {
  transform: scale(1.1) translateY(-2px);
}

.anim-twist {
  animation: owlSpin 0.9s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes owlSpin {
  0% { transform: scale(1) rotate(0deg); }
  50% { transform: scale(0.9) rotate(180deg); }
  100% { transform: scale(1) rotate(360deg); }
}

.anim-bounce {
  animation: mascotHop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes mascotHop {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-16px); }
}

.anim-gentle-breathe {
  animation: owlBreathe 1.5s ease-in-out;
}

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

.anim-victory {
  animation: victoryDance 1s ease-in-out infinite alternate;
}

.anim-victory .wing-left {
  animation: flapLeft 0.35s ease-in-out infinite alternate !important;
}

.anim-victory .wing-right {
  animation: flapRight 0.35s ease-in-out infinite alternate !important;
}

.anim-bounce .wing-left {
  animation: flapLeft 0.22s ease-in-out 2 alternate !important;
}

.anim-bounce .wing-right {
  animation: flapRight 0.22s ease-in-out 2 alternate !important;
}

@keyframes victoryDance {
  0% { transform: translateY(0) rotate(-10deg); }
  100% { transform: translateY(-12px) rotate(10deg); }
}

.anim-defeat {
  transform: translateY(6px) rotate(5deg);
  opacity: 0.85;
}

/* ==========================================================================
   TABLERO SUDOKU 9x9 (Grid Layout Perfecto)
   ========================================================================== */
.board-container {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: flex;
  justify-content: center;
  align-items: center;
}

.sudoku-grid {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  background: var(--board-border);
  border: 3px solid var(--board-border-thick);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
  gap: 1px;
}

.sudoku-cell {
  background: var(--cell-bg);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.12s ease;
}

.sudoku-cell.border-right-thick {
  border-right: 2px solid var(--board-border-thick) !important;
}

.sudoku-cell.border-bottom-thick {
  border-bottom: 2px solid var(--board-border-thick) !important;
}

/* Tintes sutiles de fondo para distinguir cada área irregular */
.sudoku-cell.jigsaw-region-0 { background: rgba(99, 102, 241, 0.08); }
.sudoku-cell.jigsaw-region-1 { background: rgba(236, 72, 153, 0.08); }
.sudoku-cell.jigsaw-region-2 { background: rgba(16, 185, 129, 0.08); }
.sudoku-cell.jigsaw-region-3 { background: rgba(245, 158, 11, 0.08); }
.sudoku-cell.jigsaw-region-4 { background: rgba(139, 92, 246, 0.08); }
.sudoku-cell.jigsaw-region-5 { background: rgba(14, 165, 233, 0.08); }
.sudoku-cell.jigsaw-region-6 { background: rgba(244, 63, 94, 0.08); }
.sudoku-cell.jigsaw-region-7 { background: rgba(20, 184, 166, 0.08); }
.sudoku-cell.jigsaw-region-8 { background: rgba(234, 179, 8, 0.08); }

.cell-value {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--cell-text);
  line-height: 1;
  transition: transform 0.1s ease;
}

.cell-value.tile-icon-display {
  font-size: 1.35rem;
  animation: tilePop 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

@keyframes tilePop {
  0% { transform: scale(0.6) rotate(-15deg); }
  100% { transform: scale(1) rotate(0deg); }
}

.sudoku-cell.initial .cell-value {
  font-weight: 800;
  color: var(--cell-initial-text);
}

/* Estados de Resaltado Configurable */
.sudoku-cell.highlight-area {
  background: var(--cell-highlight-area);
}

.sudoku-cell.highlight-same {
  background: var(--cell-highlight-same);
}

.sudoku-cell.selected {
  background: var(--cell-selected) !important;
}

.sudoku-cell.conflict {
  background: var(--cell-conflict-bg) !important;
}

.sudoku-cell.conflict .cell-value {
  color: var(--cell-conflict-text) !important;
}

/* Micro-Notas (Pencil Marks) */
.notes-grid {
  position: absolute;
  inset: 2px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  pointer-events: none;
}

.note-item {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--note-text);
  line-height: 1;
}

/* ==========================================================================
   BOTONES DE ACCIÓN (Deshacer, Borrar, Notas, Pista)
   ========================================================================== */
.game-controls-row {
  display: flex;
  justify-content: space-around;
  width: 100%;
  padding: 4px 0;
}

.action-tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 600;
  transition: all 0.15s ease;
}

.action-tool-btn .btn-icon-bubble {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--surface-card);
  border: 1px solid var(--surface-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  color: var(--text-main);
  transition: all 0.15s ease;
}

.action-tool-btn:active .btn-icon-bubble {
  transform: scale(0.92);
}

.action-tool-btn.active-tool .btn-icon-bubble {
  background: var(--surface-accent);
  color: #FFFFFF;
  border-color: transparent;
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.5);
}

.action-tool-btn.active-tool {
  color: var(--surface-accent);
}

/* ==========================================================================
   TECLADO NUMÉRICO (Numpad 1-9)
   ========================================================================== */
.numpad-container {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 5px;
  width: 100%;
  padding-bottom: 6px;
}

.numpad-btn {
  aspect-ratio: 1 / 1.15;
  border-radius: 10px;
  border: 1px solid var(--surface-border);
  background: var(--surface-card);
  backdrop-filter: blur(8px);
  color: var(--text-main);
  font-size: 1.35rem;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: all 0.15s ease;
}

.numpad-btn:active {
  transform: scale(0.92);
  background: var(--surface-accent);
  color: #FFFFFF;
}

.numpad-btn .num-badge {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-top: -2px;
}

.numpad-btn.completed {
  opacity: 0.35;
  pointer-events: none;
}

/* ==========================================================================
   MODALES (Ajustes, Pausa, Victoria, Derrota, Dificultad)
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

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

.modal-content {
  background: var(--board-bg);
  border: 1px solid var(--surface-border);
  border-radius: 20px;
  width: 100%;
  max-width: 380px;
  padding: 24px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
  transform: scale(0.92);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-overlay.active .modal-content {
  transform: scale(1);
}

.modal-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-main);
  text-align: center;
}

.settings-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 8px 0;
}

.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.95rem;
  color: var(--text-main);
}

.setting-item span {
  font-weight: 500;
}

/* Switches estilo iOS */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: var(--btn-bg);
  transition: 0.25s;
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.25s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--surface-accent);
}

input:checked + .slider:before {
  transform: translateX(20px);
}

.select-control {
  background: var(--surface-card);
  color: var(--text-main);
  border: 1px solid var(--surface-border);
  padding: 6px 12px;
  border-radius: 10px;
  font-size: 0.9rem;
}

/* Modales Victoria / Derrota */
.modal-mascot-celebrate {
  display: flex;
  justify-content: center;
  margin: 10px 0;
}

.stats-desc {
  font-size: 0.95rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.4;
}
