:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c2130;
  --muted: #6b7280;
  --border: #d9dde5;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --chunk-a: rgba(47, 111, 237, 0.13);
  --chunk-b: rgba(16, 163, 127, 0.14);
  --chunk-active: rgba(245, 158, 11, 0.35);
  --danger: #c2410c;
  --danger-bg: rgba(220, 38, 38, 0.12);
  --ok: #16a34a;
  --warn: #f59e0b;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1218;
    --surface: #171b24;
    --text: #e6e8ee;
    --muted: #9aa3b2;
    --border: #2a3140;
    --accent: #5b8def;
    --accent-text: #0b1020;
    --chunk-a: rgba(91, 141, 239, 0.22);
    --chunk-b: rgba(45, 212, 191, 0.2);
    --chunk-active: rgba(245, 158, 11, 0.4);
    --danger: #fb923c;
    --danger-bg: rgba(248, 113, 113, 0.18);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  }
}
:root[data-theme="dark"] {
  --bg: #0f1218;
  --surface: #171b24;
  --text: #e6e8ee;
  --muted: #9aa3b2;
  --border: #2a3140;
  --accent: #5b8def;
  --accent-text: #0b1020;
  --chunk-a: rgba(91, 141, 239, 0.22);
  --chunk-b: rgba(45, 212, 191, 0.2);
  --chunk-active: rgba(245, 158, 11, 0.4);
  --danger: #fb923c;
  --danger-bg: rgba(248, 113, 113, 0.18);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 16px 32px;
}

.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.brand h1 { margin: 0; font-size: 1.6rem; letter-spacing: -0.01em; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 0.92rem; }
.status { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.9rem; padding: 6px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); white-space: nowrap; }
.status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.status.ok .dot { background: var(--ok); }
.status.busy .dot { background: var(--warn); }
.status.loading .dot { background: var(--warn); animation: pulse 1.2s infinite; }
.status.down .dot { background: var(--danger); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

.banner { background: var(--danger-bg); border: 1px solid var(--danger); color: var(--text); padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px; }
.banner.info { background: var(--chunk-active); border-color: var(--warn); }
.hidden { display: none !important; }

.panes { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 860px) { .panes { grid-template-columns: 1fr; } }
.pane { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; display: flex; flex-direction: column; min-width: 0; }
.pane-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.pane-head label { font-weight: 600; font-size: 0.95rem; }
.pane-foot { margin-top: 6px; min-height: 1.4em; }
.counter { color: var(--muted); font-size: 0.88rem; font-variant-numeric: tabular-nums; }
.counter.over { color: var(--danger); font-weight: 600; }
.hint { color: var(--muted); font-size: 0.85rem; }
.hint.err { color: var(--danger); }

/* Поле ввода с подсветкой: прозрачный textarea поверх слоя с тем же шрифтом и отступами. */
.editor { position: relative; }
.backdrop, #src {
  font-family: inherit;
  font-size: 1.04rem;
  line-height: 1.55;
  letter-spacing: normal;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 100%;
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-wrap: break-word;
  word-break: normal;
  tab-size: 4;
}
.backdrop {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--bg);
  color: transparent;
  pointer-events: none;
  border-color: transparent;
}
.highlights { min-height: 100%; }
.highlights mark { background: var(--chunk-a); color: transparent; border-radius: 3px; }
.highlights mark.b { background: var(--chunk-b); }
.highlights mark.active { background: var(--chunk-active); }
.highlights mark.done { opacity: 0.55; }
#src {
  position: relative;
  display: block;
  height: 320px;
  min-height: 160px;
  resize: vertical;
  background: transparent;
  color: var(--text);
  outline: none;
  overflow: auto;
}
#src:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
#src::placeholder { color: var(--muted); opacity: 0.8; }

.output {
  font-size: 1.04rem;
  line-height: 1.55;
  padding: 12px 14px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  min-height: 320px;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  overflow: auto;
  max-height: 70vh;
  background: var(--bg);
}
.output:empty::before { content: "Здесь появится перевод…"; color: var(--muted); opacity: 0.8; }
.output .chunk-out.active { background: var(--chunk-active); border-radius: 3px; }
.output .cursor { display: inline-block; width: 2px; height: 1.1em; background: var(--accent); vertical-align: text-bottom; margin-left: 1px; animation: pulse 1s infinite; }
.output .trunc { color: var(--danger); font-size: 0.85em; }

.controls { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-top: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); }
.temp { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; min-width: 0; }
.temp label { font-weight: 600; white-space: nowrap; }
.temp output { font-variant-numeric: tabular-nums; }
.temp input[type="range"] { width: 220px; max-width: 60vw; accent-color: var(--accent); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn { font: inherit; font-size: 0.95rem; padding: 9px 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; transition: filter 0.15s, opacity 0.15s; }
.btn:hover:not(:disabled) { filter: brightness(0.96); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 600; }
.btn.small { padding: 5px 10px; font-size: 0.85rem; }
.btn kbd { font: inherit; font-size: 0.78em; opacity: 0.75; margin-left: 6px; }

.foot { margin-top: 18px; color: var(--muted); font-size: 0.84rem; display: flex; flex-wrap: wrap; gap: 6px; }
.foot .sep { opacity: 0.6; }
.foot a { color: inherit; }

@media (max-width: 600px) {
  body { padding: 12px 16px 24px; }
  .brand h1 { font-size: 1.3rem; }
  #src, .output { height: 220px; min-height: 180px; }
  .btn kbd { display: none; }
}
