:root {
  --bg: #111316;
  --bg-2: #171a1e;
  --panel: #1c2025;
  --line: #2a2f36;
  --line-2: #363c45;
  --text: #e4e6e9;
  --muted: #8d939c;
  --accent: #e8a33d;
  --accent-ink: #1a1206;
  --ok: #5fb878;
  --warn: #d9734e;
  --mono: 'IBM Plex Mono', ui-monospace, Consolas, monospace;
  --sans: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --r: 6px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, textarea, select { font: inherit; color: inherit; }

/* ---------- top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 20px;
  padding: 10px 24px;
  background: rgba(17,19,22,.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--accent); font-weight: 600; letter-spacing: .02em; }
.brand:hover { text-decoration: none; }
.brand span { color: var(--text); }
.brand em { font-style: normal; color: var(--muted); font-weight: 400; margin-left: 6px; font-family: var(--mono); font-size: 13px; }
.tabs { display: flex; gap: 4px; align-self: stretch; margin: -10px 0; }
.tabs a {
  display: flex; align-items: center; padding: 0 14px; font-size: 14px; color: var(--muted);
  border-bottom: 2px solid transparent;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.on { color: var(--text); border-bottom-color: var(--accent); }
.search { flex: 1; max-width: 400px; margin-left: auto; }
.search input {
  width: 100%; padding: 7px 12px; border-radius: var(--r);
  background: var(--panel); border: 1px solid var(--line); outline: none;
}
.search input:focus { border-color: var(--accent); }
.topnav { display: flex; gap: 16px; align-items: center; font-size: 14px; }
.topnav a { color: var(--muted); }
.topnav a:hover { color: var(--text); text-decoration: none; }

.app { max-width: 1180px; margin: 0 auto; padding: 32px 24px 80px; }
.loading, .empty { color: var(--muted); padding: 40px 0; }

/* ---------- common ---------- */
.eyebrow { font-family: var(--mono); font-size: 12px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }
h1 { font-size: 34px; line-height: 1.15; margin: 6px 0 12px; font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: 22px; margin: 36px 0 12px; font-weight: 600; }
h3 { font-size: 17px; margin: 24px 0 8px; }
.lead { color: var(--muted); font-size: 17px; max-width: 720px; margin: 0; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 8px; font-family: var(--mono); }
.crumbs a { color: var(--muted); }
.badge {
  display: inline-block; font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  padding: 2px 7px; border-radius: 3px; border: 1px solid var(--line-2); color: var(--muted);
}
.badge.ready { color: var(--ok); border-color: rgba(95,184,120,.4); }
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--r); cursor: pointer;
  background: var(--panel); border: 1px solid var(--line-2);
  font-size: 14px; color: var(--text);
}
.btn:hover { border-color: var(--muted); text-decoration: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--warn); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- home: pipeline ---------- */
.hero { margin-bottom: 40px; }
.pipeline { list-style: none; padding: 0; margin: 0; display: grid; gap: 0; counter-reset: st; }
.pipeline li { position: relative; display: grid; grid-template-columns: 56px 1fr; }
.pipeline li::before {
  counter-increment: st; content: counter(st, decimal-leading-zero);
  font-family: var(--mono); font-size: 13px; color: var(--muted);
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line-2);
  display: grid; place-items: center; background: var(--bg); z-index: 1; margin-top: 18px;
}
.pipeline li::after {
  content: ''; position: absolute; left: 20px; top: 0; bottom: 0; width: 1px; background: var(--line);
}
.pipeline li:first-child::after { top: 38px; }
.pipeline li:last-child::after { bottom: calc(100% - 38px); }
.pipeline li.ready::before { border-color: var(--accent); color: var(--accent); }
.stage-card {
  display: block; margin: 8px 0; padding: 16px 20px; border-radius: var(--r);
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  transition: border-color .15s, transform .15s;
}
.stage-card:hover { border-color: var(--line-2); text-decoration: none; transform: translateX(2px); }
.pipeline li.ready .stage-card { border-color: rgba(232,163,61,.35); }
.pipeline li.ready .stage-card:hover { border-color: var(--accent); }
.stage-card h3 { margin: 0 0 4px; font-size: 18px; display: flex; gap: 10px; align-items: center; }
.stage-card p { margin: 0; color: var(--muted); font-size: 14px; }
.stage-card .meta { margin-top: 8px; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.pipeline li.draft .stage-card { opacity: .72; }

/* ---------- stage ---------- */
.stage-grid { display: grid; grid-template-columns: 1fr 380px; gap: 32px; margin-top: 28px; align-items: start; }
.art-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.art-list a {
  display: grid; grid-template-columns: 32px 1fr; gap: 4px 12px;
  padding: 14px 16px; border-radius: var(--r); background: var(--panel); border: 1px solid var(--line); color: var(--text);
}
.art-list a:hover { border-color: var(--accent); text-decoration: none; }
.art-list .n { font-family: var(--mono); color: var(--accent); font-size: 13px; padding-top: 2px; }
.art-list .t { font-weight: 600; }
.art-list .s { grid-column: 2; color: var(--muted); font-size: 14px; }

.checklist { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 18px; position: sticky; top: 76px; }
.checklist h2 { margin: 0 0 4px; font-size: 17px; }
.checklist .progress { height: 3px; background: var(--line); border-radius: 2px; margin: 10px 0 12px; overflow: hidden; }
.checklist .progress div { height: 100%; width: 100%; background: var(--accent); transform-origin: left; transform: scaleX(0); transition: transform .2s; }
.checklist ul { list-style: none; margin: 0; padding: 0; }
.checklist li label { display: grid; grid-template-columns: 18px 1fr; gap: 10px; padding: 6px 0; cursor: pointer; font-size: 14px; border-top: 1px solid var(--line); }
.checklist li:first-child label { border-top: 0; }
.checklist input[type=checkbox] { accent-color: var(--accent); margin-top: 4px; }
.checklist .should { color: var(--muted); }
.checklist .should::after { content: ' · желательно'; font-family: var(--mono); font-size: 11px; }
.checklist li input:checked + span { text-decoration: line-through; color: var(--muted); }
.stage-nav { display: flex; justify-content: space-between; margin-top: 40px; padding-top: 20px; border-top: 1px solid var(--line); font-size: 14px; }

/* ---------- article ---------- */
.art-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr) 200px; gap: 40px; align-items: start; }
.side { position: sticky; top: 76px; font-size: 14px; }
.side h4 { margin: 0 0 8px; }
.side ul { list-style: none; margin: 0; padding: 0; }
.side li a { display: block; padding: 5px 10px; color: var(--muted); border-left: 2px solid var(--line); }
.side li a:hover { color: var(--text); text-decoration: none; }
.side li a.on { color: var(--text); border-left-color: var(--accent); }
.toc li a { border-left: 0; padding: 3px 0; font-size: 13px; }

.prose { max-width: 760px; }
.prose h2 { border-top: 1px solid var(--line); padding-top: 24px; scroll-margin-top: 80px; }
.prose h2:first-child { border-top: 0; padding-top: 0; margin-top: 8px; }
.prose p, .prose li { color: #cfd2d6; }
.prose strong { color: var(--text); }
.prose ul, .prose ol { padding-left: 22px; }
.prose li { margin: 4px 0; }
.prose code { font-family: var(--mono); font-size: 13px; background: var(--panel); padding: 1px 5px; border-radius: 3px; border: 1px solid var(--line); }
.prose pre { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; overflow-x: auto; }
.prose pre code { border: 0; padding: 0; }
.prose blockquote { margin: 20px 0; padding: 12px 16px; border: 1px solid rgba(232,163,61,.3); background: rgba(232,163,61,.06); border-radius: var(--r); }
.prose blockquote p { margin: 0; color: var(--text); }
.prose table { width: 100%; border-collapse: collapse; margin: 16px 0; font-size: 14px; display: block; overflow-x: auto; }
.prose th, .prose td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.prose th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; font-family: var(--mono); }
.prose img { display: block; max-width: 100%; margin: 16px 0 6px; border-radius: var(--r); border: 1px solid var(--line); cursor: zoom-in; }
.prose img + em, .prose p > img:only-child + em { display: block; font-size: 13px; color: var(--muted); margin-bottom: 16px; }
.art-foot { margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 16px; font-size: 14px; }
.updated { font-family: var(--mono); font-size: 12px; color: var(--muted); }

/* ---------- glossary / search ---------- */
.gloss { display: grid; gap: 0; margin-top: 24px; }
.gloss-item { display: grid; grid-template-columns: 240px 1fr auto; gap: 20px; padding: 14px 0; border-top: 1px solid var(--line); }
.gloss-item dt { font-weight: 600; }
.gloss-item dd { margin: 0; color: #cfd2d6; }
.gloss-filter { margin-top: 20px; max-width: 360px; }
.results { list-style: none; padding: 0; margin: 20px 0; display: grid; gap: 10px; }
.results a { display: block; padding: 14px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); color: var(--text); }
.results a:hover { border-color: var(--accent); text-decoration: none; }
.results .snip { color: var(--muted); font-size: 14px; margin-top: 4px; }
.results mark { background: rgba(232,163,61,.25); color: var(--text); padding: 0 2px; border-radius: 2px; }

/* ---------- forms ---------- */
.form { display: grid; gap: 16px; max-width: 1100px; margin-top: 20px; }
.form label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.input, .form input[type=text], .form input[type=password], .form input[type=number], .form textarea, .form select, .gloss-filter {
  width: 100%; padding: 9px 12px; border-radius: var(--r); background: var(--panel); border: 1px solid var(--line-2); outline: none; color: var(--text);
}
.input:focus, .form input:focus, .form textarea:focus, .form select:focus { border-color: var(--accent); }
.form textarea { font-family: var(--mono); font-size: 13px; line-height: 1.55; resize: vertical; }
.cols-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.cols-3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 16px; }
.editor { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.editor textarea { min-height: 560px; }
.editor .prose { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r); padding: 4px 20px; max-height: 620px; overflow: auto; }
.check-edit { display: grid; gap: 6px; }
.check-edit .ce-row { display: grid; grid-template-columns: 1fr 140px auto; gap: 8px; }
.error { color: var(--warn); font-size: 14px; }
.admin-bar { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }

@media (max-width: 1000px) {
  .art-layout { grid-template-columns: 1fr; }
  .side { position: static; }
  .toc { display: none; }
  .stage-grid { grid-template-columns: 1fr; }
  .checklist { position: static; }
  .editor { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .top { flex-wrap: wrap; padding: 10px 16px; gap: 10px; }
  .search { order: 3; max-width: none; flex-basis: 100%; }
  .tabs { order: 4; flex-basis: 100%; margin: 0; overflow-x: auto; }
  .tabs a { padding: 6px 12px; }
  .brand em { display: none; }
  .app { padding: 20px 16px 60px; }
  h1 { font-size: 26px; }
  .gloss-item { grid-template-columns: 1fr; gap: 4px; }
  .cols-2, .cols-3 { grid-template-columns: 1fr; }
  .check-edit .ce-row { grid-template-columns: 1fr; }
}

/* ---------- auth ---------- */
body.signed-out .search,
body.signed-out .topnav,
body.signed-out .tabs { display: none; }
.who { color: var(--muted); font-family: var(--mono); font-size: 13px; }
.login { max-width: 360px; margin: 10vh auto 0; }
.login .form { margin-top: 24px; }
.login .btn.primary { justify-content: center; padding: 10px 14px; }
.btn:disabled { opacity: .6; cursor: progress; }
#authSlot { display: inline-flex; gap: 12px; align-items: center; }
