/* ================================================================
   小鎮飲料戰 Little Town — 小鎮動畫地圖樣式（map_ 軌道）
   ----------------------------------------------------------------
   接在 styles.css 之後載入，沿用既有的 CSS 變數
   （--ink / --paper / --card / --line / --accent / --t1~--t5）。
   所有 class 一律 lt- 開頭，不會撞到既有樣式。

   設計原則與 styles.css 一致：
   1. 可投影 —— 時鐘與計數刻意放大，後排也看得到
   2. 手機可用 —— 900px 以下改成單欄，地圖在上、計數在下
   3. 零外部資源 —— 只用 SVG 與 CSS，不引入任何圖檔或字型
   ================================================================ */

/* ---------------------------------------------------------------- 外框 */

.lt-map-card {
  /* 地圖自己有留白，卡片就收窄一點，投影時畫面更滿 */
  padding: 16px 18px 18px;
  overflow: hidden;
}

.lt-map {
  --lt-map-fg: var(--ink, #23211c);
  --lt-map-line: var(--line, #d8d1c0);
}

/* ---------------------------------------------------------------- 時鐘列 */

.lt-map-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line-soft, #e8e2d4);
}

.lt-map-clock {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.lt-map-clock-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.lt-map-clock-label {
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  color: var(--ink-soft, #6a6559);
}

/* 投影用的大時鐘。tabular-nums 讓數字換位時不會左右抖動。 */
.lt-map-clock-time {
  font-size: 2.6rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  color: var(--ink, #23211c);
}

.lt-map-phase {
  padding: 5px 13px;
  border: 1px solid var(--line, #d8d1c0);
  border-radius: 999px;
  background: var(--paper, #f4f1ea);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink-soft, #6a6559);
  white-space: nowrap;
}

/* ── 日夜的視覺線索：一顆會變色的太陽／月亮 */

.lt-map-sky {
  position: relative;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #d8d1c0;
  box-shadow: 0 0 0 0 rgba(0, 0, 0, 0);
  transition: background 900ms ease, box-shadow 900ms ease, transform 900ms ease;
}

.lt-sky-idle      { background: #ded8c8; }
.lt-sky-dawn      { background: linear-gradient(160deg, #ffd9a0, #f6a94c); box-shadow: 0 0 20px rgba(246, 169, 76, 0.55); }
.lt-sky-morning   { background: linear-gradient(160deg, #ffe08a, #f7b733); box-shadow: 0 0 22px rgba(247, 183, 51, 0.6); }
.lt-sky-forenoon  { background: linear-gradient(160deg, #ffe89c, #f9c53d); box-shadow: 0 0 24px rgba(249, 197, 61, 0.62); }
.lt-sky-noon      { background: linear-gradient(160deg, #fff3b0, #ffc93c); box-shadow: 0 0 30px rgba(255, 201, 60, 0.75); transform: scale(1.06); }
.lt-sky-afternoon { background: linear-gradient(160deg, #ffd98a, #f0a13a); box-shadow: 0 0 24px rgba(240, 161, 58, 0.6); }
.lt-sky-dusk      { background: linear-gradient(160deg, #ffb36b, #e2683f); box-shadow: 0 0 24px rgba(226, 104, 63, 0.55); }

/* 夜晚與深夜換成月亮：用 inset 陰影挖出一個彎月 */
.lt-sky-night,
.lt-sky-latenight {
  background: #f3f2ea;
  box-shadow: inset -11px 3px 0 -1px #46506a, 0 0 18px rgba(126, 141, 179, 0.5);
  transform: scale(0.9);
}
.lt-sky-latenight {
  box-shadow: inset -13px 4px 0 -1px #333c54, 0 0 14px rgba(80, 92, 124, 0.45);
}

/* ── 一天的時間軸 */

.lt-map-daybar {
  display: flex;
  align-items: center;
  gap: 11px;
  flex: 1 1 260px;
  min-width: 210px;
  max-width: 460px;
}

.lt-map-day {
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
}

.lt-map-track {
  position: relative;
  flex: 1 1 auto;
  height: 8px;
  border-radius: 999px;
  background: var(--paper-deep, #e8e3d6);
  overflow: hidden;
}

.lt-map-track-fill {
  display: block;
  width: 0;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #f7b733, #e2683f 55%, #46506a);
  transition: width 700ms ease;
}

.lt-map-track-ends {
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink-faint, #97917f);
  white-space: nowrap;
}

/* ---------------------------------------------------------------- 版面 */

.lt-map-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(190px, 232px);
  gap: 16px;
  align-items: start;
}

.lt-map-stage {
  position: relative;
  min-width: 0;
}

.lt-map-svg-holder {
  border: 1px solid var(--line, #d8d1c0);
  border-radius: 10px;
  overflow: hidden;
  background: var(--paper, #f4f1ea);
}

.lt-map-svg {
  display: block;
  width: 100%;
  height: auto;
  /* 15×11 網格加留白，比例約 1.34；height:auto + viewBox 讓它自己等比縮放 */
}

/* live_frame 是 null 時：底圖留著，人淡出，蓋一層提示 */
.lt-map-svg.is-idle .lt-map-agents {
  opacity: 0;
  transition: opacity 500ms ease;
}
.lt-map-agents {
  opacity: 1;
  transition: opacity 400ms ease;
}

.lt-map-idle {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 6px;
  padding: 20px;
  border-radius: 10px;
  background: rgba(244, 241, 234, 0.74);
  text-align: center;
  pointer-events: none;
}
.lt-map-idle[hidden] { display: none; }

.lt-map-idle-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--ink, #23211c);
}

.lt-map-idle-sub {
  margin: 0;
  font-size: 0.95rem;
  color: var(--ink-soft, #6a6559);
}

/* ---------------------------------------------------------------- 底圖：地面、網格、街道 */

.lt-map-ground {
  fill: #f4f1ea;
  transition: fill 1200ms ease;
}

.lt-map-tint {
  fill: #20304f;
  pointer-events: none;
  transition: opacity 1200ms ease;
}

.lt-map-grid line {
  stroke: #e3ddcd;
  stroke-width: 0.7;
  opacity: 0.55;
}

/* 街道畫兩層：寬的淺色底 + 窄的白色中線，看起來像柏油路 */
.lt-map-street-base {
  fill: none;
  stroke: #e2dcca;
  stroke-width: 15;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.lt-map-street-line {
  fill: none;
  stroke: #f7f4ea;
  stroke-width: 8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------------------------------------------------------------- 地點造型 */

.lt-loc-shape {
  fill: #ddd5c2;
  stroke: #b9ae95;
  stroke-width: 1.2;
}

.lt-loc-door,
.lt-loc-window {
  fill: #f6f2e6;
  stroke: #b9ae95;
  stroke-width: 0.8;
}

.lt-loc-label {
  font-size: 11px;
  font-weight: 600;
  fill: var(--ink-soft, #6a6559);
  paint-order: stroke;
  stroke: #f7f4ec;
  stroke-width: 3.2;
  stroke-linejoin: round;
  pointer-events: none;
}

.lt-loc-label.is-shop {
  font-size: 12.5px;
  font-weight: 700;
  fill: var(--ink, #23211c);
}

/* 住宅：暖色 */
.lt-loc-residence .lt-loc-shape { fill: #e6d3b8; stroke: #bda07a; }

/* 工作地點：偏灰 */
.lt-loc-work .lt-loc-shape { fill: #d3d5d8; stroke: #9ba0a6; }
.lt-loc-work .lt-loc-window { fill: #eef1f4; stroke: #9ba0a6; }

/* 學校：淡藍 */
.lt-loc-school .lt-loc-shape { fill: #cfdce8; stroke: #8fa5bb; }
.lt-loc-pole { stroke: #8fa5bb; stroke-width: 1.6; }
.lt-loc-flag { fill: #c0453c; }

/* 自助餐：暖橘 + 熱氣 */
.lt-loc-canteen .lt-loc-shape { fill: #f0cfa0; stroke: #c79a52; }
.lt-loc-canteen .lt-loc-door { fill: #d9b478; stroke: #c79a52; }
.lt-loc-steam {
  fill: none;
  stroke: #c79a52;
  stroke-width: 1.4;
  stroke-linecap: round;
  opacity: 0.75;
}

/* 便利商店：地板競爭者，用中性綠標示 */
.lt-loc-convenience .lt-loc-shape { fill: #dfe7dd; stroke: #93a891; }
.lt-loc-sign { fill: #4a7c4e; }
.lt-loc-convenience .lt-loc-window { fill: #f3f7f2; stroke: #93a891; }

/* 公園：樹 */
.lt-loc-trunk { fill: #9c7a4d; }
.lt-loc-leaf  { fill: #97bd8b; stroke: #6f9a63; stroke-width: 1; }

/* ---------------------------------------------------------------- 五個攤位 */

.lt-loc-shop { --lt-team: #8a8375; }

.lt-shop-body {
  fill: #fdfcf8;
  stroke: var(--lt-team);
  stroke-width: 1.6;
}

.lt-shop-awning { fill: var(--lt-team); }

.lt-shop-counter {
  fill: var(--lt-team);
  opacity: 0.55;
}

/* 夜間打燈：晚上攤位會亮起來，白天不畫 */
.lt-shop-glow {
  fill: var(--lt-team);
  opacity: 0;
  transition: opacity 1200ms ease;
  pointer-events: none;
}
.lt-phase-dusk      .lt-shop-glow { opacity: 0.13; }
.lt-phase-night     .lt-shop-glow { opacity: 0.2; }
.lt-phase-latenight .lt-shop-glow { opacity: 0.2; }

/* 賣出飲料的脈衝環：平常完全透明，加上 .is-selling 才跑一次 */
.lt-shop-pulse {
  fill: none;
  stroke: var(--lt-team);
  stroke-width: 3;
  opacity: 0;
  pointer-events: none;
  transform-box: fill-box;
  transform-origin: center;
}

.lt-loc-shop.is-selling .lt-shop-pulse {
  animation: lt-shop-ring 1s ease-out 1;
}

/* 一小時內賣超過 5 杯：連震兩下，投影時很顯眼 */
.lt-loc-shop.is-selling .lt-shop-awning,
.lt-loc-shop.is-selling .lt-shop-body {
  animation: lt-shop-bump 0.42s ease-out 1;
}
.lt-loc-shop.is-hot .lt-shop-awning,
.lt-loc-shop.is-hot .lt-shop-body {
  animation: lt-shop-bump 0.42s ease-out 2;
}
.lt-loc-shop.is-hot .lt-shop-pulse {
  stroke-width: 4.5;
}

.lt-loc-shop.is-selling .lt-loc-label {
  fill: var(--lt-team);
}

@keyframes lt-shop-ring {
  0%   { opacity: 0.85; transform: scale(0.42); }
  70%  { opacity: 0.28; }
  100% { opacity: 0;    transform: scale(1.65); }
}

@keyframes lt-shop-bump {
  0%   { transform: translateY(0); }
  38%  { transform: translateY(-3.2px); }
  100% { transform: translateY(0); }
}

/* 這一小時賣了幾杯：常駐在攤位右上角，不像脈衝一閃就沒 */
.lt-shop-badge {
  transition: opacity 400ms ease;
  pointer-events: none;
}

.lt-shop-badge-bg {
  stroke: #fdfcf8;
  stroke-width: 1.8;
}

.lt-shop-badge-num {
  font-size: 11px;
  font-weight: 700;
  fill: #fdfcf8;
}

/* 攤位上方飄出的「+3」 */
.lt-map-float {
  font-size: 15px;
  font-weight: 700;
  paint-order: stroke;
  stroke: #fdfcf8;
  stroke-width: 3.4;
  stroke-linejoin: round;
  pointer-events: none;
  animation: lt-float-up 1.5s ease-out forwards;
}

@keyframes lt-float-up {
  0%   { opacity: 0;    transform: translateY(4px); }
  18%  { opacity: 1;    transform: translateY(0); }
  100% { opacity: 0;    transform: translateY(-22px); }
}

/* ---------------------------------------------------------------- 鎮民 */

.lt-agent {
  --lt-seg: #6a6559;
  /* transform 由 JS 逐格寫入，這裡不要加 transition，否則會跟 rAF 打架 */
}

/* 圓點半徑由 JS 依現場人數算出來寫在 r 屬性上（人擠時自動縮小）。
   CSS 這邊一律不要再寫 r，否則會蓋掉 JS 的計算——改用 scale 做強調。 */
.lt-agent-dot {
  fill: var(--lt-seg);
  stroke: #fdfcf8;
  stroke-width: 1.3;
  transform-box: fill-box;
  transform-origin: center;
}

.lt-seg-student  { --lt-seg: #2f6fe0; }
.lt-seg-office   { --lt-seg: #e8871a; }
.lt-seg-family   { --lt-seg: #d13f7a; }
.lt-seg-shift    { --lt-seg: #8b5cf6; }
.lt-seg-retiree  { --lt-seg: #4b5563; }
.lt-seg-tourist  { --lt-seg: #12a594; }

/* 走路中：加一圈淡淡的光暈，看得出誰在移動 */
.lt-agent.is-walking .lt-agent-dot {
  stroke-width: 1.6;
  filter: drop-shadow(0 1px 1.5px rgba(35, 33, 28, 0.35));
}

/* 休息中：縮小、變淡，晚上一眼看得出「大家都睡了」 */
.lt-agent.is-resting .lt-agent-dot {
  transform: scale(0.76);
  opacity: 0.55;
}

/* 上班中：描邊換色、稍微收一點，跟閒晃的人區分開 */
.lt-agent.is-working .lt-agent-dot {
  stroke: #efe9da;
  opacity: 0.9;
}

/* 正在買飲料：放大 + 一圈脈動，最醒目 */
.lt-agent.is-buying .lt-agent-dot {
  stroke-width: 2;
  animation: lt-agent-buy 0.9s ease-in-out infinite;
}

@keyframes lt-agent-buy {
  0%, 100% { opacity: 1;    stroke-width: 2;   transform: scale(1.32); }
  50%      { opacity: 0.72; stroke-width: 3.4; transform: scale(1.5); }
}

/* ---------------------------------------------------------------- 右側計數 */

.lt-map-side {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.lt-map-side-title {
  margin-bottom: 8px;
  font-size: 0.86rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ink-soft, #6a6559);
}

.lt-map-stat {
  padding: 13px 15px;
  border: 1px solid var(--line-soft, #e8e2d4);
  border-radius: 9px;
  background: var(--paper, #f4f1ea);
}

.lt-map-stat-label {
  display: block;
  font-size: 0.85rem;
  color: var(--ink-soft, #6a6559);
}

.lt-map-stat-value {
  display: block;
  margin: 2px 0 3px;
  font-size: 2.1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  color: var(--accent, #1f6f7a);
}

.lt-map-stat-sub {
  display: block;
  font-size: 0.82rem;
  color: var(--ink-faint, #97917f);
}

.lt-map-cup-rows {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.lt-map-cup-row {
  display: grid;
  grid-template-columns: minmax(0, 4.6em) minmax(0, 1fr) 2.4em;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
}

.lt-map-cup-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink, #23211c);
}

.lt-map-cup-track {
  height: 9px;
  border-radius: 999px;
  background: var(--paper-deep, #e8e3d6);
  overflow: hidden;
}

.lt-map-cup-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  transition: width 600ms ease;
}

.lt-map-cup-num {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  text-align: right;
}

.lt-map-legend-rows {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 12px;
}

.lt-map-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.84rem;
  color: var(--ink-soft, #6a6559);
  white-space: nowrap;
}

.lt-map-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  box-shadow: 0 0 0 1.5px #fdfcf8;
}

/* ---------------------------------------------------------------- 投影模式
   帶領人按下「投影模式」後，時鐘與計數再放大一級。 */

body.project-mode .lt-map-clock-time { font-size: 3.6rem; }
body.project-mode .lt-map-sky        { width: 54px; height: 54px; }
body.project-mode .lt-map-phase      { font-size: 1.15rem; }
body.project-mode .lt-map-day        { font-size: 1.2rem; }
body.project-mode .lt-map-stat-value { font-size: 2.7rem; }
body.project-mode .lt-map-cup-row    { font-size: 1.02rem; }
body.project-mode .lt-map-body       { grid-template-columns: minmax(0, 1fr) minmax(220px, 280px); }
body.project-mode .lt-map-idle-title { font-size: 1.8rem; }

/* 投影時地點名稱要更大 */
body.project-mode .lt-loc-label         { font-size: 13px; }
body.project-mode .lt-loc-label.is-shop { font-size: 15px; }
/* 投影時人也放大一點。用 scale 不用 r——r 會蓋掉 JS 依人數算出來的大小。 */
body.project-mode .lt-agent-dot         { transform: scale(1.18); }
body.project-mode .lt-agent.is-resting .lt-agent-dot { transform: scale(0.9); }

/* ---------------------------------------------------------------- 響應式 */

@media (max-width: 900px) {
  /* 平板與手機：地圖在上、計數在下，計數改成橫排 */
  .lt-map-body {
    grid-template-columns: minmax(0, 1fr);
  }

  .lt-map-side {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .lt-map-stat  { flex: 1 1 190px; }
  .lt-map-cups  { flex: 2 1 240px; }
  .lt-map-legend { flex: 1 1 100%; }
}

@media (max-width: 760px) {
  .lt-map-card {
    padding: 14px 12px 15px;
  }

  .lt-map-head {
    gap: 9px 14px;
  }

  .lt-map-clock-time {
    font-size: 2.1rem;
  }

  .lt-map-sky {
    width: 34px;
    height: 34px;
  }

  .lt-map-daybar {
    flex: 1 1 100%;
    max-width: none;
  }

  /* 手機螢幕窄，地點名稱會擠成一團，只留攤位的名字 */
  .lt-loc-label {
    display: none;
  }
  .lt-loc-label.is-shop {
    display: block;
    font-size: 14px;
  }

  /* 相對地，人與攤位要畫大一點才點得到、看得清 */
  .lt-agent-dot { transform: scale(1.14); }
  .lt-agent.is-resting .lt-agent-dot { transform: scale(0.86); }
  .lt-map-stat-value { font-size: 1.8rem; }
}

/* ---------------------------------------------------------------- 減少動態
   使用者若在系統設定開了「減少動態效果」，就只留下顏色與位置變化。
   （JS 那邊也會直接讓人就位，不跑補間。） */

@media (prefers-reduced-motion: reduce) {
  .lt-map-sky,
  .lt-map-ground,
  .lt-map-tint,
  .lt-map-track-fill,
  .lt-map-cup-fill,
  .lt-map-agents {
    transition-duration: 1ms;
  }

  .lt-loc-shop.is-selling .lt-shop-pulse,
  .lt-loc-shop.is-selling .lt-shop-awning,
  .lt-loc-shop.is-selling .lt-shop-body,
  .lt-loc-shop.is-hot .lt-shop-awning,
  .lt-loc-shop.is-hot .lt-shop-body,
  .lt-agent.is-buying .lt-agent-dot,
  .lt-map-float {
    animation: none;
  }

  /* 動畫關掉後仍要看得出「這家在賣」：改用靜態強調 */
  .lt-loc-shop.is-selling .lt-shop-pulse { opacity: 0.5; }
  .lt-agent.is-buying .lt-agent-dot { transform: scale(1.4); stroke-width: 2.6; }
}

/* ---------------------------------------------------------------- 列印
   覆盤講義用：不印地圖動畫，只留計數。 */

@media print {
  .lt-map-stage { display: none; }
  .lt-map-body  { grid-template-columns: minmax(0, 1fr); }
}
