/* styles.css — 全部外觀。舞台固定 960×540，由 JS 等比縮放。 */

:root {
  --wood-dark: #33200f;
  --wood: #57391f;
  --wood-light: #7a5230;
  --gold: #e8c07a;
  --cream: #f6ead2;
  --danger: #d2564b;
  --ok: #8fce9b;
  --ink: #1a1109;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0b0704;
  font-family: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
  color: var(--cream);
  -webkit-font-smoothing: antialiased;
}

#viewport {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
}

#stage {
  position: relative;
  width: 960px;
  height: 540px;
  overflow: hidden;
  border-radius: 20px;
  background: #150d07;
  box-shadow: 0 40px 90px rgba(0, 0, 0, 0.85), 0 0 0 1px rgba(232, 192, 122, 0.08);
  transform-origin: center center;
  user-select: none;
  cursor: default;
}

/* ---------- 場景 ---------- */

#floor {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 42%, rgba(255, 199, 120, 0.16), transparent 58%),
    radial-gradient(ellipse at 12% 92%, rgba(255, 160, 80, 0.08), transparent 45%),
    repeating-linear-gradient(90deg, #241811 0 44px, #2b1d15 44px 88px);
}

#counter {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 76px;
  background: linear-gradient(#5b3c22, #3a2416);
  border-bottom: 4px solid #241407;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.55);
  z-index: 2;
}

#pass-label {
  position: absolute;
  left: 50%;
  bottom: -22px;
  transform: translateX(-50%);
  padding: 2px 16px;
  border-radius: 0 0 12px 12px;
  background: #241407;
  border: 2px solid #6b4428;
  border-top: none;
  color: var(--gold);
  font-size: 12px;
  letter-spacing: 3px;
}

#door {
  position: absolute;
  left: 10px;
  bottom: 10px;
  width: 58px;
  height: 78px;
  display: grid;
  place-items: center;
  border-radius: 10px 10px 0 0;
  background: linear-gradient(180deg, #6b4428, #402a18);
  border: 2px solid #241407;
  color: rgba(246, 234, 210, 0.5);
  font-size: 11px;
  letter-spacing: 3px;
  z-index: 1;
}

.layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
}

#dish-layer { z-index: 4; }
#customer-layer { z-index: 5; }
#staff-layer { z-index: 6; }

/* ---------- 桌子 ---------- */

.table {
  position: absolute;
  left: 0;
  top: 0;
  border-radius: 16px;
  background: linear-gradient(160deg, var(--wood-light), var(--wood) 55%, var(--wood-dark));
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.14),
    inset 0 -6px 12px rgba(0, 0, 0, 0.35),
    0 10px 22px rgba(0, 0, 0, 0.45);
  transition: filter 0.2s ease;
}

.table::before {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: 11px;
  background: rgba(0, 0, 0, 0.18);
}

.table.dirty { filter: saturate(0.55) brightness(0.86); }

.table.dirty::before {
  background:
    radial-gradient(circle at 34% 42%, rgba(120, 90, 40, 0.55) 0 10px, transparent 11px),
    radial-gradient(circle at 63% 58%, rgba(120, 90, 40, 0.4) 0 8px, transparent 9px),
    rgba(0, 0, 0, 0.22);
}

.table-bubble {
  position: absolute;
  left: 50%;
  top: -30px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 14px;
  background: rgba(246, 234, 210, 0.94);
  color: #2a1a08;
  font-size: 15px;
  line-height: 1;
  pointer-events: auto;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.45);
  animation: bob 1.6s ease-in-out infinite;
  white-space: nowrap;
}

.table-bubble .tag {
  font-size: 11px;
  letter-spacing: 1px;
  font-weight: 700;
}

/* ---------- 客人 ---------- */

.customer {
  position: absolute;
  left: 0;
  top: 0;
  width: 44px;
  height: 44px;
  pointer-events: none;
}

.customer .avatar {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  font-size: 25px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #3b2a1c, #241609);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
  transition: transform 0.15s ease;
}

.customer.angry .avatar { animation: shake 0.35s linear infinite; }
.customer.eating .avatar { transform: scale(1.06); }

.customer .bubble {
  position: absolute;
  left: 50%;
  bottom: 100%;
  margin-bottom: 8px;
  transform: translateX(-50%);
  min-width: 54px;
  padding: 5px 8px 4px;
  border-radius: 14px;
  background: rgba(246, 234, 210, 0.95);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  pointer-events: none;
}

.customer .bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: rgba(246, 234, 210, 0.95);
}

.customer .bubble .dish {
  font-size: 20px;
  line-height: 1;
}

.customer .bubble.cooking .dish { opacity: 0.35; filter: grayscale(0.6); }
.customer .bubble.bill .dish { font-size: 19px; }

.customer .bubble.ready {
  pointer-events: auto;
  cursor: pointer;
  animation: bob 1.3s ease-in-out infinite;
  box-shadow: 0 0 0 2px rgba(232, 192, 122, 0.65), 0 6px 16px rgba(0, 0, 0, 0.5);
}

.customer .bubble.bill {
  pointer-events: auto;
  cursor: pointer;
  box-shadow: 0 0 0 2px rgba(143, 206, 155, 0.7), 0 6px 16px rgba(0, 0, 0, 0.5);
}

.customer .bar {
  display: block;
  width: 46px;
  height: 4px;
  border-radius: 3px;
  background: rgba(42, 26, 8, 0.22);
  overflow: hidden;
}

.customer .bar > i {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, #7fbf7f, #e8c07a);
  transition: width 0.08s linear;
}

.customer.urgent .bar > i { background: linear-gradient(90deg, #d2564b, #f0913f); }
.customer.urgent .bubble { animation-duration: 0.55s; }

.customer .dbg {
  display: none;
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translateX(-50%);
  margin-top: 2px;
  font-size: 9px;
  letter-spacing: 0.5px;
  color: #ffd9a0;
  white-space: nowrap;
  text-shadow: 0 1px 2px #000;
}

#stage.debug .customer .dbg { display: block; }

/* ---------- 員工 ---------- */

.staff {
  position: absolute;
  left: 0;
  top: 0;
  width: 46px;
  height: 46px;
  pointer-events: auto;
  cursor: pointer;
}

.staff .avatar {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  font-size: 24px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 30%, #3b2a1c, #1d1209);
  box-shadow: 0 0 0 2px var(--tint, #7fb0e8), 0 6px 14px rgba(0, 0, 0, 0.55);
}

.staff.idle { cursor: default; }
.staff.working .avatar { animation: bobY 0.6s ease-in-out infinite; }

.staff .name {
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translateX(-50%);
  margin-top: 1px;
  font-size: 10px;
  letter-spacing: 1px;
  color: rgba(246, 234, 210, 0.72);
  white-space: nowrap;
  text-shadow: 0 1px 3px #000;
}

.staff .badge {
  position: absolute;
  right: -4px;
  top: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 4px;
  border-radius: 10px;
  background: rgba(246, 234, 210, 0.95);
  color: #2a1a08;
  font-size: 12px;
  line-height: 20px;
  text-align: center;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.45);
}

/* ---------- 出餐口的菜 ---------- */

.dish {
  position: absolute;
  left: 0;
  top: 0;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: rgba(246, 234, 210, 0.92);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5), 0 0 0 2px rgba(232, 192, 122, 0.55);
}

.dish .dish-face {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  font-size: 19px;
  border-radius: 9px;
  animation: bobY 1.8s ease-in-out infinite;
}

/* ---------- HUD ---------- */

#hud {
  position: absolute;
  top: 12px;
  left: 16px;
  right: 16px;
  display: flex;
  gap: 10px;
  z-index: 10;
  pointer-events: none;
}

.hud-chip {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 12px;
  background: rgba(20, 12, 6, 0.72);
  border: 1px solid rgba(232, 192, 122, 0.22);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 1px;
  backdrop-filter: blur(4px);
}

.hud-chip .hud-label {
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 2px;
  color: rgba(246, 234, 210, 0.55);
}

.hud-chip.danger { color: #f0a79f; margin-left: auto; }
.hud-chip .hud-cap { font-size: 12px; opacity: 0.55; }

#hud-time-chip.lastcall {
  border-color: rgba(210, 86, 75, 0.8);
  color: #ff9d92;
  animation: pulse 0.9s ease-in-out infinite;
}

#toast {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(6px);
  padding: 8px 18px;
  border-radius: 999px;
  background: rgba(20, 12, 6, 0.86);
  border: 1px solid rgba(232, 192, 122, 0.25);
  font-size: 14px;
  letter-spacing: 1px;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  z-index: 12;
  white-space: nowrap;
}

#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 覆蓋層 ---------- */

#overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(10, 6, 3, 0.82);
  backdrop-filter: blur(3px);
  z-index: 20;
  transition: opacity 0.25s ease;
}

#overlay.hidden { opacity: 0; pointer-events: none; }

.panel {
  width: 520px;
  padding: 34px 40px 30px;
  border-radius: 20px;
  background: linear-gradient(160deg, #2a1a0f, #1a1008);
  border: 1px solid rgba(232, 192, 122, 0.25);
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.7);
  text-align: center;
}

.panel.hidden { display: none; }

.panel h1 {
  margin: 0 0 6px;
  font-size: 34px;
  letter-spacing: 6px;
  color: var(--gold);
}

.panel .subtitle {
  margin: 0 0 20px;
  font-size: 14px;
  color: rgba(246, 234, 210, 0.62);
  letter-spacing: 1px;
}

.panel .rules {
  margin: 0 0 24px;
  padding: 0;
  list-style: none;
  text-align: left;
  font-size: 14px;
  line-height: 1.9;
  color: rgba(246, 234, 210, 0.85);
}

.panel .rules li { padding-left: 18px; position: relative; }
.panel .rules li::before {
  content: "•";
  position: absolute;
  left: 2px;
  color: var(--gold);
}

.panel button {
  padding: 12px 42px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(180deg, #f0cf93, #d8a862);
  color: #2a1a08;
  font-family: inherit;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 3px;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(216, 168, 98, 0.28);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.panel button:hover { transform: translateY(-2px); box-shadow: 0 14px 28px rgba(216, 168, 98, 0.36); }
.panel button:active { transform: translateY(0); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px 14px;
  margin-bottom: 16px;
  text-align: left;
}

.stats-grid > div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.035);
}

.stats-grid .wide { grid-column: 1 / -1; background: rgba(232, 192, 122, 0.1); }
.stats-grid .stat-label { font-size: 12px; color: rgba(246, 234, 210, 0.6); letter-spacing: 1px; }
.stats-grid .stat-value { font-size: 19px; font-weight: 700; color: var(--cream); }
.stats-grid .stat-value.big { font-size: 26px; color: var(--gold); }

.panel .best {
  margin: 0 0 20px;
  font-size: 13px;
  color: var(--gold);
  letter-spacing: 1px;
  min-height: 18px;
}

/* ---------- 動畫 ---------- */

@keyframes bob {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-3px); }
}

@keyframes bobY {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.table-bubble, .customer .bubble { animation-name: bob; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-2px) rotate(-3deg); }
  75% { transform: translateX(2px) rotate(3deg); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
