:root {
  color-scheme: light;
  --night: #263036;
  --night-2: #374148;
  --ink: #232827;
  --muted: #5d625f;
  --paper: #f4f0e7;
  --paper-2: #e7e2d7;
  --line: #8d918c;
  --steel: #b8b9b3;
  --amber: #bd743f;
  --amber-dark: #7b4427;
  --rain: #55758b;
  --ok: #315f4d;
  --danger: #8b372f;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Microsoft JhengHei", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--night); }
body { margin: 0; min-width: 320px; min-height: 100dvh; background: var(--night); color: var(--ink); font-size: 15px; font-weight: 500; line-height: 1.45; }
button { font: inherit; }
button:focus-visible { outline: 3px solid #f0b777; outline-offset: 2px; }
button:disabled { cursor: not-allowed; opacity: .46; }

#app {
  width: min(100%, 390px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 10px max(14px, env(safe-area-inset-bottom));
  background: #d8d3c8;
  overflow-x: hidden;
}

.screen { display: grid; gap: 10px; min-height: calc(100dvh - 24px); align-content: start; }
.panel { background: var(--paper); border: 1px solid #8a8d88; border-radius: 12px; box-shadow: 0 2px 0 rgba(28, 34, 35, .12); }
.pad { padding: 13px; }
.eyebrow { margin: 0 0 3px; color: var(--muted); font-size: 14px; font-weight: 700; letter-spacing: .08em; }
.key-number { font-size: 30px; line-height: 1; font-weight: 750; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.small { font-size: 14px; color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.topbar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
  min-height: 58px;
  padding: 9px 11px;
  color: #fbf7ed;
  background: var(--night);
  border: 1px solid #161c1f;
  border-radius: 11px;
}
.topbar .date { font-size: 17px; font-weight: 760; }
.topbar .sub { color: #d5d8d4; font-size: 14px; }
.topbar .cash { min-width: 72px; text-align: right; font-size: 22px; font-weight: 760; font-variant-numeric: tabular-nums; }
.topbar .rep { min-width: 60px; text-align: right; color: #ffd79a; font-weight: 760; }

.primary, .secondary, .danger-button {
  width: 100%;
  min-height: 48px;
  padding: 11px 14px;
  border-radius: 9px;
  border: 1px solid #57301e;
  font-weight: 760;
}
.primary { color: #fffaf1; background: var(--amber-dark); }
.secondary { color: var(--ink); background: var(--paper); border-color: var(--line); }
.danger-button { color: #fff; background: var(--danger); border-color: #5e211c; }

.opening-card { padding: 15px; display: grid; gap: 5px; }
.opening-card .season { font-size: 20px; font-weight: 760; }
.opening-card .date-line { font-size: 32px; font-weight: 780; font-variant-numeric: tabular-nums; }
.opening-card .mood { color: var(--muted); font-size: 15px; }
.art-full, .art-crop { overflow: hidden; padding: 0; background: #c7c5bd; }
.art-full img { display: block; width: 100%; height: auto; aspect-ratio: 2 / 3; object-fit: contain; }
.art-crop { height: 190px; }
.art-crop img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: center 56%; }

.forecast-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.forecast-card { padding: 11px; min-height: 88px; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; }
.forecast-card.tomorrow { background: #e8edf0; border-color: #7e929e; }
.forecast-card .weather { font-size: 19px; font-weight: 760; }
.forecast-card .event { margin-top: 3px; color: var(--muted); font-size: 14px; }

.metrics { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 7px; }
.metric { min-height: 78px; padding: 9px; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; }
.metric strong { display: block; margin-top: 3px; font-size: 22px; font-variant-numeric: tabular-nums; }
.metric .slots { font-size: 25px; }

.expansion { padding: 11px; display: grid; gap: 8px; }
.expansion-row { display: grid; grid-template-columns: 1fr auto; gap: 9px; align-items: center; }
.expansion button { min-width: 112px; min-height: 44px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: #ded9cf; font-weight: 720; }
.expansion button.selected { color: #fff; background: var(--ok); border-color: #204635; }

.fridge-list { display: grid; gap: 5px; padding: 11px; }
.fridge-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.fridge-life { color: #1d4e60; font-size: 14px; }
.fridge-item { display: flex; justify-content: space-between; gap: 10px; }
.fridge-item strong { font-variant-numeric: tabular-nums; }

/* §5 飯・湯備量面板 */
.staple-list { display: grid; gap: 8px; padding: 11px; }
.staple-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.staple-head { min-width: 0; }
.staple-name { font-size: 16px; font-weight: 780; }
/* p1.1 §3：預填＝系統建議值的小標，低醒目度；玩家改動該格後不出現。 */
.staple-hint { margin-left: 6px; font-size: 13px; font-weight: 500; color: var(--muted); letter-spacing: .04em; }
.staple-head .small { display: block; }
.staple-control { grid-template-columns: 44px 40px 44px; }

.dish-list { display: grid; gap: 8px; }
.dish-row { padding: 10px; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; }
.dish-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; margin-bottom: 8px; }
.dish-name { font-size: 16px; font-weight: 780; }
.dish-meta { color: var(--muted); font-size: 14px; text-align: right; }
/* r7 §7：菜卡四個數分兩行排（一盤食材＋工錢／一份賣・一盤幾份），數字用 tabular-nums 對齊。 */
.dish-meta > div + div { margin-top: 2px; }
.dish-meta .meta-cost, .dish-meta .meta-yield { font-variant-numeric: tabular-nums; white-space: nowrap; }
.dish-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.control-group { display: grid; grid-template-columns: 1fr 44px 36px 44px; gap: 3px; align-items: center; min-width: 0; }
.control-group.unavailable { opacity: .52; }
.control-label { min-width: 0; color: var(--muted); font-size: 14px; }
.stepper { width: 44px; height: 44px; padding: 0; border: 1px solid #777c78; border-radius: 8px; background: #e4dfd5; color: var(--ink); font-size: 22px; font-weight: 800; }
.step-value { min-width: 36px; text-align: center; font-size: 20px; font-weight: 780; font-variant-numeric: tabular-nums; }
.fridge-chip { display: inline-block; margin-left: 5px; padding: 1px 5px; color: #1d4e60; background: #dce9ee; border: 1px solid #8eaab5; border-radius: 5px; font-size: 13px; }

.prep-footer { position: sticky; bottom: max(8px, env(safe-area-inset-bottom)); z-index: 20; padding: 10px; background: var(--night); border: 1px solid #141a1d; border-radius: 11px; color: #fff; }
.prep-summary { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 8px; font-size: 14px; }
.prep-summary strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.warning { min-height: 21px; margin: 6px 0; color: #ffd3a5; font-size: 14px; }

.service-head { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; padding: 10px 11px; }
.service-head .weather { font-size: 18px; font-weight: 760; }
.service-head button { min-width: 90px; min-height: 44px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper-2); font-weight: 720; }
.scene {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  background: #c6c5bf;
  border: 1px solid #707773;
  border-radius: 12px;
}
.scene > img { display: block; width: 100%; height: 100%; object-fit: contain; }
/* p1.2 §1 中島前景層：同一張圖、同位置、同 object-fit 疊在最上，clip-path 只留中島輪廓。
   z:15 介於背排客（.behind z:10）與其他客（z≥~55）之間 ⇒ 只把走到背排的客人下半身蓋住。
   前景＝背景同像素同位置 ⇒ 對著背景零接縫（clip 描不準也不露餡）；只要背排客的頭肩能露出島頂。 */
.scene > .island-fg {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: contain;
  z-index: 15;
  pointer-events: none;
  clip-path: polygon(36% 47%, 79% 47%, 79% 75%, 36% 75%);
}
.people-layer { position: absolute; inset: 0; pointer-events: none; }
/* r6 §A/§B 客人：烘小 sprite（cust-*-01@256.webp）＋接地陰影＋壓進場景光。
   錨點＝底部中心，--y 就是腳底那條線；--gh 隨景深（--y）在 70–100px 之間走。 */
.guest {
  --x: 73;
  --y: 87;
  --step: 100ms;
  /* 高度隨景深（--y）走：走道後段 ~110px、門口 ~128px。上限 128＝烘出的 256 sprite
     在 2× DPR 剛好 1:1。※ spec §A 寫「遊戲只用 70–100px」，實測在這張場景會變娃娃
     （頭頂只到中島下層層板、搆不到菜格）——見交貨紀錄 §H 異議與 _r6-gh-compare.png。 */
  --gh: clamp(104px, calc(110px + (var(--y) - 76) * 1.55px), 128px);
  position: absolute;
  left: calc(var(--x) * 1%);
  top: calc(var(--y) * 1%);
  width: auto;
  height: var(--gh);
  z-index: calc(20 + var(--y));
  transform: translate(-50%, -100%);
  transition: left var(--step) var(--ease, linear), top var(--step) var(--ease, linear);
}
/* p1.2 §1 遮擋：背排客（.behind）掉到前景中島層（z:15）之下 ⇒ 下半身被中島蓋住。
   其餘客人 z=calc(20+y)≥~55 都在前景層之上（前排／兩側照常最上，不被誤蓋）。 */
.guest.behind { z-index: 10; }
.guest .body {
  display: block;
  width: auto;
  height: 100%;
  /* 壓進場景光：極淡暖調＋略降亮度，讓角色不比場景亮。克制，寧可不足。 */
  filter: brightness(.93) sepia(.10) saturate(.96);
  /* p1.2 §3 步感：行進方向微傾（--lean，setActorPosition 給值），停下回正。 */
  transform: rotate(var(--lean, 0deg));
  transition: transform .12s ease-out;
}
/* p1.2 §3 步感：走路時上下 bob（步頻節奏，幅度 2.5px）；停下不 bob。免新美術、純 CSS。 */
.guest.walking .body { animation: guest-bob .42s ease-in-out infinite; }
@keyframes guest-bob {
  0%, 100% { transform: translateY(0) rotate(var(--lean, 0deg)); }
  50%      { transform: translateY(-2.5px) rotate(var(--lean, 0deg)); }
}
/* 接地陰影：寬＝sprite 寬、高＝寬/3、alpha .43、blur 3px、橢圓中心貼腳底
   （照 _scaletest-out2.png 下排右的實測參數；跟著 .guest 的 transform 走）。 */
.guest::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 0;
  width: calc(var(--gh) * .32);
  height: calc(var(--gh) * .107);
  transform: translate(-50%, 50%);
  border-radius: 50%;
  background: rgba(0, 0, 0, .43);
  filter: blur(calc(var(--gh) * .028));
  z-index: -1;
}
.guest.named .body { filter: brightness(.93) sepia(.10) saturate(.96) drop-shadow(0 0 1.5px rgba(212, 154, 88, .9)); }
.guest.empty .body { filter: brightness(.93) sepia(.10) saturate(.96) grayscale(.5); }
.speech, .checkout-pop { position: absolute; left: 50%; bottom: calc(100% + 4px); transform: translateX(-50%); min-width: max-content; padding: 3px 6px; border: 1px solid #4b4e4b; border-radius: 6px; background: #f8f4ea; color: var(--ink); font: 700 14px/1.2 inherit; z-index: 3; }
.checkout-pop { color: #6d321d; font-size: 15px; }

/* p1 §3.1 客群名牌：頭上小 pill，既有群名（功能性文字，襯底＋高對比），左側色帶＝群色。
   說話時（.speaking）名牌讓位給氣泡，兩者共用頭頂那格、不疊。 */
.guest .tag {
  position: absolute; left: 50%; bottom: calc(100% + 4px); transform: translateX(-50%);
  min-width: max-content; padding: 2px 6px 2px 5px;
  border: 1px solid #6d716c; border-left: 3px solid var(--g, #6d716c); border-radius: 6px;
  background: rgba(248, 244, 234, .96); color: var(--ink);
  font: 700 13px/1.15 inherit; white-space: nowrap; z-index: 2;
}
.guest.speaking .tag { opacity: 0; }
.guest.g1 { --g: #2f7d6b; } /* 學生 */
.guest.g2 { --g: #bd743f; } /* 工地師傅 */
.guest.g3 { --g: #4d6b8a; } /* 上班族 */
.guest.g4 { --g: #8a6a44; } /* 老人家 */
.guest.g5 { --g: #a75f68; } /* 兒童 */
.guest.g6 { --g: #6b5a86; } /* 外國人 */
.guest.empty .tag { color: var(--danger); border-left-color: var(--danger); }

/* p1 §3.2 托盤：客人手邊一排色塊，夾一道長一塊（色＝tag）。醒目度低於場景主體。 */
.guest .tray {
  position: absolute; right: -3px; bottom: 34%;
  display: flex; flex-wrap: wrap-reverse; gap: 2px; width: 22px;
  padding: 2px; border-radius: 4px; background: rgba(232, 228, 216, .0);
}
.guest .tray:not(:empty) { background: rgba(232, 228, 216, .82); border: 1px solid #9a9d97; }
.guest .tray .chip { width: 8px; height: 8px; border-radius: 2px; border: 1px solid rgba(40, 44, 43, .35); background: var(--steel); }
.chip.t-fried { background: #c98a44; }
.chip.t-braise { background: #8a5a34; }
.chip.t-steam { background: #9fb2b0; }
.chip.t-veg { background: #6f9153; }
.chip.t-egg { background: #d8bf6b; }
.chip.t-hotsoup { background: #b06a4a; }
.chip.t-cold { background: #7fa6ac; }
.chip.t-sauce { background: #9c6f4a; }
.chip.t-stir { background: #b1794f; }
/* p1 §3.2 結帳拿到的飯／湯：低醒目度標記——比主菜 chip 小、無邊框、圓點，只讀「這人有買飯/湯」。 */
.guest .tray .staple-mark { width: 5px; height: 5px; border-radius: 999px; border: 0; opacity: .72; background: #b7ad97; align-self: center; }
.staple-mark.s-S01 { background: #d9cfae; } /* 白飯：米白 */
.staple-mark.s-S02 { background: #b98f6a; } /* 貢丸湯：暖湯棕 */
.staple-mark.s-S03 { background: #8fb0af; } /* 冰綠豆湯：冷調 */

.stock-strip { display: flex; gap: 6px; overflow-x: auto; padding: 8px; scrollbar-width: thin; }
.stock-item { flex: 0 0 auto; min-width: 92px; padding: 7px 8px; background: var(--paper); border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }
.stock-item strong { float: right; font-size: 17px; font-variant-numeric: tabular-nums; }
.stock-item.sold { color: var(--danger); background: #efe2dc; }

.ledger { padding: 14px; }
.ledger h1 { margin: 0 0 12px; font-size: 23px; }
.ledger-line { display: flex; justify-content: space-between; align-items: baseline; min-height: 44px; padding: 8px 0; border-bottom: 1px solid #b7b6af; }
.ledger-line span { font-size: 16px; }
.ledger-line strong { font-size: 22px; font-variant-numeric: tabular-nums; }
.ledger-line.net { border-bottom: 0; padding-top: 12px; }
.ledger-line.net span { font-weight: 780; }
.ledger-line.net strong { font-size: 34px; color: var(--amber-dark); }
.ledger-notes { display: grid; gap: 7px; padding: 12px; }
.note-line { display: flex; justify-content: space-between; gap: 8px; }
.note-line strong { text-align: right; }
.rating-change { color: var(--amber-dark); }
/* p1.1 §1：日結星等方向色（漲綠／跌紅／持平灰），覆蓋 .rating-change 預設琥珀。 */
.rating-change.rep-up strong { color: var(--ok); }
.rating-change.rep-down strong { color: var(--danger); }
.rating-change.rep-flat strong { color: var(--muted); }
/* p1.1 §2：冷藏先做＝拆項註記，讀作「食材／工錢裡的一部分」，低醒目度。 */
.note-inclusive { color: var(--muted); }
.note-inclusive .note-sub { margin-left: 6px; font-size: 13px; color: var(--muted); font-weight: 500; }

.end-card { padding: 18px; text-align: center; display: grid; gap: 10px; }
.end-card .score { font-size: 48px; line-height: 1; font-weight: 800; font-variant-numeric: tabular-nums; }
.end-card .rating { font-size: 22px; font-weight: 760; }

@media (max-width: 350px) {
  #app { padding-left: 7px; padding-right: 7px; }
  .topbar { grid-template-columns: 1fr auto; }
  .topbar .rep { grid-column: 1 / -1; text-align: left; }
  .forecast-grid, .metrics { grid-template-columns: 1fr; }
  .metric { min-height: 62px; }
  .dish-controls { grid-template-columns: 1fr; }
  .dish-head { align-items: flex-start; }
  /* r7 §7：菜卡的四個數是功能性文字（不讀懂就不會玩），≤350px 也不准擠掉，48%→58%。 */
  .dish-meta { max-width: 58%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
