html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0b0d12;
  color: #3a261e;
  font-family: "Trebuchet MS", "Nunito", "Segoe UI", system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

canvas#game {
  display: block;
  width: 100vw;
  height: 100vh;
}

/* Claymation Toybox UI System */
.clay-panel {
  background: #fff6e5;
  border: 4px solid #f0cfa0;
  border-radius: 22px;
  box-shadow:
    0 6px 0 #c79a6b,
    0 12px 24px rgba(15, 10, 28, 0.38),
    inset 0 3px 0 rgba(255, 255, 255, 0.85);
  color: #4a2d20;
}

.clay-btn {
  appearance: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.3px;
  padding: 10px 18px;
  border-radius: 16px;
  border: 3px solid #d9822b;
  background: #ffd66b;
  color: #4a2d20;
  box-shadow: 0 4px 0 #b86a1f, inset 0 2px 0 rgba(255, 255, 255, 0.7);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.clay-btn:hover {
  filter: brightness(1.04);
}

.clay-btn:active, .clay-btn.selected {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #b86a1f, inset 0 2px 0 rgba(255, 255, 255, 0.5);
}

.clay-btn.pink {
  background: #ff8fb1;
  border-color: #d95b84;
  box-shadow: 0 4px 0 #b34268, inset 0 2px 0 rgba(255, 255, 255, 0.65);
}

.clay-btn.mint {
  background: #8fe3c4;
  border-color: #4db38e;
  box-shadow: 0 4px 0 #348a6b, inset 0 2px 0 rgba(255, 255, 255, 0.65);
}

.clay-btn.sky {
  background: #7cc4ff;
  border-color: #4592d6;
  box-shadow: 0 4px 0 #2d6ea8, inset 0 2px 0 rgba(255, 255, 255, 0.65);
}

.clay-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* HUD Container */
#hud-root {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

/* Top-Left: Day, Clock, Coins */
#hud-top-left {
  position: fixed;
  top: 14px;
  left: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: auto;
}

.hud-stats-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
}

.hud-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 900;
  font-size: 16px;
}

.coin-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff2a6, #ffd66b 55%, #d99126);
  border: 2px solid #b86a1f;
  display: inline-block;
  box-shadow: 0 2px 0 #9e5614;
}

.day-badge {
  background: #ff8fb1;
  color: #4a1e2e;
  padding: 3px 10px;
  border-radius: 12px;
  border: 2px solid #d95b84;
  font-weight: 900;
  font-size: 13px;
}

.day-twist-tag {
  font-size: 12px;
  font-weight: 800;
  color: #7a4b3a;
  padding: 4px 12px;
  background: #ffe8b5;
  border: 3px solid #e6be7a;
  border-radius: 14px;
  box-shadow: 0 3px 0 #c29755;
  width: fit-content;
}

/* Top-Right: Current Order Card */
#hud-top-right {
  position: fixed;
  top: 14px;
  right: 14px;
  width: 280px;
  padding: 12px 14px;
  pointer-events: auto;
}

.order-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

/* CSS-drawn Clay Customer Portraits */
.portrait {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid #4a2d20;
  position: relative;
  flex-shrink: 0;
  box-shadow: inset -3px -4px 0 rgba(0, 0, 0, 0.12), 0 3px 0 rgba(0, 0, 0, 0.2);
}

.portrait::before, .portrait::after {
  content: "";
  position: absolute;
  top: 14px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #2b1a14;
}
.portrait::before { left: 11px; }
.portrait::after { right: 11px; }

.portrait .smile {
  position: absolute;
  bottom: 9px;
  left: 50%;
  width: 14px;
  height: 7px;
  transform: translateX(-50%);
  border-bottom: 3px solid #2b1a14;
  border-radius: 0 0 12px 12px;
}

.portrait .hat {
  position: absolute;
  top: -7px;
  left: 50%;
  transform: translateX(-50%);
  width: 22px;
  height: 10px;
  border-radius: 8px 8px 2px 2px;
  border: 2px solid #4a2d20;
}

.order-meta {
  flex: 1;
  min-width: 0;
}

.order-customer {
  font-weight: 900;
  font-size: 15px;
  line-height: 1.15;
}

.order-dome {
  font-size: 12px;
  font-weight: 700;
  color: #7a4b3a;
}

.order-items-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}

.pastry-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  background: #ffefd1;
  border: 2px solid #e6be7a;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 800;
  position: relative;
}

.pastry-icon {
  display: inline-block;
  font-size: 16px;
  transform-origin: center bottom;
  transition: transform 0.2s ease;
}

.pastry-chip.wobble .pastry-icon {
  animation: clayWobble 0.6s ease-in-out infinite;
}

.pastry-chip.sweating::after {
  content: "";
  position: absolute;
  top: -4px;
  right: 3px;
  width: 6px;
  height: 9px;
  background: #7cc4ff;
  border: 1.5px solid #2d6ea8;
  border-radius: 50% 50% 50% 50% / 70% 70% 35% 35%;
  animation: sweatDrop 0.9s ease-in infinite;
}

@keyframes clayWobble {
  0%, 100% { transform: rotate(-6deg) scaleY(var(--sq, 1)); }
  50% { transform: rotate(6deg) scaleY(var(--sq, 1)); }
}

@keyframes sweatDrop {
  0% { transform: translateY(0) scale(0.8); opacity: 1; }
  80% { transform: translateY(7px) scale(1.05); opacity: 0.9; }
  100% { transform: translateY(10px) scale(0.6); opacity: 0; }
}

.fresh-bar-wrap, .timer-bar-wrap {
  height: 11px;
  background: #e6d4be;
  border-radius: 99px;
  border: 2px solid #c29e74;
  overflow: hidden;
  margin-top: 5px;
}

.fresh-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #8fe3c4, #ffd66b);
  transition: width 0.15s ease;
}

.timer-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #7cc4ff, #ff8fb1);
  transition: width 0.15s linear;
}

.order-subrow {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 800;
  margin-top: 4px;
  color: #6b4634;
}

/* Bottom HUD: Jelly Thruster Gauge & Compass */
#hud-bottom {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
}

.fuel-tube-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.fuel-label {
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #7a4b3a;
}

.fuel-tube {
  width: 170px;
  height: 22px;
  border-radius: 99px;
  background: #ead9c5;
  border: 3px solid #c29769;
  box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.18);
  padding: 2px;
  overflow: hidden;
  position: relative;
}

.fuel-jelly {
  height: 100%;
  width: 100%;
  border-radius: 99px;
  background: linear-gradient(180deg, #a8f5db 0%, #58d4a7 60%, #39b386 100%);
  box-shadow: inset 0 3px 2px rgba(255, 255, 255, 0.65);
  transition: width 0.06s linear;
}

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

.compass-dial {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #ffe8b5;
  border: 3px solid #c79a6b;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15);
}

.compass-arrow {
  width: 0;
  height: 0;
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-bottom: 22px solid #ff6b4a;
  transform-origin: center 62%;
  filter: drop-shadow(0 2px 0 #a83920);
}

.compass-dist {
  font-weight: 900;
  font-size: 13px;
  color: #4a2d20;
  min-width: 52px;
}

/* Title Icing Overlay */
#title-overlay {
  position: fixed;
  top: 15%;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  pointer-events: none;
  z-index: 25;
  transition: opacity 0.6s ease, transform 0.6s ease;
}

#title-overlay.hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(-20px) scale(0.92);
}

.icing-title {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px;
  font-size: clamp(32px, 5.5vw, 58px);
  font-weight: 900;
  letter-spacing: 2px;
  color: #ffd66b;
  text-shadow:
    0 5px 0 #b85d19,
    0 8px 16px rgba(10, 6, 20, 0.55),
    -2px -2px 0 #fff7d6;
}

.icing-letter {
  display: inline-block;
  animation: icingBounce 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
}

@keyframes icingBounce {
  0% { transform: scale(0.1) translateY(24px); opacity: 0; }
  70% { transform: scale(1.18) translateY(-6px); opacity: 1; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.icing-subtitle {
  margin-top: 10px;
  display: inline-block;
  padding: 7px 18px;
  border-radius: 99px;
  background: rgba(255, 246, 229, 0.94);
  border: 3px solid #ff8fb1;
  color: #4a2d20;
  font-weight: 800;
  font-size: 14px;
  box-shadow: 0 4px 0 #c95d7f;
}

/* Non-blocking Continue / New Game Banner */
#save-banner {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
  z-index: 30;
  font-size: 13px;
  font-weight: 800;
}

#save-banner.hidden {
  display: none;
}

/* Pop-up Text (Butter Landing, Squish, +Coins) */
#popup-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 20;
}

.clay-popup {
  position: absolute;
  left: 50%;
  top: 34%;
  transform: translate(-50%, -50%);
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 1px;
  white-space: nowrap;
  text-shadow: 0 4px 0 rgba(58, 30, 18, 0.85), 0 8px 18px rgba(0, 0, 0, 0.4);
  animation: popupFloat 1.35s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes popupFloat {
  0% { transform: translate(-50%, -20%) scale(0.4); opacity: 0; }
  20% { transform: translate(-50%, -55%) scale(1.14); opacity: 1; }
  45% { transform: translate(-50%, -65%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -125%) scale(0.92); opacity: 0; }
}

/* Speech Bubbles */
#speech-bubble {
  position: fixed;
  max-width: 300px;
  padding: 10px 14px;
  z-index: 18;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

#speech-bubble.hidden {
  opacity: 0;
}

.speech-speaker {
  font-size: 12px;
  font-weight: 900;
  color: #c95d7f;
  margin-bottom: 2px;
}

.speech-text {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.3;
}

/* Prompt Hint at Bakery */
#action-hint {
  position: fixed;
  bottom: 92px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 900;
  pointer-events: auto;
  z-index: 19;
}

#action-hint.hidden {
  display: none;
}

/* Modals (Order Board, Garage, Summary, Pause) */
#modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(14, 12, 26, 0.56);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  pointer-events: auto;
}

#modal-backdrop.hidden {
  display: none;
}

.modal-card {
  width: min(640px, 92vw);
  max-height: 86vh;
  overflow-y: auto;
  padding: 22px 24px;
}

.modal-title {
  margin: 0 0 6px 0;
  font-size: 24px;
  font-weight: 900;
  color: #4a2d20;
}

.modal-sub {
  margin: 0 0 14px 0;
  font-size: 14px;
  font-weight: 700;
  color: #7a4b3a;
}

.order-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 12px;
  margin: 12px 0 16px 0;
}

.order-option {
  padding: 12px;
  border-radius: 18px;
  border: 3px solid #e6be7a;
  background: #ffefd1;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.1s ease;
}

.order-option.selected {
  border-color: #ff6b4a;
  background: #fff9ec;
  transform: translateY(-3px);
  box-shadow: 0 5px 0 #d95b40;
}

.upgrade-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 12px 0 16px 0;
}

.upgrade-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 16px;
  border: 3px solid #e6be7a;
  background: #ffefd1;
}

.upgrade-row.selected {
  border-color: #ff6b4a;
  background: #fff9ec;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
}

.star-row {
  font-size: 24px;
  letter-spacing: 4px;
  color: #f5a623;
}
