:root {
  --ink: #1d2b3a;
  --muted: #6b7a8c;
  --go: #2fbf71; --go-d: #1f8f52;
  --ad: #7c4dff; --ad-d: #5530c4;
  --ghost: #eef2f7; --ghost-d: #c9d3df;
  --gold: #ffb800;
  --red: #ff4d6d;
  --shadow: 0 3px 0 rgba(0, 0, 0, .10), 0 6px 16px rgba(20, 40, 60, .14);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body {
  width: 100%; height: 100%; overflow: hidden; background: #e6f4e9; color: var(--ink);
  font-family: 'Trebuchet MS', 'Segoe UI', system-ui, -apple-system, sans-serif;
  user-select: none; -webkit-user-select: none; touch-action: none; overscroll-behavior: none;
}
button { font: inherit; color: inherit; }
#game { position: fixed; inset: 0; display: block; touch-action: none; }
#ui { position: fixed; inset: 0; pointer-events: none; }
#ui [hidden] { display: none !important; }

/* ---------- level HUD ---------- */
#hud {
  position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 6px max(12px, env(safe-area-inset-left));
}
#hud > *, #bar > *, #menu, #modal { pointer-events: auto; }
.round {
  flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .92);
  box-shadow: var(--shadow); display: grid; place-items: center; cursor: pointer; color: var(--ink);
}
.round svg { width: 22px; height: 22px; fill: currentColor; }
.round:active, .tool:active, .btn:active, .lv:active { transform: translateY(2px); }
.round:disabled { opacity: .35; cursor: default; }
.title {
  display: flex; flex-direction: column; line-height: 1.1; min-width: 0; background: rgba(255, 255, 255, .92);
  padding: 5px 12px; border-radius: 14px; box-shadow: var(--shadow);
}
.title b { font-size: 17px; white-space: nowrap; }
.title small { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#hearts { flex: 1; display: flex; justify-content: center; gap: 2px; min-width: 0; }
.heart { width: 30px; height: 30px; fill: var(--red); stroke: #fff; stroke-width: 1.8; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .18)); }
.heart.off { fill: rgba(120, 130, 150, .35); }
.heart.lost { animation: lost .7s ease-out; }
@keyframes lost { 0% { transform: scale(1.6) rotate(-14deg); fill: var(--red); } 45% { transform: scale(.75) rotate(10deg); } 100% { transform: none; } }
.pill {
  flex: none; display: flex; align-items: center; gap: 6px; height: 38px; padding: 0 13px 0 6px; border-radius: 19px;
  background: rgba(255, 255, 255, .92); font-weight: 800; font-size: 17px; box-shadow: var(--shadow);
}
.pill svg { width: 26px; height: 26px; }
.pill.stars svg { fill: var(--gold); stroke: #c98a00; stroke-width: 1.2; }
.pill.bump { animation: bump .45s; }
@keyframes bump { 40% { transform: scale(1.18); } }

/* ---------- tool bar ---------- */
#bar {
  position: absolute; bottom: 0; left: 0; right: 0; display: flex; align-items: center; justify-content: center; gap: 14px;
  padding: 6px 12px max(12px, env(safe-area-inset-bottom));
}
.tool {
  position: relative; display: flex; align-items: center; gap: 8px; height: 54px; padding: 0 18px 0 13px; border: 0; border-radius: 27px;
  background: #fff; font-weight: 800; font-size: 16px; box-shadow: 0 4px 0 rgba(0, 0, 0, .12), 0 8px 18px rgba(20, 40, 60, .14); cursor: pointer;
}
.tool svg { width: 28px; height: 28px; flex: none; }
.tool em {
  position: absolute; top: -7px; right: -7px; min-width: 26px; height: 26px; border-radius: 13px; padding: 0 6px; border: 2px solid #fff;
  background: var(--red); color: #fff; font-style: normal; font-size: 14px; display: grid; place-items: center;
}
.tool em.add { background: var(--go); }
#left { display: flex; flex-direction: column; align-items: center; min-width: 104px; background: rgba(255, 255, 255, .88); border-radius: 16px; padding: 5px 12px 7px; box-shadow: var(--shadow); }
#left b { font-size: 21px; line-height: 1.1; }
#left small { font-size: 11px; color: var(--muted); }
#left i { display: block; width: 100%; height: 6px; background: rgba(0, 0, 0, .08); border-radius: 3px; margin-top: 4px; overflow: hidden; }
#left u { display: block; height: 100%; width: 0; background: var(--go); border-radius: 3px; transition: width .3s; }

/* ---------- start screen ---------- */
#menu { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; padding: max(12px, env(safe-area-inset-top)) 16px 16px; }
#menu .top { align-self: stretch; display: flex; justify-content: flex-end; gap: 8px; }
.hero { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; width: 100%; max-width: 420px; }
.logo { display: flex; flex-direction: column; align-items: center; }
.logo-arrows { width: 150px; height: 75px; filter: drop-shadow(0 4px 0 rgba(0, 0, 0, .12)); }
.logo h1 {
  font-size: clamp(46px, 13vw, 76px); letter-spacing: 4px; font-weight: 900; line-height: .95; color: #fff;
  -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; text-shadow: 0 6px 0 var(--ink);
}
.tag { font-size: 16px; font-weight: 700; text-align: center; background: rgba(255, 255, 255, .85); padding: 6px 14px; border-radius: 14px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; }

/* ---------- buttons ---------- */
.btn {
  position: relative; display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 54px; padding: 8px 16px; width: 100%;
  border: 0; border-radius: 16px; font-weight: 800; font-size: 18px; cursor: pointer; text-align: center; line-height: 1.1;
}
.btn svg { width: 24px; height: 24px; flex: none; fill: currentColor; }
.btn span { display: flex; flex-direction: column; align-items: flex-start; }
.btn small { font-size: 12px; font-weight: 700; opacity: .85; display: flex; align-items: center; gap: 3px; }
.btn small svg { width: 16px; height: 16px; }
.btn.go { background: var(--go); color: #fff; box-shadow: 0 5px 0 var(--go-d), 0 10px 20px rgba(20, 120, 60, .25); }
.btn.big { min-height: 76px; font-size: 26px; border-radius: 22px; }
.btn.big svg { width: 34px; height: 34px; }
.btn.big small { font-size: 14px; }
.btn.ad { background: var(--ad); color: #fff; box-shadow: 0 5px 0 var(--ad-d); flex-direction: row; }
.btn.ad small { margin-left: 4px; }
.btn.ghost { background: var(--ghost); color: var(--ink); box-shadow: 0 4px 0 var(--ghost-d); }
#menu .btn.ghost { background: rgba(255, 255, 255, .94); }
.btn.off { opacity: .55; }
.btn .dot, .dot { position: absolute; top: 8px; right: 10px; width: 11px; height: 11px; border-radius: 50%; background: var(--red); border: 2px solid #fff; }
.btn.daily.done { color: var(--go-d); }
.ad-tag { font-style: normal; font-size: 11px; background: rgba(255, 255, 255, .25); padding: 2px 6px; border-radius: 6px; }

/* ---------- windows ---------- */
#modal { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(18, 28, 48, .42); padding: 12px; }
.card {
  width: 100%; max-width: 380px; max-height: calc(100% - 8px); overflow: auto; background: #fff; border-radius: 24px; padding: 20px 18px 18px;
  box-shadow: 0 18px 50px rgba(10, 20, 40, .35); animation: pop .28s cubic-bezier(.2, 1.5, .5, 1); text-align: center;
}
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
.card h2 { font-size: 28px; font-weight: 900; margin: 2px 0 6px; }
.card .note { color: var(--muted); font-size: 14px; margin: 4px 0 10px; }
.card .note.small { font-size: 12px; }
.btns { display: flex; gap: 10px; margin-top: 12px; }
.btns.col { flex-direction: column; }
.win-head small, .maphead small { font-size: 13px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.stars { display: flex; justify-content: center; gap: 4px; }
.stars.big span { display: block; animation: starIn .5s both; animation-delay: var(--d); }
.stars.big span:nth-child(2) { transform: translateY(-10px); }
.stars.big svg { width: 62px; height: 62px; }
@keyframes starIn { from { transform: scale(0) rotate(-40deg); opacity: 0; } }
.star { fill: #e3e8ef; stroke: #c4ccd8; stroke-width: 1; }
.star.on { fill: var(--gold); stroke: #c98a00; }
.lines { background: #f5f8fb; border-radius: 14px; padding: 6px 12px; margin: 8px 0 2px; }
.lines > div { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 6px 0; font-size: 15px; font-weight: 700; }
.lines > div + div { border-top: 1px solid #e6ebf1; }
.lines b { display: flex; align-items: center; gap: 4px; font-size: 18px; }
.lines b svg { width: 22px; height: 22px; }
.lines .good { color: var(--go-d); justify-content: center; }
.lines .gift span { display: flex; align-items: center; gap: 6px; }
.lines .gift svg.gifti { width: 22px; height: 22px; }
.lines .gift .pips { display: flex; gap: 4px; }
.lines .gift .pips u { width: 16px; height: 8px; border-radius: 4px; background: #dfe5ec; }
.lines .gift .pips u.on { background: #ff6f61; }
.lines .gift.got { color: #d9472b; }
.lines .gift.got b svg { width: 20px; height: 20px; }
.lines .gift.got span { animation: bump .6s .3s; }
.doubled { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 54px; font-weight: 800; font-size: 18px; color: var(--go-d); }
.doubled svg { width: 24px; height: 24px; }
.fail-head > svg { width: 64px; height: 64px; }
.fail-head .heart { width: 70px; height: 70px; }
.toggles { display: flex; gap: 10px; justify-content: center; margin: 8px 0 6px; }
.toggles button { flex: 1; max-width: 150px; height: 46px; border-radius: 14px; border: 2px solid var(--ghost-d); background: #fff; font-weight: 800; cursor: pointer; color: var(--muted); }
.toggles button.on { background: var(--go); border-color: var(--go); color: #fff; }
.howto { background: #f5f8fb; border-radius: 14px; padding: 10px 14px; margin: 8px 0; text-align: left; font-size: 14px; line-height: 1.4; }
.howto b { display: block; margin-bottom: 2px; }

/* level map */
.card.levels { max-width: 420px; }
.maphead { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.maphead > div { flex: 1; }
.maphead h2 { font-size: 24px; margin: 0; background: linear-gradient(90deg, var(--w1), var(--w2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.maphead .round { background: var(--ghost); box-shadow: 0 3px 0 var(--ghost-d); }
.wstars { display: inline-flex; align-items: center; gap: 4px; font-weight: 800; font-size: 14px; }
.wstars svg { width: 18px; height: 18px; }
.lvgrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.lv {
  aspect-ratio: 1; border: 0; border-radius: 14px; background: var(--ghost); box-shadow: 0 3px 0 var(--ghost-d); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-weight: 900; font-size: 18px;
}
.lv .st { display: flex; gap: 0; }
.lv .st svg { width: 13px; height: 13px; }
.lv.done { background: #e4f7ec; box-shadow: 0 3px 0 #b7e3c8; }
.lv.cur { background: var(--go); color: #fff; box-shadow: 0 3px 0 var(--go-d); animation: pulse 1.4s infinite; }
.lv.cur .star { fill: rgba(255, 255, 255, .45); stroke: none; }
.lv.locked { cursor: default; color: #a9b4c2; background: #f3f5f8; box-shadow: none; }
.lv.locked svg { width: 20px; height: 20px; fill: currentColor; }
@keyframes pulse { 50% { transform: scale(1.07); } }

/* ---------- hints and toasts ---------- */
#hint {
  position: absolute; z-index: 5; pointer-events: none; transform: translateX(-50%); max-width: min(320px, 86vw); text-align: center;
  background: var(--ink); color: #fff; font-weight: 800; font-size: 15px; padding: 9px 14px; border-radius: 14px; box-shadow: 0 8px 20px rgba(0, 0, 0, .25);
  animation: hintBob 1.2s ease-in-out infinite;
}
#hint.up { margin-top: 10px; }
#hint.down { transform: translate(-50%, -100%); margin-top: -10px; }
#hint.up::before, #hint.down::after { content: ''; position: absolute; left: 50%; margin-left: -8px; border: 8px solid transparent; }
#hint.up::before { bottom: 100%; border-bottom-color: var(--ink); }
#hint.down::after { top: 100%; border-top-color: var(--ink); }
#hint.none { animation: none; }
@keyframes hintBob { 50% { translate: 0 4px; } }
#toasts { position: absolute; top: 74px; left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 6; }
.toast { background: rgba(29, 43, 58, .92); color: #fff; padding: 8px 16px; border-radius: 14px; font-weight: 800; font-size: 15px; animation: toast 2.6s both; }
.toast.bad { background: rgba(214, 48, 72, .95); }
@keyframes toast { 0% { transform: translateY(-8px); opacity: 0; } 8%, 85% { transform: none; opacity: 1; } 100% { opacity: 0; } }

/* ---------- small phones ---------- */
@media (max-width: 400px) {
  #hud { gap: 6px; padding-left: 8px; padding-right: 8px; }
  .round { width: 40px; height: 40px; }
  .title { padding: 4px 9px; }
  .title b { font-size: 15px; }
  .heart { width: 24px; height: 24px; }
  .pill { height: 34px; font-size: 15px; padding-right: 10px; }
  .pill svg { width: 22px; height: 22px; }
  .tool { height: 50px; padding: 0 14px 0 10px; font-size: 15px; }
  #bar { gap: 10px; }
  #left { min-width: 88px; }
}
@media (max-width: 340px) { .tool span { display: none; } .tool { padding: 0 12px; } }

/* ---------- phones held sideways: HUD on the left, tools on the right ---------- */
@media (orientation: landscape) and (max-height: 520px) {
  #hud {
    right: auto; bottom: 0; width: 170px; flex-direction: column; align-items: stretch; justify-content: flex-start; gap: 8px;
    padding: max(10px, env(safe-area-inset-top)) 8px 10px max(10px, env(safe-area-inset-left));
  }
  #hud .title { order: 2; }
  #hud #hearts { order: 3; flex: none; justify-content: flex-start; }
  #hud .pill { order: 4; align-self: flex-start; }
  #h-home { order: 1; position: absolute; top: max(10px, env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left)); }
  #h-pause { order: 1; position: absolute; top: max(10px, env(safe-area-inset-top)); left: calc(max(10px, env(safe-area-inset-left)) + 52px); }
  #hud .title { margin-top: 52px; }
  #bar {
    left: auto; top: 0; width: 150px; flex-direction: column; justify-content: center; gap: 12px;
    padding: 10px max(10px, env(safe-area-inset-right)) 10px 8px;
  }
  .tool { width: 100%; }
  #left { width: 100%; }
  #toasts { top: 12px; }
  .hero { gap: 8px; }
  .logo-arrows { width: 100px; height: 50px; }
  .logo h1 { font-size: 44px; }
  .btn.big { min-height: 60px; font-size: 22px; }
  .card { max-width: 560px; padding: 14px; }
  .card.levels { max-width: 600px; }
  .lvgrid { grid-template-columns: repeat(9, 1fr); gap: 6px; }
  .lv { font-size: 15px; border-radius: 10px; }
  .stars.big svg { width: 46px; height: 46px; }
  .card h2 { font-size: 24px; }
  .btns.col { display: grid; grid-template-columns: 1fr 1fr; }
  .btns.col .row2 { grid-column: 1 / -1; }
  .btns.col > .btn:nth-child(odd):has(+ .row2), .btns.col > .btn:last-child:nth-child(odd) { grid-column: 1 / -1; }
}
