/* Kira-Kira: counting game. Same design family as kasih4u.my / Mewarna (tokens first). */
@font-face { font-family: "Fredoka"; src: url("/assets/fonts/fredoka-latin.woff2") format("woff2"); font-weight: 500 700; font-display: swap; }
@font-face { font-family: "Nunito"; src: url("/assets/fonts/nunito-latin.woff2") format("woff2"); font-weight: 400 800; font-display: swap; }
:root {
  --paper: #fff7ec; --card: #ffffff; --line: rgba(31,35,71,.12); --line-strong: rgba(31,35,71,.24);
  --ink: #1f2347;            /* on paper 14.6:1 */
  --muted: #4a4f78;          /* 7.3:1 */
  --blue: #4361ee; --yellow: #ffb703; --red: #e63946; --green: #2a9d8f; --pink: #f15bb5; --purple: #9b5de5;
  --ok-bg: #e3f6ec; --ok-fg: #11613a; --bad-bg: #fde8e6; --bad-fg: #a1231b;
  --shadow-1: 0 1px 2px rgba(31,35,71,.06), 0 3px 8px rgba(31,35,71,.06);
  --shadow-2: 0 2px 4px rgba(31,35,71,.06), 0 10px 24px rgba(31,35,71,.10);
  --shadow-3: 0 4px 8px rgba(31,35,71,.08), 0 24px 48px rgba(31,35,71,.14);
  --font-display: "Fredoka", ui-rounded, system-ui, sans-serif; --font-body: "Nunito", ui-rounded, system-ui, sans-serif;
  --r-card: 28px; --r-inner: 20px; --r-chip: 12px;
  --ease: cubic-bezier(.16,1,.3,1); --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
}
*, *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--paper); color: var(--ink); font-family: var(--font-body); font-size: 17px; line-height: 1.5; overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
h1, h2 { font-family: var(--font-display); font-weight: 700; margin: 0; letter-spacing: -.02em; line-height: 1.15; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; border-radius: 10px; }

.top { display: flex; align-items: center; gap: 10px; padding: calc(12px + var(--safe-t)) 16px 12px; background: #fff; border-bottom: 1px solid var(--line); }
.brand { font-family: var(--font-display); font-weight: 700; font-size: 1.6rem; }
.brand b { color: var(--blue); }
.spacer { flex: 1; }
.icon-btn { display: inline-grid; place-items: center; min-width: 48px; height: 48px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line-strong); background: #fff; font-family: var(--font-display); font-weight: 600; font-size: 1.1rem; text-decoration: none; color: var(--ink); box-shadow: var(--shadow-1); transition: transform 150ms var(--ease); }
.icon-btn:active { transform: scale(.94); }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 52px; padding: 12px 28px; border-radius: 999px; border: 2px solid var(--ink); background: #fff; font-family: var(--font-display); font-weight: 600; font-size: 1.1rem; box-shadow: 0 3px 0 var(--ink); transition: transform 150ms var(--ease), box-shadow 150ms var(--ease); }
.btn:active { transform: translateY(2px) scale(.98); box-shadow: 0 1px 0 var(--ink); }
.btn-primary { background: var(--yellow); }
.btn-xl { min-height: 60px; font-size: 1.25rem; padding: 14px 34px; }
.chip { min-height: 48px; padding: 8px 22px; border-radius: 999px; border: 2px solid var(--line-strong); background: #fff; font-family: var(--font-display); font-weight: 600; transition: transform 150ms var(--ease); }
.chip:active { transform: scale(.96); }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }

#app { height: calc(100% - 73px - var(--safe-t)); overflow-y: auto; }
.view { max-width: 920px; margin: 0 auto; padding: 24px 20px calc(32px + var(--safe-b)); display: grid; gap: 22px; justify-items: center; text-align: center; }
.view > h1 { font-size: clamp(2rem, 6vw, 3rem); }
.sub { color: var(--muted); font-size: 1.15rem; }

.profiles { display: flex; flex-wrap: wrap; gap: 16px; justify-content: center; }
.pcard, .game-card { border: 2px solid var(--line); border-radius: var(--r-card); background: var(--card); box-shadow: var(--shadow-2); transition: transform 200ms var(--ease), box-shadow 200ms var(--ease); }
.pcard { width: 170px; padding: 20px 10px; font-family: var(--font-display); font-weight: 600; font-size: 1.3rem; }
.pcard .av { display: block; font-size: 64px; line-height: 1.1; }
.pcard:active, .game-card:active { transform: scale(.97); }
.pcard.add { border-style: dashed; color: var(--muted); }
.add-form { display: flex; gap: 10px; width: min(100%, 420px); }
.add-form input { flex: 1; min-width: 0; font: inherit; padding: 12px 16px; border-radius: 16px; border: 2px solid var(--line-strong); -webkit-user-select: text; user-select: text; }

.levels { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.games { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; width: 100%; }
.game-card { display: grid; justify-items: center; gap: 6px; padding: 24px 16px; }
.game-card b { font-family: var(--font-display); font-size: 1.4rem; }
.game-card small { color: var(--muted); font-size: 1rem; }
.g1 { background: #ffe9ec; } .g2 { background: #e3f6ec; } .g3 { background: #e8edff; }
.plus { display: grid; place-items: center; width: 76px; height: 76px; border-radius: 50%; background: var(--green); color: #fff; font-size: 48px; line-height: 1; border: 3px solid var(--ink); }
.it { width: 52px; height: 52px; }
.it.big { width: 76px; height: 76px; }

.game-top { display: flex; align-items: center; gap: 14px; width: 100%; }
.progress { flex: 1; height: 16px; border-radius: 999px; background: #fff; border: 2px solid var(--line-strong); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--yellow), var(--pink)); border-radius: 999px; transition: width 400ms var(--ease); }
.score { font-family: var(--font-display); font-weight: 700; font-variant-numeric: tabular-nums; min-width: 4.5em; text-align: right; }
.question { font-size: clamp(1.7rem, 5vw, 2.6rem); }
.stage { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 14px; width: 100%; min-height: 200px; padding: 20px; border-radius: var(--r-card); background: var(--card); border: 2px solid var(--line); box-shadow: var(--shadow-1); }
.group { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; max-width: 380px; padding: 8px; border-radius: var(--r-inner); border: 3px solid transparent; background: transparent; }
.group .it { transform: rotate(var(--r, 0deg)); transition: transform 250ms var(--ease); }
.group.pick { cursor: pointer; background: #f6f7ff; border-color: var(--line-strong); }
.group.pick:active { transform: scale(.97); }
.group.right { border-color: var(--green); background: var(--ok-bg); }
.group.wrong { border-color: var(--red); background: var(--bad-bg); animation: shake 380ms; }
.it.hl { transform: scale(1.35) rotate(0deg); filter: drop-shadow(0 4px 0 rgba(31,35,71,.25)); }
.num-badge { position: relative; }
.op { font-family: var(--font-display); font-weight: 700; font-size: 3.2rem; color: var(--muted); }
.qmark { display: grid; place-items: center; width: 76px; height: 76px; border-radius: 22px; border: 3px dashed var(--line-strong); font-family: var(--font-display); font-weight: 700; font-size: 2.6rem; color: var(--blue); }
.options { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; width: 100%; }
.opt { min-height: 88px; border-radius: var(--r-inner); border: 3px solid var(--ink); background: #fff; font-family: var(--font-display); font-weight: 700; font-size: 2.6rem; font-variant-numeric: tabular-nums; box-shadow: 0 5px 0 var(--ink); transition: transform 150ms var(--ease), box-shadow 150ms var(--ease), background-color 150ms; }
.opt:nth-child(1) { background: #ffe9ec; } .opt:nth-child(2) { background: #fff3c9; } .opt:nth-child(3) { background: #e3f6ec; } .opt:nth-child(4) { background: #e8edff; }
.opt:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }
.opt.right { background: var(--ok-bg); border-color: var(--ok-fg); box-shadow: 0 5px 0 var(--ok-fg); }
.opt.wrong { background: var(--bad-bg); border-color: var(--bad-fg); box-shadow: 0 5px 0 var(--bad-fg); animation: shake 380ms; }

.view#v-end { position: relative; min-height: 100%; align-content: center; }
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.end-card { position: relative; display: grid; gap: 14px; justify-items: center; padding: 28px 24px; width: min(100%, 520px); border-radius: var(--r-card); background: var(--card); border: 2px solid var(--line); box-shadow: var(--shadow-3); animation: pop 500ms cubic-bezier(.34,1.56,.64,1); }
.stars { display: flex; gap: 8px; }
.stars .it { width: 84px; height: 84px; animation: pop 600ms cubic-bezier(.34,1.56,.64,1) backwards; }
.stars .it.off { filter: grayscale(1); opacity: .3; }
.reward { display: flex; align-items: center; gap: 12px; padding: 8px 16px; border-radius: 18px; background: #fff7d6; border: 3px dashed var(--yellow); }
.reward span { font-size: 54px; line-height: 1; }
.end-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }

.dlg { width: min(92vw, 420px); padding: 28px; border: 1px solid var(--line-strong); border-radius: var(--r-card); background: #fff; color: var(--ink); box-shadow: var(--shadow-3); }
.dlg::backdrop { background: rgba(31,35,71,.55); }
.dlg h2 { font-size: 1.7rem; margin-bottom: 8px; }
.lock-q { font-family: var(--font-display); font-weight: 700; font-size: 1.8rem; text-align: center; margin: 12px 0; }
.lock-a { width: 100%; font: inherit; font-size: 1.8rem; text-align: center; padding: 12px; border-radius: 16px; border: 3px solid var(--line-strong); -webkit-user-select: text; user-select: text; }
.err { color: var(--bad-fg); font-weight: 800; }
.dlg-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
.break { position: fixed; inset: 0; z-index: 300; display: grid; place-items: center; background: linear-gradient(160deg, #2b2d42, #4361ee); }
.break-card { text-align: center; color: #fff; padding: 28px; max-width: 520px; }
.break-card h2 { font-size: 2.4rem; margin: 6px 0; } .break-card p { font-size: 1.2rem; opacity: .9; margin: 0 0 24px; }
.break-emoji { font-size: 90px; } .break .btn { background: rgba(255,255,255,.14); color: #fff; border-color: rgba(255,255,255,.4); box-shadow: none; }
.toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%); padding: 12px 20px; border-radius: 999px; background: var(--ink); color: #fff; font-weight: 800; z-index: 120; max-width: 92vw; text-align: center; }

@keyframes shake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
@keyframes pop { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@media (max-width: 640px) { .options { grid-template-columns: repeat(2, 1fr); } .it { width: 44px; height: 44px; } .opt { min-height: 76px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; } }

.g4 { background: #fff0d6; } .g5 { background: #f1e6ff; }
.plus.minus { background: var(--red); }
.game-card .pat { display: flex; gap: 2px; }
.game-card .pat .it { width: 40px; height: 40px; }
.it.gone { opacity: .22; filter: grayscale(1); transform: rotate(var(--r, 0deg)) scale(.85); }
.opt .it { width: 58px; height: 58px; vertical-align: middle; }
.opt.pic { display: grid; place-items: center; background: #fff !important; }
.seq { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px; }
.seq .it { width: 62px; height: 62px; }
.update-bar { position: fixed; z-index: 150; left: 50%; bottom: calc(18px + var(--safe-b)); transform: translateX(-50%); display: flex; align-items: center; gap: 14px; padding: 8px 10px 8px 20px; border-radius: 999px; background: var(--ink); color: #fff; font-weight: 800; box-shadow: 0 10px 30px rgba(0,0,0,.3); max-width: 94vw; }
.update-bar .btn { min-height: 44px; padding: 8px 20px; box-shadow: none; }
