:root {
  --bg: #0e1116;
  --surface: #171b22;
  --surface-2: #1f2430;
  --text: #eef1f5;
  --muted: #8b94a3;
  --line: #2a303c;
  --to-vi: #ffb454;
  --to-en: #6cb6ff;
  --unsure: #9aa4b2;
  --bad: #ff7b7b;
  --good: #4cd08b;
  --tr-size: 28px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans TC", "Noto Sans", sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; }

/* ---------- 上方狀態列 ---------- */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.status { display: flex; align-items: center; gap: 8px; font-size: 15px; color: var(--muted); min-width: 0; }
.status .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.status[data-state="listening"] { color: var(--text); }
.status[data-state="listening"] .dot { background: var(--good); }
.status[data-state="hearing"] { color: var(--text); }
.status[data-state="hearing"] .dot { background: var(--to-vi); animation: pulse 0.9s ease-in-out infinite; }
.status[data-state="loading"] .dot { background: var(--to-en); animation: pulse 1.2s ease-in-out infinite; }
.status[data-state="error"] { color: var(--bad); }
.status[data-state="error"] .dot { background: var(--bad); }

@keyframes pulse { 50% { transform: scale(1.6); opacity: 0.5; } }

.tools { display: flex; gap: 4px; }
.ghost { background: none; border: 0; padding: 8px 10px; color: var(--muted); font-size: 15px; border-radius: 8px; }
.ghost:active { background: var(--surface); }

.banner { padding: 8px 16px; background: #3a2a14; color: var(--to-vi); font-size: 14px; text-align: center; }

/* ---------- 對話紀錄 ---------- */
main {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px 24px;
  scroll-behavior: smooth;
}

.empty { margin: 18vh 8px 0; text-align: center; color: var(--muted); line-height: 1.8; font-size: 16px; }

.turn {
  margin: 0 0 12px;
  padding: 12px 14px 12px 16px;
  background: var(--surface);
  border-radius: 14px;
  border-left: 5px solid var(--unsure);
  cursor: pointer;
}
.turn[data-tgt="vi"] { border-left-color: var(--to-vi); }
.turn[data-tgt="en"] { border-left-color: var(--to-en); }
.turn[data-status="error"] { border-left-color: var(--bad); }

.chip {
  display: inline-block;
  margin-bottom: 6px;
  padding: 2px 8px;
  font-size: 13px;
  line-height: 1.5;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}
.turn[data-tgt="vi"] .chip { color: var(--to-vi); }
.turn[data-tgt="en"] .chip { color: var(--to-en); }

.tr {
  margin: 0;
  font-size: var(--tr-size);
  font-weight: 650;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.tr.muted { font-size: 18px; font-weight: 500; color: var(--muted); }
.tr.bad { font-size: 18px; font-weight: 500; color: var(--bad); }

.src {
  margin: 8px 0 0;
  font-size: 15px;
  line-height: 1.5;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.fix { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.fix p { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.fix .opts { display: flex; flex-wrap: wrap; gap: 8px; }
.fix button {
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
}
.fix button:active { background: var(--line); }

/* ---------- 下方大按鈕 ---------- */
.dock { padding: 12px 16px calc(12px + var(--safe-b)); border-top: 1px solid var(--line); background: var(--bg); }

.listen {
  width: 100%;
  min-height: 60px;
  border: 0;
  border-radius: 16px;
  background: var(--to-en);
  color: #08121f;
  font-size: 20px;
  font-weight: 700;
}
.listen:active { filter: brightness(0.9); }
.listen[data-on="true"] { background: var(--surface-2); color: var(--text); border: 2px solid var(--good); }

/* ---------- 對話框 ---------- */
dialog {
  width: min(92vw, 420px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }

.sheet { display: flex; flex-direction: column; gap: 8px; padding: 20px; }
.sheet h2 { margin: 0 0 4px; font-size: 20px; }
.sheet label { margin-top: 8px; font-size: 14px; color: var(--muted); }
.sheet input[type="text"], .sheet input[type="password"] {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}
.sheet input[type="range"] { width: 100%; }
.note { margin: 0; font-size: 13px; color: var(--muted); }
.error { margin: 0; font-size: 14px; color: var(--bad); }
.row { display: flex; justify-content: flex-end; margin-top: 12px; }
.primary { padding: 12px 22px; border: 0; border-radius: 10px; background: var(--to-en); color: #08121f; font-weight: 700; font-size: 16px; }

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

/* ---------- 設定裡的帳號區 ---------- */
.account { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.who { margin: 0 0 8px; font-size: 15px; }
.account-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.chip-link {
  display: inline-block;
  padding: 8px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
}
.chip-link:active { background: var(--line); }
.account details { margin-top: 4px; }
.account summary { cursor: pointer; padding: 6px 0; color: var(--muted); font-size: 14px; }
.account details[open] { display: flex; flex-direction: column; gap: 8px; padding-bottom: 6px; }
