/* =====================================================
   app.css

   Общие стили всех страниц: /login, / и /help.
   Отдаётся сервером как статика (STATIC_ROUTES в
   server.js). Разделов немного, поэтому одного файла на
   три страницы достаточно — лишние правила весят копейки
   и не стоят дробления.
   ===================================================== */

:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-muted: #6b6b68;
  --border: #e2e2de;
  --radius: 14px;

  --accent: #3454d1;
  --accent-soft: #eef1fc;
  --side-a: #3454d1;
  --side-a-bg: #eef1fc;
  --side-b: #0e8272;
  --side-b-bg: #e9f5f2;

  --danger: #dc2626;

  --dot-green: #16a34a;
  --dot-amber: #d97706;
  --dot-violet: #7c3aed;
  --dot-grey: #9c9c98;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0 0 32px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
}

/* ---------- шапка (главная и инструкция) ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.topbar-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  color: var(--accent);
  text-decoration: none;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
}

.topbar-link:active { background: var(--accent-soft); }

.topbar-link.help::before {
  content: "?";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  font-size: 13px;
  font-weight: 700;
}

.topbar-link.back {
  padding-left: 8px;
}

.topbar-link.back::before {
  content: "‹";
  font-size: 24px;
  line-height: 1;
  margin-top: -2px;
}

/* инструкция: шапка липнет к верху при прокрутке */
.topbar.sticky {
  position: sticky;
  top: 0;
  z-index: 10;
  justify-content: flex-start;
}

/* ---------- карточки и кнопки ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

button {
  width: 100%;
  min-height: 52px;
  padding: 12px 16px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.15s;
}

button[data-running="true"] { background: var(--danger); }

button:active:not(:disabled) { opacity: 0.85; }

button:disabled { opacity: 0.5; cursor: not-allowed; }

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- страница входа ---------- */

.login-wrap {
  max-width: 380px;
  margin: 0 auto;
  padding: 48px 16px 16px;
}

.login-wrap h1 {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 600;
  text-align: center;
}

.login-wrap .subtitle {
  margin: 0 0 20px;
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
}

.field { margin-bottom: 14px; }

.field label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.field input {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}

.field input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.form-error {
  margin-top: 12px;
  color: var(--danger);
  font-size: 14px;
  text-align: center;
  min-height: 20px;
}

/* ---------- главная: выбор языков ---------- */

.lang-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 14px;
}

.lang-field { flex: 1; min-width: 0; }

.swap-icon {
  color: var(--text-muted);
  padding-bottom: 11px;
  font-size: 16px;
  user-select: none;
}

.lang-field label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.lang-field select {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}

/* ---------- главная: крупный индикатор состояния ---------- */

.stage {
  --stage-bg: #f0f0ee;
  --stage-fg: #5a5a57;
  --stage-line: #dcdcd8;

  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  margin-bottom: 14px;
  border: 2px solid var(--stage-line);
  border-radius: var(--radius);
  background: var(--stage-bg);
  color: var(--stage-fg);
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.stage-icon {
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--stage-line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  line-height: 1;
}

.stage-text { min-width: 0; }

.stage-title {
  font-size: 21px;
  font-weight: 700;
  line-height: 1.2;
}

.stage-hint {
  font-size: 13px;
  opacity: 0.85;
  margin-top: 2px;
}

/* «можно говорить» — самое заметное состояние: насыщенный
   зелёный фон и пульсирующий ореол вокруг иконки */
.stage[data-state="listening"] {
  --stage-bg: #16a34a;
  --stage-fg: #ffffff;
  --stage-line: #15803d;
}

.stage[data-state="listening"] .stage-icon {
  background: rgba(255, 255, 255, 0.22);
  animation: halo 1.5s ease-out infinite;
}

.stage[data-state="speech"] {
  --stage-bg: #0e8272;
  --stage-fg: #ffffff;
  --stage-line: #0b6b5e;
}

.stage[data-state="speech"] .stage-icon {
  background: rgba(255, 255, 255, 0.22);
  animation: blink 1s ease-in-out infinite;
}

.stage[data-state="connecting"],
.stage[data-state="translating"] {
  --stage-bg: #fef3c7;
  --stage-fg: #92400e;
  --stage-line: #fcd34d;
}

.stage[data-state="translating"] .stage-icon {
  animation: blink 1.2s ease-in-out infinite;
}

.stage[data-state="playing"] {
  --stage-bg: #7c3aed;
  --stage-fg: #ffffff;
  --stage-line: #6d28d9;
}

.stage[data-state="playing"] .stage-icon {
  background: rgba(255, 255, 255, 0.22);
}

.stage[data-state="error"] {
  --stage-bg: #fee2e2;
  --stage-fg: #991b1b;
  --stage-line: #fca5a5;
}

@keyframes halo {
  0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.55); }
  100% { box-shadow: 0 0 0 18px rgba(255, 255, 255, 0); }
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@media (prefers-reduced-motion: reduce) {
  .stage-icon { animation: none !important; }
}

/* ---------- главная: стоимость и выход ---------- */

.cost-summary {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

.cost-summary strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.page-actions {
  margin-top: 16px;
  text-align: center;
}

.link-muted {
  display: inline-block;
  padding: 8px 12px;
  color: var(--text-muted);
  font-size: 14px;
  text-decoration: none;
  background: none;
  border: none;
  width: auto;
  min-height: 0;
  font-weight: 400;
  cursor: pointer;
}

.link-muted:hover { color: var(--text); }

/* ---------- главная: окно чата ---------- */

.chat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  height: 46vh;
  min-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.chat-empty {
  margin: auto;
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
}

.msg {
  max-width: 85%;
  padding: 8px 12px 6px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.msg-a {
  align-self: flex-start;
  background: var(--side-a-bg);
  border-bottom-left-radius: 4px;
}

.msg-b {
  align-self: flex-end;
  background: var(--side-b-bg);
  border-bottom-right-radius: 4px;
}

.msg-unknown { align-self: flex-start; }

.msg .original {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 3px;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg .translation {
  font-size: 15px;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.pending .translation {
  color: var(--text-muted);
  font-style: italic;
}

.msg.msg-error .translation { color: var(--danger); }

.msg .meta {
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
  margin-top: 3px;
  user-select: none;
}

.msg .badge {
  display: inline-block;
  padding: 0 6px;
  border-radius: 8px;
  background: var(--border);
  margin-right: 6px;
}

/* ---------- страница инструкции ---------- */

.help-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.help-section h2 {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 600;
}

.help-section p {
  margin: 0;
  color: var(--text-muted);
}

.help-section ol,
.help-section ul {
  margin: 0;
  padding-left: 22px;
  color: var(--text-muted);
}

.help-section li + li { margin-top: 6px; }

/* цветная точка перед описанием состояния индикатора */
.states { list-style: none; padding-left: 0 !important; }

.states li {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.states li::before {
  content: "";
  flex-shrink: 0;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--dot);
  transform: translateY(1px);
}

.states .green { --dot: var(--dot-green); }
.states .amber { --dot: var(--dot-amber); }
.states .violet { --dot: var(--dot-violet); }
.states .grey { --dot: var(--dot-grey); }
