/* ============ ATOMIX — Descubre. Combina. Domina. ============ */
:root {
  --bg: #fff8ec;
  --bg-soft: #fff1d6;
  --ink: #33322e;
  --ink-soft: #6b6a63;
  --card: #ffffff;
  --line: #f0e4cc;
  --accent: #ff8a5c;
  --accent-2: #4cbfa6;
  --shadow: 0 10px 24px rgba(90, 70, 20, 0.12);
  /* Familias */
  --c-h: #f4747c; --c-h-soft: #fde3e4;
  --c-na: #f2a65a; --c-na-soft: #fdeacc;
  --c-am: #e9c46a; --c-am-soft: #faf0d2;
  --c-tm: #7bc86c; --c-tm-soft: #e3f4dd;
  --c-m: #4cbfa6; --c-m-soft: #daf2ec;
  --c-mm: #5aa9e6; --c-mm-soft: #ddeefd;
  --c-ng: #9d7bde; --c-ng-soft: #ece2fa;
  --c-hal: #e56fb1; --c-hal-soft: #fbe1f0;
  --c-om: #ef7fae; --c-om-soft: #fce4ee;
  --c-l: #8ed081; --c-l-soft: #e6f5e0;
  --c-sim: #b0b6c3; --c-sim-soft: #eceef2;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  /* 100% offline: pila de fuentes del sistema, sin Google Fonts */
  font-family: 'Baloo 2', ui-rounded, 'Comic Sans MS', 'Chalkboard SE', 'Trebuchet MS', system-ui, sans-serif;
  background:
    radial-gradient(1200px 600px at 110% -10%, #ffe9c9 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 110%, #dff5ef 0%, transparent 55%),
    var(--bg);
  color: var(--ink);
  min-height: 100vh;
  /* Safe areas de iPhone (notch) y eliminación del zoom por doble-tap en iOS */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  touch-action: manipulation;
}
button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }

#app { max-width: 1240px; margin: 0 auto; padding: 10px 14px 40px; }

/* ============ Topbar ============ */
#topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 4px; margin-bottom: 6px;
  background: linear-gradient(var(--bg) 78%, transparent);
}
.btn-icon {
  border: none; background: var(--card); border-radius: 12px;
  width: 40px; height: 40px; font-size: 19px; box-shadow: var(--shadow);
  transition: transform .15s;
}
.btn-icon:hover { transform: scale(1.12) rotate(-4deg); }
#hud { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; flex: 1; }
.hud-chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--card); border-radius: 999px; padding: 6px 14px;
  box-shadow: var(--shadow); font-size: 14px; font-weight: 600;
}
.xpbar { width: 110px; height: 9px; background: var(--bg-soft); border-radius: 999px; overflow: hidden; }
#hud-xp-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent-2), #8ed081);
  border-radius: 999px; transition: width .5s cubic-bezier(.22,1,.36,1);
}

/* ============ Screens ============ */
.screen { animation: pop-in .35s cubic-bezier(.22,1,.36,1); }
@keyframes pop-in { from { opacity: 0; transform: translateY(10px) scale(.99); } to { opacity: 1; transform: none; } }

#screen-loading { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 70vh; }
.loading-atom { position: relative; width: 120px; height: 120px; }
.loading-atom .nucleus {
  position: absolute; inset: 44px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffd7a1, var(--accent));
  animation: pulse 1.2s ease-in-out infinite alternate;
}
.loading-atom .orbit {
  position: absolute; inset: 0; border: 2px dashed #c9b98f; border-radius: 50%;
}
.loading-atom .o1 { transform: rotate(0deg) scaleY(.55); }
.loading-atom .o2 { transform: rotate(60deg) scaleY(.55); }
.loading-atom .o3 { transform: rotate(120deg) scaleY(.55); }
.loading-atom .orbit::after {
  content: ''; position: absolute; top: -5px; left: 50%; width: 10px; height: 10px;
  margin-left: -5px; border-radius: 50%; background: var(--accent-2);
}
.loading-atom .o1::after { animation: spin 1.4s linear infinite; }
.loading-atom .o2::after { animation: spin 1.9s linear infinite; }
.loading-atom .o3::after { animation: spin 2.4s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { to { transform: scale(1.18); } }
.loading-text { margin-top: 18px; font-weight: 600; color: var(--ink-soft); }

/* ============ Home ============ */
.home-hero { text-align: center; padding: 26px 0 8px; }
.title { font-size: clamp(46px, 9vw, 76px); margin: 0; letter-spacing: 2px; }
/* Logotipo ATOMIX — minimalista: letras en tinta, peso pesado y tracking
   apretado. La O es un átomo: anillo orbital + núcleo + UN electrón en
   color de acento (el único color del logotipo), en órbita lenta. */
.logo-atomix { font-weight: 900; letter-spacing: .04em; color: var(--ink); }
.logo-o {
  display: inline-block; position: relative;
  width: .78em; height: .78em;
  margin: 0 .03em;
  vertical-align: -0.06em;
}
.logo-o::before {            /* núcleo */
  content: ''; position: absolute; inset: 33%;
  border-radius: 50%; background: var(--ink);
}
.logo-o-orbit {              /* anillo + electrón */
  position: absolute; inset: 0;
  border: .075em solid var(--ink);
  border-radius: 50%;
  animation: orbit 5.5s linear infinite;
}
.logo-o-orbit::after {       /* electrón: único acento */
  content: ''; position: absolute;
  top: -.15em; left: 50%;
  width: .21em; height: .21em;
  margin-left: -.105em;
  border-radius: 50%;
  background: var(--accent);
}
.home-hero:hover .logo-o-orbit { animation-duration: 1.6s; } /* micro-detalle al pasar el dedo/mouse */
@keyframes orbit { to { transform: rotate(360deg); } }
.subtitle { font-size: 20px; color: var(--ink-soft); font-weight: 600; margin: 4px 0 0; }
.tagline {
  text-transform: uppercase;
  letter-spacing: .32em; text-indent: .32em; /* compensa el tracking del último carácter */
  font-size: 13px; font-weight: 800;
  margin-top: 10px;
}

.home-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 16px; margin: 26px 0;
}
.mode-card {
  position: relative; overflow: hidden; text-align: left;
  border: none; border-radius: 22px; padding: 20px 20px 18px;
  display: flex; flex-direction: column; gap: 6px; color: #3a3630;
  box-shadow: var(--shadow); transition: transform .18s cubic-bezier(.22,1,.36,1), box-shadow .18s;
}
.mode-card::after {
  content: ''; position: absolute; right: -30px; top: -30px; width: 110px; height: 110px;
  border-radius: 50%; background: rgba(255,255,255,.45);
}
.mode-card:hover { transform: translateY(-6px) scale(1.02); box-shadow: 0 16px 30px rgba(90,70,20,.18); }
.mode-card:active { transform: scale(.98); }
.mode-emoji { font-size: 40px; line-height: 1; }
.mode-name { font-size: 24px; font-weight: 800; }
.mode-desc { font-size: 14.5px; font-weight: 500; color: #55524a; }
.card-explorer { background: linear-gradient(145deg, #bfe8ff, #e7f7ff); }
.card-trivia { background: linear-gradient(145deg, #ffd9e6, #fff0f6); }
.card-hunter { background: linear-gradient(145deg, #ffe3bd, #fff6e6); }
.card-memory { background: linear-gradient(145deg, #d5f2e4, #effbf5); }

.home-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.stat-card {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border-radius: 18px; padding: 14px 18px; box-shadow: var(--shadow);
}
.stat-icon { font-size: 30px; }
.stat-num { font-size: 21px; font-weight: 800; }
.stat-label { font-size: 13.5px; color: var(--ink-soft); font-weight: 600; }
.link-btn {
  display: block; margin: 22px auto 0; border: none; background: none;
  color: #c26a4a; font-size: 14px; font-weight: 600; text-decoration: underline dotted;
}
.link-btn:hover { color: #a34d2f; }

/* ============ Explorer ============ */
.explorer-toolbar {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 4px 0 12px;
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(var(--bg) 82%, transparent);
  padding: 6px 0 10px;
}
#search {
  flex: 1; min-width: 220px; max-width: 380px; padding: 12px 18px;
  border: 2px solid var(--line); border-radius: 999px; font-family: inherit; font-size: 16px;
  background: var(--card); outline: none; transition: border-color .2s, box-shadow .2s;
}
#search:focus { border-color: var(--accent-2); box-shadow: 0 0 0 4px rgba(76,191,166,.15); }
.btn {
  border: none; background: var(--card); color: var(--ink);
  padding: 9px 16px; border-radius: 999px; font-size: 15px; font-weight: 700; box-shadow: var(--shadow);
  transition: transform .15s;
}
.btn:hover { transform: translateY(-2px); }
.btn.pill { border-radius: 999px; }
.btn-special { background: linear-gradient(120deg, #ffe3bd, #ffd9e6); }
.btn-primary { background: linear-gradient(120deg, var(--accent), #ffb28c); color: #fff; font-size: 16.5px; padding: 11px 22px; }

.legend {
  display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px;
  -webkit-overflow-scrolling: touch;
}
.legend-item {
  flex: 0 1 auto; white-space: normal; text-align: left;
}
.legend-item {
  display: inline-flex; align-items: center; gap: 7px; border: 2px solid transparent;
  background: var(--card); border-radius: 999px; padding: 5px 12px 5px 7px;
  font-size: 13px; font-weight: 700; box-shadow: var(--shadow); transition: transform .12s;
}
.legend-item:hover { transform: scale(1.05); }
.legend-item.active { border-color: var(--ink); }
.legend-dot { width: 16px; height: 16px; border-radius: 50%; }

#table-wrap {
  overflow-x: auto; padding-bottom: 10px;
  -webkit-overflow-scrolling: touch; /* inercia suave en iOS */
  overscroll-behavior-x: contain;    /* no navegar hacia atrás al llegar al borde */
  scroll-snap-type: x proximity;     /* asienta cerca de los bloques al soltar */
}
#ptable, .ptable-grid {
  display: grid; grid-template-columns: repeat(18, minmax(52px, 1fr)); gap: 5px;
  min-width: 980px;
}
.ptile {
  position: relative; aspect-ratio: 1; border: none; border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-family: inherit; color: #33322e; padding: 2px;
  transition: transform .12s, box-shadow .12s, filter .2s;
}
.ptile:hover { transform: scale(1.16); z-index: 5; box-shadow: 0 8px 18px rgba(90,70,20,.25); }
.ptile .z { position: absolute; top: 3px; left: 5px; font-size: 9.5px; font-weight: 700; opacity: .75; }
.ptile .sym { font-size: clamp(15px, 1.6vw, 21px); font-weight: 800; line-height: 1.05; }
.ptile .nm { font-size: 9.5px; font-weight: 600; opacity: .8; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ptile.discovered::after {
  content: '✓'; position: absolute; bottom: 2px; right: 4px; font-size: 9px; font-weight: 800;
  color: #2e7d5b;
}
.ptile.placeholder { background: transparent; box-shadow: none; pointer-events: none; }
.ptile.dimmed { filter: grayscale(.9) opacity(.25); }
.ptile.glow { animation: glow 1s ease-in-out 3; }
@keyframes glow { 50% { box-shadow: 0 0 0 5px rgba(255,138,92,.45), 0 0 24px rgba(255,138,92,.6); transform: scale(1.18); } }
.ptile.shake { animation: shake .35s; }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.ptile.correct { animation: correct .5s; }
@keyframes correct { 40% { transform: scale(1.3); box-shadow: 0 0 0 6px rgba(76,191,166,.5); } }

/* Ficha de detalle */
#detail-panel {
  position: fixed; z-index: 90; top: 0; right: 0; height: 100vh; width: min(440px, 100vw);
  background: var(--card); box-shadow: -14px 0 40px rgba(90,70,20,.2);
  border-radius: 24px 0 0 24px; padding: 18px; overflow-y: auto;
  animation: slide-in .3s cubic-bezier(.22,1,.36,1);
  overscroll-behavior: contain; /* el scroll interno no arrastra la página */
  -webkit-overflow-scrolling: touch;
}
@keyframes slide-in { from { transform: translateX(60px); opacity: 0; } to { transform: none; opacity: 1; } }
#detail-close { position: absolute; top: 12px; right: 12px; z-index: 2; }
.detail-hero { border-radius: 20px; padding: 18px; text-align: center; margin-bottom: 14px; position: relative; }
.detail-hero .d-sym { font-size: 64px; font-weight: 800; line-height: 1; }
.detail-hero .d-name { font-size: 26px; font-weight: 800; }
.detail-hero .d-z { font-weight: 700; opacity: .8; }
.d-badge {
  display: inline-block; margin-top: 8px; padding: 4px 12px; border-radius: 999px;
  background: rgba(255,255,255,.7); font-size: 13px; font-weight: 700;
}
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin: 12px 0; }
.d-cell { background: var(--bg-soft); border-radius: 14px; padding: 9px 12px; }
.d-cell .k { font-size: 11.5px; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .4px; }
.d-cell .v { font-size: 17px; font-weight: 800; }
.atom-embed { background: var(--bg-soft); border-radius: 18px; padding: 12px; }
.atom-embed-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.atom-embed-head .k { font-size: 11.5px; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .4px; }
.atom-embed-cap { font-size: 11.5px; font-weight: 700; color: var(--accent-2); background: #fff; border-radius: 999px; padding: 2px 10px; }
.atom-viewport {
  position: relative; height: 300px; border-radius: 14px; overflow: hidden;
  background: radial-gradient(circle at 50% 38%, #ffffff, #fff1d6);
  touch-action: none; /* el gesto es del visor, no del scroll */
}
.atom-viewport canvas { display: block; width: 100% !important; height: 100% !important; }
.atom-expand-btn {
  position: absolute; right: 8px; top: 8px; z-index: 3;
  border: none; border-radius: 10px; width: 34px; height: 34px;
  background: rgba(255,255,255,.9); box-shadow: 0 3px 10px rgba(90,70,20,.2);
  font-size: 16px; line-height: 1;
}
.atom-viewport .atom-hint {
  position: absolute; left: 10px; bottom: 8px; z-index: 2;
  font-size: 11px; font-weight: 700; color: #8b7a5c;
  background: rgba(255,255,255,.75); border-radius: 999px; padding: 3px 10px; pointer-events: none;
}
.atom-legend {
  display: flex; gap: 7px; flex-wrap: wrap; justify-content: center;
  padding: 0 14px calc(14px + env(safe-area-inset-bottom));
}
.legend-chip {
  background: #fff; border-radius: 999px; padding: 4px 13px;
  font-size: 13px; font-weight: 800; box-shadow: var(--shadow);
}
/* Visor expandido a pantalla completa */
.atom-full {
  position: fixed; inset: 0; z-index: 150;
  background: radial-gradient(circle at 50% 40%, #fffdf7, #ffedd2);
  display: flex; flex-direction: column;
}
.atom-full .atom-full-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(14px + env(safe-area-inset-top)) 16px 6px;
}
.atom-full .atom-full-head h3 { margin: 0; font-size: 20px; }
.atom-full .atom-full-box { flex: 1; position: relative; margin: 6px 14px 18px; }
.atom-full .atom-full-box .atom-viewport { position: absolute; inset: 0; height: auto; border-radius: 18px; }
.atom-loading { display: flex; height: 100%; align-items: center; justify-content: center; font-weight: 700; color: var(--ink-soft); font-size: 14px; }
.story-box { background: linear-gradient(120deg, #eaf3ff, #f3ecff); border-radius: 16px; padding: 12px 14px; margin-top: 12px; }
.story-title { font-size: 14px; font-weight: 800; margin-bottom: 5px; color: #4a5fa5; }
.story-box p { margin: 0; font-size: 14.5px; font-weight: 600; line-height: 1.45; }
.facts-list { margin-top: 12px; display: flex; flex-direction: column; gap: 7px; }
.facts-list .story-title { color: #b0562e; }
.fact-item { display: flex; gap: 9px; align-items: flex-start; background: linear-gradient(120deg, #fff3d6, #ffe4ec); border-radius: 13px; padding: 9px 12px; font-size: 14px; font-weight: 600; line-height: 1.4; }
.fact-num {
  flex: 0 0 auto; width: 20px; height: 20px; border-radius: 50%; margin-top: 1px;
  background: #ff8a5c; color: #fff; font-size: 11.5px; font-weight: 800;
  display: inline-flex; align-items: center; justify-content: center;
}
.fact-box {
  background: linear-gradient(120deg, #fff3d6, #ffe4ec); border-radius: 16px; padding: 12px 14px;
  font-size: 14.5px; font-weight: 600; margin-top: 12px;
}
.fact-box b { color: #b0562e; }
.detail-actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.new-badge {
  position: absolute; top: 10px; left: 10px; background: #2e9e6b; color: white;
  font-size: 11px; font-weight: 800; padding: 3px 10px; border-radius: 999px; transform: rotate(-6deg);
}

/* Overlay 3D de la tabla */
#table3d-overlay {
  position: fixed; inset: 0; z-index: 95; background: rgba(40, 36, 28, .92);
}
#table3d-canvas { position: absolute; inset: 0; }
/* El canvas toma el tamaño del contenedor por CSS: si dependiera de sus
   atributos, resize() mediría su propio output y entraría en bucle. */
#table3d-canvas > canvas { display: block; width: 100%; height: 100%; }
#table3d-close { position: absolute; top: 16px; right: 16px; z-index: 3; }
#table3d-tip {
  position: absolute; bottom: calc(14px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  color: #f5e9d0; background: rgba(0,0,0,.35); padding: 7px 16px; border-radius: 999px;
  font-size: 13px; font-weight: 600; z-index: 3; white-space: nowrap;
}
#table3d-close { top: calc(16px + env(safe-area-inset-top)); right: calc(16px + env(safe-area-inset-right)); }
#table3d-hover {
  position: absolute; top: 16px; left: 16px; z-index: 3; color: white; pointer-events: none;
  background: rgba(0,0,0,.4); padding: 8px 14px; border-radius: 14px; font-weight: 700;
  opacity: 0; transition: opacity .15s;
}
#table3d-hover.show { opacity: 1; }
#table3d-hover .h-sym { font-size: 22px; }
#table3d-hover .h-sub { font-size: 12px; opacity: .85; }

/* ============ Modo RA (realidad aumentada sobre el papel impreso) ============ */
.ar-overlay {
  position: fixed; inset: 0; z-index: 160; overflow: hidden;
  background: #171410; /* se tapa con el vídeo apenas enciende */
}
/* Sin cámara: papel del póster como fondo del modo manual */
.ar-overlay.manual {
  background:
    radial-gradient(900px 500px at 80% -10%, #ffe9c9 0%, transparent 55%),
    radial-gradient(700px 420px at 12% 108%, #dff5ef 0%, transparent 50%),
    repeating-linear-gradient(0deg, transparent 0 34px, rgba(90,70,20,.05) 34px 35px),
    repeating-linear-gradient(90deg, transparent 0 34px, rgba(90,70,20,.05) 34px 35px),
    var(--bg);
}
.ar-video {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  opacity: 0; transition: opacity .5s;
}
.ar-video.live { opacity: 1; }
.ar-overlay.manual .ar-video { display: none; }
.ar-canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.ar-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 4;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(12px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right)) 0 calc(14px + env(safe-area-inset-left));
  pointer-events: none;
}
.ar-top .btn { pointer-events: auto; }
.ar-title {
  color: #fff8ec; font-weight: 800; font-size: clamp(13px, 3.4vw, 17px); text-align: center;
  background: rgba(23,20,16,.55); padding: 8px 16px; border-radius: 999px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ar-status {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(56px + env(safe-area-inset-bottom)); z-index: 4; max-width: 90vw;
  color: #fff8ec; background: rgba(23,20,16,.66); padding: 9px 18px; border-radius: 999px;
  font-size: 13.5px; font-weight: 700; text-align: center; pointer-events: none;
  transition: background .25s;
}
.ar-status.ok { background: rgba(46,158,107,.8); }
.ar-status.lost { background: rgba(199,84,52,.8); }
.ar-hint {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(14px + env(safe-area-inset-bottom)); z-index: 4;
  color: rgba(255,248,236,.85); font-size: 11.5px; font-weight: 700;
  background: rgba(23,20,16,.42); padding: 5px 13px; border-radius: 999px;
  white-space: nowrap; pointer-events: none;
}
/* Botón que abre el modo RA desde la ficha del explorador y el constructor */
.btn-ar {
  background: linear-gradient(120deg, var(--accent), #ffb28c); color: #fff;
  font-size: 12px; font-weight: 800; padding: 5px 12px; box-shadow: 0 3px 8px rgba(255,138,92,.35);
}
.btn-ar:hover { transform: translateY(-1px) scale(1.04); }
.atom-embed-head .k { flex: 1; } /* con el botón RA, el título ocupa el hueco libre */
.atom-full-actions { display: flex; gap: 8px; flex-shrink: 0; }
.builder-view-tools { display: inline-flex; align-items: center; gap: 10px; }

/* ============ Constructor ============ */
.builder-scene { display: flex; flex-direction: column; gap: 12px; max-width: 1080px; margin: 0 auto; padding: 14px clamp(10px, 3vw, 22px) 30px; }
.builder-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.builder-title { font-size: clamp(15px, 2.6vw, 19px); font-weight: 800; color: var(--ink); }
.builder-tray { background: #fffdf7; border: 2px solid var(--line); border-radius: 18px; padding: 12px 14px 14px; }
.builder-tray-title { font-size: 13px; font-weight: 800; color: var(--ink-soft); margin-bottom: 9px; }
.builder-tray-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 8px; }
.atom-pod {
  --pod: #999; position: relative; display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 8px 4px 7px; border-radius: 12px; cursor: grab; user-select: none; touch-action: none;
  background: color-mix(in srgb, var(--pod) 16%, white); border: 2px solid var(--pod);
  transition: transform .12s, box-shadow .12s;
}
.atom-pod:hover { transform: translateY(-3px) scale(1.04); box-shadow: 0 6px 14px color-mix(in srgb, var(--pod) 35%, transparent); }
.atom-pod.dragging { opacity: .45; cursor: grabbing; }
.pod-sym { font-size: 21px; font-weight: 900; color: var(--pod); line-height: 1.05; }
.pod-name { font-size: 10.5px; font-weight: 700; color: var(--ink-soft); }
.builder-mix {
  min-height: 150px; border-radius: 18px; border: 2.5px dashed color-mix(in srgb, var(--accent) 55%, white);
  background: color-mix(in srgb, var(--accent) 7%, white); padding: 12px; transition: background .15s, border-color .15s;
}
.builder-mix.over { background: color-mix(in srgb, var(--accent) 16%, white); border-color: var(--accent); }
.builder-mix-slots { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.mix-hint { color: var(--ink-soft); font-weight: 700; font-size: 14px; padding: 8px 4px; }
.mix-slot {
  --pod: #999; display: flex; align-items: center; gap: 7px; padding: 8px 12px 8px 9px; border-radius: 13px;
  background: color-mix(in srgb, var(--pod) 15%, white); border: 2px solid var(--pod); cursor: pointer;
  animation: slot-pop .18s ease-out;
}
@keyframes slot-pop { from { transform: scale(.7); opacity: 0; } }
.mix-slot .slot-n { font-size: 12px; font-weight: 900; color: var(--pod); }
.mix-aux { display: flex; gap: 8px; margin-left: auto; align-items: center; }
/* Escenario: visor 3D arriba, ficha al lado; teclado de elementos al fondo. */
.builder-stage { display: grid; grid-template-columns: minmax(280px, 1.1fr) minmax(280px, 1fr); gap: 12px; align-items: stretch; }
@media (max-width: 760px) { .builder-stage { grid-template-columns: 1fr; } }
/* Teclado: pods tipo botón con respuesta táctil marcada. */
.atom-pod:active { transform: scale(.92); }
.builder-tray-grid { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); }
/* Botón Enviar: protagonista de la pantalla de entrada. */
#btn-send { min-width: 128px; box-shadow: 0 4px 0 color-mix(in srgb, var(--accent) 60%, #7a4be0); }
#btn-send:active { transform: translateY(2px); box-shadow: 0 2px 0 color-mix(in srgb, var(--accent) 60%, #7a4be0); }
#btn-send:disabled { opacity: .5; box-shadow: none; }
/* Línea de estado bajo la pantalla de entrada. */
.entry-status { margin-top: 10px; font-size: 12.5px; font-weight: 700; color: var(--ink-soft); }
.entry-status.error { color: #c0392b; }
/* Sacudida del visor cuando la mezcla no forma nada conocido. */
.builder-view.shake { animation: view-shake .6s cubic-bezier(.36,.07,.19,.97); }
@keyframes view-shake {
  10%, 90% { transform: translateX(-1.5px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-5px); }
  40%, 60% { transform: translateX(5px); }
}
.builder-bottom { display: grid; grid-template-columns: minmax(280px, 1.05fr) minmax(280px, 1fr); gap: 12px; align-items: start; }
@media (max-width: 760px) { .builder-bottom { grid-template-columns: 1fr; } }
.builder-info { background: #fffdf7; border: 2px solid var(--line); border-radius: 18px; padding: 14px 16px; min-height: 190px; }
.info-empty { color: var(--ink-soft); font-weight: 700; padding: 26px 6px; text-align: center; }
.mol-head { display: flex; gap: 13px; align-items: center; margin-bottom: 8px; }
.mol-formula { font-size: 34px; font-weight: 900; color: var(--accent); letter-spacing: -1px; }
.mol-formula.unknown { color: var(--ink-soft); }
.mol-name { font-size: 17px; font-weight: 900; color: var(--ink); }
.mol-known { font-size: 10.5px; font-weight: 800; color: #2e9e6b; background: #e3f4dd; padding: 2px 8px; border-radius: 999px; margin-left: 7px; vertical-align: 2px; }
.mol-owned { font-size: 10.5px; font-weight: 800; color: #8a5cf5; background: #ece2fa; padding: 2px 8px; border-radius: 999px; margin-left: 5px; vertical-align: 2px; }
.mol-counter { font-size: 12.5px; font-weight: 800; color: var(--ink); background: #fffdf7; border: 2px solid var(--line); border-radius: 999px; padding: 6px 13px; }
.mol-counter b { color: #8a5cf5; }
.mol-sub { font-size: 12.5px; color: var(--ink-soft); font-weight: 700; }
.mol-uses, .mol-fact { font-size: 13.5px; font-weight: 600; background: var(--paper); border-radius: 10px; padding: 7px 11px; margin-top: 7px; }
.mol-fact { background: color-mix(in srgb, var(--accent) 10%, white); }
.mol-ingredients { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.ing-chip { --pod: #999; font-size: 12.5px; font-weight: 800; color: var(--pod); background: color-mix(in srgb, var(--pod) 13%, white); border: 1.5px solid var(--pod); border-radius: 10px; padding: 4px 9px; }
.ing-chip small { color: var(--ink-soft); font-weight: 700; }
.mol-note { font-size: 11.5px; color: var(--ink-soft); margin-top: 9px; }
/* Dato del libro de Química tras responder en la Trivia. */
.book-note { margin-top: 12px; font-size: 12.5px; font-weight: 600; line-height: 1.45; color: #5b3fa8; background: #f3edff; border: 1.5px dashed #b49cf0; border-radius: 12px; padding: 9px 12px; }
.book-note { animation: booknote .35s ease-out; }
@keyframes booknote { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.builder-view { background: #fffdf7; border: 2px solid var(--line); border-radius: 18px; padding: 12px 14px; }
.builder-view-head { font-size: 13px; font-weight: 800; color: var(--ink-soft); margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }
.builder-view-hint { font-size: 11px; font-weight: 700; opacity: .8; }
.builder-3d-box { height: 240px; position: relative; }
.builder-3d-box canvas { width: 100% !important; height: 100% !important; display: block; touch-action: none; }
.challenge-banner { display: flex; gap: 10px; align-items: center; background: linear-gradient(120deg, #ffe9d2, #ffd6e0); border: 2px solid var(--accent); border-radius: 16px; padding: 10px 16px; }
.challenge-emoji { font-size: 26px; }
.challenge-main { font-size: 18px; font-weight: 900; color: var(--ink); }
.challenge-sub { font-size: 12px; font-weight: 700; color: var(--ink-soft); }
.challenge-timer { text-align: center; font-size: 26px; font-weight: 900; color: var(--ink); background: #fffdf7; border: 2px solid var(--line); border-radius: 14px; padding: 6px; }
.challenge-timer.won { color: #2e9e6b; border-color: #2e9e6b; }
.challenge-timer small { font-size: 13px; }
.card-builder { background: linear-gradient(135deg, #e6f7f0, #d9f2ea); }
.card-builder .mode-emoji { filter: drop-shadow(0 3px 6px rgba(46, 158, 107, .25)); }

/* ============ Trivia ============ */
.game-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin: 6px 0 14px; }
.game-title { font-size: 26px; font-weight: 800; margin: 0; }
.lives { font-size: 22px; letter-spacing: 2px; }
.timerbar { height: 10px; background: var(--bg-soft); border-radius: 999px; overflow: hidden; margin-bottom: 16px; }
.timerbar > div { height: 100%; width: 100%; background: linear-gradient(90deg, var(--accent-2), #8ed081); border-radius: 999px; }
.timerbar.urgent > div { background: linear-gradient(90deg, #f4747c, #f2a65a); }

.q-card { background: var(--card); border-radius: 22px; padding: 26px; box-shadow: var(--shadow); text-align: center; }
.q-progress { color: var(--ink-soft); font-weight: 700; font-size: 14px; margin-bottom: 10px; }
.q-text { font-size: clamp(20px, 3.4vw, 27px); font-weight: 800; margin: 0 0 6px; }
.q-sub { color: var(--ink-soft); font-weight: 600; margin: 0 0 18px; }
.q-sub .chip { background: var(--bg-soft); border-radius: 999px; padding: 3px 12px; }
.q-emoji { font-size: 52px; display: block; margin-bottom: 4px; }
.answers { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; margin-top: 8px; }
.answer {
  border: 3px solid var(--line); background: #fffdf7; border-radius: 18px; padding: 14px 12px;
  font-size: 17.5px; font-weight: 700; color: var(--ink); transition: transform .12s, border-color .15s, background .2s;
  display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 64px;
}
.answer:hover:not(:disabled) { transform: translateY(-3px); border-color: var(--accent); }
.answer.correct { background: #e2f6ec; border-color: #2e9e6b; }
.answer.wrong { background: #fde5e6; border-color: #f4747c; animation: shake .35s; }
.answer .a-sym { font-size: 24px; font-weight: 800; }
.streak-tag { display: inline-block; background: #ffe3bd; border-radius: 999px; padding: 2px 12px; font-weight: 800; font-size: 14px; }

.result-card { background: var(--card); border-radius: 26px; padding: 30px; text-align: center; box-shadow: var(--shadow); }
.result-emoji { font-size: 64px; }
.result-title { font-size: 30px; font-weight: 800; margin: 6px 0; }
.result-sub { color: var(--ink-soft); font-weight: 600; font-size: 16px; }
.result-stats { display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; margin: 18px 0; }
.rstat { background: var(--bg-soft); border-radius: 16px; padding: 10px 18px; }
.rstat .n { font-size: 24px; font-weight: 800; }
.rstat .l { font-size: 12.5px; color: var(--ink-soft); font-weight: 700; }
.review { text-align: left; margin: 10px 0 18px; }
.review-item { display: flex; gap: 10px; align-items: baseline; padding: 8px 12px; border-radius: 12px; margin-bottom: 6px; font-size: 14.5px; font-weight: 600; }
.review-item.ok { background: #e2f6ec; }
.review-item.bad { background: #fde5e6; }
.actions-row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* ============ Hunter ============ */
.hunter-hud { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin: 6px 0 10px; }
.hud-big {
  background: var(--card); border-radius: 16px; padding: 8px 16px; box-shadow: var(--shadow);
  font-weight: 800; font-size: 19px; display: flex; align-items: center; gap: 8px;
}
.hud-big small { font-size: 12px; color: var(--ink-soft); font-weight: 700; }
#hunter-target {
  background: linear-gradient(120deg, #ffe3bd, #ffd9e6); border-radius: 20px; padding: 16px 22px;
  box-shadow: var(--shadow); margin-bottom: 14px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
#hunter-target .t-emoji { font-size: 40px; }
#hunter-target .t-main { font-size: clamp(20px, 3vw, 26px); font-weight: 800; }
#hunter-target .t-hint { font-weight: 600; color: #7a6a4f; font-size: 15px; }
.combo-tag { background: #ff8a5c; color: white; border-radius: 999px; padding: 4px 14px; font-weight: 800; animation: pulse .8s infinite alternate; }

/* ============ Memory ============ */
.memory-board { display: grid; gap: 10px; margin: 14px auto; max-width: 900px; }
.mcard { aspect-ratio: 3/4; perspective: 800px; border: none; background: none; padding: 0; }
.mcard-inner { position: relative; width: 100%; height: 100%; transition: transform .4s cubic-bezier(.22,1,.36,1); transform-style: preserve-3d; }
.mcard.flipped .mcard-inner, .mcard.matched .mcard-inner { transform: rotateY(180deg); }
.mface {
  position: absolute; inset: 0; border-radius: 16px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; backface-visibility: hidden; font-weight: 800;
  box-shadow: var(--shadow);
}
.mface.back {
  background: linear-gradient(145deg, #9d7bde, #e56fb1); color: white; font-size: 34px;
}
.mface.front { transform: rotateY(180deg); background: var(--card); font-size: 22px; padding: 6px; text-align: center; }
.mface.front .m-sub { font-size: 11px; color: var(--ink-soft); font-weight: 600; }
.mface.front.sym-face { background: #ddeefd; font-size: 40px; }
.mcard.matched .mface.front { background: #e2f6ec; outline: 3px solid #2e9e6b; }
.mcard.matched { animation: correct .5s; }

/* ============ Toasts & confeti ============ */
#toasts {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 200;
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none;
  width: max-content; max-width: min(92vw, 480px);
}
#toasts .toast { max-width: 100%; text-align: center; }
@media (max-width: 720px) {
  #toasts { top: calc(10px + env(safe-area-inset-top)); }
  #toasts .toast { font-size: 13.5px; padding: 8px 16px; }
}
.toast {
  background: #33322e; color: #fff8ec; border-radius: 999px; padding: 10px 22px;
  font-weight: 700; font-size: 15px; box-shadow: 0 10px 30px rgba(0,0,0,.25);
  animation: toast-in .3s cubic-bezier(.22,1,.36,1);
}
.toast.medal { background: linear-gradient(120deg, #f2a65a, #e56fb1); }
.toast.error { background: #c0392b; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-14px) scale(.9); } to { opacity: 1; transform: none; } }
#confetti-layer { position: fixed; inset: 0; pointer-events: none; z-index: 300; overflow: hidden; }
.confetti { position: absolute; width: 10px; height: 14px; top: -20px; animation: confetti-fall linear forwards; border-radius: 3px; }
@keyframes confetti-fall { to { transform: translateY(110vh) rotate(720deg); } }

/* ============ Modal genérico ============ */
.modal-back {
  position: fixed; inset: 0; background: rgba(51,50,46,.5); z-index: 120;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  background: var(--card); border-radius: 24px; padding: 26px; max-width: 480px; width: 100%;
  box-shadow: var(--shadow); text-align: center; animation: pop-in .3s cubic-bezier(.22,1,.36,1);
}
.modal h2 { margin: 0 0 6px; font-size: 26px; }
.modal p { color: var(--ink-soft); font-weight: 600; margin: 4px 0 16px; }
.opt-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }

/* ============ Responsive ============ */
/* Targets táctiles ≥44px en pantallas pequeñas */
@media (pointer: coarse) {
  .btn, .btn-icon, .legend-item, .mode-card, .answer, .ptile { min-height: 44px; }
  .btn-icon { width: 44px; height: 44px; }
  .legend-item { min-height: 40px; }
}

/* Accesibilidad: menos movimiento si el usuario lo pide */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ============ Móvil (≤720px) ============ */
@media (max-width: 720px) {
  #hud-xp .xpbar { width: 54px; }
  .hud-chip { font-size: 11.5px; padding: 5px 9px; gap: 5px; }
  #hud { gap: 6px; }
  #topbar { padding: 8px 2px; gap: 6px; }
  .home-hero { padding-top: 12px; }
  .title { font-size: clamp(38px, 11vw, 52px); }
  .subtitle { font-size: 16px; }
  .tagline { font-size: 11px; letter-spacing: .22em; text-indent: .22em; white-space: nowrap; } /* una sola línea en móvil */
  .mode-card { padding: 16px; }
  .mode-name { font-size: 20px; }
  .mode-desc { font-size: 13px; }
  .stat-card { padding: 11px 14px; }
  .stat-num { font-size: 18px; }
  .stat-icon { font-size: 25px; }

  /* Tabla compacta y legible sin zoom */
  #ptable, .ptable-grid { grid-template-columns: repeat(18, minmax(40px, 1fr)); gap: 3px; min-width: 760px; }
  .ptile { border-radius: 8px; }
  .ptile .z { font-size: 8px; top: 2px; left: 3.5px; }
  .ptile .sym { font-size: 15px; }
  .ptile .nm { display: none; } /* Símbolo grande > nombre microscópico */
  .ptile:hover { transform: none; } /* Sin hover fantasma tras tocar */

  .explorer-toolbar { gap: 7px; }
  #search { flex-basis: 100%; min-width: 0; max-width: none; order: -1; font-size: 16px; }
  /* La ficha sube desde abajo como bottom-sheet (patrón móvil) */
  #detail-panel {
    width: 100vw; height: 82dvh; top: auto; bottom: 0; right: 0;
    border-radius: 24px 24px 0 0; animation: slide-up .3s cubic-bezier(.22,1,.36,1);
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
  }
  @keyframes slide-up { from { transform: translateY(60px); opacity: 0; } to { transform: none; opacity: 1; } }
  .detail-hero .d-sym { font-size: 52px; }
  .detail-grid { grid-template-columns: 1fr 1fr; gap: 7px; }
  .atom-viewport { height: 240px; }
  .story-box p { font-size: 13.5px; }
  .fact-item { font-size: 13px; }

  .q-card { padding: 16px; }
  .q-text { font-size: 19px; }
  .answers { grid-template-columns: 1fr; }
  .result-card { padding: 20px; }
  .result-title { font-size: 23px; }
  .rstat { padding: 8px 13px; }
  .rstat .n { font-size: 19px; }
  .hunter-hud { gap: 8px; }
  .hud-big { font-size: 15.5px; padding: 7px 11px; }
  #hunter-target { padding: 12px 14px; gap: 10px; }
  #hunter-target .t-main { font-size: 18.5px; }
  .mcard { border-radius: 13px; }
  .mface.back { font-size: 26px; }
  .mface.front { font-size: 16px; }
  .mface.front.sym-face { font-size: 30px; }
  /* Tap-highlight de las cartas coincide con el tema y no parpadea */
  .mcard { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
  #table3d-tip { font-size: 11px; padding: 6px 12px; max-width: 92vw; white-space: normal; text-align: center; }
  #table3d-hover { display: none; } /* No hay hover en táctil */
}

/* ============ Móvil pequeño (≤480px) ============ */
@media (max-width: 480px) {
  #app { padding: 8px 10px 32px; }
  .title { font-size: 36px; letter-spacing: 1px; }
  .home-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .mode-emoji { font-size: 30px; }
  .mode-name { font-size: 17px; }
  .mode-desc { display: none; }
  .hud-chip#hud-discovered { display: none; } /* Priorizar XP y nivel */
  #table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 12px; }
}
