:root {
  --txt: #eef3ff; --mut: #a9bbdd; --panel: rgba(12, 22, 44, 0.86); --line: rgba(160, 190, 255, 0.25);
  --ok: #3ddc84; --bad: #ff6b7a; --acc: #19d3c5; --gold: #ffd23f;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%; height: 100%; overflow: hidden; color: var(--txt);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: radial-gradient(ellipse at 50% 38%, #3a68a8 0%, #1a2f58 52%, #0a1226 100%);
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#app {
  position: fixed; inset: 0; display: flex; flex-direction: column; pointer-events: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.spacer { flex: 1; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
button:focus-visible, .spc:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* Barra superior */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; pointer-events: auto; }
.level-info, .stars, .tools { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 8px 14px; backdrop-filter: blur(6px); }
.level-tag { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--mut); }
.level-name { font-size: 17px; font-weight: 800; }
.stars { display: flex; gap: 12px; color: var(--gold); font-size: 17px; letter-spacing: 1px; }
.tools { display: flex; gap: 6px; padding: 6px; }
.tool { width: 44px; height: 44px; border-radius: 12px; font-size: 20px; background: rgba(255, 255, 255, 0.08); transition: transform 0.12s, background 0.12s; }
.tool:hover:not(:disabled) { background: rgba(255, 255, 255, 0.18); }
.tool:active:not(:disabled) { transform: scale(0.93); }
.tool:disabled { opacity: 0.35; cursor: default; }

/* Panel inferior */
.dock { width: min(1000px, 100%); margin: 0 auto; padding: 6px 12px 12px; display: flex; flex-direction: column; gap: 8px; pointer-events: auto; }
.mascot { display: flex; align-items: center; gap: 10px; }
.face { flex: none; border-radius: 50%; border: 3px solid var(--gold); background-color: #12304d; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4); }
.face.big { margin: 0 auto 8px; width: 96px; height: 96px; }
.bubble {
  position: relative; flex: 1; min-height: 64px; max-height: 120px; overflow: auto; display: flex; align-items: center;
  background: #f4f8ff; color: #14203c; border-radius: 16px; padding: 10px 14px; font-size: 15px; line-height: 1.35; font-weight: 600;
}
.bubble::before { content: ''; position: absolute; left: -8px; top: 50%; margin-top: -8px; border: 8px solid transparent; border-left: 0; border-right-color: #f4f8ff; }
.mascot.bump .bubble { animation: bump 0.35s ease-out; }
@keyframes bump { 0% { transform: scale(0.94); } 60% { transform: scale(1.03); } 100% { transform: scale(1); } }

.equation { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px; }
.equation.locked { pointer-events: none; opacity: 0.7; }
.plus, .arrow { font-size: 26px; font-weight: 800; color: var(--mut); }
.spc { background: var(--panel); border: 2px solid var(--line); border-radius: 16px; padding: 8px 10px 6px; display: flex; flex-direction: column; align-items: center; gap: 2px; transition: border-color 0.15s, box-shadow 0.15s; }
.spc.sel { border-color: var(--acc); box-shadow: 0 0 0 3px rgba(25, 211, 197, 0.25); }
.stepper { display: flex; align-items: center; gap: 6px; }
.step { width: 44px; height: 44px; border-radius: 50%; background: var(--acc); color: #05242a; font-size: 26px; font-weight: 900; line-height: 1; transition: transform 0.1s; }
.step.minus { background: #ffb347; color: #3a2300; }
.step:active:not(:disabled) { transform: scale(0.9); }
.step:disabled { opacity: 0.3; cursor: default; }
.num { min-width: 34px; text-align: center; font-size: 34px; font-weight: 900; color: var(--gold); font-variant-numeric: tabular-nums; }
.num.pop { animation: numpop 0.3s ease-out; }
@keyframes numpop { 0% { transform: scale(1.6); } 100% { transform: scale(1); } }
.formula { font-size: 24px; font-weight: 800; padding: 2px 8px; border-radius: 8px; }
.formula:hover { background: rgba(255, 255, 255, 0.1); }
.spc.hinted { animation: hinted 0.9s ease-in-out 3; }
@keyframes hinted { 50% { box-shadow: 0 0 0 6px rgba(255, 210, 63, 0.65); border-color: var(--gold); } }

.foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ledger { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.ledger-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--mut); }
.chip, .mass { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 12px; background: var(--panel); border: 2px solid var(--line); font-size: 15px; font-variant-numeric: tabular-nums; transition: border-color 0.2s, background 0.2s; }
.chip.ok { border-color: var(--ok); background: rgba(61, 220, 132, 0.16); }
.chip.bad { border-color: var(--bad); background: rgba(255, 107, 122, 0.16); }
.chip .dot { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, 0.5); }
.chip .mark { font-weight: 900; }
.chip.ok .mark { color: var(--ok); }
.chip.bad .mark { color: var(--bad); }
.mass { font-size: 13px; color: var(--mut); border-style: dashed; }
.mass.ok { color: var(--ok); border-color: var(--ok); }

.btn { min-height: 44px; padding: 10px 18px; border-radius: 12px; background: rgba(255, 255, 255, 0.12); font-weight: 700; border: 1px solid var(--line); transition: transform 0.1s, filter 0.15s; }
.btn:hover:not(:disabled) { filter: brightness(1.15); }
.btn:active:not(:disabled) { transform: scale(0.96); }
.btn.primary { background: linear-gradient(180deg, #34d27b, #1a9e57); border-color: #5ff0a0; color: #04210f; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.react { min-height: 52px; font-size: 18px; padding: 10px 26px; margin-left: auto; }
.btn.react.ready { animation: ready 1s ease-in-out infinite; }
@keyframes ready { 50% { box-shadow: 0 0 0 8px rgba(95, 240, 160, 0.35); transform: scale(1.04); } }

/* Tarjetas */
#overlay { position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(6, 12, 28, 0.74); backdrop-filter: blur(4px); }
#overlay[hidden] { display: none; }
.card { width: min(480px, 100%); max-height: 100%; overflow: auto; text-align: center; background: #14233f; border: 2px solid var(--line); border-radius: 22px; padding: 22px 22px 20px; box-shadow: 0 14px 50px rgba(0, 0, 0, 0.55); animation: popin 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes popin { from { opacity: 0; transform: scale(0.88); } }
.card-title { font-size: 24px; line-height: 1.2; margin-bottom: 10px; }
.card-text { color: #d3def5; font-size: 16px; line-height: 1.5; margin-bottom: 12px; }
.intro-eq { font-size: 22px; font-weight: 800; color: var(--gold); margin: 6px 0 12px; }
.card-tip { background: rgba(25, 211, 197, 0.12); border: 1px solid rgba(25, 211, 197, 0.45); border-radius: 12px; padding: 10px 12px; font-size: 14.5px; line-height: 1.45; text-align: left; margin-bottom: 10px; }
.card-fact { font-size: 13.5px; color: var(--mut); line-height: 1.45; font-style: italic; margin-bottom: 4px; }
.big-stars { font-size: 38px; color: var(--gold); letter-spacing: 4px; margin-bottom: 10px; }
.help-list { text-align: left; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; font-size: 14.5px; line-height: 1.4; color: #d3def5; margin-bottom: 8px; }
.card-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 12px; }

@media (max-width: 640px) {
  .topbar { padding: 6px 8px; gap: 6px; }
  .level-info { padding: 6px 10px; min-width: 0; }
  .level-name { font-size: 14px; }
  .stars { display: none; }
  .tool { width: 40px; height: 40px; font-size: 18px; }
  .dock { padding: 4px 8px 8px; gap: 6px; }
  .bubble { font-size: 13px; min-height: 52px; max-height: 96px; padding: 8px 10px; }
  .equation { gap: 4px; }
  .plus, .arrow { font-size: 20px; }
  .spc { padding: 6px 4px 4px; }
  .stepper { flex-direction: column-reverse; gap: 2px; }
  .num { font-size: 28px; }
  .formula { font-size: 19px; padding: 0 4px; }
  .btn.react { width: 100%; margin-left: 0; }
  .card { padding: 16px; }
  .card-title { font-size: 20px; }
}
@media (prefers-reduced-motion: reduce) {
  .btn.react.ready, .spc.hinted, .mascot.bump .bubble, .card { animation: none; }
}
