/* Piece of Cake: a warm bakery counter. One light theme. */
:root {
  color-scheme: light;
  --bg: #fbe3d3;
  --bg-2: #f6d0bd;
  --cream: #fff8f0;
  --panel: rgba(255, 250, 244, 0.86);
  --panel-solid: #fffaf4;
  --ink: #5a2e1e;
  --text: #5a2e1e;
  --muted: #9a6a55;
  --faint: #c49a86;
  --line: rgba(122, 64, 40, 0.14);
  --berry: #ec4f72;
  --berry-deep: #c9325a;
  --berry-ink: #ffffff;
  --gold: #ffc94a;
  --gold-deep: #e8a21a;
  --mint: #6fd3b0;
  --danger: #d6384f;
  --focus: rgba(236, 79, 114, 0.85);
  --scrim: rgba(90, 40, 25, 0.42);
  --shadow: 0 12px 32px rgba(122, 52, 30, 0.2);
  --display: "Fredoka", ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif;
  --ease: cubic-bezier(0.2, 0.9, 0.25, 1);
  --spring: cubic-bezier(0.3, 1.5, 0.5, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 600 16px/1.35 var(--display);
  color: var(--text);
  background:
    radial-gradient(120% 60% at 50% -10%, #fff3e6 0%, rgba(255, 243, 230, 0) 60%),
    radial-gradient(70% 50% at 100% 100%, rgba(255, 190, 200, 0.55) 0%, rgba(255, 190, 200, 0) 70%),
    linear-gradient(180deg, #fde9da 0%, #f8d6c4 100%);
  background-attachment: fixed;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
/* A faint polka-dot tablecloth under everything. */
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; opacity: 0.5;
  background-image: radial-gradient(rgba(255, 255, 255, 0.7) 2px, transparent 2.5px);
  background-size: 26px 26px;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
button:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
svg { width: 24px; height: 24px; flex: none; }

#app {
  position: relative; height: 100%; max-width: 560px; margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.screen {
  position: absolute; inset: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  display: flex; flex-direction: column; opacity: 0; pointer-events: none;
  transform: translateY(12px) scale(0.99); transition: opacity 260ms var(--ease), transform 320ms var(--ease);
}
.screen.active { opacity: 1; pointer-events: auto; transform: none; }

/* ---------------------------------------------------------------- home -- */

.topbar { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px 0; }
peanut-menu {
  --pm-bg: #fffaf4; --pm-fg: #5a2e1e; --pm-muted: #9a6a55; --pm-line: rgba(122, 64, 40, 0.14);
  --pm-hover: #fdeee4; --pm-accent: #ec4f72; --pm-accent-fg: #fff; --pm-danger: #d6384f;
  --pm-font: var(--display); --pm-trigger-bg: rgba(255, 250, 244, 0.8); --pm-trigger-fg: #5a2e1e;
  --pm-shadow: 0 10px 30px rgba(122, 52, 30, 0.2);
}
.wordmark {
  margin: 4px 0 0; text-align: center; font-weight: 700; line-height: 0.88;
  display: flex; flex-direction: column; align-items: center;
  color: #fff; letter-spacing: -0.01em;
  -webkit-text-stroke: 0;
  text-shadow: 0 3px 0 #c9325a, 0 6px 0 #a8244a, 0 12px 22px rgba(168, 36, 74, 0.35);
}
.wordmark span { font-size: clamp(54px, 15vw, 76px); }
.wordmark small { font-size: 26px; color: #ffd3dd; text-shadow: 0 2px 0 #c9325a; margin: 6px 0 2px; }
.hero { flex: 1; min-height: 150px; width: 100%; display: block; }
.home-actions { display: flex; flex-direction: column; gap: 12px; padding: 0 22px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 52px; padding: 0 22px; border-radius: 18px; font-weight: 700; font-size: 18px;
  transition: transform 160ms var(--spring), box-shadow 160ms, filter 160ms;
}
.btn:active { transform: scale(0.96); }
.btn.primary, .btn.play {
  color: var(--berry-ink);
  background: linear-gradient(180deg, #ff7394 0%, #ec4f72 55%, #d93d63 100%);
  box-shadow: 0 5px 0 #b02b52, 0 12px 24px rgba(201, 50, 90, 0.35), inset 0 2px 0 rgba(255, 255, 255, 0.35);
}
.btn.primary:active, .btn.play:active { transform: translateY(3px) scale(0.98); box-shadow: 0 2px 0 #b02b52, 0 6px 14px rgba(201, 50, 90, 0.3), inset 0 2px 0 rgba(255, 255, 255, 0.35); }
.btn.play { min-height: 72px; border-radius: 24px; font-size: 26px; }
.btn.play svg { width: 34px; height: 34px; }
.btn.play span { display: flex; flex-direction: column; align-items: flex-start; line-height: 1; }
.btn.play small { font-size: 15px; opacity: 0.85; margin-top: 4px; font-weight: 600; }
.btn.soft {
  background: rgba(255, 250, 244, 0.9); color: var(--ink);
  box-shadow: 0 4px 0 rgba(160, 90, 60, 0.22), 0 10px 22px rgba(122, 52, 30, 0.12);
  position: relative;
}
.btn.soft:active { transform: translateY(2px) scale(0.98); }
.btn.soft svg { color: var(--berry); }
.pill { margin-left: auto; font-size: 14px; padding: 3px 10px; border-radius: 99px; background: #fde4e9; color: var(--berry-deep); }
.dot { position: absolute; top: 10px; left: 38px; width: 11px; height: 11px; border-radius: 50%; background: var(--berry); box-shadow: 0 0 0 3px #fffaf4; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.35); } }
.btn.wide { width: 100%; }
.btn.danger { background: #fde4e7; color: var(--danger); }

.recipe-meter { margin: 16px 22px 0; padding: 12px 14px; border-radius: 18px; background: rgba(255, 250, 244, 0.65); }
.meter-row { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); margin-bottom: 7px; }
.meter-row b { color: var(--ink); }
.meter { height: 12px; border-radius: 99px; background: rgba(122, 64, 40, 0.12); overflow: hidden; }
.meter i {
  display: block; height: 100%; width: 0; border-radius: inherit;
  background: linear-gradient(90deg, #ffc94a, #ff8fb0);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.5);
  transition: width 900ms var(--ease);
}
.build { text-align: center; color: var(--faint); font-size: 11px; margin: 10px 0 12px; font-weight: 500; }

/* ---------------------------------------------------------------- game -- */

.hud { display: flex; align-items: center; gap: 10px; padding: 10px 12px 4px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 15px; display: grid; place-items: center; flex: none;
  background: rgba(255, 250, 244, 0.85); color: var(--ink);
  box-shadow: 0 3px 0 rgba(160, 90, 60, 0.2);
}
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(160, 90, 60, 0.2); }
.icon-spacer { width: 44px; flex: none; }
.hud-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.hud-level { font-size: 15px; color: var(--muted); line-height: 1; }
.goal { position: relative; width: 100%; max-width: 230px; }
.goal-bar { height: 26px; border-radius: 99px; background: rgba(255, 250, 244, 0.85); box-shadow: inset 0 2px 4px rgba(122, 52, 30, 0.15); overflow: hidden; }
.goal-bar i {
  display: block; height: 100%; width: 0; border-radius: inherit;
  background: linear-gradient(180deg, #ffa3bb, #ec4f72);
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.35);
  transition: width 500ms var(--spring);
}
.goal-text { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 4px; font-size: 16px; color: var(--ink); text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7); }
.goal-text svg { width: 18px; height: 18px; color: #c98a4f; }
.goal.bump .goal-bar { animation: bump 380ms var(--spring); }
@keyframes bump { 40% { transform: scale(1.08); } }
.score { width: 64px; text-align: right; display: flex; flex-direction: column; line-height: 1.05; }
.score small { font-size: 12px; color: var(--muted); }
.score b { font-size: 22px; font-variant-numeric: tabular-nums; }
.stage { position: relative; flex: 1; min-height: 0; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }

/* ---------------------------------------------------------------- book -- */

.book-hud h2 { margin: 0; font-size: 24px; line-height: 1; }
.book-hud p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.book-meter { margin-top: 8px; }
.book-list { flex: 1; overflow-y: auto; padding: 6px 14px 30px; -webkit-overflow-scrolling: touch; }
.set-title { margin: 18px 6px 8px; font-size: 18px; display: flex; justify-content: space-between; align-items: baseline; }
.set-title small { font-size: 13px; color: var(--muted); }
.set-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.recipe {
  position: relative; border-radius: 18px; background: rgba(255, 250, 244, 0.75); padding: 4px 4px 10px;
  display: flex; flex-direction: column; align-items: center; text-align: center;
  box-shadow: 0 3px 0 rgba(160, 90, 60, 0.12);
}
.recipe canvas { width: 100%; aspect-ratio: 1 / 0.82; display: block; }
.recipe span { font-size: 13px; line-height: 1.15; padding: 0 4px; min-height: 30px; display: flex; align-items: center; }
.recipe.locked { background: rgba(255, 250, 244, 0.4); }
.recipe.locked span { color: var(--faint); }
.recipe .new { position: absolute; top: 6px; right: 6px; font-size: 11px; padding: 2px 7px; border-radius: 99px; background: var(--berry); color: #fff; }

/* -------------------------------------------------------------- sheets -- */

.overlay {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center;
  background: var(--scrim); padding: 12px; padding-bottom: max(12px, env(safe-area-inset-bottom));
  animation: fade 220ms var(--ease);
}
.overlay[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: relative; width: 100%; max-width: 440px; border-radius: 28px; padding: 22px 20px 20px;
  background: var(--panel-solid); box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 12px;
  animation: rise 420ms var(--spring);
}
@keyframes rise { from { transform: translateY(40px) scale(0.96); opacity: 0; } }
.sheet h3 { margin: -6px 0 0; font-size: 30px; line-height: 1.05; }
.sheet .close { position: absolute; top: 14px; right: 14px; }
.eyebrow { margin: 0; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--berry); }
.sheet-copy { margin: 0; color: var(--muted); font-weight: 500; }

.end { text-align: center; align-items: center; }
.end h3 { font-size: 38px; }
.end-stats { display: flex; gap: 8px; width: 100%; }
.end-stats div { flex: 1; border-radius: 16px; background: #fdf0e6; padding: 8px 4px; display: flex; flex-direction: column; }
.end-stats small { font-size: 12px; color: var(--muted); }
.end-stats b { font-size: 24px; font-variant-numeric: tabular-nums; }
.end-meter { margin: 0; width: 100%; background: #fdf0e6; }
.end-actions { display: flex; gap: 10px; width: 100%; margin-top: 4px; }
.end-actions .btn { flex: 1; }
.unlock { width: 100%; border-radius: 22px; padding: 4px 10px 14px; background: radial-gradient(90% 80% at 50% 30%, #fff5c9 0%, #ffe3ec 70%); animation: rise 600ms var(--spring); }
.unlock canvas { width: 100%; height: 150px; display: block; }
.unlock h4 { margin: 2px 0 0; font-size: 26px; }
.unlock small { color: var(--muted); }

.cake-card { align-items: center; text-align: center; }
.cake-card canvas { width: 100%; height: 220px; display: block; }
.cake-num { margin: 0; color: var(--faint); font-size: 13px; }

.toggles { display: flex; flex-direction: column; }
.toggle { display: flex; align-items: center; gap: 12px; min-height: 56px; border-top: 1px solid var(--line); cursor: pointer; }
.toggle:first-child { border-top: 0; }
.toggle span { flex: 1; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle i { flex: none; width: 50px; height: 30px; border-radius: 15px; background: rgba(122, 64, 40, 0.15); position: relative; transition: background 150ms; }
.toggle i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 220ms var(--spring); }
.toggle input:checked + i { background: var(--berry); }
.toggle input:checked + i::after { transform: translateX(20px); }
.toggle input:focus-visible + i { outline: 3px solid var(--focus); outline-offset: 2px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30;
  background: #5a2e1e; color: #fff; padding: 10px 16px; border-radius: 14px; font-size: 15px; box-shadow: var(--shadow);
}

/* account (shared sign-in) */
.account { display: flex; flex-direction: column; gap: 12px; }
.acct-row { display: flex; gap: 8px; }
.acct-row input {
  flex: 1; min-width: 0; height: 52px; border-radius: 16px; border: 2px solid var(--line); padding: 0 14px;
  font: 600 17px var(--display); color: var(--ink); background: #fff;
}
.acct-row input:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
#acctCodeInput { letter-spacing: 0.35em; text-align: center; }
.acct-row .btn { flex: none; padding-inline: 18px; }
.acct-links { display: flex; justify-content: space-between; gap: 8px; }
.link-btn { color: var(--berry-deep); font-size: 14px; padding: 6px 2px; }
.link-btn:disabled { opacity: 0.5; }
.acct-wait { margin: 0; min-height: 50px; display: flex; align-items: center; gap: 10px; color: var(--muted); }
.acct-in p { margin: 0 0 4px; display: flex; flex-direction: column; gap: 2px; }
.acct-in b { font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-in small { color: var(--muted); font-size: 13px; }
.acct-captcha:empty { display: none; }
.acct-captcha { display: flex; justify-content: center; }
.spin { flex: none; width: 16px; height: 16px; border-radius: 50%; border: 2.5px solid currentColor; border-right-color: transparent; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.acct-error { margin: 0; color: var(--danger); font-size: 14px; }
.btn:disabled { opacity: 0.55; }

@media (prefers-reduced-motion: reduce) {
  .screen, .sheet, .overlay, .unlock { transition: none; animation: none; }
}
