/* 旅译 · 墨 + 纸 */
:root {
  --paper: #F5F3EE;
  --card: #FFFFFF;
  --ink: #1B1E24;
  --on-ink: #FAF8F4;
  --accent: #B24A32;
  --hairline: #E4E0D8;
  --wash: #EEEBE4;
  --muted: #8A8780;
  --faint: #B9B5AD;
  --stage: #111214;
  /* 与 App 一致：拉丁字母用 New York（ui-serif），中日文用苹方 */
  --serif: ui-serif, "New York", Georgia, -apple-system, "PingFang SC", "Hiragino Sans", "Noto Sans CJK SC", sans-serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans", "Noto Sans CJK SC", "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0E0F11;
    --card: #18191C;
    --ink: #ECE8E0;
    --on-ink: #111214;
    --accent: #E07C5E;
    --hairline: #2A2B30;
    --wash: #202126;
    --muted: #8D8B86;
    --faint: #5C5B58;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button, select, input { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
[hidden] { display: none !important; }

.app {
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-t);
}

.card {
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: 18px;
}

.tag {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .12em;
  color: var(--muted);
  text-transform: uppercase;
}
.tag.accent { color: var(--accent); }

/* ---------- 顶栏 ---------- */
.top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px 10px;
}
.brand {
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 600;
  margin: 0 auto 0 0;
  letter-spacing: .02em;
}
.seg {
  position: relative;
  display: flex;
  padding: 3px;
  background: var(--wash);
  border-radius: 999px;
}
.seg-pill {
  position: absolute;
  top: 3px; bottom: 3px; left: 3px;
  border-radius: 999px;
  background: var(--ink);
  transition: transform .35s cubic-bezier(.3,1.3,.5,1), width .35s cubic-bezier(.3,1.3,.5,1);
}
.seg-btn {
  position: relative;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  border-radius: 999px;
  transition: color .25s;
}
.seg-btn.active { color: var(--on-ink); }
.icon-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--wash);
  display: grid; place-items: center;
}

.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 20px 8px;
  padding: 12px 16px;
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  font-size: 15px;
  text-align: left;
}
.banner b { margin-left: auto; color: var(--accent); font-weight: 600; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex: none; }

.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* ---------- 语言栏 ---------- */
.langbar {
  display: flex;
  align-items: center;
  margin: 0 20px 4px;
  padding: 0 6px;
  border-radius: 16px;
}
.lang {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 0;
}
.lang select {
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  background: transparent;
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  text-align-last: center;
  padding: 0 14px 0 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='9' height='6'%3E%3Cpath d='M1 1l3.5 3.5L8 1' fill='none' stroke='%23999' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right center;
  outline: none;
}
.lang select:disabled { opacity: .55; }
.swap {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  color: var(--muted);
}

/* ---------- 消息 ---------- */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  -webkit-overflow-scrolling: touch;
}
.msg {
  position: relative;
  max-width: calc(100% - 40px);
  padding: 14px 18px 16px;
  animation: rise .35s cubic-bezier(.2,.9,.3,1.1);
}
.msg.me { align-self: flex-end; }
.msg.partner { align-self: flex-start; }
.msg::before {
  content: "";
  position: absolute;
  left: -1px; top: 18px; bottom: 18px;
  width: 2px;
  border-radius: 2px;
  background: var(--ink);
}
.msg.partner::before { background: var(--accent); }
.msg.partner .msg-dir { color: var(--accent); }
.msg-head { display: flex; justify-content: space-between; align-items: center; }
.msg-dir { color: var(--ink); }
.msg-time { font-size: 11px; color: var(--faint); }
.msg-original { margin-top: 8px; font-size: 15px; color: var(--muted); line-height: 1.5; }
.msg-translation {
  margin-top: 10px;
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 500;
  line-height: 1.5;
  word-break: break-word;
}
.msg-error { margin-top: 10px; font-size: 14px; color: var(--accent); }
.msg-actions { display: flex; gap: 8px; margin-top: 14px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--hairline);
}
.pill.solid { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.loading { color: var(--muted); font-size: 15px; }
.loading::after { content: ""; animation: dots 1.4s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }

.empty { padding: 48px 0 0; text-align: center; }
.empty-hello { font-family: var(--serif); font-size: 30px; }
.rule { width: 24px; height: 2px; background: var(--accent); margin: 12px auto; }
.empty-sub { color: var(--muted); font-size: 15px; }
.tips { margin-top: 26px; padding: 18px 20px; text-align: left; display: grid; gap: 14px; }
.tip { display: flex; gap: 14px; font-size: 15px; color: color-mix(in srgb, var(--ink) 80%, transparent); }
.tip b { font-family: var(--serif); color: var(--accent); font-weight: 600; font-size: 13px; }

/* ---------- 按住说话 ---------- */
.talkbar {
  display: flex;
  gap: 12px;
  padding: 12px 20px calc(10px + var(--safe-b));
  border-top: 1px solid var(--hairline);
}
.talk {
  position: relative;
  flex: 1;
  height: 104px;
  border-radius: 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  transition: transform .2s, box-shadow .2s, opacity .2s;
  box-shadow: 0 3px 8px rgba(0,0,0,.04);
}
.talk.partner { background: var(--card); color: var(--ink); border: 1px solid var(--hairline); }
.talk.me { background: var(--ink); color: var(--on-ink); }
.talk .mic { margin-bottom: 2px; }
.talk-label { font-size: 15px; font-weight: 600; }
.talk-code { opacity: .6; color: inherit; }
.talk.active { transform: scale(.97); box-shadow: 0 6px 16px rgba(0,0,0,.14); }
.talk.active::after {
  content: ""; position: absolute; top: 14px; right: 14px;
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
}
.talk.disabled { opacity: .35; }

.recording {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  pointer-events: none;
  z-index: 20;
}
.recording-card {
  width: 270px;
  padding: 26px 28px;
  border-radius: 24px;
  text-align: center;
  box-shadow: 0 12px 30px rgba(0,0,0,.1);
  animation: pop .25s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes pop { from { opacity: 0; transform: scale(.92); } }
.bars { height: 44px; display: flex; gap: 6px; justify-content: center; align-items: center; }
.bars i { width: 3px; height: 100%; border-radius: 3px; background: var(--ink); transform: scaleY(.1); transition: transform .08s; }
.recording.cancel .bars i { background: var(--accent); }
.rec-title { margin-top: 16px; font-family: var(--serif); font-size: 21px; font-weight: 600; }
.recording.cancel .rec-title { color: var(--accent); }
.rec-hint { margin-top: 8px; font-size: 12px; color: var(--muted); }

/* ---------- 实时字幕 ---------- */
#view-live { padding: 0 0 calc(8px + var(--safe-b)); gap: 12px; }
#view-live .langbar { margin-bottom: 0; }
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  margin: 0 20px;
  background: var(--stage);
  border-radius: 24px;
  overflow: hidden;
  color: #fff;
}
.stage-tools {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 14px;
  z-index: 2;
  background: linear-gradient(var(--stage) 60%, transparent);
}
.spacer { flex: 1; }
.stage-btn {
  width: 32px; height: 32px; border-radius: 50%;
  background: rgba(255,255,255,.08);
  color: rgba(255,255,255,.7);
  font-size: 12px; font-weight: 600;
  display: grid; place-items: center;
}
.live-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,.08);
  font-family: var(--mono); font-size: 10px; font-weight: 600; letter-spacing: .12em;
  color: rgba(255,255,255,.8);
}
.live-badge i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: blink 1.8s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .3; } }
.captions {
  height: 100%;
  overflow-y: auto;
  padding: 60px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}
.cap { position: relative; }
.cap-t { font-family: var(--serif); font-size: 18px; font-weight: 500; line-height: 1.55; color: rgba(255,255,255,.62); }
.cap-o { margin-top: 8px; font-size: 13px; line-height: 1.5; color: rgba(255,255,255,.32); }
.captions.big .cap-t { font-size: 23px; }
.captions.big .cap-o { font-size: 15px; }
.cap.latest .cap-t { color: #fff; }
.cap.latest .cap-o { color: rgba(255,255,255,.5); }
.cap.pending::before {
  content: ""; position: absolute; left: -12px; top: 4px; bottom: 4px;
  width: 2px; border-radius: 2px; background: var(--accent);
}
.stage-empty {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 20px;
}
.stage-title { font-family: var(--serif); font-size: 26px; color: rgba(255,255,255,.9); }
.stage-empty p { margin: 0; font-size: 13px; line-height: 1.8; color: rgba(255,255,255,.45); }

.control {
  margin: 0 20px;
  padding: 12px 12px 12px 20px;
  border-radius: 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.status { font-family: var(--serif); font-size: 17px; font-weight: 600; margin-bottom: 4px; }
.rec {
  position: relative;
  width: 64px; height: 64px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--on-ink);
  display: grid; place-items: center;
  transition: background .25s;
}
.rec > * { grid-area: 1 / 1; }
.rec-ring {
  position: absolute; inset: 0;
  border-radius: 50%;
  border: 1.5px solid color-mix(in srgb, var(--accent) 35%, transparent);
  transform: scale(1.08);
  transition: transform .12s ease-out;
  opacity: 0;
}
.rec-stop { width: 18px; height: 18px; border-radius: 4px; background: #fff; display: none; }
.rec .spinner { display: none; }
.rec.running { background: var(--accent); }
.rec.running .rec-mic { display: none; }
.rec.running .rec-stop { display: block; }
.rec.running .rec-ring { opacity: 1; }
.rec.busy .rec-mic, .rec.busy .rec-stop { display: none; }
.rec.busy .spinner { display: block; }

.spinner {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  animation: spin .8s linear infinite;
}
.spinner.dark { width: 16px; height: 16px; border-color: var(--hairline); border-top-color: var(--ink); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 放大展示 ---------- */
.showcase {
  position: fixed; inset: 0;
  background: var(--stage);
  color: #fff;
  z-index: 40;
  display: flex; flex-direction: column;
  animation: fade .25s;
}
@keyframes fade { from { opacity: 0; } }
.showcase-body {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 24px;
  padding: 28px;
  text-align: center;
  transition: transform .5s cubic-bezier(.3,1.2,.5,1);
}
.showcase-body.flipped { transform: rotate(180deg); }
.sc-translation { font-family: var(--serif); font-size: clamp(28px, 9vw, 44px); font-weight: 500; line-height: 1.4; }
.sc-original { font-size: 18px; color: rgba(255,255,255,.45); }
.sc-actions { display: flex; justify-content: center; gap: 16px; padding: 0 0 calc(24px + var(--safe-b)); }
.sc-btn {
  width: 56px; height: 56px; border-radius: 50%;
  background: rgba(255,255,255,.1);
  color: rgba(255,255,255,.85);
  font-size: 18px;
  display: grid; place-items: center;
}

/* ---------- 设置 ---------- */
.sheet-mask {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.28);
  z-index: 30;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .2s;
}
.sheet {
  width: 100%; max-width: 560px;
  max-height: 92dvh;
  background: var(--paper);
  border-radius: 22px 22px 0 0;
  display: flex; flex-direction: column;
  animation: up .3s cubic-bezier(.2,.9,.3,1);
}
@keyframes up { from { transform: translateY(100%); } }
.sheet-head {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 14px 16px;
}
.sheet-head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.done { justify-self: end; font-weight: 600; padding: 8px 14px; border-radius: 999px; background: var(--wash); }
.sheet-body { overflow-y: auto; padding: 0 16px calc(24px + var(--safe-b)); }
.group-title { font-size: 13px; color: var(--muted); margin: 18px 4px 8px; }
.group { overflow: hidden; margin-top: 8px; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 50px;
  padding: 0 16px;
  width: 100%;
  font-size: 16px;
  text-align: left;
}
.row + .row { border-top: 1px solid var(--hairline); }
.row input[type=password], .row input[type=text] {
  flex: 1; border: 0; background: transparent; outline: none;
  font-family: var(--mono); font-size: 15px; min-width: 0;
}
.row select {
  appearance: none; -webkit-appearance: none;
  border: 0; background: transparent; outline: none;
  color: var(--muted); text-align: right; text-align-last: right;
  font-size: 15px; max-width: 60%;
}
.eye { color: var(--muted); font-size: 14px; }
.row.link { color: var(--ink); font-weight: 500; }
.row.danger { color: var(--accent); justify-content: center; }
.row.result { font-size: 14px; padding-top: 12px; padding-bottom: 12px; line-height: 1.5; }
.row.result.ok { color: #2F7D4F; }
.row.result.err { color: var(--accent); }
.group-foot { font-size: 12px; color: var(--muted); margin: 8px 4px 0; line-height: 1.6; }
.group-foot.center { text-align: center; font-family: var(--mono); font-size: 10px; margin-top: 18px; }

.switch {
  appearance: none; -webkit-appearance: none;
  width: 50px; height: 30px; border-radius: 999px;
  background: var(--hairline);
  position: relative; transition: background .2s; flex: none; margin: 0;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 26px; height: 26px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .2s;
}
.switch:checked { background: var(--ink); }
.switch:checked::after { transform: translateX(20px); }

/* ---------- 提示 ---------- */
.toast {
  position: fixed; left: 50%; top: calc(12px + var(--safe-t));
  transform: translateX(-50%);
  max-width: calc(100% - 40px);
  padding: 11px 18px;
  border-radius: 999px;
  background: var(--ink); color: var(--on-ink);
  font-size: 14px;
  box-shadow: 0 6px 14px rgba(0,0,0,.12);
  z-index: 50;
  animation: drop .3s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes drop { from { opacity: 0; transform: translate(-50%, -12px); } }

/* ---------- 登录 ---------- */
.muted { color: var(--muted); font-size: 15px; }
.login {
  position: fixed; inset: 0;
  background: var(--paper);
  z-index: 60;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-box { width: 100%; max-width: 320px; text-align: center; margin-top: -8vh; }
.login-brand { font-family: var(--serif); font-size: 40px; font-weight: 600; letter-spacing: .04em; }
.login-sub { color: var(--muted); font-size: 14px; margin-bottom: 28px; }
.login-input {
  display: block; width: 100%;
  height: 52px; padding: 0 18px;
  border-radius: 14px;
  font-size: 17px; text-align: center; letter-spacing: .2em;
  outline: none;
}
.login-input:focus { border-color: var(--ink); }
.login-btn {
  width: 100%; height: 52px; margin-top: 12px;
  border-radius: 14px;
  background: var(--ink); color: var(--on-ink);
  font-size: 16px; font-weight: 600;
}
.login-btn:disabled { opacity: .5; }
.login-err { min-height: 20px; margin-top: 14px; font-size: 14px; color: var(--accent); }
