/* bakery: the Gingerbread bakery. Rounds of 30 s, cookies pile up on your tray. */
.bk { display: flex; flex-direction: column; gap: 6px; height: 100%; min-height: 0; }
.bk__title { margin: 0; font-size: clamp(20px, 3.2dvh, 26px); font-weight: 400; text-align: center; line-height: 1.1; }

/* No page scroll while you play: exactly the visible viewport (minus the garland strip on top and the
   corner-pill zone below); the top zone shrinks to leave the ovens their room. */
#screen:has(> .bk) {
  --bk-h: clamp(160px, calc(100vh - 372px), 250px); /* fallback; bakery.js measures the real height */
  --bk-h: clamp(160px, calc(100dvh - 372px), 250px);
  height: 100vh; height: 100dvh; min-height: 0; overflow: hidden;
  padding: calc(80px + env(safe-area-inset-top, 0px)) 16px calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column;
}
#screen:has(> .bk) > .bk { flex: 1 1 auto; }
@media (max-height: 540px) { #screen:has(> .bk) { overflow-y: auto; } } /* too short to fit: scroll rather than clip */

.bk__top { display: flex; align-items: flex-start; gap: 14px; height: var(--bk-h, 220px); flex: 0 0 auto; }

/* the tray: kraft rim, baking paper, cookies laid out from the bottom up */
.bk__tray {
  position: relative; flex: 0 0 auto; height: var(--bk-h, 220px); aspect-ratio: 1.02 / 1; max-width: 58%;
  border-radius: 18px; background: linear-gradient(160deg, var(--kraft), var(--kraft-dark));
  box-shadow: 0 6px 8px -4px oklch(0.3 0.03 50 / 0.45), inset 0 0 0 2px oklch(0.6 0.07 62);
}
.bk__tray::before { content: ""; position: absolute; inset: 9px; border-radius: 11px;
  background: oklch(0.94 0.03 88); box-shadow: inset 0 2px 5px oklch(0.4 0.04 60 / 0.35); }
.bk__cookies { position: absolute; inset: 12px; }
.bk__tc { position: absolute; width: 17%; height: auto; color: oklch(0.7 0.12 62);
  filter: drop-shadow(0 1.5px 1px oklch(0.3 0.05 55 / 0.45)); }
.bk__tc.is-new { animation: bk-land 0.35s cubic-bezier(.2,.9,.3,1.3); }
@keyframes bk-land { from { opacity: 0; margin-top: -26px; } to { opacity: 1; margin-top: 0; } }

.bk__side { flex: 1; min-width: 0; height: 100%; overflow: hidden; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
.bk__stats { display: flex; flex-wrap: wrap; justify-content: center; align-items: baseline; column-gap: 8px; }
.bk__clock {
  --p: 100;
  position: relative; display: grid; place-items: center;
  --ring: var(--ring-px, 72px); flex: 0 0 auto; width: var(--ring); height: var(--ring); border-radius: 50%;
  background:
    radial-gradient(circle, var(--tag) 0 56%, transparent 57%),
    conic-gradient(var(--red) calc(var(--p) * 1%), oklch(0.86 0.03 75) 0);
  box-shadow: 0 6px 8px -4px oklch(0.3 0.03 50 / 0.4), inset 0 0 0 2px var(--kraft-dark);
  font-family: "Young Serif", serif; font-size: calc(var(--ring) * 0.43); line-height: 1; color: var(--red-dark, var(--red));
}
.bk__clock.is-low { animation: bk-pulse 0.5s ease-in-out infinite alternate; color: var(--red); }
@keyframes bk-pulse { to { transform: scale(1.09); } }
.bk__count { margin: 0; font-weight: 600; font-size: 16px; text-align: center; }
.bk__best { margin: 0; font-size: 20px; color: var(--soft); text-align: center; line-height: 1.1; }
.bk__hint { margin: 0; min-height: 2.2em; font-size: 18px; line-height: 1.1; text-align: center; color: var(--soft); }
.bk.is-compact .bk__title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.bk__done { flex: 0 0 auto; min-width: 0; min-height: 44px; padding: 0 16px; font-size: 15px; }

/* the stage: ovens standing on a kraft counter */
.bk__stage { position: relative; width: 100%; flex: 1 1 0; min-height: 270px; display: flex; flex-direction: column; justify-content: flex-end; user-select: none; -webkit-user-select: none; }
.bk__ovens {
  flex: 1 1 auto; min-height: 0; display: grid; gap: 10px 12px; padding: 2px 2px 0;
  grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: minmax(0, 1fr); max-height: 330px;
}
.bk__ovens[data-n="3"] { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.bk__ovens[data-n="4"] { grid-template-columns: repeat(2, minmax(0, 1fr)); max-height: 400px; }
.bk__counter {
  flex: 0 0 62px; margin: -6px -4px 0; border-radius: 12px; position: relative; z-index: 0;
  background: linear-gradient(to bottom, oklch(0.8 0.06 70), var(--kraft) 18%, var(--kraft-dark));
  box-shadow: 0 6px 8px -4px oklch(0.3 0.03 50 / 0.45), inset 0 2px 0 oklch(0.88 0.05 75);
}

.bk__oven {
  --brick: oklch(0.5 0.11 38);
  position: relative; z-index: 1; display: flex; gap: 8px; align-items: stretch; min-width: 0; min-height: 44px;
  padding: 0; border: 0; background: none; cursor: pointer; touch-action: manipulation; font: inherit; color: inherit;
  -webkit-user-select: none; user-select: none;
}
.bk__oven:focus { outline: none; }
.bk__oven:focus-visible .bk__body { outline: 3px solid var(--gold); outline-offset: 2px; }
.bk__body {
  position: relative; flex: 1 1 0; min-width: 0; border-radius: 16px 16px 8px 8px; overflow: hidden;
  background:
    linear-gradient(oklch(0.38 0.08 38 / 0.45) 2px, transparent 2px) 0 0 / 100% 16px,
    linear-gradient(90deg, oklch(0.38 0.08 38 / 0.35) 2px, transparent 2px) 0 0 / 30px 32px,
    linear-gradient(to bottom, oklch(0.56 0.12 40), var(--brick));
  box-shadow: inset 0 0 0 3px oklch(0.4 0.07 45), inset 0 -8px 0 oklch(0.4 0.09 40 / 0.5), 0 5px 6px -3px oklch(0.25 0.04 50 / 0.55);
  transition: box-shadow 0.15s;
}
.bk__knobs { position: absolute; top: 6%; left: 0; right: 0; display: flex; justify-content: center; gap: 12%; }
.bk__knobs i { width: clamp(7px, 8%, 12px); aspect-ratio: 1; border-radius: 50%; background: radial-gradient(circle at 35% 30%, oklch(0.9 0.1 90), oklch(0.7 0.13 80)); box-shadow: 0 1px 2px #0006; }
.bk__window {
  position: absolute; left: 13%; right: 13%; top: 20%; bottom: 25%; overflow: hidden;
  border-radius: 40% 40% 10px 10px / 30% 30% 10px 10px;
  background: oklch(0.2 0.03 40);
  box-shadow: inset 0 4px 10px #000c, 0 0 0 3px oklch(0.78 0.07 70), 0 0 0 5px oklch(0.45 0.07 50);
}
.bk__glow { position: absolute; inset: 0; opacity: calc(0.3 + var(--v) * 0.65);
  background: radial-gradient(ellipse at 50% 90%, oklch(0.85 0.17 75), oklch(0.65 0.18 50) 45%, transparent 75%); }
.bk__cookie { position: absolute; left: 50%; bottom: 7%; height: 80%; width: auto; transform: translateX(-50%);
  max-width: 88%; color: var(--ck); filter: drop-shadow(0 2px 3px #0008); }
.bk__says { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; opacity: 0;
  font: 400 clamp(15px, 4.2vw, 20px)/1 var(--serif); color: #fffaf0; text-shadow: 0 1px 3px #000c; }
.bk__handle { position: absolute; left: 22%; right: 22%; bottom: 11%; height: clamp(5px, 6%, 8px); border-radius: 4px;
  background: linear-gradient(oklch(0.9 0.1 90), oklch(0.68 0.12 78)); box-shadow: 0 1px 2px #0006; }
.bk__num { position: absolute; right: 7%; bottom: 6%; display: none; font: 600 11px/1 var(--body); color: oklch(0.92 0.05 80); opacity: 0.85; }
@media (hover: hover) and (pointer: fine) { .bk__num { display: block; } }

/* the temperature meter: raw (bottom) - golden - perfect - burnt (top), with a needle */
.bk__meter { flex: 0 0 clamp(18px, 20%, 30px); display: flex; justify-content: center; padding: 8px 0; }
.bk__tube {
  position: relative; width: 100%; border-radius: 999px; border: 2px solid oklch(0.4 0.06 50);
  background: linear-gradient(to top,
    oklch(0.9 0.045 88) 0 55%,
    oklch(0.83 0.13 82) 55% 65%, oklch(0.7 0.17 62) 65% 75%, oklch(0.83 0.13 82) 75% 85%,
    oklch(0.36 0.08 30) 85% 100%);
  box-shadow: inset 2px 0 3px oklch(1 0 0 / 0.35), inset -2px 0 3px oklch(0.2 0.04 40 / 0.3), 0 2px 3px -1px oklch(0.25 0.04 50 / 0.5);
}
.bk__star { position: absolute; left: 50%; bottom: 70%; width: 100%; aspect-ratio: 1; transform: translate(-50%, 50%); }
.bk__star::before { content: "\2726"; position: absolute; inset: 0; display: grid; place-items: center; font-size: 12px; line-height: 1; color: #fffaf0; text-shadow: 0 0 3px oklch(0.4 0.1 50); }
.bk__needle { position: absolute; left: -6px; right: -6px; height: 5px; bottom: calc(var(--v) * 100%); transform: translateY(50%);
  border-radius: 3px; background: var(--ink); box-shadow: 0 0 0 2px #fffaf0, 0 2px 4px #0006; }
.bk__needle::before, .bk__needle::after { content: ""; position: absolute; top: 50%; transform: translateY(-50%); border: 6px solid transparent; }
.bk__needle::before { right: 100%; border-left-color: var(--ink); margin-right: -1px; }
.bk__needle::after { left: 100%; border-right-color: var(--ink); margin-left: -1px; }

/* an oven whose cookie is golden or better glows */
.bk__oven.is-ready .bk__body { box-shadow: inset 0 0 0 3px oklch(0.4 0.07 45), inset 0 -8px 0 oklch(0.4 0.09 40 / 0.5), 0 0 0 3px oklch(0.82 0.14 85), 0 0 14px oklch(0.82 0.14 85 / 0.8); }
.bk__oven.is-done .bk__meter { opacity: 0.6; }
.bk__oven.is-done .bk__says { opacity: 1; animation: bk-says 0.7s ease-out both; }
.bk__oven.is-burnt .bk__says { color: oklch(0.85 0.1 50); }
.bk__oven.is-raw .bk__says { color: oklch(0.9 0.06 88); }
.bk__oven.is-pop .bk__cookie { animation: bk-pop 0.45s cubic-bezier(.2,.9,.3,1.3); }
.bk__oven.is-burnt.is-pop .bk__body { animation: bk-shake 0.4s; }
.bk__oven.is-perfect .bk__window::after { content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(circle at 18% 28%, #fffaf0 0 3px, transparent 4px), radial-gradient(circle at 82% 22%, #fffaf0 0 2.5px, transparent 3.5px),
    radial-gradient(circle at 70% 62%, #fffaf0 0 3px, transparent 4px), radial-gradient(circle at 26% 66%, #fffaf0 0 2px, transparent 3px);
  animation: bk-sparkle 0.7s ease-out both; }
.bk__oven.is-arriving { animation: bk-arrive 0.55s cubic-bezier(.2,.9,.3,1.15); }
@keyframes bk-says { from { transform: translateY(14px) scale(0.7); opacity: 0; } 25% { opacity: 1; } to { transform: translateY(-6px) scale(1); opacity: 1; } }
@keyframes bk-pop { 0% { transform: translateX(-50%) translateY(0) scale(1); } 40% { transform: translateX(-50%) translateY(-14%) scale(1.14); } 100% { transform: translateX(-50%) translateY(0) scale(1); } }
@keyframes bk-shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-4px); } 40% { transform: translateX(4px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(2px); } }
@keyframes bk-sparkle { from { opacity: 1; transform: scale(0.6); } to { opacity: 0; transform: scale(1.35); } }
@keyframes bk-arrive { from { opacity: 0; transform: translateX(70px) scale(0.6); } to { opacity: 1; transform: none; } }

.bk__start { position: absolute; left: 50%; bottom: 9px; z-index: 4; transform: translateX(-50%); min-width: 170px; font-size: 20px; }
.bk__start:active:not(:disabled) { transform: translateX(-50%) translateY(3px); }
.bk__start[hidden], .bk__end[hidden] { display: none; }
/* before Start (and on the end card) the ovens wait quietly */
.bk:not(.is-playing) .bk__oven { pointer-events: none; }

.bk__end { position: absolute; left: 8px; right: 8px; top: 30px; z-index: 6; }
.bk__end .tag { padding: 20px 20px 20px 56px; }
.bk__end-title { margin: 4px 0 2px; font-size: 24px; font-weight: 400; line-height: 1.15; }
.bk__end-new { margin: 0 0 10px; font-size: 26px; color: var(--red); min-height: 1em; }
.bk__end-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.bk__end-actions .btn { padding: 0 18px; min-height: 44px; font-size: 16px; }

@media (prefers-reduced-motion: reduce) {
  .bk__clock.is-low, .bk__tc.is-new, .bk__oven.is-pop .bk__cookie, .bk__oven.is-burnt.is-pop .bk__body,
  .bk__oven.is-perfect .bk__window::after, .bk__oven.is-arriving { animation: none; }
  .bk__oven.is-done .bk__says { animation: none; opacity: 1; }
}
