:root {
  color: #222623;
  background: #f4f6f2;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --danger: #9b2c2c;
  --muted: #657067;
  --surface: #fff;
  --line: #dce3dc;
  --soft: #f1f4ee;
  --draft: #fff7e6;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(24, 39, 30, .08), 0 8px 24px rgba(24, 39, 30, .04);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; }
button, input, select, textarea { font: inherit; }
button, select, input[type="range"] { cursor: pointer; }
button:disabled, select:disabled, input:disabled { cursor: not-allowed; opacity: .55; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid rgba(15,118,110,.24); outline-offset: 2px; }

.loading, .gate-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
}
.gate-card {
  width: min(580px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 30px;
}
.gate-card h1 { margin: 0 0 8px; font-size: 28px; letter-spacing: -.02em; }
.gate-card p { color: var(--muted); line-height: 1.55; }
.gate-card form { display: grid; gap: 15px; margin-top: 24px; }
.security-note { padding: 12px 14px; background: var(--soft); border-radius: 9px; font-size: 13px; }

.app-shell { min-height: 100vh; padding: 18px; display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 14px; }
.surface { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.header { display: flex; align-items: center; gap: 12px; padding: 14px 16px; overflow-x: auto; }
.brand { min-width: 245px; margin-right: auto; }
.brand h1 { font-size: 23px; margin: 0 0 3px; letter-spacing: -.02em; }
.status-text { color: var(--muted); font-size: 14px; white-space: nowrap; max-width: 440px; overflow: hidden; text-overflow: ellipsis; }
.header-control { display: grid; gap: 4px; min-width: 138px; }
.header-control label, .chip-label { font-size: 11px; color: var(--muted); }
.header-control select { height: 39px; }
.chip { width: 128px; padding: 7px 10px; border-radius: 9px; background: #f1e9e2; color: #7a4a24; flex: 0 0 auto; }
.chip.positive { background: #e5f3e8; color: #1f6b3a; }
.chip-value { display: block; margin-top: 2px; font-size: 13px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

.workspace { display: grid; min-height: 0; grid-template-columns: 370px minmax(0, 1fr); gap: 14px; }
.controls { padding: 16px; overflow-y: auto; display: grid; align-content: start; gap: 17px; }
.output-grid { min-width: 0; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.output-panel { padding: 16px; min-height: 0; display: grid; grid-template-rows: auto auto minmax(0, 1fr); }
.output-panel h2 { margin: 0; font-size: 20px; }
.subtitle { color: var(--muted); font-size: 12px; margin: 3px 0 12px; }
.sentence-list { overflow-y: auto; display: grid; align-content: start; gap: 12px; padding-right: 3px; }
.empty { color: var(--muted); }
.sentence { background: var(--soft); border-radius: 9px; padding: 12px; }
.sentence.pending { opacity: .72; }
.sentence-head { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.sentence-text { white-space: pre-wrap; font-size: 16px; line-height: 1.45; }
.draft { background: var(--draft); color: #3a2b1f; }
.draft .sentence-head { color: #7a4a24; }

.section { display: grid; gap: 8px; }
.section-title { display: flex; align-items: center; justify-content: space-between; font-weight: 650; }
.help { color: var(--muted); font-size: 12px; line-height: 1.45; }
.row { display: flex; align-items: center; gap: 9px; }
.row > .grow { flex: 1; }
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

button, select, input[type="text"], input[type="password"], input[type="number"], textarea {
  border: 1px solid #bfcac1;
  border-radius: 8px;
  background: #fff;
  color: #222623;
}
select, input[type="text"], input[type="password"], input[type="number"], textarea { width: 100%; padding: 10px 11px; }
textarea { resize: vertical; min-height: 130px; line-height: 1.45; cursor: text; }
button { min-height: 40px; padding: 9px 14px; font-weight: 600; }
.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.primary:hover { background: var(--primary-dark); }
.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.outline { background: #fff; }
.text-button { border: 0; background: transparent; color: var(--primary); min-height: auto; padding: 3px 4px; }
.danger-text { color: var(--danger); }
.start-stop { width: 100%; min-height: 47px; font-size: 15px; }
.full { width: 100%; }

.field { display: grid; gap: 6px; }
.field > label { font-size: 13px; font-weight: 650; }
.checkbox { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.checkbox input { width: 18px; height: 18px; accent-color: var(--primary); }
input[type="range"] { width: 100%; accent-color: var(--primary); }
.range-value { color: var(--muted); font-size: 12px; }
.meter { height: 7px; border-radius: 99px; overflow: hidden; background: #e3e8df; }
.meter > span { display: block; width: 0; height: 100%; background: var(--primary); transition: width 80ms linear; }
.progress { position: relative; height: 3px; overflow: hidden; background: #dce9e6; border-radius: 99px; }
.progress::after { content: ""; position: absolute; width: 32%; inset-block: 0; background: var(--primary); animation: busy 1.1s ease-in-out infinite; }
@keyframes busy { from { left: -32%; } to { left: 100%; } }

.warning { background: #ffe8e3; color: var(--danger); border-radius: 8px; padding: 9px 12px; font-size: 13px; font-weight: 650; }
.session-note { color: var(--muted); font-size: 13px; min-height: 19px; }

.modal-backdrop { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; background: rgba(20,31,25,.43); padding: 24px; }
.modal { width: min(680px, 100%); max-height: min(88vh, 900px); overflow-y: auto; padding: 23px; background: #fff; border-radius: 14px; box-shadow: 0 20px 70px rgba(0,0,0,.25); }
.modal.wide { width: min(1050px, 100%); }
.modal h2 { margin: 0 0 8px; }
.modal-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-top: 20px; }
.modal-actions .left { margin-right: auto; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.settings-card { border: 1px solid var(--line); border-radius: 10px; padding: 14px; display: grid; gap: 11px; align-content: start; }
.settings-card h3 { margin: 0; }
.marker-hints { display: grid; gap: 8px; margin: 16px 0; padding: 13px; border-radius: 9px; background: var(--soft); }
.marker-hints > div { display: grid; grid-template-columns: max-content 1fr; align-items: baseline; gap: 12px; color: var(--muted); font-size: 13px; line-height: 1.4; }
.marker-hints code { color: var(--primary-dark); font-weight: 700; }
.archive-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; height: min(55vh, 500px); }
.archive-column { background: var(--soft); border-radius: 9px; padding: 12px; overflow-y: auto; white-space: pre-wrap; line-height: 1.45; }

.smooth-modal { width: min(1100px, 96vw); height: min(82vh, 850px); display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 14px; overflow: hidden; }
.smooth-toolbar { display: flex; gap: 14px; align-items: center; }
.smooth-toolbar h2 { margin: 0 auto 0 0; }
.smooth-copy { background: var(--soft); border-radius: 10px; padding: 24px; overflow-y: auto; white-space: pre-wrap; font-size: 28px; line-height: 1.45; }
.smooth-footer { text-align: right; color: var(--muted); font-size: 12px; }

.toast { position: fixed; z-index: 30; left: 50%; bottom: 24px; transform: translate(-50%, 18px); background: #223029; color: #fff; padding: 10px 16px; border-radius: 9px; opacity: 0; pointer-events: none; transition: .2s ease; box-shadow: var(--shadow); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.spinner { width: 34px; height: 34px; border: 4px solid #dfe9e5; border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 310px minmax(0, 1fr); }
  .header { align-items: flex-end; }
  .chip { display: none; }
}
@media (max-width: 820px) {
  .app-shell { padding: 10px; }
  .workspace { grid-template-columns: 1fr; }
  .controls { overflow: visible; }
  .output-grid { grid-template-columns: 1fr; }
  .output-panel { min-height: 480px; }
  .settings-grid, .archive-grid { grid-template-columns: 1fr; }
  .archive-grid { height: auto; }
  .archive-column { max-height: 340px; }
}
