:root {
  /* Ichie — 和紙、墨色與小巴綠：綠底白字編號牌是唯一主角；Logo 圓相保留朱紅印章 */
  --paper: #F5F2EB;
  --card: #FFFFFF;
  --ink: #1E1B18;
  --muted: #655D55;
  --line: #DDD6CA;
  --brand: #0E6B47;        /* 小巴綠：編號牌、主按鈕、White */
  --brand-soft: #DCEBE3;
  --red: #B8322A;          /* Bad、危險操作：朱紅（與 logo 印章同色） */
  --red-soft: #F6E3DF;
  --slate: #5B6670;
  --slate-soft: #E5E8EA;
  --focus: #C58A00;
  --plate-text: #FFFFFF;
  --radius-s: 6px;
  --radius-m: 12px;
  --cjk: "PingFang HK", "Noto Sans HK", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  --code: "Shippori Mincho B1", "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif TC", serif;
  color-scheme: light dark;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #161311; --card: #201C19; --ink: #EFEAE2; --muted: #ABA196; --line: #3A332D;
    --brand: #2E9A6C; --brand-soft: #1C3A2D; --red: #E5555C; --red-soft: #3D2224;
    --slate: #97A3AC; --slate-soft: #2A2F33;
  }
}
:root[data-theme="dark"] {
  --paper: #161311; --card: #201C19; --ink: #EFEAE2; --muted: #ABA196; --line: #3A332D;
  --brand: #2E9A6C; --brand-soft: #1C3A2D; --red: #E5555C; --red-soft: #3D2224;
  --slate: #97A3AC; --slate-soft: #2A2F33;
}
*, *::before, *::after { box-sizing: inherit; }
html { height: 100%; scroll-padding-top: env(safe-area-inset-top, 0px); }
body {
  margin: 0; min-height: 100%; background: var(--paper); color: var(--ink);
  font: 16px/1.6 var(--cjk); -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); }
img, svg { max-width: 100%; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

/* ---------- 頂欄／底欄 ---------- */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: var(--paper); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 6px; text-decoration: none; color: var(--ink); }
.brand-mark { width: 28px; height: 28px; display: block; align-self: center; }
.brand-name { font: 700 22px/1 var(--code); letter-spacing: .02em; }
.topbar-title { color: var(--muted); font-size: 14px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.topbar-login { margin-left: auto; flex: none; font-size: 14px; font-weight: 600; color: var(--brand); text-decoration: none; padding: 6px 2px; }
.topbar-login[hidden] { display: none; }

main:focus, main:focus-visible { outline: none; }
main { max-width: 640px; margin: 0 auto; padding: 16px 16px 104px; outline: none; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; padding: 8px 0 10px; font-size: 12px; color: var(--muted); text-decoration: none; }
.tabbar a .ti { font-size: 18px; line-height: 1.2; }
.tabbar a[aria-current="page"] { color: var(--brand); font-weight: 600; }
body.no-nav .tabbar, body.chat-open .tabbar { display: none; }
/* 未登入訪客：底部選單只顯示「探索」（BR-PUB-02） */
body.guest .tabbar a.auth-only, body.guest .tabbar #admin-tab { display: none; }

/* ---------- 編號牌（主角） ---------- */
.plate {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--brand); color: var(--plate-text);
  font: 700 18px/1 var(--code); letter-spacing: .08em;
  padding: 5px 9px 4px; border-radius: var(--radius-s);
}
.plate .av { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; letter-spacing: 0; }
.plate.big {
  font-size: 64px; letter-spacing: .12em; padding: 14px 22px 10px; border-radius: var(--radius-m);
  box-shadow: inset 0 0 0 3px rgba(255,255,255,.85), inset 0 0 0 6px var(--brand);
}
.plate.big .av { width: 52px; height: 52px; font-size: 30px; }
.plate.name { font-family: var(--cjk); font-size: 15px; letter-spacing: 0; font-weight: 700; }
.mycode { text-align: center; margin: 8px 0 20px; }
.mycode p { margin: 8px 0 0; color: var(--muted); font-size: 14px; }

/* ---------- 版面元件 ---------- */
h1 { font-size: 24px; line-height: 1.3; margin: 4px 0 8px; }
h2 { font-size: 17px; margin: 28px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 12px; }

.list { list-style: none; margin: 0; padding: 0; }
.item {
  display: block; text-decoration: none; color: inherit;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-m);
  padding: 14px; margin-bottom: 10px;
}
.item-title { font-weight: 700; font-size: 17px; margin: 6px 0 2px; }
.item-meta { color: var(--muted); font-size: 14px; }
.cat { font-weight: 700; color: var(--brand); font-size: 14px; }

.chip {
  display: inline-block; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 999px; padding: 4px 12px; font-size: 14px; cursor: pointer; font-family: inherit;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.chips > * { flex: 0 0 auto; white-space: nowrap; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.tag { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 6px; }
.badge { font-size: 12px; font-weight: 700; padding: 1px 8px; border-radius: 4px; }
.badge.ok { background: var(--brand-soft); color: var(--brand); }
.badge.warn { background: var(--red-soft); color: var(--red); }
.badge.neutral { background: var(--slate-soft); color: var(--slate); }
.badge.women { display: inline-block; margin-top: 4px; background: var(--brand-soft); color: var(--brand); }
.notice.women { border-left-color: var(--brand); background: var(--brand-soft); }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 14px; }
.notice { border-left: 4px solid var(--brand); background: var(--brand-soft); padding: 10px 12px; border-radius: 0 var(--radius-s) var(--radius-s) 0; font-size: 14px; }

.people { list-style: none; margin: 0; padding: 0; }
.people li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.people li:last-child { border-bottom: 0; }
.score { font-size: 14px; color: var(--muted); white-space: nowrap; }

/* 神秘統計 */
.bars { display: grid; grid-template-columns: 64px 1fr 28px; gap: 6px 10px; align-items: center; font-size: 14px; }
.bar { height: 10px; background: var(--slate-soft); border-radius: 5px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brand); }

/* 表單 */
label.f { display: block; margin-bottom: 14px; }
label.f > span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius-s); padding: 10px 12px;
}
textarea { min-height: 80px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.checks label { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 4px 12px; font-size: 14px; }
.checks input { width: auto; }

.btn {
  display: inline-flex; justify-content: center; align-items: center; gap: 6px;
  font: 600 16px/1 var(--cjk); border: 0; border-radius: var(--radius-s); padding: 13px 18px; cursor: pointer;
  background: var(--brand); color: #fff; text-decoration: none;
}
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--red); border: 1px solid var(--red); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.actions { display: grid; gap: 10px; margin-top: 20px; }

/* 地圖 */
.map { height: 260px; border-radius: var(--radius-m); border: 1px solid var(--line); overflow: hidden; z-index: 0; }
.results { list-style: none; margin: 6px 0 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--card); max-height: 220px; overflow-y: auto; }
.results li button { all: unset; display: block; width: 100%; box-sizing: border-box; padding: 10px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.results li button:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }
.results small { display: block; color: var(--muted); }

/* 互評 */
.stars { display: flex; gap: 4px; }
.stars button { all: unset; cursor: pointer; font-size: 30px; line-height: 1; color: var(--line); padding: 2px; }
.stars button.on { color: var(--focus); }
.stars button:focus-visible { outline: 3px solid var(--focus); border-radius: 4px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; }
.seg button { all: unset; text-align: center; padding: 8px 4px; cursor: pointer; font-size: 14px; background: var(--card); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"][data-v="white"] { background: var(--brand); color: #fff; }
.seg button[aria-pressed="true"][data-v="fate"] { background: var(--slate); color: #fff; }
.seg button[aria-pressed="true"][data-v="bad"] { background: var(--red); color: #fff; }
.seg button:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }
.hint { font-size: 13px; color: var(--brand); margin-top: 6px; }

/* 登入 */
.hero { padding: 32px 0 12px; }
.hero h1 { font-size: 30px; margin-bottom: 4px; }
.hero .tagline { margin: 0 0 12px; font-weight: 600; color: var(--brand); }
.hero .plate.big { margin-bottom: 18px; }

.empty { text-align: center; padding: 40px 12px; color: var(--muted); }
.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: var(--radius-s);
  font-size: 14px; max-width: calc(100% - 32px); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50;
}
.toast.show { opacity: 1; }
.update-bar {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--brand); color: #fff; border: 0; padding: 10px 16px; border-radius: var(--radius-s);
  font: inherit; font-size: 14px; font-weight: 600; max-width: calc(100% - 32px); cursor: pointer; z-index: 49;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .15);
}

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

/* 舉報 */
.linkbtn { all: unset; cursor: pointer; font-size: 13px; color: var(--muted); text-decoration: underline; padding: 6px 4px; }
.linkbtn:focus-visible { outline: 3px solid var(--focus); border-radius: 4px; }
.linkbtn[hidden] { display: none; }
dialog { border: 1px solid var(--line); border-radius: var(--radius-m); background: var(--card); color: var(--ink); padding: 20px; width: min(92vw, 440px); }
dialog::backdrop { background: rgba(0,0,0,.45); }
.notice.danger { border-left-color: var(--red); background: var(--red-soft); }

/* 管理頁 */
.tabbar a[hidden] { display: none; }
.adm-tabs { display: flex; gap: 8px; overflow-x: auto; margin: 4px 0 16px; }
.adm-tabs a { flex: 0 0 auto; text-decoration: none; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink); background: var(--card); font-size: 14px; }
.adm-tabs a[aria-current="page"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.adm-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 12px 14px; margin-bottom: 10px; }
.adm-card.alert { border-left: 4px solid var(--red); }
.adm-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 14px; }
.adm-kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.adm-kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 12px; }
.adm-kpi b { display: block; font-size: 24px; font-family: var(--code); }
.adm-kpi span { font-size: 13px; color: var(--muted); }
.adm-bars { display: grid; grid-template-columns: 58px 1fr 36px; gap: 4px 8px; align-items: center; font-size: 13px; }
.adm-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.adm-table td, .adm-table th { border-bottom: 1px solid var(--line); padding: 6px 4px; text-align: left; vertical-align: top; }
.adm-pre { white-space: pre-wrap; font-size: 13px; }

/* 聊天室 */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.chat-list { list-style: none; margin: 12px 0 0; padding: 0 0 76px; display: grid; gap: 12px; }
.msg { max-width: 86%; justify-self: start; }
.msg.mine { justify-self: end; text-align: right; }
.msg-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }
.msg.mine .msg-head { justify-content: flex-end; }
.msg-head .plate { font-size: 14px; padding: 3px 7px 2px; }
.msg-head .plate .av { width: 18px; height: 18px; font-size: 11px; }
.msg-text { display: inline-block; text-align: left; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 8px 12px; }
.msg.mine .msg-text { background: var(--brand-soft); border-color: transparent; }
.msg-img { all: unset; cursor: zoom-in; display: block; width: min(260px, 70vw); max-height: 360px; background: var(--slate-soft); border-radius: var(--radius-m); overflow: hidden; margin-top: 4px; }
.msg.mine .msg-img { margin-left: auto; }
.msg-img img { display: block; width: 100%; height: 100%; object-fit: cover; }
.msg-img:focus-visible { outline: 3px solid var(--focus); }
.msg-act { min-height: 4px; }
.msg-act .linkbtn { font-size: 12px; padding: 2px 4px; }
.chat-form { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; display: flex; gap: 8px; align-items: flex-end;
  max-width: 640px; margin: 0 auto; padding: 8px 16px calc(8px + env(safe-area-inset-bottom, 0px)); background: var(--paper); border-top: 1px solid var(--line); }
.chat-form[hidden] { display: none; }
.chat-form textarea { min-height: 42px; max-height: 160px; flex: 1; resize: none; }
.chat-form .btn { flex: none; }
.chat-pick { flex: none; display: grid; place-items: center; width: 42px; height: 42px; border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--card); cursor: pointer; font-size: 22px; }
.chat-pick:focus-within { outline: 3px solid var(--focus); }
.img-dlg { width: min(96vw, 900px); padding: 12px; }
.img-dlg img { display: block; max-width: 100%; max-height: 78vh; margin: 0 auto 12px; }

/* ---------- en 版（APP_LOCALE=en，<html lang="en">）：英文字體；英文標籤較長，統計欄加闊 ---------- */
:root[lang="en"] {
  --cjk: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --code: "Source Serif 4", Georgia, "Times New Roman", serif;
}
:root[lang="en"] .bars { grid-template-columns: 128px 1fr 28px; }
:root[lang="en"] .adm-bars { grid-template-columns: 96px 1fr 36px; }
:root[lang="en"] .grid2 > * { min-width: 0; } /* 英文日期時間輸入較闊，避免撐出畫面 */
