:root {
  --bg: #f3f6f7;
  --surface: #ffffff;
  --border: #e3e7ec;
  --text: #121826;
  --text-2: #4b5565;
  --muted: #9aa4b2;
  --accent: #5046e5;
  --accent-hover: #4338ca;
  --accent-soft: #8f88f2;
  --badge: #9aa5b8;
  --danger: #c2410c;
  --radius: 14px;
  --radius-sm: 10px;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, textarea { font: inherit; color: inherit; }

.container {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  /* на iPhone в горизонтальном положении — не залезать под вырез экрана */
  padding-left: max(24px, env(safe-area-inset-left));  /* только по бокам: вертикальные отступы у main свои */
  padding-right: max(24px, env(safe-area-inset-right));
}

/* верхняя полоса */
.topbar {
  background: var(--surface);
  padding-top: env(safe-area-inset-top);
}
.topbar__inner {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 60px;
}
.logo {
  color: var(--accent);
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.01em;
  text-decoration: none;
}
.badge {
  background: var(--badge);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
  padding: 4px 7px;
  border-radius: 999px;
}

/* кнопки под переводом и окно «Сообщить об ошибке» */
.pane__actions { display: flex; gap: 2px; flex: none; }
.btn.btn--ghost { background: var(--bg); color: var(--text); }  /* .btn: общие правила кнопки идут в файле ниже */
@media (hover: hover) { .btn.btn--ghost:hover:not(:disabled) { background: #e8edf0; } }
.dialog {
  width: min(480px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 60px rgba(18, 24, 38, .18);
}
.dialog::backdrop { background: rgba(18, 24, 38, .35); }
.dialog form { display: flex; flex-direction: column; gap: 12px; padding: 22px; }
.dialog__title { margin: 0 0 4px; font-size: 19px; font-weight: 800; }
.dialog__label { display: block; margin-bottom: 4px; color: var(--text-2); font-size: 13px; font-weight: 600; }
.dialog__quote p {
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-size: 15px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 96px;
  overflow-y: auto;
}
.dialog__field textarea, .dialog__input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  min-height: 64px;  /* не как у главного поля переводчика (там 120px и растягивание) */
  flex: none;
  font-size: 16px;  /* 16px — iPhone не увеличивает страницу при вводе */
  line-height: 1.45;
  resize: vertical;
  outline: 0;
}
.dialog__input { min-height: 0; resize: none; }
.dialog__field textarea:focus, .dialog__input:focus { border-color: var(--accent-soft); }
.dialog__field textarea::placeholder, .dialog__input::placeholder { color: var(--muted); }
.dialog__trap { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.dialog__note { margin: 0; color: var(--muted); font-size: 12.5px; }
.dialog__error { margin: 0; color: var(--danger); font-size: 13.5px; }
.dialog__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* вход через Hugging Face: кнопки в стиле переводчика — «Войти» как переключатель языков,
   «Регистрация» как «Перевести» */
.auth { margin-left: auto; position: relative; }
.auth__login, .auth__user, .auth__signup {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 16px;
  border: 0;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, box-shadow .15s;
}
.auth__login { background: var(--bg); color: var(--text); }
.auth__signup { background: var(--accent); color: #fff; }
.auth__user { background: var(--surface); border: 1px solid var(--border); font-weight: 700; }
.auth__login:focus-visible, .auth__signup:focus-visible, .auth__user:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.auth__user[aria-expanded="true"] { border-color: var(--accent-soft); }
@media (hover: hover) {
  .auth__login:hover { background: #e8edf0; }
  .auth__signup:hover { background: var(--accent-hover); }
  .auth__user:hover { border-color: var(--accent-soft); }
}
.auth__login:active, .auth__signup:active { transform: scale(.98); }
.auth__user { padding: 0 10px 0 5px; }
.auth__guest { display: flex; align-items: center; gap: 8px; }
@media (max-width: 420px) {  /* узкий телефон: кнопки компактнее, чтобы шапка поместилась */
  .auth__login, .auth__signup { min-height: 36px; padding: 0 12px; font-size: 13px; }
  .auth__guest { gap: 6px; }
}
@media (max-width: 340px) { .badge { display: none; } }
.auth__login:focus-visible, .auth__user:focus-visible { outline: none; border-color: var(--accent-soft); box-shadow: 0 0 0 3px rgba(80, 70, 229, .2); }
.auth__user[aria-expanded="true"] { border-color: var(--accent-soft); }
@media (hover: hover) { .auth__login:hover, .auth__user:hover { border-color: var(--accent-soft); } }
.auth__avatar {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #ece9fd;
  color: var(--accent);
}
.auth__avatar svg { width: 16px; height: 16px; }
.auth__name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.auth__chevron { width: 16px; height: 16px; color: var(--muted); transition: transform .2s ease; }
.auth__user[aria-expanded="true"] .auth__chevron { transform: rotate(180deg); }

.user-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 8px);
  right: 0;
  width: max-content;
  min-width: 240px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 12px 32px rgba(18, 24, 38, .10), 0 2px 6px rgba(18, 24, 38, .05);
  animation: menu-in .14s ease-out;
}
.user-menu__item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.user-menu__item:focus-visible { outline: none; background: var(--bg); }
@media (hover: hover) { .user-menu__item:hover { background: var(--bg); } }
.user-menu__icon { flex: none; width: 18px; height: 18px; margin-top: 1px; color: var(--muted); }
.user-menu__icon--accent { color: var(--accent); }
.user-menu__title { display: block; font-weight: 700; line-height: 1.35; white-space: nowrap; }
.user-menu__title--plain { font-weight: 500; color: var(--text-2); }
.user-menu__hint { display: block; margin-top: 2px; color: var(--muted); font-size: 12.5px; }
.user-menu__sep { height: 1px; margin: 6px 4px; background: var(--border); }
.out-action { margin-top: 12px; }
.out-link { color: var(--accent); font-weight: 600; }

/* на высоких экранах (планшет вертикально) отступы и поля растут, чтобы внизу не оставалось пустоты */
main { flex: 1; display: flex; flex-direction: column; padding-bottom: clamp(64px, 10vh - 40px, 120px); }
/* лишнее место по высоте — поровну сверху и снизу: переводчик по центру экрана */
main > .hero { margin-top: auto; }
main > .about { margin-bottom: auto; }

/* заголовок */
.hero { padding: clamp(56px, 10vh - 40px, 120px) 0 40px; }
.hero h1 {
  margin: 0;
  font-size: clamp(24px, 2.2vw + 16px, 38px);  /* плавно: 24px на маленьком телефоне → 38px на компьютере */
  line-height: 1.15;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.hero .accent { color: var(--accent); }
.hero p {
  margin: 10px 0 0;
  color: var(--text-2);
  font-size: 14px;
}

/* карточка переводчика */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
}
.card__head {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}
.direction {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 26px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s;
}
@media (hover: hover) { .direction:hover { background: #e8edf0; } }
.direction:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.direction__icon {
  width: 16px;
  height: 16px;
  transition: transform .25s ease;
}
.direction.is-flipped .direction__icon { transform: rotate(180deg); }

.panes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
.pane {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 310px;
  min-height: clamp(310px, 100dvh - 560px, 560px);
  border-radius: var(--radius-sm);
}
.pane--input {
  border: 1px solid var(--border);
  background: var(--surface);
  transition: border-color .15s;
}
.pane--input:focus-within { border-color: var(--accent-soft); }
.pane--output { background: var(--bg); }

textarea, .output {
  flex: 1;
  width: 100%;
  margin: 0;
  padding: 18px 48px 8px 20px;
  font-size: 17px;
  line-height: 1.55;
}
textarea {
  flex: 1 0 auto;
  min-height: 120px;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
}
textarea::placeholder { color: var(--muted); }
.output {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  padding-right: 20px;
}
.output.is-error { color: var(--danger); font-size: 15px; }
.output.is-loading::after {
  content: "";
  display: inline-block;
  width: 1.2em;
  text-align: left;
  animation: dots 1.2s steps(4, end) infinite;
}
@keyframes dots {
  0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; }
}

/* слово из словаря с вариантами */
.word-wrap { position: relative; display: inline-block; max-width: 100%; overflow-wrap: normal; }
.word {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  margin: -2px 0 0 -10px;
  padding: 5px 12px 5px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 17px;
  font-weight: 600;
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
@media (hover: hover) { .word:hover { border-color: var(--accent-soft); } }
.word[aria-expanded="true"] { border-color: var(--accent-soft); box-shadow: 0 0 0 3px rgba(80, 70, 229, .12); }
.word:focus { outline: none; }
.word:focus-visible { border-color: var(--accent-soft); box-shadow: 0 0 0 3px rgba(80, 70, 229, .2); }
.word__chevron {
  flex: none;
  width: 18px;
  height: 18px;
  margin-top: 2px;  /* по центру строчных букв, а не всей строки */
  color: var(--accent);
  transition: transform .2s ease;
}
.word[aria-expanded="true"] .word__chevron { transform: rotate(180deg); }

.menu {
  position: absolute;
  z-index: 10;
  top: calc(100% + 6px);
  left: -10px;
  min-width: 220px;
  max-width: min(320px, calc(100vw - 48px));
  max-height: 300px;
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: 0 12px 32px rgba(18, 24, 38, .12), 0 2px 6px rgba(18, 24, 38, .06);
  white-space: normal;
  animation: menu-in .14s ease-out;
}
@keyframes menu-in { from { opacity: 0; transform: translateY(-4px); } }
.menu__head {
  padding: 6px 10px 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.menu__group { display: flex; gap: 4px; }
.menu__group + .menu__group { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 4px; }
.menu__label {
  flex: none;
  width: 22px;
  padding-top: 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}
.menu__items { flex: 1; min-width: 0; }
.menu__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 7px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}
.menu__item:focus-visible { background: var(--bg); outline: 0; }
@media (hover: hover) { .menu__item:hover { background: var(--bg); } }
.menu__item.is-selected { color: var(--accent); font-weight: 600; }
.menu__check { flex: none; width: 16px; height: 16px; visibility: hidden; }
.menu__item.is-selected .menu__check { visibility: visible; }

.pane__clear {
  position: absolute;
  top: 10px;
  right: 10px;
}
.pane__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px 12px 20px;
  min-height: 56px;
}
.counter, .note {
  color: var(--muted);
  font-size: 13px;
}
.note { color: var(--text-2); font-size: 12px; line-height: 1.4; }
.counter.is-full { color: var(--danger); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn svg { width: 17px; height: 17px; }
@media (hover: hover) { .icon-btn:hover:not(:disabled) { background: rgba(18, 24, 38, .06); color: var(--text); } }
.icon-btn:disabled { opacity: .4; cursor: default; }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn {
  flex: none;
  min-height: 40px;
  padding: 0 20px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}
@media (hover: hover) { .btn:hover:not(:disabled) { background: var(--accent-hover); } }
.btn:disabled { opacity: .6; cursor: default; }
.btn:active:not(:disabled), .direction:active { transform: scale(.98); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* плашка внизу */
/* «О переводчике» — внизу, мелким серым текстом */
.about {
  max-width: 720px;
  margin: 40px auto 0;
  color: var(--text-2);
  font-size: 14px;
  line-height: 1.6;
  text-align: center;
}
.about h2 { margin: 0 0 6px; color: var(--text); font-size: 15px; font-weight: 700; }
.about p { margin: 0; }
@media (max-width: 720px) { .about { margin-top: 28px; font-size: 13px; text-align: left; } }

.info {
  display: flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  max-width: 100%;
  margin: 28px auto 0;
  padding: 8px 16px;
  border: 1px solid var(--accent-soft);
  border-radius: 999px;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
}
.info svg { flex: none; width: 15px; height: 15px; color: var(--muted); }

.footer {
  height: 56px;
  background: var(--surface);
  padding-bottom: env(safe-area-inset-bottom);
  box-sizing: content-box;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--text);
  color: #fff;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.is-shown { opacity: 1; transform: translate(-50%, 0); }

/* большой монитор */
@media (min-width: 1440px) {
  .container { max-width: 1040px; }
  .pane { min-height: clamp(360px, 100dvh - 580px, 600px); }
}

/* планшет */
@media (min-width: 721px) and (max-width: 1024px) {
  .container { padding-left: max(32px, env(safe-area-inset-left)); padding-right: max(32px, env(safe-area-inset-right)); }
  .hero { padding: clamp(44px, 10vh - 50px, 110px) 0 32px; }
  .pane { min-height: clamp(280px, 100dvh - 540px, 720px); }
}

/* телефон */
@media (max-width: 720px) {
  .container { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .topbar__inner { height: 52px; }
  .hero { padding: clamp(28px, 6vh - 12px, 48px) 0 20px; }
  .hero p { font-size: 13px; }
  .card { padding: 12px; }
  .card__head { margin-bottom: 12px; }
  .direction { width: 100%; justify-content: center; }
  .panes { grid-template-columns: 1fr; gap: 12px; }
  .pane { min-height: clamp(190px, (100dvh - 420px) / 2, 280px); }  /* два поля друг под другом */
  textarea { min-height: 110px; }
  textarea, .output { font-size: 17px; padding-left: 16px; }
  .pane__foot { padding-left: 16px; }
  .info { border-radius: 14px; align-items: flex-start; font-size: 12px; margin-top: 20px; }
  .info svg { margin-top: 1px; }
  main { padding-bottom: 32px; }
  .footer { height: 24px; }
}

/* маленький телефон (iPhone SE, старые Android) */
@media (max-width: 360px) {
  .container { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .hero { padding: 20px 0 16px; }
  .hero p { font-size: 12px; }
  .card { padding: 10px; border-radius: 12px; }
  .direction { font-size: 13px; padding: 0 12px; }
  textarea, .output { font-size: 16px; padding: 14px 44px 6px 14px; }
  .output { padding-right: 14px; }
  .pane__foot { padding: 8px 8px 10px 14px; gap: 8px; }
  .btn { padding: 0 16px; }
  .info { font-size: 11.5px; padding: 8px 12px; }
}

/* телефон в горизонтальном положении: экран низкий — меньше отступов */
@media (max-height: 500px) and (orientation: landscape) {
  .topbar__inner { height: 44px; }
  .hero { padding: 16px 0 12px; }
  .hero h1 { font-size: 24px; }
  .hero p { margin-top: 4px; }
  .card__head { margin-bottom: 10px; }
  .direction { min-height: 40px; }
  .panes { grid-template-columns: 1fr 1fr; gap: 10px; }
  .pane { min-height: 160px; }
  textarea { min-height: 90px; }
  .info { margin-top: 14px; }
}

/* сенсорный экран: кнопки не меньше 44px, чтобы попадать пальцем */
@media (pointer: coarse) {
  .icon-btn { width: 44px; height: 44px; }
  .btn { min-height: 44px; }
  .menu__item { padding: 11px 12px; }
  .pane__clear { top: 6px; right: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
