:root {
  --bg1: #4b3fd1; --bg2: #8a4fff; --ink: #24214a; --muted: #6b6890; --card: #ffffff;
  --ok: #22c55e; --bad: #ef4444; --gold: #ffc531; --accent: #ff7a45; --soft: #f1efff;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Trebuchet MS", "Segoe UI", Roboto, system-ui, sans-serif;
  background: linear-gradient(160deg, var(--bg1), var(--bg2)) fixed; color: #fff;
  user-select: none; -webkit-user-select: none; overscroll-behavior: none;
}
button { font-family: inherit; border: 0; cursor: pointer; touch-action: manipulation; color: inherit; }
button:active:not(:disabled) { transform: scale(.96); }
h1, h2, h3 { margin: .3em 0; }
.hidden { display: none !important; }

.screen { max-width: 520px; margin: 0 auto; padding: max(14px, env(safe-area-inset-top)) 16px 28px; min-height: 100vh; }
.center { display: flex; flex-direction: column; align-items: center; text-align: center; }

/* Botons */
.btn { display: block; width: 100%; margin: 10px 0; padding: 13px 16px; border-radius: 16px; background: rgba(255,255,255,.18); color: #fff; font-size: 17px; font-weight: 700; }
.btn.big { padding: 16px; font-size: 19px; }
.btn.primary { background: var(--gold); color: #3b2a00; box-shadow: 0 5px 0 #c9921a; }
.btn.accent { background: var(--accent); box-shadow: 0 5px 0 #c4501f; }
.btn.danger { background: transparent; color: #ffd0d0; text-decoration: underline; font-weight: 600; }
.modal .btn:not(.primary):not(.danger) { background: var(--soft); color: var(--ink); }

/* Benvinguda */
.welcome { justify-content: center; }
.logo { width: 110px; height: 110px; border-radius: 30px; background: var(--gold); color: var(--bg1); font-size: 96px; line-height: 104px; font-weight: 900; box-shadow: 0 8px 0 #c9921a; margin-top: 20px; animation: bob 2.4s ease-in-out infinite; }
.welcome h1 { font-size: 40px; }
.sub { opacity: .9; margin: 0 0 18px; }
.lbl { align-self: stretch; text-align: left; font-weight: 700; margin: 12px 0 6px; display: block; }
.lbl small { font-weight: 400; opacity: .8; }
input { width: 100%; padding: 14px; font-size: 20px; border-radius: 14px; border: 3px solid transparent; outline: none; font-family: inherit; color: var(--ink); user-select: text; -webkit-user-select: text; }
input:focus { border-color: var(--gold); }
.avatars { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-bottom: 14px; }
.av { width: 62px; height: 62px; border-radius: 18px; background: rgba(255,255,255,.18); font-size: 34px; border: 3px solid transparent; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.av.sel { border-color: var(--gold); background: rgba(255,255,255,.35); }
.av.locked { font-size: 20px; opacity: .55; }
.av small { font-size: 11px; }

/* Inici */
.player { display: flex; align-items: center; gap: 12px; background: rgba(255,255,255,.14); border-radius: 22px; padding: 12px; margin-bottom: 16px; cursor: pointer; }
.avatar { font-size: 44px; width: 64px; height: 64px; background: #fff; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.pinfo { flex: 1; min-width: 0; }
.pname { font-size: 21px; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ptitle { font-size: 14px; opacity: .9; }
.xpbar, .lvbar, .mini { display: block; height: 10px; background: rgba(0,0,0,.22); border-radius: 10px; overflow: hidden; margin-top: 5px; }
.xpbar i, .lvbar i, .mini i { display: block; height: 100%; background: var(--gold); border-radius: 10px; transition: width .6s; }
.xptxt { font-size: 12px; opacity: .85; margin-top: 2px; }
.streak { display: flex; flex-direction: column; align-items: center; font-size: 22px; line-height: 1; }
.streak b { font-size: 20px; } .streak small { font-size: 11px; opacity: .8; }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.card { border-radius: 22px; padding: 16px 12px 14px; text-align: left; display: flex; flex-direction: column; gap: 4px; min-height: 150px; box-shadow: 0 6px 0 rgba(0,0,0,.18); color: #fff; }
.card .ci { font-size: 38px; }
.card .ct { font-size: 18px; font-weight: 800; line-height: 1.15; flex: 1; }
.card .cs { font-size: 13px; opacity: .95; }
.c1 { background: linear-gradient(135deg, #ff6b8b, #ff8e53); }
.c2 { background: linear-gradient(135deg, #18b8a2, #3bd17f); }
.c3 { background: linear-gradient(135deg, #3a8dff, #42c6ff); }
.c4 { background: linear-gradient(135deg, #f7a400, #ffcf3f); color: #3b2a00; }
.c4 .ct { color: #3b2a00; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.tile { background: rgba(255,255,255,.16); border-radius: 18px; padding: 14px 6px; font-size: 28px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.tile span { font-size: 13px; font-weight: 700; }

/* Capçalera de pantalla */
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.topbar h2 { font-size: 22px; }
.back { width: 44px; height: 44px; border-radius: 14px; background: rgba(255,255,255,.2); font-size: 22px; font-weight: 800; flex-shrink: 0; }
.hint { opacity: .92; font-size: 15px; line-height: 1.4; }
h3 { margin-top: 20px; }

/* Mapa de nivells */
.path { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.node { display: flex; align-items: center; gap: 12px; background: #fff; color: var(--ink); border-radius: 18px; padding: 10px 12px; text-align: left; box-shadow: 0 4px 0 rgba(0,0,0,.15); }
.node .num { width: 44px; height: 44px; border-radius: 50%; background: var(--bg1); color: #fff; font-weight: 900; font-size: 20px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.node .nd { flex: 1; display: flex; flex-direction: column; }
.node small { color: var(--muted); font-size: 13px; }
.node.current { outline: 4px solid var(--gold); }
.node.current .num { background: var(--accent); animation: pulse 1.4s infinite; }
.node.locked { opacity: .55; background: #e9e7f7; }
.node.locked .num { background: #b9b5d9; }
.stars { color: #d8d5ea; font-size: 18px; letter-spacing: -2px; }
.stars .on { color: var(--gold); }

/* Practica */
.tgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 10px 0 8px; }
.tbtn { background: #fff; color: var(--ink); border-radius: 16px; padding: 10px 6px 8px; display: flex; flex-direction: column; align-items: center; box-shadow: 0 4px 0 rgba(0,0,0,.15); }
.tbtn b { font-size: 26px; } .tbtn small { color: var(--muted); font-size: 12px; }
.tbtn .mini { width: 80%; height: 6px; background: #e6e4f5; }
.tbtn .mini i { background: var(--ok); }

/* Insígnies */
.bgrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.badge { background: rgba(255,255,255,.12); border-radius: 18px; padding: 12px; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 3px; opacity: .7; }
.badge.got { background: #fff; color: var(--ink); opacity: 1; box-shadow: 0 4px 0 rgba(0,0,0,.15); }
.badge .bi { font-size: 36px; } .badge small { font-size: 12px; opacity: .85; }

/* Progrés */
.statgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.statgrid div { background: rgba(255,255,255,.16); border-radius: 14px; padding: 10px 4px; text-align: center; display: flex; flex-direction: column; }
.statgrid b { font-size: 20px; } .statgrid small { font-size: 11px; opacity: .85; }
.prow { display: grid; grid-template-columns: 1fr 90px 42px; align-items: center; gap: 8px; margin: 8px 0; font-size: 15px; }
.prow .lvbar { margin: 0; }
.legend { display: flex; flex-wrap: wrap; gap: 6px; font-size: 12px; margin-bottom: 8px; }
.legend span { padding: 3px 8px; border-radius: 8px; color: var(--ink); }
.mgrid { display: grid; grid-template-columns: repeat(13, 1fr); gap: 2px; font-size: 10px; font-weight: 700; }
.mgrid span { aspect-ratio: 1; display: flex; align-items: center; justify-content: center; border-radius: 4px; color: var(--ink); }
.mgrid .h { background: transparent; color: #fff; font-size: 12px; }
.u { background: rgba(255,255,255,.35); } .g { background: #4ade80; } .y { background: #fde047; } .r { background: #f87171; }

/* Joc */
.game { display: flex; flex-direction: column; padding-bottom: 16px; }
.gtop { display: flex; align-items: center; gap: 10px; }
.dots { flex: 1; display: flex; gap: 5px; justify-content: center; }
.dots i { width: 14px; height: 14px; border-radius: 50%; background: rgba(255,255,255,.3); }
.dots i.ok { background: var(--ok); } .dots i.bad { background: var(--bad); }
.dots i.cur { background: #fff; transform: scale(1.25); }
.combo { font-weight: 900; font-size: 16px; padding: 6px 10px; border-radius: 12px; background: rgba(0,0,0,.2); opacity: .4; }
.combo.on { opacity: 1; background: var(--accent); animation: pulse 1s infinite; }
.clock { flex: 1; text-align: center; font-size: 34px; font-weight: 900; }
.clock.hurry { color: #ffd1d1; animation: pulse .5s infinite; }
.timebar { height: 8px; background: rgba(0,0,0,.25); border-radius: 8px; overflow: hidden; margin-top: 10px; }
.timebar i { display: block; height: 100%; width: 100%; background: var(--ok); transition: width .1s linear; }
.timebar i.hurry { background: var(--bad); }
.glabel { text-align: center; font-size: 14px; opacity: .85; margin-top: 10px; }
.goldtag { align-self: center; margin-top: 6px; background: var(--gold); color: #3b2a00; font-weight: 800; padding: 5px 12px; border-radius: 20px; font-size: 14px; animation: pulse 1.2s infinite; }
.game.golden .qcard { box-shadow: 0 0 0 5px var(--gold), 0 8px 0 rgba(0,0,0,.15); }
.qcard { background: #fff; color: var(--ink); border-radius: 26px; padding: 22px 16px; margin: 12px 0; min-height: 130px; display: flex; flex-direction: column; justify-content: center; align-items: center; box-shadow: 0 8px 0 rgba(0,0,0,.15); transition: background .2s; }
.qcard.ok { background: #dcfce7; } .qcard.bad { background: #fee2e2; animation: shake .4s; }
.expr { font-size: 44px; font-weight: 900; white-space: nowrap; letter-spacing: .5px; }
.hole { display: inline-block; min-width: 1.6em; padding: 0 .2em; border-bottom: 5px dashed #c8c3ef; color: #b5b0dc; text-align: center; }
.hole.filled { color: var(--bg1); border-bottom-style: solid; border-color: var(--bg1); }
.qcard.ok .hole { color: #15803d; border-color: #15803d; } .qcard.bad .hole { color: #b91c1c; border-color: #b91c1c; }
.ptext { font-size: 20px; line-height: 1.4; margin: 0 0 12px; text-align: left; align-self: stretch; }
.ans { font-size: 34px; font-weight: 900; display: flex; align-items: baseline; gap: 10px; }
.unit { font-size: 20px; color: var(--muted); }
.answers { margin-top: auto; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.key { background: #fff; color: var(--ink); font-size: 30px; font-weight: 800; padding: 13px 0; border-radius: 18px; box-shadow: 0 5px 0 rgba(0,0,0,.18); }
.key.del { background: #ffe1d6; } .key.ok { background: var(--ok); color: #fff; } .key.skip { background: #e0e7ff; }
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.opt { background: #fff; color: var(--ink); font-size: 32px; font-weight: 900; padding: 20px 0; border-radius: 20px; box-shadow: 0 5px 0 rgba(0,0,0,.18); }
.opt.right { background: var(--ok); color: #fff; } .opt.wrong { background: var(--bad); color: #fff; }
.gxp { display: flex; justify-content: space-between; margin-top: 12px; font-weight: 700; opacity: .9; }

.feedback { position: fixed; left: 0; right: 0; bottom: 0; transform: translateY(110%); transition: transform .25s ease-out; z-index: 20; display: flex; justify-content: center; }
.feedback.show { transform: none; }
.fb { width: 100%; max-width: 520px; border-radius: 26px 26px 0 0; padding: 18px 18px max(18px, env(safe-area-inset-bottom)); color: var(--ink); background: #fff; box-shadow: 0 -6px 30px rgba(0,0,0,.25); }
.fb.ok { background: #dcfce7; border-top: 6px solid var(--ok); text-align: center; }
.fb.bad { background: #fff; border-top: 6px solid var(--bad); }
.fbt { font-size: 24px; font-weight: 900; margin-bottom: 4px; }
.fbx { font-weight: 700; color: #15803d; }
.fb b.big { font-size: 26px; color: #b91c1c; }
.tip { background: var(--soft); border-radius: 14px; padding: 10px 12px; margin: 10px 0 4px; line-height: 1.5; font-size: 16px; }

/* Final */
.end h1 { font-size: 34px; margin-top: 24px; }
.bigstars { font-size: 64px; color: rgba(255,255,255,.25); letter-spacing: 4px; }
.bigstars .on { color: var(--gold); display: inline-block; animation: pop .5s both; text-shadow: 0 4px 0 #c9921a; }
.bigscore { font-size: 54px; font-weight: 900; display: flex; flex-direction: column; line-height: 1; }
.bigscore small { font-size: 15px; font-weight: 600; opacity: .85; margin-top: 4px; }
.endmsg { font-size: 19px; font-weight: 700; }
.xpgain { background: var(--gold); color: #3b2a00; font-weight: 900; font-size: 22px; padding: 8px 20px; border-radius: 30px; animation: pop .5s .8s both; }
.levelup { margin-top: 14px; background: rgba(255,255,255,.18); padding: 12px; border-radius: 16px; width: 100%; }
.newbadges { width: 100%; margin-top: 10px; }
.nb { display: flex; align-items: center; gap: 10px; background: #fff; color: var(--ink); border-radius: 16px; padding: 10px; margin: 8px 0; text-align: left; animation: pop .5s both; }
.nb span { font-size: 34px; } .nb b { flex-shrink: 0; } .nb small { color: var(--muted); }
.endbtns { width: 100%; margin-top: 12px; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(20,15,60,.6); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.mbox { background: #fff; color: var(--ink); border-radius: 24px; padding: 20px; width: 100%; max-width: 400px; text-align: center; animation: pop .25s; }
.about { text-align: center; font-size: 13px; opacity: .75; margin-top: 18px; }

/* Efectes */
#fx { position: fixed; inset: 0; pointer-events: none; z-index: 60; overflow: hidden; }
.conf { position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 3px; animation: fall linear forwards; }
.floaty { position: absolute; transform: translateX(-50%); font-weight: 900; font-size: 26px; color: var(--gold); text-shadow: 0 2px 0 #8a5d00; animation: rise 1.2s ease-out forwards; white-space: nowrap; }
.shake { animation: shake .4s; }

@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }
@keyframes rise { from { opacity: 1; margin-top: 0; } to { opacity: 0; margin-top: -90px; } }
@keyframes pop { 0% { transform: scale(.3); opacity: 0; } 70% { transform: scale(1.15); opacity: 1; } 100% { transform: scale(1); } }
@keyframes pulse { 50% { transform: scale(1.08); } }
@keyframes bob { 50% { transform: translateY(-8px) rotate(-4deg); } }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

@media (max-width: 360px) {
  .expr { font-size: 36px; } .key { font-size: 26px; padding: 10px 0; } .card { min-height: 135px; }
}
