/* Вавилон v2 — «дорожный дневник»: светлая бумага, чернила, два штампа-акцента.
   Светлая тема выбрана намеренно: разговор идёт на улице, при солнце. */

:root {
  --paper: #f3eee4;
  --paper-2: #eae2d1;
  --paper-3: #e0d6c1;
  --ink: #17130f;
  --ink-2: #5e564b;
  --ink-3: #948a7b;
  --line: rgba(23, 19, 15, 0.12);
  --me: #c8471f;
  --me-deep: #9f3312;
  --me-soft: #f7dfd3;
  --them: #1e6e6a;
  --them-deep: #124d4a;
  --them-soft: #d3ebe5;
  --ok: #2e7d4f;
  --warn: #b7791f;
  --bad: #b3261e;
  --shadow: 0 18px 40px -22px rgba(23, 19, 15, 0.45);
  --r-lg: 26px;
  --r-md: 18px;
  --r-sm: 12px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --display: "Unbounded", "Golos Text", system-ui, sans-serif;
  --body: "Golos Text", "Be Vietnam Pro", "Sarabun", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.4;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* бумага: лёгкое зерно + тёплое виньетирование */
.paper {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(255, 255, 255, 0.55), transparent 60%),
    radial-gradient(90% 60% at 50% 110%, rgba(200, 71, 31, 0.08), transparent 60%);
}
.paper::after {
  content: ""; position: absolute; inset: 0; opacity: 0.35; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.2 0 0 0 0 0.17 0 0 0 0 0.13 0 0 0 0.35 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

/* ------------------------------------------------------------- экраны */
.screen {
  position: relative; z-index: 1;
  max-width: 520px; margin: 0 auto;
  min-height: 100dvh;
  padding: calc(var(--safe-t) + 20px) 20px calc(var(--safe-b) + 24px);
  display: flex; flex-direction: column; gap: 22px;
  animation: rise 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------- бренд */
.brand { display: flex; align-items: center; gap: 16px; padding-top: 6px; }
.brand__stamp {
  width: 58px; height: 58px; border-radius: 50%; flex: none;
  border: 3px solid var(--me); display: grid; place-items: center;
  position: relative; transform: rotate(-8deg);
  font-family: var(--display); font-weight: 800; font-size: 26px; color: var(--ink);
}
.brand__stamp::before {
  content: ""; position: absolute; inset: 6px; border-radius: 50%;
  border: 2px dashed var(--them);
}
.brand__stamp--lg { width: 86px; height: 86px; font-size: 40px; margin: 0 auto 14px; }
.brand__text h1 {
  margin: 0; font-family: var(--display); font-weight: 800; font-size: 30px; letter-spacing: -0.01em; line-height: 1;
}
.brand__text p { margin: 6px 0 0; color: var(--ink-2); font-size: 15px; }

/* ------------------------------------------------------------- поля */
.field { display: flex; flex-direction: column; gap: 10px; }
.field--inline { gap: 8px; }
.field__lbl {
  font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-3); font-weight: 600;
}
.input {
  width: 100%; padding: 14px 16px; border-radius: var(--r-sm);
  border: 1.5px solid var(--line); background: rgba(255, 255, 255, 0.55);
  outline: none; transition: border-color 0.2s, background 0.2s;
}
.input:focus { border-color: var(--ink); background: #fff; }
.input--pin { text-align: center; font-size: 28px; letter-spacing: 0.4em; font-family: var(--display); }

.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px; margin: -2px; }
.chips::-webkit-scrollbar { display: none; }
.chips--wrap { flex-wrap: wrap; overflow: visible; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; flex: none;
  padding: 10px 14px 10px 11px; border-radius: 999px;
  border: 1.5px solid var(--line); background: rgba(255, 255, 255, 0.5);
  font-weight: 500; font-size: 15px; color: var(--ink);
  transition: transform 0.15s, border-color 0.2s, background 0.2s, box-shadow 0.2s;
}
.chip:active { transform: scale(0.97); }
.chip .f { font-size: 18px; line-height: 1; }
.chip.is-on { border-color: var(--ink); background: var(--ink); color: var(--paper); box-shadow: var(--shadow); }
.chips--them .chip.is-on { background: var(--them); border-color: var(--them); }
.chip--more { color: var(--ink-2); border-style: dashed; background: transparent; font-family: var(--display); font-size: 13px; }

/* переключатель голоса */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 4px; border-radius: 14px; background: var(--paper-2); }
.seg__opt {
  padding: 11px 10px; border-radius: 10px; font-weight: 600; font-size: 14.5px; color: var(--ink-2);
  display: flex; align-items: center; justify-content: center; gap: 6px; transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}
.seg__opt.is-on { background: #fff; color: var(--ink); box-shadow: 0 2px 8px -4px rgba(23, 19, 15, 0.4); }
.join .seg { text-align: left; }

/* ------------------------------------------------------------- режимы */
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 4px; }
.mode {
  position: relative; text-align: left; display: flex; flex-direction: column; gap: 8px;
  padding: 18px 16px 18px; border-radius: var(--r-lg); min-height: 190px;
  background: rgba(255, 255, 255, 0.6); border: 1.5px solid var(--line);
  transition: transform 0.18s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.2s;
}
.mode:active { transform: scale(0.98); }
.mode__glyph { color: var(--ink-2); margin-bottom: 4px; }
.mode__title { font-family: var(--display); font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.mode__desc { color: var(--ink-2); font-size: 13.5px; line-height: 1.35; }
.mode--primary { background: var(--ink); color: var(--paper); border-color: var(--ink); box-shadow: var(--shadow); }
.mode--primary .mode__glyph { color: var(--me-soft); }
.mode--primary .mode__desc { color: rgba(243, 238, 228, 0.72); }
.mode--primary::after {
  content: ""; position: absolute; right: 14px; top: 14px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--me); box-shadow: 0 0 0 6px rgba(200, 71, 31, 0.25);
}
.foot { margin: auto 0 0; color: var(--ink-3); font-size: 13px; text-align: center; }

/* ------------------------------------------------------------- гость */
.join { margin: auto 0; display: flex; flex-direction: column; gap: 14px; text-align: center; }
.join__from { margin: 0; color: var(--ink-2); font-size: 15px; }
.join__from b { color: var(--ink); }
.join__title { margin: 0; font-family: var(--display); font-weight: 700; font-size: 22px; line-height: 1.2; }
.join__desc { margin: 0 0 8px; color: var(--ink-2); font-size: 15px; }
.join .chips { justify-content: center; }
.join .field__lbl { margin-top: 10px; }

.cta {
  width: 100%; padding: 18px 20px; border-radius: var(--r-md);
  background: var(--ink); color: var(--paper); font-family: var(--display); font-weight: 700; font-size: 17px;
  box-shadow: var(--shadow); transition: transform 0.15s;
}
.cta:active { transform: scale(0.98); }
.cta:disabled { opacity: 0.5; }
.ghost {
  width: 100%; padding: 14px; border-radius: var(--r-md); border: 1.5px solid var(--line);
  font-weight: 600; color: var(--ink-2); background: rgba(255, 255, 255, 0.5);
}
.ghost--close { border: 0; background: none; }
.err { color: var(--bad); font-weight: 500; margin: 0; }

/* ------------------------------------------------------------- разговор */
.screen--talk { padding: calc(var(--safe-t) + 8px) 0 0; gap: 0; height: 100dvh; min-height: 0; animation: none; }
.bar {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px 10px;
  border-bottom: 1px solid var(--line);
}
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; color: var(--ink-2);
  transition: background 0.2s;
}
.icon-btn:active { background: var(--paper-2); }
.bar__pair { display: flex; align-items: center; gap: 8px; margin-left: 2px; }
.bar__lang {
  font-family: var(--display); font-weight: 700; font-size: 14px; letter-spacing: 0.04em;
  padding: 6px 10px; border-radius: 8px;
}
.bar__lang--me { background: var(--me-soft); color: var(--me-deep); }
.bar__lang--them { background: var(--them-soft); color: var(--them-deep); }
.bar__arr { color: var(--ink-3); }
.bar__right { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.pill {
  padding: 9px 14px; border-radius: 999px; background: var(--ink); color: var(--paper);
  font-weight: 600; font-size: 13.5px;
}
.conn { width: 28px; height: 28px; display: grid; place-items: center; }
.conn__dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ink-3); transition: background 0.3s; }
.conn.is-live .conn__dot { background: var(--ok); box-shadow: 0 0 0 4px rgba(46, 125, 79, 0.18); }
.conn.is-wait .conn__dot { background: var(--warn); animation: blink 1s infinite; }
.conn.is-bad .conn__dot { background: var(--bad); }
@keyframes blink { 50% { opacity: 0.3; } }

.presence {
  display: flex; align-items: center; gap: 8px; justify-content: center;
  padding: 8px 14px; font-size: 13.5px; color: var(--ink-2); background: var(--paper-2);
}
.presence__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); }
.presence.is-on .presence__dot { background: var(--ok); }
.presence.is-speaking { color: var(--them-deep); background: var(--them-soft); }
.presence.is-speaking .presence__dot { background: var(--them); animation: blink 0.8s infinite; }

/* лента */
.feed {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px 14px 10px; display: flex; flex-direction: column; gap: 12px;
  scroll-behavior: smooth;
}
.feed__empty { margin: auto; text-align: center; color: var(--ink-3); padding: 20px; }
.feed__empty p { margin: 0 0 8px; font-size: 15px; }
.feed__hint { font-size: 13px; }

.msg {
  position: relative; max-width: 88%; padding: 12px 16px 12px 18px; border-radius: var(--r-md);
  background: rgba(255, 255, 255, 0.72); border: 1px solid var(--line);
  animation: pop 0.35s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
.msg::before { content: ""; position: absolute; left: 0; top: 12px; bottom: 12px; width: 4px; border-radius: 4px; }
.msg--me { align-self: flex-end; border-top-right-radius: 6px; }
.msg--me::before { background: var(--me); }
.msg--them { align-self: flex-start; border-top-left-radius: 6px; }
.msg--them::before { background: var(--them); }
.msg__who {
  display: flex; align-items: center; gap: 6px; font-size: 11.5px; letter-spacing: 0.1em; text-transform: uppercase;
  font-weight: 600; color: var(--ink-3); margin-bottom: 6px;
}
.msg--me .msg__who { color: var(--me-deep); }
.msg--them .msg__who { color: var(--them-deep); }
.msg__main { font-size: 19px; line-height: 1.32; font-weight: 500; overflow-wrap: anywhere; }
.msg__alt { margin-top: 6px; font-size: 14px; line-height: 1.35; color: var(--ink-2); overflow-wrap: anywhere; }
.msg__state {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 6px;
  font-size: 13px; color: var(--ink-3);
}
.msg__state::before {
  content: ""; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--ink-2); animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.msg__replay {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 8px;
  padding: 6px 10px 6px 8px; border-radius: 999px; font-size: 13px; font-weight: 600;
  color: var(--ink-2); background: var(--paper-2);
}
.msg__replay svg { width: 14px; height: 14px; }
.msg.is-playing .msg__replay { color: var(--paper); background: var(--ink); }
.msg.is-failed { opacity: 0.6; }
.msg.is-failed .msg__main { color: var(--bad); font-size: 15px; font-weight: 500; }

/* подсказка над кнопками */
.hint {
  text-align: center; font-size: 13.5px; color: var(--ink-3); padding: 6px 16px; min-height: 26px;
  transition: color 0.2s;
}
.hint.is-live { color: var(--me-deep); font-weight: 600; }
.hint.is-warn { color: var(--bad); font-weight: 600; }

/* кнопки удержания */
.controls {
  padding: 8px 18px calc(var(--safe-b) + 18px);
  display: flex; justify-content: center; align-items: flex-end;
  background: linear-gradient(to top, var(--paper) 70%, transparent);
}
.duo { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; width: 100%; }
.hold {
  --c: var(--me); --c-deep: var(--me-deep); --c-soft: var(--me-soft);
  position: relative; width: 100%; aspect-ratio: 1.15; max-height: 190px; border-radius: 30px;
  display: grid; place-items: center; isolation: isolate;
  background: var(--c-soft); color: var(--c-deep);
  border: 1.5px solid color-mix(in srgb, var(--c) 35%, transparent);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  transition: transform 0.12s cubic-bezier(0.2, 0.8, 0.2, 1), background 0.2s, box-shadow 0.2s;
  box-shadow: 0 10px 28px -16px color-mix(in srgb, var(--c) 60%, transparent);
}
.hold--them { --c: var(--them); --c-deep: var(--them-deep); --c-soft: var(--them-soft); }
.hold--one { width: min(100%, 320px); aspect-ratio: 1.7; max-height: 180px; }
.hold__core { position: relative; z-index: 2; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.hold__flag { font-size: 36px; line-height: 1; }
.hold__mic { opacity: 0.9; }
.hold__lbl { font-family: var(--display); font-weight: 700; font-size: 13px; letter-spacing: 0.02em; text-align: center; padding: 0 10px; }
.hold__ring {
  position: absolute; inset: -1.5px; border-radius: inherit; z-index: 0;
  border: 2px solid var(--c); opacity: 0; transition: opacity 0.2s;
}
.hold__level {
  position: absolute; left: 50%; top: 50%; width: 60%; aspect-ratio: 1; border-radius: 50%; z-index: 1;
  background: radial-gradient(circle, color-mix(in srgb, var(--c) 32%, transparent), transparent 70%);
  transform: translate(-50%, -50%) scale(var(--lvl, 0)); opacity: 0; transition: transform 0.08s linear, opacity 0.2s;
}
.hold.is-rec { background: var(--c); color: #fff; transform: scale(0.985); box-shadow: 0 16px 40px -14px var(--c); }
.hold.is-rec .hold__ring { opacity: 1; animation: ring 1.2s ease-out infinite; }
.hold.is-rec .hold__level { opacity: 1; background: radial-gradient(circle, rgba(255, 255, 255, 0.45), transparent 70%); }
@keyframes ring { 0% { transform: scale(1); opacity: 0.9; } 100% { transform: scale(1.08); opacity: 0; } }
.hold.is-busy { opacity: 0.55; pointer-events: none; }
.hold.is-off { opacity: 0.4; }
.hold:disabled { opacity: 0.5; }

/* ------------------------------------------------------------- шторки */
.sheet {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(23, 19, 15, 0.42); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: fade 0.25s both;
}
@keyframes fade { from { opacity: 0; } }
.sheet__card {
  width: 100%; max-width: 520px; background: var(--paper); border-radius: 28px 28px 0 0;
  padding: 10px 20px calc(var(--safe-b) + 20px); display: flex; flex-direction: column; gap: 12px;
  animation: up 0.35s cubic-bezier(0.2, 0.8, 0.2, 1) both; max-height: 92dvh; overflow-y: auto;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet__grip { width: 40px; height: 4px; border-radius: 4px; background: var(--paper-3); margin: 4px auto 6px; }
.sheet h3 { margin: 0; font-family: var(--display); font-weight: 700; font-size: 20px; }
.muted { margin: 0; color: var(--ink-2); font-size: 15px; }
.small { font-size: 13px; color: var(--ink-3); text-align: center; }
.qr-wrap { display: grid; place-items: center; padding: 10px 0 4px; }
.qr {
  width: min(62vw, 260px); height: auto; aspect-ratio: 1; background: #fff; border-radius: var(--r-md);
  padding: 12px; border: 1.5px solid var(--line); box-shadow: var(--shadow);
}
.code { display: flex; align-items: baseline; justify-content: center; gap: 10px; }
.code b { font-family: var(--display); font-weight: 800; font-size: 26px; letter-spacing: 0.22em; color: var(--ink); }

/* ------------------------------------------------------------- крупно */
.big {
  position: fixed; inset: 0; z-index: 30; background: var(--ink); color: var(--paper);
  display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 22px;
  padding: 40px 28px; text-align: center; animation: fade 0.2s both;
}
.big__text { font-family: var(--body); font-weight: 600; font-size: clamp(30px, 8vw, 54px); line-height: 1.2; overflow-wrap: anywhere; }
.big__sub { color: rgba(243, 238, 228, 0.6); font-size: clamp(16px, 4vw, 22px); overflow-wrap: anywhere; }
.big__close {
  position: absolute; top: calc(var(--safe-t) + 14px); right: 16px; width: 46px; height: 46px; border-radius: 50%;
  background: rgba(243, 238, 228, 0.12); color: var(--paper); font-size: 28px; line-height: 1;
}

/* ------------------------------------------------------------- тост */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 230px); z-index: 40; transform: translate(-50%, 20px);
  max-width: min(92vw, 440px); padding: 12px 16px; border-radius: 14px;
  background: var(--ink); color: var(--paper); font-size: 14.5px; font-weight: 500; text-align: center;
  opacity: 0; pointer-events: none; transition: opacity 0.25s, transform 0.25s; box-shadow: var(--shadow);
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }
.toast.is-bad { background: var(--bad); }

/* ------------------------------------------------------------- шрифты по языкам */
:lang(th), [lang="th"] { font-family: "Sarabun", var(--body); }
:lang(vi), [lang="vi"] { font-family: "Be Vietnam Pro", var(--body); }

@media (min-width: 560px) {
  .screen--talk { max-width: 560px; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
