:root {
  --bg1: #fdf3ff; --bg2: #d9ecff;
  --ink: #2a2140; --ink2: #6b6385;
  --card: #ffffffee; --line: #e6e0f3;
  --pri: #6c4cf5; --pri2: #8f73ff; --acc: #ff7eb6; --gold: #ffb627; --ok: #2fbf71;
  --shadow: 0 8px 24px rgba(60, 40, 120, .16);
  --r: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg1: #1d1830; --bg2: #102238; --ink: #f2eeff; --ink2: #b3abcf;
    --card: #2a2442ee; --line: #3d3560; --shadow: 0 8px 24px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  font-family: 'Baloo 2', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--ink);
  background: radial-gradient(120% 90% at 20% 0%, var(--bg1), var(--bg2));
  user-select: none; -webkit-user-select: none; touch-action: none;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; display: none; z-index: 5; }
.screen.show { display: block; }
.panel-screen { background: radial-gradient(120% 90% at 20% 0%, var(--bg1), var(--bg2)); overflow-y: auto; touch-action: pan-y; padding: calc(12px + var(--safe-t)) 16px calc(24px + var(--safe-b)); }
#home { pointer-events: none; }
#home > * { pointer-events: auto; }
.home-inner { position: absolute; left: 0; right: 0; bottom: calc(28px + var(--safe-b)); display: flex; flex-direction: column; align-items: center; padding: 0 16px; pointer-events: none; }
.home-inner > * { pointer-events: auto; }
.logo { margin: 0; font-size: clamp(44px, 12vw, 76px); line-height: .9; font-weight: 800; letter-spacing: -1px;
  background: linear-gradient(90deg, #ff6b9a, #ffb627 35%, #36b56a 60%, #2f6fed 80%, #7b4ff0); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 0 rgba(42, 33, 64, .12)); }
.logo span { font-size: .55em; margin-left: 6px; vertical-align: super; }
.tag { margin: 6px 0 18px; color: var(--ink2); font-weight: 500; text-align: center; max-width: 380px; line-height: 1.3; }
.home-btns { display: grid; gap: 10px; width: min(360px, 100%); }
.home-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 16px; margin-top: 14px; font-size: 15px; font-weight: 600; }
.home-links a { color: var(--ink2); text-decoration: none; white-space: nowrap; }
.home-links a:hover { color: var(--pri); text-decoration: underline; }
.visits { margin-top: 4px; font-size: 13px; color: var(--ink2); opacity: .85; }
.nojs { position: absolute; top: 40%; left: 16px; right: 16px; text-align: center; background: var(--card); padding: 12px; border-radius: 12px; }
.topright { position: absolute; top: calc(12px + var(--safe-t)); right: 16px; display: flex; gap: 8px; align-items: center; }

.big-btn { background: var(--card); border-radius: 16px; padding: 12px 18px; font-size: 20px; font-weight: 700; box-shadow: var(--shadow), inset 0 -3px 0 rgba(0,0,0,.07); transition: transform .08s; }
.big-btn:active { transform: translateY(2px) scale(.98); }
.big-btn.primary { background: linear-gradient(180deg, var(--pri2), var(--pri)); color: #fff; box-shadow: 0 6px 0 #4b30c4, var(--shadow); }
.big-btn.primary:active { box-shadow: 0 2px 0 #4b30c4; transform: translateY(4px); }
.big-btn.alt { background: linear-gradient(180deg, #ffd36b, var(--gold)); color: #4a3000; box-shadow: 0 6px 0 #d98e00, var(--shadow); }
.icon-btn { width: 44px; height: 44px; border-radius: 14px; background: var(--card); box-shadow: var(--shadow); font-size: 22px; font-weight: 800; display: grid; place-items: center; flex: none; }
.icon-btn.small { width: 40px; height: 40px; font-size: 18px; border-radius: 12px; }
.icon-btn.on { background: var(--pri); color: #fff; }
.icon-btn:disabled { opacity: .4; }
.coins { display: flex; align-items: center; gap: 6px; background: var(--card); padding: 6px 12px 6px 8px; border-radius: 999px; box-shadow: var(--shadow); font-size: 18px; }
.coin-ic { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff3b0, var(--gold) 55%, #e08e00); color: transparent; font-size: 0; }

.screen-head { display: flex; align-items: center; gap: 12px; max-width: 980px; margin: 0 auto; }
.screen-head h2 { flex: 1; margin: 0; font-size: 28px; }
.screen-sub { max-width: 980px; margin: 6px auto 14px; color: var(--ink2); }
.grid { max-width: 980px; margin: 0 auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.card { position: relative; background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 8px 8px 10px; text-align: center; transition: transform .1s; }
.card:active { transform: scale(.97); }
.card .thumb { width: 100%; aspect-ratio: 1; border-radius: 12px; background: linear-gradient(160deg, #fff, #efeaff); display: grid; place-items: center; font-size: 44px; overflow: hidden; }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.card .nm { font-weight: 700; margin-top: 4px; font-size: 17px; line-height: 1.1; }
.card .num { position: absolute; top: 12px; left: 12px; background: var(--pri); color: #fff; border-radius: 10px; padding: 0 8px; font-weight: 800; font-size: 14px; }
.card .st { color: #d8d2e8; font-size: 18px; letter-spacing: 2px; }
.card .st b { color: var(--gold); font-weight: 400; }
.card.locked { opacity: .55; }
.card.locked .thumb { filter: grayscale(1) blur(1px); }
.card .lock { position: absolute; inset: 8px 8px auto 8px; aspect-ratio: 1; display: grid; place-items: center; font-size: 36px; }

.shop-list { max-width: 640px; margin: 0 auto; display: grid; gap: 10px; }
.shop-item { display: flex; align-items: center; gap: 12px; background: var(--card); border-radius: var(--r); padding: 12px; box-shadow: var(--shadow); }
.shop-item .ic { width: 56px; height: 56px; border-radius: 14px; display: grid; place-items: center; font-size: 28px; background: linear-gradient(160deg, #fff, #efeaff); flex: none; }
.shop-item .tx { flex: 1; min-width: 0; }
.shop-item .tx b { display: block; font-size: 18px; }
.shop-item .tx span { color: var(--ink2); font-size: 14px; line-height: 1.2; display: block; }
.shop-item button { background: linear-gradient(180deg, #ffd36b, var(--gold)); color: #4a3000; border-radius: 12px; padding: 8px 12px; font-weight: 800; white-space: nowrap; }
.shop-item button:disabled { background: #ddd; color: #888; }
.shop-item .owned { color: var(--ok); font-weight: 800; }

/* ---------- HUD ---------- */
.hud { pointer-events: none; }
.hud > * { pointer-events: auto; }
.hud-top { position: absolute; top: calc(8px + var(--safe-t)); left: 12px; right: 12px; display: flex; gap: 8px; align-items: center; pointer-events: none; }
.hud-top > * { pointer-events: auto; }
.hud-title { flex: 1; min-width: 0; background: var(--card); border-radius: 14px; padding: 4px 12px; box-shadow: var(--shadow); height: 44px; display: flex; flex-direction: column; justify-content: center; }
#hud-name { font-weight: 800; font-size: 17px; line-height: 1.05; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acc { display: none; align-items: center; gap: 8px; }
.hud.challenge .acc { display: flex; }
.acc-bar { position: relative; flex: 1; height: 8px; background: #e9e4f5; border-radius: 4px; overflow: hidden; }
.acc-bar i { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, #ff7eb6, #ffb627, #2fbf71); border-radius: 4px; transition: width .3s; }
.acc-bar s { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; }
.acc b { font-size: 14px; min-width: 38px; text-align: right; }

.ref-card { position: absolute; display: none; right: 12px; top: calc(60px + var(--safe-t)); width: 116px; height: 116px; border-radius: 16px; border: 3px solid #fff; box-shadow: var(--shadow); pointer-events: none; background: transparent; }
.hud.challenge .ref-card { display: block; }
.ref-label { position: absolute; top: -10px; left: 8px; background: var(--pri); color: #fff; font-size: 12px; font-weight: 800; padding: 0 8px; border-radius: 8px; }
.peek { pointer-events: auto; position: absolute; bottom: -14px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; font-size: 12px; font-weight: 700; padding: 2px 10px; border-radius: 10px; white-space: nowrap; }
.peek.on { background: var(--acc); }
.hint { position: absolute; left: 12px; top: calc(60px + var(--safe-t)); max-width: calc(100% - 160px); background: var(--card); padding: 6px 12px; border-radius: 12px; box-shadow: var(--shadow); font-size: 14px; line-height: 1.2; display: none; }
.hint.show { display: block; }

.side-btns { position: absolute; left: 12px; top: 50%; transform: translateY(-60%); display: flex; flex-direction: column; gap: 8px; }
.hud.challenge .free-only, .hud:not(.challenge) .challenge-only { display: none !important; }
.done-btn { position: absolute; right: 12px; bottom: calc(var(--dock-h, 170px) + 12px); background: linear-gradient(180deg, #4fdc8f, var(--ok)); color: #fff; font-weight: 800; font-size: 18px; padding: 8px 16px; border-radius: 14px; box-shadow: 0 5px 0 #1f9a55, var(--shadow); }
.done-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #1f9a55; }

.dock { position: absolute; left: 50%; transform: translateX(-50%); bottom: 0; width: min(760px, 100%); background: var(--card); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-radius: 22px 22px 0 0; box-shadow: 0 -6px 24px rgba(60,40,120,.12); padding: 10px 12px calc(10px + var(--safe-b)); display: grid; gap: 8px; }
@media (min-width: 800px) and (min-height: 600px) { .dock { bottom: 16px; border-radius: 22px; } .palette { flex-wrap: wrap; overflow: visible; } }
.tools { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; touch-action: pan-x; }
.tools::-webkit-scrollbar, .palette::-webkit-scrollbar { display: none; }
.tool { flex: 1 0 58px; display: flex; flex-direction: column; align-items: center; padding: 4px 2px 2px; border-radius: 12px; background: transparent; font-size: 12px; font-weight: 700; color: var(--ink2); position: relative; }
.tool .ti { font-size: 24px; line-height: 1.1; }
.tool.on { background: var(--pri); color: #fff; box-shadow: 0 3px 0 #4b30c4; }
.tool.locked { opacity: .45; }
.tool.locked::after { content: '🔒'; position: absolute; top: 0; right: 4px; font-size: 11px; }
.size-row { display: flex; align-items: center; gap: 10px; padding: 0 4px; }
.size-dot { width: 26px; height: 26px; display: grid; place-items: center; flex: none; }
.size-dot::before { content: ''; width: var(--d, 10px); height: var(--d, 10px); max-width: 26px; max-height: 26px; border-radius: 50%; background: var(--c, #333); box-shadow: 0 0 0 1px rgba(0,0,0,.15); }
.size-val { width: 28px; font-weight: 700; color: var(--ink2); text-align: right; }
input[type=range] { flex: 1; -webkit-appearance: none; appearance: none; height: 28px; background: transparent; touch-action: pan-x; }
input[type=range]::-webkit-slider-runnable-track { height: 8px; border-radius: 4px; background: linear-gradient(90deg, #e3ddf5, #c9bcf6); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 24px; height: 24px; margin-top: -8px; border-radius: 50%; background: var(--pri); border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.25); }
input[type=range]::-moz-range-track { height: 8px; border-radius: 4px; background: #d7cff3; }
input[type=range]::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; background: var(--pri); border: 3px solid #fff; }
.palette { display: flex; gap: 8px; overflow-x: auto; padding: 6px 6px 4px; touch-action: pan-x; scrollbar-width: none; align-items: center; }
.sw { flex: none; width: 36px; height: 36px; border-radius: 50%; box-shadow: inset 0 0 0 2px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.12); position: relative; transition: transform .1s; }
.sw.on { transform: scale(1.12); box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--pri); }
.sw.goal::after { content: ''; position: absolute; right: -2px; top: -2px; width: 12px; height: 12px; border-radius: 50%; background: var(--ok); border: 2px solid #fff; }
.sw.rainbow { background: conic-gradient(#ff5e5e, #ffd23f, #36b56a, #2f6fed, #7b4ff0, #ff5e5e); }
.sw.custom { background: conic-gradient(from 90deg, #f55, #ff5, #5f5, #5ff, #55f, #f5f, #f55); display: grid; place-items: center; overflow: hidden; }
.sw.custom input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.sw.custom::before { content: '+'; color: #fff; font-weight: 800; font-size: 20px; text-shadow: 0 1px 2px rgba(0,0,0,.4); }
.sep { flex: none; width: 2px; height: 28px; background: var(--line); border-radius: 1px; }
.cursor { position: fixed; left: 0; top: 0; border: 2px solid rgba(255,255,255,.95); border-radius: 50%; box-shadow: 0 0 0 1px rgba(0,0,0,.35); pointer-events: none; display: none; transform: translate(-50%, -50%); z-index: 4; }

@media (orientation: landscape) and (max-height: 520px) {
  .dock { width: min(560px, 60%); left: auto; right: 0; transform: none; border-radius: 22px 0 0 0; padding: 6px 10px calc(6px + var(--safe-b)); gap: 4px; }
  .tool .ti { font-size: 20px; }
  .sw { width: 30px; height: 30px; }
  .ref-card { width: 92px; height: 92px; }
  .side-btns { gap: 6px; top: calc(60px + var(--safe-t)); transform: none; }
  .icon-btn.small { width: 36px; height: 36px; }
}

/* ---------- modal / misc ---------- */
.modal { position: fixed; inset: 0; z-index: 20; display: none; place-items: center; background: rgba(30, 20, 60, .45); padding: 16px; }
.modal.show { display: grid; animation: fade .2s; }
.modal-card { background: var(--card); background-color: #fff; border-radius: 24px; padding: 20px; width: min(380px, 100%); text-align: center; box-shadow: var(--shadow); animation: popin .35s cubic-bezier(.2,1.6,.4,1); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .modal-card { background-color: #2a2442; } }
.modal-card h3 { margin: 0; font-size: 28px; }
.modal-card p { color: var(--ink2); }
.stars { font-size: 56px; letter-spacing: 6px; color: #e2dcef; margin: 6px 0; }
.stars span.on { color: var(--gold); display: inline-block; animation: starin .5s cubic-bezier(.2,1.8,.4,1) both; text-shadow: 0 3px 0 #d98e00; }
.res-acc { font-size: 18px; }
.res-coins { font-size: 22px; font-weight: 800; color: #c98200; margin: 4px 0 14px; }
.modal-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.link-btn { margin-top: 12px; color: var(--ink2); text-decoration: underline; }
.pop { position: fixed; z-index: 15; display: none; background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 6px; flex-direction: column; gap: 4px; }
.pop.show { display: flex; }
.pop button { padding: 8px 14px; border-radius: 10px; font-weight: 700; text-align: left; }
.pop button.on { background: var(--pri); color: #fff; }
.pop button.locked { opacity: .5; }
.loading { position: fixed; inset: 0; z-index: 30; display: none; place-items: center; align-content: center; gap: 12px; background: rgba(250, 245, 255, .6); backdrop-filter: blur(4px); font-weight: 700; color: var(--ink); }
.loading.show { display: grid; }
.spin { width: 48px; height: 48px; border-radius: 50%; border: 5px solid #e3dcf8; border-top-color: var(--pri); animation: rot 0.8s linear infinite; justify-self: center; }
.toast { position: fixed; z-index: 25; left: 50%; top: calc(64px + var(--safe-t)); transform: translate(-50%, -20px); opacity: 0; background: var(--ink); color: #fff; padding: 8px 16px; border-radius: 999px; font-weight: 700; transition: .25s; pointer-events: none; max-width: calc(100% - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 21; }
@keyframes rot { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes popin { from { transform: scale(.7); opacity: 0; } }
@keyframes starin { from { transform: scale(0) rotate(-90deg); } }
