:root {
  --ink: #5c3d2e;
  --paper: #fffaf0;
  --paper-2: #f6ead2;
  --accent: #ef7d6c;
  --accent-dark: #c95a4b;
  --mint: #8fcfc4;
  --gold: #ffc93c;
  --font: ui-rounded, "SF Pro Rounded", "Avenir Next", "Nunito", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #e9dcc3; font-family: var(--font); color: var(--ink); }
body { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#game { cursor: crosshair; }
.hidden { display: none !important; }

/* HUD */
#hud { position: fixed; top: 0; left: 0; right: 0; height: 60px; display: flex; align-items: center; justify-content: space-between; padding: 8px max(12px, env(safe-area-inset-left)); gap: 8px; pointer-events: none; }
#hud > *, #hud button { pointer-events: auto; }
.hud-mid { display: flex; align-items: center; gap: 10px; }
.tag { background: var(--paper); padding: 6px 14px; border-radius: 999px; font-weight: 800; font-size: 15px; box-shadow: 0 3px 0 rgba(60,30,15,.18), 0 6px 14px rgba(60,30,15,.12); }
.hud-stars { display: flex; gap: 4px; background: var(--paper); padding: 5px 10px; border-radius: 999px; box-shadow: 0 3px 0 rgba(60,30,15,.18); }
.hud-stars i, .big-stars i { display: inline-block; width: 24px; height: 24px; background: #d9cbb2; clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); transition: background .2s; }
.hud-stars i.on { background: var(--gold); animation: pop .45s cubic-bezier(.3,1.8,.5,1); }
.right { display: flex; gap: 8px; }
button { font-family: inherit; color: inherit; }
.icon { width: 44px; height: 44px; border: 0; border-radius: 14px; background: var(--paper); display: grid; place-items: center; cursor: pointer; box-shadow: 0 3px 0 rgba(60,30,15,.2), 0 6px 14px rgba(60,30,15,.12); transition: transform .12s; }
.icon:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(60,30,15,.2); }
.icon svg { width: 22px; height: 22px; fill: var(--ink); color: var(--ink); }
.mute .cross { display: none; }
.mute.off .cross { display: inline; }
.mute.off .wave { display: none; }
#hud { justify-content: flex-start; }
#hud .hud-mid { margin: 0 auto; }

.banner { position: fixed; left: 50%; top: 22%; transform: translate(-50%, 0); background: var(--paper); padding: 10px 22px; border-radius: 16px; font-weight: 800; font-size: 20px; box-shadow: 0 4px 0 rgba(60,30,15,.18), 0 10px 30px rgba(60,30,15,.18); opacity: 0; pointer-events: none; white-space: nowrap; }
.banner.show { animation: banner 1.8s ease forwards; }
.banner small { display: block; font-size: 12px; font-weight: 700; opacity: .65; text-transform: uppercase; letter-spacing: .08em; }

/* Screens */
.screen { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: rgba(70,40,25,.28); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); overflow-y: auto; }
.screen.show-in .panel { animation: panelIn .38s cubic-bezier(.2,1.4,.4,1); }
.panel { position: relative; width: min(420px, 100%); background: var(--paper); border-radius: 26px; padding: 26px 24px 22px; text-align: center; box-shadow: 0 6px 0 var(--paper-2), 0 8px 0 rgba(60,30,15,.15), 0 20px 50px rgba(60,30,15,.3); background-image: repeating-linear-gradient(0deg, transparent 0 27px, rgba(150,110,70,.07) 27px 28px); }
.panel::before { content: ""; position: absolute; top: -12px; left: 50%; width: 90px; height: 24px; transform: translateX(-50%) rotate(-2deg); background: rgba(255,214,140,.75); border-radius: 3px; box-shadow: 0 2px 4px rgba(60,30,15,.12); }
.panel.wide { width: min(640px, 100%); }
h2 { margin: 4px 0 12px; font-size: 30px; font-weight: 900; letter-spacing: -.01em; }
.sub { margin: 4px 0 14px; opacity: .8; font-weight: 600; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.col { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.btn { border: 0; cursor: pointer; font-weight: 900; font-size: 18px; padding: 12px 24px; border-radius: 16px; background: #fff; color: var(--ink); box-shadow: 0 4px 0 rgba(60,30,15,.22), 0 8px 18px rgba(60,30,15,.12); transition: transform .12s, box-shadow .12s, filter .12s; min-width: 120px; }
.btn:hover { filter: brightness(1.04); transform: translateY(-1px) rotate(-1deg); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(60,30,15,.22); }
.btn:focus-visible, .icon:focus-visible, .lvl:focus-visible, .boxcard:focus-visible { outline: 3px solid var(--mint); outline-offset: 3px; }
.btn.primary { background: linear-gradient(#ff9a86, var(--accent)); color: #fff; font-size: 24px; padding: 14px 44px; box-shadow: 0 5px 0 var(--accent-dark), 0 10px 24px rgba(200,80,60,.35); text-shadow: 0 2px 0 rgba(0,0,0,.15); }
.btn.small { font-size: 16px; padding: 10px 18px; }
.btn.ghost { background: transparent; box-shadow: inset 0 0 0 2px rgba(92,61,46,.25); }
.btn.done { background: #e4f4ef; }

.logo { margin: 0 0 6px; font-size: clamp(54px, 13vw, 82px); line-height: .9; font-weight: 900; letter-spacing: -.02em; display: flex; flex-direction: column; align-items: center; }
.logo span { display: inline-block; color: #fff; -webkit-text-stroke: 0; text-shadow: 0 3px 0 var(--accent), 0 6px 0 var(--accent-dark), 0 12px 16px rgba(120,40,30,.3); }
.logo span:first-child { color: #ffe6ea; transform: rotate(-4deg); text-shadow: 0 3px 0 #f28fa5, 0 6px 0 #c9637a, 0 12px 16px rgba(120,40,30,.3); }
.logo span:last-child { transform: rotate(2deg) translateX(18px); color: #fff8e3; text-shadow: 0 3px 0 #7cbfb4, 0 6px 0 #4f9a8e, 0 12px 16px rgba(40,90,80,.3); }
.greet { margin: 10px 0 4px; font-weight: 700; }
.total { margin: 14px 0 6px; font-weight: 800; }
.howto { text-align: left; margin: 10px 0 0; padding: 12px 14px 12px 30px; font-size: 14px; line-height: 1.5; background: rgba(143,207,196,.18); border-radius: 14px; }

.box-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
.boxcard { border: 0; cursor: pointer; padding: 18px 12px 14px; border-radius: 20px; font-weight: 800; color: var(--ink); box-shadow: 0 5px 0 rgba(60,30,15,.22), 0 10px 20px rgba(60,30,15,.12); transition: transform .15s; position: relative; overflow: hidden; }
.boxcard:hover { transform: translateY(-2px) rotate(-1deg); }
.boxcard .bname { font-size: 20px; font-weight: 900; display: block; }
.boxcard .bblurb { font-size: 13px; font-weight: 600; opacity: .8; display: block; margin: 4px 0 10px; }
.boxcard .bstars { font-size: 15px; }
.boxcard .lid { width: 70px; height: 46px; margin: 0 auto 10px; border-radius: 8px; background: rgba(255,255,255,.55); box-shadow: inset 0 -8px 0 rgba(0,0,0,.08); position: relative; }
.boxcard .lid::after { content: ""; position: absolute; left: 50%; top: 50%; width: 22px; height: 22px; transform: translate(-50%,-50%); background: var(--gold); clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); }
.boxcard.locked { filter: grayscale(.7); opacity: .75; cursor: not-allowed; }
.boxcard.locked .lid::after { background: #9a8a7a; clip-path: none; border-radius: 4px 4px 6px 6px; width: 18px; height: 14px; top: 58%; box-shadow: 0 -9px 0 -3px transparent; }
.box-meadow { background: linear-gradient(#e3f2d8, #bfdfae); }
.box-kitchen { background: linear-gradient(#ffe7d2, #f4b5a8); }
.box-starlight { background: linear-gradient(#7c86d6, #4b569d); color: #fff7e6 !important; }

.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.lvl { aspect-ratio: 1; border: 0; border-radius: 16px; cursor: pointer; background: #fff; font-weight: 900; font-size: 22px; box-shadow: 0 4px 0 rgba(60,30,15,.2); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; transition: transform .12s; }
.lvl:hover { transform: translateY(-2px) rotate(1deg); }
.lvl .mini { display: flex; gap: 1px; }
.lvl .mini i { width: 13px; height: 13px; background: #e2d6c2; clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); }
.lvl .mini i.on { background: var(--gold); }
.lvl.locked { background: #eee3d2; color: #b3a28f; cursor: not-allowed; }
.lvl.daily { box-shadow: 0 4px 0 rgba(60,30,15,.2), inset 0 0 0 3px var(--mint); }

.big-stars { display: flex; justify-content: center; gap: 10px; margin: 8px 0; }
.big-stars i { width: 64px; height: 64px; transform: scale(.6); }
.big-stars i.on { background: var(--gold); animation: starIn .5s cubic-bezier(.3,1.9,.5,1) both; transform: none; }
.big-stars i:nth-child(2) { margin-top: -14px; }
.big-stars i.on:nth-child(2) { animation-delay: .25s; }
.big-stars i.on:nth-child(3) { animation-delay: .5s; }
.big-stars.dim i.on { background: #e8c873; }

@keyframes pop { 0% { transform: scale(.3) rotate(-40deg); } 100% { transform: scale(1); } }
@keyframes starIn { 0% { transform: scale(0) rotate(-90deg); background: #d9cbb2; } 60% { background: var(--gold); } 100% { transform: scale(1) rotate(0); background: var(--gold); } }
@keyframes panelIn { 0% { transform: translateY(30px) scale(.94); opacity: 0; } 100% { transform: none; opacity: 1; } }
@keyframes banner { 0% { opacity: 0; transform: translate(-50%, 16px) scale(.9); } 15% { opacity: 1; transform: translate(-50%, 0) scale(1); } 75% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -12px); } }

@media (max-height: 560px) {
  .title-panel .howto { display: none; }
  .logo { font-size: 48px; }
  .panel { padding: 18px 18px 14px; }
}
@media (max-width: 420px) {
  .level-grid { gap: 7px; }
  .lvl { font-size: 18px; border-radius: 12px; }
  .lvl .mini i { width: 10px; height: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* wide screens: menus on the left, live scene on the right */
body.wide-menu .screen { justify-items: start; padding-left: max(5vw, 24px); background: linear-gradient(90deg, rgba(70,40,25,.32), rgba(70,40,25,.05) 60%); backdrop-filter: none; -webkit-backdrop-filter: none; }
body.wide-menu #pause, body.wide-menu #win, body.wide-menu #lose { justify-items: center; }
