/* ===========================================================================
   The Magical Bakery — shared theme & design system
   See THEME.md for the full spec. Use the CSS variables, not raw hex.
   =========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;500;600;700&family=Nunito:ital,wght@0,400;0,600;0,700;0,800;1,700&display=swap');

:root {
  /* surfaces */
  --cream:            #FFF3DF;
  --cream-deep:       #FBE7C6;
  --parchment:        #FFFBF2;
  --wood:             #C98A4B;
  --wood-deep:        #9C6431;

  /* ink */
  --cocoa:            #4A2E18;
  --cocoa-soft:       #7A5638;

  /* place value (also used to color-code digits) */
  --ones-gold:        #E3A13C;
  --ones-gold-deep:   #C5811F;
  --tens-mint:        #4FBF96;
  --tens-mint-deep:   #2F9C76;
  --hundreds-berry:   #9A6FD0;
  --hundreds-berry-deep:#774FB0;
  --thousands-blue:   #4F90C4;
  --thousands-blue-deep:#2E6E9E;
  --tenk-caramel:     #EF8A4C;
  --tenk-caramel-deep:#CC6A2E;

  /* action / feedback */
  --frosting:         #F2789B;
  --frosting-deep:    #E0517E;
  --leaf:             #7FD1AE;
  --cherry:           #E8523F;

  /* shapes & motion */
  --r-sm: 14px;
  --r-md: 20px;
  --r-lg: 28px;
  --shadow-soft: 0 6px 0 rgba(156,100,49,.18), 0 12px 26px rgba(74,46,24,.16);
  --shadow-lift: 0 10px 0 rgba(156,100,49,.18), 0 20px 40px rgba(74,46,24,.22);
  --ease-bounce: cubic-bezier(.34, 1.56, .64, 1);

  --font-display: "Fredoka", "Baloo 2", system-ui, sans-serif;
  --font-body: "Nunito", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--cocoa);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* --- The bakery wall: warm cream with a soft polka texture & top glow --- */
.bakery-page {
  min-height: 100%;
  background-color: var(--cream);
  background-image:
    radial-gradient(circle at 50% -10%, #FFFAF0 0%, rgba(255,250,240,0) 55%),
    radial-gradient(rgba(201,138,75,.10) 1.5px, transparent 1.6px),
    linear-gradient(180deg, var(--cream) 0%, var(--cream-deep) 100%);
  background-size: auto, 26px 26px, auto;
  background-attachment: fixed;
}

h1, h2, h3, .display { font-family: var(--font-display); font-weight: 700; letter-spacing: .2px; }

/* ----------------------------- Buttons ----------------------------------- */
.btn {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--cocoa);
  background: #fff;
  border: none;
  border-radius: 999px;
  padding: 14px 28px;
  min-height: 56px;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: transform .12s var(--ease-bounce), box-shadow .12s ease, filter .12s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.btn:hover   { transform: translateY(-2px); }
.btn:active  { transform: translateY(3px); box-shadow: 0 2px 0 rgba(156,100,49,.18), 0 6px 14px rgba(74,46,24,.16); }
.btn:focus-visible { outline: 4px solid var(--frosting); outline-offset: 3px; }
.btn[disabled] { opacity: .45; cursor: default; transform: none; filter: grayscale(.3); }

.btn--primary { background: var(--frosting); color: #fff; box-shadow: 0 6px 0 var(--frosting-deep), 0 14px 26px rgba(224,81,126,.35); }
.btn--primary:active { box-shadow: 0 2px 0 var(--frosting-deep), 0 6px 14px rgba(224,81,126,.3); }
.btn--mint    { background: var(--tens-mint); color: #fff; box-shadow: 0 6px 0 var(--tens-mint-deep), 0 14px 26px rgba(47,156,118,.3); }
.btn--mint:active { box-shadow: 0 2px 0 var(--tens-mint-deep); }
.btn--ghost   { background: rgba(255,255,255,.7); }
.btn--lg { font-size: 1.5rem; padding: 18px 38px; min-height: 68px; }

/* ----------------------------- Card / counter ---------------------------- */
.card {
  background: var(--parchment);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-soft);
  padding: 24px;
}

/* Wooden counter surface that games sit on */
.counter {
  background:
    linear-gradient(180deg, rgba(255,255,255,.18), rgba(0,0,0,.06)),
    repeating-linear-gradient(90deg, var(--wood) 0 38px, #C28247 38px 76px);
  border-radius: var(--r-lg);
  box-shadow: inset 0 3px 0 rgba(255,255,255,.25), inset 0 -10px 24px rgba(120,73,30,.35), var(--shadow-soft);
  border-bottom: 10px solid var(--wood-deep);
}

/* ----------------------------- Baker Pip --------------------------------- */
.pip {
  width: 96px; height: 96px;
  flex: 0 0 auto;
  position: relative;
  animation: pip-breathe 3.4s ease-in-out infinite;
}
@keyframes pip-breathe { 0%,100%{ transform: translateY(0) rotate(-1deg);} 50%{ transform: translateY(-5px) rotate(1deg);} }
.pip.is-cheer { animation: pip-cheer .6s var(--ease-bounce); }
@keyframes pip-cheer { 0%{transform:scale(1)} 40%{transform:scale(1.18) rotate(-6deg)} 70%{transform:scale(.96) rotate(4deg)} 100%{transform:scale(1)} }

.pip-bubble {
  position: relative;
  background: #fff;
  color: var(--cocoa);
  border-radius: 22px;
  padding: 14px 20px;
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.3;
  box-shadow: var(--shadow-soft);
  max-width: 520px;
}
.pip-bubble::after { /* little tail pointing left toward Pip */
  content: "";
  position: absolute; left: -14px; top: 26px;
  border: 12px solid transparent;
  border-right-color: #fff;
  filter: drop-shadow(-3px 2px 2px rgba(74,46,24,.08));
}

/* ----------------------------- Stars ------------------------------------- */
.star { color: var(--ones-gold); filter: drop-shadow(0 2px 1px rgba(197,129,31,.5)); }
.star--empty { color: rgba(74,46,24,.18); filter: none; }

/* --------------------- Base-ten "baked goods" blocks ---------------------
   Drawn with CSS so no images are needed. Proportional on purpose:
   a tray is 10 cookies tall, a crate is a 10x10 grid.                       */

.cookie {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 30%, #F0C078 0 18%, var(--ones-gold) 45%, var(--ones-gold-deep) 100%);
  box-shadow: inset 0 -3px 4px rgba(120,73,30,.45), 0 2px 3px rgba(74,46,24,.25);
  position: relative;
}
.cookie::before, .cookie::after { /* chocolate chips */
  content: ""; position: absolute; width: 4px; height: 4px; border-radius: 50%;
  background: #5A3415;
}
.cookie::before { top: 6px; left: 14px; box-shadow: 7px 9px 0 #5A3415, -4px 8px 0 #5A3415; }
.cookie::after  { top: 14px; left: 6px; }

/* a tray of ten: a tall slot holding ten little cookies */
.tray {
  width: 34px;
  padding: 4px;
  border-radius: 9px;
  background: linear-gradient(180deg, #65cda6, var(--tens-mint) 30%, var(--tens-mint-deep));
  box-shadow: inset 0 2px 0 rgba(255,255,255,.4), 0 3px 5px rgba(47,156,118,.4);
  display: grid; grid-template-rows: repeat(10, 1fr); gap: 2px;
}
.tray i { display:block; height: 9px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #F0C078, var(--ones-gold) 60%, var(--ones-gold-deep));
  box-shadow: inset 0 -1px 1px rgba(120,73,30,.5); }

/* a crate of one hundred: a 10x10 grid */
.crate {
  width: 78px; height: 78px;
  padding: 5px;
  border-radius: 12px;
  background: linear-gradient(180deg, #b693e0, var(--hundreds-berry) 35%, var(--hundreds-berry-deep));
  box-shadow: inset 0 2px 0 rgba(255,255,255,.35), 0 4px 7px rgba(119,79,176,.4);
  display: grid; grid-template-columns: repeat(10, 1fr); grid-template-rows: repeat(10,1fr); gap: 1.5px;
}
.crate i { display:block; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #F0C078, var(--ones-gold) 65%, var(--ones-gold-deep)); }

/* color-coded numerals helper */
.d-ones      { color: var(--ones-gold-deep); }
.d-tens      { color: var(--tens-mint-deep); }
.d-hundreds  { color: var(--hundreds-berry-deep); }
.d-thousands { color: var(--thousands-blue-deep); }

/* ----------------------------- Confetti ---------------------------------- */
.sprinkle {
  position: fixed; top: -20px; width: 12px; height: 12px; border-radius: 3px;
  pointer-events: none; z-index: 9999;
  animation: sprinkle-fall linear forwards;
}
@keyframes sprinkle-fall {
  to { transform: translateY(105vh) rotate(640deg); opacity: .9; }
}

/* utility */
.row { display: flex; align-items: center; }
.center { display: flex; align-items: center; justify-content: center; }
.hidden { display: none !important; }
/* the [hidden] attribute must always win, even over class rules that set
   display (e.g. .celebrate/.choices use display:flex) */
[hidden] { display: none !important; }
.sr-only { position:absolute; width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);border:0; }

/* ===========================================================================
   Bakers (profiles) — chip + first-run gate. Injected by shared/profiles.js.
   =========================================================================== */

/* round avatar token (the kid's treat on a frosting-coloured disc) */
.baker-avatar {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  box-shadow: inset 0 -3px 6px rgba(74,46,24,.22), inset 0 2px 0 rgba(255,255,255,.45), 0 2px 4px rgba(74,46,24,.2);
  line-height: 1; flex: 0 0 auto;
}
.baker-avatar--add { background: var(--cream-deep); color: var(--cocoa-soft); box-shadow: none; }

/* the always-on "who's playing" chip, top-left (mute owns top-right) */
.baker-chip {
  position: fixed; z-index: 60;
  top: calc(16px + env(safe-area-inset-top, 0px));
  left: calc(16px + env(safe-area-inset-left, 0px));
  display: inline-flex; align-items: center; gap: 9px;
  padding: 6px 16px 6px 6px;
  background: var(--parchment); color: var(--cocoa);
  border: none; border-radius: 999px; cursor: pointer;
  font-family: var(--font-display); font-weight: 600; font-size: 1.1rem;
  box-shadow: var(--shadow-soft);
  transition: transform .12s var(--ease-bounce);
  -webkit-tap-highlight-color: transparent;
}
.baker-chip:hover { transform: translateY(-2px); }
.baker-chip:active { transform: translateY(1px); }
.baker-chip:focus-visible { outline: 4px solid var(--frosting); outline-offset: 3px; }
.baker-chip__name { padding-right: 2px; }

/* full-screen gate / switcher overlay */
.baker-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: rgba(74,46,24,.55);
  backdrop-filter: blur(3px);
  overflow: auto;
}
.baker-modal {
  width: min(560px, 100%);
  text-align: center;
  animation: baker-pop .35s var(--ease-bounce);
}
@keyframes baker-pop { 0% { transform: scale(.9); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.baker-modal__pip { display: flex; justify-content: center; margin-top: -6px; }
.baker-modal__pip svg { animation: pip-breathe 3.4s ease-in-out infinite; }
.baker-modal__title { margin: 6px 0 18px; font-size: 1.8rem; color: var(--cocoa); }

/* grid of baker cards (pick / switch) */
.baker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 16px; }
.baker-card {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  background: var(--cream); border: none; border-radius: var(--r-md);
  padding: 16px 10px; box-shadow: var(--shadow-soft);
  color: var(--cocoa); cursor: pointer; font-family: var(--font-body);
  transition: transform .12s var(--ease-bounce);
}
.baker-card:hover { transform: translateY(-4px) rotate(-1deg); }
.baker-card.is-active { outline: 4px solid var(--leaf); outline-offset: 2px; }
.baker-card--add { border: 3px dashed var(--wood); background: var(--parchment); }
.baker-card__pick {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  background: none; border: none; cursor: pointer; padding: 0; width: 100%;
  color: inherit; font: inherit;
}
.baker-card__name { font-family: var(--font-display); font-weight: 600; font-size: 1.2rem; }
.baker-card__edit { display: flex; gap: 6px; margin-top: 2px; }
.baker-mini {
  width: 34px; height: 34px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--parchment); box-shadow: var(--shadow-soft);
  font-size: 1rem; line-height: 1; color: var(--cocoa-soft);
  -webkit-tap-highlight-color: transparent;
}
.baker-mini:hover { transform: translateY(-1px); }
.baker-mini:focus-visible, .baker-treat:focus-visible, .baker-swatch:focus-visible { outline: 3px solid var(--frosting); outline-offset: 2px; }

/* create-a-baker form */
.baker-form { display: flex; flex-direction: column; gap: 18px; text-align: left; }
.baker-field { display: flex; flex-direction: column; gap: 8px; }
.baker-field > span { font-family: var(--font-display); font-weight: 600; font-size: 1.1rem; color: var(--cocoa-soft); }
.baker-name-input {
  font-family: var(--font-display); font-size: 1.4rem; font-weight: 600; color: var(--cocoa);
  background: var(--cream); border: 3px solid var(--cream-deep); border-radius: var(--r-sm);
  padding: 12px 16px; min-height: 56px; width: 100%;
}
.baker-name-input:focus { outline: none; border-color: var(--frosting); }
.baker-treats, .baker-swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.baker-treat {
  width: 52px; height: 52px; border-radius: 16px; border: 3px solid transparent;
  background: var(--cream); cursor: pointer; font-size: 1.7rem; line-height: 1;
  box-shadow: var(--shadow-soft); transition: transform .12s var(--ease-bounce);
  -webkit-tap-highlight-color: transparent;
}
.baker-treat:hover { transform: translateY(-2px); }
.baker-treat.is-on { border-color: var(--frosting); transform: translateY(-2px) scale(1.05); }
.baker-swatch {
  width: 48px; height: 48px; border-radius: 50%; border: 4px solid #fff; cursor: pointer;
  box-shadow: var(--shadow-soft); transition: transform .12s var(--ease-bounce);
  -webkit-tap-highlight-color: transparent;
}
.baker-swatch:hover { transform: translateY(-2px); }
.baker-swatch.is-on { border-color: var(--cocoa); transform: translateY(-2px) scale(1.08); }
.baker-form__actions { display: flex; justify-content: flex-end; gap: 12px; flex-wrap: wrap; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
