/*
  GDE - Games de Escritorio
  Estilos globales y por juego. Temas claro/oscuro vía CSS custom properties.
  Responsive: desktop-first con breakpoints adaptativos.
  Autor: Desarrollo interno
*/

/* ============================================================
   RESET Y VARIABLES GLOBALES
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Skip-to-content link */
.skip-link {
  position: absolute;
  top: -100%;
  left: 0;
  background: var(--accent);
  color: #fff;
  padding: 8px 16px;
  z-index: 10000;
  font-size: 14px;
  transition: top 0.2s;
}
.skip-link:focus {
  top: 0;
}

/* Focus-visible global */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

:root {
  /* Tema Oscuro/Gamer (por defecto) */
  --bg-primary:        #07070d;
  --bg-secondary:      #0e0e1a;
  --bg-tertiary:       #16162a;
  --bg-elevated:       #1e1e34;
  --bg-hover:          #282844;
  --bg-overlay:        rgba(0, 0, 0, 0.65);

  --text-primary:      #e8e8f0;
  --text-secondary:    #9494a8;
  --text-muted:        #5c5c78;
  --text-on-accent:    #07070d;

  --accent:             #00d4ff;
  --accent-hover:       #33ddff;
  --accent-dim:         rgba(0, 212, 255, 0.10);
  --accent-secondary:   #a855f7;
  --accent-secondary-hover: #c084fc;
  --accent-tertiary:    #22d3a1;
  --accent-tertiary-hover: #4adeb3;

  --success:            #22d3a1;
  --danger:             #ff4060;
  --warning:            #f59e0b;

  --border-color:       #2a2a44;
  --border-accent:      #00d4ff;
  --border-subtle:      #1a1a2e;

  --shadow-sm:          0 2px 4px rgba(0, 0, 0, 0.4);
  --shadow-md:          0 4px 12px rgba(0, 0, 0, 0.5);
  --shadow-lg:          0 8px 24px rgba(0, 0, 0, 0.6);

  --glow-sm:            0 0 6px rgba(0, 212, 255, 0.15);
  --glow-md:            0 0 12px rgba(0, 212, 255, 0.25);
  --glow-lg:            0 0 24px rgba(0, 212, 255, 0.35);
  --glow-danger:        0 0 12px rgba(255, 64, 96, 0.4);
  --glow-success:       0 0 12px rgba(34, 211, 161, 0.4);
  --glow-secondary:     0 0 12px rgba(168, 85, 247, 0.4);

  --radius-sm:          4px;
  --radius-md:          8px;
  --radius-lg:          12px;
  --radius-xl:          16px;
  --radius-none:        0;
  --radius-2xl:         24px;
  --radius-full:        9999px;

  --font-size-xs:       0.7rem;
  --font-size-sm:       0.8rem;
  --font-size-base:     1rem;
  --font-size-md:       1.125rem;
  --font-size-lg:       1.25rem;
  --font-size-xl:       1.5rem;
  --font-size-2xl:      2rem;
  --font-size-3xl:      2.5rem;

  --font-normal:        400;
  --font-medium:        500;
  --font-semibold:      600;
  --font-bold:          700;

  --font:               'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono:          'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;

  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-8:  32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;
  --space-20: 80px;

  --sidebar-width:       230px;
  --sidebar-collapsed:   56px;
  --topbar-height:       44px;
  --transition:          0.25s ease;
  --transition-fast:     0.15s ease;
  --transition-slow:     0.4s ease;
}

/* Tema claro */
[data-theme="light"] {
  --bg-primary:        #f0f2f8;
  --bg-secondary:      #ffffff;
  --bg-tertiary:       #e8ecf4;
  --bg-elevated:       #ffffff;
  --bg-hover:          #dce0ec;
  --bg-overlay:        rgba(0, 0, 0, 0.35);

  --text-primary:      #0f1118;
  --text-secondary:    #3a3e50;
  --text-muted:        #6a6e80;
  --text-on-accent:    #ffffff;

  --accent:             #3b82f6;
  --accent-hover:       #2563eb;
  --accent-dim:         rgba(59, 130, 246, 0.08);
  --accent-secondary:   #8b5cf6;
  --accent-secondary-hover: #7c3aed;
  --accent-tertiary:    #10b981;
  --accent-tertiary-hover: #059669;

  --success:            #10b981;
  --danger:             #ef4444;
  --warning:            #f59e0b;

  --border-color:       #d0d5e0;
  --border-accent:      #3b82f6;
  --border-subtle:      #e5e9f0;

  --shadow-sm:          0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md:          0 4px 12px rgba(0, 0, 0, 0.1);
  --shadow-lg:          0 8px 24px rgba(0, 0, 0, 0.12);

  --glow-sm:            0 0 6px rgba(59, 130, 246, 0.12);
  --glow-md:            0 0 12px rgba(59, 130, 246, 0.18);
  --glow-lg:            0 0 20px rgba(59, 130, 246, 0.25);
  --glow-danger:        0 0 10px rgba(239, 68, 68, 0.3);
  --glow-success:       0 0 10px rgba(16, 185, 129, 0.3);

  /* Cards y paneles en tema claro: fondo blanco con borde sutil */
  [data-theme="light"] .game-card,
  [data-theme="light"] .modal-content,
  [data-theme="light"] .settings-panel {
    background: #ffffff;
    border: 1px solid #d0d5e0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  }
}

/* ============================================================
   BASE
   ============================================================ */
html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  margin: 0;
  overflow-x: hidden;
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ============================================================
   TOP BAR
   ============================================================ */
.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0 16px;
  z-index: 100;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  transition: background var(--transition), border-color var(--transition);
}

.menu-toggle,
.theme-toggle {
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.menu-toggle:hover,
.theme-toggle:hover {
  background: var(--bg-hover);
}

.app-title {
  flex: 1;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--accent);
}

/* ============================================================
   SIDE MENU
   ============================================================ */
.side-menu {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  padding-top: var(--topbar-height);
  display: flex;
  flex-direction: column;
  z-index: 200;
  transform: translateX(-100%);
  transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s ease, background var(--transition), border-color var(--transition);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.side-menu.open {
  transform: translateX(0);
}


.menu-list {
  list-style: none;
  padding: 4px;
  flex: 1;
  overflow-y: auto;
}

.menu-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
}
.menu-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.menu-link.active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: var(--font-semibold);
  border-left: 3px solid var(--accent);
  box-shadow: var(--glow-sm) inset;
}

/* Tooltips para sidebar colapsado (no expandido) */
.side-menu:not(.expanded) .menu-link {
  position: relative;
}
/* Solo en desktop */
@media (min-width: 768px) {
  .side-menu:not(.expanded) .menu-link:hover::after {
    content: attr(data-title);
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-left: 8px;
    padding: 4px 10px;
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 13px;
    white-space: nowrap;
    z-index: 1000;
    pointer-events: none;
  }
}

/* ============================================================
   GAME RULES
   ============================================================ */
.game-rules {
  margin-top: 6px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  max-width: 100%;
}
.game-rules summary {
  cursor: pointer;
  display: inline-block;
  padding: 3px 10px;
  border-radius: 99px;
  background: var(--bg-tertiary);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  transition: all var(--transition);
}
.game-rules summary:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.game-rules-content {
  padding: 8px 12px;
  margin-top: 6px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  line-height: 1.5;
  max-height: 200px;
  overflow-y: auto;
}
.game-rules-content p {
  margin-bottom: 6px;
}
.game-rules-content ul {
  padding-left: 20px;
  margin-bottom: 6px;
}
.game-rules-content li {
  margin-bottom: 2px;
}
.game-rules-content .example {
  display: inline-block;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 3px;
  padding: 2px 6px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  margin: 1px 0;
}

.menu-separator {
  list-style: none;
  padding: 6px 12px 2px;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  border-top: 1px solid var(--border-color);
  margin-top: 4px;
}
.menu-separator span {
  display: block;
}

.menu-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-top: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 0.75rem;
  gap: 8px;
}

.sidebar-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  transition: all var(--transition);
  line-height: 1;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
}
.sidebar-toggle:hover {
  color: var(--accent);
  background: var(--accent-dim);
}
.sidebar-toggle:active {
  transform: scale(0.9);
}
.menu-footer-text {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.menu-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0,0,0,0.4);
  z-index: 150;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.menu-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
#mainContent {
  margin-top: var(--topbar-height);
  min-height: calc(100vh - var(--topbar-height));
  transition: margin-left var(--transition);
}

.page {
  display: none;
  padding: 12px 12px;
  max-width: 1100px;
  margin: 0 auto;
  min-height: calc(100vh - var(--topbar-height));
  animation: fadeIn 0.3s ease;
  flex-direction: column;
}
.page.active {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px) translateZ(0); }
  to   { opacity: 1; transform: translateY(0) translateZ(0); }
}

/* Prevenir flickering en Safari/Brave durante animaciones */
.page, .game-panel, .modal-overlay, .canvas-container, .canvas-game-container {
  will-change: opacity;
}

/* ============================================================
   HOME / GAME GRID
   ============================================================ */
.home-header {
  text-align: center;
  margin-bottom: 32px;
}
.home-header h2 {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 8px;
}
.home-subtitle {
  color: var(--text-secondary);
  font-size: 1.05rem;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.game-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.game-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--glow-md);
  border-color: var(--border-accent);
}
.game-card:active {
  transform: translateY(-1px) scale(0.98);
  box-shadow: var(--glow-sm);
}
.game-card:focus-visible {
  box-shadow: var(--glow-md);
  border-color: var(--border-accent);
}

.game-card-icon {
  font-size: 2.2rem;
  margin-bottom: 12px;
}
.game-card h3 {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 8px;
}
.game-card p {
  color: var(--text-secondary);
  font-size: 0.88rem;
  line-height: 1.45;
  margin-bottom: 12px;
}
.game-card-tag {
  display: inline-block;
  background: var(--accent-dim);
  color: var(--accent);
  font-size: var(--font-size-xs);
  font-weight: var(--font-semibold);
  padding: 3px 10px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
}

/* Barra de categoría en game-card */
.game-card[data-category="logica"]    { border-top: 3px solid var(--accent); }
.game-card[data-category="estrategia"] { border-top: 3px solid var(--accent-secondary); }
.game-card[data-category="deduccion"]  { border-top: 3px solid var(--accent-tertiary); }
.game-card[data-category="aventura"]   { border-top: 3px solid var(--accent-secondary); }
.game-card[data-category="clasico"]    { border-top: 3px solid var(--accent); }
.game-card[data-category="arcade"]     { border-top: 3px solid var(--accent-tertiary); }

/* ============================================================
   GAME PAGE HEADER
   ============================================================ */
.game-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.game-header h2 {
  font-size: var(--font-size-lg);
  font-weight: var(--font-bold);
  flex: 1;
}
.game-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn:hover {
  background: var(--bg-hover);
}
.btn:active {
  transform: scale(0.97);
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
.btn-success {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}
.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-sm {
  padding: 5px 12px;
  font-size: 0.82rem;
}
.btn-back {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  padding: 6px 14px;
  font-size: 0.92rem;
  border-radius: var(--radius-md);
  transition: all var(--transition);
}
.btn-back:hover {
  color: var(--accent);
  border-color: var(--border-accent);
  background: var(--accent-dim);
  box-shadow: var(--glow-sm);
}
.btn-back:active {
  transform: scale(0.97);
}

/* ============================================================
   GAME CONTAINER COMÚN
   ============================================================ */
.game-container {
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 12px;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  transition: background var(--transition), border-color var(--transition);
  overflow-x: auto;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}

.game-msg {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 600;
  padding: 12px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  border: 1px solid transparent;
}
.game-msg.win {
  background: rgba(34, 211, 161, 0.10);
  color: var(--success);
  border-color: rgba(34, 211, 161, 0.2);
  box-shadow: var(--glow-success);
}
.game-msg.lose {
  background: rgba(255, 64, 96, 0.10);
  color: var(--danger);
  border-color: rgba(255, 64, 96, 0.2);
  box-shadow: var(--glow-danger);
}
.game-msg.info {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: rgba(0, 212, 255, 0.2);
  box-shadow: var(--glow-sm);
}
/* Animación de entrada para game-msg */
@keyframes msgPop {
  0% { opacity: 0; transform: scale(0.95); }
  50% { transform: scale(1.05); }
  100% { opacity: 1; transform: scale(1); }
}
.game-msg {
  animation: msgPop 0.3s ease;
}

.game-select {
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.88rem;
  cursor: pointer;
}
.game-select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ============================================================
   CANVAS GAMES (compartido)
   ============================================================ */
.canvas-game-container {
  text-align: center;
  padding: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.canvas-game-container canvas {
  display: block;
  margin: 0 auto;
  border-radius: var(--radius-sm);
  max-width: 100%;
  max-height: 65vh;
  width: auto;
  height: auto;
  image-rendering: pixelated;
}
.canvas-game-ui {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: center;
  margin: 10px 0;
  font-size: 0.9rem;
}
.canvas-game-ui .stat {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-weight: 600;
}
.canvas-game-ui .stat-value {
  font-family: var(--font-mono);
  color: var(--text-primary);
  font-size: 1.05rem;
}
.canvas-game-controls {
  margin-top: 8px;
  font-size: 0.82rem;
  color: var(--text-muted);
}
.canvas-game-controls kbd {
  display: inline-block;
  padding: 1px 6px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
}

/* Next piece preview (Tetris) */
.tetris-side {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-left: 12px;
  vertical-align: top;
}
.tetris-side canvas {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
}

/* ============================================================
   SUDOKU
   ============================================================ */
.sudoku-board {
  display: inline-grid;
  grid-template-columns: repeat(9, 1fr);
  border: 2px solid var(--border-color);
  user-select: none;
  max-width: 100%;
  overflow: auto;
}
.sudoku-cell {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  font-weight: 500;
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: background 0.15s;
  font-family: var(--font);
}
.sudoku-cell:hover {
  background: var(--bg-hover);
}
.sudoku-cell.given {
  font-weight: 700;
  color: var(--text-primary);
}
.sudoku-cell.user {
  color: var(--accent);
}
.sudoku-cell.selected {
  background: var(--accent-dim);
  box-shadow: inset 0 0 0 2px var(--accent), var(--glow-sm);
}
.sudoku-cell.error {
  color: var(--danger);
  background: rgba(239, 71, 111, 0.12);
}
.sudoku-cell.highlighted {
  background: var(--accent-dim);
}
.sudoku-cell.same-number {
  background: rgba(0, 212, 255, 0.15);
}
.sudoku-cell:nth-child(9n+1) {
  border-left: 2px solid var(--border-color);
}
.sudoku-cell:nth-child(9n) {
  border-right: 2px solid var(--border-color);
}
.sudoku-cell:nth-child(n+19):nth-child(-n+27) {
  border-bottom: 2px solid var(--border-color);
}
.sudoku-cell:nth-child(n+46):nth-child(-n+54) {
  border-bottom: 2px solid var(--border-color);
}
.sudoku-cell:nth-child(3n) {
  border-right: 2px solid var(--border-color);
}
.sudoku-cell:nth-child(3n+1) {
  border-left: 2px solid var(--border-color);
}
.sudoku-cell:nth-child(n+1):nth-child(-n+9) {
  border-top: 2px solid var(--border-color);
}
.sudoku-cell:nth-child(28),
.sudoku-cell:nth-child(29),
.sudoku-cell:nth-child(30),
.sudoku-cell:nth-child(31),
.sudoku-cell:nth-child(32),
.sudoku-cell:nth-child(33),
.sudoku-cell:nth-child(34),
.sudoku-cell:nth-child(35),
.sudoku-cell:nth-child(36) {
  border-top: 2px solid var(--border-color);
}
.sudoku-cell:nth-child(55),
.sudoku-cell:nth-child(56),
.sudoku-cell:nth-child(57),
.sudoku-cell:nth-child(58),
.sudoku-cell:nth-child(59),
.sudoku-cell:nth-child(60),
.sudoku-cell:nth-child(61),
.sudoku-cell:nth-child(62),
.sudoku-cell:nth-child(63) {
  border-top: 2px solid var(--border-color);
}

.sudoku-numpad {
  display: flex;
  gap: 6px;
  margin-top: 16px;
  flex-wrap: wrap;
  justify-content: center;
}
.sudoku-numpad button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}
.sudoku-numpad button:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}
.sudoku-numpad button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.sudoku-controls {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

/* ============================================================
   BUSCAMINAS
   ============================================================ */
.minesweeper-board {
  display: inline-grid;
  gap: 2px;
  user-select: none;
  touch-action: manipulation;
}
.ms-cell {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  font-weight: 700;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
  background: var(--bg-tertiary);
  border: 1px solid transparent;
}
.ms-cell:hover {
  background: var(--bg-hover);
  box-shadow: var(--glow-sm);
}
.ms-cell:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.ms-cell.revealed {
  background: var(--bg-secondary);
  border-color: var(--border-color);
  cursor: default;
}
.ms-cell.flag {
  background: rgba(245, 158, 11, 0.15);
  color: var(--warning);
}
.ms-cell.mine {
  background: var(--danger);
  color: #fff;
}
.ms-cell.mine-exploded {
  background: var(--danger);
  color: var(--text-on-accent);
}
.ms-cell.revealed.empty {
  background: var(--bg-secondary);
}
.ms-cell.revealed.n1 { color: #7ddb9e; }
.ms-cell.revealed.n2 { color: #7bccd4; }
.ms-cell.revealed.n3 { color: #f08a9b; }
.ms-cell.revealed.n4 { color: #e6c36a; }
.ms-cell.revealed.n5 { color: #e69a5e; }
.ms-cell.revealed.n6 { color: #5dd4c2; }
.ms-cell.revealed.n7 { color: #d0d5dd; }
.ms-cell.revealed.n8 { color: #8e95a3; }
[data-theme="light"] .ms-cell.revealed.n1 { color: #155724; }
[data-theme="light"] .ms-cell.revealed.n2 { color: #0c5460; }
[data-theme="light"] .ms-cell.revealed.n3 { color: #721c24; }
[data-theme="light"] .ms-cell.revealed.n4 { color: #533f03; }
[data-theme="light"] .ms-cell.revealed.n5 { color: #7a3b08; }
[data-theme="light"] .ms-cell.revealed.n6 { color: #117a65; }
[data-theme="light"] .ms-cell.revealed.n7 { color: #1b1b1b; }
[data-theme="light"] .ms-cell.revealed.n8 { color: #6c757d; }

.ms-stats {
  display: flex;
  gap: 20px;
  margin-bottom: 12px;
  font-size: 0.92rem;
  color: var(--text-secondary);
}
.ms-stat {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ============================================================
   NONOGRAMAS
   ============================================================ */
.nonogram-container {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.nonogram-wrapper {
  display: flex;
  align-items: flex-start;
}
.nonogram-col-clues {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  padding-right: 4px;
}
.nonogram-col-clues .col-clue {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 28px;
  padding: 1px 0;
}
.nonogram-row-clues {
  display: flex;
  align-items: center;
  padding-bottom: 4px;
}
.nonogram-row-clues .row-clue {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-align: right;
  padding: 0 4px;
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  white-space: nowrap;
}
.nonogram-board {
  display: inline-grid;
  gap: 1px;
  background: var(--border-color);
  border: 2px solid var(--border-color);
}
.nonogram-cell {
  width: 36px;
  height: 36px;
  background: var(--bg-secondary);
  cursor: pointer;
  transition: background 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  color: var(--text-muted);
}
.nonogram-cell:hover {
  background: var(--bg-hover);
}
.nonogram-cell.filled {
  background: var(--text-primary);
}
.nonogram-cell.cross {
  background: var(--bg-secondary);
}
.nonogram-cell.cross::after {
  content: '\2715';
  color: var(--text-muted);
  font-size: 0.8rem;
}
.nonogram-cell.completed {
  background: var(--success);
  opacity: 0.7;
}

/* ============================================================
   CAMPO MINADO LÓGICO
   ============================================================ */
.cml-board {
  display: inline-grid;
  gap: 3px;
  user-select: none;
}
.cml-cell {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  background: var(--bg-tertiary);
  border: 2px solid transparent;
}
.cml-cell:hover {
  background: var(--bg-hover);
}
.cml-cell.clue {
  background: var(--bg-secondary);
  border-color: var(--border-color);
  cursor: default;
}
.cml-cell.marked-mine {
  background: rgba(245, 158, 11, 0.15);
  border-color: var(--warning);
  color: var(--warning);
}
.cml-cell.marked-safe {
  background: rgba(34, 211, 161, 0.10);
  border-color: rgba(34, 211, 161, 0.3);
  color: var(--success);
}
.cml-cell.marked-mine.correct {
  background: rgba(34, 211, 161, 0.10);
  border-color: rgba(34, 211, 161, 0.3);
  color: var(--success);
}
.cml-cell.marked-mine.wrong {
  background: rgba(255, 64, 96, 0.10);
  border-color: rgba(255, 64, 96, 0.3);
  color: var(--danger);
}
.cml-cell.cm-error {
  background: rgba(255, 64, 96, 0.15) !important;
  border-color: rgba(255, 64, 96, 0.4) !important;
  color: var(--danger) !important;
}
.cml-cell.cm-correct {
  background: rgba(34, 211, 97, 0.15) !important;
  border-color: rgba(34, 211, 97, 0.4);
}

/* ============================================================
   LABERINTO
   ============================================================ */
.maze-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.maze-view {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border-color);
}
.maze-2d {
  display: grid;
  gap: 0;
}
.maze-cell {
  width: 100%;
  height: 100%;
}
.maze-wall {
  position: relative;
}
.maze-wall::before {
  content: '';
  position: absolute;
  background: var(--accent);
  opacity: 0.8;
}

/* 2D maze */
.maze-2d-cell {
  position: relative;
}
.maze-player {
  background: var(--accent) !important;
  border-radius: 50%;
  z-index: 2;
}
.maze-goal {
  background: var(--success) !important;
  border-radius: 3px;
  z-index: 1;
}
.maze-2d-wall-top { border-top: 2px solid var(--text-primary); }
.maze-2d-wall-right { border-right: 2px solid var(--text-primary); }
.maze-2d-wall-bottom { border-bottom: 2px solid var(--text-primary); }
.maze-2d-wall-left { border-left: 2px solid var(--text-primary); }

/* First-person view */
.maze-fp {
  width: 400px;
  height: 340px;
  position: relative;
  overflow: hidden;
  background: #1a1a2e;
  border-radius: var(--radius-sm);
}
.maze-fp-canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
}
.maze-fp-overlay {
  position: absolute;
  bottom: 12px;
  left: 0;
  right: 0;
  text-align: center;
  color: rgba(255,255,255,0.7);
  font-size: 0.8rem;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
  pointer-events: none;
}
.maze-controls-hint {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.82rem;
}
.maze-controls-hint kbd {
  display: inline-block;
  padding: 2px 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

/* ============================================================
   TRES EN LÍNEA
   ============================================================ */
.tictactoe-board {
  display: inline-grid;
  grid-template-columns: repeat(3, 100px);
  gap: 4px;
  background: var(--border-color);
  padding: 4px;
  border-radius: var(--radius-sm);
  margin: 0 auto;
}
.ttt-cell {
  width: 100px;
  height: 100px;
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
  border-radius: var(--radius-sm);
}
.ttt-cell:hover {
  background: var(--bg-hover);
}
.ttt-cell.x { color: var(--accent); }
.ttt-cell.o { color: var(--danger); }
.ttt-cell.win-cell {
  background: rgba(34, 211, 161, 0.15);
  box-shadow: var(--glow-success);
}

.ttt-score {
  display: flex;
  gap: 24px;
  margin: 12px 0;
  font-size: 0.95rem;
  color: var(--text-secondary);
}
.ttt-score span {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (min-width: 768px) {
  .side-menu {
    transform: translateX(0);
    box-shadow: none;
  }
  .side-menu:not(.open) {
    transform: translateX(0);
  }

  /* ── Estado colapsado por defecto (solo iconos) ── */
  .side-menu {
    width: var(--sidebar-collapsed);
  }
  .side-menu .menu-text,
  .side-menu .menu-separator,
  .side-menu .menu-footer-text {
    display: none;
  }
  .side-menu .menu-link {
    justify-content: center;
    padding: 6px 0;
    font-size: 1.15rem;
  }
  .side-menu .menu-icon {
    line-height: 1;
    font-size: 1.15rem;
  }
  .side-menu .menu-list {
    padding: 2px;
  }
  .side-menu .sidebar-toggle {
    font-size: 0.9rem;
    padding: 4px;
  }
  .side-menu .menu-footer {
    justify-content: center;
    padding: 6px;
  }

  /* ── Estado expandido ── */
  .side-menu.expanded {
    width: var(--sidebar-width);
  }
  .side-menu.expanded .menu-text,
  .side-menu.expanded .menu-separator,
  .side-menu.expanded .menu-footer-text {
    display: inline;
  }
  .side-menu.expanded .menu-link {
    justify-content: flex-start;
    padding: 7px 12px;
    gap: 10px;
    font-size: 0.9rem;
  }
  .side-menu.expanded .menu-icon {
    font-size: 1rem;
    width: 20px;
    text-align: center;
  }
  .side-menu.expanded .menu-footer {
    justify-content: flex-end;
    padding: 6px 12px;
  }
  .side-menu.expanded .sidebar-toggle {
    order: 1;
  }

  /* ── Hamburguesa oculta en desktop (el toggle está en sidebar) ── */
  .menu-toggle {
    display: none;
  }
  .menu-overlay {
    display: none;
  }

  /* ── Layout del contenido ── */
  #mainContent {
    margin-left: var(--sidebar-collapsed);
    transition: margin-left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  }
  .top-bar {
    left: var(--sidebar-collapsed);
    transition: left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  }
  body.sidebar-expanded #mainContent {
    margin-left: var(--sidebar-width);
  }
  body.sidebar-expanded .top-bar {
    left: var(--sidebar-width);
  }

  /* ── Hover temporal sobre colapsado ── */
  .side-menu:not(.expanded):hover {
    width: var(--sidebar-width);
    box-shadow: var(--shadow-lg);
    z-index: 210;
  }
  .side-menu:not(.expanded):hover .menu-text,
  .side-menu:not(.expanded):hover .menu-separator,
  .side-menu:not(.expanded):hover .menu-footer-text {
    display: inline;
  }
  .side-menu:not(.expanded):hover .menu-link {
    justify-content: flex-start;
    padding: 7px 12px;
    gap: 10px;
    font-size: 0.9rem;
  }
  .side-menu:not(.expanded):hover .menu-link .menu-icon {
    font-size: 1rem;
    width: 20px;
    text-align: center;
  }
  .side-menu:not(.expanded):hover .menu-footer {
    justify-content: flex-end;
    padding: 6px 12px;
  }
}

@media (max-width: 768px) {
  .key-hint,
  .keyboard-only {
    display: none !important;
  }
}

@media (max-width: 767px) {
  .page {
    padding: 16px 12px;
  }
  .game-grid {
    grid-template-columns: 1fr;
  }
  .sudoku-cell {
    width: 36px;
    height: 36px;
    font-size: 1rem;
  }
  .sudoku-numpad button {
    width: 40px;
    height: 40px;
  }
  .ms-cell {
    width: 36px;
    height: 36px;
    font-size: 0.85rem;
  }
  .nonogram-cell {
    width: 32px;
    height: 32px;
  }
  .tictactoe-board {
    grid-template-columns: repeat(3, 80px);
  }
  .ttt-cell {
    width: 80px;
    height: 80px;
    font-size: 2rem;
  }
  .maze-fp {
    width: 320px;
    height: 280px;
  }
}

@media (max-width: 480px) {
  .sudoku-numpad button {
    width: 40px;
    height: 40px;
    font-size: 16px;
  }
}

@media (max-width: 400px) {
  .sudoku-cell {
    width: 30px;
    height: 30px;
    font-size: 0.85rem;
  }
  .ms-cell {
    width: 28px;
    height: 28px;
    font-size: 0.75rem;
  }
  .cml-cell {
    width: 34px;
    height: 34px;
    font-size: 0.85rem;
  }
  .nonogram-cell {
    width: 28px;
    height: 28px;
  }
  .ttt-cell {
    width: 64px;
    height: 64px;
    font-size: 1.6rem;
  }
  .maze-fp {
    width: 280px;
    height: 240px;
  }
}

/* ============================================================
   SCROLLBAR PERSONALIZADO
   ============================================================ */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
