@font-face {
  font-family: 'Fredoka';
  src: url('../assets/fonts/fredoka-latin.woff2') format('woff2');
  font-weight: 300 700;
  font-display: swap;
}
:root {
  --ink: #3d4a3a;
  --ink-soft: #6b7a66;
  --paper: #fffaf0;
  --card: rgba(255, 252, 244, 0.96);
  --green: #6cc77a;
  --green-dark: #3f9a54;
  --peach: #ffb38a;
  --peach-dark: #e07f52;
  --lilac: #b9a3ef;
  --lilac-dark: #8a6fd3;
  --butter: #ffd86b;
  --shadow: 0 6px 0 rgba(61, 74, 58, 0.18), 0 14px 28px rgba(61, 74, 58, 0.16);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: 'Fredoka', ui-rounded, 'Arial Rounded MT Bold', 'Trebuchet MS', system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #cdeefe; color: var(--ink); font-family: var(--font);
  -webkit-user-select: none; user-select: none; overscroll-behavior: none; touch-action: none;
}
#game { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; touch-action: none; }
#ui { position: fixed; inset: 0; pointer-events: none; }
svg { width: 1em; height: 1em; flex: none; }
button { font-family: inherit; color: inherit; cursor: pointer; border: 0; }
button:focus-visible { outline: 4px solid #4a8cff; outline-offset: 3px; }
[hidden] { display: none !important; }

.screen { position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; }
.screen.active { display: flex; }
.screen > * { pointer-events: auto; }
.screen.overlay { background: rgba(70, 96, 72, 0.32); pointer-events: auto; animation: fade .25s ease-out; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { 0% { transform: scale(.7); opacity: 0; } 70% { transform: scale(1.04); opacity: 1; } 100% { transform: scale(1); } }

.card {
  position: relative; background: none; border: 30px solid transparent; border-image: url(../assets/card.webp) 90 fill / 30px stretch;
  filter: drop-shadow(0 14px 22px rgba(50,70,30,.3)); padding: 4px 0 0;
  width: min(92vw, 380px); display: flex; flex-direction: column; align-items: center; gap: 14px; animation: pop .35s cubic-bezier(.2,.9,.3,1.3);
}
.card h2, .bar h2 { margin: 0; font-size: 26px; font-weight: 650; text-align: center; line-height: 1.15; }
.row { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.small { font-size: 16px; margin: 0; text-align: center; color: var(--ink-soft); line-height: 1.35; }
.muted { opacity: .75; }
.warn { color: #c4573a; }

.big-btn { position: relative;
  min-height: 64px; min-width: 220px; padding: 10px 26px; border-radius: 999px; font-size: 26px; font-weight: 650;
  display: inline-flex; align-items: center; justify-content: center; gap: 12px; color: #fff;
  background: var(--green); box-shadow: 0 6px 0 var(--green-dark), 0 10px 18px rgba(0,0,0,.14);
  text-shadow: 0 2px 0 rgba(0,0,0,.14); transition: transform .08s;
}
.big-btn svg { width: 30px; height: 30px; }
.big-btn .badge { position: absolute; top: -8px; right: -8px; min-width: 28px; height: 28px; border-radius: 999px; background: #fff; color: var(--peach-dark); font-size: 16px; display: inline-flex; align-items: center; justify-content: center; box-shadow: 0 2px 6px rgba(0,0,0,.15); }
.big-btn.peach { background: var(--peach); box-shadow: 0 6px 0 var(--peach-dark), 0 10px 18px rgba(0,0,0,.14); }
.big-btn.lilac { background: var(--lilac); box-shadow: 0 6px 0 var(--lilac-dark), 0 10px 18px rgba(0,0,0,.14); font-size: 22px; }
.big-btn.small-big { min-width: 160px; }
.big-btn:active, .round-btn:active, .tool-btn:active, .icon-btn:active { transform: translateY(4px) scale(.98); }

.round-btn {
  min-width: 72px; min-height: 72px; border-radius: 22px; background: linear-gradient(180deg, #fffaf0 0%, #f6e3c3 100%); border: 3px solid #fff; box-shadow: 0 5px 0 #c99a62, 0 8px 14px rgba(60,40,10,.16);
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 6px 8px; font-size: 15px; font-weight: 650;
}
.round-btn svg { width: 30px; height: 30px; color: var(--green-dark); }
.round-btn .lbl { color: var(--ink-soft); }
.round-btn.toggle[aria-pressed="false"] { background: #eee7da; }
.round-btn.toggle[aria-pressed="false"] svg { color: #a9a191; }
.round-btn.toggle[aria-pressed="false"]::after { content: ''; position: absolute; }
.round-btn.toggle { position: relative; }
.round-btn.toggle[aria-pressed="false"] svg { opacity: .55; }
.round-btn:disabled { opacity: 1; background: #efe7d8; color: #a39a88; box-shadow: 0 4px 0 #cfc3ab; }
.round-btn:disabled svg { opacity: .5; }

.icon-btn {
  width: 56px; height: 56px; border-radius: 18px; background: linear-gradient(180deg, #fffaf0 0%, #f6e3c3 100%); border: 3px solid #fff; box-shadow: 0 4px 0 #c99a62, 0 6px 12px rgba(60,40,10,.18);
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn svg { width: 28px; height: 28px; color: var(--green-dark); }

/* Home */
#screen-home { justify-content: center; }
.home-card { display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 16px; }
.logo { margin: 0 0 6px; display: flex; flex-direction: column; align-items: center; line-height: .9; transform: rotate(-3deg); }
.logo span { font-weight: 700; color: #fff; -webkit-text-stroke: 0; text-shadow: 0 4px 0 var(--green-dark), 0 8px 0 rgba(63,154,84,.35), 0 12px 20px rgba(0,0,0,.18); }
.logo-top { font-size: 58px; color: #fff; }
.logo-bottom { font-size: 74px; color: #fff7c9 !important; text-shadow: 0 4px 0 var(--peach-dark), 0 8px 0 rgba(224,127,82,.35), 0 12px 20px rgba(0,0,0,.18) !important; }
.hero { width: clamp(140px, 30vh, 250px); height: auto; aspect-ratio: 1; border-radius: 50%; -webkit-mask-image: radial-gradient(circle, #000 64%, transparent 71%); mask-image: radial-gradient(circle, #000 64%, transparent 71%); animation: float 4s ease-in-out infinite; margin-bottom: -4px; }
@keyframes float { 50% { transform: translateY(-6px) rotate(1deg); } }
.home-best { display: flex; align-items: center; gap: 8px; margin: 0; padding: 6px 16px; border-radius: 999px; background: rgba(255,255,255,.85); font-size: 22px; font-weight: 600; }
.home-best svg { color: #e6a92e; width: 24px; height: 24px; }

/* Bars */
.bar { position: absolute; top: calc(var(--safe-top) + 10px); left: 0; right: 0; display: flex; align-items: center; justify-content: space-between; padding: 0 14px; gap: 10px; }
.bar h2 { color: #fff; text-shadow: 0 3px 0 var(--green-dark), 0 6px 12px rgba(0,0,0,.15); font-size: 30px; }
.bar-spacer { width: 56px; }
.star-total { min-width: 56px; height: 44px; padding: 0 12px; border-radius: 999px; background: rgba(255,255,255,.9); display: inline-flex; align-items: center; gap: 6px; font-weight: 650; font-size: 20px; }
.star-total svg { color: #f4b81f; width: 24px; height: 24px; }

/* Levels */
#screen-levels { justify-content: flex-start; }
.levels-scroll { position: absolute; top: calc(var(--safe-top) + 78px); bottom: 0; left: 0; right: 0; overflow-y: auto; padding: 4px 14px calc(var(--safe-bottom) + 24px); touch-action: pan-y; -webkit-overflow-scrolling: touch; }
.garden-group { max-width: 460px; margin: 0 auto 18px; background: rgba(255,252,244,.9); border-radius: 26px; padding: 14px; box-shadow: var(--shadow); }
.garden-group h3 { margin: 0 0 10px; text-align: center; font-size: 22px; font-weight: 650; }
.level-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.level-btn {
  min-height: 72px; aspect-ratio: 1; border-radius: 20px; background: #fff; box-shadow: 0 5px 0 #d8cdb6; font-size: 26px; font-weight: 650;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; position: relative;
}
.level-btn:not(:disabled) {
  background: url(../assets/sprites.webp) calc(var(--k, 0) * 100% / 6) 0 / 700% 300% no-repeat; box-shadow: none; color: #fff;
  text-shadow: 0 2px 0 rgba(40,60,30,.55), 0 0 6px rgba(40,60,30,.35); font-size: 28px;
}
.level-btn:not(:disabled) .mini-stars { background: rgba(255,255,255,.85); border-radius: 999px; padding: 1px 4px; }
.level-btn:disabled { opacity: .8; background: url(../assets/sprites.webp) 0 100% / 700% 300% no-repeat !important; box-shadow: none !important; color: #fff !important; }
.level-btn:disabled svg.lock { color: #fff; filter: drop-shadow(0 2px 0 rgba(40,60,30,.4)); }
.level-btn.next { animation: bob 1.6s ease-in-out infinite; filter: drop-shadow(0 0 8px rgba(255,214,90,.95)); }
.level-btn:disabled { opacity: 1; background: url(../assets/plot.webp) center / 100% 100% no-repeat !important; color: #fff3df !important; box-shadow: none !important; }
.level-btn:disabled .lk-n { font-size: 22px; line-height: 1; text-shadow: 0 2px 0 rgba(90,55,25,.5); }
.level-btn:disabled svg.lock { width: 15px; height: 15px; color: #fff3df; opacity: .9; filter: drop-shadow(0 1px 0 rgba(90,55,25,.5)); }
.garden-group h3 { display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--g-ink, #4f8f45); }
.garden-group.g0 { --g-soft: #eaf6df; --g-edge: #cfe6bd; --g-ink: #5f9f52; background: linear-gradient(180deg, #f4fbea, rgba(255,252,244,.94)); }
.garden-group.g1 { --g-soft: #e2f2fb; --g-edge: #c3dff0; --g-ink: #4f8fbf; background: linear-gradient(180deg, #ecf8ff, rgba(255,252,244,.94)); }
.garden-group.g2 { --g-soft: #fdf3d6; --g-edge: #ecdba8; --g-ink: #c08a1e; background: linear-gradient(180deg, #fff8df, rgba(255,252,244,.94)); }
.garden-group h3 .g-icon { width: 30px; height: 30px; }
.level-btn .mini-stars { display: flex; gap: 1px; }
.level-btn .mini-stars svg { width: 15px; height: 15px; color: #e3dccb; }
.level-btn .mini-stars svg.on { color: #f4b81f; }
@keyframes bob { 50% { transform: translateY(-3px); } }

/* HUD */
#screen-play { justify-content: space-between; }
.hud { position: absolute; top: calc(var(--safe-top) + 8px); left: 0; right: 0; display: flex; align-items: flex-start; justify-content: space-between; padding: 0 12px; }
.hud-mid { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.hud-score { font-size: 46px; font-weight: 700; color: #fff; line-height: 1; text-shadow: 0 3px 0 var(--green-dark), 0 6px 12px rgba(0,0,0,.18); font-variant-numeric: tabular-nums; }
.hud-score.bump { animation: bump .3s ease-out; }
@keyframes bump { 40% { transform: scale(1.18); } }
.hud-best, .hud-goal { display: inline-flex; align-items: center; gap: 6px; padding: 3px 12px; border-radius: 999px; background: rgba(255,255,255,.88); font-size: 18px; font-weight: 600; }
.hud-best svg { color: #e6a92e; width: 20px; height: 20px; }
.hud-goal { font-size: 28px; padding: 6px 18px; box-shadow: 0 4px 0 rgba(201,154,98,.55); border: 3px solid #fff; background: #fffaf0; }
.hud-goal svg { width: 32px; height: 32px; color: var(--green-dark); }
.hud-goal.done { background: #fff3c4; }
.hud-trays { min-width: 56px; height: 56px; border-radius: 18px; background: rgba(255,255,255,.92); display: inline-flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 650; font-size: 18px; box-shadow: 0 4px 0 #dcd3bf; }
.hud-trays svg { width: 22px; height: 22px; color: var(--peach-dark); }
.hud-trays.low { background: #ffe3d2; }
.hud-trays small { font-size: 13px; font-weight: 500; }
.hud-trays { min-width: 68px; }
.goal-cue { position: absolute; top: calc(var(--hud-bottom, 100px) + 4px); display: flex; align-items: center; gap: 8px; width: min(94vw, 410px); min-height: 48px; padding: 0 0 0 12px; border-radius: 18px; background: var(--paper); box-shadow: 0 3px 0 rgba(61,74,58,.15); font-size: 16px; line-height: 1.15; }
.goal-cue > svg { width: 26px; height: 26px; color: var(--green-dark); }
.goal-cue > span { flex: 1; }
.goal-cue button { min-width: 48px; min-height: 48px; background: transparent; border-radius: 18px; font-size: 26px; }
.key-hint { display: none; }
@media (min-width: 900px) and (min-aspect-ratio: 6/5) {
  .key-hint { display: block; position: absolute; left: 20px; top: 135px; padding: 12px 16px; background: var(--paper); border-radius: 18px; font-size: 16px; line-height: 1.7; }
}
.hud-spacer { width: 56px; }
.tools { position: absolute; left: 0; right: 0; bottom: calc(var(--safe-bottom) + 10px); display: flex; justify-content: space-between; padding: 0 14px; pointer-events: none; }
@media (min-width: 900px) and (min-aspect-ratio: 6/5) {
  /* wide screens: Oops and Hint sit beside the tray instead of in the far corners */
  .tools { left: calc(50% - var(--play-w, 420px) / 2 - 168px); right: calc(50% - var(--play-w, 420px) / 2 - 168px); bottom: var(--tray-bottom, 40px); transform: translateY(50%); padding: 0; }
  .tools .tool-btn { min-width: 112px; }
}
.tool-btn {
  pointer-events: auto; min-width: 84px; min-height: 60px; border-radius: 20px; background: linear-gradient(180deg, #fffaf0 0%, #f6e3c3 100%); border: 3px solid #fff; box-shadow: 0 5px 0 #c99a62, 0 8px 14px rgba(60,40,10,.18);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 6px 14px; font-size: 18px; font-weight: 650; position: relative;
}
.tool-btn svg { width: 28px; height: 28px; }
#btn-undo svg { color: var(--lilac-dark); }
#btn-hint svg { color: #e6a92e; }
.tool-btn:disabled { opacity: 1; background: #efe7d8; color: #a39a88; box-shadow: 0 4px 0 #cfc3ab; }
.tool-btn:disabled svg { opacity: .5; }
.badge { position: absolute; top: -6px; right: -6px; min-width: 24px; height: 24px; border-radius: 12px; background: var(--peach); color: #fff; font-size: 15px; display: flex; align-items: center; justify-content: center; padding: 0 6px; }
.badge:empty { display: none; }

/* Nap / win */
.nap-art { position: relative; width: 90px; height: 70px; }
.nap-flower { width: 64px !important; height: 64px !important; color: var(--lilac); position: absolute; left: 10px; top: 6px; animation: sway 3s ease-in-out infinite; }
@keyframes sway { 50% { transform: rotate(-8deg) translateY(2px); } }
.zzz { position: absolute; font-weight: 700; color: var(--lilac-dark); animation: zz 2.4s ease-in-out infinite; opacity: 0; }
.zzz:nth-child(1) { left: 66px; top: 26px; font-size: 16px; }
.zzz:nth-child(2) { left: 76px; top: 10px; font-size: 20px; animation-delay: .8s; }
.zzz:nth-child(3) { left: 88px; top: -8px; font-size: 26px; animation-delay: 1.6s; }
@keyframes zz { 0% { opacity: 0; transform: translateY(6px); } 30% { opacity: 1; } 100% { opacity: 0; transform: translateY(-10px); } }
.nap-score { font-size: 56px; font-weight: 700; line-height: 1; color: var(--green-dark); }
.nap-best { display: flex; align-items: center; gap: 8px; font-size: 22px; font-weight: 600; }
.nap-best svg { color: #e6a92e; width: 24px; height: 24px; }
.new-best { background: var(--butter); border-radius: 999px; padding: 2px 10px; font-size: 16px; animation: bob 1.2s ease-in-out infinite; }
.nap-line { margin: 0; font-size: 20px; text-align: center; color: var(--ink-soft); }
.stars { display: flex; align-items: flex-end; gap: 6px; }
.stars .star { width: 62px; height: 62px; color: #e3dccb; }
.stars .star.big { width: 82px; height: 82px; }
.stars .star.on { color: #f4b81f; filter: drop-shadow(0 3px 0 #d08d10); animation: starpop .5s cubic-bezier(.2,.9,.3,1.5) both; }
.stars .star.on:nth-child(2) { animation-delay: .2s; }
.stars .star.on:nth-child(3) { animation-delay: .4s; }
@keyframes starpop { 0% { transform: scale(0) rotate(-40deg); } 100% { transform: scale(1); } }

/* Settings / board */
#screen-settings, #screen-board { justify-content: center; }
.settings-card, .board-card { margin-top: 40px; }
.board-list { list-style: none; margin: 0; padding: 0; width: 100%; max-height: 46vh; overflow-y: auto; touch-action: pan-y; }
.board-list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 14px; font-size: 19px; }
.board-list li:nth-child(odd) { background: #f6efdf; }
.board-list li.me { background: #fff1b8; }
.board-list .rk { width: 32px; font-weight: 700; color: var(--ink-soft); }
.board-list .nm { flex: 1; }
.board-list .sc { font-weight: 650; font-variant-numeric: tabular-nums; }
.board-me { margin: 0; font-size: 18px; font-weight: 600; }

/* Modals */
.modal { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(70,96,72,.4); z-index: 20; }
.picker-preview { font-size: 30px; font-weight: 700; color: var(--green-dark); min-height: 38px; }
.chips { display: flex; gap: 8px; overflow-x: auto; width: 100%; padding: 4px 2px 8px; touch-action: pan-x; scrollbar-width: none; }
.chips button { flex: none; min-height: 48px; min-width: 48px; padding: 6px 14px; border-radius: 999px; background: #f2ecdd; font-size: 18px; font-weight: 600; }
.chips button[aria-pressed="true"] { background: var(--green); color: #fff; }
#picker-input { width: 100%; min-height: 52px; border-radius: 16px; border: 3px solid #e4dcc8; font: inherit; font-size: 20px; padding: 6px 14px; text-align: center; color: var(--ink); background: #fff; user-select: text; -webkit-user-select: text; }
.stretch-art svg { width: 84px; height: 84px; color: var(--green); animation: stretch 2s ease-in-out infinite; }
@keyframes stretch { 50% { transform: scaleY(1.18) translateY(-6px); } }

.update-banner {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 16px); transform: translateX(-50%); z-index: 15;
  display: flex; align-items: center; gap: 12px; background: #fff; border-radius: 999px; padding: 8px 8px 8px 20px; box-shadow: var(--shadow);
  font-size: 17px; font-weight: 600; white-space: nowrap; max-width: calc(100vw - 24px);
}
.pill-btn { min-height: 48px; min-width: 96px; border-radius: 999px; background: var(--green); color: #fff; font-size: 18px; font-weight: 650; padding: 0 18px; box-shadow: 0 4px 0 var(--green-dark); }

@media (max-height: 700px) {
  .logo-top { font-size: 46px; } .logo-bottom { font-size: 58px; }
  .home-card { gap: 12px; }
  .hero { width: clamp(110px, 22vh, 150px); }
  .card { padding: 16px; gap: 10px; }
  .nap-score { font-size: 46px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
