/* Fredoka (SIL Open Font License), self-hosted so the game works offline */
@font-face {
  font-family: 'Fredoka';
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url(fonts/fredoka-latin.woff2) format('woff2');
}

/* Colour meaning is fixed across every Lav Studio game (docs/02-desain-visual.md):
   green + video icon = rewarded ad, --accent = main action, --gold = coins/score. */
:root {
  --bg0: #1a1033;
  --bg1: #2b1d4e;
  --bg2: #4a2c6e;
  --ink: #2a1840;
  --ink-2: #6b5a80;   /* secondary text on cream, ~5.5:1 */
  --cream: #fff7e8;
  --muted: #cfc3e6;   /* secondary text on dark, ~9:1 */
  --accent: #ff6b81;
  --accent-d: #d94860;
  --gold: #ffd23f;
  --green: #22c55e;
  --green-d: #15803d;
  --danger: #ff5a5f;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: radial-gradient(120% 90% at 50% 0%, var(--bg2) 0%, var(--bg1) 60%, var(--bg0) 100%);
  background-color: var(--bg1);
  color: var(--cream);
  font-family: "Fredoka", ui-rounded, "Segoe UI", system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
  touch-action: none;
}
body { position: fixed; inset: 0; }
button { touch-action: manipulation; font-family: inherit; cursor: pointer; color: inherit; border: 0; background: none; }
.hidden { display: none !important; }
.at-home .play-only { display: none !important; }
body:not(.at-home) .home-only { display: none !important; }

.ic { width: 1.25em; height: 1.25em; flex: none; vertical-align: middle; --acc: transparent; }

#app {
  height: 100%;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: max(8px, env(safe-area-inset-top)) 12px max(8px, env(safe-area-inset-bottom));
  gap: 8px;
}

/* ---------- HUD ---------- */
#hud { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; min-height: 56px; }
.stat { display: flex; flex-direction: column; line-height: 1; }
.stat .label { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.stat .value { font-size: 28px; font-weight: 700; margin-top: 4px; }
.score .value { color: var(--gold); text-shadow: 0 3px 0 rgba(0,0,0,.25); display: inline-block; transition: transform .12s; transform-origin: left center; }
.score .value.bump { transform: scale(1.18); }
.time { align-items: center; }
.time.low .value { color: var(--danger); }
.hud-right { grid-column: 3; display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.coin-chip { display: inline-flex; align-items: center; gap: 6px; background: rgba(0,0,0,.25); padding: 6px 12px 6px 6px; border-radius: 999px; font-weight: 700; color: var(--gold); }
.coin-chip .ic { width: 22px; height: 22px; }
.icon-btn { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: rgba(255,255,255,.1); color: var(--cream); }
.icon-btn .ic { width: 24px; height: 24px; --acc: rgba(255,255,255,.18); }
.icon-btn:active { transform: scale(.94); }

/* ---------- stage ---------- */
#stage { position: relative; flex: 1; min-height: 0; display: flex; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; border-radius: 22px; background: rgba(0,0,0,.18); box-shadow: inset 0 0 0 2px rgba(255,255,255,.08); }

#home { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; text-align: center; padding: 0 8px; }
.logo { margin: 0; font-size: 64px; line-height: 1; color: var(--accent); text-shadow: 3px 0 var(--cream), -3px 0 var(--cream), 0 3px var(--cream), 0 -3px var(--cream), 2px 2px var(--cream), -2px -2px var(--cream), 2px -2px var(--cream), -2px 2px var(--cream), 0 9px 0 rgba(0,0,0,.25); }
.tagline { margin: 0; max-width: 300px; font-size: 17px; color: var(--muted); }
.goal { margin: 0; min-height: 20px; font-size: 15px; color: var(--muted); }
.levels { display: flex; gap: 10px; }
.level { min-width: 120px; padding: 10px 14px; border-radius: 16px; background: rgba(255,255,255,.08); box-shadow: inset 0 0 0 2px rgba(255,255,255,.12); text-align: left; }
.level b { display: block; font-size: 18px; }
.level span { font-size: 13px; color: var(--muted); }
.level[aria-checked="true"] { box-shadow: inset 0 0 0 3px var(--accent); background: rgba(255,107,129,.16); }
.home-menu { display: flex; gap: 12px; }
.menu-btn { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 76px; min-height: 64px; padding: 8px; border-radius: 16px; background: rgba(255,255,255,.08); font-size: 13px; font-weight: 600; }
.menu-btn .ic { width: 28px; height: 28px; --acc: var(--accent); }
.dot { position: absolute; top: 6px; right: 12px; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 2px var(--bg1); }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 22px; border-radius: 16px; font-size: 18px; font-weight: 700; color: var(--cream); background: rgba(255,255,255,.12); box-shadow: inset 0 0 0 2px rgba(255,255,255,.2); transition: transform .08s; }
.btn:active { transform: translateY(3px); }
.btn:disabled { opacity: .55; }
.btn.big { min-height: 64px; min-width: 220px; font-size: 24px; border-radius: 20px; }
.btn.primary { background: linear-gradient(180deg, #ff8a9b, var(--accent)); box-shadow: 0 6px 0 var(--accent-d), 0 10px 18px rgba(255,107,129,.3); }
.btn.primary:active { box-shadow: 0 3px 0 var(--accent-d); }
.btn.ad { background: linear-gradient(180deg, #4ade80, var(--green)); color: #fff; box-shadow: 0 6px 0 var(--green-d); }
.btn.ad:active { box-shadow: 0 3px 0 var(--green-d); }
.btn.ad .ic, .btn.primary .ic { --acc: rgba(255,255,255,.35); }
.card .btn:not(.primary):not(.ad) { color: var(--ink); background: transparent; box-shadow: inset 0 0 0 2px rgba(42,24,64,.25); }
.btn.wide { width: 100%; }

/* ---------- banner (rules; the timer waits for it) ---------- */
.banner { position: absolute; inset: 0; margin: auto; width: min(320px, 90%); height: fit-content; padding: 22px; border-radius: 24px; text-align: center; background: rgba(26,16,51,.82); backdrop-filter: blur(6px); box-shadow: 0 0 0 2px rgba(255,255,255,.12); }
.banner h2 { margin: 6px 0; font-size: 26px; }
.banner p { margin: 0 0 16px; color: var(--muted); }
.big-ic { width: 48px; height: 48px; --acc: var(--accent); }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; top: calc(max(8px, env(safe-area-inset-top)) + 70px); transform: translateX(-50%); padding: 8px 16px; border-radius: 999px; background: rgba(0,0,0,.7); font-weight: 600; z-index: 40; max-width: 90vw; text-align: center; }

/* ---------- modal card ---------- */
.overlay { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px; background: rgba(10,6,24,.6); }
.card { width: min(360px, 100%); max-height: 100%; overflow: auto; padding: 22px 20px 20px; border-radius: 26px; background: var(--cream); color: var(--ink); box-shadow: 0 10px 0 rgba(0,0,0,.25); text-align: center; position: relative; }
.card h2 { margin: 0 0 6px; font-size: 28px; }
.card p { margin: 0 0 12px; color: var(--ink-2); }
.card .actions { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.card .row { display: flex; gap: 10px; }
.card .row .btn { flex: 1; }
.close-btn { position: absolute; top: 10px; right: 10px; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 14px; color: var(--ink-2); }
.close-btn .ic { width: 22px; height: 22px; }
.stars { display: flex; justify-content: center; gap: 6px; margin: 6px 0 10px; }
.stars .ic { width: 48px; height: 48px; }
.stars .on { color: var(--gold); filter: drop-shadow(0 3px 0 #c98f00); }
.stars .off { color: rgba(42,24,64,.18); }
.big-score { font-size: 44px; font-weight: 700; color: var(--ink); }
.coin-box { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border-radius: 18px; background: #f6ead2; }
.coin-box .n { display: flex; align-items: center; gap: 6px; font-size: 22px; font-weight: 700; color: #a86b00; }
.coin-box .btn { min-height: 44px; font-size: 16px; padding: 0 14px; }
.toggle { display: flex; align-items: center; justify-content: space-between; padding: 10px 4px; font-size: 17px; font-weight: 600; border-bottom: 1px solid rgba(42,24,64,.1); }
.toggle .ic { width: 24px; height: 24px; margin-right: 10px; --acc: var(--accent); }
.switch { width: 56px; height: 32px; border-radius: 999px; background: #d9cfe6; position: relative; }
.switch::after { content: ''; position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: left .15s; }
.switch[aria-checked="true"] { background: var(--green); }
.switch[aria-checked="true"]::after { left: 28px; }
.days { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 10px 0; }
.day { padding: 8px 4px; border-radius: 14px; background: #f1e4cc; font-size: 13px; color: var(--ink-2); }
.day b { display: block; font-size: 16px; color: #a86b00; }
.day.done { background: #d9f5e3; }
.day.today { box-shadow: inset 0 0 0 3px var(--accent); }
.day:last-child { grid-column: span 2; }
.help-list { text-align: left; padding-left: 20px; color: var(--ink); line-height: 1.5; }

/* ---------- mock ad ---------- */
.ad-mock { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.92); display: grid; place-items: center; opacity: 0; transition: opacity .2s; }
.ad-mock.show { opacity: 1; }
.ad-box { width: min(320px, 90vw); padding: 24px; border-radius: 22px; background: #fff; color: #222; text-align: center; }
.ad-tag { display: inline-block; padding: 3px 10px; border-radius: 999px; background: #222; color: #fff; font-size: 12px; letter-spacing: .1em; }
.ad-title { margin-top: 12px; font-size: 22px; font-weight: 700; }
.ad-sub { font-size: 13px; color: #666; }
.ad-ring { width: 84px; height: 84px; margin: 16px auto; border-radius: 50%; display: grid; place-items: center; box-shadow: inset 0 0 0 6px var(--green); font-size: 32px; font-weight: 700; }
.ad-note { font-size: 13px; color: #666; }
.ad-close { color: #fff !important; background: #222 !important; box-shadow: none !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- PUTAR! ---------- */
:root { --bg0: #0b0820; --bg1: #14102e; --bg2: #2a1f5c; }
#stage { touch-action: none; }
#home { gap: 14px; }
.emblem { width: 168px; height: 168px; }
.emblem .lane { fill: none; stroke: rgba(255,255,255,.18); stroke-width: 4; }
.emblem .core { fill: rgba(0,0,0,.3); stroke: var(--accent); stroke-width: 4; }
.emblem .ball { fill: var(--cream); stroke: var(--gold); stroke-width: 4; }
.emblem .spike { fill: #ff4d6d; stroke: #4a0d1e; stroke-width: 2; }
.emblem .spin, .emblem .spin2 { transform-origin: 100px 100px; animation: spin 3.2s linear infinite; }
.emblem .spin2 { animation-duration: 9s; animation-direction: reverse; }
@keyframes spin { to { transform: rotate(360deg); } }
.logo { font-size: 58px; }
.link-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 12px; color: var(--muted); font-weight: 600; font-size: 15px; }
.link-btn .ic { --acc: transparent; }
.home-menu { display: grid; grid-template-columns: repeat(4, minmax(0, 76px)); gap: 10px; }
.menu-btn { min-width: 0; }

.ballbar { display: flex; flex-direction: column; gap: 6px; width: min(300px, 100%); padding: 10px 14px; border-radius: 16px; background: rgba(255,255,255,.08); text-align: left; }
.ballbar-top { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; font-weight: 600; color: var(--muted); }
.ballbar-top b { color: var(--cream); font-weight: 700; }
.bar { display: block; height: 10px; border-radius: 999px; background: rgba(255,255,255,.12); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--accent), #ffb86b); transition: width .9s cubic-bezier(.2,.8,.2,1); }
.ballbar.in-card { width: 100%; background: #f6ead2; margin: 10px 0; }
.ballbar.in-card .ballbar-top { color: var(--ink-2); }
.ballbar.in-card .ballbar-top b { color: var(--ink); }
.ballbar.in-card .bar { background: rgba(42,24,64,.12); }

.ready-bar { position: absolute; left: 0; right: 0; bottom: 18px; display: flex; justify-content: center; pointer-events: none; }
.ready-bar > * { pointer-events: auto; }
.btn.ghost { background: rgba(255,255,255,.12); box-shadow: inset 0 0 0 2px rgba(255,255,255,.25); font-size: 16px; min-height: 46px; }
.btn.ghost .ic, .chip .ic { --acc: rgba(125,211,252,.35); color: #7dd3fc; }
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: 999px; background: rgba(125,211,252,.16); font-weight: 700; }
.ready-bar .btn.ad { font-size: 16px; min-height: 46px; }

.card .sub { margin-top: -4px; }
.run-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 6px 0; }
.run-stats span { display: flex; flex-direction: column; padding: 8px 4px; border-radius: 14px; background: #f1e4cc; font-size: 13px; color: var(--ink-2); }
.run-stats b { font-size: 20px; color: var(--ink); }
.unlock { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 16px; background: #ffe9a8; text-align: left; font-size: 15px; }
.ball-dot { display: inline-block; flex: none; border-radius: 50%; }
.mission-done { display: flex; align-items: center; gap: 8px; justify-content: center; font-size: 14px; font-weight: 600; color: var(--green-d); margin: 4px 0; }
.mission-done .ic { width: 18px; height: 18px; }

.mission { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid rgba(42,24,64,.1); text-align: left; }
.m-main { flex: 1; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.m-main .bar { background: rgba(42,24,64,.12); }
.m-main small { color: var(--ink-2); }
.m-reward { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; color: #a86b00; }
.m-done { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; color: var(--green-d); }
.m-btns { display: flex; flex-direction: column; gap: 6px; }
.btn.sm { min-height: 44px; font-size: 15px; padding: 0 12px; border-radius: 12px; }

.ball-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.ball-cell { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 2px; border-radius: 14px; background: #f1e4cc; font-size: 12px; font-weight: 600; color: var(--ink); min-height: 76px; justify-content: center; }
.ball-cell[aria-pressed="true"] { box-shadow: inset 0 0 0 3px var(--accent); }
.ball-cell.locked { color: var(--ink-2); }
.ball-cell.locked .ic { width: 26px; height: 26px; --acc: rgba(42,24,64,.12); }
.shop-item { display: flex; gap: 12px; align-items: center; text-align: left; padding: 12px; border-radius: 16px; background: #f1e4cc; }
.shop-item > .ic { width: 44px; height: 44px; color: #0e7490; --acc: #a5f3fc; }
.shop-item b { font-size: 18px; }
.shop-item small { display: block; color: var(--ink-2); }
.card .sub.note { margin-top: 12px; }
