:root {
  --bg: #0b0f1a;
  --panel: #121a2c;
  --panel2: #182238;
  --line: #24304d;
  --text: #e9edf9;
  --muted: #8f9ab8;
  --accent: #7c5cff;
  --accent2: #22d3ee;
  --gold: #f5b942;
  --danger: #f43f5e;
  --radius: 18px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  --pix: "Press Start 2P", monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  min-height: 100dvh;
  background-image:
    radial-gradient(60% 40% at 50% 0%, rgba(124, 92, 255, .18), transparent 70%),
    linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
  background-size: 100% 100%, 24px 24px, 24px 24px;
}
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }
.pix { font-family: var(--pix); letter-spacing: .5px; }
.pix.small { font-size: .62rem; color: var(--muted); }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h1.pix { font-size: 1.05rem; line-height: 1.6; }
h2 { font-size: 1.15rem; margin: 1.2rem 0 .6rem; }
h2.pix { font-size: .62rem; color: var(--muted); margin: 1.4rem 0 .6rem; }
p { margin: .3rem 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
button {
  font: inherit; color: inherit; cursor: pointer; border: 1px solid var(--line);
  background: var(--panel2); border-radius: 14px; padding: .7rem 1rem;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
  -webkit-tap-highlight-color: transparent;
}
button:active { transform: scale(.97); }
button.primary { background: linear-gradient(135deg, var(--accent), #5b3df5); border-color: transparent; font-weight: 700; box-shadow: 0 8px 24px rgba(124,92,255,.35); }
button.primary:disabled { opacity: .4; box-shadow: none; cursor: not-allowed; }
button.ghost { background: transparent; }
button.danger { color: var(--danger); border-color: rgba(244,63,94,.4); }
button.big { padding: 1rem 1.2rem; font-size: 1.05rem; }
button.wide { width: 100%; }
.icon-btn { padding: .4rem .7rem; border-radius: 10px; background: transparent; font-size: 1.1rem; }

#app { max-width: 520px; margin: 0 auto; padding: 1rem 1rem calc(2rem + env(safe-area-inset-bottom)); }
.screen { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Top bar */
.top {
  position: sticky; top: 0; z-index: 10;
  display: grid; grid-template-columns: auto 1fr auto; gap: .8rem; align-items: center;
  max-width: 520px; margin: 0 auto; padding: .6rem 1rem;
  background: rgba(11,15,26,.85); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.top-left { display: flex; align-items: center; gap: .5rem; font-weight: 700; }
.avatar { font-size: 1.4rem; }
.top-mid { display: grid; grid-template-columns: auto 1fr auto; gap: .5rem; align-items: center; }
.lvl { font-size: .55rem; color: var(--gold); }
.xp { font-size: .5rem; color: var(--muted); white-space: nowrap; }
.xpbar { height: 8px; background: var(--panel2); border-radius: 99px; overflow: hidden; border: 1px solid var(--line); }
.xpbar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent2), var(--accent)); transition: width .4s ease; }
.top-right { display: flex; align-items: center; gap: .4rem; }
.sync { font-size: .95rem; padding: .2rem .45rem; border-radius: 8px; background: var(--panel2); }
.sync.pending { background: rgba(245,185,66,.18); color: var(--gold); }

/* Gate */
#gate { min-height: 85dvh; display: grid; place-items: center; }
.gate-box { text-align: center; width: 100%; max-width: 340px; }
.logo { font-size: 1.5rem; line-height: 1.7; color: var(--text); text-shadow: 0 0 18px rgba(124,92,255,.7); margin-bottom: .4rem; }
.dots { display: flex; justify-content: center; gap: .8rem; margin: 1.2rem 0; }
.dots i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--muted); display: block; transition: all .15s; }
.dots i.on { background: var(--accent2); border-color: var(--accent2); box-shadow: 0 0 12px var(--accent2); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
.keypad button { font-size: 1.4rem; padding: .9rem 0; border-radius: 16px; }
.hint { min-height: 1.4em; color: var(--danger); font-size: .9rem; }
.shake { animation: shake .4s; }
@keyframes shake { 0%,100% { transform: translateX(0);} 20%,60% { transform: translateX(-8px);} 40%,80% { transform: translateX(8px);} }

/* Player select */
.players { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1.2rem; }
.players button { padding: 1.4rem .8rem; border-radius: var(--radius); display: grid; gap: .5rem; justify-items: center; font-weight: 700; font-size: 1.1rem; }
.players button .av { font-size: 3rem; }

/* Map */
.progress { height: 12px; background: var(--panel2); border: 1px solid var(--line); border-radius: 99px; overflow: hidden; margin: .8rem 0; }
.progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent2), var(--accent), var(--gold)); transition: width .4s; }
.how { display: flex; flex-wrap: wrap; gap: .4rem .7rem; font-size: .8rem; color: var(--muted); margin: .4rem 0 1rem; }
.actions { display: grid; gap: .6rem; margin: .6rem 0; }
.world-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.world {
  text-align: left; display: grid; gap: .25rem; padding: .9rem; border-radius: var(--radius);
  background: linear-gradient(160deg, var(--panel2), var(--panel)); border: 1px solid var(--line); position: relative; overflow: hidden;
}
.world::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--wc); }
.world .w-icon { font-size: 1.7rem; }
.world .w-name { font-weight: 700; font-size: .95rem; line-height: 1.2; }
.world .w-count { font-family: var(--pix); font-size: .5rem; color: var(--muted); }
.world .w-bar { height: 5px; background: rgba(255,255,255,.08); border-radius: 99px; overflow: hidden; }
.world .w-bar i { display: block; height: 100%; background: var(--wc); }
.world.done { opacity: .75; }
.world.done .w-count::after { content: " ✓"; color: #34d399; }
#btnList { margin-top: 1rem; }

/* Play */
.play-head { display: flex; align-items: center; gap: .6rem; margin-bottom: .6rem; }
.play-head .chip { margin-left: auto; }
.chip { font-size: .75rem; padding: .25rem .6rem; border-radius: 99px; background: var(--panel2); border: 1px solid var(--line); color: var(--muted); }
.card {
  background: linear-gradient(170deg, var(--panel2), var(--panel));
  border: 1px solid var(--line); border-radius: 22px; padding: 1.2rem;
  box-shadow: 0 20px 50px rgba(0,0,0,.4);
  animation: cardIn .25s ease;
}
@keyframes cardIn { from { opacity: 0; transform: translateX(40px) rotate(2deg);} to { opacity: 1; transform: none; } }
.card.out { animation: cardOut .22s ease forwards; }
@keyframes cardOut { to { opacity: 0; transform: translateX(-60px) rotate(-3deg); } }
.card-icon { font-size: 2.4rem; }
.card h2 { margin: .4rem 0 .4rem; font-size: 1.3rem; line-height: 1.25; }
.card > p { color: #c9d1ea; }
.video { margin: .8rem 0; padding: .6rem .8rem; border-left: 3px solid var(--accent2); background: rgba(34,211,238,.07); border-radius: 0 12px 12px 0; }
.video .vlabel { font-size: .72rem; color: var(--accent2); font-weight: 700; letter-spacing: .3px; }
.video p { margin: .2rem 0 0; font-size: .95rem; }
.tags { display: flex; flex-wrap: wrap; gap: .4rem; margin: .6rem 0; }
.tags span { font-size: .75rem; padding: .2rem .55rem; border-radius: 99px; background: rgba(245,185,66,.12); color: var(--gold); border: 1px solid rgba(245,185,66,.3); }
.scores { display: grid; grid-template-columns: repeat(5, 1fr); gap: .4rem; margin: 1rem 0 .7rem; }
.scores button { display: grid; gap: .2rem; justify-items: center; padding: .6rem .2rem; border-radius: 14px; background: var(--panel); }
.scores button .e { font-size: 1.5rem; }
.scores button .l { font-size: .62rem; color: var(--muted); }
.scores button.sel { border-color: var(--accent2); background: rgba(34,211,238,.12); box-shadow: 0 0 0 2px rgba(34,211,238,.35); transform: translateY(-2px); }
.scores button.sel .l { color: var(--text); }
textarea { width: 100%; resize: vertical; background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: .6rem .8rem; font: inherit; }
textarea:focus { outline: none; border-color: var(--accent); }
.card-actions { display: grid; grid-template-columns: 1fr 2fr; gap: .6rem; margin-top: .8rem; }

/* Done */
#done { text-align: center; }
.trophy { font-size: 4rem; margin-top: 1rem; animation: pop .6s ease; }
@keyframes pop { 0% { transform: scale(.4); opacity: 0;} 70% { transform: scale(1.15);} 100% { transform: scale(1); opacity: 1;} }
.sync-line { font-size: .9rem; }
.favs { text-align: left; padding-left: 1.3rem; margin: .4rem 0 1rem; }
.favs li { padding: .3rem 0; border-bottom: 1px dashed var(--line); }
.favs .c { display: block; font-size: .85rem; color: var(--muted); }

/* List */
.lw { margin: 1rem 0 .4rem; display: flex; align-items: center; gap: .5rem; font-weight: 700; }
.lw .cnt { margin-left: auto; font-family: var(--pix); font-size: .5rem; color: var(--muted); }
.li { width: 100%; text-align: left; display: grid; grid-template-columns: 2.2rem 1fr auto; gap: .5rem; align-items: center; padding: .6rem .7rem; margin: .3rem 0; border-radius: 12px; background: var(--panel); }
.li .sc { font-size: 1.3rem; text-align: center; }
.li .t { font-size: .95rem; }
.li .cm { display: block; font-size: .8rem; color: var(--muted); }
.li .arrow { color: var(--muted); }
.li.unrated .sc { opacity: .3; }

/* Toast, sheet */
.toast { position: fixed; left: 50%; bottom: calc(1.5rem + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line); padding: .7rem 1rem; border-radius: 14px; z-index: 60; box-shadow: 0 10px 30px rgba(0,0,0,.5); font-weight: 600; animation: fade .2s; max-width: 90vw; text-align: center; }
.toast.gold { border-color: var(--gold); color: var(--gold); }
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 40; display: grid; align-items: end; }
.sheet-body { background: var(--panel); border-radius: 22px 22px 0 0; padding: 1rem 1rem calc(1.2rem + env(safe-area-inset-bottom)); display: grid; gap: .5rem; max-width: 520px; width: 100%; margin: 0 auto; }
[hidden] { display: none !important; }
