/* 以米色（beige）為主的日系配色：低彩度的大地色、淡淡的線條和陰影。
   淺色款：生成米色的背景、奶油白的卡片、亞麻色的自己訊息、胡桃棕的按鈕
   深色款：深焦茶色的背景、深胡桃色的自己訊息、砂米色的按鈕
   每一組「文字／底色」的對比度都 ≥ 4.5，小字也讀得清楚 */
:root {
  color-scheme: light dark; /* 讓勾選框、捲軸這些瀏覽器內建元件也跟著深淺色切換 */
  --bg: #f2ece2;          /* 背景：生成米色 */
  --surface: #faf7f1;     /* 卡片、輸入列：奶油白 */
  --text: #3b342c;        /* 內文：帶暖色的深棕 */
  --muted: #6c6154;       /* 次要文字：時間、已送達、說明 */
  --line: #e2d9cb;        /* 細線、外框 */
  --chip: #ece5d9;        /* 系統訊息、標籤、打字中泡泡的底色 */
  --accent: #7e6347;      /* 強調色（按鈕、離開、送出）：胡桃棕 */
  --accent-ink: #faf7f1;  /* 強調色上的文字 */
  --theirs: #faf7f1;      /* 對方的訊息 */
  --mine: #d9c6ab;        /* 自己的訊息：亞麻色 */
  --mine-ink: #3b342c;
  --warn-bg: #f3e6d3;     /* 提示（例如被封鎖、連線中斷） */
  --warn-ink: #74502a;
  --danger: #a3453a;      /* 警示（確定離開）：低彩度的磚紅 */
  --danger-ink: #faf7f1;
  --shadow: 74 58 40;     /* 陰影和遮罩用暖棕色，不用純黑 */
}

/* 深色款：系統是深色、而且使用者沒有在選單指定「淺色」時套用 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1915;        /* 背景：深焦茶 */
    --surface: #25211c;
    --text: #e8dfd1;      /* 內文：米白 */
    --muted: #a69b8b;
    --line: #3a332a;
    --chip: #312b24;
    --accent: #cdb491;    /* 強調色：砂米色 */
    --accent-ink: #231e18;
    --theirs: #2b2620;
    --mine: #57483a;      /* 自己的訊息：深胡桃 */
    --mine-ink: #f0e7d9;
    --warn-bg: #3a2f22;
    --warn-ink: #e6cda6;
    --danger: #db9286;
    --danger-ink: #231e18;
    --shadow: 0 0 0;
  }
}

/* 使用者在選單指定「深色」：不管系統設定都套用。顏色要和上面那段一致，改一邊要記得改另一邊 */
:root[data-theme="dark"] {
  --bg: #1c1915;        /* 背景：深焦茶 */
  --surface: #25211c;
  --text: #e8dfd1;      /* 內文：米白 */
  --muted: #a69b8b;
  --line: #3a332a;
  --chip: #312b24;
  --accent: #cdb491;    /* 強調色：砂米色 */
  --accent-ink: #231e18;
  --theirs: #2b2620;
  --mine: #57483a;      /* 自己的訊息：深胡桃 */
  --mine-ink: #f0e7d9;
  --warn-bg: #3a2f22;
  --warn-ink: #e6cda6;
  --danger: #db9286;
  --danger-ink: #231e18;
  --shadow: 0 0 0;
}

/* 瀏覽器內建元件（勾選框、捲軸、輸入框）也跟著使用者的選擇，不看系統設定 */
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }

body {
  font-family: system-ui, -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  letter-spacing: 0.02em; /* 字距稍微放寬，看起來比較透氣 */
  text-wrap: pretty; /* 換行時避免最後一行只剩一個字 */
  background: var(--bg);
  color: var(--text);
}

.app {
  max-width: 640px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative; /* 側邊選單以 .app 為範圍，桌機上也貼著聊天區塊左邊 */
  overflow: hidden;
}

/* 頂端列：目前只有管理後台在用（聊天頁面拿掉了，改成左上角浮動的選單按鈕） */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

/* 只給螢幕閱讀器念、畫面上不顯示 */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.conn-banner { background: var(--warn-bg); color: var(--warn-ink); text-align: center; font-size: 13px; padding: 6px 56px; } /* 左右留空間，文字才不會被左上角的選單按鈕擋住 */

main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.center { align-items: center; justify-content: center; text-align: center; padding: 24px; gap: 12px; }
.lead { font-size: 20px; font-weight: 600; margin: 0; }
.sub { color: var(--muted); margin: 0 0 12px; }
.notice { background: var(--warn-bg); color: var(--warn-ink); padding: 10px 14px; border-radius: 12px; font-size: 14px; margin: 0 0 8px; }

button { font: inherit; border: 0; border-radius: 999px; padding: 10px 20px; cursor: pointer; }
button:disabled { opacity: 0.5; cursor: default; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; } /* 用鍵盤操作時的焦點框，用主題色，不用瀏覽器預設的藍色 */
.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; letter-spacing: 0.08em; }
.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.big { padding: 14px 44px; font-size: 18px; }
.small { padding: 6px 14px; font-size: 14px; }

.spinner {
  width: 40px; height: 40px;
  border: 4px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.phrase-chip { margin: 0; padding: 4px 14px; border-radius: 999px; background: var(--chip); font-size: 14px; overflow-wrap: anywhere; }

/* ---- 左上角選單按鈕 ---- */
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
}
.icon-btn:hover { background: var(--chip); }
.icon-btn:focus-visible, .drawer-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.topbar .icon-btn { margin-left: -6px; }

/* 聊天頁面沒有頂端列：選單按鈕浮在左上角。加上底色和細框，訊息捲到它下面時也看得清楚 */
.menu-fab {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top));
  left: calc(8px + env(safe-area-inset-left));
  z-index: 5; /* 在訊息上面，在側邊選單的遮罩下面 */
  width: 40px;
  height: 40px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 2px 8px rgb(var(--shadow) / 0.08);
}

/* ---- 側邊選單：平常藏在左邊外面，加上 .drawer-open 時滑進來 ---- */
.backdrop {
  position: absolute;
  inset: 0;
  z-index: 10;
  background: rgb(var(--shadow) / 0.35);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0s linear 0.25s; /* 等淡出播完才真的隱藏 */
}
.drawer {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 11;
  width: min(300px, 85%);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
  box-shadow: 4px 0 24px rgb(var(--shadow) / 0.14);
  transform: translateX(-100%);
  visibility: hidden; /* 收起時不能被 Tab 到、螢幕閱讀器也不會念 */
  transition: transform 0.25s ease, visibility 0s linear 0.25s;
}
.drawer-open .backdrop { opacity: 1; visibility: visible; transition: opacity 0.25s ease; }
.drawer-open .drawer { transform: none; visibility: visible; transition: transform 0.25s ease; }
@media (prefers-reduced-motion: reduce) {
  .drawer, .backdrop { transition: none !important; }
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 10px 12px 16px;
  border-bottom: 1px solid var(--line);
}
.drawer-title { font-weight: 600; font-size: 16px; }
.drawer-body { padding: 8px; overflow-y: auto; }

.drawer-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  text-align: left;
}
.drawer-item:hover, .drawer-item[aria-expanded="true"] { background: var(--chip); }
.drawer-item svg { flex-shrink: 0; color: var(--accent); }
.drawer-item strong { display: block; font-weight: 600; }
.drawer-item small { display: block; margin-top: 2px; font-size: 12px; color: var(--muted); }

.drawer-item[aria-disabled="true"] { opacity: 0.55; cursor: default; }

/* ---- 選單裡的分隔區塊（使用說明） ---- */
.drawer-section { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }

/* ---- 選單裡的「外觀」：跟隨系統／淺色／深色，三個並排的文字選項 ---- */
.theme-picker { margin-top: 8px; padding: 14px 12px 8px; border-top: 1px solid var(--line); }
.drawer-label { margin: 0 0 10px; font-weight: 600; }
.segmented { display: flex; gap: 4px; padding: 4px; border-radius: 12px; background: var(--chip); }
.segmented label { position: relative; flex: 1; cursor: pointer; }
.segmented input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; } /* 看不到，但點得到、鍵盤選得到 */
.segmented span { display: block; padding: 8px 4px; border-radius: 9px; text-align: center; font-size: 14px; color: var(--muted); }
.segmented label:hover span { color: var(--text); }
.segmented input:checked + span { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgb(var(--shadow) / 0.12); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.drawer-item[aria-disabled="true"]:hover { background: transparent; }

/* ---- 主畫面：密語欄位＋開始聊天 ---- */
/* ---- 首頁：「標誌＋標語」一組、「開始聊天」一組。組內靠近、組間拉開 ---- */
#view-idle { gap: 52px; padding-bottom: calc(24px + 8vh); } /* 下方多留一點，整組略高於正中間（視覺上的中心） */
.hero { display: flex; flex-direction: column; align-items: center; gap: 18px; }
/* 標誌：圓相用強調色，BeigeTalk 和米語用內文色，中間的細線用淡一點的次要文字色，跟著淺色／深色（包括使用者自己選的外觀）。
   畫面太窄時（例如 320 寬的手機）跟著縮小，不會超出畫面 */
.brand { display: block; width: 329px; max-width: 100%; height: auto; aspect-ratio: 328.6 / 50; flex-shrink: 0; }
.brand-rule { fill: none; stroke: var(--muted); stroke-opacity: 0.45; stroke-width: 1; vector-effect: non-scaling-stroke; }
/* 標語：字距放寬；左邊補上同樣的字距，抵銷最後一個字後面多出來的空白，才會真正置中 */
.tagline { margin: 0; padding-left: 0.16em; font-size: 16px; letter-spacing: 0.16em; color: var(--muted); }
.brand-mark { fill: var(--accent); }
.brand-stroke { stroke: var(--accent); }
.brand-text { fill: var(--text); }

.start-form { display: flex; flex-direction: column; align-items: center; gap: 16px; width: 100%; max-width: 320px; }
.phrase-field { display: flex; flex-direction: column; gap: 6px; width: 100%; text-align: left; }
.start-form .notice { margin: 0; }
/* 提示下面的文字按鈕（例如「回報」）：自己一行，跟著提示的文字顏色，只加底線，沒有框 */
.notice-link { display: block; margin: 6px auto 0; padding: 0; border-radius: 4px; background: none; color: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.notice-link:focus-visible { outline-offset: 2px; }
.notice-sub { display: block; margin-top: 6px; font-size: 13px; opacity: 0.85; } /* 例如「已送出申訴」 */
.start-form .phrase-field { margin-bottom: 8px; }
/* 人機驗證框：平常是空的（高度 0），用負的下邊距抵掉表單的間距；Cloudflare 要使用者點一下時才出現（app.js 加上 .shown） */
.human-check { margin-bottom: -16px; }
.human-check.shown { margin-bottom: 0; }
/* 密語欄：提示文字直接寫在欄位裡，右邊的叉叉是「不用密語」 */
.phrase-box {
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}
.phrase-box:focus-within { outline: 2px solid var(--accent); outline-offset: -1px; }
.phrase-box input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 18px;
  padding: 14px 4px 14px 18px;
  border: 0;
  background: transparent;
  color: var(--text);
}
.phrase-box input:focus { outline: none; } /* 外框已經用 :focus-within 標示 */
.phrase-box input::placeholder { color: var(--accent); opacity: 0.85; }
.phrase-off {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  margin-right: 6px;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--accent);
}
.phrase-off:hover { background: var(--chip); }
.phrase-off:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }
.link-btn { padding: 4px 2px; border-radius: 6px; background: transparent; color: var(--muted); font-size: 13px; text-decoration: underline; text-underline-offset: 3px; }
.link-btn:hover { color: var(--text); }
.link-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hint { margin: 0; font-size: 12px; line-height: 1.5; letter-spacing: 0; color: var(--muted); } /* 小字不加寬字距 */
.hint.error { color: var(--warn-ink); background: var(--warn-bg); padding: 6px 10px; border-radius: 8px; }

.messages {
  list-style: none;
  margin: 0;
  padding: 56px 16px 16px; /* 上方留出左上角選單按鈕的位置，第一則才不會被蓋住 */
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
/* 每則訊息：泡泡旁邊放小字（自己的訊息在左邊，對方的在右邊） */
.msg { display: flex; flex-direction: column; align-items: flex-start; max-width: 82%; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg .line { display: flex; align-items: flex-end; gap: 6px; max-width: 100%; }
.mine .line { flex-direction: row-reverse; } /* 自己的訊息：泡泡在右，小字在左 */
.bubble {
  padding: 9px 13px;
  border-radius: 18px;
  background: var(--theirs);
  border: 1px solid var(--line);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.45;
}
.mine .bubble { background: var(--mine); color: var(--mine-ink); border-color: transparent; }
/* 泡泡旁邊的小字（已傳送／已送達在上、時間在下），和泡泡底部對齊 */
.meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  flex-shrink: 0;
  padding-bottom: 2px;
  font-size: 11px;
  line-height: 1.35;
  color: var(--muted);
  white-space: nowrap;
}
.mine .meta { align-items: flex-end; } /* 自己的訊息：小字靠右，貼近泡泡 */
/* 「已傳送」「已送達」和時間同樣是灰色，只靠文字區分 */
.system {
  align-self: center;
  font-size: 12px;
  color: var(--muted);
  background: var(--chip);
  padding: 4px 12px;
  border-radius: 999px;
  text-align: center;
}

/* 對方打字中：放在對話最後面的灰色泡泡，裡面三個點輪流變深再變淺（泡泡本身不閃動） */
.typing-bubble {
  position: relative;
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px; /* 留位置給左下角的小圓點（左邊的位置由訊息清單的留白提供） */
  padding: 15px 16px;
  border-radius: 999px;
  background: var(--chip);
}
.typing-bubble::after {
  /* 左下角的小圓點，像對話泡泡的尾巴 */
  content: '';
  position: absolute;
  left: -6px;
  bottom: -6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--chip);
}
.typing-bubble .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.35;
  animation: typing-dot 1.2s ease-in-out infinite;
}
.typing-bubble .dot:nth-child(2) { animation-delay: 0.2s; }
.typing-bubble .dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-dot {
  0%, 60%, 100% { opacity: 0.35; }
  30% { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .typing-bubble .dot { animation: none; opacity: 0.6; } /* 不想看動畫的人：三個點靜止 */
}
.composer {
  display: flex;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.composer input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 16px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
}
.composer input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
/* 離開、送出：只有文字，沒有外框和底色 */
.composer .text-btn {
  flex-shrink: 0;
  padding: 10px 6px;
  border-radius: 8px;
  background: transparent;
  color: var(--accent);
  font-weight: 600;
}
.composer .text-btn:hover:not(:disabled) { opacity: 0.75; }
.composer .text-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }

/* ---- 離開確認視窗 ---- */
.dialog {
  width: min(340px, calc(100% - 32px));
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 12px 40px rgb(var(--shadow) / 0.2);
}
.dialog::backdrop { background: rgb(var(--shadow) / 0.4); }
.dialog[open] { animation: dialog-in 0.16s ease-out; }
.dialog[open]::backdrop { animation: fade-in 0.16s ease-out; }
@keyframes dialog-in { from { opacity: 0; transform: scale(0.96); } }
@keyframes fade-in { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .dialog[open], .dialog[open]::backdrop { animation: none; }
}
.dialog form { display: flex; flex-direction: column; gap: 8px; padding: 22px 20px 18px; }
.dialog h2 { margin: 0; font-size: 18px; }
.dialog p { margin: 0 0 12px; font-size: 14px; line-height: 1.55; color: var(--muted); }
.dialog-actions { display: flex; gap: 10px; }
.dialog-actions button { flex: 1; }
.dialog-actions button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.danger { background: var(--danger); color: var(--danger-ink); font-weight: 600; }

/* 離開確認、檢舉視窗的按鈕：只有文字，沒有外框和底色 */
.dialog-actions.text-actions { gap: 2px; margin: 4px -10px -8px; }
.dialog-actions.text-actions button {
  flex: 0 0 auto;
  padding: 8px 12px;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  font-weight: 600;
}
.dialog-actions.text-actions button:hover { background: var(--chip); }
.dialog-actions.text-actions .push { margin-left: auto; } /* 把後面的按鈕推到右邊 */
.dialog-actions.text-actions .confirm { color: var(--danger); }

/* ---- 檢舉視窗 ---- */
.dialog.report { width: min(400px, calc(100% - 32px)); max-height: calc(100dvh - 32px); overflow-y: auto; }
.report form { gap: 10px; }
.report-reasons { display: flex; flex-direction: column; gap: 12px; margin: 4px 0 0; padding: 0; border: 0; }
.report-reasons label { display: flex; align-items: center; gap: 10px; font-size: 15px; cursor: pointer; }
.report-reasons input { width: 20px; height: 20px; margin: 0; flex-shrink: 0; accent-color: var(--accent); }
.report-label { margin: 10px 0 0; font-size: 16px; font-weight: 600; }
#report-note, #appeal-text {
  font: inherit;
  font-size: 16px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
}
#report-note:focus, #appeal-text:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---- 申訴視窗（沿用檢舉視窗的大小和間距）---- */
#appeal-text { min-height: 132px; line-height: 1.6; resize: vertical; }
.appeal .count { margin: -4px 0 0; text-align: right; font-variant-numeric: tabular-nums; }
.transcript {
  list-style: none;
  margin: 0;
  padding: 10px 12px;
  max-height: 190px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  font-size: 14px;
  line-height: 1.6;
}
.transcript li { white-space: pre-wrap; overflow-wrap: anywhere; }
.transcript .who { color: var(--muted); }
.transcript .empty { color: var(--muted); }
.report .hint.error { margin: 0; }
.report .dialog-actions { margin-top: 8px; }
.report .dialog-actions button { white-space: nowrap; }

/* ---- 使用說明：從選單打開的全畫面面板（桌機上是置中的大視窗） ---- */
.sheet {
  width: 100%;
  max-width: 640px;
  height: 100%;
  max-height: 100%;
  margin: 0 auto;
  padding: 0;
  border: 0;
  background: var(--bg);
  color: var(--text);
}
.sheet[open] { display: flex; flex-direction: column; animation: dialog-in 0.16s ease-out; }
.sheet::backdrop { background: rgb(var(--shadow) / 0.4); }
@media (min-width: 700px) {
  .sheet { height: min(780px, calc(100% - 48px)); margin: auto; border-radius: 18px; box-shadow: 0 12px 40px rgb(var(--shadow) / 0.2); }
}
@media (prefers-reduced-motion: reduce) {
  .sheet[open] { animation: none; }
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 10px 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.sheet-head h2 { margin: 0; font-size: 18px; font-weight: 600; }
.sheet-body { flex: 1; overflow-y: auto; padding: 4px 20px calc(32px + env(safe-area-inset-bottom)); line-height: 1.75; }
.sheet-body h3 { margin: 24px 0 6px; font-size: 16px; font-weight: 600; }
.sheet-body p, .sheet-body ul, .sheet-body ol { margin: 0 0 8px; }
.sheet-body ul, .sheet-body ol { padding-left: 1.4em; }
.sheet-body li + li { margin-top: 4px; }
.terms-callout { margin-top: 20px; padding: 2px 18px 10px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.terms-callout h3 { margin-top: 14px; }
.text-link { color: var(--accent); font-weight: 600; text-underline-offset: 3px; }
.text-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.link-note { font-size: 13px; color: var(--muted); }

/* ---- 使用條款頁面（/terms，內容來自 docs/terms.md） ---- */
.doc-page { height: auto; min-height: 100%; }
.doc { max-width: 720px; margin: 0 auto; padding: calc(24px + env(safe-area-inset-top)) 20px 64px; line-height: 1.8; }
.doc-back { display: inline-block; margin-bottom: 8px; color: var(--accent); font-weight: 600; text-underline-offset: 3px; }
.doc h1 { margin: 16px 0 4px; font-size: 26px; font-weight: 600; letter-spacing: 0.04em; }
.doc h2 { margin: 36px 0 10px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 18px; font-weight: 600; }
.doc p, .doc ol, .doc ul { margin: 0 0 12px; }
.doc ol, .doc ul { padding-left: 1.4em; }
.doc li + li { margin-top: 6px; }
.doc li > ul { margin: 6px 0 0; }
/* 表格：手機上太寬就在自己的框裡左右捲動，不會撐開整個頁面 */
.doc table { display: block; overflow-x: auto; margin: 0 0 16px; border-collapse: collapse; font-size: 14px; line-height: 1.6; }
.doc th, .doc td { padding: 10px 12px; border: 1px solid var(--line); text-align: left; vertical-align: top; min-width: 7em; }
.doc th { background: var(--chip); font-weight: 600; }
.doc td { background: var(--surface); }
.doc a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---- 系統故障畫面：蓋在整個畫面上（伺服器當機、無法連線、資料庫連不上時） ---- */
.outage {
  position: absolute;
  inset: 0;
  z-index: 20; /* 蓋過選單按鈕和側邊選單 */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px 24px calc(24px + 8vh); /* 和首頁一樣略高於正中間 */
  background: var(--bg);
  text-align: center;
}
.outage-mark { width: 72px; height: 72px; margin-bottom: 12px; }
/* keep-all：只在空格和標點處換行（「系統」不會被拆成兩行） */
.outage-title { margin: 0; max-width: 20em; font-size: 20px; font-weight: 600; letter-spacing: 0.04em; line-height: 1.6; word-break: keep-all; }
.outage-sub { margin: 0 0 16px; max-width: 22em; color: var(--muted); font-size: 15px; line-height: 1.7; word-break: keep-all; }

/* ---- 同意使用條款的視窗 ---- */
.consent { width: min(400px, calc(100% - 32px)); }
.consent form { max-height: calc(100dvh - 48px); overflow-y: auto; }
.consent-points { margin: 0 0 12px; padding-left: 1.3em; font-size: 14px; line-height: 1.65; }
.consent-points li + li { margin-top: 6px; }
.consent-check { display: flex; align-items: flex-start; gap: 10px; margin: 4px 0 8px; padding: 12px 14px; border-radius: 12px; background: var(--chip); font-size: 14px; line-height: 1.55; cursor: pointer; }
.consent-check input { width: 20px; height: 20px; margin: 0; flex-shrink: 0; accent-color: var(--accent); }
.consent-check input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.dialog-actions.text-actions .agree { color: var(--accent); }
.consent h2 { word-break: keep-all; } /* 在逗號處換行，不會把「條款」拆開 */
/* 小螢幕上視窗放不下時，內容捲動，按鈕固定在底部，一定看得到「同意並開始聊天」 */
.consent .dialog-actions {
  position: sticky;
  bottom: -18px; /* 抵銷表單底部的留白，貼齊視窗底邊 */
  margin-bottom: -18px;
  padding: 10px 10px 18px;
  background: var(--surface); /* 捲動時蓋住下面的內容 */
}
