:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --header-bg: #0f172a;
  --header-surface: #1e293b;
  --header-text: #f8fafc;
  --header-muted: #94a3b8;
  --text: #0f172a;
  --text-muted: #475569;
  --border: #dbe3ee;
  --blue: #1d4ed8;
  --blue-hover: #1e40af;
  --blue-soft: #eff6ff;
  --green: #047857;
  --green-hover: #065f46;
  --green-soft: #ecfdf5;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --amber: #b45309;
  --amber-soft: #fffbeb;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 6px 18px rgba(15, 23, 42, 0.08);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  background: var(--bg);
}

/* Top bar */
.top-bar {
  flex: 0 0 auto;
  background: var(--header-bg);
  color: var(--header-text);
  padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.18);
  z-index: 10;
}

.top-bar__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

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

.brand__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, #2563eb, #10b981);
  color: #ffffff;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.brand__title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.status-pill {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
}

.status-pill--auto {
  background: rgba(16, 185, 129, 0.22);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.4);
}

.top-bar__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.latency-badge {
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 4px 8px;
  border-radius: 8px;
  background: var(--header-surface);
  color: #cbd5e1;
  min-width: 44px;
  text-align: center;
}

.latency-badge.is-fast {
  color: #6ee7b7;
}

.latency-badge.is-slow {
  color: #fcd34d;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: var(--header-surface);
  color: var(--header-text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
}

.icon-btn:active {
  transform: scale(0.96);
}

.icon-btn--light {
  background: var(--surface-subtle);
  color: var(--text);
  border-color: var(--border);
  font-size: 22px;
}

/* Scenario chips strip */
.scenario-strip {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 1px;
}

.scenario-strip::-webkit-scrollbar {
  display: none;
}

.scenario-chip {
  flex: 0 0 auto;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(30, 41, 59, 0.85);
  color: #cbd5e1;
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  transition: background-color 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.scenario-chip.is-active {
  background: #2563eb;
  border-color: #60a5fa;
  color: #ffffff;
}

/* Context single-line field */
.context-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.context-input {
  width: 100%;
  height: 38px;
  padding: 0 34px 0 11px;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(30, 41, 59, 0.9);
  color: #f8fafc;
  font-size: 13.5px;
}

.context-input::placeholder {
  color: #94a3b8;
}

.context-input:focus {
  outline: 2px solid #60a5fa;
  outline-offset: -1px;
}

.context-clear-btn {
  position: absolute;
  right: 4px;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #94a3b8;
  font-size: 18px;
  line-height: 1;
}

/* Main area */
.main-area {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Notices */
.notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  line-height: 1.35;
}

.notice--warn {
  background: var(--amber-soft);
  color: #78350f;
  border: 1px solid #fde68a;
}

.notice--error {
  background: var(--red-soft);
  color: #991b1b;
  border: 1px solid #fecaca;
}

.notice__text {
  flex: 1 1 auto;
}

.notice__btn {
  flex: 0 0 auto;
  border: 1px solid #d97706;
  background: #ffffff;
  color: #92400e;
  font-weight: 700;
  font-size: 12.5px;
  padding: 6px 10px;
  border-radius: 8px;
}

.notice__close {
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 20px;
  line-height: 1;
  padding: 0 4px;
}

/* Live speech panel */
.live-panel {
  background: var(--surface);
  border: 2px solid #3b82f6;
  border-radius: var(--radius-md);
  padding: 10px 12px;
  box-shadow: var(--shadow-sm);
}

.live-panel.is-ru {
  border-color: #10b981;
}

.live-panel.is-loading {
  border-color: #6366f1;
}

.live-panel__head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.live-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ef4444;
  flex-shrink: 0;
  animation: pulse 1.1s infinite ease-in-out;
}

.live-panel.is-loading .live-dot {
  background: #4f46e5;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.35); opacity: 0.45; }
}

.live-panel__status {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  flex: 1 1 auto;
}

.live-panel__btns {
  display: flex;
  gap: 6px;
}

.live-panel__text {
  margin: 8px 0 0;
  font-size: 16px;
  line-height: 1.4;
  color: var(--text);
  min-height: 22px;
  word-break: break-word;
}

.live-panel__interim {
  color: var(--text-muted);
  font-style: italic;
}

.mini-btn {
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--text);
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
}

.mini-btn--primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #ffffff;
}

.mini-btn--danger {
  background: var(--red-soft);
  border-color: #fecaca;
  color: var(--red);
}

/* Stage cards */
.stage {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  box-shadow: var(--shadow-sm);
}

.card--empty {
  text-align: left;
  background: var(--surface);
}

.empty-title {
  margin: 0 0 6px;
  font-size: 17px;
  font-weight: 700;
}

.empty-desc {
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text-muted);
}

.card__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue);
}

.badge--green {
  background: var(--green-soft);
  color: var(--green);
}

.badge--offline {
  background: #ede9fe;
  color: #5b21b6;
}

.meta-time {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.incoming-ru {
  margin: 0 0 10px;
  font-size: 21px;
  font-weight: 800;
  line-height: 1.3;
  color: var(--text);
}

.incoming-de-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.incoming-de {
  margin: 0;
  font-size: 14px;
  line-height: 1.4;
  color: var(--text-muted);
  flex: 1 1 auto;
}

/* Suggestions list */
.suggestions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.suggestion-card {
  display: flex;
  align-items: stretch;
  gap: 8px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: 11px 12px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.14s ease, background-color 0.14s ease, transform 0.08s ease;
}

.suggestion-card.is-selected {
  border-color: #10b981;
  background: var(--green-soft);
}

.suggestion-card__main {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 0;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.suggestion-card__top {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.tone-tag {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 7px;
  border-radius: 6px;
  background: #e2e8f0;
  color: #334155;
}

.said-tag {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--green);
}

.suggestion-card__de {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.3;
  color: var(--text);
  word-break: break-word;
}

.suggestion-card__ru {
  font-size: 13.5px;
  line-height: 1.35;
  color: var(--text-muted);
}

.tts-btn {
  flex: 0 0 auto;
  align-self: center;
  min-width: 44px;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--text);
  font-size: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tts-btn:active {
  transform: scale(0.95);
}

.tts-btn.is-speaking {
  background: #dbeafe;
  border-color: #3b82f6;
}

.tts-btn--wide {
  padding: 0 14px;
  gap: 6px;
  font-size: 15px;
  font-weight: 700;
}

/* RU -> DE and Quick phrase hero display */
.hero-de {
  margin: 4px 0 8px;
  font-size: 23px;
  font-weight: 800;
  line-height: 1.3;
  color: var(--text);
  word-break: break-word;
}

.hero-sub {
  margin: 0 0 12px;
  font-size: 14.5px;
  line-height: 1.4;
  color: var(--text-muted);
}

.hero-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.alt-box {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.alt-box__label {
  display: block;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 3px;
}

.alt-box__text {
  font-size: 16.5px;
  font-weight: 700;
  color: var(--text);
}

.note-line {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

/* Manual text fallback form */
.manual-form {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 5px;
  box-shadow: var(--shadow-sm);
}

.lang-toggle {
  display: inline-flex;
  background: var(--bg);
  border-radius: 9px;
  padding: 2px;
  flex-shrink: 0;
}

.lang-toggle__btn {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 800;
  padding: 6px 9px;
  border-radius: 7px;
}

.lang-toggle__btn.is-active {
  background: var(--header-bg);
  color: #ffffff;
}

.manual-form__input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 6px 4px;
  font-size: 14.5px;
  color: var(--text);
}

.manual-form__input:focus {
  outline: none;
}

.manual-form__submit {
  width: 38px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: var(--header-bg);
  color: #ffffff;
  font-size: 18px;
  font-weight: 700;
  flex-shrink: 0;
}

/* History panel */
.history-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.history-box__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 10px 2px 4px;
}

.history-box__toggle {
  flex: 1 1 auto;
  border: 0;
  background: transparent;
  padding: 10px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-muted);
}

.history-box__chevron {
  transition: transform 0.15s ease;
}

.history-box__toggle[aria-expanded="true"] .history-box__chevron {
  transform: rotate(180deg);
}

.link-btn {
  border: 0;
  background: transparent;
  color: var(--red);
  font-size: 12.5px;
  font-weight: 700;
  padding: 6px 6px;
}

.history-list {
  border-top: 1px solid var(--border);
  padding: 8px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 240px;
  overflow-y: auto;
}

.history-item {
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 13.5px;
  line-height: 1.35;
}

.history-item--them {
  background: var(--blue-soft);
  border: 1px solid #dbeafe;
}

.history-item--me {
  background: var(--green-soft);
  border: 1px solid #d1fae5;
}

.history-item__role {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.history-item__de {
  font-weight: 700;
  color: var(--text);
}

.history-item__ru {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

.history-empty {
  margin: 4px 0;
  font-size: 13px;
  color: var(--text-muted);
}

/* Bottom thumb dock */
.bottom-dock {
  flex: 0 0 auto;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.08);
  z-index: 10;
}

.quick-strip {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.quick-strip::-webkit-scrollbar {
  display: none;
}

.quick-chip {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.quick-chip:active {
  background: #e2e8f0;
  transform: scale(0.97);
}

.quick-chip.is-active {
  background: #ede9fe;
  border-color: #8b5cf6;
  color: #5b21b6;
}

.mic-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mic-btn {
  min-height: 60px;
  border: 0;
  border-radius: 16px;
  padding: 10px 12px;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: left;
  box-shadow: 0 3px 10px rgba(15, 23, 42, 0.16);
  transition: transform 0.08s ease, background-color 0.15s ease;
}

.mic-btn:active {
  transform: scale(0.98);
}

.mic-btn--de {
  background: linear-gradient(135deg, #1d4ed8, #2563eb);
}

.mic-btn--ru {
  background: linear-gradient(135deg, #047857, #10b981);
}

.mic-btn.is-recording {
  background: linear-gradient(135deg, #b91c1c, #ef4444);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.28);
}

.mic-btn__icon {
  font-size: 21px;
  line-height: 1;
}

.mic-btn__copy {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.mic-btn__title {
  font-size: 14.5px;
  font-weight: 800;
}

.mic-btn__sub {
  font-size: 11.5px;
  opacity: 0.9;
}

/* Modal bottom sheet */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.56);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 0;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-sheet {
  width: 100%;
  max-width: 520px;
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -10px 30px rgba(15, 23, 42, 0.25);
}

.modal-sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-sheet__title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field__label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.field__label {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text);
}

.field__value {
  font-size: 13px;
  font-weight: 700;
  color: var(--blue);
  font-variant-numeric: tabular-nums;
}

.field__input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  font-size: 14.5px;
}

.field__input--mt {
  margin-top: 6px;
}

.field__hint {
  margin: 0;
  font-size: 12px;
  line-height: 1.35;
  color: var(--text-muted);
}

.input-with-btn {
  display: flex;
  gap: 6px;
}

.input-with-btn .field__input {
  flex: 1 1 auto;
}

.field--inline-actions {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.test-result {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.test-result.is-ok {
  color: var(--green);
}

.test-result.is-err {
  color: var(--red);
}

.range-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.range-row input[type="range"] {
  flex: 1 1 auto;
  accent-color: var(--blue);
}

.field--switch {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.switch-input {
  width: 22px;
  height: 22px;
  accent-color: var(--blue);
  flex-shrink: 0;
}

.settings-footer {
  display: flex;
  gap: 8px;
  justify-content: space-between;
  margin-top: 4px;
}

.btn {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-size: 14.5px;
  font-weight: 700;
}

.btn--primary {
  background: var(--blue);
  color: #ffffff;
  flex: 1 1 auto;
}

.btn--secondary {
  background: var(--surface-subtle);
  border-color: var(--border);
  color: var(--text);
}

.btn--danger-outline {
  background: #ffffff;
  border-color: #fecaca;
  color: var(--red);
}

.btn--added {
  background: var(--green-soft);
  border-color: #6ee7b7;
  color: var(--green);
}
