:root {
  --bg-top: #fff7e6;
  --bg-bottom: #f9dfb3;
  --card-bg: rgba(255, 252, 245, 0.94);
  --wood-dark: #5b361a;
  --wood-mid: #8c5529;
  --espresso: #331a0d;
  --espresso-soft: #633d25;
  --saigon-sun: #f59e0b;
  --saigon-amber: #d97706;
  --straw-green: #16a34a;
  --stool-blue: #1d6fa5;
  --danger: #dc2626;
  --border: rgba(91, 54, 26, 0.16);
  --shadow: 0 12px 30px rgba(72, 41, 16, 0.14);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--espresso);
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
  overscroll-behavior: none;
  user-select: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 960px;
  margin: 0 auto;
  padding: 8px 12px 10px;
  gap: 8px;
}

/* Header HUD */
.top-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 8px 12px;
  box-shadow: 0 4px 14px rgba(72, 41, 16, 0.08);
}

.top-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.home-link {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  color: var(--wood-dark);
  background: #fef1d8;
  border: 1px solid rgba(91, 54, 26, 0.2);
  border-radius: 10px;
  padding: 6px 10px;
  white-space: nowrap;
  touch-action: manipulation;
  transition: transform 0.12s ease, background 0.15s ease;
}

.home-link:hover {
  background: #fde5b8;
}

.home-link:active {
  transform: scale(0.96);
}

.title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}

.game-title {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--espresso);
}

.shift-badge {
  font-size: 11px;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 999px;
  background: #fef3c7;
  color: #92400e;
  border: 1px solid rgba(217, 119, 6, 0.28);
  white-space: nowrap;
}

.shift-badge.is-rush {
  background: #fee2e2;
  color: #b91c1c;
  border-color: rgba(220, 38, 38, 0.35);
  animation: pulseBadge 1.1s ease-in-out infinite;
}

@keyframes pulseBadge {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

.top-stats {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.stat-pill {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  background: #fff7e8;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px 9px;
  line-height: 1.15;
}

.stat-pill .stat-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--espresso-soft);
}

.stat-pill strong {
  font-size: 13px;
  font-weight: 800;
  color: var(--espresso);
}

.stat-revenue strong {
  color: #047857;
}

.stat-combo.is-hot {
  background: #fef3c7;
  border-color: #f59e0b;
}

.stat-combo.is-hot strong {
  color: #b45309;
}

.hearts-pill {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: #fff1f2;
  border: 1px solid rgba(220, 38, 38, 0.18);
  border-radius: 10px;
  padding: 5px 8px;
  font-size: 15px;
}

.heart {
  transition: transform 0.2s ease, opacity 0.2s ease, filter 0.2s ease;
}

.heart.is-lost {
  opacity: 0.25;
  filter: grayscale(1);
  transform: scale(0.84);
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff7e8;
  font-size: 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease, background 0.15s ease;
}

.icon-btn:hover {
  background: #fde8c3;
}

.icon-btn:active {
  transform: scale(0.94);
}

/* Rush hour alert banner */
.rush-banner {
  background: linear-gradient(90deg, #dc2626, #ea580c);
  color: #fff;
  text-align: center;
  font-size: 13px;
  font-weight: 800;
  padding: 6px 12px;
  border-radius: 12px;
  box-shadow: 0 6px 16px rgba(220, 38, 38, 0.28);
  animation: slideDown 0.25s ease-out;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Main Stage */
.stage-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 240px;
  border-radius: 20px;
  overflow: hidden;
  border: 2px solid rgba(91, 54, 26, 0.18);
  background: #ffe8ba;
  box-shadow: var(--shadow);
}

#cafeCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.toast-pill {
  position: absolute;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  z-index: 5;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
  color: #fff;
  background: rgba(51, 26, 13, 0.9);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
  white-space: nowrap;
  max-width: calc(100% - 24px);
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.toast-pill.is-good {
  background: linear-gradient(135deg, #15803d, #16a34a);
}

.toast-pill.is-bad {
  background: linear-gradient(135deg, #b91c1c, #dc2626);
}

.toast-pill.is-warn {
  background: linear-gradient(135deg, #b45309, #d97706);
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: rgba(34, 18, 8, 0.56);
  backdrop-filter: blur(4px);
}

.overlay[hidden] {
  display: none;
}

.modal-card {
  width: 100%;
  max-width: 470px;
  max-height: 100%;
  overflow-y: auto;
  background: #fffcf5;
  border: 2px solid rgba(140, 85, 41, 0.24);
  border-radius: 22px;
  padding: 18px 20px;
  box-shadow: 0 18px 44px rgba(30, 14, 4, 0.34);
  text-align: center;
}

.modal-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 999px;
  background: #fef3c7;
  color: #92400e;
  margin-bottom: 8px;
}

.modal-badge-dark {
  background: #fde68a;
  color: #78350f;
}

.modal-card h2 {
  margin: 0 0 8px;
  font-size: 21px;
  font-weight: 900;
  color: var(--espresso);
}

.modal-desc {
  margin: 0 0 12px;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--espresso-soft);
}

.tips-list {
  list-style: none;
  padding: 0;
  margin: 0 0 12px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tips-list li {
  font-size: 12.5px;
  line-height: 1.4;
  background: #fff6e5;
  border: 1px solid rgba(140, 85, 41, 0.14);
  border-radius: 10px;
  padding: 7px 10px;
}

.tips-list code {
  background: #fde6bd;
  padding: 1px 5px;
  border-radius: 5px;
  font-weight: 800;
  color: var(--wood-dark);
}

.record-row {
  display: flex;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--wood-dark);
  margin-bottom: 14px;
}

.rank-line {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 800;
  color: #b45309;
}

.over-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.over-stat {
  background: #fff6e5;
  border: 1px solid rgba(140, 85, 41, 0.16);
  border-radius: 12px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.over-stat span {
  font-size: 11px;
  font-weight: 700;
  color: var(--espresso-soft);
}

.over-stat strong {
  font-size: 16px;
  font-weight: 900;
  color: var(--espresso);
}

.over-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.primary-btn,
.secondary-btn {
  border: none;
  border-radius: 14px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 800;
  transition: transform 0.12s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.primary-btn {
  background: linear-gradient(135deg, #d97706, #b45309);
  color: #fff;
  box-shadow: 0 6px 16px rgba(180, 83, 9, 0.35);
  flex: 1 1 150px;
}

.primary-btn:hover {
  filter: brightness(1.06);
}

.primary-btn:active {
  transform: scale(0.97);
}

.secondary-btn {
  background: #f3e8d2;
  color: var(--espresso);
  border: 1px solid rgba(91, 54, 26, 0.24);
  flex: 1 1 150px;
}

.secondary-btn:hover {
  background: #ead9b7;
}

.secondary-btn:active {
  transform: scale(0.97);
}

/* Controls Panel */
.controls-panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 10px;
  box-shadow: 0 6px 18px rgba(72, 41, 16, 0.1);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ingredients-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 7px;
}

.ing-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 62px;
  padding: 6px 4px;
  border-radius: 14px;
  border: 2px solid rgba(91, 54, 26, 0.16);
  background: #fffaf0;
  color: var(--espresso);
  box-shadow: 0 3px 0 rgba(91, 54, 26, 0.14);
  transition: transform 0.1s ease, box-shadow 0.1s ease, border-color 0.15s ease, background 0.15s ease;
}

.ing-btn:hover {
  background: #fff2d8;
  border-color: rgba(180, 83, 9, 0.45);
}

.ing-btn:active,
.ing-btn.is-pressed {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(91, 54, 26, 0.14);
}

.ing-btn.is-added {
  background: #ecfdf5;
  border-color: #16a34a;
  box-shadow: 0 3px 0 rgba(22, 163, 74, 0.24);
}

.ing-btn.is-added::after {
  content: "✓";
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 11px;
  font-weight: 900;
  color: #15803d;
}

.key-cap {
  position: absolute;
  top: 4px;
  left: 6px;
  font-size: 10px;
  font-weight: 800;
  color: rgba(91, 54, 26, 0.55);
}

.ing-emoji {
  font-size: 22px;
  line-height: 1.1;
}

.ing-name {
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 8px;
}

.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  border-radius: 14px;
  border: none;
  font-size: 15px;
  font-weight: 800;
  transition: transform 0.1s ease, filter 0.15s ease;
}

.action-btn kbd {
  font-family: inherit;
  font-size: 11px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.24);
}

.btn-clear {
  background: #fee2e2;
  color: #991b1b;
  border: 2px solid rgba(220, 38, 38, 0.25);
}

.btn-clear kbd {
  background: rgba(185, 28, 28, 0.12);
}

.btn-clear:hover {
  background: #fecaca;
}

.btn-clear:active {
  transform: scale(0.97);
}

.btn-serve {
  background: linear-gradient(135deg, #16a34a, #15803d);
  color: #fff;
  box-shadow: 0 4px 14px rgba(21, 128, 61, 0.34);
}

.btn-serve:hover {
  filter: brightness(1.06);
}

.btn-serve:active {
  transform: scale(0.98);
}

/* Responsive adjustments */
@media (max-width: 720px) {
  .app-shell {
    padding: 6px 8px 8px;
    gap: 6px;
  }

  .top-bar {
    padding: 7px 9px;
    border-radius: 14px;
  }

  .game-title {
    font-size: 14px;
  }

  .home-link {
    font-size: 12px;
    padding: 5px 8px;
  }

  .stat-pill {
    padding: 2px 7px;
  }

  .stat-pill strong {
    font-size: 12px;
  }

  .hearts-pill {
    font-size: 13px;
    padding: 4px 6px;
  }

  .icon-btn {
    width: 32px;
    height: 32px;
    font-size: 15px;
  }

  .ingredients-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }

  .ing-btn {
    min-height: 54px;
  }

  .ing-emoji {
    font-size: 20px;
  }

  .ing-name {
    font-size: 11.5px;
  }

  .action-btn {
    min-height: 44px;
    font-size: 14px;
  }

  .action-btn kbd,
  .key-cap {
    display: none;
  }
}

@media (max-height: 670px) {
  .ing-btn {
    min-height: 46px;
  }

  .action-btn {
    min-height: 40px;
  }

  .modal-card {
    padding: 14px 16px;
  }

  .modal-card h2 {
    font-size: 18px;
  }
}
