:root {
  --ink: #5c3044;
  --berry: #c73b6b;
  --berry-deep: #9d2454;
  --cream: #fff8f3;
  --shadow: 0 14px 34px rgba(90, 30, 55, 0.18);
  --font: "Nunito", "Trebuchet MS", "Arial Rounded MT Bold", sans-serif;
  --display: "Fredoka", "Trebuchet MS", "Arial Rounded MT Bold", sans-serif;
  /* cake width & tray piece size scale with the screen */
  --cw: clamp(130px, min(28vw, 30vh), 280px);
  --pw: clamp(78px, 8.6vw, 124px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  color: var(--ink);
  font-family: var(--font);
  background: #f7c9d8;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

.bg {
  position: fixed;
  inset: 0;
  background: linear-gradient(180deg, rgba(255, 244, 248, 0.2), rgba(255, 228, 238, 0.45)), url("assets/bakery-bg.jpg") center / cover no-repeat;
}

#app {
  position: relative;
  z-index: 1;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(8px + env(safe-area-inset-top)) 14px 4px;
}

.topbar h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(1.25rem, 3vw, 2.3rem);
  color: #fff;
  text-shadow: 0 3px 0 #e07aa0, 0 8px 18px rgba(120, 30, 60, 0.28);
  white-space: nowrap;
}

.hud { display: flex; align-items: center; gap: 10px; }

.score {
  background: rgba(255, 255, 255, 0.92);
  border-radius: 999px;
  padding: 4px 14px;
  display: flex;
  align-items: baseline;
  gap: 6px;
  box-shadow: 0 4px 0 #f0b6cb;
}
.score span { font-size: 0.85rem; font-weight: 800; color: #a14a68; }
.score strong { font-family: var(--display); font-size: 1.5rem; color: var(--berry-deep); min-width: 2ch; text-align: right; }

.lives { display: flex; gap: 2px; background: rgba(255, 255, 255, 0.92); border-radius: 999px; padding: 4px 10px; box-shadow: 0 4px 0 #f0b6cb; }
.lives i { font-style: normal; font-size: 1.45rem; line-height: 1.2; transition: transform 0.3s; }
.lives i.lost { filter: grayscale(1); opacity: 0.35; transform: scale(0.8); }
.lives i.lost-now { animation: lose 0.6s ease; }

.icon-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 3px solid #fff;
  background: linear-gradient(180deg, #fff, #ffe0ec);
  box-shadow: 0 5px 0 #f3b4ca;
  font-size: 1.5rem;
  line-height: 1;
  padding: 0;
}

/* ---------- stage ---------- */

.stage {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr) minmax(0, 1fr);
  grid-template-areas: "harley cake gg";
  gap: 8px;
  padding: 4px 12px calc(6px + env(safe-area-inset-bottom));
}

.chef-harley { grid-area: harley; }
.chef-gg { grid-area: gg; }
.cake-zone { grid-area: cake; }

.chef {
  position: relative;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.tray {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  padding: 10px;
  background: rgba(255, 250, 247, 0.88);
  border: 3px solid #fff;
  border-radius: 26px;
  box-shadow: var(--shadow);
  position: relative;
  z-index: 3;
}

.piece {
  width: var(--pw);
  min-height: var(--pw);
  border-radius: 20px;
  border: 4px solid var(--pc, #f3c6d6);
  background: #fff;
  box-shadow: 0 6px 0 var(--pc, #f3c6d6);
  padding: 6px 4px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: transform 0.12s;
}
.piece svg { width: 92%; height: auto; display: block; pointer-events: none; }
.piece .lbl { font-family: var(--display); font-weight: 650; font-size: clamp(0.78rem, 1.1vw, 1rem); line-height: 1.1; pointer-events: none; }
.piece:hover { transform: translateY(-3px); }
.piece:active { transform: translateY(3px); box-shadow: 0 3px 0 var(--pc); }
.piece:focus-visible { outline: 4px solid var(--berry); outline-offset: 2px; }
.piece.hint { animation: hint 0.7s ease-in-out 3; }
.piece.flash-wrong { animation: wrongShake 0.4s ease; }

.chef-body {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  margin-top: 6px;
}
.chef-body img, .chef-body svg {
  height: 100%;
  max-width: 100%;
  object-fit: contain;
  object-position: bottom;
  filter: drop-shadow(0 14px 12px rgba(120, 40, 70, 0.28));
  transform-origin: 50% 100%;
  animation: bob 3.4s ease-in-out infinite;
}
.chef-gg .chef-body svg { animation-delay: -1.7s; }

.chef.throw .chef-body img, .chef.throw .chef-body svg { animation: toss 0.45s ease; }
.chef.cheer .chef-body img, .chef.cheer .chef-body svg { animation: hop 0.5s ease 2; }
.chef.oops .chef-body img, .chef.oops .chef-body svg { animation: wrongShake 0.45s ease; }

.gg-arm { transform-box: view-box; transform-origin: 214px 266px; transition: transform 0.18s ease; }
.chef-gg.throw .gg-arm, .chef-gg.cheer .gg-arm { transform: rotate(-150deg); }

.name-tag {
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  background: #fff;
  color: var(--berry-deep);
  border-radius: 999px;
  padding: 3px 14px;
  font-family: var(--display);
  font-size: 1rem;
  box-shadow: 0 3px 0 #f0b6cb;
  white-space: nowrap;
  z-index: 2;
}
.gg-tag { color: #6b4aa8; box-shadow: 0 3px 0 #d9c8f2; }

/* ---------- cake zone ---------- */

.cake-zone {
  position: relative;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.ticket {
  position: absolute;
  top: 4px;
  left: 4px;
  z-index: 4;
  width: clamp(90px, 11vw, 150px);
  background: #fffdf2;
  border: 3px dashed #e6b9cc;
  border-radius: 16px;
  padding: 6px 6px 8px;
  text-align: center;
  transform: rotate(-3deg);
  box-shadow: 0 8px 18px rgba(90, 30, 55, 0.16);
}
.ticket-title { display: block; font-family: var(--display); font-size: 1rem; color: var(--berry-deep); margin-bottom: 4px; }
.ticket-stack { display: flex; flex-direction: column; align-items: center; }
.t-item { position: relative; width: 100%; display: flex; justify-content: center; }
.t-item svg { width: 86%; height: auto; display: block; }
.t-item + .t-item { margin-top: -5%; }
.t-item.done { opacity: 0.35; }
.t-item.done::after {
  content: "✓";
  position: absolute;
  right: -2px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #4fbf85;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 800;
  display: grid;
  place-items: center;
}
.t-item.next { z-index: 2; }
.t-item.next svg { filter: drop-shadow(0 0 4px #ff4f8b) drop-shadow(0 0 8px #ffd23f); animation: nextPulse 1s ease-in-out infinite; }
.t-item.next::before {
  content: "▶";
  position: absolute;
  left: -14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--berry);
  font-size: 0.9rem;
}

.cake-area {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding-bottom: 6px;
  position: relative;
}

.wobble {
  width: var(--cw);
  transform-origin: 50% 100%;
  position: relative;
  z-index: 2;
}
.wobble.hit { animation: hit 0.7s ease; }
.wobble.hit-big { animation: hitBig 0.9s ease; }
.wobble.serve { animation: serve 0.65s ease-in forwards; }

.stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  transform-origin: 50% 100%;
  animation: sway var(--sway-time, 3s) ease-in-out infinite;
}

.part { width: 100%; position: relative; }
.part svg { display: block; width: 100%; height: auto; }
.part.k-layer { margin-bottom: calc(var(--cw) * -0.18); }
.part.k-frosting { margin-bottom: calc(var(--cw) * -0.26); }
.part.k-candle { margin-bottom: calc(var(--cw) * -0.08); }
.stack > .part:last-child { margin-bottom: calc(var(--cw) * -0.07); }
.part.drop-in { animation: dropIn 0.32s ease-out; }

.stand {
  width: calc(var(--cw) * 1.3);
  height: auto;
  display: block;
  position: relative;
  z-index: 1;
  filter: drop-shadow(0 10px 10px rgba(110, 40, 70, 0.18));
}

.flame { transform-box: fill-box; transform-origin: 50% 100%; animation: flicker 0.35s ease-in-out infinite alternate; }

.toast {
  position: absolute;
  top: 8%;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  z-index: 5;
  background: #fff;
  border-radius: 999px;
  padding: 8px 18px;
  font-family: var(--display);
  font-size: clamp(1.1rem, 2.4vw, 1.6rem);
  color: var(--berry-deep);
  box-shadow: var(--shadow);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
}
.toast.show { animation: toast 1.4s ease forwards; }
.toast.bad { color: #b3263f; background: #fff1f1; }

/* ---------- flying pieces & effects ---------- */

.fly {
  position: fixed;
  z-index: 40;
  pointer-events: none;
  transform-origin: 50% 50%;
}
.fly svg { display: block; width: 100%; height: auto; }

#fx { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 45; }
#fx i { position: absolute; top: -20px; width: 12px; height: 18px; border-radius: 3px; animation: fall linear forwards; }
#fx i.round { border-radius: 50%; width: 13px; height: 13px; }

.pop-text {
  position: fixed;
  z-index: 46;
  font-family: var(--display);
  font-size: 1.6rem;
  color: #2f9a63;
  text-shadow: 0 2px 0 #fff, 0 0 10px #fff;
  pointer-events: none;
  animation: floatUp 0.9s ease forwards;
  transform: translate(-50%, -50%);
}
.pop-text.bad { color: #d12d4a; font-size: 2.6rem; }

/* ---------- overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(80, 30, 50, 0.4);
  display: grid;
  place-items: center;
  padding: 16px;
}

.card {
  width: min(460px, 100%);
  max-height: 100%;
  overflow: auto;
  background: var(--cream);
  border: 4px solid #fff;
  border-radius: 30px;
  padding: 18px 20px 22px;
  text-align: center;
  box-shadow: var(--shadow);
  animation: popIn 0.35s ease;
}
.card h2 { font-family: var(--display); font-size: 2.1rem; margin: 4px 0 8px; color: var(--berry-deep); }
.card p { font-size: 1.12rem; font-weight: 700; line-height: 1.4; margin: 6px 0; }
.card .small { font-size: 0.98rem; color: #a14a68; }
.card .stats { font-size: 1.3rem; }
.card-faces { display: flex; justify-content: center; align-items: flex-end; gap: 6px; height: clamp(90px, 20vh, 150px); }
.card-faces img { height: 100%; width: auto; }
.card-faces .card-gg { height: 70%; }

.big-btn {
  margin-top: 12px;
  min-width: 200px;
  min-height: 70px;
  padding: 12px 28px;
  border: none;
  border-radius: 999px;
  font-family: var(--display);
  font-size: 1.6rem;
  font-weight: 650;
  color: #fff;
  background: linear-gradient(180deg, #ff9cbe, #e25084);
  box-shadow: 0 8px 0 var(--berry-deep), 0 14px 20px rgba(160, 30, 70, 0.2);
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 4px 0 var(--berry-deep); }

/* ---------- animations ---------- */

@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes toss { 0% { transform: none; } 35% { transform: translateY(-14px) rotate(-4deg) scale(1.03); } 100% { transform: none; } }
@keyframes hop { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-18px); } }
@keyframes wrongShake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-8px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(4px); } }
@keyframes hint { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.1); box-shadow: 0 0 0 6px #ffd23f, 0 6px 0 var(--pc); } }
@keyframes nextPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }
@keyframes sway { 0%, 100% { transform: rotate(calc(var(--sway, 0.4deg) * -1)); } 50% { transform: rotate(var(--sway, 0.4deg)); } }
@keyframes hit { 0% { transform: none; } 20% { transform: rotate(2.6deg) scaleY(0.97); } 45% { transform: rotate(-2deg); } 70% { transform: rotate(1deg); } 100% { transform: none; } }
@keyframes hitBig { 0% { transform: none; } 15% { transform: rotate(-5deg) translateX(-6px); } 35% { transform: rotate(4.5deg) translateX(5px); } 55% { transform: rotate(-3deg); } 75% { transform: rotate(1.5deg); } 100% { transform: none; } }
@keyframes serve { to { transform: translateY(-30px) scale(0.6); opacity: 0; } }
@keyframes dropIn { 0% { transform: translateY(-18px) scaleY(1.08); } 60% { transform: translateY(2px) scaleY(0.9); } 100% { transform: none; } }
@keyframes flicker { from { transform: scale(1, 1) rotate(-3deg); } to { transform: scale(0.92, 1.1) rotate(3deg); } }
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, 10px) scale(0.9); } 15% { opacity: 1; transform: translate(-50%, 0) scale(1.05); } 75% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; transform: translate(-50%, -10px); } }
@keyframes lose { 0% { transform: scale(1.6); } 100% { transform: scale(0.8); } }
@keyframes fall { to { transform: translateY(105vh) rotate(540deg); } }
@keyframes floatUp { 0% { opacity: 0; transform: translate(-50%, -30%) scale(0.7); } 20% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); } 100% { opacity: 0; transform: translate(-50%, -160%); } }
@keyframes popIn { from { transform: scale(0.9); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- phones held upright ---------- */

@media (orientation: portrait) and (max-width: 900px) {
  :root {
    --cw: clamp(120px, min(40vw, 25vh), 230px);
    --pw: clamp(66px, calc(25vw - 24px), 118px);
  }
  .stage {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas: "cake cake" "harley gg";
    gap: 6px;
    padding-left: 8px;
    padding-right: 8px;
  }
  .chef { height: auto; }
  .tray { gap: 8px; padding: 8px; border-radius: 22px; }
  .chef-body { flex: none; height: clamp(225px, 37vh, 480px); margin-top: 2px; }
  .name-tag { font-size: 0.85rem; padding: 2px 10px; }
  .topbar h1 { font-size: clamp(1.05rem, 5vw, 1.6rem); }
  .ticket { width: clamp(76px, 20vw, 110px); }
}

@media (max-width: 420px) {
  .icon-btn { width: 44px; height: 44px; font-size: 1.25rem; }
  .lives i { font-size: 1.15rem; }
  .score strong { font-size: 1.2rem; }
  .score span { display: none; }
}

/* short landscape phones */
@media (orientation: landscape) and (max-height: 500px) {
  :root { --cw: clamp(110px, 26vh, 180px); --pw: clamp(64px, 7.6vw, 90px); }
  .topbar { padding-top: 4px; }
  .topbar h1 { font-size: 1.2rem; }
  .icon-btn { width: 42px; height: 42px; font-size: 1.2rem; }
  .tray { gap: 6px; padding: 6px; }
  .piece { padding: 3px; }
  .ticket { width: 76px; }
}

@media (prefers-reduced-motion: reduce) {
  .chef-body img, .chef-body svg, .stack, .flame, .t-item.next svg { animation: none !important; }
}

/* Harley's throwing / cheering arm */
.chef-harley .chef-body svg { overflow: visible; }
.harley-arm { transform-box: view-box; transform-origin: 200px 268px; transition: transform 0.18s ease; }
.chef-harley.throw .harley-arm, .chef-harley.cheer .harley-arm { transform: rotate(-125deg); }
.topbar h1 .and { display: block; font-size: 0.62em; line-height: 1; }
