* { box-sizing: border-box; }
:root {
  --cream: #fff8e7; --cream2: #f6e7c8; --coral: #f25c54; --apricot: #f7b267; --teal: #2a9d8f; --night: #264653;
  --ink: #1b2f3a; --gold: #ffd36b;
  --font: "Baloo 2", "Nunito", system-ui, "Noto Sans", sans-serif;
  --cut: 0 3px 0 rgba(27,47,58,.35), 0 8px 0 rgba(27,47,58,.12);
}
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #10232c; color: var(--ink); font-family: var(--font);
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; touch-action: none;
}
#viewport { position: fixed; inset: 0; }
#stage { position: absolute; left: 0; top: 0; width: 1280px; height: 720px; transform-origin: 0 0; overflow: hidden; }
#game { position: absolute; inset: 0; width: 1280px; height: 720px; display: block; touch-action: none; }
button, select { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ---------------------------------------------------------------- paper surfaces */
.card, .pill, .btn, .toast, .rbtn {
  background-color: var(--cream);
  background-image:
    radial-gradient(rgba(120,90,40,.07) 1px, transparent 1.4px),
    linear-gradient(180deg, #fffaf0, #f8ecd2);
  background-size: 7px 7px, 100% 100%;
}
.card {
  position: relative; width: 560px; max-width: 92%; padding: 26px 32px 22px; border-radius: 22px 18px 24px 16px;
  /* second paper sheet peeking behind + cast shadow */
  box-shadow: 8px 8px 0 var(--apricot), 16px 16px 0 rgba(10,20,28,.35), 0 0 0 3px rgba(27,47,58,.12) inset;
  animation: cardIn .35s cubic-bezier(.2,1.6,.4,1) both;
}
.card.wide { width: 900px; }
.card.narrow { width: 380px; }
.card h2 { margin: 0 0 6px; font-size: 38px; line-height: 1.1; color: var(--coral); text-shadow: 2px 2px 0 rgba(27,47,58,.15); overflow-wrap: anywhere; }
.card .sub { margin: 4px 0 12px; font-size: 19px; font-weight: 700; color: #5a6a70; line-height: 1.3; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
@keyframes cardIn { from { transform: translateY(40px) rotate(-3deg) scale(.8); opacity: 0; } }

.overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.overlay.dim { background: rgba(10,22,30,.55); }

/* ---------------------------------------------------------------- buttons */
.btn {
  position: relative; border: 0; cursor: pointer; padding: 10px 26px; min-height: 58px; border-radius: 16px 14px 18px 12px;
  font-size: 24px; font-weight: 800; color: var(--ink); box-shadow: var(--cut); transition: transform .08s;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; line-height: 1.1; text-align: center;
}
.btn:hover { transform: translateY(-2px) rotate(-.6deg); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(27,47,58,.35); }
.btn.play { background: linear-gradient(180deg, #ff7a6e, var(--coral)); color: var(--cream); text-shadow: 0 2px 0 rgba(0,0,0,.18); }
.btn.daily { background: linear-gradient(180deg, #3cb8a8, var(--teal)); color: var(--cream); flex-direction: column; gap: 0; }
.btn.daily small { font-size: 15px; opacity: .9; font-weight: 700; }
.btn.ghost { background: rgba(255,248,231,.6); }
.btn.small { font-size: 20px; min-height: 50px; padding: 8px 18px; }
.btn .em { font-size: 24px; }
.btn[disabled] { filter: grayscale(.8); opacity: .6; cursor: default; }
.rbtn {
  width: 52px; height: 52px; border-radius: 50%; border: 0; cursor: pointer; font-size: 22px; font-weight: 800;
  box-shadow: var(--cut); display: grid; place-items: center;
}
.rbtn:active { transform: translateY(2px); }
.badge {
  position: absolute; top: -8px; right: -8px; min-width: 24px; height: 24px; border-radius: 12px; background: var(--coral);
  color: #fff; font-style: normal; font-size: 15px; line-height: 24px; border: 2px solid var(--cream); animation: bob 1s ease-in-out infinite;
}
@keyframes bob { 50% { transform: translateY(-4px); } }
.actions { display: flex; gap: 12px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 44px; padding: 0 16px 0 10px; border-radius: 22px;
  font-weight: 800; font-size: 22px; box-shadow: 0 3px 0 rgba(27,47,58,.35);
}
.pill.big { height: 50px; font-size: 26px; }
.pill.daily { background: var(--teal); color: var(--cream); padding: 0 14px; font-size: 18px; }
.pill.streak { color: var(--coral); font-size: 18px; padding: 0 14px; }
.ico-candle {
  display: inline-block; width: 30px; height: 30px; background: url(assets/items.webp) 0 50% / 400% auto no-repeat;
}
body.noart .ico-candle { background: radial-gradient(circle at 50% 30%, var(--gold) 25%, transparent 26%), linear-gradient(#fff1d0, #fff1d0) 50% 80% / 30% 55% no-repeat; }

/* ---------------------------------------------------------------- HUD */
#hud { position: absolute; left: 0; right: 0; top: 0; height: 110px; pointer-events: none; }
.hud-left { position: absolute; left: 18px; top: 16px; display: flex; gap: 10px; }
.hud-right { position: absolute; right: 18px; top: 16px; pointer-events: auto; }
.hud-score { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); text-align: center; }
#hud-score {
  display: inline-block; font-size: 76px; line-height: 1; color: var(--cream); font-weight: 800;
  text-shadow: 0 4px 0 var(--coral), 0 8px 0 rgba(10,20,28,.4), -3px 0 0 var(--night), 3px 0 0 var(--night), 0 -3px 0 var(--night);
}
#hud-score.pop { animation: pop .25s cubic-bezier(.2,2,.4,1); }
@keyframes pop { 0% { transform: scale(1.45) rotate(-4deg); } 100% { transform: scale(1); } }
.combo {
  margin-top: 2px; font-size: 22px; font-weight: 800; color: var(--gold); text-shadow: 0 2px 0 var(--night), 0 0 10px rgba(255,180,80,.7);
  animation: pop .25s cubic-bezier(.2,2,.4,1);
}

/* big callouts (combo praise, medals, scene names) */
#calls { position: absolute; left: 0; right: 0; top: 120px; display: flex; flex-direction: column; align-items: center; pointer-events: none; gap: 6px; }
.call {
  font-size: 50px; font-weight: 800; color: var(--cream); padding: 0 30px; max-width: 1000px; text-align: center; line-height: 1.1;
  text-shadow: 0 4px 0 var(--coral), 0 7px 0 rgba(10,20,28,.4), -2px 0 0 var(--night), 2px 0 0 var(--night);
  animation: callIn 1.6s cubic-bezier(.2,1.6,.4,1) both;
}
.call.gold { color: var(--gold); }
.call.teal { text-shadow: 0 4px 0 var(--teal), 0 7px 0 rgba(10,20,28,.4), -2px 0 0 var(--night), 2px 0 0 var(--night); }
.call.banner {
  font-size: 40px; color: var(--night); text-shadow: none; padding: 10px 44px; background: var(--cream);
  clip-path: polygon(0 0, 100% 0, 96% 50%, 100% 100%, 0 100%, 4% 50%); box-shadow: 0 6px 0 rgba(0,0,0,.3);
  animation: bannerIn 2.4s cubic-bezier(.2,1.4,.4,1) both;
}
.call.medal { display: flex; align-items: center; gap: 12px; }
.call.medal i { width: 90px; height: 90px; background: url(assets/medals.webp) 0 0 / 400% 100% no-repeat; animation: stampIn .5s cubic-bezier(.2,2,.4,1) both; }
@keyframes callIn { 0% { transform: scale(.3) rotate(-10deg); opacity: 0; } 12% { transform: scale(1.15) rotate(3deg); opacity: 1; } 22% { transform: scale(1); } 80% { opacity: 1; } 100% { transform: translateY(-30px); opacity: 0; } }
@keyframes bannerIn { 0% { transform: translateY(-120px) rotate(-6deg); } 15% { transform: translateY(0) rotate(2deg); } 85% { transform: translateY(0); opacity: 1; } 100% { transform: translateY(-120px); opacity: 0; } }
@keyframes stampIn { 0% { transform: scale(3) rotate(-30deg); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

.hint {
  position: absolute; left: 50%; top: 470px; transform: translateX(-50%); display: flex; align-items: center; gap: 12px;
  font-size: 30px; font-weight: 800; color: var(--cream); text-shadow: 0 3px 0 var(--night), 0 0 12px rgba(0,0,0,.5);
  pointer-events: none; white-space: nowrap; max-width: 1100px;
}
.hint .hand { font-size: 44px; animation: tap 0.9s ease-in-out infinite; }
@keyframes tap { 50% { transform: translateY(12px) scale(.9); } }

.toast {
  position: absolute; left: 50%; bottom: 36px; transform: translateX(-50%); padding: 12px 28px; border-radius: 16px;
  font-size: 22px; font-weight: 800; box-shadow: var(--cut); animation: cardIn .3s both; max-width: 80%; text-align: center; pointer-events: none;
}

/* ---------------------------------------------------------------- menu */
#menu { justify-content: flex-start; padding-top: 90px; background: linear-gradient(90deg, rgba(10,22,30,.55), rgba(10,22,30,.05) 60%); align-items: flex-start; padding-left: 80px; }
.menu-top { position: absolute; top: 18px; right: 20px; display: flex; gap: 12px; align-items: center; }
.logo h1 {
  margin: 0; font-size: 104px; line-height: .95; color: var(--cream); letter-spacing: 1px; max-width: 700px;
  text-shadow: 0 5px 0 var(--coral), 0 10px 0 var(--apricot), 0 16px 0 rgba(10,20,28,.45), -3px 0 0 var(--night), 3px 0 0 var(--night);
  transform: rotate(-3deg); animation: logoBob 3s ease-in-out infinite;
}
.logo p { margin: 18px 0 0 6px; font-size: 30px; font-weight: 800; color: var(--gold); text-shadow: 0 3px 0 var(--night); max-width: 640px; }
@keyframes logoBob { 50% { transform: rotate(-2deg) translateY(-6px); } }
.menu-main { display: flex; flex-direction: column; gap: 14px; margin-top: 34px; width: 360px; }
.menu-main .btn { width: 100%; }
.btn.play#btn-play { font-size: 40px; min-height: 84px; animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(1.04) rotate(-1deg); } }
.menu-row { display: flex; gap: 12px; margin-top: 14px; width: 360px; }
.menu-row .btn { flex: 1; padding: 8px 10px; font-size: 19px; }
.menu-foot { margin-top: 18px; font-size: 22px; font-weight: 800; color: var(--cream); text-shadow: 0 2px 0 var(--night); display: flex; gap: 16px; align-items: center; }
.medal-row { display: flex; gap: 8px; }
.medal-row span { display: inline-flex; align-items: center; gap: 2px; font-size: 18px; }
.medal-row i { width: 34px; height: 34px; background: url(assets/medals.webp) 0 0 / 400% 100% no-repeat; }
.medal-row .off { filter: grayscale(1) brightness(.6); opacity: .6; }

/* ---------------------------------------------------------------- daily */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: rgba(42,157,143,.12); border-radius: 12px; padding: 8px 12px; font-size: 20px; font-weight: 800; }

/* ---------------------------------------------------------------- shop */
.skin-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin-top: 10px; }
.skin {
  position: relative; border: 0; border-radius: 14px; padding: 6px 4px 8px; cursor: pointer; background: rgba(38,70,83,.08);
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 176px; transition: transform .1s;
}
.skin:hover { transform: translateY(-3px) rotate(-1deg); }
.skin.on { background: rgba(242,92,84,.18); box-shadow: 0 0 0 3px var(--coral) inset; }
.skin .pic { width: 118px; height: 88px; background: center / 400% 100% no-repeat; background-position: 0 0; }
.skin:hover .pic { background-position: 33.333% 0; animation: wiggle .4s ease-in-out infinite; }
@keyframes wiggle { 50% { transform: rotate(4deg) scale(1.05); } }
.skin.locked .pic { filter: brightness(0) opacity(.35); }
.skin .nm { font-size: 17px; font-weight: 800; line-height: 1.1; text-align: center; }
.skin .ds { font-size: 13px; font-weight: 700; color: #5a6a70; line-height: 1.15; text-align: center; min-height: 30px; }
.skin .tag { font-size: 16px; font-weight: 800; padding: 2px 10px; border-radius: 10px; background: var(--cream2); display: inline-flex; align-items: center; gap: 2px; }
.skin .tag .ico-candle { width: 22px; height: 22px; }
.skin .tag.buy { background: var(--gold); }
.skin .tag.use { background: var(--teal); color: var(--cream); }
.skin .tag.req { font-size: 12px; background: transparent; color: #5a6a70; text-align: center; }

/* ---------------------------------------------------------------- missions */
.mission-list { display: flex; flex-direction: column; gap: 10px; margin: 10px 0; }
.mission { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; background: rgba(38,70,83,.08); padding: 10px 14px; border-radius: 12px; }
.mission .txt { font-size: 20px; font-weight: 800; line-height: 1.15; }
.mission .bar { grid-column: 1; height: 10px; border-radius: 6px; background: rgba(27,47,58,.15); overflow: hidden; }
.mission .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--apricot), var(--coral)); }
.mission .btn { grid-row: 1 / span 2; grid-column: 2; min-height: 46px; font-size: 18px; padding: 6px 14px; }
.mission.done .txt { color: var(--teal); }

/* ---------------------------------------------------------------- settings */
.set-list { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.set { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 22px; font-weight: 800; }
.toggle { min-width: 90px; height: 42px; border-radius: 21px; border: 0; cursor: pointer; font-weight: 800; background: #cfd8d6; box-shadow: 0 3px 0 rgba(27,47,58,.3); }
.toggle.on { background: var(--teal); color: var(--cream); }
select { height: 44px; border-radius: 12px; border: 2px solid rgba(27,47,58,.3); background: var(--cream); font-size: 19px; font-weight: 700; padding: 0 8px; max-width: 260px; }

/* ---------------------------------------------------------------- results */
#result { background: radial-gradient(ellipse at center, rgba(10,22,30,.3), rgba(10,22,30,.6)); }
.card.result { width: 680px; text-align: center; }
.card.result h2 { font-size: 34px; }
.res-body { display: grid; grid-template-columns: 140px 1fr 190px; gap: 16px; align-items: center; margin-top: 8px; }
.medal-slot { width: 130px; height: 130px; border-radius: 50%; background: rgba(38,70,83,.1); display: grid; place-items: center; }
.medal-slot i.none { filter: grayscale(1) brightness(1.4); opacity: .22; animation: none; }
.medal-slot i { width: 128px; height: 128px; background: url(assets/medals.webp) 0 0 / 400% 100% no-repeat; animation: stampIn .45s .5s cubic-bezier(.2,2,.4,1) both; }
.res-line { display: flex; justify-content: space-between; align-items: baseline; font-size: 22px; font-weight: 800; color: #5a6a70; padding: 0 10px; }
.res-line b { font-size: 50px; color: var(--ink); line-height: 1.1; }
.newbest { display: inline-block; margin-top: 4px; font-size: 26px; font-weight: 800; color: var(--cream); background: var(--coral); padding: 2px 16px; border-radius: 10px; transform: rotate(-4deg); animation: stampIn .4s .9s both, bob 1s 1.3s infinite; }
.res-side { display: flex; flex-direction: column; gap: 6px; }
.res-chip { display: flex; align-items: center; gap: 6px; justify-content: flex-start; font-size: 18px; font-weight: 800; background: rgba(247,178,103,.25); border-radius: 10px; padding: 4px 10px; text-align: left; line-height: 1.15; }
.goal { margin: 12px 0 0; font-size: 21px; font-weight: 800; color: var(--teal); }
.res-missions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 6px; }
.res-missions span { font-size: 15px; font-weight: 800; background: var(--teal); color: var(--cream); padding: 3px 10px; border-radius: 10px; }
.retry-hint { margin: 10px 0 0; font-size: 16px; font-weight: 700; color: #7a8a90; animation: blink 1.4s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .4; } }

/* ---------------------------------------------------------------- loading / rotate */
.loader { text-align: center; color: var(--cream); font-size: 26px; font-weight: 800; }
.spin { width: 60px; height: 60px; margin: 0 auto 10px; border-radius: 50%; border: 6px solid rgba(255,248,231,.25); border-top-color: var(--coral); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#rotate {
  display: none; position: fixed; inset: 0; z-index: 9; background: var(--night); color: var(--cream); font-size: 22px; font-weight: 800;
  flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 20px;
}
#rotate span { font-size: 60px; animation: bob 1.2s infinite; }
@media (orientation: portrait) and (max-width: 700px) { body.touch #rotate { display: flex; } }

/* phones: the 1280x720 stage is scaled to ~50%, so small print gets bigger and flavour text goes */
@media (max-height: 500px), (max-width: 700px) {
  .skin .ds { display: none; }
  .skin { min-height: 150px; }
  .skin .nm { font-size: 21px; }
  .skin .tag { font-size: 20px; }
  .res-chip { font-size: 22px; }
  .retry-hint, .goal { font-size: 24px; }
  .mission .txt { font-size: 24px; }
  .card .sub { font-size: 22px; }
  .stat { font-size: 24px; }
  .btn.daily small { font-size: 18px; }
  .menu-foot { font-size: 26px; }
  .rbtn { width: 64px; height: 64px; font-size: 26px; }
}

/* CJK / Thai: slightly tighter headline sizes */
:lang(ja) .logo p, :lang(zh) .logo p, :lang(ko) .logo p, :lang(th) .logo p { font-size: 28px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}

/* phones: invisible hit-area padding around buttons (the 1280×720 stage is scaled down on small screens) */
@media (pointer: coarse) {
  .btn::after { content: ''; position: absolute; inset: -7px -5px; }
}
