/* Единое приложение @allvoicecoderobot — общие токены, флаги, выбор языка.
   Палитра та же, что у боевого переводчика (exchanger / qeksi). */

:root, [data-theme="day"] {
  --bg:          #FCFBFC;
  --card:        #FFFFFF;
  --card2:       #FFF0F4;
  --border:      #F0D0DC;
  --sakura:      #D93060;
  --sakura2:     #F0507A;
  --sakura-glow: rgba(217, 48, 96, 0.16);
  --cyan:        #0088BB;
  --cyan-glow:   rgba(0, 136, 187, 0.15);
  --text:        #1A0A14;
  --muted:       #8B6070;
  --faint:       #EAC8D4;
  --brand-shadow: 0 0 16px rgba(217, 48, 96, 0.25);
  --nav-bg:      #FFFFFF;
  --stage:       #F4E9EE;
  --tertiary:    #B78A9B;
  --on-brand:    #FFFFFF;
  --petals:      none;
  --shadow:      0 1px 2px rgba(26, 10, 20, .05), 0 10px 30px rgba(26, 10, 20, .08);
}

[data-theme="night"] {
  --bg:          #0B122D;
  --card:        #101640;
  --card2:       #141B4A;
  --border:      #1F2C5C;
  --sakura:      #FF6EB4;
  --sakura2:     #FFB3D8;
  --sakura-glow: rgba(255, 110, 180, 0.22);
  --cyan:        #00D4FF;
  --cyan-glow:   rgba(0, 212, 255, 0.18);
  --text:        #EEF0FF;
  --muted:       #7888C0;
  --faint:       #112040;
  --brand-shadow: 0 0 25px rgba(255, 110, 180, 0.6), 0 0 55px rgba(255, 110, 180, 0.2);
  --nav-bg:      #070F28;
  --stage:       #05091A;
  --tertiary:    #5A69A0;
  --on-brand:    #0B122D;
  --shadow:      0 1px 2px rgba(0, 0, 0, .5), 0 10px 30px rgba(0, 0, 0, .5);
  --petals:
    radial-gradient(ellipse 18px 10px at 12%  9%,  rgba(255, 110, 180, 0.16) 0%, transparent 100%),
    radial-gradient(ellipse 12px  7px at 30% 16%,  rgba(255, 179, 216, 0.12) 0%, transparent 100%),
    radial-gradient(ellipse 20px 11px at 74%  7%,  rgba(255, 110, 180, 0.14) 0%, transparent 100%),
    radial-gradient(ellipse 14px  8px at 88% 20%,  rgba(255, 179, 216, 0.10) 0%, transparent 100%),
    radial-gradient(ellipse 16px  9px at 46% 26%,  rgba(255, 110, 180, 0.09) 0%, transparent 100%),
    radial-gradient(ellipse 22px 12px at 20% 44%,  rgba(255, 179, 216, 0.07) 0%, transparent 100%),
    radial-gradient(ellipse 15px  8px at 64% 50%,  rgba(255, 110, 180, 0.08) 0%, transparent 100%),
    radial-gradient(ellipse 80px 22px at 50% 100%, rgba(0, 212, 255, 0.06) 0%, transparent 100%);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--stage);
  color: var(--text);
  font-family: 'Inter', "Noto Sans Thai", "Noto Sans Lao", "Noto Sans SC", ui-sans-serif, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background .6s ease, color .6s ease;
}

button, textarea, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--sakura); outline-offset: 2px; }

/* ── флаги ─────────────────────────────────────────────── */

.flag { display: block; flex: none; width: 21px; height: 14px; }
.flag-sm { width: 24px; height: 16px; }
.flag-lg { width: 42px; height: 28px; }
.flag-xl { width: 48px; height: 32px; }

img.flag {
  object-fit: cover;
  border-radius: 3px;
  box-shadow: 0 0 0 .6px rgba(0, 0, 0, .14);
}

/* язык без государства (эсперанто, курдский…) — плашка с кодом */
.flag-code {
  display: grid;
  place-items: center;
  border-radius: 3px;
  background: var(--card2);
  color: var(--sakura);
  box-shadow: inset 0 0 0 1px var(--border);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: .02em;
}
.flag-sm.flag-code { font-size: 9px; }
.flag-lg.flag-code { font-size: 13px; }
.flag-xl.flag-code { font-size: 14px; }

/* ── выбор языка ───────────────────────────────────────── */

.picker {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 16px calc(18px + env(safe-area-inset-bottom));
  background-color: var(--bg);
  background-image: var(--petals);
  opacity: 0;
  visibility: hidden;
  transform: translateY(14px);
  transition: opacity .22s ease, transform .26s cubic-bezier(.2, .8, .3, 1), visibility 0s .26s;
}

.picker.on {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: opacity .22s ease, transform .26s cubic-bezier(.2, .8, .3, 1);
}

.picker-top {
  width: 100%;
  max-width: 430px;
  display: flex;
  justify-content: flex-end;
}

.picker-close {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: none;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  color: var(--muted);
}

.picker-close:hover { background: var(--card2); color: var(--sakura); }
.picker-close svg { width: 18px; height: 18px; }

.picker-cols {
  flex: 1;
  width: 100%;
  max-width: 430px;
  display: grid;
  grid-template-columns: 1fr 28px 1fr;
  align-items: center;
  gap: 4px;
}

.picker-col { min-width: 0; }

.picker-label {
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--cyan);
  margin-bottom: 10px;
}

.picker-mid { color: var(--sakura); padding-top: 24px; }
.picker-mid svg { width: 26px; height: 26px; display: block; margin: 0 auto; }

/* видно три строки, выбранная — средняя */
.wheel {
  position: relative;
  height: 276px;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 30%, #000 70%, transparent 100%);
          mask-image: linear-gradient(to bottom, transparent 0, #000 30%, #000 70%, transparent 100%);
}

.wheel::-webkit-scrollbar { display: none; }

.wheel-pad { height: 92px; }

.wheel-item {
  height: 92px;
  width: 100%;
  /* по центру: точку прилипания Chrome считает по уменьшенному пункту,
     а центр от масштаба не сдвигается */
  scroll-snap-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: none;
  border: 0;
  border-radius: 16px;
  cursor: pointer;
  transform: scale(.8);
  opacity: .55;
  transition: transform .18s ease, opacity .18s ease, background .18s ease;
}

.wheel-item.on {
  transform: none;
  opacity: 1;
  background: var(--sakura-glow);
}

.wheel-name, .wheel-ru {
  max-width: 100%;
  padding: 0 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wheel-name { font-size: 16px; font-weight: 600; line-height: 1.15; }
.wheel-ru { font-size: 11.5px; color: var(--muted); min-height: 13px; }
.wheel-beta {
  margin-left: 5px;
  padding: 0 5px;
  border-radius: 6px;
  border: 1px solid var(--sakura);
  color: var(--sakura);
  font-size: 9.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  vertical-align: 1px;
}

.wheel-empty {
  height: 92px;
  display: grid;
  place-items: center;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

.picker-search {
  display: block;
  width: 100%;
  margin: 0 0 8px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  font-size: 14px;
  outline: none;
  -webkit-appearance: none;
          appearance: none;
}
.picker-search:focus { border-color: var(--sakura); }
.picker-search::placeholder { color: var(--tertiary); }

.picker-go {
  width: 100%;
  max-width: 398px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 15px 18px;
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  background: var(--sakura);
  color: var(--on-brand);
  font-size: 16px;
  font-weight: 700;
  box-shadow: var(--brand-shadow);
}

.picker-go:active { transform: scale(.99); }
.picker-go .go-arrow { width: 16px; height: 16px; opacity: .8; }
.picker-go span { margin-left: 6px; }

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

/* ── язык интерфейса ─────────────────────────────────── */

/* словарь языка интерфейса ещё грузится — не показываем русский на миг */
.i18n-wait body { visibility: hidden; }

/* интерфейс на арабском, иврите и т.п.: раскладка прежняя, но каждая
   надпись сама берёт направление по своему тексту */
.ui-rtl [data-i18n],
.ui-rtl [data-i18n-html] { unicode-bidi: plaintext; }

/* ── история (all-history.js) ──────────────────────────── */

.hist {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 16px calc(14px + env(safe-area-inset-bottom));
  background-color: var(--bg);
  background-image: var(--petals);
  color: var(--text);
  opacity: 0;
  visibility: hidden;
  transform: translateY(14px);
  transition: opacity .22s ease, transform .26s cubic-bezier(.2, .8, .3, 1), visibility 0s .26s;
}

.hist.on {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: opacity .22s ease, transform .26s cubic-bezier(.2, .8, .3, 1);
}

.hist > * { width: 100%; max-width: 430px; }

.hist-top {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hist-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hist-btn {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: none;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  color: var(--muted);
}
.hist-btn:hover { background: var(--card2); color: var(--sakura); }
.hist-btn svg { width: 18px; height: 18px; }
.hist-back { display: none; }
.hist.in-talk .hist-back { display: grid; }
.hist:not(.in-talk) .hist-title { padding-left: 6px; }

.hist-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 8px 0 10px;
  padding: 4px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--border);
}
.hist.in-talk .hist-tabs { display: none; }

.hist-tabs button {
  padding: 9px 6px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.hist-tabs button[aria-selected="true"] { background: var(--sakura); color: var(--on-brand); }

.hist-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 8px;
}

.hist-empty, .hist-note {
  margin: 0;
  padding: 18px 10px;
  text-align: center;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--muted);
}
.hist-empty { margin: auto 0; }
.hist-note { padding: 6px 10px; font-size: 12px; }

.hist-card {
  position: relative;
  flex: none;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--border);
}

.hist-open {
  display: block;
  width: 100%;
  padding: 10px 40px 11px 13px;
  border: 0;
  border-radius: 14px;
  background: none;
  color: inherit;
  font: inherit;
  text-align: start;
  cursor: pointer;
}
.hist-talk { padding-right: 13px; }
.hist-open:active { background: var(--card2); }

.hist-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.hist-meta + .hist-src { margin-top: 6px; }
.hist-talk .hist-src + .hist-meta { margin-top: 6px; }

.hist-pair { display: inline-flex; align-items: center; gap: 4px; }
.hist-pair svg { width: 12px; height: 12px; color: var(--tertiary); }
.hist-kind svg { width: 14px; height: 14px; display: block; color: var(--cyan); }
.hist-time { margin-left: auto; }
.hist-ttl { color: var(--cyan); }
.hist-meta .hist-ttl { margin-left: auto; }

.hist-src, .hist-out {
  font-size: 15px;
  line-height: 1.35;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow-wrap: anywhere;
}
.hist-src { color: var(--muted); }
.hist-out { margin-top: 3px; font-weight: 600; }
.hist-talk .hist-src { color: var(--text); -webkit-line-clamp: 2; }

.hist-del {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--tertiary);
  cursor: pointer;
}
.hist-del:hover { background: var(--card2); color: var(--sakura); }
.hist-del svg { width: 15px; height: 15px; }

.hist-foot { display: flex; gap: 8px; padding-top: 8px; }
.hist-foot:empty { display: none; }

.hist-action {
  flex: 1;
  padding: 13px 10px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
}
.hist-action:active { transform: scale(.99); }
.hist-danger { flex: none; color: var(--sakura); }

/* разговор: мои реплики справа, собеседника слева — как в мессенджере */
.talk-msg {
  flex: none;
  max-width: 86%;
  padding: 8px 12px 10px;
  border-radius: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  overflow-wrap: anywhere;
}
.talk-msg.me {
  align-self: flex-end;
  border-bottom-right-radius: 5px;
  background: var(--sakura-glow);
  border-color: transparent;
}
.talk-msg.them { align-self: flex-start; border-bottom-left-radius: 5px; }

.talk-who { font-size: 11.5px; color: var(--muted); margin-bottom: 3px; }
.talk-main { font-size: 16px; line-height: 1.38; }
.talk-sub {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
  font-size: 13.5px;
  line-height: 1.35;
  color: var(--muted);
}
.talk-msg.me .talk-sub { border-top-color: var(--sakura-glow); }

/* кнопка истории: точка — есть разговор, который ещё можно перечитать */
.hist-dot { position: relative; }
.hist-dot::after {
  content: "";
  position: absolute;
  top: 7px;
  right: 7px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--sakura);
}
