/* ==========================================================================
   Apple Cupertino Design System • Tabla Periódica
   Estilos puros CSS para iPhone / Web
   ========================================================================== */

:root {
  --apple-font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  --bg-system: #f2f2f7;
  --bg-card: #ffffff;
  --border-card: rgba(0, 0, 0, 0.08);
  --text-main: #1c1c1e;
  --text-sub: #8e8e93;

  /* Apple System Colors */
  --apple-blue: #0071e3;
  --apple-blue-soft: #e1f0ff;
  --apple-green: #34c759;
  --apple-green-soft: #e8f9ed;
  --apple-red: #ff3b30;
  --apple-red-soft: #feebe9;

  /* Colores exactos de la foto de la tabla */
  --col-no-metal: #b5aef9;        /* Lavanda suave (H, C, N, O, P, S, Se) */
  --col-alcalino: #f8ad7f;        /* Naranja salmón (Li, Na, K, Rb, Cs, Fr) */
  --col-alcalinoterreo: #ebd299;  /* Beige arena (Be, Mg, Ca, Sr, Ba, Ra) */
  --col-transicion: #e5f39d;      /* Verde lima pastel (Sc-Zn, Y-Cd, Lu-Hg) */
  --col-otros-metales: #fff59d;   /* Amarillo limón claro (Al, Ga, In, Sn, Tl, Pb, Bi) */
  --col-metaloide: #7be396;       /* Verde menta brillante (B, Si, Ge, As, Sb, Te, Po) */
  --col-halogeno: #ff9ee2;        /* Rosa pastel (F, Cl, Br, I, At) */
  --col-gas-noble: #8cd8fe;       /* Azul celeste claro (He, Ne, Ar, Kr, Xe, Rn) */

  --safe-top: env(safe-area-inset-top, 16px);
  --safe-bottom: env(safe-area-inset-bottom, 16px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  font-family: var(--apple-font);
  background-color: var(--bg-system);
  color: var(--text-main);
  min-height: 100vh;
  min-height: -webkit-fill-available;
  display: flex;
  justify-content: center;
  padding: calc(var(--safe-top) + 4px) 10px calc(var(--safe-bottom) + 8px);
  -webkit-font-smoothing: antialiased;
}

.app-wrapper {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Header Apple */
.apple-bar {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 16px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.apple-title-box {
  display: flex;
  align-items: center;
  gap: 6px;
}

.apple-icon-logo {
  font-size: 18px;
}

.apple-title-box h1 {
  font-size: 14.5px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.badge-count {
  font-size: 11px;
  font-weight: 700;
  color: var(--apple-blue);
  background: var(--apple-blue-soft);
  padding: 2px 8px;
  border-radius: 10px;
}

.bar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-icon {
  background: #f2f2f7;
  border: 1px solid #e5e5ea;
  color: var(--text-main);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  cursor: pointer;
}

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

/* Sub-barra de orden y progreso */
.order-status-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 14px;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.03);
}

.order-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11.5px;
}

.order-phase-tag {
  font-weight: 700;
  color: var(--apple-blue);
  background: var(--apple-blue-soft);
  padding: 2px 8px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.order-direction-text {
  color: var(--text-sub);
  font-weight: 600;
}

.progress-bar-track {
  width: 100%;
  height: 5px;
  background: #e5e5ea;
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--apple-blue);
  border-radius: 3px;
  transition: width 0.3s ease;
}

/* ==========================================================================
   TABLA PERIÓDICA REAL (18 columnas x 7 filas)
   ========================================================================== */
.periodic-table-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 16px;
  padding: 6px;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.04);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.table-matrix-grid {
  display: grid;
  grid-template-columns: repeat(18, 1fr);
  grid-template-rows: repeat(7, 24px);
  gap: 2px;
  width: 100%;
  background: #f8f8fa;
  padding: 3px;
  border-radius: 10px;
  border: 1px solid #e5e5ea;
}

/* Casilla vacía (sin elemento en ese periodo/grupo) */
.cell-slot.void {
  visibility: hidden;
  pointer-events: none;
}

/* HUECO VACÍO (Casilla por rellenar) */
.cell-slot.empty-hole {
  background: #ffffff;
  border: 1px dashed #c7c7cc;
  border-radius: 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
}

.cell-slot.empty-hole .z-label {
  font-size: 6px;
  font-weight: 700;
  color: #aeaeb2;
  line-height: 1;
}

/* HUECO VACÍO ACTIVO (El que toca en este turno exacto) */
.cell-slot.active-hole {
  border: 2px solid var(--apple-blue) !important;
  background: #e1f0ff !important;
  box-shadow: 0 0 8px rgba(0, 113, 227, 0.6);
  transform: scale(1.18);
  z-index: 10;
  border-radius: 4px;
  animation: beaconSlot 1.2s infinite alternate ease-in-out;
}

@keyframes beaconSlot {
  0% { transform: scale(1.12); box-shadow: 0 0 6px rgba(0, 113, 227, 0.5); }
  100% { transform: scale(1.28); box-shadow: 0 0 14px rgba(0, 113, 227, 0.9); }
}

.cell-slot.active-hole::after {
  content: '?';
  font-size: 9px;
  font-weight: 900;
  color: var(--apple-blue);
  line-height: 1;
}

/* ELEMENTO CREADO / RELLENADO CON SU COLOR DE LA FOTO */
.cell-slot.filled {
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #1a1a1a;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
  cursor: pointer;
}

.cell-slot.filled.pop-in {
  animation: popIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
  0% { transform: scale(0.2); opacity: 0; }
  70% { transform: scale(1.35); }
  100% { transform: scale(1); }
}

.cell-slot.filled .elem-symbol {
  font-size: 8px;
  font-weight: 800;
  line-height: 1;
}

.cell-slot.filled .elem-z {
  font-size: 5px;
  font-weight: 700;
  color: rgba(0, 0, 0, 0.65);
  line-height: 1;
  margin-top: 1px;
}

/* ==========================================================================
   SECCIÓN DE PREGUNTA Y 3 OPCIONES TIPO TEST
   ========================================================================= */
.quiz-interactive-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 16px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
}

.quiz-prompt-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.quiz-title {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-main);
}

.quiz-cat-chip {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 8px;
  color: #1a1a1a;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

/* GRUPO DE 3 OPCIONES */
.options-group-3 {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.option-card-btn {
  background: #f8f8fa;
  border: 1.2px solid #e5e5ea;
  border-radius: 12px;
  padding: 9px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 48px;
}

.option-card-btn:active {
  transform: scale(0.98);
  background: #f0f0f5;
}

.opt-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.opt-letter {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #ffffff;
  color: var(--text-sub);
  font-size: 11.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #d1d1d6;
}

.opt-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
}

.opt-sub {
  font-size: 11px;
  color: var(--text-sub);
}

.opt-badge {
  font-size: 18px;
  font-weight: 800;
  color: #1a1a1a;
  padding: 3px 10px;
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  min-width: 44px;
  text-align: center;
}

/* Animaciones acierto / fallo */
.option-card-btn.correct {
  background: var(--apple-green-soft) !important;
  border-color: var(--apple-green) !important;
  animation: bounceOpt 0.35s ease;
}

.option-card-btn.wrong {
  background: var(--apple-red-soft) !important;
  border-color: var(--apple-red) !important;
  animation: shakeOpt 0.35s ease;
}

@keyframes bounceOpt {
  0% { transform: scale(0.97); }
  50% { transform: scale(1.02); }
  100% { transform: scale(1); }
}

@keyframes shakeOpt {
  10%, 90% { transform: translate3d(-3px, 0, 0); }
  20%, 80% { transform: translate3d(3px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-3px, 0, 0); }
  40%, 60% { transform: translate3d(3px, 0, 0); }
}

/* Pista mnemotécnica */
.hint-container {
  margin-top: 2px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hint-btn {
  background: #f2f2f7;
  border: 1px solid #e5e5ea;
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 600;
  color: #5856d6;
  cursor: pointer;
  text-align: center;
}

.hint-text {
  background: #f8f8fa;
  border: 1px dashed #d1d1d6;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 11px;
  line-height: 1.35;
  color: #3a3a3c;
  display: none;
}

.hint-text.visible {
  display: block;
}

/* Modal de fases */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  display: none;
  align-items: flex-end;
  justify-content: center;
}

.sheet-backdrop.open {
  display: flex;
}

.sheet-content {
  background: #ffffff;
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  width: 100%;
  max-width: 480px;
  max-height: 75vh;
  overflow-y: auto;
  padding: 14px 16px calc(var(--safe-bottom) + 14px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sheet-header h3 {
  font-size: 15px;
  font-weight: 700;
}

.btn-close-sheet {
  border: none;
  background: #e5e5ea;
  border-radius: 50%;
  width: 26px;
  height: 26px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}

.sheet-phase-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.phase-item-row {
  background: #f8f8fa;
  border: 1px solid var(--border-card);
  border-radius: 12px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}

.phase-item-row.active {
  background: #e1f0ff;
  border-color: var(--apple-blue);
}

.victory-content {
  text-align: center;
  align-items: center;
}

.victory-icon {
  font-size: 50px;
}

.victory-content h2 {
  font-size: 19px;
  font-weight: 800;
}

.victory-content p {
  font-size: 13px;
  color: var(--text-sub);
}

.btn-primary {
  background: var(--apple-blue);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 12px 24px;
  font-size: 15px;
  font-weight: 700;
  width: 100%;
  cursor: pointer;
}

.btn-primary:active {
  background: #0062c4;
}
