:root {
  --bg: #f6f3ee;
  --paper: #fffdf9;
  --ink: #1f2430;
  --muted: #6b6f78;
  --line: #e2ddd3;
  --accent: #233a5e;
  --accent-ink: #ffffff;
  --accent-soft: #e6ebf3;
  --ok: #2f7a4f;
  --warn: #9a6a12;
  --warn-soft: #fbf1dc;
  --err: #a33a2e;
  --err-soft: #f8e5e1;
  --run: #2a62b8;
  --run-soft: #e4edf9;
  --radius: 10px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "PT Serif", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d; --paper: #1d2027; --ink: #e7e4dd; --muted: #9a9ca3; --line: #30343d;
    --accent: #8fb0e6; --accent-ink: #10131a; --accent-soft: #263248;
    --ok: #6cc08f; --warn: #e2b35a; --warn-soft: #3a2f1a; --err: #ef8a7c; --err-soft: #3d2320;
    --run: #8fb4f0; --run-soft: #1f2c42;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--sans); }
a { color: var(--accent); }
h1 { font-family: var(--serif); font-weight: 600; font-size: 1.7rem; line-height: 1.25; margin: 0 0 .3rem; }
.muted { color: var(--muted); font-size: .92rem; }

/* --- верхня панель --- */
.topbar { display: flex; align-items: center; gap: .6rem; padding: .7rem 1.25rem; border-bottom: 1px solid var(--line); background: var(--paper); position: sticky; top: 0; z-index: 5; }
.brand { font-family: var(--serif); font-weight: 700; color: var(--ink); text-decoration: none; font-size: 1.05rem; white-space: nowrap; }
.crumb { color: var(--muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logout { margin-left: auto; }

main.narrow { max-width: 760px; margin: 2rem auto; padding: 0 16px; }
main.wide { max-width: 1240px; margin: 1.5rem auto; padding: 0 16px; }

/* --- кнопки й поля --- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .55rem 1rem; border-radius: 8px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); font: inherit; font-size: .95rem; text-decoration: none; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.big { padding: .8rem 1.4rem; font-size: 1.05rem; }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
button.link { background: none; border: 0; color: var(--muted); font: inherit; cursor: pointer; padding: .3rem; }
button.link:hover { color: var(--ink); }
form.inline { display: inline; }

label { display: block; font-weight: 600; font-size: .9rem; margin: 1rem 0 .35rem; }
input, select, textarea { width: 100%; font: inherit; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: .6rem .7rem; }
textarea { line-height: 1.55; resize: vertical; }
::placeholder { color: var(--muted); opacity: .6; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.form-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.4rem; }
details > summary { cursor: pointer; color: var(--accent); margin: 1.2rem 0 .2rem; font-weight: 600; }
.error-text { color: var(--err); margin: .5rem 0 0; }

/* --- вхід --- */
.login-card { max-width: 380px; margin: 12vh auto 0; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 2rem 1.6rem; }
.login-card .btn { margin-top: 1.2rem; }

/* --- список розділів --- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.2rem; }
.chapters { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.chapters a { display: flex; flex-direction: column; gap: .45rem; padding: 1rem 1.15rem; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); text-decoration: none; }
.chapters a:hover { border-color: var(--accent); }
.ch-title { font-family: var(--serif); font-size: 1.12rem; font-weight: 600; }
.ch-meta { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; }
.dots { display: inline-flex; gap: 4px; }

.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--line); flex: none; }
.dot.done { background: var(--ok); border-color: var(--ok); }
.dot.stale { background: var(--warn-soft); border-color: var(--warn); }
.dot.running { border-color: var(--run); border-top-color: transparent; animation: spin 1s linear infinite; }

.badge { font-size: .8rem; padding: .1rem .55rem; border-radius: 99px; }
.badge.running { background: var(--run-soft); color: var(--run); }
.badge.stale { background: var(--warn-soft); color: var(--warn); }
.badge.error { background: var(--err-soft); color: var(--err); }
.badge.done { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }

.empty { text-align: center; padding: 2.5rem 1rem; border: 1px dashed var(--line); border-radius: var(--radius); background: var(--paper); }

/* --- сторінка розділу --- */
.chapter { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 1.6rem; align-items: start; }
.side { position: sticky; top: 4.2rem; min-width: 0; }
.steps { display: flex; flex-direction: column; gap: 2px; }
.step { display: flex; align-items: center; gap: .6rem; padding: .55rem .7rem; border-radius: 8px; color: var(--ink); text-decoration: none; }
.step:hover { background: var(--paper); }
.step.current { background: var(--paper); box-shadow: inset 3px 0 0 var(--accent); font-weight: 600; }
.step em { margin-left: auto; font-style: normal; font-size: .75rem; color: var(--muted); }
.downloads { margin-top: 1.2rem; padding: 1rem; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; gap: .5rem; font-size: .92rem; }

.stage { min-width: 0; }
.stage-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; }
.tools { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: flex-end; }

.doc { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 2rem 2.4rem; font-family: var(--serif); font-size: 1.08rem; line-height: 1.7; overflow-wrap: anywhere; }
.doc > :first-child { margin-top: 0; }
.doc h1, .doc h2, .doc h3 { font-family: var(--serif); line-height: 1.3; }
.doc h1 { font-size: 1.45rem; }
.doc h2 { font-size: 1.22rem; margin-top: 1.8rem; }
.doc h3 { font-size: 1.08rem; }
.doc p { margin: 0 0 .9rem; }
.doc code { font-size: .9em; background: var(--bg); padding: .05rem .3rem; border-radius: 4px; }
.doc pre { white-space: pre-wrap; background: var(--bg); padding: .8rem; border-radius: 8px; }
.doc table { border-collapse: collapse; width: 100%; font-size: .95rem; }
.doc th, .doc td { border: 1px solid var(--line); padding: .35rem .5rem; text-align: left; }
.doc blockquote { margin: 0 0 1rem; padding-left: 1rem; border-left: 3px solid var(--line); color: var(--muted); }
.doc.small { font-size: .98rem; padding: 1.2rem 1.5rem; }
.doc.old { opacity: .9; border-style: dashed; }

.editor textarea { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .92rem; background: var(--paper); }

.notes, .versions { margin-top: 1rem; }
.versions ul { margin: .3rem 0 0; padding-left: 1.2rem; }
.versions a.current { font-weight: 700; }

.notice { border-radius: var(--radius); padding: .9rem 1.1rem; margin-bottom: 1rem; border: 1px solid transparent; }
.notice p { margin: .35rem 0 .2rem; }
.notice.error { background: var(--err-soft); border-color: color-mix(in srgb, var(--err) 30%, transparent); }
.notice.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.notice.info { background: var(--accent-soft); display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; }
.notice.running { background: var(--run-soft); border-color: color-mix(in srgb, var(--run) 30%, transparent); }
.job-head { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.job-log { margin: .5rem 0 0; max-height: 9rem; overflow: auto; font-size: .8rem; color: var(--muted); white-space: pre-wrap; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--run); border-top-color: transparent; border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.next { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin: 1.6rem 0 2rem; }
.done-box { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.2rem; }

/* --- телефон / планшет --- */
@media (max-width: 820px) {
  .chapter { grid-template-columns: minmax(0, 1fr); gap: 1rem; }
  .side { position: static; }
  .steps { flex-direction: row; overflow-x: auto; gap: .3rem; padding-bottom: .3rem; }
  .step { flex: none; padding: .45rem .7rem; border: 1px solid var(--line); background: var(--paper); }
  .step.current { box-shadow: inset 0 -3px 0 var(--accent); }
  .step em { display: none; }
  .downloads { margin-top: .6rem; }
  .doc { padding: 1.2rem 1.1rem; font-size: 1.02rem; }
  .row { grid-template-columns: 1fr; }
  .stage-head { flex-direction: column; }
  .tools { justify-content: flex-start; }
}
