/* css/style.css */

:root {
  --bg-color: #0f172a;          /* Azul oscuro de fondo */
  --card-bg: #1e293b;           /* Fondo de tarjetas */
  --chrome-color: var(--card-bg);
  --card-hover: #334155;        /* Hover */
  --text-main: #f8fafc;         /* Texto principal */
  --text-muted: #b4c0d1;        /* Texto secundario con mayor contraste */
  --accent-color: #38bdf8;      /* Azul neón */
  --correct-color: #22c55e;     /* Verde de acierto */
  --wrong-color: #ef4444;       /* Rojo de fallo */
  --font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius: 16px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-color);
  color: var(--text-main);
  font-family: var(--font-family);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* --- CONTENEDOR PRINCIPAL --- */
.app-container {
  width: 100%;
  max-width: 800px;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  flex-grow: 1;
}

.site-header {
  width: 100%;
  text-align: center;
  padding: 18px 16px;
  background: var(--chrome-color);
  border-bottom: 1px solid rgba(56, 189, 248, 0.18);
}

.site-title {
  color: #fff;
  text-decoration: none;
}

.site-title h1 {
  font-size: clamp(1.45rem, 4vw, 1.8rem);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.03em;
}

/* --- META DEL JUEGO (RETO DIARIO Y ESTADÍSTICAS) --- */
.game-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.daily-badge {
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--accent-color);
  text-transform: uppercase;
}

.stats-bar {
  display: flex;
  gap: 10px;
}

.stat-item {
  background: var(--card-bg);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

/* --- BARRA DE MISIÓN Y PREGUNTA --- */
.mission-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mission-info {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
}

.mission-title {
  color: var(--text-main);
}

.question-counter {
  color: var(--accent-color);
}

.progress-bar-container {
  width: 100%;
  height: 8px;
  background-color: var(--card-bg);
  border-radius: 10px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #38bdf8, #818cf8);
  transition: width 0.3s ease;
}

/* --- TABLERO DE JUEGO (GAME BOARD) --- */
.game-board {
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
}

.event-card {
  background-color: var(--card-bg);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 24px;
  min-height: 180px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  width: 100%;
/* --- Imgs de fondo --- */
  background-size: cover;            /* La imagen cubre toda la tarjeta sin deformarse */
  background-position: center;       /* Centra la imagen */
  position: relative;                /* Para controlar capas */
  overflow: hidden;                  /* Mantiene los bordes redondeados */
}

/* Capa oscura (Overlay) sobre la imagen para asegurar que el texto sea 100% legible */
.event-card.has-image::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.6) 0%, rgba(15, 23, 42, 0.85) 100%);
  z-index: 1;
}

/* Asegurar que el texto y las etiquetas queden por encima de la capa oscura */
.event-card > * {
  position: relative;
  z-index: 2;
}

.event-card:hover {
  background-color: var(--card-hover);
  transform: translateY(-2px);
}

.event-card:active {
  transform: scale(0.98);
}

.category-badge {
  align-self: flex-start;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 12px;
  background-color: rgba(56, 189, 248, 0.15);
  color: var(--accent-color);
  margin-bottom: 12px;
}

.event-title {
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text-main);
  flex-grow: 1;
}

.date-reveal {
  margin-top: 12px;
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text-muted);
  opacity: 1;
  transition: all 0.3s ease;
}

.date-reveal.visible {
  opacity: 1;
  color: var(--accent-color);
}

.event-card.correct {
  border-color: var(--correct-color);
  background-color: rgba(34, 197, 94, 0.1);
}

.event-card.wrong {
  border-color: var(--wrong-color);
  background-color: rgba(239, 68, 68, 0.1);
}

.vs-divider {
  align-self: center;
  background-color: var(--accent-color);
  color: #0f172a;
  font-weight: 800;
  font-size: 0.8rem;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.4);
  z-index: 2;
  margin: -6px 0;
}

/* --- RESULTADOS --- */
.results-screen {
  background-color: var(--card-bg);
  border-radius: var(--radius);
  padding: 32px 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.score-number {
  font-size: 3rem;
  font-weight: 800;
  color: var(--accent-color);
}

.score-label {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.btn-share {
  background: linear-gradient(135deg, #38bdf8, #818cf8);
  color: #0f172a;
  border: none;
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.btn-share:hover {
  transform: scale(1.05);
}

.daily-lock {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 18px;
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: var(--radius);
  background: rgba(15, 23, 42, 0.72);
  text-align: center;
}

.daily-lock-icon {
  font-size: 2rem;
}

.daily-lock h3 {
  color: var(--accent-color);
}

.daily-lock p {
  color: var(--text-muted);
}

.daily-lock-countdown {
  font-size: 1.4rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
}

.hidden {
  display: none !important;
}

/* --- FOOTER --- */
.main-footer {
  width: 100%;
  padding: 24px 20px;
  background: var(--chrome-color);
  border-top: 1px solid rgba(56, 189, 248, 0.18);
  margin-top: 28px;
}

.footer-content {
  max-width: 1000px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 16px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.footer-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.footer-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
}

.footer-brand > a {
  flex: 0 0 auto;
}

.footer-logo {
  display: block;
  width: 80px;
  height: 80px;
  object-fit: contain;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 8px 20px;
}

.footer-links a {
  color: var(--accent-color);
  text-decoration: none;
  font-weight: 600;
}

.footer-links a:hover {
  text-decoration: underline;
}

.footer-links a:focus-visible,
a:focus-visible,
button:focus-visible {
  outline: 3px solid #facc15;
  outline-offset: 3px;
}

.footer-copyright {
  font-size: 0.85rem;
}

.footer-description {
  font-size: 0.78rem;
  line-height: 1.4;
}

.footer-description a {
  color: inherit;
}

.footer-description a:hover {
  text-decoration: underline;
}

.info-page {
  max-width: 900px;
}

.info-page > h2 {
  font-size: clamp(1.7rem, 5vw, 2.3rem);
  line-height: 1.2;
}

.info-intro,
.info-section {
  background: linear-gradient(145deg, rgba(30, 41, 59, 0.95), rgba(30, 41, 59, 0.72));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  padding: 22px;
}

.info-intro {
  color: var(--text-muted);
  line-height: 1.7;
}

.info-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.info-section h3 {
  color: var(--accent-color);
  font-size: 1.15rem;
}

.info-section p,
.info-section li {
  color: var(--text-muted);
  line-height: 1.65;
}

.info-section ul {
  padding-left: 22px;
}

.credits-table-wrapper {
  width: 100%;
}

.credits-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  text-align: left;
}

.credits-table th,
.credits-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
  line-height: 1.5;
  vertical-align: top;
}

.credits-table td {
  overflow-wrap: anywhere;
}

.credits-table th {
  color: var(--text-main);
}

.credits-table a {
  display: inline-block;
  margin-right: 8px;
}

.credits-table .source-link {
  padding: 3px 9px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  background: var(--card-hover);
  color: var(--text-main);
  font-size: 0.8rem;
  line-height: 1.4;
  text-decoration: none;
  white-space: nowrap;
}

.credits-table .source-link:hover {
  background: #475569;
}

.info-section a {
  color: var(--accent-color);
  overflow-wrap: anywhere;
}

.info-return a {
  color: var(--accent-color);
  font-weight: 600;
  text-decoration: none;
  transition: color 0.2s ease;
}

.info-return a:hover {
  color: var(--text-main);
  text-decoration: underline;
}

.info-notice {
  border-left: 3px solid var(--accent-color);
  padding-left: 14px;
}

@media (max-width: 639px) {
  .credits-table,
  .credits-table tbody {
    display: block;
  }

  .credits-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .credits-table tr {
    display: block;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }

  .credits-table td {
    display: grid;
    grid-template-columns: minmax(6.5rem, 35%) minmax(0, 1fr);
    gap: 12px;
    padding: 8px 0;
    border-bottom: 0;
    overflow-wrap: anywhere;
  }

  .credits-table td::before {
    content: attr(data-label);
    color: var(--text-main);
    font-weight: 600;
  }
}

/* --- RESPONSIVE ESCRITORIO --- */
@media (min-width: 640px) {
  .game-board {
    flex-direction: row;
    align-items: stretch;
  }

  .event-card {
    flex: 1;
    min-height: 260px;
  }

  .vs-divider {
    margin: 0 -18px;
  }

  .footer-content {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
  }

  .footer-links {
    justify-content: flex-end;
  }
}

/* --- MENÚ DE NAVEGACIÓN ENTRE MODOS Y LOGROS --- */
.mode-selector {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  background-color: var(--card-bg);
  padding: 6px;
  border-radius: 30px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.mode-btn {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 8px 16px;
  border-radius: 20px;
  transition: all 0.2s ease;
}

.mode-btn:hover,
.mode-btn.active {
  color: #0f172a;
  background: linear-gradient(135deg, #38bdf8, #818cf8);
}

/* Modo Infinito: Vidas */
.lives-container {
  font-size: 1.2rem;
  letter-spacing: 4px;
}

/* --- ESTILOS LÍNEA DEL TIEMPO (CRONOLOGÍA) --- */
.timeline-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--card-bg);
  padding: 20px;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.timeline-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 200px;
}

.timeline-item {
  background: var(--card-hover);
  padding: 14px 18px;
  border-radius: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  cursor: grab;
  user-select: none;
  border: 2px solid transparent;
  transition: transform 0.2s ease;
}

.timeline-item:active {
  cursor: grabbing;
  transform: scale(1.02);
}

.timeline-item.dragging {
  opacity: 0.5;
  border-color: var(--accent-color);
}

.timeline-date {
  font-weight: 800;
  color: var(--accent-color);
}

.btn-check-timeline {
  background: linear-gradient(135deg, #38bdf8, #818cf8);
  color: #0f172a;
  border: none;
  padding: 14px;
  border-radius: 24px;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  margin-top: 10px;
}

/* --- ESTILOS PÁGINA DE LOGROS --- */
.stats-overview {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  width: 100%;
}

.stat-card {
  background-color: var(--card-bg);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.stat-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-align: center;
}

.stat-number {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--accent-color);
  line-height: 1;
}

.stat-number small {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
}

.achievements-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-top: 10px;
}

.achievement-card {
  background: var(--card-bg);
  padding: 22px 18px;
  border-radius: var(--radius);
  border: 2px solid transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  transition: all 0.3s ease;
}

.achievement-icon {
  font-size: 2.8rem;
  margin-bottom: 4px;
}

.achievement-title {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text-main);
}

.achievement-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.3;
}

.achievement-card.unlocked {
  border-color: var(--accent-color);
  background: linear-gradient(180deg, rgba(30, 41, 59, 0.9) 0%, rgba(56, 189, 248, 0.12) 100%);
  box-shadow: 0 0 20px rgba(56, 189, 248, 0.25);
}

.achievement-card.unlocked .achievement-title {
  color: var(--accent-color);
}

.achievement-card.locked {
  opacity: 0.35;
  filter: grayscale(1);
}

.btn-primary {
  background: var(--card-hover);
  color: var(--text-main);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary:hover {
  background-color: #475569;
}

.share-box {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.high-score-box {
  color: var(--correct-color);
  font-weight: 800;
  font-size: 1.1rem;
}

/* --- MODO LÍNEA DEL TIEMPO --- */
.active-card-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-height: 180px;
}

.instruction-text {
  font-size: 0.9rem;
  color: var(--text-muted);
  text-align: center;
}

.draggable-card-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(260px, 100%);
  touch-action: none;
  cursor: grab;
  z-index: 100;
  transition: transform 0.1s ease;
}

.draggable-card-wrapper:active {
  cursor: grabbing;
}

.draggable-card-wrapper.dragging {
  position: fixed;
  pointer-events: none;
  transform: none;
  box-shadow: none;
  transition: none;
  z-index: 9999;
}

.draggable-card-wrapper.dragging .timeline-drawn-card,
.draggable-card-wrapper.dragging .timeline-drawn-card:hover,
.draggable-card-wrapper.dragging .timeline-drawn-card:active {
  transform: none;
}

.timeline-drawn-card {
  width: 260px;
  min-height: 130px;
  max-width: 320px;
  border-color: rgba(56, 189, 248, 0.4);
  box-shadow: 0 8px 24px rgba(56, 189, 248, 0.2);
}

.timeline-board-wrapper {
  width: 100%;
  padding: 20px 10px;
  position: relative;
  border-radius: var(--radius);
  background-color: rgba(30, 41, 59, 0.4);
}

.timeline-track {
  display: grid;
  gap: 18px;
  width: 100%;
}

.timeline-row {
  position: relative;
  display: grid;
  align-items: center;
  height: 146px;
}

.timeline-row > * {
  grid-row: 1;
}

.timeline-row[data-columns="3"] {
  grid-template-columns: 24px minmax(0, 1fr) 24px minmax(0, 1fr) 24px minmax(0, 1fr) 24px;
}

.timeline-row[data-columns="2"] {
  grid-template-columns: 24px minmax(0, 1fr) 24px minmax(0, 1fr) 24px;
}

.timeline-row::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 12px;
  right: 12px;
  height: 4px;
  transform: translateY(-50%);
  border-radius: 4px;
  background-color: var(--card-hover);
  z-index: 0;
}

.timeline-row:not(:last-child)::after {
  content: '';
  position: absolute;
  top: 50%;
  right: 12px;
  width: 4px;
  height: 164px;
  border-radius: 4px;
  background-color: var(--card-hover);
  z-index: 0;
}

.timeline-row[data-reverse="true"]:not(:last-child)::after {
  right: auto;
  left: 12px;
}

.placed-card {
  position: relative;
  justify-self: center;
  z-index: 2;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 100%;
  max-width: 180px;
  height: 130px;
  min-width: 0;
  padding: 9px 10px;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  background-color: var(--card-bg);
  background-position: center;
  background-size: cover;
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.25);
}

.placed-card.has-image::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.58), rgba(15, 23, 42, 0.92));
  z-index: 0;
}

.placed-card > * {
  position: relative;
  z-index: 1;
}

.placed-card .event-title {
  display: -webkit-box;
  display: box; /* Compatibilidad estándar */
  overflow: hidden;
  -webkit-box-orient: vertical;
  box-orient: vertical; /* Compatibilidad estándar */
  -webkit-line-clamp: 4;
  line-clamp: 4; /* Propiedad estándar */
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.placed-card .placed-year {
  align-self: flex-start;
  margin-top: 4px;
  padding: 2px 6px;
  border-radius: 6px;
  background-color: rgba(15, 23, 42, 0.78);
  color: var(--accent-color);
  font-size: 0.85rem;
  font-weight: 800;
}

.drop-slot {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: stretch;
  min-width: 0;
  width: 44px;
  justify-self: center;
  margin: 0 -10px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
}

.drop-slot::before {
  content: '';
  width: 12px;
  height: 12px;
  border: 2px solid var(--text-muted);
  border-radius: 50%;
  background-color: var(--card-bg);
  transition: transform 0.2s ease, background-color 0.2s ease, border-color 0.2s ease;
  pointer-events: none;
}

.drop-slot.active-target::before {
  transform: scale(1.5);
  border-color: var(--accent-color);
  background-color: var(--accent-color);
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.7);
}

.drop-slot:hover,
.drop-slot:focus-visible {
  background: rgba(56, 189, 248, 0.16);
}

.timeline-feedback {
  min-height: 1.5em;
  color: var(--text-main);
  text-align: center;
}

.timeline-feedback.incorrect {
  color: var(--wrong-color);
  font-weight: 800;
}

.timeline-feedback.correct {
  color: var(--correct-color);
  font-weight: 800;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}