/**
 * =============================================================================
 *  67DLE - Hoja de Estilos Principal (CSS)
 * =============================================================================
 * Estructura del archivo:
 * 1. Variables de Tema (Modo Oscuro Carbón Neutro & Modo Claro Tiza Mate)
 * 2. Reset y Estilos Globales
 * 3. Contenedor Principal (App Layout)
 * 4. Encabezado y Selector de Tema (Switch iOS)
 * 5. Navegación (Categorías, Modos y Fechas Diarias)
 * 6. Objetivo (Target) y Mensajes de Estado
 * 7. Tablero de Juego (Casilleros / Tiles)
 * 8. Historial de Intentos (Scroll con Máscara de Transparencia)
 * 9. Teclado Interactivo (Estándar y Dinámico Ordena 67)
 * 10. Modales (Fin de Juego y Calendario Mensual)
 * 11. Adaptabilidad y Media Queries (Móviles y Pantallas Bajas)
 * =============================================================================
 */

/* =============================================================================
   1. VARIABLES DE TEMA (DARK / LIGHT)
   ============================================================================= */

:root {
  --space: clamp(8px, 2vmin, 20px);
  --gap: clamp(4px, 1.2vmin, 8px);

  /* MODO OSCURO (Alto Contraste y Legibilidad en Pantallas OLED/Móviles) */
  --bg-app: #121214;
  --bg-card: #222226;
  --bg-card-sub: #2a2a30;
  --bg-tile: #202024;
  --bg-key: #2d2e35;
  --bg-key-locked: #18181c;
  --bg-stats: #18181c;
  --bg-cal-day: #26262c;
  --bg-modal-overlay: rgba(0, 0, 0, 0.85);

  --text-main: #ffffff;
  --text-sub: #c4c4cc;
  --text-label: #e2e2e8;
  --text-muted: #848490;
  --text-key: #ffffff;

  --border-main: #4a4a56;
  --border-subtle: #34343e;
  --border-dashed: #50505c;
  --border-filled: #9c9ca8;
  --key-active: #3a3a44;

  /* Acentos Vivos y Nítidos */
  --green: #4ade80;        /* Verde menta/esmeralda pastel brillante */
  --blue: #60a5fa;         /* Azul cielo pastel brillante */
  --red: #f87171;          /* Rosa coral pastel */
  --yellow: #fbbf24;       /* Ámbar pastel */

  /* Tipografías Modernas */
  --font-ui: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", "Segoe UI Mono", Menlo, Monaco, Consolas, "Courier New", monospace;
}

[data-theme="light"],
html.light-mode,
body.light-mode,
html[data-theme="light"] body {
  /* MODO CLARO (100% Grises Neutros y Blanco Puro - Sin Tinte Azul ni Celeste) */
  --bg-app: #e5e5e5;
  --bg-card: #ffffff;
  --bg-card-sub: #f4f4f4;
  --bg-tile: #ffffff;
  --bg-key: #ffffff;
  --bg-key-locked: #e8e8e8;
  --bg-stats: #eeeeee;
  --bg-cal-day: #ffffff;
  --bg-modal-overlay: rgba(0, 0, 0, 0.7);

  --text-main: #171717;
  --text-sub: #525252;
  --text-label: #262626;
  --text-muted: #737373;
  --text-key: #171717;

  --border-main: #666666;
  --border-subtle: #888888;
  --border-dashed: #666666;
  --border-filled: #171717;
  --key-active: #d4d4d4;

  /* Acentos de Alto Contraste para Modo Claro */
  --green: #16a34a;        /* Verde nítido de alto contraste */
  --blue: #2563eb;         /* Azul vibrante para foco/cursor */
  --red: #dc2626;          /* Rojo de error */
  --yellow: #ca8a04;       /* Ámbar de advertencia */
}


/* =============================================================================
   2. RESET Y ESTILOS GLOBALES
   ============================================================================= */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--font-ui);
  -webkit-tap-highlight-color: transparent;
}

html {
  background-color: var(--bg-app);
  color: var(--text-main);
  overflow-x: hidden;
  overflow-y: auto;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--bg-app);
  color: var(--text-main);
  display: flex;
  flex-direction: column;
  align-items: center;
  user-select: none;
  -webkit-user-select: none;
  transition: background-color 0.25s ease, color 0.25s ease;
}

button,
.keyboard-wrapper,
.tile {
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.hidden {
  display: none !important;
}


/* =============================================================================
   3. CONTENEDOR PRINCIPAL (APP LAYOUT)
   ============================================================================= */

.app-container {
  width: 100%;
  height: 100dvh;
  max-width: 600px;
  padding: var(--space) clamp(8px, 2.5vw, 16px);
  padding-top: calc(clamp(6px, 1.2vh, 12px) + env(safe-area-inset-top, 0px));
  padding-bottom: calc(clamp(6px, 1.2vh, 12px) + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: clamp(2px, 0.8vh, 8px);
  overflow: hidden;
  position: relative;
  flex-shrink: 0;
}

header {
  width: 100%;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(4px, 1vh, 10px);
  position: relative;
  padding-top: clamp(28px, 4vh, 38px);
}

@media (min-width: 620px) {
  header {
    padding-top: 0;
  }
}

.top-left-controls {
  position: fixed !important;
  top: calc(clamp(10px, 1.8vh, 18px) + env(safe-area-inset-top, 0px));
  left: calc(clamp(12px, 2vw, 22px) + env(safe-area-inset-left, 0px));
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: clamp(8px, 1.5vw, 12px);
}

.top-controls-container,
.theme-switch-container {
  position: fixed !important;
  top: calc(clamp(10px, 1.8vh, 18px) + env(safe-area-inset-top, 0px));
  right: calc(clamp(12px, 2vw, 22px) + env(safe-area-inset-right, 0px));
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: clamp(8px, 1.5vw, 12px);
}

.btn-sound-toggle,
.btn-top-info {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 32px;
  background: var(--bg-card-sub);
  border: 1.5px solid var(--border-main);
  border-radius: 32px;
  color: var(--text-main);
  cursor: pointer;
  padding: 0;
  text-decoration: none;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.btn-sound-toggle:focus,
.btn-top-info:focus {
  outline: none;
}

.btn-sound-toggle:focus:not(:focus-visible),
.btn-top-info:focus:not(:focus-visible) {
  outline: none;
}

.btn-sound-toggle:focus-visible,
.btn-top-info:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

@media (hover: hover) and (pointer: fine) {
  .btn-sound-toggle:hover,
  .btn-top-info:hover {
    border-color: var(--blue);
    color: var(--blue);
    transform: scale(1.05);
  }

  .btn-sound-toggle.muted:hover {
    opacity: 1;
    color: var(--text-sub);
    border-color: var(--border-main);
  }
}

.btn-sound-toggle:active,
.btn-top-info:active {
  transform: scale(0.94);
}

.btn-sound-toggle.muted {
  color: var(--text-muted);
  border-color: var(--border-subtle);
  opacity: 0.75;
}

h1 {
  font-family: var(--font-mono);
  color: var(--text-main);
  font-size: clamp(1.45rem, 4.4vmin, 2.3rem);
  font-weight: 800;
  letter-spacing: 3px;
  margin: 0;
  line-height: 1.1;
}

.subtitle {
  width: 100%;
  max-width: 540px;
  min-height: clamp(24px, 3vh, 32px);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-sub);
  font-size: clamp(.7rem, 1.7vmin, .84rem);
  text-align: center;
  line-height: 1.25;
  margin: 0;
  padding: 0 4px;
}

.ios-switch {
  position: relative;
  display: inline-block;
  width: 58px;
  height: 32px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.ios-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
  margin: 0;
}

.ios-switch-slider {
  position: absolute;
  inset: 0;
  background-color: #1c1c21;
  border: 2px solid #3f3f46;
  border-radius: 32px;
  transition: background-color 0.28s cubic-bezier(0.4, 0, 0.2, 1), border-color 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.4);
}

.ios-switch-icons {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 7px;
  pointer-events: none;
}

.ios-switch-icons .icon-moon {
  color: #71717a;
  opacity: 0.95;
  transition: opacity 0.22s ease, color 0.22s ease;
}
.ios-switch-icons .icon-sun {
  color: #fbbf24;
  opacity: 0.95;
  transition: opacity 0.22s ease, color 0.22s ease;
}

.ios-switch-knob {
  position: absolute;
  left: 3px;
  width: 22px;
  height: 22px;
  background-color: #ffffff;
  border-radius: 50%;
  transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.2s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35), 0 0 1px rgba(0, 0, 0, 0.2);
}

/* Estado activo del switch (Modo Claro) */
.ios-switch input:checked + .ios-switch-slider,
[data-theme="light"] .ios-switch-slider,
.light-mode .ios-switch-slider {
  background-color: #10b981;
  border-color: #059669;
  box-shadow: inset 0 1px 3px rgba(5, 150, 105, 0.3);
}

.ios-switch input:checked + .ios-switch-slider .ios-switch-knob,
[data-theme="light"] .ios-switch-knob,
.light-mode .ios-switch-knob {
  transform: translateX(26px);
  background-color: #ffffff;
}

.ios-switch input:checked + .ios-switch-slider .icon-moon,
[data-theme="light"] .icon-moon,
.light-mode .icon-moon {
  color: #022c22;
  opacity: 0.45;
}

.ios-switch input:checked + .ios-switch-slider .icon-sun,
[data-theme="light"] .icon-sun,
.light-mode .icon-sun {
  color: #fbbf24;
  opacity: 1;
}

.ios-switch:hover .ios-switch-slider {
  filter: brightness(1.06);
}

/* =============================================================================
   5. BOTONES DE NAVEGACIÓN Y SELECTOR DE FECHAS
   ============================================================================= */

.nav-categories {
  display: flex;
  justify-content: center;
  gap: 8px;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
}

.nav-modes {
  display: flex;
  justify-content: center;
  gap: 8px;
  width: 100%;
  max-width: 320px;
  margin: 0 auto;
}

.tab-btn,
.btn-primary,
.btn-secondary {
  cursor: pointer;
  font-weight: 700;
  border-radius: 6px;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.08s ease;
}

.tab-btn {
  height: clamp(34px, 4.5vmin, 38px);
  min-height: clamp(34px, 4.5vmin, 38px);
  max-height: clamp(34px, 4.5vmin, 38px);
  box-sizing: border-box;
  padding: 0 clamp(10px, 2.2vmin, 16px);
  background: var(--bg-card-sub);
  border: 1.5px solid var(--border-main);
  border-radius: 6px;
  color: var(--text-sub);
  font-size: clamp(.72rem, 1.9vmin, .86rem);
  font-weight: 700;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  white-space: nowrap;
}

.nav-categories .tab-btn {
  flex: 1 1 0;
  min-width: 0;
}

.nav-modes > #btn-random {
  flex: 1 1 0;
  min-width: 0;
  max-width: 154px;
  height: clamp(34px, 4.5vmin, 38px);
  min-height: clamp(34px, 4.5vmin, 38px);
  max-height: clamp(34px, 4.5vmin, 38px);
}

.daily-stepper-btn {
  flex: 1 1 0;
  min-width: 0;
  max-width: 154px;
  height: clamp(34px, 4.5vmin, 38px);
  min-height: clamp(34px, 4.5vmin, 38px);
  max-height: clamp(34px, 4.5vmin, 38px);
  box-sizing: border-box;
  padding: 0 4px !important;
  display: inline-flex;
  align-items: stretch;
  justify-content: space-between;
  background: var(--bg-card-sub);
  border: 1.5px solid var(--border-main);
  border-radius: 6px;
  color: var(--text-sub);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.tab-btn.active,
.daily-stepper-btn.active,
.nav-modes > #btn-random.active {
  background: var(--bg-card-sub);
  color: var(--green);
  border-color: var(--green);
  box-shadow: 0 0 0 1px var(--green), 0 2px 5px rgba(0, 0, 0, 0.15);
}

@media (hover: hover) and (pointer: fine) {
  .tab-btn:hover:not(.active),
  .daily-stepper-btn:hover:not(.active),
  .nav-modes > #btn-random:hover:not(.active) {
    border-color: var(--text-muted);
    color: var(--text-main);
  }
}

.stepper-arrow-btn {
  background: transparent;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: 0 6px;
  font-size: 0.72rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  transition: color 0.15s ease, transform 0.1s ease;
}

@media (hover: hover) and (pointer: fine) {
  .stepper-arrow-btn:hover:not(:disabled) {
    transform: scale(1.15);
  }
}

.stepper-arrow-btn:active:not(:disabled) {
  transform: scale(0.92);
}

.stepper-arrow-btn:disabled {
  opacity: 0.18;
  cursor: not-allowed;
}

.stepper-label-btn {
  background: transparent;
  border: none;
  color: inherit;
  cursor: pointer;
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  padding: 0 2px;
  font-size: clamp(.72rem, 1.9vmin, .86rem);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  white-space: nowrap;
  transition: color 0.15s ease;
}


/* =============================================================================
   6. OBJETIVO (TARGET) Y MENSAJES DE ESTADO
   ============================================================================= */

.target-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.target-group {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  gap: 6px;
  height: clamp(36px, 5vmin, 42px);
}

.target-container {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  box-sizing: border-box;
  gap: 8px;
  padding: 0 clamp(12px, 2.5vmin, 18px);
  background: var(--bg-card);
  border: 1.5px solid var(--border-subtle);
  border-radius: 6px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.target-label {
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: clamp(.78rem, 2vmin, .88rem);
  font-weight: 700;
  letter-spacing: 0.6px;
  line-height: 1;
  text-transform: uppercase;
  margin: 0;
  padding: 0;
}

.target-display {
  color: var(--green);
  font-family: var(--font-mono);
  font-size: clamp(1.15rem, 3.2vmin, 1.35rem);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  margin: 0;
  padding: 0;
}

.btn-reroll-square {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  aspect-ratio: 1 / 1;
  box-sizing: border-box;
  padding: 0;
  background: var(--bg-card-sub);
  border: 1.5px solid var(--border-subtle);
  border-radius: 5px;
  color: var(--text-sub);
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

@media (hover: hover) and (pointer: fine) {
  .btn-reroll-square:hover {
    color: var(--green);
    border-color: var(--green);
  }
}

.btn-reroll-square .reroll-icon-svg {
  display: block;
  width: clamp(14px, 3.2vmin, 16px);
  height: clamp(14px, 3.2vmin, 16px);
  stroke: currentColor;
  pointer-events: none;
  transform-origin: center center;
}

.btn-reroll-square.is-spinning .reroll-icon-svg {
  animation: reroll-spin 0.45s cubic-bezier(0.25, 1, 0.5, 1);
}

@keyframes reroll-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.btn-reroll-square.hidden {
  display: none !important;
}

.message-banner {
  height: 0;
  min-height: 0;
  overflow: visible;
  display: flex;
  justify-content: center;
  align-items: center;
  padding-top: clamp(8px, 1.5vh, 14px);
  font-size: clamp(.75rem, 2vmin, .95rem);
  font-weight: bold;
  text-align: center;
  pointer-events: none;
  z-index: 50;
}


/* =============================================================================
   7. TABLERO DE CASILLEROS (TILES)
   ============================================================================= */

.board-wrapper {
  width: 100%;
  min-height: 0;
  flex: 1 1 auto;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0;
  margin: 0;
}

.board-area {
  width: 100%;
  max-width: min(640px, 92vmin);
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: clamp(8px, 2vh, 18px);
}

.board {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(var(--board-columns, 10), minmax(0, 1fr));
  gap: var(--gap);
}

.tile {
  aspect-ratio: 1 / 1.1;
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--bg-tile);
  border: 2px solid var(--border-main);
  border-radius: 4px;
  color: var(--text-main);
  font-size: clamp(1.1rem, 4vmin, 1.8rem);
  font-weight: bold;
  cursor: pointer;
  transition: border-color .12s ease, transform .12s ease, background-color .12s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06);
}

.tile.filled {
  border-color: var(--border-filled);
  transform: scale(1.02);
}

.tile.cursor {
  border-color: var(--blue);
  box-shadow: 0 0 0 1px var(--blue);
}

.tile.correct {
  border-color: var(--green) !important;
  color: var(--green) !important;
}

.tile.absent {
  border-color: var(--red) !important;
  color: var(--red) !important;
  animation: shake 0.35s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-4px); }
  40%, 80% { transform: translateX(4px); }
}


/* =============================================================================
   7.1 TABLERO DE CRUCIGRAMA 67 (CROSSWORD 67)
   ============================================================================= */

.crossword-board {
  width: 100%;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(2px, 0.8vh, 8px) 0 clamp(8px, 1.8vh, 16px) 0;
}

.crossword-grid {
  width: min(330px, 80vw, 30vh);
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-template-rows: repeat(5, minmax(0, 1fr));
  gap: clamp(3px, 0.8vmin, 5px);
  background: #18181c;
  padding: clamp(4px, 1vmin, 7px);
  border-radius: 8px;
  border: 1.5px solid var(--border-main);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
  margin-bottom: clamp(6px, 1.5vh, 14px);
}

[data-theme="light"] .crossword-grid,
.light-mode .crossword-grid {
  background: #e5e5e5;
  border-color: var(--border-main);
}

.cw-cell {
  width: 100%;
  height: 100%;
  aspect-ratio: 1 / 1;
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--bg-card);
  border: 1.5px solid var(--border-main);
  border-radius: 4px;
  color: var(--text-main);
  font-size: clamp(1.15rem, 4.5vmin, 1.85rem);
  font-weight: bold;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}

[data-theme="light"] .cw-cell,
.light-mode .cw-cell {
  background: #ffffff;
  border: 1.5px solid var(--border-main);
  color: #111111;
}

@media (hover: hover) and (pointer: fine) {
  .cw-cell:hover:not(.cw-clue):not(.cw-block) {
    border-color: var(--blue);
  }
}

.cw-cell.cw-active {
  border-color: var(--blue) !important;
  box-shadow: 0 0 0 2px var(--blue);
}

.cw-cell.cw-clue,
.cw-cell.cw-block {
  background: #28282e !important;
  border: none !important;
  border-radius: 4px;
  color: #ffffff !important;
  cursor: default;
  font-weight: bold;
  pointer-events: none;
}

[data-theme="light"] .cw-cell.cw-clue,
[data-theme="light"] .cw-cell.cw-block,
.light-mode .cw-cell.cw-clue,
.light-mode .cw-cell.cw-block {
  background: #d4d4d8 !important;
  border: none !important;
  color: #171717 !important;
}

.cw-cell.cw-correct:not(.cw-clue):not(.cw-block) {
  border-color: var(--green) !important;
  color: var(--green) !important;
}

.cw-cell.cw-clue.cw-flash-success {
  color: var(--green) !important;
  transition: color 0.3s ease;
}


/* =============================================================================
   8. HISTORIAL DE INTENTOS (SCROLL CON MÁSCARA)
   ============================================================================= */

.history {
  position: relative;
  width: 100%;
  height: clamp(46px, 12vmin, 100px);
  min-height: 0;
  flex: 0 0 auto;
  overflow: hidden;
  padding-top: 2px;
}

.history-list {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(4px, 1.2vmin, 6px);
  height: 100%;
  overflow-y: auto;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(to bottom, black 70%, transparent 100%);
  mask-image: linear-gradient(to bottom, black 70%, transparent 100%);
}


.history-entry {
  width: min(240px, 82%);
  min-height: clamp(28px, 5vmin, 38px);
  margin-left: auto;
  margin-right: auto;
  padding: 4px 8px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 20px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-main);
  border-radius: 6px;
  color: var(--red);
  font-size: clamp(.72rem, 2vmin, .9rem);
}

.history-entry + .history-entry {
  margin-top: var(--gap);
}

.history-expression {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  justify-self: center;
  text-align: center;
}

.history-result {
  flex-shrink: 0;
  justify-self: center;
  text-align: center;
  color: var(--text-sub);
}

.history-entry-correct {
  color: var(--red);
}

.history-entry-correct .history-expression {
  color: var(--green);
}

.history-equals {
  display: block;
  justify-self: center;
  color: var(--text-label);
  font-weight: bold;
  text-align: center;
}


/* =============================================================================
   9. TECLADO EN PANTALLA
   ============================================================================= */

.keyboard-wrapper {
  width: 100%;
  max-width: 480px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: clamp(6px, 1.2vh, 10px);
}

.keyboard-row {
  display: flex;
  gap: var(--gap);
  width: 100%;
}

.keyboard-row.available-row {
  display: flex;
  justify-content: center;
  gap: var(--gap);
  width: 100%;
}

.keyboard-row.available-row .key {
  flex: 1 1 0;
  max-width: 60px;
  min-height: 40px;
  height: clamp(40px, 6vh, 52px);
  font-size: clamp(1rem, 3.2vmin, 1.3rem);
}

.key {
  cursor: pointer;
  flex: 1;
  min-height: 38px;
  height: clamp(38px, 5.8vh, 48px);
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--bg-key);
  border: 1.5px solid var(--border-main);
  border-radius: 5px;
  color: var(--text-key);
  font-size: clamp(0.95rem, 3.2vmin, 1.25rem);
  font-weight: bold;
  box-shadow: 0 2px 0 var(--border-subtle);
  outline: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.08s ease, box-shadow 0.08s ease;
}

.key:focus,
.key:focus-visible {
  outline: none;
}

@media (hover: hover) and (pointer: fine) {
  .key:hover:not(:disabled):not(.key-locked) {
    background: var(--bg-card-sub);
    border-color: var(--text-label);
  }

  [data-theme="light"] .key:hover:not(:disabled):not(.key-locked),
  .light-mode .key:hover:not(:disabled):not(.key-locked) {
    background: #d8d8d8;
    border-color: #171717;
    color: #000000;
  }

  [data-theme="light"] .key.op:hover:not(:disabled):not(.key-locked),
  .light-mode .key.op:hover:not(:disabled):not(.key-locked) {
    color: var(--blue);
  }
}

.key.op {
  color: var(--blue);
  font-weight: bold;
}

.key.action-key {
  flex: 1.5;
  font-size: clamp(0.85rem, 2.8vmin, 1.05rem);
  font-weight: bold;
  background: var(--bg-card-sub);
}

.key:active {
  background: var(--key-active);
  transform: translateY(2px);
  box-shadow: 0 0 0;
}

.key.key-locked,
.key:disabled {
  background: var(--bg-key-locked) !important;
  border: 1.5px solid var(--border-subtle) !important;
  color: var(--text-muted) !important;
  opacity: 0.55;
  box-shadow: none;
  cursor: not-allowed;
}

[data-theme="light"] .key.key-locked,
[data-theme="light"] .key:disabled,
.light-mode .key.key-locked,
.light-mode .key:disabled {
  background: #e5e5e8 !important;
  border: 1.5px solid #cccccc !important;
  color: #888890 !important;
  opacity: 0.6;
}


/* =============================================================================
   10. MODALES (FIN DE PARTIDA Y CALENDARIO)
   ============================================================================= */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  padding: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--bg-modal-overlay);
  backdrop-filter: blur(2px);
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 410px;
  padding: 26px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--bg-card);
  border: 2px solid var(--border-main);
  border-radius: 8px;
  text-align: center;
  color: var(--text-main);
  box-sizing: border-box;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 14px;
  background: transparent;
  border: 0;
  color: var(--text-sub);
  font-size: 1.6rem;
  cursor: pointer;
}

.modal-close:hover {
  color: var(--text-main);
}

.modal-stats {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  align-items: center;
  gap: 8px;
  padding: 14px 10px;
  background: var(--bg-stats);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
}

.stat-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  text-align: center;
}

.stat-label {
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  line-height: 1;
  white-space: nowrap;
}

.stat-box strong {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.solution-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 16px;
  background: var(--bg-stats);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
}

.solution-label {
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  line-height: 1;
}

#modal-solution {
  color: var(--green);
  font-family: var(--font-mono);
  font-size: 1.2rem;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: 0.5px;
  font-variant-numeric: tabular-nums;
  word-break: break-word;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.modal-daily-nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 2vmin, 14px);
  width: 100%;
}

.modal-daily-nav.hidden {
  display: none !important;
}

.modal-nav-day-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  padding: 4px 8px;
  color: var(--text-sub);
  cursor: pointer;
  font-size: 1.05rem;
  line-height: 1;
  transition: color 0.15s ease, transform 0.1s ease;
  user-select: none;
}

.modal-nav-day-btn:hover:not(:disabled) {
  color: var(--green);
  transform: scale(1.2);
}

.modal-nav-day-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.modal-nav-day-btn:disabled {
  opacity: 0.15;
  cursor: not-allowed;
}

.daily-countdown {
  color: var(--text-sub);
  font-size: clamp(.78rem, 2vmin, .95rem);
  font-weight: bold;
  text-align: center;
}

.btn-primary,
.btn-secondary {
  padding: 12px;
  font-size: .9rem;
}

.btn-primary {
  background: var(--green);
  border: 0;
  color: #000;
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border-main);
  color: var(--text-main);
}

@media (hover: hover) and (pointer: fine) {
  .btn-secondary:hover {
    border-color: var(--green);
    color: var(--green);
  }
}

/* Modal del Calendario */
.calendar-modal-card {
  max-width: 360px;
  padding: 20px;
  gap: 14px;
}

.calendar-month-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: bold;
  color: var(--green);
  font-size: 0.95rem;
  min-height: 36px;
}

#calendar-month-year {
  flex: 1;
  text-align: center;
}

.calendar-nav-btn {
  background: var(--bg-card-sub);
  border: 1px solid var(--border-main);
  color: var(--text-main);
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
}

@media (hover: hover) and (pointer: fine) {
  .calendar-nav-btn:hover {
    border-color: var(--green);
  }
}

.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  font-size: 0.75rem;
  color: var(--text-sub);
  text-transform: uppercase;
}

.calendar-days-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: 4px;
}

.calendar-day {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: var(--bg-cal-day);
  border: 1px solid var(--border-main);
  border-radius: 4px;
  font-size: 0.85rem;
  color: var(--text-main);
  cursor: pointer;
  position: relative;
  box-sizing: border-box;
  transition: border-color .15s ease, background-color .15s ease;
}

.calendar-day.empty {
  background: transparent !important;
  border-color: transparent !important;
  pointer-events: none;
}

@media (hover: hover) and (pointer: fine) {
  .calendar-day:hover:not(.disabled) {
    border-color: var(--text-main);
  }
}

.calendar-day.completed {
  background: rgba(74, 222, 128, 0.18) !important;
  border: 1.5px solid var(--green) !important;
  color: var(--green) !important;
  font-weight: bold;
}

[data-theme="light"] .calendar-day.completed,
.light-mode .calendar-day.completed {
  background: #dcfce7 !important;
  border: 1.5px solid #16a34a !important;
  color: #15803d !important;
  font-weight: bold;
}

.calendar-day.in-progress {
  background: rgba(251, 191, 36, 0.15) !important;
  border: 1.5px solid var(--yellow) !important;
  color: var(--yellow) !important;
  font-weight: bold;
}

[data-theme="light"] .calendar-day.in-progress,
.light-mode .calendar-day.in-progress {
  background: #fef3c7 !important;
  border: 1.5px solid #d97706 !important;
  color: #b45309 !important;
  font-weight: bold;
}

.calendar-day.selected {
  box-shadow: 0 0 0 2px var(--blue);
}

.calendar-day.disabled {
  opacity: 0.35;
  cursor: not-allowed;
  background: var(--bg-stats);
  color: var(--text-muted);
}

.calendar-actions {
  margin-top: 6px;
  display: flex;
  justify-content: center;
}

/* Modal de Ayuda (How to Play) */
.help-modal-card {
  width: min(450px, 92vw);
  max-width: 450px;
  height: auto;
  max-height: min(510px, 90vh);
  padding: clamp(14px, 3.2vmin, 20px);
  gap: 10px;
  text-align: left;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.help-modal-card h2 {
  text-align: center;
  font-size: clamp(1.1rem, 3.2vmin, 1.3rem);
  letter-spacing: 1px;
  color: var(--text-main);
  flex-shrink: 0;
  margin: 0;
}

.help-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-stats);
  padding: 3px;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.help-tab-btn {
  flex: 1;
  padding: 5px 3px;
  background: transparent;
  border: none;
  border-radius: 4px;
  color: var(--text-muted);
  font-size: clamp(.72rem, 1.8vmin, .82rem);
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: center;
}

.help-tab-btn.active {
  background: var(--bg-card-sub);
  color: var(--green);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.help-content {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: clamp(6px, 1.4vh, 10px);
  flex: 1 1 auto;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.help-content::-webkit-scrollbar {
  display: none;
}

.help-desc {
  font-size: clamp(.8rem, 1.9vmin, .9rem);
  color: var(--text-sub);
  line-height: 1.4;
  margin: 0;
}

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

.help-example-grid {
  display: flex;
  justify-content: center;
  gap: 5px;
  margin: 2px 0;
}

.help-example-grid .tile {
  width: clamp(32px, 6.5vmin, 38px);
  height: clamp(32px, 6.5vmin, 38px);
  aspect-ratio: 1;
  font-size: clamp(.9rem, 2.6vmin, 1.15rem);
}

.help-list {
  padding-left: 18px;
  font-size: clamp(.76rem, 1.7vmin, .84rem);
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
  line-height: 1.35;
  margin: 0;
}

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

.help-actions {
  margin-top: auto;
  padding-top: 4px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.help-guide-link {
  display: block;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 500;
  text-decoration: none;
  padding: 4px 8px;
  transition: color 0.15s ease;
}

.help-guide-link:hover {
  color: var(--green);
  text-decoration: underline;
}


/* =============================================================================
   11. ADAPTABILIDAD Y MEDIA QUERIES (RESPONSIVE)
   ============================================================================= */

/* Pantallas móviles estrechas (ancho <= 480px) */
@media (max-width: 480px) {
  .app-container {
    padding-right: clamp(6px, 2.5vw, 12px);
    padding-left: clamp(6px, 2.5vw, 12px);
    gap: 4px;
  }

  header {
    gap: 6px;
  }

  h1 {
    font-size: clamp(1.6rem, 5.5vmin, 2.2rem);
    letter-spacing: 3px;
  }

  .subtitle {
    white-space: normal;
    font-size: clamp(.65rem, 1.7vmin, .78rem);
    line-height: 1.2;
  }

  .nav-categories,
  .nav-modes {
    gap: 4px;
  }

  .tab-btn {
    padding: 5px 10px;
    font-size: 0.72rem;
  }

  .board {
    width: min(100%, 380px);
    margin: 0 auto;
    gap: clamp(2px, 1vw, 5px);
  }

  .board-area {
    gap: clamp(8px, 2vh, 16px);
  }

  .tile {
    font-size: clamp(.85rem, 4.2vw, 1.25rem);
  }

  .keyboard-wrapper {
    max-width: 420px;
    gap: 4px;
  }

  .keyboard-row.available-row .key {
    flex: 1 1 0;
    max-width: 58px;
    min-height: 42px;
    height: clamp(42px, 11vw, 52px);
    font-size: clamp(1rem, 3.8vmin, 1.25rem);
  }

  .key {
    min-height: 42px;
    height: clamp(42px, 12vw, 54px);
    font-size: clamp(0.9rem, 3.2vmin, 1.15rem);
  }

  .key.action-key {
    font-size: 0.85rem;
  }
}

/* Pantallas de altura reducida (ej: iPhone SE, altura <= 720px) */
@media (max-height: 720px) {
  :root {
    --space: 4px;
    --gap: 3px;
  }

  h1 {
    font-size: 1.5rem;
    letter-spacing: 2px;
  }

  .target-wrapper {
    gap: 4px;
  }

  .random-action-row {
    min-height: 24px;
  }

  .btn-reroll {
    padding: 3px 8px;
    font-size: 0.75rem;
  }

  .board-area {
    gap: 8px;
  }

  .history {
    height: 42px;
  }

  .history-list {
    max-height: 42px;
  }

  .history-entry {
    min-height: 24px;
    padding: 2px 6px;
    font-size: 0.72rem;
  }

  .key {
    min-height: 38px;
    height: clamp(38px, 5.5vmin, 46px);
    font-size: 0.95rem;
  }

  .keyboard-row.available-row .key {
    min-height: 34px;
    height: 38px;
  }

  .key.action-key {
    font-size: 0.8rem;
  }

  .crossword-board {
    max-width: 100%;
    margin-bottom: 0;
  }

  .crossword-grid {
    width: min(330px, 36vh, 84vw);
    max-width: 100%;
    max-height: 100%;
  }
}

/* Pantallas ultra-compactas / Apaisadas (altura <= 560px) */
@media (max-height: 560px) {
  .app-container {
    overflow-y: auto;
    justify-content: flex-start;
    padding-top: 4px;
    padding-bottom: 4px;
  }

  h1,
  .subtitle,
  .history {
    display: none;
  }

  .crossword-board {
    max-width: 100%;
    margin-bottom: 0;
  }

  .crossword-grid {
    width: min(220px, 44vh, 70vw);
    max-width: 100%;
    max-height: 100%;
  }
}

/* =============================================================================
   12. GAME JUICE - MICRO-ANIMACIONES Y CONFETI
   ============================================================================= */

@keyframes tilePop {
  0% {
    transform: scale(0.88);
  }
  50% {
    transform: scale(1.14);
  }
  100% {
    transform: scale(1);
  }
}

.tile.tile-pop,
.cw-cell.tile-pop {
  animation: tilePop 0.12s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}

@keyframes rowShake {
  0%, 100% {
    transform: translateX(0);
  }
  15% {
    transform: translateX(-7px);
  }
  30% {
    transform: translateX(7px);
  }
  45% {
    transform: translateX(-5px);
  }
  60% {
    transform: translateX(5px);
  }
  75% {
    transform: translateX(-2px);
  }
  90% {
    transform: translateX(2px);
  }
}

.board.shake,
.crossword-grid.shake {
  animation: rowShake 0.42s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes winBounce {
  0%, 100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-12px);
  }
  50% {
    transform: translateY(2px);
  }
  70% {
    transform: translateY(-4px);
  }
}

.tile.win-bounce,
.cw-cell.win-bounce {
  animation: winBounce 0.6s ease forwards;
}

.confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 10000;
}

/* Legal Footer */
.site-legal-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 6px 10px;
  width: 100%;
  max-width: 580px;
  margin: 0 auto;
  flex-shrink: 0;
  padding: 4px 4px 2px 4px;
  font-size: clamp(0.72rem, 1.4vmin, 0.8rem);
  color: var(--text-muted);
  z-index: 10;
}

.site-legal-footer .footer-dot {
  opacity: 0.4;
  user-select: none;
}

.site-legal-footer a {
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.15s ease;
}

.site-legal-footer a:hover,
.modal-legal-footer a:hover {
  color: var(--text-main);
  text-decoration: underline;
}

.modal-legal-footer {
  margin-top: 14px;
  text-align: center;
  font-size: 0.75rem;
}

.modal-legal-footer a {
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.15s ease;
}

/* =============================================================================
   12. SECCIÓN EDITORIAL Y EDUCATIVA (HOMEPAGE RICH CONTENT)
   ============================================================================= */

.homepage-editorial-section {
  width: 100%;
  max-width: 680px;
  margin: 16px auto 40px auto;
  padding: 0 clamp(12px, 3vw, 20px);
  user-select: text;
  -webkit-user-select: text;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.editorial-card {
  background: var(--bg-card);
  border: 1.5px solid var(--border-main);
  border-radius: 12px;
  padding: clamp(20px, 3.5vw, 32px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  line-height: 1.75;
}

.editorial-card h2 {
  font-size: clamp(1.25rem, 2.5vw, 1.55rem);
  color: var(--blue);
  margin-top: 26px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 6px;
  font-weight: 700;
}

.editorial-card h2:first-child {
  margin-top: 0;
}

.editorial-card h3 {
  font-size: 1.1rem;
  color: var(--text-main);
  margin-top: 18px;
  margin-bottom: 8px;
  font-weight: 600;
}

.editorial-card p,
.editorial-card ul,
.editorial-card ol {
  color: var(--text-sub);
  font-size: 0.95rem;
  margin-bottom: 14px;
}

.editorial-card ul,
.editorial-card ol {
  padding-left: 22px;
}

.editorial-card li {
  margin-bottom: 8px;
}

.editorial-card strong {
  color: var(--text-main);
  font-weight: 600;
}

.editorial-card code {
  font-family: var(--font-mono);
  background: var(--bg-card-sub);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  font-size: 0.9em;
}

.editorial-callout {
  background: var(--bg-card-sub);
  border-left: 4px solid var(--green);
  padding: 14px 18px;
  border-radius: 0 8px 8px 0;
  margin: 16px 0;
  font-family: var(--font-mono);
  font-size: 0.96rem;
  color: var(--text-main);
}

.editorial-faq-item {
  background: var(--bg-card-sub);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 14px 18px;
  margin-bottom: 12px;
}

.editorial-faq-item h3 {
  margin-top: 0;
  margin-bottom: 6px;
  font-size: 1.02rem;
}

.editorial-faq-item p {
  margin-bottom: 0;
  font-size: 0.92rem;
}

.editorial-links-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 20px;
}

.editorial-link-box {
  display: flex;
  flex-direction: column;
  padding: 14px;
  background: var(--bg-card-sub);
  border: 1px solid var(--border-main);
  border-radius: 8px;
  text-decoration: none;
  transition: all 0.2s ease;
}

.editorial-link-box:hover {
  border-color: var(--green);
  transform: translateY(-2px);
}

.editorial-link-box strong {
  color: var(--green);
  font-size: 0.95rem;
  margin-bottom: 4px;
}

.editorial-link-box span {
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.4;
}

.editorial-footer-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 14px;
  padding-top: 16px;
  margin-top: 20px;
  border-top: 1px solid var(--border-subtle);
  font-size: 0.82rem;
}

.editorial-footer-nav a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s ease;
}

.editorial-footer-nav a:hover {
  color: var(--text-main);
  text-decoration: underline;
}

.editorial-copyright {
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 10px;
}



