/* ============================================================
   SISTEMA DE DISEÑO — CRUCIGRAMA INTERACTIVO
   ============================================================ */

/* ----- TOKENS ----- */
:root {
  --bg-primary:       #fdfbf7; /* Blanco roto / Marfil claro */
  --bg-secondary:     #f4f1ea;
  --bg-surface:       #ffffff;
  --bg-surface-2:     #f8f6f2;
  --bg-surface-3:     #efede8;

  --cell-bg:          #ffffff;
  --cell-empty:       transparent;
  --cell-active:      #fef3c7; /* Oro muy claro */
  --cell-highlight:   #fffbeb;
  --cell-correct:     rgba(74, 222, 128, 0.15);
  --cell-incorrect:   rgba(248, 113, 113, 0.15);
  --cell-revealed:    rgba(251, 191, 36, 0.15);
  --cell-border:      #e2e8f0;
  --cell-border-active: #d4af37;

  --accent:           #d4af37; /* Oro */
  --accent-2:         #b8860b;
  --accent-glow:      rgba(212, 175, 55, 0.15);
  --accent-dark:      #8b6508;

  --correct:          #16a34a; /* Verde más oscuro para lectura en blanco */
  --incorrect:        #dc2626; /* Rojo más oscuro */
  --revealed:         #d97706;
  --warning:          #ea580c;

  --text-primary:     #1a1a1a;
  --text-secondary:   #4a4a4a;
  --text-muted:       #717171;
  --text-number:      #b8860b;

  --border:           rgba(0,0,0,0.06);
  --border-light:     rgba(0,0,0,0.1);

  --radius-sm:        6px;
  --radius-md:        12px;
  --radius-lg:        20px;
  --radius-xl:        28px;

  --shadow-glow:      0 8px 20px rgba(212, 175, 55, 0.12);
  --shadow-card:      0 10px 40px rgba(0,0,0,0.08);

  --font-body:        'Inter', sans-serif;
  --font-display:     'Outfit', sans-serif;

  --cell-size:        44px;
  --cell-gap:         3px;
}

/* ----- TEMAS LITÚRGICOS (VARIANTES CLARAS) ----- */
.theme-vatican_gold, .theme-liturgical_gold {
  --bg-primary:       #fffcf5; /* Blanco Papal */
  --bg-secondary:     #fdf8ed;
  --bg-surface:       #ffffff;
  --accent:           #d4af37;
  --text-primary:     #2c241a;
  --border-light:     rgba(212, 175, 55, 0.2);
}

/* Tema Púrpura Litúrgico (Adviento/Cuaresma) */
.theme-liturgical_purple {
  --bg-primary:       #1a0521; /* Púrpura muy oscuro */
  --bg-secondary:     #24082e;
  --bg-surface:       #310b3d;
  --bg-surface-2:     #451056;
  --bg-surface-3:     #5a1570;

  --cell-bg:          #24082e;
  --accent:           #9333ea;
  --accent-2:         #c084fc;
  --text-primary:     #f8fafc;
}

/* ----- RESET ----- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  height: 100vh;
  overflow: hidden;
}
button { cursor: pointer; font-family: inherit; border: none; background: none; }
input { font-family: inherit; }

/* ----- UTILITIES ----- */
.hidden { display: none !important; }
.gradient-text {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ============================================================
   PANTALLA BASE
   ============================================================ */
.screen { display: none; height: 100vh; width: 100vw; overflow: hidden; }
.screen.active { display: flex; flex-direction: column; }

/* ============================================================
   PANTALLA DE INICIO
   ============================================================ */
#screen-start {
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: radial-gradient(ellipse at 50% 0%, var(--bg-surface) 0%, var(--bg-primary) 70%);
  position: relative;
  overflow: hidden;
}

/* Estrellas animadas */
.start-bg { position: absolute; inset: 0; pointer-events: none; }
.star {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--s);
  height: var(--s);
  background: var(--accent);
  opacity: 0.3;
  border-radius: 50%;
  animation: twinkle var(--d) ease-in-out infinite alternate;
}
@keyframes twinkle {
  from { opacity: 0.2; transform: scale(1); }
  to   { opacity: 1;   transform: scale(1.5); }
}

.start-card {
  position: relative;
  z-index: 1;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  padding: 3rem 2.5rem;
  max-width: 520px;
  width: 100%;
  text-align: center;
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow-card), var(--shadow-glow);
}

.start-icon {
  font-size: 3.5rem;
  margin-bottom: 1rem;
  animation: float 3s ease-in-out infinite;
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-10px); }
}

.start-title {
  font-family: var(--font-display);
  font-size: 2.8rem;
  font-weight: 800;
  line-height: 1.15;
  margin-bottom: 0.75rem;
}

.start-subtitle {
  color: var(--text-secondary);
  font-size: 1rem;
  line-height: 1.6;
  margin-bottom: 2rem;
}

/* Drop Zone */
.drop-zone {
  border: 2px dashed var(--cell-border);
  border-radius: var(--radius-lg);
  padding: 2rem 1.5rem;
  transition: border-color 0.2s, background 0.2s;
  cursor: pointer;
}
.drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(124, 111, 255, 0.08);
}
.drop-icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.drop-text { color: var(--text-secondary); margin-bottom: 0.5rem; font-size: 0.95rem; }
.drop-text strong { color: var(--text-primary); }
.drop-or { color: var(--text-muted); margin: 0.75rem 0; font-size: 0.85rem; }

.btn-load {
  display: inline-block;
  background: linear-gradient(135deg, var(--accent), #9333ea);
  color: white;
  padding: 0.65rem 1.75rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 20px var(--accent-glow);
}
.btn-load:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 28px var(--accent-glow);
}

.drop-hint { margin-top: 1rem; color: var(--text-muted); font-size: 0.85rem; }

.theme-menu {
  margin-top: 1.5rem;
  margin-bottom: 1.5rem;
  text-align: left;
}
.theme-menu-title {
  font-size: 1.05rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
  text-align: center;
  font-family: var(--font-display);
}
.theme-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.theme-btn {
  background: var(--bg-surface-2);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.theme-btn::after {
  content: "→";
  color: var(--accent);
  opacity: 0;
  transform: translateX(-10px);
  transition: all 0.2s ease;
}
.theme-btn:hover {
  background: var(--bg-surface-3);
  border-color: var(--accent);
  transform: translateX(4px);
}
.theme-btn:hover::after {
  opacity: 1;
  transform: translateX(0);
}

.load-error {
  color: var(--accent-2);
  text-decoration: underline;
  background: none;
  border: none;
  cursor: pointer;
  font-size: inherit;
}
.link-btn:hover { color: white; }

.load-error {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: var(--radius-md);
  color: var(--incorrect);
  font-size: 0.85rem;
}

/* ============================================================
   PANTALLA DE JUEGO
   ============================================================ */
#screen-game {
  background: var(--bg-primary);
  min-height: 100vh;
}

/* ----- HEADER ----- */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.5rem;
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 1rem;
}
.header-left { display: flex; align-items: center; gap: 1rem; min-width: 0; }
.header-right { display: flex; align-items: center; gap: 0.75rem; flex-shrink: 0; }

.icon-btn {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 1.1rem;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s, color 0.2s;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-surface-2); color: var(--text-primary); }

.puzzle-info { min-width: 0; }
.puzzle-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.puzzle-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-box {
  display: flex; flex-direction: column; align-items: center;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.85rem;
}
.stat-label { font-size: 0.65rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 0.95rem; font-weight: 600; color: var(--accent-2); font-variant-numeric: tabular-nums; }

/* ----- BOTONES ----- */
.btn {
  padding: 0.55rem 1.2rem;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  font-weight: 600;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #9333ea);
  color: white;
  box-shadow: 0 3px 14px var(--accent-glow);
}
.btn-primary:hover { box-shadow: 0 5px 22px var(--accent-glow); }

.btn-secondary {
  background: var(--bg-surface-2);
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
}
.btn-secondary:hover { color: var(--text-primary); background: var(--bg-surface-3); }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: white;
  border-radius: 10px;
  font-size: 0.7rem;
  padding: 0 0.4rem;
  margin-left: 0.4rem;
  height: 18px;
  min-width: 18px;
}
.badge.hidden { display: none; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text-secondary); border-color: var(--border-light); }

.btn-lg { padding: 0.8rem 2rem; font-size: 1rem; border-radius: var(--radius-lg); }

/* ----- LAYOUT PRINCIPAL ----- */
.game-main {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: calc(100vh - 61px);
  overflow: hidden;
}

/* ----- PANEL DE PISTAS ----- */
.clues-panel {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.clues-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.clue-tab {
  flex: 1;
  padding: 0.75rem 0.5rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}
.clue-tab.active {
  color: var(--accent-2);
  border-bottom-color: var(--accent);
}
.clue-tab:hover { color: var(--text-secondary); }

.clues-list {
  overflow-y: auto;
  flex: 1;
  padding: 0.5rem;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-surface-3) transparent;
}

.clue-item {
  display: flex;
  gap: 0.5rem;
  padding: 0.55rem 0.65rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 2px;
  align-items: flex-start;
}
.clue-item:hover { background: var(--bg-surface); }
.clue-item.active { background: rgba(124, 111, 255, 0.15); }
.clue-item.completed .clue-text { color: var(--correct); }
.clue-item.revealed .clue-text { color: var(--revealed); }

.clue-num {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-number);
  min-width: 22px;
  margin-top: 1px;
}
.clue-text {
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.45;
  transition: color 0.2s;
}

/* ----- SECCIÓN DEL GRID ----- */
.grid-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 2rem 1.5rem;
  overflow-y: auto;
  gap: 1.5rem;
  flex: 1;
}

.grid-wrapper {
  display: flex;
  width: 100%;
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 4rem; /* Más espacio para evitar recortes visuales */
  scrollbar-width: thin;
  scrollbar-color: var(--accent) transparent;
}

/* ----- GRID DEL CRUCIGRAMA ----- */
.crossword-grid {
  display: grid;
  gap: var(--cell-gap);
  user-select: none;
  margin: auto; /* Centrado perfecto que respeta el scroll si el contenido es mayor */
  padding: 20px;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  background: var(--cell-bg);
  border: 1.5px solid var(--cell-border);
  border-radius: 4px;
  position: relative;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.cell.empty {
  background: transparent;
  border-color: transparent;
  cursor: default;
  pointer-events: none;
}
.cell:not(.empty):hover { border-color: var(--accent); transform: scale(1.05); }
.cell.highlighted {
  background: var(--cell-highlight);
  border-color: rgba(124, 111, 255, 0.5);
}
.cell.active {
  background: var(--cell-active);
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow), inset 0 0 8px rgba(124,111,255,0.2);
  transform: scale(1.08);
  z-index: 5;
}
.cell.correct {
  background: var(--cell-correct);
  border-color: rgba(74, 222, 128, 0.5);
}
.cell.incorrect {
  background: var(--cell-incorrect);
  border-color: rgba(248, 113, 113, 0.5);
  animation: shake 0.4s ease;
}
.cell.revealed {
  background: var(--cell-revealed);
  border-color: rgba(251, 191, 36, 0.4);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%       { transform: translateX(-4px); }
  75%       { transform: translateX(4px); }
}
@keyframes pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.2); }
  100% { transform: scale(1); }
}
.cell.pop { animation: pop 0.25s ease; }

.cell-number {
  position: absolute;
  top: 2px; left: 3px;
  font-size: 0.52rem;
  font-weight: 700;
  color: var(--text-number);
  line-height: 1;
  pointer-events: none;
}
.cell-letter {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  text-transform: uppercase;
  pointer-events: none;
  transition: color 0.2s;
}
.cell.correct   .cell-letter { color: var(--correct); }
.cell.incorrect .cell-letter { color: var(--incorrect); }
.cell.revealed  .cell-letter { color: var(--revealed); }

/* ----- PISTA ACTIVA (MÓVIL) ----- */
.active-clue-bar {
  display: none;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.6rem 1rem;
  width: 100%;
  max-width: 600px;
  gap: 0.5rem;
  align-items: flex-start;
}
.active-clue-num {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-2);
  flex-shrink: 0;
}
.active-clue-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* ----- CONTROLES ----- */
.controls-bar {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
}

/* ----- OVERLAY DE VICTORIA ----- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 8, 20, 0.85);
  backdrop-filter: blur(6px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.overlay.hidden { display: none; }

.victory-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  padding: 3rem 2.5rem;
  text-align: center;
  box-shadow: var(--shadow-card), var(--shadow-glow);
  position: relative;
  z-index: 2;
  max-width: 380px;
  width: 90%;
  animation: fadeUp 0.4s ease;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(30px); }
  to   { opacity: 1; transform: translateY(0); }
}

.victory-emoji { font-size: 4rem; margin-bottom: 1rem; }
.victory-title {
  font-family: var(--font-display);
  font-size: 2.2rem;
  font-weight: 800;
  margin-bottom: 0.4rem;
}
.victory-subtitle { color: var(--text-secondary); margin-bottom: 2rem; }

.victory-stats {
  display: flex;
  gap: 2rem;
  justify-content: center;
  margin-bottom: 2rem;
}
.v-stat { display: flex; flex-direction: column; gap: 0.2rem; }
.v-stat-val {
  font-family: var(--font-display);
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent-2);
}
.v-stat-label { font-size: 0.78rem; color: var(--text-muted); }

#confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

/* ----- TOAST ----- */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--bg-surface-2);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 0.7rem 1.3rem;
  font-size: 0.88rem;
  color: var(--text-primary);
  box-shadow: var(--shadow-card);
  z-index: 999;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.success { border-color: rgba(74,222,128,0.4); color: var(--correct); }
.toast.error   { border-color: rgba(248,113,113,0.4); color: var(--incorrect); }
.toast.info    { border-color: rgba(124,111,255,0.4); color: var(--accent-2); }

/* ----- INPUT OCULTO ----- */
#hidden-input {
  position: fixed;
  top: -100px;
  left: -100px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  :root { --cell-size: 36px; --cell-gap: 2px; }

  .game-main {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
    height: calc(100vh - 61px);
    overflow: hidden;
  }

  .clues-panel {
    display: none; /* se reemplaza por la barra activa */
  }

  .grid-section {
    overflow-y: auto;
    padding: 1rem;
    justify-content: flex-start;
  }

  .active-clue-bar {
    display: flex !important;
  }

  .game-header {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .puzzle-desc { display: none; }
  .stat-box { display: none; }

  #btn-check-all { padding: 0.4rem 0.8rem; font-size: 0.8rem; }
}

@media (max-width: 480px) {
  :root { --cell-size: 30px; --cell-gap: 2px; }
  .start-card { padding: 2rem 1.5rem; }
  .start-title { font-size: 2.2rem; }
  .controls-bar .btn { font-size: 0.8rem; padding: 0.45rem 0.9rem; }
}
