@font-face { font-family: Fredoka; font-weight: 500; font-display: swap; src: url(fonts/fredoka-latin-500-normal.woff2) format('woff2'); }
@font-face { font-family: Fredoka; font-weight: 600; font-display: swap; src: url(fonts/fredoka-latin-600-normal.woff2) format('woff2'); }
@font-face { font-family: Fredoka; font-weight: 700; font-display: swap; src: url(fonts/fredoka-latin-700-normal.woff2) format('woff2'); }

:root {
  --ink: #5a3524; --ink2: #8a5c43; --cream: #fff8ef; --paper: #fff3e4; --peach: #f7c6a3; --berry: #ef7f86; --berry-d: #c9545d;
  --mint: #63c3a2; --mint-d: #3e9a7c; --gold: #f4b63f; --shadow: 0 6px 0 rgba(120, 60, 30, 0.22);
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px); --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #f6d9c0; color: var(--ink); font-family: Fredoka, 'Trebuchet MS', system-ui, sans-serif; font-weight: 500; overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
canvas#game { position: fixed; inset: 0; display: block; touch-action: none; }
#ui { position: fixed; inset: 0; pointer-events: none; }
.screen { position: absolute; inset: 0; display: none; pointer-events: auto; }
.screen.show { display: flex; }
.hidden { display: none !important; }

/* buttons */
.btn { font: inherit; font-weight: 600; font-size: 20px; color: var(--ink); background: var(--cream); border: 3px solid #e3b994; border-radius: 22px; padding: 12px 20px; min-height: 52px; box-shadow: var(--shadow); cursor: pointer; transition: transform 0.08s ease, box-shadow 0.08s ease; touch-action: manipulation; }
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(120, 60, 30, 0.22); }
.btn.big { font-size: 26px; padding: 16px 28px; min-height: 64px; border-radius: 28px; }
.btn.primary { background: linear-gradient(#ff9a8c, var(--berry)); color: #fff; border-color: var(--berry-d); text-shadow: 0 2px 0 rgba(150, 50, 50, 0.35); }
.btn.bonus { background: linear-gradient(#8fe0c2, var(--mint)); color: #fff; border-color: var(--mint-d); text-shadow: 0 2px 0 rgba(30, 110, 80, 0.4); }
.btn.danger { background: #fff0ee; border-color: #e8a19a; color: #b14a40; }
.btn.link { background: none; border: none; box-shadow: none; text-decoration: underline; min-height: 44px; }
.btn:disabled { opacity: 0.55; filter: grayscale(0.4); }
.icon-btn { width: 56px; height: 56px; padding: 0; display: inline-grid; place-items: center; }
.icon-btn svg { width: 30px; height: 30px; fill: none; stroke: var(--ink); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.round { border-radius: 50%; }
.row { display: flex; gap: 12px; justify-content: center; }
.row.wrap { flex-wrap: wrap; justify-content: flex-start; }
.row.center { justify-content: center; }
.col { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }

/* coins */
.coin { display: inline-block; width: 1.1em; height: 1.1em; border-radius: 50%; vertical-align: -0.18em; background: radial-gradient(circle at 35% 30%, #fff3b0 0 18%, #ffd34f 30%, #e9a520 75%, #b9761a 100%); box-shadow: inset 0 0 0 2px #b9761a; position: relative; }
.coin::after { content: ''; position: absolute; left: 36%; top: 22%; width: 28%; height: 56%; border-radius: 40% 40% 30% 30%; background: rgba(185, 118, 26, 0.55); }
.coins-pill { position: absolute; top: calc(14px + var(--sat)); right: calc(14px + var(--sar)); background: var(--cream); border: 3px solid #e3b994; border-radius: 30px; padding: 6px 16px; font-weight: 700; font-size: 22px; box-shadow: var(--shadow); }
.coins-pill.small { position: static; font-size: 19px; padding: 4px 12px; }
.coins-pill span { margin-left: 6px; }
.coins-pill.bump { animation: bump 0.4s ease; }
@keyframes bump { 50% { transform: scale(1.15); } }

/* title */
#screen-title { align-items: flex-end; justify-content: center; }
.title-wrap { width: 100%; max-width: 560px; padding: 0 20px calc(28px + var(--sab)); display: flex; flex-direction: column; align-items: center; }
.logo { margin: 0; text-align: center; line-height: 0.95; color: #fff; text-shadow: 0 4px 0 var(--berry-d), 0 7px 14px rgba(120, 50, 30, 0.35); -webkit-text-stroke: 2px var(--berry-d); }
.logo span { display: block; font-size: clamp(40px, 11vw, 64px); }
.logo b { display: block; font-size: clamp(54px, 15vw, 86px); color: #fff1c9; }
.tagline { margin: 10px 0 18px; font-size: 20px; color: var(--ink); background: rgba(255, 248, 239, 0.85); padding: 4px 16px; border-radius: 20px; }
.title-buttons { width: 100%; display: flex; flex-direction: column; gap: 14px; }
.title-buttons .row .btn:not(.icon-btn) { flex: 1; }

/* panel screens */
.panel-screen { flex-direction: column; background: rgba(255, 243, 228, 0.97); overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; padding: calc(10px + var(--sat)) calc(14px + var(--sar)) calc(24px + var(--sab)) calc(14px + var(--sal)); }
.panel-head { display: flex; align-items: center; gap: 12px; justify-content: space-between; position: sticky; top: 0; background: rgba(255, 243, 228, 0.97); padding: 6px 0 10px; z-index: 2; }
.panel-head h2 { margin: 0; font-size: 28px; flex: 1; text-align: center; }
.panel-sub { margin: 0 0 12px; text-align: center; color: var(--ink2); }
.recipe-grid, .shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(156px, 1fr)); gap: 14px; max-width: 960px; width: 100%; margin: 0 auto; }
.card { background: #fff; border: 3px solid #f0cfae; border-radius: 22px; padding: 10px; text-align: center; box-shadow: 0 5px 0 rgba(150, 90, 50, 0.16); position: relative; display: flex; flex-direction: column; gap: 6px; }
.card canvas { width: 100%; aspect-ratio: 1 / 0.82; border-radius: 16px; background: linear-gradient(#fff6ea, #fde4cf); }
.card h4 { margin: 2px 0 0; font-size: 18px; line-height: 1.1; }
.card p { margin: 0; font-size: 14px; color: var(--ink2); line-height: 1.2; min-height: 2.4em; }
.card .btn { font-size: 18px; padding: 8px 10px; min-height: 46px; }
.card.locked canvas { filter: grayscale(0.85) brightness(1.05); opacity: 0.6; }
.card .badge { position: absolute; top: 8px; left: 8px; background: var(--mint); color: #fff; border-radius: 12px; padding: 2px 9px; font-size: 14px; font-weight: 600; }
.mini-stars { display: flex; gap: 3px; justify-content: center; }
.mini-stars i { width: 20px; height: 20px; background: #e6d6c6; clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); }
.mini-stars i.on { background: var(--gold); }
.tabs { display: flex; gap: 8px; justify-content: center; margin: 14px 0; flex-wrap: wrap; }
.tabs button { font: inherit; font-weight: 600; font-size: 18px; border: 3px solid #e3b994; background: var(--cream); color: var(--ink); border-radius: 18px; padding: 8px 14px; min-height: 48px; }
.tabs button.on { background: var(--peach); border-color: #d99a6d; }
.tipjar { display: grid; grid-template-columns: 90px 1fr; gap: 6px 12px; align-items: center; background: #fff; border: 3px solid #bfe7d6; border-radius: 22px; padding: 12px; max-width: 960px; width: 100%; margin: 0 auto; }
.tipjar canvas { width: 90px; height: 90px; grid-row: span 2; }
.tipjar h3 { margin: 0; font-size: 21px; }
.tipjar p { margin: 2px 0 0; font-size: 15px; color: var(--ink2); }
.tipjar .btn { grid-column: 2; justify-self: start; }

/* settings */
.settings { max-width: 640px; margin: 0 auto; width: 100%; }
.set-row { display: grid; grid-template-columns: 1.2fr 1.4fr auto; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 2px dashed #f0cfae; font-size: 20px; }
.set-row input[type=range] { width: 100%; height: 36px; accent-color: var(--berry); }
.toggle { font: inherit; font-weight: 600; min-width: 74px; min-height: 48px; border-radius: 16px; border: 3px solid #e3b994; background: var(--cream); color: var(--ink); }
.toggle[aria-pressed=true] { background: var(--mint); border-color: var(--mint-d); color: #fff; }
.settings h3 { margin: 22px 0 4px; }
.small-print { font-size: 15px; color: var(--ink2); line-height: 1.35; }

/* hud */
#hud { position: absolute; inset: 0; pointer-events: none; }
.hud-top { position: absolute; top: calc(10px + var(--sat)); left: calc(10px + var(--sal)); right: calc(10px + var(--sar)); display: flex; align-items: center; gap: 10px; pointer-events: auto; }
.hud-title { flex: 1; text-align: center; background: rgba(255, 248, 239, 0.92); border: 3px solid #e3b994; border-radius: 22px; padding: 4px 10px 6px; box-shadow: var(--shadow); min-width: 0; }
.hud-title b { display: block; font-size: 19px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pips { display: flex; gap: 5px; justify-content: center; margin-top: 3px; }
.pips i { width: 12px; height: 12px; border-radius: 50%; background: #ead7c4; }
.pips i.done { background: var(--mint); }
.pips i.now { background: var(--berry); transform: scale(1.25); }
.hud-say { position: absolute; left: calc(10px + var(--sal)); right: calc(10px + var(--sar)); top: calc(86px + var(--sat)); display: grid; grid-template-columns: 56px 1fr; gap: 2px 8px; align-items: center; background: rgba(255, 252, 246, 0.94); border: 3px solid #f0cfae; border-radius: 22px; padding: 6px 12px 8px 6px; pointer-events: none; box-shadow: 0 4px 0 rgba(150, 90, 50, 0.12); }
.hud-say canvas { width: 56px; height: 56px; grid-row: span 2; }
.hud-say p { margin: 0; font-size: 19px; line-height: 1.2; }
.bar { height: 9px; background: #f1e0cf; border-radius: 5px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ffb27d, var(--berry)); border-radius: 5px; transition: width 0.2s ease; }
#btn-serve { position: absolute; bottom: calc(160px + var(--sab)); left: 50%; transform: translateX(-50%); pointer-events: auto; min-width: 200px; }
#btn-serve:active { transform: translateX(-50%) translateY(4px); }

/* modals */
.modal-screen { align-items: center; justify-content: center; background: rgba(90, 45, 25, 0.35); padding: calc(14px + var(--sat)) 14px calc(14px + var(--sab)); }
.modal { background: var(--paper); border: 4px solid #e9bf98; border-radius: 30px; padding: 20px; width: min(520px, 100%); max-height: 100%; overflow-y: auto; box-shadow: 0 10px 0 rgba(120, 60, 30, 0.25); animation: pop 0.3s ease; }
@keyframes pop { from { transform: scale(0.85); opacity: 0; } }
.modal h2 { margin: 0 0 12px; text-align: center; font-size: 30px; }
.modal p { text-align: center; font-size: 18px; margin: 8px 0 14px; }
.modal textarea { width: 100%; font: 14px/1.3 monospace; border: 3px solid #e3b994; border-radius: 14px; padding: 8px; margin-bottom: 12px; -webkit-user-select: text; user-select: text; }
.complete canvas { width: 100%; height: auto; display: block; }
.stars { display: flex; justify-content: center; gap: 10px; }
.stars i { width: 54px; height: 54px; background: #e6d6c6; clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); transform: scale(0); }
.stars i.on { background: linear-gradient(#ffe27a, var(--gold)); }
.stars i.show { animation: starIn 0.45s cubic-bezier(.2, 1.6, .4, 1) forwards; }
@keyframes starIn { to { transform: scale(1); } }
.reward { display: flex; justify-content: center; align-items: center; gap: 10px; font-size: 22px; margin-bottom: 12px; }
.reward b { font-size: 30px; }
#toast { position: absolute; left: 50%; bottom: calc(190px + var(--sab)); transform: translateX(-50%) translateY(20px); background: #fffaf2; border: 3px solid #e3b994; color: var(--ink); font-size: 20px; font-weight: 600; padding: 10px 18px; border-radius: 20px; opacity: 0; transition: all 0.25s ease; pointer-events: none; box-shadow: var(--shadow); max-width: 90%; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#loading { align-items: center; justify-content: center; background: #f6d9c0; z-index: 10; }
.load-card { text-align: center; font-size: 20px; }
.spinner { width: 54px; height: 54px; margin: 0 auto 12px; border-radius: 50%; border: 7px solid #f2d2b8; border-top-color: var(--berry); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 760px) and (min-height: 700px) {
  .hud-say { left: 50%; right: auto; transform: translateX(-50%); width: min(680px, 92vw); }
  .hud-top { left: 50%; right: auto; transform: translateX(-50%); width: min(700px, 94vw); }
}
@media (prefers-reduced-motion: reduce) { * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; } }
