/* ================================================================ тема */
:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --text: #0f172a;
  --muted: #64748b;
  --line: rgba(15, 23, 42, .08);
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);

  --ru: #2563eb;
  --ru-2: #1d4ed8;
  --ru-soft: #e8efff;
  --ru-ink: #1e3a8a;
  --zh: #e11d48;
  --zh-2: #be123c;
  --zh-soft: #ffe8ee;
  --zh-ink: #881337;
  --pinyin: #0e7490;
  --error-bg: #fff1f2;
  --error-ink: #be123c;

  --radius: 22px;
  --safe-b: env(safe-area-inset-bottom);
  --safe-t: env(safe-area-inset-top);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0f1a;
    --surface: #151b2b;
    --surface-2: #1c2438;
    --text: #e8ecf5;
    --muted: #8b95ab;
    --line: rgba(255, 255, 255, .08);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
    --ru: #3b82f6;
    --ru-2: #2563eb;
    --ru-soft: #16264d;
    --ru-ink: #bfd4ff;
    --zh: #f43f5e;
    --zh-2: #e11d48;
    --zh-soft: #3a1522;
    --zh-ink: #ffc4d1;
    --pinyin: #67e8f9;
    --error-bg: #3a1522;
    --error-ink: #fda4af;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0f1a;
  --surface: #151b2b;
  --surface-2: #1c2438;
  --text: #e8ecf5;
  --muted: #8b95ab;
  --line: rgba(255, 255, 255, .08);
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
  --ru: #3b82f6;
  --ru-2: #2563eb;
  --ru-soft: #16264d;
  --ru-ink: #bfd4ff;
  --zh: #f43f5e;
  --zh-2: #e11d48;
  --zh-soft: #3a1522;
  --zh-ink: #ffc4d1;
  --pinyin: #67e8f9;
  --error-bg: #3a1522;
  --error-ink: #fda4af;
  color-scheme: dark;
}

/* ================================================================ база */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Segoe UI", Roboto, "Noto Sans SC", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--ru) 55%, transparent); outline-offset: 2px; }

/* ================================================================ вход */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border-radius: 28px; padding: 32px 24px 24px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; text-align: center;
}
.login-logo, .brand-logo {
  font-weight: 800; letter-spacing: -.02em;
  background: linear-gradient(90deg, var(--ru), var(--zh)); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.login-logo { font-size: 40px; }
.login-logo span, .brand-logo span { color: var(--muted); -webkit-text-fill-color: var(--muted); font-weight: 500; margin: 0 2px; }
.login h1 { margin: 0; font-size: 24px; }
.login-sub { margin: 0 0 8px; color: var(--muted); }
.login input {
  font: inherit; padding: 15px 16px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text); outline: none; font-size: 17px;
}
.login input:focus { border-color: var(--ru); }
.primary {
  border: 0; border-radius: 14px; padding: 15px; font-weight: 600; font-size: 17px; color: #fff;
  background: linear-gradient(135deg, var(--ru), var(--ru-2));
}
.login-err { margin: 0; min-height: 1.4em; color: var(--error-ink); }

/* ================================================================ каркас */
.app { height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  position: relative; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(var(--safe-t) + 8px) 12px 8px 16px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.6) blur(16px); -webkit-backdrop-filter: saturate(1.6) blur(16px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-logo { font-size: 18px; }
.brand-name { font-weight: 700; font-size: 17px; }
.top-actions { display: flex; align-items: center; gap: 4px; }
.icon-btn {
  width: 44px; height: 44px; display: grid; place-items: center; border: 0; border-radius: 14px; background: transparent; color: var(--text);
}
.icon-btn:active { background: var(--surface-2); }
.balance-badge {
  height: 36px; display: inline-flex; align-items: center; gap: 5px; padding: 0 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font-size: 13px; font-weight: 600; cursor: pointer; transition: all .15s ease;
  white-space: nowrap; -webkit-tap-highlight-color: transparent;
}
.balance-badge:active { transform: scale(.97); background: var(--surface-2); }
.bal-usd { color: #10b981; font-weight: 700; }
.bal-sep { color: var(--muted); opacity: .4; }
.bal-hours { color: var(--muted); font-size: 12px; font-weight: 500; }

.chip {
  height: 36px; display: flex; align-items: center; gap: 6px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 14px; font-weight: 600;
}
.chip svg { width: 18px; height: 18px; }
.chip[aria-pressed="false"] svg { opacity: .6; }
.chip[aria-pressed="true"] {
  color: #fff; border-color: transparent; background: linear-gradient(135deg, #8b5cf6, #6366f1);
}

.menu {
  position: absolute; right: 12px; top: calc(100% + 6px); min-width: 240px; padding: 6px;
  background: var(--surface); border-radius: 18px; box-shadow: var(--shadow); border: 1px solid var(--line);
  animation: pop .16s ease-out;
}
.menu-bal-row {
  padding: 8px 12px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line); margin-bottom: 4px;
}
.menu-bal-row b { color: #10b981; }
.menu a, .menu button {
  width: 100%; display: flex; align-items: center; gap: 12px; padding: 12px; border: 0; border-radius: 12px;
  background: none; color: var(--text); text-decoration: none; font-size: 16px; text-align: left;
}
.menu a:active, .menu button:active { background: var(--surface-2); }
.menu .danger { color: var(--error-ink); }
.menu-foot { padding: 8px 12px 6px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); margin-top: 4px; }
.menu-foot:empty { display: none; }

/* ================================================================ лента */
.chat {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px 12px 24px; display: flex; flex-direction: column; gap: 14px; scroll-behavior: smooth;
}

.empty { margin: auto; text-align: center; max-width: 320px; padding: 24px 8px; color: var(--muted); }
.empty-icon {
  width: 72px; height: 72px; margin: 0 auto 16px; border-radius: 24px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--ru-soft), var(--zh-soft)); color: var(--text);
}
.empty-icon svg { width: 34px; height: 34px; }
.empty h2 { margin: 0 0 8px; color: var(--text); font-size: 20px; }
.empty p { margin: 0 0 8px; }
.empty-zh { font-size: 15px; }
.empty-tip { font-size: 13px; margin-top: 16px !important; }
.c-ru { color: var(--ru); }
.c-zh { color: var(--zh); }

.msg { display: flex; flex-direction: column; max-width: 88%; animation: rise .22s ease-out; }
.msg.from-ru { align-self: flex-end; align-items: flex-end; }
.msg.from-zh { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 12px 14px 10px; border-radius: var(--radius); box-shadow: var(--shadow); position: relative;
  background: var(--surface);
}
.from-ru .bubble { border-bottom-right-radius: 8px; background: var(--ru-soft); }
.from-zh .bubble { border-bottom-left-radius: 8px; background: var(--zh-soft); }

.who { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase; margin-bottom: 4px; }
.from-ru .who { color: var(--ru); }
.from-zh .who { color: var(--zh); }
.orig { color: var(--muted); font-size: 14.5px; }
.tr { font-size: 20px; line-height: 1.35; font-weight: 500; margin-top: 4px; color: var(--text); }
.from-ru .tr { color: var(--ru-ink); }
.from-zh .tr { color: var(--zh-ink); }
.tr:lang(zh) { font-size: 22px; }
.pinyin { color: var(--pinyin); font-size: 14px; margin-top: 2px; }

.msg-actions { display: flex; flex-wrap: wrap; gap: 2px; margin: 4px -8px -6px; }
.msg-actions button.done { color: #16a34a; }
.msg-actions button {
  height: 36px; min-width: 40px; padding: 0 10px; display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  border: 0; border-radius: 12px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 600;
}
.msg-actions button:active { background: color-mix(in srgb, var(--text) 8%, transparent); }
.msg-actions svg { width: 18px; height: 18px; }

.meta { font-size: 11.5px; color: var(--muted); margin: 5px 8px 0; font-variant-numeric: tabular-nums; opacity: .85; }
.meta a { color: inherit; text-decoration: none; }

.typing .bubble { padding: 14px 18px; }
.dots { display: flex; gap: 5px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); opacity: .5; animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }

.sys {
  align-self: center; max-width: 92%; text-align: center; font-size: 14px; padding: 10px 14px; border-radius: 16px;
  background: var(--error-bg); color: var(--error-ink); animation: rise .22s ease-out;
}
.sys a { color: inherit; font-weight: 600; }

/* ================================================================ док с кнопками */
.dock {
  padding: 8px 12px calc(var(--safe-b) + 12px);
  background: linear-gradient(to top, var(--bg) 70%, color-mix(in srgb, var(--bg) 0%, transparent));
}
.status { min-height: 22px; text-align: center; font-size: 14px; color: var(--muted); margin-bottom: 8px; font-variant-numeric: tabular-nums; }
.talk-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }

.talk {
  position: relative; isolation: isolate; height: 84px; border: 0; border-radius: 26px; color: #fff;
  display: flex; align-items: center; gap: 10px; padding: 0 16px; text-align: left;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none;
  transition: transform .12s cubic-bezier(0.2, 0, 0, 1), opacity .2s ease, filter .2s ease;
  will-change: transform;
}
.talk.ru { background: linear-gradient(145deg, var(--ru), var(--ru-2)); box-shadow: 0 8px 20px -6px color-mix(in srgb, var(--ru) 60%, transparent); }
.talk.zh { background: linear-gradient(145deg, var(--zh), var(--zh-2)); box-shadow: 0 8px 20px -6px color-mix(in srgb, var(--zh) 60%, transparent); }
.talk:active { transform: scale(.98); }
.talk:disabled, .talk.dim { opacity: .35; filter: saturate(.5); }
.talk-flag { font-size: 30px; line-height: 1; flex-shrink: 0; }
.talk-text { display: flex; flex-direction: column; min-width: 0; }
.talk-name { font-size: 19px; font-weight: 700; }
.talk-hint { font-size: 12.5px; line-height: 1.2; opacity: .88; overflow-wrap: anywhere; }

/* лаконичный, плавный световой ободок во время записи (GPU-ускоренный, без лагов) */
.talk-ring {
  position: absolute; inset: -3px; border-radius: 29px; z-index: -1; pointer-events: none;
  opacity: 0; transition: opacity .2s ease;
}
.talk.ru.recording .talk-ring {
  border: 2.5px solid var(--ru);
  box-shadow: 0 0 16px color-mix(in srgb, var(--ru) 65%, transparent);
  animation: aura 1.6s ease-in-out infinite;
  opacity: 1;
}
.talk.zh.recording .talk-ring {
  border: 2.5px solid var(--zh);
  box-shadow: 0 0 16px color-mix(in srgb, var(--zh) 65%, transparent);
  animation: aura 1.6s ease-in-out infinite;
  opacity: 1;
}
.talk.recording {
  transform: scale(.98);
}

@keyframes aura {
  0%, 100% { transform: scale(1); opacity: .65; }
  50% { transform: scale(1.025); opacity: 1; }
}

.talk.busy .talk-flag { visibility: hidden; }
.talk.busy::after {
  content: ""; position: absolute; left: 18px; top: 50%; width: 24px; height: 24px; margin-top: -12px;
  border: 2.5px solid rgba(255, 255, 255, .3); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite;
}

/* ================================================================ «показать собеседнику» */
.show {
  position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; background: var(--bg);
  padding: calc(var(--safe-t) + 16px) 20px calc(var(--safe-b) + 20px); animation: fade .18s ease-out;
}
.show-card { flex: 1; display: flex; flex-direction: column; justify-content: center; text-align: center; transition: transform .35s ease; }
.show-card.rotated { transform: rotate(180deg); }
.show-main { font-size: clamp(34px, 11vw, 64px); line-height: 1.25; font-weight: 600; word-break: break-word; }
.show-sub { margin-top: 16px; font-size: clamp(18px, 5vw, 26px); color: var(--pinyin); }
.show-actions { display: flex; justify-content: center; gap: 16px; }
.round {
  width: 60px; height: 60px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface);
  box-shadow: var(--shadow); display: grid; place-items: center;
}
.round svg { width: 24px; height: 24px; }

/* ================================================================ анимации */
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } }
@keyframes fade { from { opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { 0%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: .9; transform: translateY(-3px); } }
@keyframes beat { 50% { transform: scale(1.12); } }

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

/* широкие экраны: колонка по центру */
@media (min-width: 720px) {
  .app { max-width: 640px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .msg { max-width: 75%; }
}

/* узкие мобильные экраны: скрываем текст логотипа, чтобы бейдж баланса помещался без сжатия */
@media (max-width: 420px) {
  .brand-name { display: none; }
  .balance-badge { padding: 0 7px; font-size: 12px; height: 34px; }
  .chip { padding: 0 8px; font-size: 13px; height: 34px; }
}

