:root {
  --ink: #2b2f5c;
  --ink2: #6a6d93;
  --paper: #fffaf2;
  --teal: #12a3a0;
  --tealD: #0c7f7c;
  --mari: #f6a623;
  --rani: #e84a8a;
  --indigo: #4a5bd4;
  --leaf: #5dbb46;
  --shadow: 0 10px 28px rgba(140, 90, 40, .16), 0 2px 6px rgba(140, 90, 40, .12);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", "Trebuchet MS", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: var(--font); color: var(--ink);
  background: #fdeedb url(img/bg.jpg) center / cover no-repeat;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
}
@media (max-aspect-ratio: 1/1) { body { background-image: url(img/bgtall.jpg); } }
button { font-family: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
.hidden { display: none !important; }
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* header */
#top { position: relative; z-index: 25; display: flex; align-items: center; gap: 8px; padding: 10px 14px 6px; padding-top: max(10px, env(safe-area-inset-top)); flex: 0 0 auto; }
#title { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 6px; white-space: nowrap; overflow: hidden; }
#title b { font-size: 21px; font-weight: 900; color: var(--ink); }
#title span { font-size: 15px; font-weight: 800; color: var(--tealD); }
.ib { width: 42px; height: 42px; flex: 0 0 42px; border-radius: 50%; border: 0; background: var(--paper); display: grid; place-items: center; padding: 0; box-shadow: var(--shadow); color: var(--ink); }
.ib svg { width: 22px; height: 22px; }
.ib:active { transform: scale(.92); }
.pill { height: 38px; padding: 0 14px 0 10px; border-radius: 19px; background: var(--paper); display: flex; align-items: center; gap: 5px; font-size: 17px; box-shadow: var(--shadow); }
.st { font-style: normal; color: var(--mari); font-size: 20px; line-height: 1; }

/* buttons */
.btn { border: 0; border-radius: 999px; background: linear-gradient(180deg, #19b8b4, var(--tealD)); color: #fff; font-weight: 900; font-size: 18px; padding: 13px 26px; box-shadow: 0 5px 0 #08605e, var(--shadow); transition: transform .08s; }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #08605e; }
.btn.ghost { background: var(--paper); color: var(--ink); box-shadow: 0 4px 0 #e2cdb0, var(--shadow); }
.btn.huge { font-size: 32px; padding: 16px 72px; animation: breathe 2.4s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(1.05); } }

/* overlays */
.overlay { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 14px; background: rgba(253, 238, 219, .5); }
.sCard { width: min(560px, 100%); text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.sGappu { width: min(200px, 26vh); height: auto; animation: bob 2.8s ease-in-out infinite; filter: drop-shadow(0 8px 10px rgba(120, 80, 40, .2)); }
.sTitle { margin: 0; font-size: clamp(40px, 8vh, 64px); font-weight: 900; line-height: .95; display: flex; flex-direction: column; align-items: center; }
.sTitle span { font-size: .45em; color: var(--tealD); letter-spacing: 3px; text-transform: uppercase; margin-top: 6px; }
.sIntro { margin: 2px 0 8px; font-size: 16px; font-weight: 700; color: var(--ink2); max-width: 470px; line-height: 1.35; }
.ctrls { display: flex; flex-wrap: wrap; gap: 6px 16px; justify-content: center; font-size: 14px; font-weight: 700; color: var(--ink2); margin-top: 8px; }
.key { display: inline-block; font-style: normal; min-width: 24px; padding: 2px 7px; margin: 0 2px; border-radius: 8px; background: #fff; color: var(--ink); box-shadow: 0 2px 0 #dcc6a8; font-size: 13px; }
@keyframes bob { 50% { transform: translateY(-8px); } }

/* hub */
.screen { flex: 1; min-height: 0; }
#hub, #levels { overflow-y: auto; touch-action: pan-y; -webkit-overflow-scrolling: touch; padding: 6px 14px 28px; }
.hubWrap, .lvWrap { max-width: 980px; margin: 0 auto; }
.daily { width: 100%; display: flex; align-items: center; gap: 14px; border: 0; text-align: left; padding: 14px 18px; border-radius: 26px; color: #fff;
  background: radial-gradient(circle at 92% 20%, rgba(255,255,255,.25) 0 18%, transparent 19%), linear-gradient(120deg, #e84a8a, #f6a623); box-shadow: 0 6px 0 #b8336b, var(--shadow); }
.daily:active { transform: translateY(3px); }
.dIc canvas { width: 64px; height: 64px; display: block; }
.dTxt { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.dTxt small { font-size: 13px; font-weight: 800; opacity: .9; text-transform: uppercase; letter-spacing: 1px; }
.dTxt b { font-size: 22px; font-weight: 900; }
.dTxt span { font-size: 14px; font-weight: 700; opacity: .95; }
.dStreak { text-align: center; background: rgba(255,255,255,.22); border-radius: 18px; padding: 6px 12px; }
.dStreak b { display: block; font-size: 26px; font-weight: 900; line-height: 1; }
.dStreak small { font-size: 11px; font-weight: 800; }
.boxes { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; margin-top: 16px; }
.box { border: 0; border-radius: 24px; background: var(--paper); box-shadow: 0 5px 0 #ead6ba, var(--shadow); padding: 14px 12px 12px; display: flex; flex-direction: column; align-items: center; gap: 4px; position: relative; overflow: hidden; }
.box::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 7px; background: var(--c); }
.box:active { transform: translateY(3px); }
.box canvas { width: 88px; height: 88px; }
.box b { font-size: 18px; font-weight: 900; }
.box small { font-size: 13px; font-weight: 700; color: var(--ink2); }
.bar { width: 80%; height: 8px; border-radius: 4px; background: #f0e2cf; overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; background: var(--c); border-radius: 4px; }
.hubNote { text-align: center; color: var(--ink2); font-weight: 700; font-size: 14px; margin: 18px auto 0; max-width: 560px; }
@media (max-width: 420px) { .boxes { grid-template-columns: 1fr 1fr; gap: 10px; } .box canvas { width: 70px; height: 70px; } .daily { padding: 12px; gap: 10px; } .dTxt b { font-size: 19px; } }

/* levels */
.lvHead { display: flex; align-items: center; gap: 12px; margin: 4px 0 14px; }
.lvHead canvas { width: 64px; height: 64px; }
.lvHead h2 { margin: 0; font-size: 24px; font-weight: 900; }
.lvHead p { margin: 2px 0 0; color: var(--ink2); font-weight: 700; font-size: 14px; }
.lvGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 10px; }
.lv { border: 0; aspect-ratio: 1; border-radius: 18px; background: var(--paper); box-shadow: 0 4px 0 #ead6ba, var(--shadow); display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 20px; font-weight: 900; padding: 0; }
.lv .ss { font-size: 12px; letter-spacing: 1px; color: #e0cfb7; margin-top: 2px; }
.lv .ss .on { color: var(--mari); }
.lv.cur { background: var(--c); color: #fff; }
.lv.cur .ss { color: rgba(255,255,255,.55); }
.lv.lock { opacity: .45; }
.lv:active { transform: translateY(2px); }

/* play */
#play { display: flex; flex-direction: column; }
#hud { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 2px 16px 4px; flex: 0 0 auto; }
.hL { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.hL b { font-size: 18px; font-weight: 900; }
.hL span { font-size: 13px; font-weight: 800; color: var(--ink2); }
.hR { display: flex; gap: 8px; align-items: center; }
.mv, .goal { background: var(--paper); border-radius: 14px; padding: 6px 12px; font-weight: 800; font-size: 14px; box-shadow: var(--shadow); white-space: nowrap; }
.goal { color: var(--ink2); }
.goal i { font-style: normal; color: var(--mari); }
#stage { flex: 1; min-height: 0; position: relative; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#tip { margin: 2px 16px 6px; text-align: center; font-weight: 800; font-size: 15px; color: var(--ink); min-height: 20px; flex: 0 0 auto; }
#tip.warn { color: var(--rani); }
#tools { display: flex; justify-content: center; gap: 10px; padding: 0 12px 12px; padding-bottom: max(12px, env(safe-area-inset-bottom)); flex: 0 0 auto; }
.tb { border: 0; border-radius: 999px; background: var(--paper); box-shadow: 0 4px 0 #ead6ba, var(--shadow); display: flex; align-items: center; gap: 6px; padding: 10px 18px; font-weight: 900; font-size: 16px; }
.tb svg { width: 20px; height: 20px; }
.tb:active { transform: translateY(2px); }
.tb.hint { color: #b06d00; }

/* win */
#winPanel { background: rgba(253, 238, 219, .6); }
.wCard { width: min(380px, 100%); background: var(--paper); border-radius: 30px; box-shadow: var(--shadow); text-align: center; padding: 70px 20px 22px; position: relative; margin-top: 60px; animation: popIn .35s cubic-bezier(.3,1.5,.6,1); }
.wGappu { position: absolute; left: 50%; top: -86px; width: 150px; transform: translateX(-50%); filter: drop-shadow(0 6px 8px rgba(120, 80, 40, .2)); }
.wCard h2 { margin: 0; font-size: 32px; font-weight: 900; }
.wStars { display: flex; justify-content: center; gap: 8px; margin: 10px 0 6px; }
.wStars i { width: 54px; height: 54px; background: #eadcc8; clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); }
.wStars i:nth-child(2) { transform: translateY(-10px) scale(1.15); }
.wStars i.on { background: linear-gradient(180deg, #ffd45a, #f6a623); animation: starPop .4s cubic-bezier(.3,1.8,.6,1) both; }
.wStars i:nth-child(2).on { animation-name: starPop2; }
#wInfo { margin: 6px 0 16px; font-weight: 700; color: var(--ink2); font-size: 15px; }
.wBtns { display: flex; flex-direction: column; gap: 10px; }
.wBtns .row { display: flex; gap: 10px; }
@keyframes popIn { from { transform: scale(.7); opacity: 0; } }
@keyframes starPop { from { transform: scale(0) rotate(-40deg); } }
@keyframes starPop2 { from { transform: translateY(-10px) scale(0) rotate(-40deg); } to { transform: translateY(-10px) scale(1.15); } }
@media (max-height: 560px) { .sGappu { width: 110px; } .sIntro { font-size: 14px; } .btn.huge { font-size: 26px; padding: 12px 56px; } }
@media (max-width: 420px) { #title span { display: none; } }
#startPanel { background: rgba(253, 238, 219, .86); }
