/* ============================================================================
   css/town.css — 2.5D 分層紙藝小鎮舞台（Visual Pass PR-08 / D7）
   視覺標準：Carbon demo v1（暮光靛藍劇場燈箱・300gsm 象牙模切紙邊・棉紙感・
   鎏金壓線・獅子山遠景）。手寫 SVG 分層場景（非 SDXL 預渲染），
   建築四態（未點燈／待加固／已點燈／璀璨）由 js/town.js 按現有診斷資料驅動。
   闊度責任在本檔：手機 ~390 底欄／iPad 直 834 左欄＋右 Deck（shell.css 已讓位）／
   iPad 橫 1194 台階橫向伸展（wide viewBox 兩翼景物）／桌面 ≥1280 封頂置中。
   ============================================================================ */

/* ---------- 舞台容器（塞入 #diorama-viewport，HUD／Dock 疊喺上面） ---------- */
#town-stage {
  position: absolute; inset: 0; z-index: 2;
  display: none;
  flex-direction: column; align-items: center; justify-content: flex-start;
  padding: 94px 10px 182px;
}
#game-client.town25 #town-stage { display: flex; }
#game-client.town25 #diorama-canvas,
#game-client.town25 #diorama-pins { display: none !important; }
/* 下學期色調：沿用舊 canvas 嘅 term-2 微調，俾兩學期有可感差異 */
#game-client.term-2 #town-stage .town-svg { filter: hue-rotate(8deg) saturate(1.06); }

/* 背景：櫃外露出嘅 viewport 以暮光夜空（漸變＋星點）承接，唔留死位 */
#game-client.town25 #diorama-viewport {
  background:
    radial-gradient(1.6px 1.6px at 12% 30%, rgba(255, 243, 204, 0.75) 50%, transparent 51%),
    radial-gradient(1.3px 1.3px at 32% 62%, rgba(255, 243, 204, 0.55) 50%, transparent 51%),
    radial-gradient(1.8px 1.8px at 55% 22%, rgba(255, 243, 204, 0.65) 50%, transparent 51%),
    radial-gradient(1.2px 1.2px at 71% 48%, rgba(255, 243, 204, 0.5) 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 86% 70%, rgba(255, 243, 204, 0.6) 50%, transparent 51%),
    radial-gradient(1.2px 1.2px at 44% 84%, rgba(255, 243, 204, 0.45) 50%, transparent 51%),
    radial-gradient(ellipse 90% 34% at 50% 108%, rgba(231, 166, 107, 0.20), transparent 70%),
    linear-gradient(180deg, #0d1730 0%, #1a2958 55%, #2c2a55 100%);
}

/* ---------- 劇場燈箱櫃 ---------- */
.town-cabinet {
  width: min(940px, 100%);
  container-type: inline-size;
  border-radius: 18px;
  background: #141e3c;
  border: 1.5px solid #cbb88d;
  box-shadow: 0 3px 0 #8a7a52, 0 18px 38px -10px rgba(5, 8, 20, 0.55);
  overflow: hidden;
  position: relative;
  flex: none;
}
/* wrap 唔裁剪：SVG 本身會自我裁剪視口，名牌掣可輕微伸出畫面底邊（櫃身 overflow:hidden 保住圓角框） */
.town-scene-wrap { position: relative; width: 100%; background: #0b1228; overflow: visible; }
.town-svg { display: block; width: 100%; height: auto; }

/* ---------- 舞台 HUD（年代牌＋亮燈總數） ---------- */
.town-hud {
  position: absolute; top: 10px; left: 11px; right: 11px; z-index: 6;
  display: flex; align-items: center; justify-content: space-between;
  pointer-events: none;
}
.town-era {
  display: inline-flex; align-items: center; gap: 5px; height: 22px;
  padding: 0 9px 0 7px; border-radius: 999px;
  background: rgba(13, 20, 44, 0.78); border: 1px solid rgba(226, 184, 87, 0.5);
  color: #f9eed2; font-size: 10.5px; font-weight: 700; letter-spacing: 0.02em;
  white-space: nowrap;
}
.town-era i {
  width: 6px; height: 6px; border-radius: 50%; flex: none;
  background: #ffb84d; box-shadow: 0 0 6px #ffb84d;
}
.town-tally {
  display: inline-flex; align-items: center; height: 22px; padding: 0 8px;
  border-radius: 999px; background: rgba(13, 20, 44, 0.74);
  border: 1px solid rgba(255, 255, 255, 0.18); color: #e5e9f5;
  font-size: 10.5px; font-weight: 700; font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------- 建築狀態名牌（HTML 疊加掣，沿用舊 pin 嘅可達性角色） ---------- */
#town-chips { position: absolute; inset: 0; z-index: 5; pointer-events: none; }
#town-chips .town-chip { pointer-events: auto; }
.town-chip {
  position: absolute; z-index: 5;
  transform: translate(-50%, -50%);
  display: inline-flex; align-items: center; gap: 5px;
  min-height: 30px; padding: 4px 10px 4px 7px;
  background-color: rgba(255, 253, 247, 0.97);
  border: 2px solid #9f8258; border-radius: 999px;
  color: #43302a; font-size: 12px; font-weight: 900; white-space: nowrap;
  box-shadow: 0 3px 0 #a98c61, 0 5px 12px rgba(10, 12, 30, 0.35);
  cursor: pointer; font-family: inherit;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), border-color 0.18s ease, background-color 0.18s ease;
}
.town-chip:hover, .town-chip.is-selected {
  transform: translate(-50%, -56%) scale(1.06);
  border-color: #b47d18; background-color: #fff6db;
  box-shadow: 0 3px 0 #b47d18, 0 0 14px rgba(255, 200, 90, 0.65);
}
.town-chip .tc-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: #b9ac93; }
.town-chip .tc-lv {
  font-size: 10px; font-weight: 900; padding: 1px 6px; border-radius: 999px;
  background: #e8e0cd; color: #5c4a33; font-variant-numeric: tabular-nums;
}
.town-chip.st-lit .tc-dot { background: #f5a623; box-shadow: 0 0 6px rgba(245, 166, 35, 0.8); }
.town-chip.st-lit .tc-lv, .town-chip.st-radiant .tc-lv { background: #ffd166; color: #4a2906; }
.town-chip.st-radiant { border-color: #d4a017; background-color: #fff3cf; }
.town-chip.st-radiant .tc-dot { background: #ffcf3f; box-shadow: 0 0 8px rgba(255, 207, 63, 0.95); }
.town-chip.st-repair { border-color: #d97706; background-color: #fff8e6; }
.town-chip.st-repair .tc-dot { background: #f59e0b; box-shadow: 0 0 6px rgba(245, 158, 11, 0.8); }
.town-chip.st-repair .tc-lv { background: #fde68a; color: #7c4a03; }
.town-chip.st-mock { border-color: #7d6b91; }
.town-chip.st-mock .tc-lv { background: #e6def2; color: #4b3a63; }
.town-chip.st-locked { opacity: 0.82; }

/* ---------- 燈箱底座抽屜（叮叮線進度＋紙靈獸收藏架） ---------- */
.town-drawer {
  background: linear-gradient(180deg, #1b274d 0%, #131c38 100%);
  border-top: 1px solid rgba(226, 184, 87, 0.45);
  padding: 7px 11px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  color: #f6f1e4;
}
.town-wonder { flex: 1; min-width: 0; }
.town-wonder-top {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 10.5px; font-weight: 700; color: #f8e6b5; margin-bottom: 4px;
}
.town-wonder-top > span { white-space: nowrap; }
/* 窄櫃（手機）：抽屜改兩行——奇觀進度一行、收藏架一行，唔再夾到直書 */
@container (max-width: 600px) {
  .town-drawer { flex-wrap: wrap; row-gap: 6px; }
  .town-wonder { flex: 1 1 100%; }
  .town-drawer-div { display: none; }
  .town-shelf { margin-left: auto; }
}
.town-wonder-top small {
  font-size: 10px; color: #aeb9d6; font-weight: 600;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.town-segs { display: flex; gap: 3px; }
.town-segs i {
  flex: 1; height: 5px; border-radius: 99px;
  background: rgba(255, 255, 255, 0.14);
  transition: background 0.35s, box-shadow 0.35s;
}
.town-segs i.done {
  background: linear-gradient(90deg, #e2b857, #f6d889);
  box-shadow: 0 0 6px rgba(246, 216, 137, 0.45);
}
.town-segs i.next {
  background: rgba(226, 184, 87, 0.35);
  box-shadow: inset 0 0 0 1px rgba(226, 184, 87, 0.75);
  animation: townPulseSeg 1.8s ease-in-out infinite alternate;
}
.town-drawer-div { width: 1px; height: 26px; background: rgba(226, 184, 87, 0.25); flex: none; }
.town-shelf { display: flex; align-items: center; gap: 4px; flex: none; }
.town-slot {
  width: 26px; height: 26px; border-radius: 7px; padding: 0;
  background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(226, 184, 87, 0.35);
  display: grid; place-items: center; position: relative; cursor: pointer;
  font-family: inherit;
  transition: transform 0.18s, border-color 0.25s, background 0.25s;
}
.town-slot:hover { transform: translateY(-1px); }
.town-slot svg { width: 17px; height: 17px; display: block; }
.town-slot.collected {
  background: linear-gradient(145deg, rgba(226, 184, 87, 0.26), rgba(255, 243, 204, 0.1));
  border-color: rgba(246, 216, 137, 0.75);
}
.town-slot.hatching { border-style: dashed; border-color: #fbbf24; }
.town-slot.locked { opacity: 0.45; cursor: default; }
.town-shelf-count {
  font-size: 10px; line-height: 1.15; color: #cbd4ec; font-weight: 700;
  text-align: right; margin-left: 2px; font-variant-numeric: tabular-nums;
}
.town-shelf-count b { display: block; color: #f8e6b5; font-size: 10.5px; }

/* ---------- SVG 場景狀態規則（純 transform／opacity 動畫） ---------- */
.town-svg [data-depth] { transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1); will-change: transform; }
.tbldg { cursor: pointer; }
.tbldg:hover { filter: brightness(1.06); }
.tbldg:focus { outline: none; filter: brightness(1.1) drop-shadow(0 0 6px rgba(255, 214, 120, 0.8)); }
.tbldg.is-selected { filter: drop-shadow(0 0 7px rgba(255, 205, 92, 0.85)); }

.tbldg .win-lit-layer, .tbldg .aura-layer { opacity: 0; transition: opacity 0.65s ease; }
.tbldg.is-lit .win-lit-layer, .tbldg.is-lit .aura-layer { opacity: 1; }
.tbldg.is-radiant .aura-layer { opacity: 1; }
.tbldg .evo-wip, .tbldg .evo-done, .tbldg .repair-kit, .tbldg .radiant-kit {
  opacity: 0; pointer-events: none; transition: opacity 0.5s ease;
}
.tbldg.has-wip .evo-wip { opacity: 1; }
.tbldg.is-radiant .evo-done, .tbldg.is-radiant .radiant-kit { opacity: 1; }
.tbldg.is-repair .repair-kit { opacity: 1; pointer-events: none; }

/* 紙靈獸到訪位／孵化位（由舞台根 class 控制） */
#town-stage .town-fox { opacity: 0; transition: opacity 0.5s ease; }
#town-stage.has-beast .town-fox { opacity: 1; }
#town-stage .owl-egg { opacity: 1; transition: opacity 0.45s; }
#town-stage .owl-hatched { opacity: 0; transform: scale(0.82); transform-origin: 0 -5px; transition: opacity 0.5s, transform 0.5s ease; }
#town-stage[data-egg="hatched"] .owl-egg { opacity: 0; pointer-events: none; }
#town-stage[data-egg="hatched"] .owl-hatched { opacity: 1; transform: scale(1); }
#town-stage[data-egg="none"] .town-egg { display: none; }
#town-stage .town-tram { opacity: 0; transition: opacity 0.6s ease, transform 0.8s cubic-bezier(0.22, 1, 0.36, 1); }
#town-stage.tram-on .town-tram { opacity: 1; }

/* 已放置擺設（gacha 道具）：逐件由 root class 顯隱 */
#town-stage .town-prop { display: none; }
#town-stage.has-prop-rainbow .town-prop-rainbow,
#town-stage.has-prop-balloon .town-prop-balloon,
#town-stage.has-prop-ferris .town-prop-ferris,
#town-stage.has-prop-tree .town-prop-tree,
#town-stage.has-prop-fountain .town-prop-fountain,
#town-stage.has-prop-windmill .town-prop-windmill,
#town-stage.has-prop-cat .town-prop-cat,
#town-stage.has-prop-dog .town-prop-dog,
#town-stage.has-prop-boat .town-prop-boat,
#town-stage.has-prop-lantern .town-prop-lantern { display: block; }

/* 中央統測燈柱 */
.town-hub { cursor: pointer; }
.town-hub:hover { filter: brightness(1.08); }
.town-hub .hub-ring { opacity: 0; transition: opacity 0.5s ease; }
.town-hub.exam-ready .hub-ring { opacity: 1; animation: townHubPulse 2.2s ease-in-out infinite alternate; }

/* 輕量呼吸／微動 */
.town-cloud-a { animation: townDriftA 26s ease-in-out infinite alternate; }
.town-cloud-b { animation: townDriftB 34s ease-in-out infinite alternate; }
.town-ship-bob { animation: townBobShip 4.2s ease-in-out infinite alternate; }
.town-lantern-sway { transform-origin: 0 0; animation: townSway 3.1s ease-in-out infinite alternate; }
.town-egg-wobble { transform-origin: 0 0; animation: townEggRock 2.8s ease-in-out infinite; }
.town-zhe-bob { animation: townBobZhe 3.2s ease-in-out infinite alternate; }
.town-mote { animation: townRiseMote 5.5s ease-in-out infinite; }
.town-mote.m2 { animation-delay: -1.8s; animation-duration: 6.4s; }
.town-mote.m3 { animation-delay: -3.4s; animation-duration: 5.0s; }
.town-breath { animation: townBreath 3.4s ease-in-out infinite alternate; }

@keyframes townDriftA { from { transform: translateX(-5px); } to { transform: translateX(9px); } }
@keyframes townDriftB { from { transform: translateX(7px); } to { transform: translateX(-8px); } }
@keyframes townBobShip { from { transform: translateY(-2px); } to { transform: translateY(2.5px); } }
@keyframes townSway { from { transform: rotate(-5deg); } to { transform: rotate(5deg); } }
@keyframes townEggRock {
  0%, 100% { transform: rotate(0deg); }
  20% { transform: rotate(-6deg); } 40% { transform: rotate(6deg); }
  60% { transform: rotate(-3deg); } 80% { transform: rotate(2deg); }
}
@keyframes townBobZhe { from { transform: translateY(0); } to { transform: translateY(-1.8px); } }
@keyframes townRiseMote {
  0% { opacity: 0; transform: translateY(6px); }
  40% { opacity: 0.9; }
  100% { opacity: 0; transform: translateY(-18px); }
}
@keyframes townBreath { from { opacity: 0.78; } to { opacity: 1; } }
@keyframes townPulseSeg { from { opacity: 0.55; } to { opacity: 1; } }
@keyframes townHubPulse { from { opacity: 0.55; } to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .town-cloud-a, .town-cloud-b, .town-ship-bob, .town-lantern-sway, .town-egg-wobble,
  .town-zhe-bob, .town-mote, .town-breath, .town-segs i.next, .town-hub.exam-ready .hub-ring {
    animation: none !important;
  }
  .town-svg [data-depth] { transition: none; }
}

/* ---------- 慶典層（紙屑／氣球，TownStage 門面取代舊 canvas 慶典） ---------- */
#town-fx, #town-balloons {
  position: absolute; inset: 0; z-index: 6; pointer-events: none; overflow: hidden;
}
#town-balloons { z-index: 7; }
.town-confetto {
  position: absolute; width: 7px; height: 5px; border-radius: 1px;
  pointer-events: none; will-change: transform, opacity;
}
.town-balloon {
  position: absolute; width: 52px; height: 74px; padding: 0;
  background: none; border: 0; cursor: pointer; pointer-events: auto;
  will-change: transform;
}
.town-balloon svg { display: block; width: 100%; height: 100%; filter: drop-shadow(0 4px 6px rgba(10, 12, 30, 0.35)); }

/* ---------- 闊度微調 ---------- */
/* 手機：HUD 兩行＋摺摺帶＋四頁籤較高，底部預留多啲 */
@media (max-width: 767px) {
  #town-stage { padding: 96px 8px 190px; }
  .town-chip { font-size: 11.5px; min-height: 28px; padding: 3px 8px 3px 6px; }
}
/* iPad 直屏：舞台被 shell 夾到 ~442px 闊；頂欄左簇兩行較高，預留多啲免遮年代牌 */
@media (min-width: 768px) and (max-width: 1099px) {
  #town-stage { padding: 118px 10px 158px; }
}
/* iPad 橫屏／桌面：櫃闊由 wide viewBox 承接，兩翼景物填邊；底部要避開摺摺帶＋Dock */
@media (min-width: 1100px) {
  #town-stage { padding: 116px 14px 172px; }
  .town-cabinet { width: min(980px, 100%); }
}
/* 矮屏（橫放電話／細筆電）：收窄上下預留，保住成櫃可見 */
@media (max-height: 620px) {
  #town-stage { padding-top: 76px; padding-bottom: 128px; }
  .town-drawer { padding: 5px 9px; }
}
