:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #e3e3e8;
  --red: #d7263d;
  --red-dark: #a61b2e;
  --blue: #1565c0;
  --blue-dark: #0d47a1;
  --zh: #b3001b;
  --nav-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111114;
    --card: #1e1e22;
    --text: #f2f2f5;
    --muted: #9a9aa2;
    --line: #2e2e34;
    --zh: #ff6b7d;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
}
button, input, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 14px; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: var(--red); color: #fff;
}
.top h1 { font-size: 18px; margin: 0; flex: 1; }
.top h1 span { font-weight: 600; }
.net { font-size: 12px; background: rgba(0,0,0,.25); padding: 2px 8px; border-radius: 10px; }
.net:empty { display: none; }
.icon-btn { background: none; border: 0; font-size: 22px; padding: 4px; }

main { padding: 12px 16px calc(var(--nav-h) + var(--safe-b) + 16px); }
.tab { display: none; }
.tab.active { display: block; }
#tab-translate { padding-bottom: 210px; }

/* ---------- history cards ---------- */
.history { display: flex; flex-direction: column-reverse; gap: 10px; }
.card {
  background: var(--card); border-radius: 16px; padding: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.msg .src { color: var(--muted); font-size: 15px; margin-bottom: 6px; }
.msg .dst { font-size: 24px; font-weight: 600; line-height: 1.35; }
.msg .dst.zh { color: var(--zh); font-size: 28px; }
.msg .py { color: var(--muted); font-size: 15px; margin-top: 4px; font-style: italic; }
.msg .who { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; margin-bottom: 4px; }
.msg.from-vi .who { color: var(--red); }
.msg.from-zh .who { color: var(--blue); }
.msg .acts { display: flex; gap: 8px; margin-top: 10px; }
.msg.pending .dst { color: var(--muted); font-size: 18px; font-weight: 400; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; line-height: 1.5; }

.btn {
  border: 1px solid var(--line); background: var(--card);
  border-radius: 12px; padding: 10px 14px; font-weight: 600;
}
.btn.small { padding: 8px 12px; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn:active { transform: scale(.97); }

/* ---------- composer ---------- */
.composer {
  position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + var(--safe-b));
  background: var(--bg); border-top: 1px solid var(--line);
  padding: 10px 16px 12px; z-index: 4;
}
.text-row { display: flex; gap: 8px; margin-bottom: 10px; }
.text-row input {
  flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--card);
  border-radius: 12px; padding: 10px 12px; font-size: 16px;
}
.dir { border: 0; border-radius: 12px; padding: 0 10px; background: var(--line); font-weight: 700; font-size: 14px; }
.mics { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mic {
  border: 0; border-radius: 20px; color: #fff; height: 110px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  box-shadow: 0 4px 12px rgba(0,0,0,.15); user-select: none; -webkit-user-select: none;
}
.mic.vi { background: var(--red); }
.mic.zh { background: var(--blue); }
.mic-ico { font-size: 30px; }
.mic-label { font-size: 20px; font-weight: 700; }
.mic-sub { font-size: 13px; opacity: .85; }
.mic.recording { animation: pulse 1s infinite; background: #222 !important; }
.mic.busy { opacity: .6; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(215,38,61,.6); } 50% { box-shadow: 0 0 0 14px rgba(215,38,61,0); } }

/* ---------- phrases ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 20px; padding: 8px 14px; font-weight: 600; white-space: nowrap; }
.chip.active { background: var(--red); color: #fff; border-color: var(--red); }
.list { display: flex; flex-direction: column; gap: 8px; }
.phrase { text-align: left; border: 0; width: 100%; }
.phrase .vi { font-size: 15px; color: var(--muted); }
.phrase .zh { font-size: 22px; font-weight: 600; color: var(--zh); margin-top: 2px; }
.phrase .py { font-size: 13px; color: var(--muted); font-style: italic; }

/* ---------- places ---------- */
.form { display: flex; flex-direction: column; gap: 10px; }
.form input, .form textarea {
  border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 10px 12px; font-size: 16px; width: 100%;
}
.place .name { font-weight: 700; }
.place .addr { font-size: 20px; color: var(--zh); margin: 4px 0 8px; }
.place .acts { display: flex; gap: 8px; }

/* ---------- tabs ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabs button { border: 0; background: none; font-size: 22px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); }
.tabs button span { font-size: 12px; font-weight: 600; }
.tabs button.active { color: var(--red); }

/* ---------- big screen ---------- */
.big {
  position: fixed; inset: 0; z-index: 20; background: #fff; color: #111;
  display: flex; flex-direction: column;
  padding: calc(env(safe-area-inset-top, 0px) + 16px) 20px calc(var(--safe-b) + 16px);
}
.big-inner { flex: 1; display: flex; flex-direction: column; justify-content: center; text-align: center; gap: 14px; transition: transform .3s; overflow: auto; }
.big-inner.flipped { transform: rotate(180deg); }
.big-title { font-size: 22px; color: #555; }
.big-main { font-size: clamp(34px, 11vw, 72px); font-weight: 700; line-height: 1.25; color: #b3001b; word-break: break-word; }
.big-main.vi { color: #111; font-size: clamp(28px, 9vw, 56px); }
.big-pinyin { font-size: 20px; color: #666; font-style: italic; }
.big-sub { font-size: 17px; color: #888; }
.big-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.big-actions .btn { background: #f0f0f0; color: #111; border: 0; padding: 14px; }
.big-actions .btn.primary { background: var(--red); color: #fff; }

/* ---------- dialog / toast ---------- */
dialog { border: 0; border-radius: 18px; padding: 20px; width: min(92vw, 420px); background: var(--card); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog h3 { margin: 0 0 4px; }
dialog label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
dialog label.row { flex-direction: row; align-items: center; gap: 8px; font-size: 15px; }
dialog label.row input { width: auto; }
.row-btns { display: flex; justify-content: space-between; gap: 10px; margin-top: 6px; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + var(--safe-b) + 220px);
  background: rgba(0,0,0,.85); color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 30;
  max-width: 90vw; text-align: center; font-size: 15px;
}
