/* «Almost Delivered» — clean glass style.
 * Real footage underneath, soft glass on top. Manrope for the interface, Caveat for Kiki's handwriting.
 * Accents: white, lime #D7F65A (targets, right answers), Kiki's ball purple #8E2BD8 (paw), red for "too much / splat". */
:root {
  --ink: #15121C;
  --lime: #D7F65A;
  --purple: #8E2BD8;
  --red: #FF5A6E;
  --glass: rgba(255,255,255,0.16);
  --glass-line: rgba(255,255,255,0.5);
  --sheet: rgba(20,18,28,0.55);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #000; color: #fff; }
body { font-family: Manrope, system-ui, -apple-system, "Segoe UI", sans-serif; overscroll-behavior: none; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

#app { position: relative; width: 100%; max-width: 480px; height: 100vh; height: 100dvh; margin: 0 auto; overflow: hidden; overflow: clip; background: #0E0E12; }
.screen { position: absolute; inset: 0; display: none; overflow: hidden; }
.screen.active { display: block; }
.bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.bg.glassy { filter: blur(4px) saturate(1.12) brightness(0.9); transform: scale(1.05); }
.bg.glassy.dark { filter: blur(10px) saturate(1.1) brightness(0.55); transform: scale(1.1); }
#home .bg { object-position: 50% 30%; }

/* ---------- type ---------- */
.h-big { margin: 0; font-size: 36px; line-height: 1.02; font-weight: 800; letter-spacing: -0.02em; }
.h-mid { margin: 0; font-size: 24px; line-height: 1.15; font-weight: 800; letter-spacing: -0.01em; }
.h-small { margin: 0; font-size: 17px; font-weight: 800; line-height: 1.3; }
.h-huge { font-size: 64px; font-weight: 800; letter-spacing: -0.03em; line-height: 1; }
.muted { margin: 0; font-size: 15px; line-height: 1.45; color: rgba(255,255,255,0.85); }
.sub { margin: 4px 0 0; font-size: 14px; font-weight: 700; color: rgba(255,255,255,0.8); }
.small { margin: 0; font-size: 13px; color: rgba(255,255,255,0.62); }
.center { text-align: center; }
.lime { color: var(--lime); }

/* ---------- pieces ---------- */
.chip { display: inline-block; padding: 6px 12px; border-radius: 999px; background: rgba(255,255,255,0.22); border: 1px solid rgba(255,255,255,0.45); font-size: 13px; font-weight: 700; white-space: nowrap; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
button.chip { cursor: pointer; }
.lang { background: rgba(255,255,255,0.08); opacity: 0.6; }
.lang.on { background: rgba(255,255,255,0.28); opacity: 1; }
.lang:disabled { opacity: 0.35; cursor: default; }

.btn { position: relative; overflow: hidden; height: 56px; width: 100%; border: 0; border-radius: 18px; background: #fff; color: var(--ink); font-size: 17px; font-weight: 800; }
.btn:disabled { background: rgba(255,255,255,0.35); color: rgba(21,18,28,0.75); }
.btn:active { transform: scale(0.98); }
.btn.ghost { height: 50px; background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.5); color: #fff; font-size: 15px; font-weight: 700; }
.btn-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: rgba(255,255,255,0.75); transition: width .2s ease; }
.btn span:not(.btn-fill) { position: relative; }
.link { border: 0; background: none; color: rgba(255,255,255,0.8); font-size: 14px; font-weight: 700; padding: 6px; text-decoration: underline; text-underline-offset: 3px; }
.round { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; padding: 0; font-size: 22px; font-weight: 800; }
.glass-chip { background: var(--glass); border: 1px solid var(--glass-line); box-shadow: 0 6px 20px rgba(0,0,0,0.2); }

.sheet { border-radius: 28px; padding: 22px 20px 20px; background: var(--sheet); border: 1px solid rgba(255,255,255,0.28); box-shadow: inset 0 1px 0 rgba(255,255,255,0.35); display: flex; flex-direction: column; gap: 14px;
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); }
.sheet.bottom, .home-sheet { position: absolute; left: 12px; right: 12px; bottom: calc(12px + var(--safe-b)); }
.card { border-radius: 30px; padding: 24px 20px 22px; background: var(--glass); border: 1px solid var(--glass-line);
  box-shadow: 0 20px 50px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.6); display: flex; flex-direction: column; gap: 14px; }
.topbar { position: absolute; left: 0; right: 0; top: var(--safe-t); padding: 18px; display: flex; justify-content: space-between; align-items: center; z-index: 3; }
.topbar.left { justify-content: flex-start; gap: 12px; }
.brand { font-weight: 800; font-size: 18px; }
.langs { display: flex; gap: 8px; align-items: center; justify-content: center; }
.lang-l { font-size: 13px; font-weight: 700; color: rgba(255,255,255,0.75); margin-right: 2px; }
.home-sheet .lang { padding: 8px 16px; font-size: 14px; }
.col { display: flex; flex-direction: column; gap: 10px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row2:has(#btn-share[hidden]) { grid-template-columns: 1fr; }

/* ---------- stage & glass cover ---------- */
#stage { position: absolute; inset: 0; overflow: hidden; overflow: clip; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#vid { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000;
  transform-origin: var(--mx, 50%) var(--my, 50%);
  transition: filter .45s ease, transform .6s cubic-bezier(.2,.7,.2,1); }
#stage.glass #vid { filter: blur(4px) saturate(1.12) brightness(0.9); transform: scale(1.05); }
/* the swap: a short, stronger blur while the next clip is put underneath */
#stage.glass.swap #vid { filter: blur(16px) saturate(1.1) brightness(0.85); transition: filter .18s ease; }
#shade { position: absolute; inset: 0; background: rgba(10,10,20,0.28); opacity: 0; transition: opacity .4s ease; pointer-events: none; }
#stage.glass #shade { opacity: 1; }

.game-brand { position: absolute; left: 18px; top: calc(var(--safe-t) + 20px); z-index: 4; pointer-events: none; text-shadow: 0 1px 8px rgba(0,0,0,0.45); }
#hud { position: absolute; left: 18px; right: 18px; top: calc(var(--safe-t) + 62px); display: flex; align-items: center; justify-content: space-between; gap: 10px; z-index: 4; pointer-events: none; }
.pips { display: flex; gap: 6px; }
.pips i { width: 22px; height: 6px; border-radius: 3px; background: rgba(255,255,255,0.35); transition: background .3s; }
.pips i.done { background: #fff; }
.pips i.now { background: var(--lime); }
.step { font-size: 13px; font-weight: 700; color: rgba(255,255,255,0.9); text-shadow: 0 1px 6px rgba(0,0,0,0.35); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#btn-mute { position: absolute; right: 14px; top: calc(var(--safe-t) + 12px); z-index: 5; }
#btn-mute svg { width: 20px; height: 20px; }
#btn-mute .spk { fill: #fff; }
#btn-mute .wave, #btn-mute .x { stroke: #fff; stroke-width: 2; fill: none; stroke-linecap: round; }
#btn-mute .x { display: none; }
#btn-mute.off .wave { display: none; }
#btn-mute.off .x { display: block; }

#caption { position: absolute; left: 50%; bottom: calc(var(--safe-b) + 34px); transform: translate(-50%, 10px); max-width: calc(100% - 40px);
  padding: 10px 16px; border-radius: 16px; background: rgba(20,18,28,0.5); border: 1px solid rgba(255,255,255,0.35);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  font-size: 16px; font-weight: 800; text-align: center; opacity: 0; transition: opacity .25s, transform .25s; pointer-events: none; z-index: 4; }
#caption.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- panels ---------- */
.panel { opacity: 0; visibility: hidden; pointer-events: none; transition: opacity .3s ease, transform .35s cubic-bezier(.2,.7,.2,1), visibility 0s .35s; z-index: 6; }
.panel.show { opacity: 1; visibility: visible; pointer-events: auto; transition: opacity .3s ease, transform .35s cubic-bezier(.2,.7,.2,1), visibility 0s; }
.center-card { position: absolute; left: 16px; right: 16px; top: calc(var(--safe-t) + 100px); transform: translateY(18px) scale(0.98); }
.center-card.show { transform: none; }
.center-card.tilt.show { transform: rotate(-2deg); }
#panel-start { transform: translateY(20px); }
#panel-start.show { transform: none; }
#panel-slip { top: 30%; left: 30px; right: 30px; text-align: center; padding: 30px 22px 26px; gap: 10px; }

/* math */
.eq { display: flex; justify-content: center; align-items: center; gap: 8px; font-size: 52px; font-weight: 800; letter-spacing: -0.02em; line-height: 1; }
.eq b { color: var(--lime); font-weight: 800; }
.eq-q { min-width: 58px; height: 64px; padding: 0 10px; border-radius: 16px; display: grid; place-items: center; background: var(--lime); color: var(--ink); }
.say { text-align: center; font-size: 14px; font-weight: 700; color: rgba(255,255,255,0.78); margin-top: -4px; }
.timer-row { display: flex; align-items: center; gap: 12px; }
.bar { flex: 1; height: 8px; border-radius: 4px; background: rgba(255,255,255,0.25); overflow: hidden; }
.bar i { display: block; height: 100%; width: 100%; border-radius: 4px; background: var(--lime); transform-origin: left center; }
.timer-row span { font-size: 14px; font-weight: 800; white-space: nowrap; min-width: 80px; text-align: right; }
.verdict { display: none; margin: 0; text-align: center; font-size: 16px; line-height: 1.45; color: rgba(255,255,255,0.92); }
#panel-math.judged .verdict { display: block; }
#panel-math.judged .timer-row, #panel-math.judged .say { display: none; }
#panel-math.judged #math-title { font-size: 38px; }
#panel-math.judged .eq { font-size: 40px; }
#panel-math.judged .eq-q { height: 52px; }
.opts { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 2px; }
.opts button { flex: 0 0 calc((100% - 20px) / 3); height: 54px; border-radius: 16px; background: rgba(255,255,255,0.18); border: 1px solid var(--glass-line); color: #fff; font-size: 19px; font-weight: 800; }
.opts button:active { background: rgba(255,255,255,0.4); }
.opts.locked button { pointer-events: none; background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.55); border-color: rgba(255,255,255,0.25); }
.opts.locked button.picked { background: var(--red); color: #fff; border-color: var(--red); text-decoration: line-through; }

/* power */
.meter-wrap { position: relative; margin-top: 30px; }
.meter { position: relative; height: 34px; border-radius: 17px; overflow: hidden; background: rgba(255,255,255,0.16); border: 1px solid rgba(255,255,255,0.45); }
.m-over { position: absolute; left: 70%; right: 0; top: 0; bottom: 0; background: rgba(255,90,110,0.45); }
.m-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: linear-gradient(90deg, rgba(255,255,255,0.35), rgba(255,255,255,0.85)); border-right: 4px solid #fff; }
.m-good { position: absolute; left: 60%; width: 10%; top: 0; height: 34px; border-radius: 6px; border: 3px solid var(--lime); transition: box-shadow .2s; }
.meter-wrap.hit .m-good { box-shadow: 0 0 0 4px rgba(215,246,90,0.9), 0 0 24px rgba(215,246,90,0.9); }
.m-labels { display: flex; justify-content: space-between; font-size: 13px; font-weight: 700; color: rgba(255,255,255,0.82); }
.stamp { position: absolute; left: 63.5%; top: -42px; padding: 6px 12px; border-radius: 12px; background: var(--lime); color: var(--ink); font-size: 16px; font-weight: 800; white-space: nowrap;
  transform: translateX(-50%) scale(0.6) rotate(-8deg); opacity: 0; transition: transform .25s cubic-bezier(.3,1.6,.5,1), opacity .2s; }
.stamp.show { opacity: 1; transform: translateX(-50%) scale(1) rotate(-8deg); }
.stamp.bad { background: var(--red); color: #fff; }

/* balance */
.slope { position: relative; height: 58px; margin-top: 6px; }
.slope-track { position: absolute; inset: 0; border-radius: 29px; overflow: hidden; background: rgba(255,255,255,0.16); border: 1px solid rgba(255,255,255,0.45); }
.edge { position: absolute; top: 0; bottom: 0; width: 15%; background: rgba(255,90,110,0.35); display: grid; place-items: center; font-size: 12px; font-weight: 800; transition: background .15s; }
.edge.l { left: 0; } .edge.r { right: 0; }
.edge.warn { background: rgba(255,90,110,0.85); }
.zone { position: absolute; left: 38.1%; width: 23.8%; top: 8px; bottom: 8px; border-radius: 21px; background: rgba(215,246,90,0.28); border: 2px solid var(--lime); transition: background .15s; }
.slope.in .zone { background: rgba(215,246,90,0.5); }
.paw-knob { position: absolute; top: 6px; left: 50%; width: 46px; height: 46px; margin-left: -23px; border-radius: 50%; background: #fff; box-shadow: 0 6px 14px rgba(0,0,0,0.3); display: grid; place-items: center; }
.paw-knob svg, .paw-dot svg { width: 24px; height: 24px; fill: var(--purple); }

#panel-balance .slope { height: 64px; }
#panel-balance .slope .paw-knob { top: 7px; width: 50px; height: 50px; margin-left: -25px; }
#finger { position: absolute; width: 60px; height: 60px; margin: -30px 0 0 -30px; border-radius: 50%; border: 3px solid rgba(255,255,255,0.85); background: rgba(255,255,255,0.18); pointer-events: none; opacity: 0; transition: opacity .12s; z-index: 7; }
#finger.on { opacity: 1; }
#stage { touch-action: none; }

/* hold button + live hint */
.hold-wrap { position: absolute; left: 0; right: 0; bottom: calc(var(--safe-b) + 40px); display: flex; justify-content: center; }
.hold { width: 112px; height: 112px; border-radius: 50%; border: 3px solid #fff; background: rgba(255,255,255,0.18); color: #fff; font-size: 17px; font-weight: 800; letter-spacing: 0.02em;
  box-shadow: 0 0 0 10px rgba(255,255,255,0.12); touch-action: none; transition: transform .12s, background .12s; }
.hold.down { transform: scale(0.9); background: rgba(215,246,90,0.5); }
.hold.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 10px rgba(255,255,255,0.12); } 50% { box-shadow: 0 0 0 18px rgba(255,255,255,0.22); } }
.hint { position: absolute; left: 20px; right: 20px; bottom: calc(var(--safe-b) + 176px); text-align: center; font-size: 17px; font-weight: 800; text-shadow: 0 1px 10px rgba(0,0,0,0.45);
  opacity: 0; transition: opacity .2s; z-index: 6; pointer-events: none; }
.hint.show { opacity: 1; }

/* final */
.final { position: absolute; inset: 0; padding: calc(var(--safe-t) + 100px) 22px calc(var(--safe-b) + 22px); display: flex; flex-direction: column; gap: 16px; transform: translateY(16px); }
.final.show { transform: none; }
.final-head { display: flex; flex-direction: column; gap: 6px; }
.final .h-big { font-size: 40px; }
.final .muted { font-size: 17px; }
.teaser { position: relative; flex: 1; min-height: 140px; margin: 0 40px; border-radius: 26px; overflow: hidden; border: 1px solid rgba(255,255,255,0.55); box-shadow: 0 20px 50px rgba(0,0,0,0.3); }
.teaser img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; filter: blur(22px) saturate(1.2); transform: scale(1.2); }
.teaser-in { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; font-size: 18px; font-weight: 800; line-height: 1.25; padding: 0 12px; }
.paw-dot { width: 64px; height: 64px; border-radius: 50%; background: #fff; display: grid; place-items: center; }
.paw-dot svg { width: 34px; height: 34px; }

/* name */
.name-head { position: absolute; left: 22px; right: 22px; top: calc(var(--safe-t) + 40px); display: flex; flex-direction: column; gap: 10px; }
#name-screen .bg { filter: blur(4px) saturate(1.12) brightness(0.55); }
.stack { position: absolute; left: 0; right: 0; top: calc(var(--safe-t) + 230px); height: 250px; }
.st { position: absolute; left: 50%; top: 0; width: 160px; height: 226px; margin-left: -80px; border-radius: 20px; overflow: hidden; border: 1px solid rgba(255,255,255,0.55); box-shadow: 0 14px 30px rgba(0,0,0,0.35); }
.st img { width: 100%; height: 100%; object-fit: cover; filter: blur(16px) saturate(1.2); transform: scale(1.2); }
.s1 { transform: translateX(-62px) rotate(-10deg); } .s2 { transform: translateX(62px) rotate(10deg); }
.stack.shuffle .s1 { animation: sh1 1.2s ease-in-out infinite; } .stack.shuffle .s2 { animation: sh2 1.2s ease-in-out infinite; }
@keyframes sh1 { 50% { transform: translateX(-20px) rotate(-3deg); } }
@keyframes sh2 { 50% { transform: translateX(20px) rotate(3deg); } }
.stack .q { position: absolute; left: 50%; top: 86px; width: 56px; height: 56px; margin-left: -28px; border-radius: 50%; background: #fff; color: var(--purple); display: grid; place-items: center; font-size: 30px; font-weight: 800; }
.label { font-size: 15px; font-weight: 700; }
#name { height: 56px; border-radius: 16px; background: rgba(255,255,255,0.14); border: 2px solid #fff; padding: 0 16px; font-size: 20px; font-weight: 800; outline: none; caret-color: var(--lime); }
#name::placeholder { color: rgba(255,255,255,0.45); }

/* card */
.card-preview { position: absolute; left: 0; right: 0; top: calc(var(--safe-t) + 72px); bottom: calc(var(--safe-b) + 200px); display: flex; justify-content: center; }
#cv { height: 100%; width: auto; max-width: calc(100% - 40px); object-fit: contain; border-radius: 22px; box-shadow: 0 24px 60px rgba(0,0,0,0.45); }
.card-btns { position: absolute; left: 18px; right: 18px; bottom: calc(var(--safe-b) + 14px); align-items: stretch; }

@media (max-height: 700px) {
  .h-big { font-size: 30px; }
  .eq { font-size: 44px; }
  .center-card { top: calc(var(--safe-t) + 88px); }
  #hud { top: calc(var(--safe-t) + 56px); }
  .final { padding-top: calc(var(--safe-t) + 84px); }
  .hold { width: 96px; height: 96px; }
  .hint { bottom: calc(var(--safe-b) + 150px); }
  .stack { top: calc(var(--safe-t) + 190px); transform: scale(0.85); }
}

/* backend numbers: "N people have helped" on home, "player #N" on the final screen */
.home-count { color: var(--lime); font-weight: 700; }
.final-rank { margin-top: 6px; font-size: 15px; font-weight: 700; color: var(--lime); }
.final-rank:empty { display: none; }
