/* ──────────────────────────────────────────────
   CSS Custom Properties  (from UI-mockup)
   ────────────────────────────────────────────── */
:root {
  --bg:       #f5f4ef;
  --surface:  #ffffff;
  --panel:    #f1efe8;
  --text:     #2c2c2a;
  --muted:    #5f5e5a;
  --hint:     #888780;
  --line:     rgba(0,0,0,.12);

  --info-bg:     #e6f1fb;
  --info-tx:     #0c447c;
  --info-strong: #185fa5;

  --ok-bg:  #e1f5ee;
  --ok-tx:  #0f6e56;
  --ok-dot: #1d9e75;

  --warn-bg: #faeeda;
  --warn-tx: #854f0b;

  --err-bg: #fde8e8;
  --err-tx: #a32d2d;

  --danger: #a32d2d;
}

/* ──────────────────────────────────────────────
   Reset / Base
   ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", "PingFang TC", "Noto Sans TC", sans-serif;
  line-height: 1.6;
  display: flex;
  justify-content: center;
}

/* Native <hidden> attribute */
[hidden] { display: none !important; }

/* ──────────────────────────────────────────────
   App Shell — full-viewport column layout
   ────────────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 760px;
  height: 100vh;
  background: var(--surface);
  border-left:  .5px solid var(--line);
  border-right: .5px solid var(--line);
}

/* ──────────────────────────────────────────────
   Topbar
   ────────────────────────────────────────────── */
.topbar {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 13px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: .5px solid var(--line);
  font-size: 12.5px;
}

.topbar-brand  { font-weight: 600; }
.sep           { color: var(--hint); }

.topbar-settings {
  margin-left: auto;
  cursor: pointer;
  color: var(--muted);
  user-select: none;
}
.topbar-settings:hover { color: var(--text); }

/* ──────────────────────────────────────────────
   Pills
   ────────────────────────────────────────────── */
.pill {
  padding: 2px 8px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 12.5px;
}
.pill.ok   { background: var(--ok-bg);   color: var(--ok-tx);   }
.pill.info { background: var(--info-bg); color: var(--info-tx); }
.pill.warn { background: var(--warn-bg); color: var(--warn-tx); }
.pill.err  { background: var(--err-bg);  color: var(--err-tx);  }

.topbar-refined {
  cursor: pointer;
  user-select: none;
  transition: background .15s, color .15s;
}
.topbar-refined:not(.info) {
  background: var(--panel);
  color: var(--hint);
}
.topbar-refined:hover { opacity: .8; }

/* Dot indicator (inside pill) */
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok-dot);
  vertical-align: 1px;
  margin-right: 4px;
}

/* ──────────────────────────────────────────────
   Feed wrapper (fills remaining height)
   ────────────────────────────────────────────── */
.feed-wrapper {
  flex: 1;
  min-height: 0;       /* needed for Firefox */
  position: relative;
  overflow: hidden;
}

.feed {
  height: 100%;
  overflow-y: auto;
  padding: 12px 14px;
}

.feedtitle {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

/* Scroll-to-bottom hint */
.scroll-hint {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--info-bg);
  color: var(--info-tx);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 12px;
  border: .5px solid rgba(12,68,124,.18);
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,.08);
  user-select: none;
  transition: opacity .2s;
}
.scroll-hint:hover { opacity: .85; }

/* ──────────────────────────────────────────────
   Conversation Cards
   ────────────────────────────────────────────── */
.card {
  display: flex;
  gap: 10px;
  padding: 10px 0;
  border-bottom: .5px solid var(--line);
  transition: background-color .25s ease;
}
.card:last-child { border-bottom: none; }

/* Timestamp */
.ts {
  font-size: 12px;
  color: var(--hint);
  min-width: 38px;
  padding-top: 1px;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

/* Card body */
.card-body { flex: 1; min-width: 0; }

/* Source text */
.src {
  margin: 0 0 3px;
  font-size: 15px;
  font-weight: 600;
  word-break: break-word;
}

/* Translation text */
.tr {
  margin: 0 0 3px;
  font-size: 14px;
  color: var(--muted);
  word-break: break-word;
}
.tr.tr-pending {
  color: var(--hint);
  font-style: italic;
}

/* Refined translation text */
.refined {
  margin: 0 0 6px;
  font-size: 14px;
  color: var(--info-tx);
  word-break: break-word;
}

/* Refined translation error notice */
.refined-error {
  margin: 2px 0 4px;
  font-size: 12px;
  color: var(--hint);
  font-style: italic;
}

/* Draft card styling */
.card.draft .src {
  font-style: italic;
  font-weight: 400;
  color: var(--muted);
}

/* Flash animation when a draft card becomes final */
@keyframes flash-finalized {
  0%   { background-color: rgba(30, 157, 117, .12); }
  100% { background-color: transparent; }
}
.card.just-finalized {
  animation: flash-finalized .5s ease forwards;
}

/* ──────────────────────────────────────────────
   Badges
   ────────────────────────────────────────────── */
.badge {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 8px;
  margin-right: 4px;
  display: inline-block;
  vertical-align: middle;
}
.b-rt { background: var(--panel);    color: var(--muted);   }
.b-rf { background: var(--info-bg);  color: var(--info-tx); }
.b-dr { background: var(--warn-bg);  color: var(--warn-tx); }

/* ──────────────────────────────────────────────
   Audio Settings Panel
   ────────────────────────────────────────────── */
.audio {
  flex-shrink: 0;
  padding: 13px 14px;
  background: var(--panel);
  border-top: .5px solid var(--line);
}

.audiohd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.audiohd p {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
}

/* Hint text below audio header */
.hint {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--hint);
}

/* Mode radio row */
.modes {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
  font-size: 13px;
}
.mode-option {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 0;
}
.mode-option.on  { font-weight: 600; }
.mode-option.off { color: var(--hint); }
.mode-option:focus-visible { outline: 2px solid var(--info-strong); border-radius: 4px; }

/* Custom radio dot */
.mk {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid #bbb;
  display: inline-block;
  vertical-align: -2px;
  margin-right: 5px;
  flex-shrink: 0;
  transition: border-color .15s, background .15s;
}
.mk.sel {
  border-color: var(--info-strong);
  background: var(--info-strong);
  box-shadow: inset 0 0 0 2px #fff;
}

/* Generic row: label + control */
.row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.row label {
  font-size: 12.5px;
  color: var(--muted);
  min-width: 78px;
  flex-shrink: 0;
}
.row input[type="range"] { flex: 1; }

/* Threshold value display */
.threshold-val {
  font-size: 12.5px;
  min-width: 32px;
}

/* Level Meter */
.meter {
  flex: 1;
  height: 12px;
  border-radius: 8px;
  background: #e3e1d8;
  overflow: hidden;
  position: relative;
}
.meter > i {
  display: block;
  height: 100%;
  background: var(--ok-dot);
  transition: width .05s linear;
  border-radius: 8px;
}
.mark {
  position: absolute;
  top: -2px;
  width: 2px;
  height: 16px;
  background: var(--danger);
  border-radius: 1px;
  pointer-events: none;
}

/* Scale labels under meter */
.scale {
  display: flex;
  justify-content: space-between;
  font-size: 10.5px;
  color: var(--hint);
  padding-left: 88px;   /* label(78px) + gap(10px) */
  margin-top: -6px;
  margin-bottom: 4px;
}

/* Microphone selector */
select {
  padding: 6px 8px;
  border: .5px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
  flex: 1;
  min-width: 0;
  cursor: pointer;
}
select:focus { outline: 2px solid var(--info-strong); }

/* Grey-out wrapper (Manual mode: threshold disabled) */
.grey {
  opacity: .4;
  pointer-events: none;
  user-select: none;
}

/* ──────────────────────────────────────────────
   Speak Button
   ────────────────────────────────────────────── */
.speak {
  font-size: 14px;
  font-weight: 600;
  padding: 8px 22px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: background .15s, transform .08s, box-shadow .15s;
  white-space: nowrap;
}

/* Disabled / Auto mode */
.speak.dis {
  background: #e3e1d8;
  color: #a8a69d;
  cursor: not-allowed;
}

/* Active / Manual mode idle */
.speak.on {
  background: var(--info-strong);
  color: #fff;
}
.speak.on:hover {
  background: #1571bf;
  box-shadow: 0 2px 8px rgba(24,95,165,.35);
}
.speak.on:active {
  transform: scale(.97);
  box-shadow: none;
}

/* Speaking state */
.speak.speaking {
  background: #c0392b;
  color: #fff;
}
.speak.speaking:hover {
  background: #a93226;
  box-shadow: 0 2px 8px rgba(160,44,36,.35);
}
.speak.speaking:active {
  transform: scale(.97);
  box-shadow: none;
}

/* ──────────────────────────────────────────────
   Safety Notice
   ────────────────────────────────────────────── */
.safety {
  flex-shrink: 0;
  padding: 9px 14px;
  background: var(--warn-bg);
  border-top: .5px solid var(--line);
  font-size: 11.5px;
  color: var(--warn-tx);
  line-height: 1.5;
}
.safety .en { padding-left: 6px; }

/* ──────────────────────────────────────────────
   Feed Font-Size Scaling (A− / A+)
   Only active when #feed has class .fs-scaled.
   At scale=1 the class is removed → zero effect on existing declarations.
   ────────────────────────────────────────────── */
#feed.fs-scaled .ts      { font-size: calc(12px * var(--feed-scale, 1)); }
#feed.fs-scaled .src     { font-size: calc(15px * var(--feed-scale, 1)); }
#feed.fs-scaled .tr      { font-size: calc(14px * var(--feed-scale, 1)); }
#feed.fs-scaled .refined { font-size: calc(14px * var(--feed-scale, 1)); }
#feed.fs-scaled .badge   { font-size: calc(11px * var(--feed-scale, 1)); }

/* Font-size control buttons in topbar */
.fs-btn {
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 6px;
  border: .5px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
  line-height: 1.4;
  user-select: none;
  transition: background .15s, color .15s;
}
.fs-btn:hover { background: var(--bg); color: var(--text); }
