:root {
  --ground: #f4f6f2;
  --surface: #ffffff;
  --surface-sunk: #eef1ec;
  --ink: #10201a;
  --muted: #5c6b63;
  --line: #dbe2d9;
  --line-strong: #c3cec1;
  --accent: #0f6e52;
  --accent-ink: #ffffff;
  --accent-soft: #e2efe8;
  --gold: #a86c12;
  --danger: #9b2f1f;
  --shadow: 0 1px 2px rgba(16, 32, 26, 0.05), 0 8px 24px -16px rgba(16, 32, 26, 0.28);

  --step-0: 0.9375rem;
  --step-1: 1.0625rem;
  --step-2: 1.375rem;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #0c1310;
    --surface: #121b17;
    --surface-sunk: #0f1814;
    --ink: #e8efe9;
    --muted: #8ca096;
    --line: #22302a;
    --line-strong: #2f4139;
    --accent: #3fbf93;
    --accent-ink: #06170f;
    --accent-soft: #16281f;
    --gold: #e0a64a;
    --danger: #e8836d;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 10px 30px -20px rgba(0, 0, 0, 0.9);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

@supports (height: 100dvh) {
  body {
    min-height: 100dvh;
  }
}

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: "IBM Plex Sans", ui-sans-serif, system-ui, sans-serif;
  font-size: var(--step-0);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

/* ── masthead ─────────────────────────────────────────── */

.masthead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 12px;
}

.wordmark__name {
  font-family: "Fraunces", ui-serif, Georgia, serif;
  font-size: var(--step-2);
  font-weight: 700;
  letter-spacing: -0.015em;
}

.wordmark__rule {
  width: 28px;
  height: 1px;
  background: var(--line-strong);
}

.wordmark__model,
.status {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0;
}

.status--warn {
  color: var(--danger);
  text-transform: none;
  letter-spacing: 0;
}

/* ── layout ───────────────────────────────────────────── */

.deck {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 20px 24px 28px;
}

.langbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.field__label {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.6875rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

.select {
  appearance: none;
  width: 100%;
  padding: 9px 34px 9px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: var(--step-1);
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.swap {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, transform 0.25s;
}

.swap:hover:not(:disabled) {
  color: var(--accent);
  border-color: var(--accent);
}

.swap:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.swap svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.swap--turn {
  transform: rotate(180deg);
}

/* ── panes ────────────────────────────────────────────── */

.panes {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 340px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.pane--target {
  border-left: 1px solid var(--line);
  background: var(--surface-sunk);
}

.editor,
.output {
  flex: 1;
  padding: 18px 20px;
  font-size: var(--step-1);
  line-height: 1.65;
  overflow-y: auto;
  min-height: 220px;
}

.editor {
  width: 100%;
  border: 0;
  resize: none;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
}

.editor:focus,
.select:focus-visible,
.swap:focus-visible,
.primary:focus-visible,
.ghost:focus-visible,
.tone:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.editor::placeholder,
.placeholder {
  color: var(--muted);
}

.output {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.placeholder {
  margin: 0;
}

.output.is-streaming::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 1.05em;
  margin-left: 1px;
  background: var(--accent);
  vertical-align: text-bottom;
  animation: blink 1s steps(2) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.pane__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px 8px 20px;
  border-top: 1px solid var(--line);
  min-height: 40px;
}

.counter,
.detected {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.counter--over {
  color: var(--danger);
}

.detected b {
  color: var(--ink);
  font-weight: 500;
}

.ghost {
  border: 0;
  background: none;
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--muted);
  font: inherit;
  font-size: 0.8125rem;
  cursor: pointer;
}

.ghost:hover:not(:disabled) {
  color: var(--accent);
  background: var(--accent-soft);
}

.ghost:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── notes ────────────────────────────────────────────── */

.notes {
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--gold);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 14px 18px;
}

.notes__title {
  margin: 0 0 8px;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--gold);
}

.notes__list {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  color: var(--ink);
}

/* ── controls ─────────────────────────────────────────── */

.controls {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

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

.tones__row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tone {
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 6px 14px;
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: 0.8125rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.tone:hover {
  color: var(--ink);
  border-color: var(--line-strong);
}

.tone[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 500;
}

.primary {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 11px 22px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-size: var(--step-1);
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.primary:hover:not(:disabled) {
  opacity: 0.9;
}

.primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.primary__key {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.75rem;
  opacity: 0.7;
}

.alert {
  margin: 0;
  padding: 11px 14px;
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  color: var(--danger);
  background: var(--surface);
}

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

@media (max-width: 760px) {
  .deck {
    padding: 16px max(14px, env(safe-area-inset-left)) max(22px, env(safe-area-inset-bottom));
  }

  .masthead {
    padding-left: max(24px, env(safe-area-inset-left));
    padding-right: max(24px, env(safe-area-inset-right));
  }

  /* На телефоне и планшете физической клавиатуры обычно нет. */
  .primary__key {
    display: none;
  }

  .panes {
    grid-template-columns: 1fr;
  }

  .pane--target {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .langbar {
    grid-template-columns: 1fr auto 1fr;
    gap: 8px;
  }

  .controls {
    flex-direction: column;
    align-items: stretch;
  }

  .primary {
    justify-content: center;
  }
}

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

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.gate__card {
  width: min(360px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 28px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.gate__name {
  margin: 0;
  font-family: "Fraunces", ui-serif, Georgia, serif;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.015em;
}

.gate__hint {
  margin: -8px 0 0;
  color: var(--muted);
}

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

.gate__input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: var(--step-1);
}

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

.gate .primary {
  justify-content: center;
}
