:root {
  --line: #0070bd;
  --sea: #0b4f8a;
  --sea-2: #1a73e8;
  --ink: #102a43;
  --muted: #52667a;
  --card: #ffffff;
  --go: #2fbf71;
  --go-dark: #1f8f52;
  --ribbon: #ff7a00;
  --ribbon-ink: #b85700; /* 白底上的橘色文字用這個，對比 ≥ 4.5:1 */
  --path: #ffb300;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;

  /* 展示字型：標題、按鈕、數字、分頁、狀態列（內文、輸入框、說明小字維持系統字） */
  --font-display: "Lilita One", "Huninn", "PingFang TC", "Noto Sans TC", system-ui, sans-serif;

  /* 按鈕 token：所有元件共用，角色色只換上下兩個填色與文字樣式 */
  --btn-line: #1f2a37;        /* 深石板色描邊，也是厚底陰影的顏色 */
  --btn-line-w: 3px;
  --btn-depth: 5px;           /* 底部厚陰影高度，按下時會縮成 1px */
  --btn-radius: 14px;
  --btn-highlight: inset 0 2px 0 rgba(255, 255, 255, 0.45);
  --btn-text-ink: 0 1px 0 rgba(255, 255, 255, 0.55);
  --btn-text-white:
    -2px 0 0 var(--btn-line), 2px 0 0 var(--btn-line),
    0 -2px 0 var(--btn-line), 0 2px 0 var(--btn-line),
    -1px -1px 0 var(--btn-line), 1px -1px 0 var(--btn-line),
    -1px 1px 0 var(--btn-line), 1px 1px 0 var(--btn-line);
  /* 配色只用兩個主色：飄帶橘（主要行動）＋海藍（導覽、選取中），其餘是白色按鈕 */
  --btn-light-top: #ffffff;
  --btn-light-bottom: #eef1f4;
  --btn-orange-top: #ff8c2e;  /* 主要行動：白字＋深色描邊 */
  --btn-orange-bottom: #e8630a;
  --btn-blue-top: #3f8fd2;    /* 分頁選取、標題、選點中：白字＋深色描邊 */
  --btn-blue-bottom: #1f6aa8;
  --danger-ink: #c0392b;      /* 取消、收回：只把字變紅，不用紅色填滿 */
  --btn-disabled-line: #94a3b8;
  --ease-pop: cubic-bezier(0.2, 1.6, 0.4, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #e9edf2; overflow: hidden; overscroll-behavior: none; touch-action: manipulation; }
#map { position: fixed; inset: 0; }

/* ---------- 按鈕：厚描邊、上亮下暗漸層、厚底陰影，按下去會沉 ---------- */
button {
  --btn-top: var(--btn-light-top);
  --btn-bottom: var(--btn-light-bottom);
  --btn-fg: var(--ink);
  --btn-text: var(--btn-text-ink);
  font: inherit;
  font-family: var(--font-display);
  font-weight: 400;
  font-synthesis: none;
  letter-spacing: 0.02em;
  min-height: 44px;
  padding: 8px 14px;
  cursor: pointer;
  border: var(--btn-line-w) solid var(--btn-line);
  border-radius: var(--btn-radius);
  background: linear-gradient(180deg, var(--btn-top), var(--btn-bottom));
  color: var(--btn-fg);
  text-shadow: var(--btn-text);
  box-shadow: var(--btn-highlight), 0 var(--btn-depth) 0 var(--btn-line);
  transition: transform 0.08s, box-shadow 0.08s, filter 0.12s;
  touch-action: manipulation;
}
button:hover:not(:disabled) { filter: brightness(1.06); }
button:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: var(--btn-highlight), 0 1px 0 var(--btn-line);
}
button:disabled { cursor: not-allowed; filter: grayscale(1); opacity: 0.5; box-shadow: 0 2px 0 var(--btn-disabled-line); }
button:focus-visible { outline: 3px solid var(--btn-line); outline-offset: 3px; }

/* 角色色：主要行動＝橘、導覽與選取中＝藍、其他＝白；取消／收回是白底紅字 */
button.primary,
.ri-go,
.cc-go,
.tv-send,
.tv-vote,
.cc-bind,
.sh-join,
.vs-share,
.nav-actions .btn.go {
  --btn-top: var(--btn-orange-top);
  --btn-bottom: var(--btn-orange-bottom);
  --btn-fg: #fff;
  --btn-text: var(--btn-text-white);
}
.tab.on,
.ri-pin.active,
.tv-toggle.active {
  --btn-top: var(--btn-blue-top);
  --btn-bottom: var(--btn-blue-bottom);
  --btn-fg: #fff;
  --btn-text: var(--btn-text-white);
}
#cancel,
#trash-votes .tv-clear {
  --btn-fg: var(--danger-ink);
}
#trash-votes .tv-ctrl button { --btn-fg: var(--btn-orange-bottom); }

/* 主要按鈕（舊的 class，留給 JS 產生的元件用） */
button.primary { font-size: 18px; padding: 12px; }
button.primary:hover:not(:disabled) { filter: brightness(1.06); }

/* ---------- 上方狀態列（標題 chip 微微歪一點，不歪按鈕本身） ---------- */
.hud {
  position: fixed;
  top: calc(10px + var(--safe-t));
  left: 10px;
  right: 10px;
  z-index: 3;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}
.hud-row { width: 100%; display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.hud-title,
.hud-stat {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 4px 12px;
  border: var(--btn-line-w) solid var(--btn-line);
  border-radius: var(--btn-radius);
  box-shadow: var(--btn-highlight), 0 var(--btn-depth) 0 var(--btn-line);
}
/* 標誌式兩層標題：左邊六角形，右邊上小字「市長」、下大字「我要垃圾桶」 */
.hud-title {
  display: inline-grid;
  grid-template-columns: auto auto;
  align-items: center;
  column-gap: 8px;
  flex: 0 1 auto;
  min-width: 0;
  margin: 0;
  padding: 4px 14px 5px;
  background: linear-gradient(180deg, var(--btn-blue-top), var(--btn-blue-bottom));
  color: #fff;
  font-family: var(--font-display);
  font-weight: 400;
  line-height: 1.1;
  transform: rotate(-1deg);
  transform-origin: left center;
}
.hud-logo {
  grid-column: 1;
  grid-row: 1 / span 2;
  color: var(--path);
  font-size: 18px;
  line-height: 1;
  flex: none;
  text-shadow: var(--btn-text-white);
}
.hud-kicker {
  grid-column: 2;
  grid-row: 1;
  font-size: 12px;
  letter-spacing: 0.2em;
  color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 1px 0 var(--btn-line);
  white-space: nowrap;
}
.hud-name {
  grid-column: 2;
  grid-row: 2;
  font-size: 20px;
  letter-spacing: 0.04em;
  color: #fff;
  text-shadow: var(--btn-text-white);
  white-space: nowrap;
}
.hud-stats { display: flex; gap: 6px; flex: none; }
/* 動態條與任務提示的外層：桌機是上下堆疊；手機見下方 @media (max-width: 719px) */
.hud-strip { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; max-width: 100%; }
.hud-stat {
  padding: 4px 10px;
  background: linear-gradient(180deg, var(--btn-light-top), var(--btn-light-bottom));
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 14px;
  text-shadow: var(--btn-text-ink);
  white-space: nowrap;
}
.hud-stat b { font-variant-numeric: tabular-nums; font-size: 18px; font-weight: 400; }
.hud-stat.orange b { color: var(--ribbon-ink); }
.hud-stat.bump { animation: bump 0.35s var(--ease-pop); }
@keyframes bump { 40% { transform: scale(1.18); } }

/* 任務提示：一行對話泡泡（內文，系統字） */
.quest {
  pointer-events: auto;
  margin: 0;
  max-width: min(520px, 100%);
  padding: 8px 14px;
  font-size: 14px;
  line-height: 1.45;
  border: var(--btn-line-w) solid var(--btn-line);
  border-radius: 16px;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 4px 0 var(--btn-line);
}
.quest:empty { display: none; }
.quest.open { cursor: pointer; }
.quest b { color: var(--sea-2); }

/* ---------- 下方面板（手機是底部抽屜，桌機是左下角的卡片） ---------- */
.sheet,
.nav {
  position: fixed;
  z-index: 2;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 14px calc(14px + var(--safe-b));
  background: var(--card);
  border: var(--btn-line-w) solid var(--btn-line);
  border-bottom: none;
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -4px 0 var(--btn-line), 0 -8px 30px rgba(16, 42, 67, 0.2);
}
.sheet[hidden], .nav[hidden] { display: none; }

.tabs { display: flex; gap: 8px; }
.tab {
  flex: 1;
  height: 48px;
  min-height: 48px;
  padding: 0 8px;
  font-size: 18px;
  transition: transform 0.15s var(--ease-pop), box-shadow 0.08s;
}
.tab:hover:not(:disabled) { filter: brightness(1.04); }

.sheet-body {
  max-height: min(56vh, 520px);
  overflow: auto;
  overscroll-behavior: contain;
  margin-top: 12px;
  padding: 2px 4px 4px;
}
.sheet.collapsed .sheet-body { display: none; }
.sheet-head { position: relative; }
.pane[hidden] { display: none; }

/* ---------- 走路控制列 ---------- */
.nav-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; }
.nav-dest-wrap { min-width: 0; }
.nav-label { font-size: 12px; color: var(--muted); font-weight: 700; }
.nav-dest {
  font-family: var(--font-display);
  font-size: 22px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-meta { flex: none; font-size: 13px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.nav-track {
  position: relative;
  height: 22px;
  margin-top: 10px;
  border: 2px solid var(--btn-line);
  border-radius: 12px;
  background: #dbe6f2;
  overflow: hidden;
}
.nav-bar {
  height: 100%;
  width: 0;
  background: repeating-linear-gradient(-45deg, var(--btn-orange-top) 0 10px, var(--btn-orange-bottom) 10px 20px);
  transition: width 0.3s;
}
.nav-progress {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 13px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.nav-actions { display: flex; gap: 10px; margin-top: 14px; }
.nav-actions .btn {
  flex: 1;
  min-width: 0;
  height: 52px;
  padding: 0 4px;
  font-size: 18px;
}
.nav-actions .btn.go { flex: 2; font-size: 22px; }
.nav-actions button[hidden] { display: none; }

/* ---------- 拖曳把手（手機才顯示；src/sheet.js） ---------- */
.sheet-grip { display: none; }

/* ---------- 回到角色 ---------- */
.fab {
  position: fixed;
  z-index: 2;
  right: 14px;
  bottom: calc(var(--sheet-h, 120px) + var(--kb, 0px) + 14px);
  width: 56px;
  height: 56px;
  min-height: 56px;
  padding: 0;
  border-radius: 50%;
  color: var(--sea);
  font-size: 28px;
  transition: bottom 0.2s, transform 0.08s, box-shadow 0.08s;
}

/* ---------- 抵達的慶祝畫面 ---------- */
.cheer {
  position: fixed;
  z-index: 5;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.cheer-card {
  text-align: center;
  padding: 18px 28px;
  border: var(--btn-line-w) solid var(--btn-line);
  border-radius: 24px;
  background: var(--card);
  box-shadow: 0 8px 0 var(--btn-line), 0 16px 40px rgba(16, 42, 67, 0.3);
  animation: cheer-in 0.45s var(--ease-pop) both, cheer-out 0.35s ease 1.9s forwards;
}
.cheer-title { font-family: var(--font-display); font-size: 30px; font-weight: 400; color: var(--sea); }
.cheer-sub { margin-top: 4px; font-size: 15px; font-weight: 700; color: var(--ribbon-ink); }
.cheer-hex {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 16px;
  height: 18px;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  animation: burst 1.1s ease-out forwards;
}
@keyframes cheer-in { from { transform: scale(0.4); opacity: 0; } }
@keyframes cheer-out { to { transform: translateY(-20px); opacity: 0; } }
@keyframes burst {
  from { transform: translate(-50%, -50%) scale(0.4); opacity: 1; }
  to { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) rotate(var(--r)) scale(1); opacity: 0; }
}

.toast {
  position: fixed;
  z-index: 6;
  left: 50%;
  bottom: calc(min(var(--sheet-h, 120px), 50vh) + var(--kb, 0px) + 84px); /* 在「回到角色」按鈕和綁飄帶浮動列上方 */
  transform: translate(-50%, 20px);
  max-width: calc(100% - 32px);
  padding: 10px 18px;
  border: var(--btn-line-w) solid #fff;
  border-radius: var(--btn-radius);
  background: var(--btn-line);
  color: #fff;
  font-family: var(--font-display);
  font-size: 16px;
  text-align: center;
  box-shadow: 0 4px 0 #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.maplibregl-ctrl-bottom-right, .maplibregl-ctrl-bottom-left { bottom: var(--sheet-h, 0px); }

/* 桌機：面板改成左下角的浮動卡片 */
@media (min-width: 720px) {
  .hud { left: 16px; right: 16px; top: 16px; }
  .sheet, .nav {
    left: 16px;
    right: auto;
    bottom: 16px;
    width: 380px;
    border-bottom: var(--btn-line-w) solid var(--btn-line);
    border-radius: 22px;
    padding: 12px 16px 16px;
    box-shadow: 0 6px 0 var(--btn-line), 0 12px 30px rgba(16, 42, 67, 0.2);
  }
  .fab { right: 20px; bottom: 36px; }
  .toast { bottom: auto; top: 120px; transform: translate(-50%, -20px); }
  .maplibregl-ctrl-bottom-right { bottom: 0; }
}

/* ---------- 全市即時動態（上方，src/trash-votes.js 輪播）：橘色膠囊，內文維持系統字 ---------- */
.ticker {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: min(520px, 100%);
  min-height: 40px;
  padding: 6px 14px;
  background: linear-gradient(180deg, #2c3a4a, var(--btn-line)); /* 深色的即時動態條，橘色小點表示直播中 */
  color: #fff;
  font-family: system-ui, "PingFang TC", "Noto Sans TC", sans-serif;
  font-size: 14px;
  font-weight: 700;
  text-align: left;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
  overflow: hidden;
}
.ticker[hidden] { display: none; }
.ticker:hover:not(:disabled) { filter: brightness(1.06); }
.ticker b { flex: none; max-width: 9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ticker .ticker-what { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* 「現場直播」的小點：一直閃，表示這是即時的 */
.ticker-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--btn-orange-top); animation: ticker-pulse 1.4s ease-in-out infinite; }
.ticker-in { animation: ticker-in 0.35s ease both; }
@keyframes ticker-in { from { transform: translateY(-6px); opacity: 0; } }
@keyframes ticker-pulse { 50% { opacity: 0.25; } }

/* 減少動態：關掉位移與過場，按下去仍然會讓陰影變薄（顏色回饋） */
@media (prefers-reduced-motion: reduce) {
  button,
  .tab,
  .fab { transition: none; }
  button:active:not(:disabled) { transform: none; }
  .hud-stat.bump,
  .ticker-in,
  .ticker-dot { animation: none; }
  .cheer-card { animation: cheer-out 0.3s ease 1.6s forwards; }
  .cheer-hex { display: none; }
}

/* ---------- 手機版（< 720px，和 src/sheet.js 的 innerWidth 判斷相同）：狀態列變薄、底部抽屜、安全區 ---------- */
@media (max-width: 719px) {
  /* 上方狀態列：標題＋數字一行，下面一行放動態或提示（兩者疊在同一格，見 .hud-strip） */
  .hud {
    top: calc(6px + var(--safe-t));
    left: max(10px, env(safe-area-inset-left, 0px));
    right: max(10px, env(safe-area-inset-right, 0px));
    gap: 4px;
  }
  .hud-title { padding: 2px 12px 3px; }
  .hud-name { font-size: 18px; }
  .hud-strip { display: grid; width: 100%; }
  .hud-strip > * { grid-area: 1 / 1; min-width: 0; max-width: 100%; }
  .ticker { width: 100%; min-height: 44px; }
  .quest {
    display: none;
    width: 100%;
    min-height: 44px;
    padding: 9px 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  /* 提示：新訊息 4 秒完整顯示（.fresh）、點一下展開（.open）、或和動態輪流顯示（.turn）；沒有動態時一直顯示一行 */
  .quest:not(:empty).fresh,
  .quest:not(:empty).open,
  .quest:not(:empty).turn,
  .hud-strip:has(#live-ticker[hidden]) .quest:not(:empty) { display: block; }
  .quest.fresh,
  .quest.open { white-space: normal; }
  .hud-strip:has(.quest:not(:empty).fresh) .ticker,
  .hud-strip:has(.quest:not(:empty).open) .ticker,
  .hud-strip:has(.quest:not(:empty).turn) .ticker { visibility: hidden; }

  /* 下方面板：三段式抽屜，高度由 src/sheet.js 設定 */
  .sheet {
    display: flex;
    flex-direction: column;
    bottom: var(--kb, 0px);
    max-height: calc(var(--vvh, 100vh) - 12px);
    padding: 0 max(14px, env(safe-area-inset-right, 0px)) calc(14px + var(--safe-b)) max(14px, env(safe-area-inset-left, 0px));
    overflow: hidden;
  }
  .sheet.settling { transition: height 0.26s ease; }
  .sheet-head { flex: none; padding-top: 14px; touch-action: none; }
  .sheet-body {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    margin-top: 10px;
  }
  .sheet-grip {
    display: block;
    position: absolute;
    top: 0;
    left: 50%;
    width: 88px;
    height: 14px;
    margin-left: -44px;
    touch-action: none;
    cursor: grab;
  }
  .sheet-grip::before {
    content: "";
    position: absolute;
    top: 4px;
    left: 50%;
    width: 44px;
    height: 6px;
    margin-left: -22px;
    border-radius: 3px;
    background: #94a3b8;
  }
  .tab { min-height: 48px; }

  /* 拖曳抽屜時回到角色按鈕直接跟著走，不用過場動畫 */
  .sheet-moving .fab { transition: none; }

  /* 抽屜全開時回到角色按鈕收起來（畫面上方留給地圖） */
  body[data-sheet="full"] .fab { display: none; }

  /* 走路控制列：左右邊界避開 safe area */
  .nav {
    padding-left: max(14px, env(safe-area-inset-left, 0px));
    padding-right: max(14px, env(safe-area-inset-right, 0px));
  }
}

@media (max-width: 719px) and (prefers-reduced-motion: reduce) {
  .sheet.settling { transition: none; }
}

