:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --ink: #16181d;
  --muted: #6d727c;
  --line: rgba(22, 24, 29, .09);
  --ru: #2f5fe0;
  --ru-2: #3a6df0;
  --ru-soft: #e9eefc;
  --zh: #c63f2d;
  --zh-2: #d24a36;
  --zh-soft: #fbeae6;
  --warn: #b26a00;
  --warn-bg: #fff3dc;
  --radius: 20px;
  --shadow-card: 0 1px 2px rgba(16, 18, 22, .04), 0 10px 30px -18px rgba(16, 18, 22, .35);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
          "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- каркас ---------- */

.app {
  height: 100vh;
  height: 100svh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
  overflow: hidden;
}

.topbar, .notice, .dock { flex: none; }

@media (min-width: 720px) {
  body { background: radial-gradient(1200px 600px at 50% -10%, #eceadf, var(--bg)); }
  .app {
    max-width: 580px;
    margin: 0 auto;
    border-inline: 1px solid var(--line);
    box-shadow: 0 0 80px -40px rgba(0, 0, 0, .35);
  }
}

/* ---------- верхняя панель ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 5;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.mark {
  width: 38px; height: 38px; border-radius: 12px;
  display: grid; place-items: center;
  font-size: 20px; font-weight: 600;
  color: #fff;
  background: linear-gradient(145deg, #2b3860, #131722);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .18), 0 6px 16px -8px rgba(19, 23, 34, .8);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-text b { font-size: 15px; letter-spacing: -.01em; }
.brand-text small { font-size: 11px; color: var(--muted); letter-spacing: .06em; }

.top-actions { display: flex; gap: 6px; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center;
  color: var(--ink);
  border: 1px solid transparent;
  transition: background .15s ease, border-color .15s ease, transform .12s ease;
}
.icon-btn:hover { background: rgba(22, 24, 29, .06); }
.icon-btn:active { transform: scale(.94); }
.icon-btn[aria-pressed="true"] { color: var(--ru); background: var(--ru-soft); }
.icon-btn[aria-pressed="false"] { color: var(--muted); }

/* ---------- предупреждение ---------- */

.notice {
  margin: 10px 14px 0;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 13px;
  line-height: 1.4;
  display: flex;
  align-items: center;
  gap: 10px;
}
.notice button {
  margin-left: auto;
  font-size: 13px;
  font-weight: 600;
  color: var(--warn);
  text-decoration: underline;
  text-underline-offset: 2px;
  white-space: nowrap;
}

/* ---------- лента ---------- */

.feed {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.turn:first-of-type { margin-top: auto; }

.empty {
  margin: auto;
  text-align: center;
  max-width: 400px;
  padding: 20px 8px 8px;
  animation: rise .35s ease both;
}
.empty-mark {
  font-size: 64px; line-height: 1;
  color: rgba(22, 24, 29, .08);
  font-weight: 600;
  margin-bottom: 6px;
}
.empty h1 { font-size: 22px; letter-spacing: -.02em; margin: 0 0 8px; }
.empty p { font-size: 14px; line-height: 1.55; color: var(--muted); margin: 0 auto 18px; max-width: 330px; }

.samples { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.sample {
  max-width: 100%;
  padding: 9px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
  box-shadow: 0 1px 2px rgba(16, 18, 22, .03);
  transition: transform .12s ease, color .12s ease;
}
.sample:active { transform: scale(.97); }
.sample:hover { color: var(--ink); }
.sample[data-lang="zh"] { font-family: "PingFang SC", "Noto Sans SC", var(--font); }

/* ---------- карточка реплики ---------- */

.turn {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 15px 11px;
  box-shadow: var(--shadow-card);
  animation: rise .22s ease both;
  position: relative;
}
.turn.ru { border-left: 3px solid var(--ru); }
.turn.zh { border-left: 3px solid var(--zh); }

.who {
  display: flex; align-items: center; gap: 7px;
  font-size: 11px; font-weight: 600; letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
}
.turn.ru .who { color: var(--ru); }
.turn.zh .who { color: var(--zh); }
.who .time { margin-left: auto; font-weight: 500; letter-spacing: 0; text-transform: none; color: #a2a6ae; }

.src {
  margin-top: 7px;
  font-size: 14.5px;
  line-height: 1.45;
  color: #5f6470;
  word-break: break-word;
}
.src[lang="zh"] { font-size: 15.5px; }

.dst {
  margin-top: 9px;
  padding-top: 9px;
  border-top: 1px dashed var(--line);
  font-size: 20.5px;
  line-height: 1.5;
  font-weight: 500;
  letter-spacing: -.005em;
  word-break: break-word;
}
.dst[lang="zh"] { font-size: 22px; letter-spacing: .01em; }

.turn .tools {
  display: flex; gap: 4px; justify-content: flex-end;
  margin-top: 6px;
}
.tool {
  width: 34px; height: 32px; border-radius: 10px;
  display: grid; place-items: center;
  color: var(--muted);
  transition: background .15s ease, color .15s ease;
}
.tool:hover { background: rgba(22, 24, 29, .06); color: var(--ink); }
.tool svg { width: 18px; height: 18px; }

.turn.pending .dst, .turn.pending .src { color: var(--muted); }
.dots { display: inline-flex; gap: 4px; align-items: center; }
.dots i {
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; opacity: .35;
  animation: blink 1.1s infinite;
}
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }

.turn.error { border-left-color: #d9534f; }
.turn.error .dst { color: #b23b36; font-size: 15px; font-weight: 400; }
.err-actions { display: flex; gap: 8px; margin-top: 10px; }
.err-actions button {
  padding: 7px 12px; border-radius: 10px; font-size: 13px;
  background: rgba(22, 24, 29, .05); color: var(--ink);
}
.err-actions button.primary-sm { background: var(--ink); color: #fff; }

/* ---------- нижние кнопки ---------- */

.dock {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  z-index: 4;
}

.talk {
  height: 74px;
  border-radius: 22px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 14px;
  color: #fff;
  text-align: left;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: transform .1s ease, filter .15s ease, box-shadow .15s ease;
  position: relative;
  overflow: hidden;
}
.talk::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, .16), rgba(255, 255, 255, 0));
  pointer-events: none;
}
.talk[data-lang="ru"] {
  background: linear-gradient(160deg, var(--ru-2), #2449b5);
  box-shadow: 0 10px 26px -12px rgba(47, 95, 224, .9);
}
.talk[data-lang="zh"] {
  background: linear-gradient(160deg, var(--zh-2), #9d2b1d);
  box-shadow: 0 10px 26px -12px rgba(198, 63, 45, .9);
}
.talk:active, .talk.is-rec { transform: scale(.975); filter: brightness(1.06); }
.talk.is-rec { box-shadow: 0 0 0 3px rgba(255, 255, 255, .35), 0 14px 34px -12px currentColor; }

.talk-flag {
  width: 38px; height: 38px; border-radius: 12px;
  display: grid; place-items: center;
  font-size: 14px; font-weight: 700; letter-spacing: .02em;
  background: rgba(255, 255, 255, .18);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25);
  flex: none;
}
.talk-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.talk-text b { font-size: 16.5px; font-weight: 600; letter-spacing: -.01em; }
.talk-text small { font-size: 11.5px; opacity: .82; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.talk[data-lang="zh"] .talk-text b { font-family: "PingFang SC", "Noto Sans SC", var(--font); font-size: 18px; }

/* ---------- оверлей записи ---------- */

.overlay {
  position: fixed; inset: 0; z-index: 40;
  pointer-events: none;
  display: grid; place-items: center;
  background: rgba(12, 14, 18, .45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: fade .15s ease both;
}

.rec-card {
  pointer-events: auto;
  width: min(86vw, 340px);
  background: var(--surface);
  border-radius: 28px;
  padding: 26px 24px 18px;
  text-align: center;
  box-shadow: 0 30px 90px -30px rgba(0, 0, 0, .6);
  animation: pop .2s ease both;
}

.orb {
  width: 118px; height: 118px; border-radius: 50%;
  margin: 4px auto 14px;
  position: relative;
  display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, .3), transparent 60%), var(--ru);
  color: #fff;
  box-shadow: 0 16px 40px -14px rgba(47, 95, 224, .8);
}
.orb.zh { background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, .3), transparent 60%), var(--zh); box-shadow: 0 16px 40px -14px rgba(198, 63, 45, .8); }
.orb-core { font-size: 26px; font-weight: 700; letter-spacing: .02em; }
.orb .ring {
  position: absolute; inset: 0; border-radius: 50%;
  border: 2px solid currentColor;
  opacity: 0;
  animation: ripple 2s ease-out infinite;
}
.orb .ring:nth-child(2) { animation-delay: .9s; }
.orb::before {
  content: ""; position: absolute; inset: -10px; border-radius: 50%;
  background: currentColor; opacity: .08;
}

.bars { display: flex; align-items: center; justify-content: center; gap: 4px; height: 30px; margin-bottom: 8px; color: var(--ru); }
.bars.zh { color: var(--zh); }
.bars i {
  width: 4px; height: 8px; border-radius: 4px; background: currentColor;
  animation: bounce 1s ease-in-out infinite;
}
.bars i:nth-child(2n) { animation-duration: .8s; }
.bars i:nth-child(3n) { animation-duration: 1.15s; }
.bars i:nth-child(4n) { animation-duration: .95s; }

.rec-title { font-size: 18px; font-weight: 600; letter-spacing: -.01em; }
.rec-timer { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); margin-top: 3px; }
.rec-hint { font-size: 13px; color: var(--muted); margin-top: 12px; line-height: 1.4; }
.rec-cancel {
  margin-top: 14px; padding: 9px 16px; border-radius: 12px;
  font-size: 13.5px; color: var(--muted); background: rgba(22, 24, 29, .05);
}
.rec-card.processing .bars { visibility: hidden; }

/* ---------- шторки ---------- */

.sheet { position: fixed; inset: 0; z-index: 60; display: grid; grid-template-columns: minmax(0, 1fr); align-items: end; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(12, 14, 18, .4); backdrop-filter: blur(4px); animation: fade .18s ease both; }
.sheet-panel::before {
  content: "";
  display: block;
  width: 38px; height: 4px;
  margin: -6px auto 10px;
  border-radius: 999px;
  background: rgba(22, 24, 29, .14);
}

.sheet-panel {
  position: relative;
  background: var(--bg);
  border-radius: 24px 24px 0 0;
  padding: 18px 18px calc(20px + env(safe-area-inset-bottom));
  max-height: 90dvh;
  overflow-y: auto;
  animation: slide-up .24s cubic-bezier(.22, .9, .3, 1) both;
  box-shadow: 0 -20px 60px -30px rgba(0, 0, 0, .5);
}

.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-head b { font-size: 17px; letter-spacing: -.01em; }

.field { display: block; margin-bottom: 16px; }
.field.row { display: flex; align-items: center; justify-content: space-between; }
.field-label { display: block; font-size: 13px; font-weight: 600; color: #4a4e57; margin-bottom: 7px; }
.field.row .field-label { margin-bottom: 0; }

.field input[type="password"], .field input[type="text"], .field select, textarea {
  width: 100%;
  padding: 12px 13px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 16px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field input:focus, .field select:focus, textarea:focus {
  border-color: rgba(47, 95, 224, .55);
  box-shadow: 0 0 0 3px rgba(47, 95, 224, .13);
}

.key-row { display: flex; gap: 8px; }
.key-row input { flex: 1; }
.ghost {
  padding: 0 13px; border-radius: 12px; font-size: 13.5px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  white-space: nowrap;
}
.ghost:active { transform: scale(.97); }
.ghost.danger { color: #b23b36; border-color: rgba(178, 59, 54, .25); }

.hint { display: block; font-size: 12px; color: var(--muted); margin-top: 6px; line-height: 1.4; }
.hint a { color: var(--ru); }
.tiny { font-size: 12px; color: var(--muted); line-height: 1.45; margin: 10px 0 0; }

.seg {
  display: flex; gap: 4px; padding: 4px;
  background: rgba(22, 24, 29, .05);
  border-radius: 14px;
}
.seg button {
  flex: 1; padding: 9px 6px; border-radius: 10px;
  font-size: 13.5px; color: var(--muted); font-weight: 500;
  transition: background .15s ease, color .15s ease, box-shadow .15s ease;
}
.seg button.is-on {
  background: var(--surface); color: var(--ink); font-weight: 600;
  box-shadow: 0 1px 3px rgba(16, 18, 22, .12);
}

.switch {
  width: 48px; height: 28px; border-radius: 999px;
  background: rgba(22, 24, 29, .18);
  position: relative;
  transition: background .18s ease;
  flex: none;
}
.switch i {
  position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform .18s ease;
}
.switch[aria-pressed="true"] { background: #34a853; }
.switch[aria-pressed="true"] i { transform: translateX(20px); }

input[type="range"] { width: 100%; accent-color: var(--ru); }

.sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.sheet-actions .ghost { height: 40px; }

.primary {
  width: 100%; padding: 14px; border-radius: 14px;
  background: var(--ink); color: #fff; font-size: 15.5px; font-weight: 600;
  margin-top: 12px;
}
.primary:active { transform: scale(.99); }
.primary:disabled { opacity: .5; }

textarea { resize: none; margin-top: 10px; line-height: 1.45; }

/* ---------- тост ---------- */

.toast {
  position: fixed; left: 50%; bottom: calc(110px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  background: rgba(22, 24, 29, .92);
  color: #fff; font-size: 13.5px;
  padding: 10px 16px; border-radius: 12px;
  max-width: 84vw; text-align: center; line-height: 1.4;
  z-index: 80;
  animation: toast-in .2s ease both;
  pointer-events: none;
}

/* ---------- анимации ---------- */

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: none; } }
@keyframes slide-up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
@keyframes toast-in { from { opacity: 0; transform: translateX(-50%) translateY(10px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }
@keyframes ripple { 0% { transform: scale(1); opacity: .45; } 100% { transform: scale(1.55); opacity: 0; } }
@keyframes bounce { 0%, 100% { height: 7px; } 50% { height: 26px; } }
@keyframes blink { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

.diag { color: #8b909a; font-size: 11.5px; line-height: 1.5; margin-top: 4px; }

/* Пока держим кнопку — никаких прокруток и выделений: иначе Android
   отменяет жест и запись обрывается через 30 мс. */
html.is-holding, html.is-holding * {
  touch-action: none !important;
  user-select: none !important;
  -webkit-user-select: none !important;
}

.say {
  display: inline-grid; place-items: center;
  width: 26px; height: 26px; margin-left: 6px;
  border-radius: 8px;
  background: rgba(22, 24, 29, .06);
  color: var(--ink);
  font-size: 11px;
  vertical-align: middle;
}
.say:active { transform: scale(.94); }

.rate-value {
  font-size: 11.5px; color: var(--muted);
  font-variant-numeric: tabular-nums;
  margin-left: 4px;
}

.usage {
  margin: 2px 0 14px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(22, 24, 29, .045);
  border: 1px solid var(--line);
}
.usage-title { font-size: 12px; font-weight: 600; color: #4a4e57; margin-bottom: 5px; letter-spacing: .02em; }
.usage-line { font-size: 13.5px; line-height: 1.45; color: var(--ink); }
.usage-hint { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* Кнопка «фото» — крупная и заметная: это основной вход для документов */
.icon-btn.accent {
  width: 46px; height: 46px;
  border-radius: 15px;
  color: #fff;
  background: linear-gradient(150deg, #3c4459, #1a1e28);
  box-shadow: 0 8px 18px -10px rgba(19, 23, 34, .9), inset 0 1px 0 rgba(255, 255, 255, .14);
}
.icon-btn.accent:hover { background: linear-gradient(150deg, #48516a, #232834); }
.icon-btn.accent:active { transform: scale(.95); }
.icon-btn.accent svg { width: 25px; height: 25px; }
.icon-btn.accent:disabled { opacity: .55; }

.tool.is-playing {
  color: #fff;
  background: var(--ru);
}

.sheet-cta { display: flex; gap: 10px; align-items: stretch; margin-top: 12px; }
.sheet-cta .primary { flex: 1; margin-top: 0; }
.sheet-cta .ghost { padding: 0 16px; font-size: 14.5px; }

/* переносы строк в переводе: разбор формы идёт списком */
.dst { white-space: pre-wrap; }

/* поворот перевода: собеседник напротив читает нормально */
.dst { transition: transform .28s cubic-bezier(.22,.9,.3,1); transform-origin: center; }
.dst.flipped { transform: rotate(180deg); }

/* кнопка в режиме «нажатие» показывает, что идёт запись */
.talk.is-rec .talk-flag { background: rgba(255, 255, 255, .32); }

.tool.is-active { color: #fff; background: var(--ink); }
