:root {
  color-scheme: light;
  --paper: #f3efe6;
  --paper-deep: #e9e1d3;
  --ink: #211f1b;
  --muted: #736e65;
  --line: rgba(33, 31, 27, 0.12);
  --red: #c83f31;
  --red-dark: #a62c21;
  --green: #247a58;
  --shadow: 0 24px 70px rgba(48, 37, 24, 0.1);
  --mic-level: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html,
body {
  min-height: 100%;
  margin: 0;
  background:
    radial-gradient(circle at 90% 4%, rgba(200, 63, 49, 0.09), transparent 28rem),
    var(--paper);
  color: var(--ink);
}

body { overscroll-behavior: none; }
button, select, input { font: inherit; }
button, select { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }

.app {
  width: min(100%, 660px);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 18px calc(116px + env(safe-area-inset-bottom));
  position: relative;
}

.topbar,
.status-row,
.speaker-line,
.setting-group,
.language-pair,
.dialog-actions {
  display: flex;
  align-items: center;
}

.topbar { justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 39px;
  height: 39px;
  border-radius: 13px;
  background: var(--red);
  color: white;
  font-size: 21px;
  font-family: Georgia, "Songti SC", serif;
  box-shadow: 0 8px 22px rgba(200, 63, 49, 0.24);
}
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; letter-spacing: -0.01em; }
.brand small { margin-top: 1px; color: var(--muted); font-size: 11px; }

.icon-button,
.tiny-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.45);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.icon-button { width: 42px; height: 42px; border-radius: 15px; }
.icon-button svg, .tiny-button svg, .controls svg {
  width: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.status-row {
  gap: 8px;
  min-height: 30px;
  margin-top: 17px;
  color: var(--muted);
  font-size: 12px;
}
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #999185;
  box-shadow: 0 0 0 4px rgba(153, 145, 133, 0.12);
}
.latency { margin-left: auto; font-variant-numeric: tabular-nums; }
.app[data-phase="listening"] .status-dot,
.app[data-phase="translating"] .status-dot,
.app[data-phase="speaking"] .status-dot {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(36, 122, 88, 0.13);
}
.app[data-phase="error"] .status-dot { background: var(--red); }

.settings-panel {
  margin: 9px 0 14px;
  padding: 6px 16px;
  border: 1px solid var(--line);
  border-radius: 21px;
  background: rgba(255, 255, 255, 0.58);
  box-shadow: 0 12px 40px rgba(48, 37, 24, 0.07);
}
.setting-group {
  justify-content: space-between;
  gap: 16px;
  min-height: 68px;
  border-bottom: 1px solid var(--line);
}
.setting-group.compact { min-height: 54px; font-size: 13px; }
.setting-group:last-child { border-bottom: 0; }
.setting-group strong, .setting-group small { display: block; }
.setting-group strong { font-size: 13px; }
.setting-group small { margin-top: 4px; color: var(--muted); font-size: 11px; line-height: 1.35; }

.switch { position: relative; flex: 0 0 auto; width: 44px; height: 26px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span {
  position: absolute;
  inset: 0;
  border-radius: 99px;
  background: #cbc5ba;
  transition: 180ms ease;
}
.switch span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 2px 7px rgba(0, 0, 0, 0.18);
  transition: 180ms ease;
}
.switch input:checked + span { background: var(--red); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 3px solid rgba(200, 63, 49, 0.22); }

.language-pair { justify-content: space-between; gap: 10px; padding: 15px 0; border-bottom: 1px solid var(--line); }
.language-pair label { flex: 1; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; }
.language-pair select {
  width: 100%;
  margin-top: 6px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: white;
  color: var(--ink);
  text-transform: none;
  letter-spacing: 0;
}

.stage { margin-top: clamp(24px, 7vh, 66px); }
.language-route {
  margin-bottom: 11px;
  text-align: center;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.13em;
}
.live-card {
  min-height: 326px;
  margin-bottom: 12px;
  padding: 28px;
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: 31px;
  background: rgba(255, 255, 255, 0.7);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.empty-state {
  min-height: 268px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.empty-state h1 { margin: 25px 0 7px; font-family: Georgia, serif; font-size: clamp(25px, 7vw, 34px); font-weight: 500; letter-spacing: -0.04em; }
.empty-state p { max-width: 300px; margin: 0; color: var(--muted); font-size: 14px; line-height: 1.55; }

.listen-orb { height: 58px; display: flex; align-items: center; gap: 5px; }
.listen-orb span {
  width: 5px;
  height: 15px;
  border-radius: 99px;
  background: var(--red);
  transform: scaleY(calc(0.55 + var(--mic-level)));
  transition: transform 80ms linear;
}
.listen-orb span:nth-child(2), .listen-orb span:nth-child(4) { height: 31px; }
.listen-orb span:nth-child(3) { height: 48px; }
.app[data-phase="listening"] .listen-orb span { animation: wave 1s ease-in-out infinite alternate; }
.app[data-phase="listening"] .listen-orb span:nth-child(2) { animation-delay: -0.55s; }
.app[data-phase="listening"] .listen-orb span:nth-child(3) { animation-delay: -0.25s; }
.app[data-phase="listening"] .listen-orb span:nth-child(4) { animation-delay: -0.7s; }
.app[data-phase="listening"] .listen-orb span:nth-child(5) { animation-delay: -0.4s; }
@keyframes wave { from { transform: scaleY(0.35); } to { transform: scaleY(1); } }

.live-content { min-height: 268px; }
.speaker-line { justify-content: space-between; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; }
.translated-label { color: var(--red-dark); }
.draft-badge { padding: 4px 7px; border-radius: 99px; background: var(--paper-deep); font-size: 9px; letter-spacing: 0.06em; }
.source-text, .translation-text { margin: 11px 0 0; line-height: 1.35; overflow-wrap: anywhere; }
.source-text { min-height: 51px; color: #514d47; font-size: clamp(18px, 5vw, 23px); }
.translation-text { min-height: 74px; font-family: Georgia, "Songti SC", serif; font-size: clamp(29px, 8vw, 43px); letter-spacing: -0.025em; }
.divider { height: 1px; margin: 22px 0; background: var(--line); }
.tiny-button { width: 32px; height: 32px; border-radius: 11px; }
.tiny-button.is-muted { color: var(--red); background: rgba(200, 63, 49, 0.08); }
.pinyin { margin: 10px 0 0; color: var(--muted); font-size: 13px; line-height: 1.45; }

.warning { margin: 13px 8px 0; padding: 12px 14px; border-radius: 14px; background: #fff0cf; color: #754f12; font-size: 12px; line-height: 1.4; }
.warning strong { margin-right: 5px; }
.history { display: grid; gap: 12px; margin-bottom: 12px; }
.history:empty { display: none; }
.history-item {
  padding: 24px 28px;
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: 25px;
  background: rgba(255, 255, 255, 0.7);
  box-shadow: 0 14px 45px rgba(48, 37, 24, 0.075);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.feed-label {
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}
.feed-label.translated-label { color: var(--red-dark); }
.history-item p { margin: 0; line-height: 1.42; }
.history-source { margin-top: 9px !important; color: #514d47; font-size: clamp(17px, 4.5vw, 22px); }
.history-translation {
  margin-top: 9px !important;
  font-family: Georgia, "Songti SC", serif;
  font-size: clamp(24px, 7vw, 34px);
  font-weight: 500;
  letter-spacing: -0.02em;
}
.history-item .divider { margin: 18px 0; }
.history-meta { display: block; margin-top: 15px; color: #969087; font-size: 10px; }

.controls {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: 0;
  width: min(100%, 660px);
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: 1fr 1.45fr 1fr;
  align-items: end;
  gap: 10px;
  padding: 15px 18px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--paper) 72%, rgba(243, 239, 230, 0));
}
.controls button { border: 0; cursor: pointer; }
.listen-button {
  min-height: 67px;
  padding: 8px 12px;
  border-radius: 22px;
  background: var(--red);
  color: white;
  box-shadow: 0 14px 30px rgba(200, 63, 49, 0.28);
  font-weight: 700;
}
.listen-icon { display: inline-grid; vertical-align: middle; margin-right: 5px; }
.app[data-phase="connecting"] .listen-button,
.app[data-phase="translating"] .listen-button { animation: breathe 1.5s ease-in-out infinite; }
@keyframes breathe { 50% { transform: translateY(-2px); box-shadow: 0 18px 37px rgba(200, 63, 49, 0.36); } }
.secondary-control { min-height: 56px; background: transparent; color: var(--muted); font-size: 10px; }
.secondary-control svg, .secondary-control span { display: block; margin: 0 auto; }
.secondary-control svg { margin-bottom: 4px; }
.secondary-control.danger:not(:disabled) { color: var(--red); }
.secondary-control:disabled { opacity: 0.35; cursor: default; }

.mode-banner {
  position: fixed;
  z-index: 20;
  bottom: calc(100px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: min(calc(100% - 32px), 420px);
  padding: 10px 11px 10px 15px;
  border: 1px solid rgba(33, 31, 27, 0.12);
  border-radius: 15px;
  background: #282622;
  color: white;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.2);
  font-size: 12px;
}
.mode-banner button { float: right; border: 0; border-radius: 9px; padding: 6px 9px; background: white; color: var(--ink); font-size: 11px; font-weight: 700; cursor: pointer; }

dialog {
  width: min(calc(100% - 34px), 410px);
  padding: 0;
  border: 0;
  border-radius: 27px;
  background: #fffdf8;
  color: var(--ink);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.28);
}
dialog::backdrop { background: rgba(34, 29, 23, 0.55); backdrop-filter: blur(5px); }
dialog form { padding: 28px; }
.dialog-mark { color: var(--red); font-size: 31px; }
dialog h2 { margin: 12px 0 8px; font-family: Georgia, serif; font-weight: 500; }
dialog p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.55; }
.dialog-actions { justify-content: flex-end; gap: 9px; margin-top: 24px; }
.dialog-actions button { border: 0; border-radius: 12px; padding: 11px 16px; cursor: pointer; }
.text-button { background: transparent; }
.confirm-button { background: var(--red); color: white; font-weight: 700; }

[hidden] { display: none !important; }
:focus-visible { outline: 3px solid rgba(200, 63, 49, 0.25); outline-offset: 2px; }

@media (max-width: 420px) {
  .app { padding-left: 13px; padding-right: 13px; }
  .stage { margin-top: 21px; }
  .live-card { min-height: 304px; padding: 22px; border-radius: 26px; }
  .history-item { padding: 21px 22px; border-radius: 22px; }
  .controls { padding-left: 13px; padding-right: 13px; }
  .secondary-control span { font-size: 9px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
