/* Cavrix Studio — lapis ink and illumination gold, after the ruled margins (jadval) of Urdu manuscripts. */

@font-face { font-family: "Public Sans"; src: url("../fonts/public-sans-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Public Sans"; src: url("../fonts/public-sans-latin-500-normal.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Public Sans"; src: url("../fonts/public-sans-latin-600-normal.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Newsreader"; src: url("../fonts/newsreader-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Newsreader"; src: url("../fonts/newsreader-latin-500-normal.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Newsreader"; src: url("../fonts/newsreader-latin-400-italic.woff2") format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Noto Nastaliq Urdu"; src: url("../fonts/noto-nastaliq-urdu-arabic-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Noto Nastaliq Urdu"; src: url("../fonts/noto-nastaliq-urdu-arabic-600-normal.woff2") format("woff2"); font-weight: 600; font-display: swap; }

:root {
  --lapis: #131823;      /* page ground */
  --lapis-2: #1a2030;    /* raised surface */
  --lapis-3: #232a3c;    /* hover / inset */
  --rule: #313a50;       /* hairlines */
  --paper: #e8e3d6;      /* primary text */
  --paper-dim: #a59f92;  /* secondary text */
  --gold: #c9a65e;       /* illumination accent */
  --gold-dim: #7d6a42;
  --verdigris: #74a896;  /* accepted / done */
  --rust: #cf7457;       /* failed / destructive */

  --sans: "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  --urdu: "Noto Nastaliq Urdu", "Jameel Noori Nastaleeq", "Urdu Typesetting", "Newsreader", serif;

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px; --s8: 72px;
  --radius: 3px;
  --rail: 232px;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; min-height: 100dvh;
  background: var(--lapis); color: var(--paper);
  font: 400 15px/1.55 var(--sans);
  font-feature-settings: "kern", "liga";
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
a { color: var(--gold); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { color: var(--paper); }
code { font: 13px/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace; background: var(--lapis-3); padding: 2px 6px; border-radius: var(--radius); word-break: break-all; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
::selection { background: var(--gold-dim); color: var(--paper); }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.ur { font-family: var(--urdu); line-height: 2.3; font-feature-settings: normal; }

/* ---------- boot */
.boot { display: grid; place-items: center; min-height: 100dvh; }
.boot-mark { font: 400 22px var(--serif); color: var(--paper-dim); }

/* ---------- shell */
.app { display: grid; grid-template-columns: var(--rail) minmax(0, 1fr); min-height: 100dvh; }
.rail {
  position: sticky; top: 0; height: 100dvh;
  display: flex; flex-direction: column; gap: var(--s6);
  padding: var(--s6) var(--s5);
  border-right: 1px solid var(--rule);
}
.wordmark { display: flex; align-items: baseline; gap: var(--s2); text-decoration: none; color: var(--paper); }
.wordmark-latin { font: 500 24px/1 var(--serif); letter-spacing: -0.01em; }
.wordmark-ur { font: 400 17px/1 var(--urdu); color: var(--gold); position: relative; top: 4px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link { display: block; padding: var(--s2) var(--s3); margin-left: calc(-1 * var(--s3)); color: var(--paper-dim); text-decoration: none; border-left: 2px solid transparent; }
.nav-link:hover { color: var(--paper); }
.nav-link.is-active { color: var(--paper); border-left-color: var(--gold); }
.rail-foot { margin-top: auto; display: flex; flex-direction: column; gap: var(--s1); font-size: 13px; color: var(--paper-dim); }
.rail-user { color: var(--paper); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.view { padding: var(--s7) var(--s7) var(--s8); max-width: 1180px; width: 100%; min-width: 0; outline: none; }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s4); margin-bottom: var(--s6); flex-wrap: wrap; }
.view-title { font: 400 40px/1.1 var(--serif); letter-spacing: -0.015em; }
.view-title.ur { font: 400 34px/2 var(--urdu); }
.view-lede { max-width: 62ch; color: var(--paper-dim); margin: calc(-1 * var(--s4)) 0 var(--s6); }
.section-title { font: 500 20px/1.3 var(--serif); margin-bottom: var(--s4); }

/* ---------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 40px; padding: 0 var(--s4);
  font: 500 14px/1 var(--sans); text-decoration: none; cursor: pointer;
  border-radius: var(--radius); border: 1px solid var(--rule);
  background: transparent; color: var(--paper);
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--lapis-3); color: var(--paper); }
.btn:disabled, .btn.is-disabled { opacity: .45; cursor: not-allowed; pointer-events: none; }
.btn-primary { background: var(--gold); border-color: var(--gold); color: #1b1608; }
.btn-primary:hover { background: #dbb96f; border-color: #dbb96f; color: #1b1608; }
.btn-danger { background: var(--rust); border-color: var(--rust); color: #1b0d08; }
.btn-danger:hover { background: #e08668; color: #1b0d08; }
.btn-danger-text { color: var(--rust); }
.btn-small { min-height: 32px; padding: 0 var(--s3); font-size: 13px; }
.btn-wide { width: 100%; }
.link-btn { background: none; border: 0; padding: 0; color: var(--gold); font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; text-align: left; }
.link-btn:hover { color: var(--paper); }
.link-back { color: var(--paper-dim); text-decoration: none; }
.link-back::before { content: "‹ "; }

/* ---------- forms */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: 13px; font-weight: 500; color: var(--paper-dim); }
.field-hint { font-size: 12.5px; color: var(--paper-dim); }
input, select {
  width: 100%; min-height: 42px; padding: 0 var(--s3);
  font: 15px var(--sans); color: var(--paper);
  background: var(--lapis); border: 1px solid var(--rule); border-radius: var(--radius);
}
input:focus, select:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
input[dir="auto"]:dir(rtl) { font-family: var(--urdu); }
.form-error { color: var(--rust); font-size: 14px; min-height: 1em; }
.form-error:empty { display: none; }

/* ---------- auth */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: var(--s5); }
.auth-panel { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: var(--s5); }
.auth-ur { font: 400 44px/2.2 var(--urdu); color: var(--gold); text-align: right; margin-bottom: calc(-1 * var(--s4)); }
.auth-title { font: 400 30px/1.15 var(--serif); }
.auth-lede { color: var(--paper-dim); }
.auth-form { display: flex; flex-direction: column; gap: var(--s4); padding-top: var(--s5); border-top: 1px solid var(--rule); }
.auth-swap { font-size: 14px; color: var(--paper-dim); }

/* ---------- status & progress */
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--paper-dim); white-space: nowrap; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-ready { color: var(--verdigris); }
.status-processing { color: var(--gold); }
.status-attention { color: var(--rust); }
.bar { height: 3px; background: var(--rule); border-radius: 2px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--gold); transition: width .4s ease; }
.loading { display: flex; align-items: center; gap: var(--s3); color: var(--paper-dim); padding: var(--s5) 0; }
.loading-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gold); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }

.callout { border-left: 2px solid var(--gold); background: var(--lapis-2); padding: var(--s4) var(--s5); margin-bottom: var(--s5); display: flex; flex-direction: column; gap: var(--s3); align-items: flex-start; max-width: 72ch; }
.callout-error { border-left-color: var(--rust); }
.callout-wait { border-left-color: var(--gold); }
.empty { color: var(--paper-dim); max-width: 56ch; display: flex; flex-direction: column; gap: var(--s4); align-items: flex-start; padding: var(--s5) 0; }
.empty-ur { font: 400 36px/2 var(--urdu); color: var(--gold); }
.quiet-note { color: var(--paper-dim); font-size: 14px; margin-top: var(--s4); }

/* ---------- project list */
.project-list { border-top: 1px solid var(--rule); }
.project-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s1) var(--s5); align-items: center;
  padding: var(--s5) 0; border-bottom: 1px solid var(--rule);
  color: var(--paper); text-decoration: none;
}
.project-row:hover { color: var(--paper); background: linear-gradient(90deg, var(--lapis-2), transparent 70%); }
.project-title { font: 400 22px/1.35 var(--serif); grid-column: 1; }
.project-title.ur { font: 400 21px/2.1 var(--urdu); }
.project-meta { grid-column: 1; font-size: 13px; color: var(--paper-dim); }
.project-row .status { grid-column: 2; grid-row: 1 / span 2; }
.project-row .bar { grid-column: 1 / -1; margin-top: var(--s2); max-width: 520px; }

/* ---------- project */
.project-head { align-items: flex-start; margin-bottom: var(--s5); }
.project-head-main { display: flex; flex-direction: column; gap: var(--s2); min-width: 0; }
.project-sub { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; font-size: 14px; color: var(--paper-dim); }
.project-head-actions { display: flex; gap: var(--s2); }
.tabs { display: flex; gap: var(--s5); border-bottom: 1px solid var(--rule); margin-bottom: var(--s6); overflow-x: auto; scrollbar-width: none; }
.tab { padding: var(--s3) 0; color: var(--paper-dim); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--paper); }
.tab.is-active { color: var(--paper); border-bottom-color: var(--gold); }

.pipeline { list-style: none; margin: 0 0 var(--s5); padding: 0; max-width: 680px; counter-reset: step; }
.step { position: relative; display: grid; grid-template-columns: 28px 1fr; gap: var(--s4); padding-bottom: var(--s6); counter-increment: step; }
.step:not(:last-child)::before { content: ""; position: absolute; left: 13px; top: 30px; bottom: 4px; width: 1px; background: var(--rule); }
.step-mark { width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--rule); display: grid; place-items: center; font: 500 13px var(--serif); color: var(--paper-dim); }
.step-mark::before { content: counter(step); }
.step-done .step-mark { border-color: var(--verdigris); color: var(--verdigris); }
.step-done .step-mark::before { content: "✓"; }
.step-active .step-mark { border-color: var(--gold); color: var(--gold); }
.step-failed .step-mark { border-color: var(--rust); color: var(--rust); }
.step-failed .step-mark::before { content: "!"; }
.step-body { display: flex; flex-direction: column; gap: var(--s2); padding-top: 3px; }
.step-body .btn { align-self: flex-start; margin-top: var(--s2); }
.step-title { font-weight: 500; }
.step-todo .step-title { color: var(--paper-dim); }
.step-detail { color: var(--paper-dim); font-size: 14px; }

.legend { display: flex; flex-wrap: wrap; gap: var(--s5); font-size: 13px; color: var(--paper-dim); }
.legend-item { display: inline-flex; align-items: center; gap: var(--s2); }
.legend-item i { width: 10px; height: 10px; border: 1px solid var(--rule); border-radius: 2px; }
.legend-item.page-done i { background: var(--lapis-3); border-color: var(--verdigris); }
.legend-item.page-queued i { border-style: dashed; }
.legend-item.page-failed i { border-color: var(--rust); }
.legend-badge b { font: 600 11px/18px var(--sans); min-width: 18px; text-align: center; border-radius: 9px; background: var(--gold); color: #1b1608; }
.page-grid { list-style: none; padding: 0; margin: var(--s5) 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: var(--s2); }
.page-tile {
  position: relative; display: grid; place-items: center; aspect-ratio: 3 / 4;
  border: 1px solid var(--rule); border-radius: 2px; color: var(--paper-dim); text-decoration: none; font: 400 14px var(--serif);
}
.page-tile:hover { border-color: var(--gold); color: var(--paper); }
.page-done { background: var(--lapis-2); border-color: color-mix(in srgb, var(--verdigris) 55%, var(--rule)); color: var(--paper); }
.page-queued, .page-uploaded { border-style: dashed; }
.page-failed { border-color: var(--rust); color: var(--rust); }
.page-badge { position: absolute; top: -6px; right: -6px; font: 600 11px/18px var(--sans); min-width: 18px; padding: 0 4px; text-align: center; border-radius: 9px; background: var(--gold); color: #1b1608; }

.bulk { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s4); padding: var(--s5); background: var(--lapis-2); border-radius: var(--radius); }
.bulk-count { color: var(--paper-dim); }
.bulk-count strong { font: 400 32px/1 var(--serif); color: var(--paper); margin-right: var(--s2); }
.bulk-actions { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.bulk-actions select { width: auto; }
.corr-pages { list-style: none; padding: 0; margin: var(--s5) 0 0; max-width: 520px; border-top: 1px solid var(--rule); }
.corr-page-link { display: flex; justify-content: space-between; padding: var(--s3) 0; border-bottom: 1px solid var(--rule); color: var(--paper); text-decoration: none; }
.corr-page-link:hover { color: var(--gold); }
.corr-page-count { color: var(--paper-dim); font-size: 14px; }

.contents-book { font: 400 26px/2 var(--urdu); margin-bottom: var(--s4); text-align: right; }
.toc, .toc-sections { list-style: none; padding: 0; margin: 0; }
.toc { max-width: 760px; border-top: 1px solid var(--rule); }
.toc-chapter { border-bottom: 1px solid var(--rule); padding: var(--s3) 0; }
.toc-link { display: flex; align-items: baseline; gap: var(--s4); color: var(--paper); text-decoration: none; }
.toc-link:hover { color: var(--gold); }
.toc-title { flex: 1; }
.toc-chapter > .toc-link .toc-title { font-size: 19px; }
.toc-sections { padding-right: var(--s6); color: var(--paper-dim); }
.toc-sections .toc-link { color: var(--paper-dim); }
.toc-pages { font: 400 13px var(--sans); color: var(--paper-dim); white-space: nowrap; }

/* ---------- reader */
.reader-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); margin-bottom: var(--s5); flex-wrap: wrap; }
.reader-pos { font: 400 18px var(--serif); }
.reader-step { display: flex; gap: var(--s2); }
.pane-toggle { display: none; }
.spread { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--s6); align-items: start; }
.scan { margin: 0; position: sticky; top: var(--s5); background: #fff; border-radius: 2px; overflow: hidden; max-height: calc(100dvh - 48px); }
.scan img { display: block; width: 100%; height: auto; max-height: calc(100dvh - 48px); object-fit: contain; }

/* The folio: a ruled double frame, as on a manuscript page. */
.folio {
  position: relative; direction: rtl; padding: var(--s6) var(--s6) var(--s5);
  background: var(--lapis-2);
  border: 1px solid var(--gold-dim);
  outline: 1px solid var(--gold-dim); outline-offset: 5px;
  margin: 6px;
}
.folio > * + * { margin-top: var(--s3); }
.blk { font-size: 19px; line-height: 2.2; text-align: start; }
.blk.ur { font-size: 20px; line-height: 2.45; text-align: justify; text-justify: inter-word; }
.blk:not(.ur) { font-family: var(--serif); line-height: 1.6; }
h2.blk { font-size: 26px; font-weight: 600; text-align: center; color: var(--gold); }
h3.blk { font-size: 22px; font-weight: 600; text-align: start; }
.blk-verse { white-space: pre-line; text-align: center !important; }
.blk-list { white-space: pre-line; }
.blk-caption, .blk-footnote { font-size: 15px !important; color: var(--paper-dim); }
.blk-footnote { border-top: 1px solid var(--rule); padding-top: var(--s2); }
.blk-header_footer { font-size: 13px !important; color: var(--paper-dim); text-align: center !important; opacity: .7; }
.blk-table-wrap { overflow-x: auto; }
table.blk { border-collapse: collapse; width: 100%; font-size: 16px; }
table.blk td { border: 1px solid var(--rule); padding: 2px var(--s3); vertical-align: top; }
.folio-wait { color: var(--paper-dim); direction: ltr; text-align: left; }
.folio-meta { direction: ltr; text-align: left; font-size: 12.5px; color: var(--paper-dim); border-top: 1px solid var(--rule); padding-top: var(--s3); margin-top: var(--s5) !important; }

.mark {
  font: inherit; color: inherit; background: none; border: 0; padding: 0 1px; cursor: pointer;
  text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 6px;
}
.mark-pending { text-decoration-color: var(--gold); text-decoration-style: dotted; background: color-mix(in srgb, var(--gold) 12%, transparent); }
.mark-accepted { text-decoration-color: var(--verdigris); }
.mark-rejected { text-decoration-color: var(--rule); }
.mark:hover { background: color-mix(in srgb, var(--gold) 24%, transparent); }

.review { margin-top: var(--s7); max-width: 760px; }
.review-head { display: flex; justify-content: space-between; align-items: center; gap: var(--s4); flex-wrap: wrap; margin-bottom: var(--s4); }
.review-title { font: 500 20px var(--serif); }
.review-bulk { display: flex; gap: var(--s2); }
.cards { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; border-top: 1px solid var(--rule); }
.card { padding: var(--s4) 0; border-bottom: 1px solid var(--rule); display: flex; flex-direction: column; gap: var(--s2); outline: none; transition: background-color .4s; }
.card.is-flash { background: color-mix(in srgb, var(--gold) 14%, transparent); }
.card-change { display: flex; align-items: baseline; gap: var(--s3); flex-wrap: wrap; justify-content: flex-start; }
.card-from { font-size: 20px; color: var(--paper-dim); text-decoration: line-through; text-decoration-color: var(--rust); }
.card-to { font-size: 20px; color: var(--paper); }
.card-arrow { color: var(--gold); }
.card-meta { font-size: 13px; color: var(--paper-dim); }
.card-reason { font-size: 14px; }
.card-actions { display: flex; align-items: center; gap: var(--s3); margin-top: var(--s1); }
.card-state { font-size: 13px; color: var(--paper-dim); }
.card-accepted .card-state { color: var(--verdigris); }
.card-accepted .card-from, .card-rejected .card-to { opacity: .6; }
.card-rejected .card-from { text-decoration: none; color: var(--paper); }

/* ---------- upload dialog */
.dialog {
  width: min(480px, calc(100vw - 32px)); padding: var(--s6);
  background: var(--lapis-2); color: var(--paper);
  border: 1px solid var(--rule); border-radius: 4px;
}
.dialog-wide { width: min(560px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgb(8 10 16 / .72); }
.dialog-title { font: 400 26px/1.2 var(--serif); margin-bottom: var(--s5); }
.dialog-body { color: var(--paper-dim); margin-bottom: var(--s5); }
.dialog-actions { display: flex; justify-content: flex-end; gap: var(--s2); margin-top: var(--s5); }
.upload { display: flex; flex-direction: column; gap: var(--s4); }
.upload-confirm { display: flex; flex-direction: column; gap: var(--s4); }
.drop {
  display: flex; flex-direction: column; gap: var(--s2); align-items: center; text-align: center;
  padding: var(--s7) var(--s5); cursor: pointer;
  border: 1px dashed var(--gold-dim); border-radius: var(--radius);
}
.drop:hover, .drop.is-over, .drop:focus-within { border-color: var(--gold); background: var(--lapis-3); }
.drop-title { font: 400 20px var(--serif); }
.drop-hint { color: var(--paper-dim); font-size: 14px; max-width: 40ch; }
.upload-file { color: var(--paper-dim); font-size: 14px; word-break: break-word; }
.upload-step { font: 400 19px var(--serif); }
.upload-count { font-size: 14px; color: var(--paper-dim); }
.upload-note { font-size: 14px; color: var(--paper-dim); }

/* ---------- keys */
.key-form, .settings { padding: var(--s5); background: var(--lapis-2); border-radius: var(--radius); margin-bottom: var(--s6); display: flex; flex-direction: column; gap: var(--s4); align-items: flex-start; }
.key-form .section-title, .settings .section-title { margin-bottom: 0; }
.key-form-grid { display: grid; grid-template-columns: 160px 1fr 1.6fr; gap: var(--s4); width: 100%; }
.settings .field { width: 100%; max-width: 520px; }
.model-row { display: flex; align-items: flex-end; gap: var(--s3); width: 100%; max-width: 640px; flex-wrap: wrap; }
.model-row .field { flex: 1; min-width: 220px; }
.model-row .btn { margin-bottom: 22px; }
.key-list { list-style: none; padding: 0; margin: 0 0 var(--s6); border-top: 1px solid var(--rule); }
.key-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s2) var(--s5); padding: var(--s4) 0; border-bottom: 1px solid var(--rule); align-items: center; }
.key-id { display: flex; align-items: baseline; gap: var(--s3); min-width: 0; }
.key-label { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.key-mask { background: none; padding: 0; color: var(--paper-dim); }
.key-health { display: flex; align-items: center; gap: var(--s2); font-size: 14px; justify-self: end; }
.key-health .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--paper-dim); }
.health-healthy .dot { background: var(--verdigris); }
.health-rate_limited .dot, .health-error .dot { background: var(--gold); }
.health-invalid .dot { background: var(--rust); }
.health-invalid .key-health { color: var(--rust); }
.key-sub { color: var(--paper-dim); }
.key-usage, .key-error { grid-column: 1 / -1; font-size: 13px; color: var(--paper-dim); }
.key-error { color: var(--rust); }
.key-actions { grid-column: 1 / -1; display: flex; gap: var(--s2); }

/* ---------- toasts */
.toasts { position: fixed; z-index: 50; bottom: var(--s5); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: var(--s2); width: min(440px, calc(100vw - 32px)); pointer-events: none; }
.toast { padding: var(--s3) var(--s4); background: var(--paper); color: var(--lapis); border-radius: var(--radius); font-size: 14px; box-shadow: 0 8px 24px rgb(0 0 0 / .35); animation: rise .2s ease-out; }
.toast-error { background: var(--rust); color: #1b0d08; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

/* ---------- tablet */
@media (max-width: 1080px) {
  .view { padding: var(--s6) var(--s5) var(--s8); }
  .spread { grid-template-columns: 1fr; }
  .scan { position: static; max-height: none; }
  .scan img { max-height: 80dvh; }
  .spread[data-pane="text"] .scan { display: none; }
  .spread[data-pane="scan"] .folio { display: none; }
  .pane-toggle { display: inline-flex; border: 1px solid var(--rule); border-radius: var(--radius); margin-bottom: var(--s4); }
  .pane-btn { min-height: 36px; padding: 0 var(--s4); background: none; border: 0; color: var(--paper-dim); font: 500 14px var(--sans); cursor: pointer; }
  .pane-btn.is-active { background: var(--lapis-3); color: var(--paper); }
  .key-form-grid { grid-template-columns: 1fr 1fr; }
  .key-form-grid .field:last-child { grid-column: 1 / -1; }
}

/* ---------- phone: navigation moves to a bottom bar */
@media (max-width: 720px) {
  body { font-size: 15px; }
  .app { grid-template-columns: minmax(0, 1fr); padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
  .rail {
    position: fixed; z-index: 20; top: auto; bottom: 0; left: 0; right: 0; height: auto;
    flex-direction: row; align-items: center; gap: var(--s4);
    padding: var(--s2) var(--s4) calc(var(--s2) + env(safe-area-inset-bottom));
    background: var(--lapis); border-right: 0; border-top: 1px solid var(--rule);
  }
  .wordmark { display: none; }
  .nav { flex-direction: row; gap: var(--s2); flex: 1; }
  .nav-link { margin: 0; padding: var(--s3); border-left: 0; border-top: 2px solid transparent; }
  .nav-link.is-active { border-left-color: transparent; border-top-color: var(--gold); }
  .rail-foot { margin: 0; }
  .rail-user { display: none; }
  .view { padding: var(--s5) var(--s4) var(--s7); }
  .view-title { font-size: 30px; }
  .view-title.ur { font-size: 26px; }
  .project-head-actions { width: 100%; }
  .folio { padding: var(--s5) var(--s4); }
  .blk.ur { font-size: 18px; text-align: start; }
  .key-form-grid { grid-template-columns: 1fr; }
  .key-row { grid-template-columns: 1fr; }
  .key-health { justify-self: start; }
  .reader-head { gap: var(--s2); }
  .reader-step { width: 100%; }
  .reader-step .btn { flex: 1; }
}

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

/* ================= Milestone 2: chapters, search, notes, history ================= */

.tabs { gap: var(--s5); }
.toc-state { font: 400 12.5px var(--sans); color: var(--paper-dim); white-space: nowrap; }
.toc-state-done { color: var(--verdigris); }
.toc-state-running, .toc-state-queued { color: var(--gold); }
.toc-state-failed { color: var(--rust); }

/* chapter knowledge */
.chapter .link-back { display: inline-block; margin-bottom: var(--s4); }
.chapter-head { align-items: flex-start; }
.kn-summary { max-width: 760px; margin: var(--s5) 0 var(--s7); padding: var(--s5) 0; border-top: 1px solid var(--gold-dim); border-bottom: 1px solid var(--gold-dim); display: flex; flex-direction: column; gap: var(--s4); }
.kn-summary-ur { font-size: 20px; line-height: 2.35; text-align: justify; }
.kn-summary-en { font: 400 17px/1.6 var(--serif); color: var(--paper-dim); font-style: italic; }
.kn-section { margin-bottom: var(--s7); max-width: 960px; }
.kn-meta { font: 400 14px var(--sans); color: var(--paper-dim); }
.kn-filter { max-width: 320px; margin-bottom: var(--s4); }
.table-wrap { overflow-x: auto; border-top: 1px solid var(--rule); }
.kn-table { width: 100%; border-collapse: collapse; }
.kn-table th { text-align: left; font: 500 12.5px var(--sans); color: var(--paper-dim); padding: var(--s3) var(--s3) var(--s2) 0; border-bottom: 1px solid var(--rule); }
.kn-table td { padding: var(--s3) var(--s3) var(--s3) 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
.kn-table td:first-child { min-width: 150px; }
.kn-term { display: block; font-size: 21px; line-height: 2; color: var(--gold); }
.kn-translit { display: block; font: italic 400 15px var(--serif); color: var(--paper-dim); }
.kn-body { font-size: 17px; }
.kn-body.ur { line-height: 2.2; }
.kn-def { font-size: 15px; color: var(--paper-dim); margin-top: var(--s1); }
.kn-en-cell { min-width: 180px; font: 400 15px/1.5 var(--serif); }
.kn-cat { display: block; font: 400 12px var(--sans); color: var(--paper-dim); margin-top: var(--s1); }
.kn-none { color: var(--paper-dim); }
.src { font: 400 12.5px var(--sans); color: var(--paper-dim); white-space: nowrap; }
.src a { color: var(--paper-dim); }
.src a:hover { color: var(--gold); }
.kn-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: var(--s5) var(--s6); }
.kn-item { display: flex; flex-direction: column; gap: var(--s2); padding-top: var(--s3); border-top: 1px solid var(--rule); }
.kn-item-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s3); flex-direction: row-reverse; }
.kn-name { font-size: 20px; font-weight: 600; }
.kn-en { font: 400 15px/1.55 var(--serif); color: var(--paper-dim); }
.kn-tree { list-style: none; padding: 0 var(--s4) 0 0; margin: 0; border-right: 1px solid var(--gold-dim); display: flex; flex-direction: column; gap: var(--s1); }
.kn-tree li { position: relative; padding-right: var(--s3); }
.kn-tree li::before { content: ""; position: absolute; right: calc(-1 * var(--s4)); top: 1.3em; width: var(--s4); border-top: 1px solid var(--gold-dim); }
.kn-tree-name { font-size: 18px; }
.kn-tree-desc { display: block; font-size: 15px; color: var(--paper-dim); }
.kn-steps { margin: 0; padding-right: var(--s5); font-size: 17px; }
.kn-steps li::marker { color: var(--gold); font-family: var(--serif); }
.kn-rels, .kn-facts { list-style: none; padding: 0; margin: 0; border-top: 1px solid var(--rule); }
.kn-rel, .kn-facts li { padding: var(--s3) 0; border-bottom: 1px solid var(--rule); }
.kn-rel-line { display: flex; align-items: baseline; gap: var(--s3); flex-wrap: wrap; }
.kn-rel-node { font-size: 19px; }
.kn-rel-verb { font: italic 400 14px var(--serif); color: var(--gold); padding: 0 var(--s2); border-bottom: 1px solid var(--gold-dim); }
.kn-facts li { direction: rtl; }

/* search */
.search-bar { max-width: 640px; }
.search-input { min-height: 52px; font-size: 18px; padding: 0 var(--s4); }
.search-input:dir(rtl) { font-family: var(--urdu); font-size: 19px; }
.search-hint { margin: var(--s2) 0 var(--s6); }
.search-results { max-width: 820px; }
.search-results .section-title { margin-top: var(--s6); }
.res-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--rule); }
.res-link { display: flex; flex-direction: column; gap: var(--s1); padding: var(--s3) 0; border-bottom: 1px solid var(--rule); color: var(--paper); text-decoration: none; }
.res-link:hover { background: linear-gradient(90deg, transparent, var(--lapis-2) 60%); color: var(--paper); }
.res-title { font-size: 20px; }
.res-meta, .res-page-n { font-size: 13px; color: var(--paper-dim); }
.res-snippet { font-size: 17px; }
.res-snippet.ur { line-height: 2.3; }
mark { background: color-mix(in srgb, var(--gold) 30%, transparent); color: var(--paper); border-radius: 2px; padding: 0 1px; }

/* notes */
.notes-panel { max-width: 760px; margin-top: var(--s7); }
.notes-head { display: flex; justify-content: space-between; align-items: center; gap: var(--s4); margin-bottom: var(--s3); }
.notes-empty { color: var(--paper-dim); font-size: 14px; }
.notes-list { display: flex; flex-direction: column; gap: var(--s4); }
.note { display: flex; flex-direction: column; gap: var(--s1); }
.note + .note, .notes-target + .note { margin-top: var(--s3); }
.note-text {
  width: 100%; min-height: 96px; resize: vertical; padding: var(--s3) var(--s4);
  font: 400 16px/1.6 var(--serif); color: var(--paper);
  background: var(--lapis-2); border: 1px solid var(--rule); border-left: 2px solid var(--gold-dim); border-radius: var(--radius);
}
.note-text.ur { font-family: var(--urdu); font-size: 18px; line-height: 2.2; border-left: 1px solid var(--rule); border-right: 2px solid var(--gold-dim); }
.note-text:focus { outline: none; border-color: var(--gold); }
.note-foot { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--paper-dim); }
.notes-elsewhere { margin-top: var(--s7); }
.notes-target { display: inline-block; margin-top: var(--s5); font-size: 14px; }

/* history */
.history { list-style: none; padding: 0; margin: 0; max-width: 760px; border-top: 1px solid var(--rule); }
.hist { display: grid; grid-template-columns: 56px 1fr auto; gap: var(--s4); align-items: center; padding: var(--s3) 0; border-bottom: 1px solid var(--rule); }
.hist-v { font: 400 15px var(--serif); color: var(--paper-dim); }
.hist-label { font-size: 15px; }
.hist-time { font-size: 12.5px; color: var(--paper-dim); }
.hist-origin .hist-v { color: var(--gold); }

@media (max-width: 720px) {
  .kn-list { grid-template-columns: 1fr; }
  .kn-table thead { display: none; }
  .kn-table tr { display: grid; grid-template-columns: 1fr; padding: var(--s3) 0; border-bottom: 1px solid var(--rule); }
  .kn-table td { border: 0; padding: 2px 0; }
  .hist { grid-template-columns: 44px 1fr; }
  .hist .btn { grid-column: 2; justify-self: start; }
}

.kn-table .ur { text-align: left; }
.kn-table td:first-child .kn-term { text-align: left; }
