@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@600;700;800&display=swap');

:root {
  --bg: #fff5eb;
  --primary: #ff6b35;
  --primary-dark: #e85d04;
  --accent: #2ec4b6;
  --success: #06d6a0;
  --danger: #ef476f;
  --ink: #1a1a2e;
  --muted: #6b7280;
  --shadow: 0 8px 32px rgba(255, 107, 53, 0.15);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  background: linear-gradient(160deg, #fff5eb 0%, #ffe8d6 100%);
  font-family: 'Nunito', system-ui, sans-serif;
  color: var(--ink);
  overflow: hidden;
  overscroll-behavior: none;
}
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  background: white;
  position: relative;
  overflow: hidden;
}

header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: linear-gradient(90deg, #ff6b35, #f7931e);
  color: white;
  font-weight: 800;
  box-shadow: 0 4px 12px rgba(255,107,53,0.3);
  z-index: 5;
  flex-shrink: 0;
  min-height: 56px;
}
.home { color: white; text-decoration: none; font-size: 1.6rem; padding: 4px; }
.brand { flex: 1; font-size: 1.1rem; letter-spacing: -0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meters { display: flex; gap: 8px; font-size: 0.85rem; flex-wrap: wrap; }
.meter { display: flex; align-items: center; gap: 3px; background: rgba(255,255,255,0.2); padding: 3px 7px; border-radius: 20px; }
#soundBtn { background: none; border: none; font-size: 1.4rem; cursor: pointer; padding: 8px; }

#gameArea { flex: 1; position: relative; background: #fffaf5; overflow: hidden; min-height: 0; }
#canvas { width: 100%; height: 100%; display: block; touch-action: none; }

#uiOverlay { position: absolute; inset: 0; pointer-events: none; }
.speech {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-width: 92%;
}
.bubble-inner {
  background: white;
  border: 4px solid #ff6b35;
  border-radius: 20px;
  padding: 12px 16px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.15);
  text-align: center;
  font-weight: 800;
  font-size: 1.05rem;
  position: relative;
}
.bubble-inner::after {
  content: "";
  position: absolute;
  bottom: -12px;
  left: 50%;
  transform: translateX(-50%);
  border: 10px solid transparent;
  border-top-color: #ff6b35;
}
#orderVisual { margin-top: 6px; display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; }
.mini-pie {
  width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid #c0392b;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

#patienceBar {
  position: absolute;
  bottom: 12px;
  left: 16px;
  right: 16px;
  height: 12px;
  background: rgba(255,255,255,0.7);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
  z-index: 3;
}
#patienceFill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #06d6a0, #ffd166, #ef476f);
  border-radius: 12px;
  transition: width 0.15s;
}

#feedback {
  position: absolute;
  top: 45%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255,255,255,0.97);
  padding: 16px 24px;
  border-radius: 16px;
  font-weight: 800;
  font-size: 1.3rem;
  text-align: center;
  box-shadow: 0 16px 40px rgba(0,0,0,0.2);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 6;
  max-width: 80%;
}
#feedback.show { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }

.customer {
  position: absolute;
  top: 50px;
  left: 50%;
  transform: translateX(-50%);
  width: 80px;
  height: 80px;
  background: url('assets/customer.jpg') center/cover;
  border-radius: 50%;
  border: 4px solid white;
  box-shadow: 0 6px 16px rgba(0,0,0,0.2);
  z-index: 2;
  animation: bounce 2s ease-in-out infinite;
}

#controls {
  padding: 10px 10px 12px;
  background: linear-gradient(180deg, #fffaf5, #fff5eb);
  border-top: 3px solid #ffe0cc;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
.tray { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.topping-btn {
  width: 56px; height: 56px; border-radius: 50%;
  border: 4px solid transparent;
  font-size: 1.8rem;
  cursor: pointer;
  background: white;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  transition: all 0.15s;
  touch-action: manipulation;
}
.tools button {
  min-width: 48px; min-height: 48px;
  border-radius: 12px;
  border: 3px solid #ffe0cc;
  background: white;
  font-weight: 800;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.15s;
  touch-action: manipulation;
}
.topping-btn.selected {
  border-color: var(--primary);
  transform: scale(1.1);
  box-shadow: 0 6px 16px rgba(255,107,53,0.35);
}
.topping-btn:active { transform: scale(0.95); }

.tools { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.tools button {
  min-width: 44px; min-height: 44px;
  border-radius: 10px;
  border: 3px solid #ffe0cc;
  background: white;
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.15s;
  touch-action: manipulation;
}
.tools button.selected {
  background: var(--primary);
  color: white;
  border-color: var(--primary-dark);
  transform: scale(1.05);
}

.actions { display: flex; gap: 8px; }
.actions button, .panel button {
  flex: 1;
  min-height: 48px;
  border-radius: 12px;
  border: none;
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
  touch-action: manipulation;
}
.panel button {
  margin: 6px 4px;
  min-width: 120px;
  display: inline-block;
}
.actions button:active, .panel button:active { transform: scale(0.97); }
#clearBtn { background: #f1f5f9; color: var(--ink); }
#serveBtn, .primary { background: linear-gradient(135deg, #ff6b35, #f7931e); color: white; box-shadow: 0 4px 14px rgba(255,107,53,0.4); }
.secondary { background: #e2e8f0; color: var(--ink); }
.big { font-size: 1.2rem; padding: 14px 20px; min-width: 180px; }

#result[style*="display: none"],
#result[hidden],
.overlay[hidden] { display: none !important; }
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(26, 26, 46, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
}
.panel {
  background: white;
  border-radius: 24px;
  padding: 24px 20px;
  max-width: 400px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  margin: auto;
}
.logo { font-size: 3rem; margin-bottom: 6px; }
.panel h1, .panel h2 { margin: 0 0 10px; color: var(--primary); font-size: 1.5rem; }
.panel p { color: var(--muted); margin: 0 0 14px; line-height: 1.45; font-size: 0.95rem; }
.stats { margin: 14px 0; display: flex; justify-content: center; gap: 16px; font-weight: 700; font-size: 0.95rem; }
.stars-big { font-size: 2.2rem; margin: 10px 0; letter-spacing: 3px; }

@keyframes popIn {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes bounce {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-6px); }
}

/* Desktop enhancements */
@media (min-width: 768px) {
  #app {
    max-width: 900px;
    margin: 20px auto;
    height: calc(100dvh - 40px);
    border-radius: 20px;
    box-shadow: 0 10px 50px rgba(0,0,0,0.15);
  }
  .brand { font-size: 1.3rem; }
  .topping-btn { width: 60px; height: 60px; font-size: 2rem; }
  .tools button { min-width: 52px; min-height: 48px; font-size: 1.1rem; }
  .panel { max-width: 480px; padding: 32px 28px; }
}

@media (max-width: 480px) {
  .meters { gap: 4px; font-size: 0.75rem; }
  .brand { font-size: 0.95rem; }
  .topping-btn { width: 46px; height: 46px; font-size: 1.5rem; }
  .tools button { min-width: 40px; min-height: 40px; font-size: 0.95rem; }
  .customer { width: 60px; height: 60px; top: 50px; }
}
