:root {
  --bg: #12071f;
  --bg2: #1a0b2e;
  --card: rgba(255, 255, 255, .07);
  --card2: rgba(255, 255, 255, .12);
  --line: rgba(255, 255, 255, .12);
  --tx: #f6f1ff;
  --mut: #b9a9d6;
  --pri: #a855f7;
  --pink: #ec4899;
  --cyan: #22d3ee;
  --ok: #22c55e;
  --ko: #f43f5e;
  --gold: #fbbf24;
  --r: 20px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--tx); }
body {
  font: 500 17px/1.45 Nunito, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  min-height: 100dvh; overscroll-behavior-y: none;
  background:
    radial-gradient(900px 500px at 10% -10%, rgba(168, 85, 247, .35), transparent 60%),
    radial-gradient(700px 400px at 110% 10%, rgba(236, 72, 153, .22), transparent 60%),
    radial-gradient(700px 500px at 50% 120%, rgba(34, 211, 238, .14), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}
h1, h2, h3, .fred { font-family: Fredoka, Nunito, system-ui, sans-serif; letter-spacing: .2px; margin: 0; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
a { color: inherit; text-decoration: none; }
b { font-weight: 800; }
#app { max-width: 560px; margin: 0 auto; padding: calc(14px + var(--safe-t)) 16px calc(96px + var(--safe-b)); min-height: 100dvh; }
body.noTabs #app { padding-bottom: calc(24px + var(--safe-b)); }
body.noTabs .tabs { display: none; }

/* ── tab bar ── */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: center;
  padding: 6px 8px calc(6px + var(--safe-b)); background: rgba(18, 7, 31, .86); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabs a { flex: 1; max-width: 140px; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 0; border-radius: 14px; font-size: 12.5px; font-weight: 800; color: var(--mut); }
.tabs a span { font-size: 24px; line-height: 1.1; filter: grayscale(.6); transition: transform .15s; }
.tabs a.on { color: var(--tx); background: rgba(168, 85, 247, .18); }
.tabs a.on span { filter: none; transform: translateY(-2px) scale(1.08); }

/* ── generic ── */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; }
.row { display: flex; align-items: center; gap: 12px; }
.col { display: flex; flex-direction: column; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.mut { color: var(--mut); }
.small { font-size: 14px; }
.center { text-align: center; }
.mt { margin-top: 16px; } .mt2 { margin-top: 24px; } .mb { margin-bottom: 12px; }
.sec { font: 600 19px Fredoka, sans-serif; margin: 26px 2px 12px; display: flex; align-items: center; gap: 8px; }
.btn {
  display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; min-height: 58px; padding: 12px 18px;
  border-radius: 18px; font: 600 19px Fredoka, sans-serif; color: #fff;
  background: linear-gradient(135deg, var(--pri), var(--pink)); box-shadow: 0 6px 0 #6b21a8, 0 10px 24px rgba(168, 85, 247, .35);
  transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #6b21a8; }
.btn.alt { background: var(--card2); box-shadow: 0 5px 0 rgba(0, 0, 0, .35); border: 1px solid var(--line); }
.btn.ok { background: linear-gradient(135deg, #16a34a, #22c55e); box-shadow: 0 6px 0 #14532d; }
.btn.cyan { background: linear-gradient(135deg, #0891b2, #22d3ee); box-shadow: 0 6px 0 #155e75; }
.btn.gold { background: linear-gradient(135deg, #f59e0b, #fbbf24); box-shadow: 0 6px 0 #92400e; color: #2a1600; }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn.sm { min-height: 46px; font-size: 16px; border-radius: 14px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--card2); font-weight: 800; font-size: 15px; }
.bar { height: 12px; border-radius: 99px; background: rgba(255, 255, 255, .1); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--cyan), var(--pri), var(--pink)); transition: width .5s; }
.x { width: 44px; height: 44px; border-radius: 14px; background: var(--card2); font-size: 20px; display: grid; place-items: center; flex: none; }

/* ── home ── */
.hello { display: flex; align-items: center; gap: 12px; }
.ava { width: 56px; height: 56px; border-radius: 18px; display: grid; place-items: center; font-size: 32px; background: linear-gradient(135deg, var(--pri), var(--pink)); flex: none; }
.hello h1 { font-size: 26px; }
.stats3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 10px 6px; text-align: center; }
.stat b { display: block; font: 700 22px Fredoka, sans-serif; }
.stat span { font-size: 12.5px; color: var(--mut); font-weight: 800; }
.daily { position: relative; overflow: hidden; background: linear-gradient(135deg, #7c3aed, #db2777); border: 0; }
.daily::after { content: '📅'; position: absolute; right: -6px; bottom: -14px; font-size: 92px; opacity: .25; transform: rotate(-12deg); }
.daily.done { background: linear-gradient(135deg, #15803d, #0d9488); }
.daily.done::after { content: '✅'; }
.daily h3 { font-size: 21px; }
.path { display: flex; flex-direction: column; gap: 12px; }
.world { display: flex; align-items: center; gap: 14px; padding: 10px; border-radius: 22px; background: var(--card); border: 1px solid var(--line); position: relative; }
.world:active { transform: scale(.98); }
.world .thumb { width: 74px; height: 74px; border-radius: 18px; flex: none; background: var(--c); overflow: hidden; display: grid; place-items: center; font-size: 36px; position: relative; }
.world .thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.world .num { position: absolute; top: -6px; left: -6px; width: 28px; height: 28px; border-radius: 50%; background: var(--bg2); border: 2px solid var(--c); font: 700 14px Fredoka; display: grid; place-items: center; z-index: 1; }
.world h3 { font-size: 18px; line-height: 1.2; }
.world .sub { font-size: 13.5px; color: var(--mut); margin-top: 2px; }
.stars { font-size: 15px; letter-spacing: 1px; margin-top: 4px; }
.stars .off { filter: grayscale(1) brightness(.5); }
.world.next { border-color: var(--c); box-shadow: 0 0 0 2px var(--c), 0 0 24px color-mix(in srgb, var(--c) 45%, transparent); }
.world.next::before { content: '¡Sigue aquí!'; position: absolute; right: 10px; top: -10px; background: var(--c); color: #fff; font: 700 12px Fredoka; padding: 3px 10px; border-radius: 99px; }

/* ── world page ── */
.hero { position: relative; border-radius: 26px; overflow: hidden; aspect-ratio: 16 / 10; background: var(--c); display: grid; place-items: center; font-size: 80px; }
.hero img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.hero .shade { position: absolute; inset: auto 0 0 0; padding: 50px 16px 14px; background: linear-gradient(transparent, rgba(10, 3, 20, .92)); }
.hero h1 { font-size: 26px; }
.hero .top { position: absolute; top: 12px; left: 12px; }
.acts { display: grid; gap: 14px; margin-top: 18px; }
.act { display: flex; align-items: center; gap: 14px; padding: 16px; border-radius: 22px; background: var(--card); border: 1px solid var(--line); text-align: left; width: 100%; }
.act .ic { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; font-size: 30px; background: var(--card2); flex: none; }
.act h3 { font-size: 19px; }
.act p { margin: 2px 0 0; font-size: 14px; color: var(--mut); }
.act .chk { margin-left: auto; font-size: 22px; }

/* ── stories ── */
.storyTop { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.segs { display: flex; gap: 4px; flex: 1; }
.segs i { flex: 1; height: 5px; border-radius: 9px; background: rgba(255, 255, 255, .18); }
.segs i.on { background: #fff; }
.story { min-height: calc(100dvh - 210px - var(--safe-t) - var(--safe-b)); display: flex; flex-direction: column; border-radius: 28px; padding: 22px 18px; position: relative; overflow: hidden;
  background: linear-gradient(160deg, color-mix(in srgb, var(--c) 55%, #12071f), #1a0b2e 70%); border: 1px solid var(--line); animation: pop .25s ease-out; }
.story .em { font-size: 64px; line-height: 1; }
.story h2 { font-size: 27px; margin: 12px 0 14px; line-height: 1.15; }
.easy { background: rgba(255, 255, 255, .1); border-radius: 18px; padding: 14px 16px; font-size: 19px; font-weight: 700; line-height: 1.4; }
.easy .lbl { display: block; font: 700 13px Fredoka; color: var(--gold); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 4px; }
.more { margin-top: 14px; }
.more summary { list-style: none; cursor: pointer; font: 600 16px Fredoka; color: var(--cyan); padding: 10px 0; }
.more summary::-webkit-details-marker { display: none; }
.more .tx { font-size: 16px; line-height: 1.55; color: #e9defa; }
.exam { margin-top: 14px; border: 2px dashed var(--gold); border-radius: 16px; padding: 12px 14px; font-size: 15.5px; }
.exam .lbl { font: 700 14px Fredoka; color: var(--gold); display: block; margin-bottom: 2px; }
table.vs { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 4px; }
table.vs th { text-align: left; padding: 6px; color: var(--gold); font-family: Fredoka; }
table.vs td { padding: 6px; border-top: 1px solid var(--line); vertical-align: top; }
table.vs td:first-child { color: #fda4af; } table.vs td:last-child { color: #86efac; }
.storyNav { display: grid; grid-template-columns: 1fr 2fr; gap: 12px; margin-top: 16px; }

/* ── quiz ── */
.qTop { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.qTop .bar { flex: 1; height: 16px; }
.combo { font: 700 16px Fredoka; color: var(--gold); min-width: 54px; text-align: right; }
.combo.hot { animation: pulse .6s infinite alternate; }
.qType { font: 700 13px Fredoka; text-transform: uppercase; letter-spacing: 1px; color: var(--cyan); }
.qText { font: 600 23px/1.3 Fredoka, sans-serif; margin: 6px 0 20px; }
.opts { display: grid; gap: 12px; }
.opt { text-align: left; padding: 16px 18px; min-height: 60px; border-radius: 18px; background: var(--card); border: 2px solid var(--line); font-weight: 800; font-size: 17.5px; box-shadow: 0 4px 0 rgba(0, 0, 0, .35); transition: transform .08s; }
.opt:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, .35); }
.opt.sel { border-color: var(--pri); background: rgba(168, 85, 247, .2); }
.opt.good { border-color: var(--ok); background: rgba(34, 197, 94, .22); }
.opt.bad { border-color: var(--ko); background: rgba(244, 63, 94, .22); animation: shake .35s; }
.opt.dim { opacity: .4; }
.tf { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.tf .opt { text-align: center; font: 700 21px Fredoka; min-height: 92px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
.tf .opt span { font-size: 30px; }
.match { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.match .opt { padding: 12px; font-size: 15.5px; min-height: 64px; text-align: center; display: flex; align-items: center; justify-content: center; }
.match .opt.done { opacity: .35; border-color: var(--ok); pointer-events: none; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chips .opt { padding: 12px 14px; min-height: 0; font-size: 16px; }
.slots { min-height: 70px; border: 2px dashed var(--line); border-radius: 18px; padding: 10px; display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.slots .opt { padding: 10px 14px; min-height: 0; font-size: 16px; display: flex; gap: 10px; align-items: center; }
.slots .n { width: 26px; height: 26px; border-radius: 50%; background: var(--pri); display: grid; place-items: center; font: 700 14px Fredoka; flex: none; }
.slots:empty::before { content: 'Toca en orden 👇'; color: var(--mut); padding: 12px; }
.sortCard { font: 600 22px/1.3 Fredoka; text-align: center; padding: 28px 18px; border-radius: 22px; background: var(--card2); min-height: 140px; display: grid; place-items: center; animation: pop .2s; }
.sortBins { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.sortBins .opt { text-align: center; font: 700 18px Fredoka; min-height: 76px; }
.sortCount { text-align: center; margin-top: 12px; color: var(--mut); font-weight: 800; }

.fb { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; padding: 16px 16px calc(16px + var(--safe-b)); animation: up .22s ease-out; }
.fb > div { max-width: 560px; margin: 0 auto; }
.fb.good { background: #0f3d23; border-top: 3px solid var(--ok); }
.fb.bad { background: #4a0f1f; border-top: 3px solid var(--ko); }
.fb h3 { font-size: 23px; display: flex; align-items: center; gap: 8px; }
.fb p { margin: 6px 0 14px; font-size: 16px; }
.fb .ans { font-weight: 800; }
.spacer { height: 210px; }

/* ── results ── */
.res { text-align: center; padding-top: 20px; }
.res .big { font-size: 90px; line-height: 1; animation: pop .4s; }
.res h1 { font-size: 32px; margin: 14px 0 6px; }
.res .stars { font-size: 46px; letter-spacing: 6px; margin: 12px 0; }
.resGrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 18px 0; }

/* ── carnet ── */
.lic { background: linear-gradient(135deg, #0e7490, #6d28d9); border: 0; position: relative; overflow: hidden; }
.lic::after { content: '🪪'; position: absolute; right: -10px; top: -16px; font-size: 110px; opacity: .2; transform: rotate(12deg); }
.lic h2 { font-size: 26px; }
.rules { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.rules div { background: rgba(0, 0, 0, .22); border-radius: 14px; padding: 8px 4px; text-align: center; font-size: 12.5px; font-weight: 800; }
.rules b { display: block; font: 700 22px Fredoka; }
.hist { display: flex; flex-direction: column; gap: 8px; }
.hist .row { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; font-size: 15px; }
.tag { padding: 3px 10px; border-radius: 99px; font: 700 13px Fredoka; }
.tag.ok { background: rgba(34, 197, 94, .25); color: #86efac; } .tag.ko { background: rgba(244, 63, 94, .25); color: #fda4af; }
.nums { display: flex; gap: 6px; overflow-x: auto; padding: 4px 2px 10px; scrollbar-width: none; }
.nums::-webkit-scrollbar { display: none; }
.nums button { flex: none; width: 38px; height: 38px; border-radius: 11px; background: var(--card); border: 2px solid var(--line); font: 700 15px Fredoka; }
.nums button.ans { background: rgba(168, 85, 247, .35); }
.nums button.cur { border-color: #fff; }
.nums button.g { background: rgba(34, 197, 94, .4); } .nums button.b { background: rgba(244, 63, 94, .45); }
.timer { font: 700 20px Fredoka; font-variant-numeric: tabular-nums; }
.timer.low { color: var(--ko); animation: pulse .5s infinite alternate; }
.stmt { font: 600 23px/1.35 Fredoka; min-height: 150px; padding: 20px 18px; border-radius: 24px; background: var(--card2); display: flex; align-items: center; margin: 10px 0 18px; }
.wrongList .card { margin-bottom: 10px; }
.wrongList .card p { margin: 6px 0 0; font-size: 15px; }
.topicGrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.topic { padding: 12px; border-radius: 18px; background: var(--card); border: 1px solid var(--line); text-align: left; }
.topic .e { font-size: 26px; }
.topic b { display: block; font: 600 15px/1.2 Fredoka; margin: 4px 0; }
.topic .bar { height: 7px; }

/* ── juegos ── */
.games { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.game { border-radius: 24px; padding: 16px 14px; min-height: 150px; text-align: left; display: flex; flex-direction: column; justify-content: space-between; color: #fff; position: relative; overflow: hidden; box-shadow: 0 5px 0 rgba(0, 0, 0, .35); }
.game:active { transform: translateY(3px); }
.game .e { font-size: 40px; }
.game h3 { font-size: 19px; }
.game p { margin: 2px 0 0; font-size: 13px; opacity: .9; font-weight: 700; }
.game.wide { grid-column: span 2; min-height: 110px; }
.flip { perspective: 1000px; height: 300px; margin: 10px 0 18px; }
.flip .in { position: relative; width: 100%; height: 100%; transition: transform .45s; transform-style: preserve-3d; }
.flip.on .in { transform: rotateY(180deg); }
.flip .f, .flip .b { position: absolute; inset: 0; backface-visibility: hidden; border-radius: 26px; padding: 24px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; font: 600 22px/1.35 Fredoka; }
.flip .f { background: linear-gradient(150deg, #6d28d9, #be185d); }
.flip .b { background: linear-gradient(150deg, #0e7490, #15803d); transform: rotateY(180deg); font-size: 19px; }
.flip small { display: block; font: 700 13px Nunito; opacity: .8; margin-top: 18px; }
.clues { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.clue { background: var(--card2); border-radius: 16px; padding: 12px 14px; font-weight: 800; animation: pop .25s; }
.clue span { color: var(--gold); font-family: Fredoka; margin-right: 6px; }
.blitzBig { font: 700 64px Fredoka; text-align: center; }

/* ── perfil ── */
.badges { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.badge { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 12px 6px; text-align: center; }
.badge .e { font-size: 34px; }
.badge b { display: block; font: 600 13px/1.2 Fredoka; margin-top: 4px; }
.badge.off .e { filter: grayscale(1) brightness(.45); }
.badge.off b { color: var(--mut); }
.avas { display: flex; flex-wrap: wrap; gap: 8px; }
.avas button { width: 52px; height: 52px; border-radius: 16px; background: var(--card); font-size: 28px; border: 2px solid transparent; }
.avas button.on { border-color: var(--pri); background: rgba(168, 85, 247, .25); }
.inp { width: 100%; padding: 14px 16px; border-radius: 16px; background: var(--card); border: 2px solid var(--line); color: var(--tx); font: 700 18px Nunito; outline: none; }
.inp:focus { border-color: var(--pri); }
.switch { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; }

/* ── overlay ── */
#toasts { position: fixed; top: calc(12px + var(--safe-t)); left: 0; right: 0; z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { background: #2a1450; border: 1px solid var(--line); padding: 12px 18px; border-radius: 16px; font-weight: 800; box-shadow: 0 10px 30px rgba(0, 0, 0, .5); animation: down .3s ease-out; max-width: 92vw; }
.toast.gold { background: linear-gradient(135deg, #b45309, #f59e0b); color: #fff; }
.xpFly { position: fixed; z-index: 70; font: 700 26px Fredoka; color: var(--gold); pointer-events: none; animation: fly 1s ease-out forwards; text-shadow: 0 2px 10px rgba(0, 0, 0, .6); }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 80; width: 100vw; height: 100vh; }
.modal { position: fixed; inset: 0; z-index: 90; background: rgba(5, 0, 12, .7); display: grid; place-items: center; padding: 20px; animation: fade .2s; }
.modal > div { background: #24113f; border: 1px solid var(--line); border-radius: 26px; padding: 22px 18px; max-width: 420px; width: 100%; animation: pop .25s; }
.modal h2 { font-size: 24px; margin-bottom: 8px; }
.modal ul { padding-left: 20px; margin: 10px 0 18px; }
.modal li { margin: 6px 0; }
.lvUp { text-align: center; }
.lvUp .e { font-size: 80px; }

@keyframes pop { from { transform: scale(.92); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes down { from { transform: translateY(-30px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } }
@keyframes shake { 25% { transform: translateX(-7px); } 50% { transform: translateX(7px); } 75% { transform: translateX(-4px); } }
@keyframes pulse { to { transform: scale(1.1); } }
@keyframes fly { to { transform: translateY(-80px) scale(1.3); opacity: 0; } }
@media (min-width: 700px) { .games { grid-template-columns: repeat(3, 1fr); } .game.wide { grid-column: span 3; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
