:root {
  --pink: #ff8fb8;
  --orange: #ffb36b;
  --yellow: #ffd95e;
  --green: #7fd99a;
  --blue: #7cc4ff;
  --purple: #b998ff;
  --cream: #fff8ef;
  --ink: #46365f;
  --edge: rgba(70, 54, 95, .22); /* soft outline so white parts never melt into a light sky */
  --shadow: rgba(120, 80, 160, .28);
  --rainbow: linear-gradient(90deg, #ff8fb8, #ffb36b, #ffd95e, #7fd99a, #7cc4ff, #b998ff);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #ffe6f0;
  font-family: "Zen Maru Gothic", "Baloo 2", system-ui, sans-serif;
  color: var(--ink);
  user-select: none; -webkit-user-select: none;
  touch-action: none; overscroll-behavior: none;
}
canvas#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
button { font: inherit; border: 0; padding: 0; background: none; color: inherit; cursor: pointer; }

/* ---------- chunky toy buttons ---------- */
.round-btn, .big-btn, .pad-btn {
  display: grid; place-items: center;
  background: var(--cream);
  color: var(--ink);
  border-radius: 50%;
  box-shadow: 0 0 0 2.5px var(--edge), 0 6px 0 #d9bfe0, 0 10px 24px var(--shadow);
  transition: transform .12s cubic-bezier(.3,1.6,.5,1), box-shadow .12s;
}
.round-btn:active, .big-btn:active, .pad-btn:active, .pad-btn.down {
  transform: translateY(5px) scale(.96);
  box-shadow: 0 0 0 2.5px var(--edge), 0 1px 0 #d9bfe0, 0 4px 10px var(--shadow);
}
.round-btn { width: 64px; height: 64px; }
.round-btn svg { width: 34px; height: 34px; }
.big-btn { width: 112px; height: 112px; }
.big-btn svg { width: 56px; height: 56px; }
.big-btn.primary { background: var(--pink); color: #fff; box-shadow: 0 7px 0 #e46a98, 0 14px 30px var(--shadow); }
.big-btn.primary:active { box-shadow: 0 1px 0 #e46a98, 0 4px 10px var(--shadow); }

/* ---------- HUD ---------- */
#hud {
  position: fixed; left: 0; right: 0; top: 0;
  padding: calc(14px + var(--safe-t)) 16px 0;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  pointer-events: none; z-index: 10;
}
#hud > * { pointer-events: auto; }
#btn-sound .off { display: none; }
#btn-sound.muted .on { display: none; }
#btn-sound.muted .off { display: block; }

#sound-menu { position: fixed; z-index: 30; top: calc(88px + var(--safe-t)); right: 16px; width: 236px;
  padding: 14px; border-radius: 28px; background: rgba(255,248,239,.96); box-shadow: 0 0 0 2.5px var(--edge), 0 14px 40px var(--shadow);
  display: grid; gap: 10px; transform-origin: top right; animation: pop .35s cubic-bezier(.3,1.6,.5,1); }
#sound-menu.hidden { display: none; }
#sound-menu button { border: 0; cursor: pointer; font: 900 18px/1 "Zen Maru Gothic", system-ui, sans-serif; color: var(--ink); }
#sound-menu .toggle { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 20px; background: #fff; }
#sound-menu .toggle i { position: relative; width: 54px; height: 32px; border-radius: 16px; background: var(--green); transition: background .2s; flex: none; }
#sound-menu .toggle i::after { content: ""; position: absolute; top: 4px; left: 26px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,.15); transition: left .25s cubic-bezier(.3,1.6,.5,1); }
#sound-menu .toggle.off i { background: #d9cfe6; }
#sound-menu .toggle.off i::after { left: 4px; }
#sound-menu .voices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
#sound-menu .voice { display: grid; justify-items: center; gap: 6px; padding: 10px 6px 12px; border-radius: 22px; background: #fff; font-size: 15px;
  box-shadow: inset 0 0 0 3px transparent; transition: box-shadow .2s, transform .3s cubic-bezier(.3,1.8,.5,1); }
#sound-menu .voice img { width: 64px; height: 64px; object-fit: contain; }
#sound-menu .voice.on { box-shadow: inset 0 0 0 4px var(--pink); transform: scale(1.04); background: #fff0f6; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
#sound-menu .sync-open { padding: 10px 14px; border-radius: 20px; background: #fff; font-size: 16px; }

/* ---------- progress transfer (parents) ---------- */
#sync { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; background: rgba(70, 54, 95, .45); }
#sync.hidden { display: none; }
#sync .card { position: relative; width: min(420px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 22px 20px 20px; border-radius: 28px;
  background: var(--cream); color: var(--ink); box-shadow: 0 0 0 2.5px var(--edge), 0 20px 50px var(--shadow); display: grid; gap: 12px; animation: pop .35s cubic-bezier(.3,1.6,.5,1); }
#sync h2 { margin: 0; font-size: 24px; }
#sync .sub, #sync .tip { margin: 0; font-size: 14px; line-height: 1.5; opacity: .85; }
#sync .x { position: absolute; top: 12px; right: 14px; width: 40px; height: 40px; border-radius: 50%; background: #fff; font-size: 18px; box-shadow: 0 0 0 2px var(--edge); }
#sync .tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 5px; border-radius: 18px; background: #efe4f4; }
#sync .tabs button { padding: 10px; border-radius: 14px; font-weight: 900; font-size: 16px; }
#sync .tabs button.on { background: #fff; box-shadow: 0 0 0 2px var(--edge); }
#sync section { display: grid; gap: 10px; }
#sync .qr { justify-self: center; width: min(260px, 70vw); aspect-ratio: 1; max-width: 100%; background: #fff; border-radius: 14px; padding: 6px; box-shadow: 0 0 0 2px var(--edge); }
#sync .qr svg { width: 100%; height: 100%; display: block; }
#sync textarea { width: 100%; resize: none; padding: 10px 12px; border-radius: 14px; border: 2px solid var(--edge); background: #fff; color: var(--ink);
  font: 13px/1.4 ui-monospace, Menlo, monospace; word-break: break-all; user-select: text; -webkit-user-select: text; }
#sync .row { display: flex; gap: 8px; flex-wrap: wrap; }
#sync .row button, #sync .copy { flex: 1; padding: 12px 14px; border-radius: 16px; font-weight: 900; font-size: 16px; background: #fff; box-shadow: 0 0 0 2px var(--edge); }
#sync button.primary { background: var(--pink); color: #fff; box-shadow: 0 4px 0 #e46a98; }
#sync button.danger { background: #e8657a; color: #fff; }
#sync .confirm { display: grid; gap: 8px; padding: 12px; border-radius: 16px; background: #fde8ee; }
#sync .confirm[hidden], #sync section[hidden] { display: none; }
#sync .confirm p { margin: 0; font-weight: 800; }
#sync .msg { margin: 0; font-weight: 800; min-height: 1.2em; }
#sync .msg.ok { color: #2f8a55; } #sync .msg.bad { color: #c23a55; }

#progress {
  display: flex; flex-wrap: nowrap; justify-content: center; gap: 6px;
  max-width: min(70vw, 560px);
  padding: 10px 16px; border-radius: 40px;
  background: rgba(255, 248, 239, .92);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 0 0 2.5px var(--edge), 0 8px 24px var(--shadow);
  pointer-events: none;
}
#progress:empty { display: none; }
#progress i {
  /* shrink to stay on one row when the goal has many stars */
  --s: min(30px, calc((min(70vw, 560px) - 32px) / var(--n, 1) - 6px));
  width: var(--s); height: var(--s); flex: none; display: block;
  background: #c3b2d6;
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  transition: transform .4s cubic-bezier(.3,1.8,.5,1), background .3s;
}
#progress i.on { background: var(--c, var(--yellow)); transform: scale(1.25) rotate(20deg); animation: twinkle 1.6s ease-in-out infinite; }
@keyframes twinkle { 50% { transform: scale(1.1) rotate(-8deg); } }

/* ---------- score + choices ---------- */
#score {
  position: fixed; top: calc(88px + var(--safe-t)); left: 50%; translate: -50% 0; z-index: 10;
  padding: 6px 18px; border-radius: 30px; background: rgba(255,248,239,.85);
  box-shadow: 0 0 0 2.5px var(--edge), 0 6px 18px var(--shadow); font: 800 22px/1.2 "Baloo 2", "Zen Maru Gothic", sans-serif;
  font-variant-numeric: tabular-nums; pointer-events: none; white-space: nowrap;
}
#score.bump { animation: bump .35s cubic-bezier(.3,1.8,.5,1); }
@keyframes bump { 40% { scale: 1.2; } }
#choices {
  position: fixed; left: 50%; bottom: calc(22px + var(--safe-b)); translate: -50% 0; z-index: 11;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; width: min(94vw, 760px);
}
#choices button {
  min-width: 96px; min-height: 76px; padding: 10px 20px; border-radius: 28px;
  background: var(--cream); color: var(--ink); font: 900 26px/1.15 "Zen Maru Gothic", sans-serif;
  box-shadow: 0 6px 0 #e6cfe9, 0 10px 22px var(--shadow);
  animation: heroIn .45s cubic-bezier(.3,1.6,.5,1) both;
  transition: transform .12s cubic-bezier(.3,1.6,.5,1), box-shadow .12s, background .2s;
}
#choices button .e { display: block; font-size: 38px; line-height: 1.1; }
#choices button:active { transform: translateY(5px) scale(.96); box-shadow: 0 1px 0 #e6cfe9, 0 4px 10px var(--shadow); }
#choices button.right { background: #c9f2d3; }
#choices button.wrong { animation: shake .4s; }
@keyframes shake { 25% { transform: translateX(-8px) rotate(-3deg); } 75% { transform: translateX(8px) rotate(3deg); } }
#choices.small button { min-height: 56px; font-size: 20px; }

/* ---------- hint ---------- */
#hint {
  position: fixed; left: 12px; bottom: calc(12px + var(--safe-b));
  display: flex; align-items: flex-end; gap: 4px; z-index: 9; pointer-events: none;
  animation: hintIn .6s cubic-bezier(.3,1.6,.5,1) both;
}
#hint img { width: 110px; height: auto; filter: drop-shadow(0 8px 12px var(--shadow)); animation: bob 2.4s ease-in-out infinite; }
#hint .bubble {
  margin-bottom: 60px; padding: 12px 18px; border-radius: 26px 26px 26px 6px;
  background: var(--cream); box-shadow: 0 0 0 2.5px var(--edge), 0 10px 24px var(--shadow);
  font-size: 24px; font-weight: 900; display: flex; align-items: center; gap: 8px;
}
#hint .icon { font-size: 34px; line-height: 1; }
#hint .text:empty { display: none; }
@keyframes hintIn { from { transform: translateY(160px); } }
@keyframes bob { 50% { transform: translateY(-8px) rotate(-3deg); } }

/* ---------- virtual pad ---------- */
#pad { position: fixed; inset: auto 0 calc(18px + var(--safe-b)) 0; pointer-events: none; z-index: 9; }
#pad .pad-btn { position: absolute; width: 88px; height: 88px; pointer-events: auto; background: rgba(255,248,239,.92); }
#pad .pad-btn svg { width: 44px; height: 44px; }
#pad [data-k=left]  { left: 22px; bottom: 0; }
#pad [data-k=right] { right: 22px; bottom: 0; }
#pad [data-k=up]    { right: 22px; bottom: 104px; }
#pad [data-k=down]  { left: 22px; bottom: 104px; }
#pad.lr [data-k=up], #pad.lr [data-k=down] { display: none; }
#pad.jump [data-k=down] { display: none; }
#pad.dpad [data-k=up]   { right: 120px; bottom: 96px; }
#pad.dpad [data-k=down] { right: 120px; bottom: 0; left: auto; }
#pad.dpad [data-k=right] { right: 22px; bottom: 48px; }
#pad.dpad [data-k=left]  { right: 218px; bottom: 48px; left: auto; }
#pad.ud [data-k=left], #pad.ud [data-k=right] { display: none; }
#pad.ud [data-k=down] { left: auto; right: 22px; bottom: 0; }

/* ---------- celebration ---------- */
#celebrate {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center; align-content: center; gap: 8px;
  background: radial-gradient(circle at 50% 45%, rgba(255,250,240,.9), rgba(255,214,234,.85) 60%, rgba(214,196,255,.9));
  animation: fadeIn .4s ease both;
}
#celebrate .burst {
  position: absolute; width: 150vmax; height: 150vmax; left: 50%; top: 45%;
  translate: -50% -50%;
  background: repeating-conic-gradient(from 0deg, rgba(255,255,255,.55) 0 8deg, transparent 8deg 20deg);
  mask: radial-gradient(circle, #000 10%, transparent 55%);
  -webkit-mask: radial-gradient(circle, #000 10%, transparent 55%);
  animation: spin 18s linear infinite;
}
#celebrate .hero { position: relative; width: min(46vmin, 300px); filter: drop-shadow(0 18px 24px var(--shadow)); animation: heroIn .9s cubic-bezier(.3,1.6,.5,1) both, bob 2s 1s ease-in-out infinite; }
#celebrate .stars { position: relative; display: flex; gap: 10px; margin-top: -12px; }
#celebrate .stars i {
  width: 70px; height: 70px; display: block; background: var(--yellow);
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  filter: drop-shadow(0 4px 0 #e9b23a);
  animation: starIn .7s cubic-bezier(.3,2,.5,1) both;
}
#celebrate .stars i.dim { background: #eadff2; filter: drop-shadow(0 4px 0 #d9c6ff); }
#celebrate .stars i:nth-child(1) { animation-delay: .5s; transform: rotate(-14deg) translateY(10px); }
#celebrate .stars i:nth-child(2) { animation-delay: .7s; width: 88px; height: 88px; }
#celebrate .stars i:nth-child(3) { animation-delay: .9s; transform: rotate(14deg) translateY(10px); }
#celebrate .orb {
  position: relative; width: 54px; height: 54px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, var(--c, var(--pink)) 45%, color-mix(in srgb, var(--c, var(--pink)) 70%, #6a4a9a));
  box-shadow: 0 0 30px 8px color-mix(in srgb, var(--c, var(--pink)) 60%, transparent);
  animation: starIn .8s 1.1s cubic-bezier(.3,2,.5,1) both, bob 1.6s 2s ease-in-out infinite;
}
#celebrate .actions { position: relative; display: flex; gap: 28px; margin-top: 18px; animation: fadeUp .5s 1.3s both; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(30px); } }
@keyframes spin { to { rotate: 360deg; } }
@keyframes heroIn { from { transform: scale(.2) rotate(-20deg); opacity: 0; } }
@keyframes starIn { from { scale: 0; opacity: 0; } }

/* ---------- wipe transition ---------- */
#wipe {
  position: fixed; inset: 0; z-index: 30; pointer-events: none;
  background:
    radial-gradient(circle at 30% 30%, rgba(255,255,255,.6) 0 6%, transparent 6.5%),
    radial-gradient(circle at 70% 65%, rgba(255,255,255,.5) 0 4%, transparent 4.5%),
    linear-gradient(135deg, #ffb3cf, #ffd59a 30%, #b9eec6 55%, #a9d8ff 75%, #cdb6ff);
  clip-path: circle(0% at 50% 50%);
  transition: clip-path .55s cubic-bezier(.7,0,.3,1);
}
#wipe.on { clip-path: circle(150% at 50% 50%); pointer-events: auto; }

/* ---------- splash ---------- */
#splash {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center; align-content: center; gap: 4px;
  overflow: hidden; transition: opacity .6s ease, visibility .6s;
}
#splash.gone { opacity: 0; visibility: hidden; }
#splash .sky {
  position: absolute; inset: -20%;
  background:
    radial-gradient(ellipse at 20% 80%, #fff 0 10%, transparent 30%),
    radial-gradient(ellipse at 85% 75%, #fff 0 8%, transparent 25%),
    conic-gradient(from 200deg at 50% 120%, #ff9cc2, #ffc48a, #ffe78f, #a8ecb9, #9fd3ff, #c9adff, #ff9cc2);
  filter: saturate(.75) brightness(1.12);
  animation: spin 60s linear infinite;
}
#splash .logo { position: relative; text-align: center; }
#splash h1 {
  margin: 0; font-family: "Baloo 2", sans-serif; font-weight: 800;
  font-size: clamp(64px, 16vmin, 140px); line-height: .9; letter-spacing: .01em;
}
#splash h1 span { display: inline-block; text-shadow: 0 6px 0 rgba(255,255,255,.9), 0 14px 26px var(--shadow); animation: letter 2.2s ease-in-out infinite; }
#splash h1 span:nth-child(1) { color: #ff6fa5; }
#splash h1 span:nth-child(2) { color: #ff9d4d; animation-delay: .1s; }
#splash h1 span:nth-child(3) { color: #f5c22e; animation-delay: .2s; }
#splash h1 span:nth-child(4) { color: #4cc77a; animation-delay: .3s; }
#splash h1 span:nth-child(5) { color: #4aa9f5; animation-delay: .4s; }
#splash h1 span:nth-child(6) { color: #9a72f2; animation-delay: .5s; }
@keyframes letter { 0%, 60%, 100% { transform: none; } 30% { transform: translateY(-14px) rotate(-4deg); } }
#splash .logo p { margin: 6px 0 0; font-size: clamp(22px, 4.6vmin, 34px); font-weight: 900; color: #fff; text-shadow: 0 3px 12px rgba(150,90,170,.55); letter-spacing: .12em; }
#splash .hero { position: relative; width: min(38vmin, 260px); filter: drop-shadow(0 18px 26px var(--shadow)); animation: bob 2.4s ease-in-out infinite; }
#splash .loader { position: relative; width: min(60vw, 280px); height: 18px; border-radius: 12px; background: rgba(255,255,255,.7); overflow: hidden; box-shadow: inset 0 2px 4px rgba(0,0,0,.08); }
#splash .loader i { display: block; height: 100%; width: 0; background: var(--rainbow); border-radius: 12px; transition: width .3s; }
#splash #btn-start { position: relative; animation: heroIn .6s cubic-bezier(.3,1.6,.5,1) both, pulse 1.4s 1s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }

@media (max-height: 520px) {
  .round-btn { width: 52px; height: 52px; }
  #hint img { width: 80px; }
  #hint .bubble { margin-bottom: 40px; font-size: 20px; }
  #celebrate .hero { width: 34vmin; }
  .big-btn { width: 88px; height: 88px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01s !important; animation-iteration-count: 1 !important; }
}

/* ---------- diary ---------- */
#btn-diary { position: fixed; right: 16px; bottom: calc(16px + var(--safe-b)); z-index: 10; }
#diary { position: fixed; inset: 0; z-index: 25; display: grid; place-items: center; padding: 16px; background: rgba(120, 90, 170, .35); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); animation: fadeIn .3s both; }
#diary .book {
  width: min(100%, 760px); max-height: 100%; overflow: auto; border-radius: 28px; padding: 18px;
  background: repeating-linear-gradient(0deg, #fffaf2 0 31px, #f1e6f7 31px 32px); box-shadow: 0 20px 50px var(--shadow);
  animation: heroIn .5s cubic-bezier(.3,1.6,.5,1) both;
}
#diary header { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
#diary header img { width: 64px; }
#diary header div { flex: 1; min-width: 0; }
#diary h2 { margin: 0; font-size: 26px; font-weight: 900; }
#diary .orbs { margin: 2px 0 0; font-weight: 700; font-size: 18px; }
#diary .close { width: 52px; height: 52px; }
#diary .pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 12px; }
#diary .page { border-radius: 20px; padding: 10px 8px 8px; text-align: center; background: #fff; box-shadow: 0 6px 14px var(--shadow); }
#diary .page img { width: 80%; aspect-ratio: 1; object-fit: contain; transform: rotate(var(--r, -4deg)); filter: drop-shadow(0 3px 0 #fff) drop-shadow(0 6px 8px var(--shadow)); }
#diary .page b { display: block; font-size: 16px; margin-top: 4px; }
#diary .page i { font-style: normal; font-size: 14px; letter-spacing: 2px; }
#diary .page.empty { background: transparent; border: 3px dashed #d9c6ff; box-shadow: none; display: grid; place-items: center; min-height: 150px; font-size: 42px; color: #d9c6ff; }
