:root {
  --forest: #263d35;
  --forest-2: #355247;
  --paper: #f4f0e7;
  --sheet: #fffdf8;
  --ink: #202824;
  --muted: #69726c;
  --line: #d9d6cd;
  --gold: #c59a52;
  --gold-soft: #f2e4c7;
  --red: #a24b3d;
  --red-soft: #f5ded8;
  --green-soft: #dce9df;
  --shadow: 0 16px 42px rgba(30, 42, 36, .1);
  --sidebar: 280px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; color: var(--ink); background: var(--paper); font-family: Inter, "Segoe UI", Arial, sans-serif; font-size: 14px; }
button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.loading-screen { position: fixed; z-index: 100; inset: 0; display: grid; place-content: center; justify-items: center; color: var(--forest); background: var(--paper); transition: opacity .25s ease, visibility .25s ease; }
.loading-screen.ready { visibility: hidden; opacity: 0; }
.loading-screen p { margin: 16px 0 0; color: var(--muted); }
.loading-mark, .brand-mark { display: grid; place-items: center; color: #fff; background: var(--forest); font-family: Georgia, serif; }
.loading-mark { width: 58px; height: 58px; border-radius: 50% 50% 50% 12px; font-size: 30px; animation: breathe 1.25s ease-in-out infinite alternate; }
@keyframes breathe { to { transform: translateY(-5px); box-shadow: 0 12px 28px rgba(38, 61, 53, .25); } }

.masthead { position: fixed; z-index: 40; top: 0; left: 0; right: 0; height: 72px; display: flex; align-items: center; gap: 24px; padding: 0 22px; color: white; background: var(--forest); box-shadow: 0 2px 12px rgba(18, 31, 26, .18); }
.brand { min-width: calc(var(--sidebar) - 22px); display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand-mark { width: 38px; height: 38px; border: 1px solid rgba(255,255,255,.38); border-radius: 50% 50% 50% 9px; background: rgba(255,255,255,.08); font-size: 21px; }
.brand b, .brand small { display: block; }
.brand b { font-family: Georgia, "Times New Roman", serif; font-size: 17px; font-weight: 500; letter-spacing: .02em; }
.brand small { margin-top: 2px; color: rgba(255,255,255,.63); font-size: 10px; letter-spacing: .13em; text-transform: uppercase; }
.document-tabs { display: flex; min-width: 0; gap: 5px; }
.document-tab { max-width: 260px; overflow: hidden; padding: 9px 14px; border: 1px solid transparent; border-radius: 8px; color: rgba(255,255,255,.67); background: transparent; cursor: pointer; text-overflow: ellipsis; white-space: nowrap; transition: .18s ease; }
.document-tab:hover { color: white; background: rgba(255,255,255,.07); }
.document-tab.active { border-color: rgba(255,255,255,.14); color: white; background: rgba(255,255,255,.12); }

.app-shell { min-height: 100vh; padding-top: 72px; }
.sidebar { position: fixed; z-index: 30; top: 72px; bottom: 0; left: 0; width: var(--sidebar); display: flex; flex-direction: column; border-right: 1px solid var(--line); background: #faf8f2; }
.sidebar-head { position: relative; padding: 24px 20px 18px; border-bottom: 1px solid var(--line); }
.eyebrow { margin: 0 0 7px; color: var(--gold); font-size: 10px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.sidebar h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 20px; font-weight: 500; line-height: 1.18; }
.archive-code { margin: 8px 0 0; color: var(--muted); font-size: 11px; }
.close-sidebar { display: none; position: absolute; top: 12px; right: 12px; }
.search-wrap { position: relative; margin: 15px 15px 9px; }
.search-wrap svg { position: absolute; top: 10px; left: 11px; width: 17px; height: 17px; color: #8c938e; }
.search-wrap input { width: 100%; height: 38px; padding: 0 48px 0 36px; border: 1px solid var(--line); border-radius: 9px; outline: 0; color: var(--ink); background: white; }
.search-wrap input:focus { border-color: #82978d; box-shadow: 0 0 0 3px rgba(53,82,71,.1); }
.search-wrap kbd { position: absolute; top: 9px; right: 8px; padding: 3px 5px; border: 1px solid #dfddd6; border-radius: 4px; color: #8c938e; background: #f7f6f2; font: 9px/1.2 inherit; }
.search-results { max-height: 44%; overflow: auto; margin: 0 15px 10px; border: 1px solid var(--line); border-radius: 9px; background: white; box-shadow: var(--shadow); }
.search-result { width: 100%; padding: 10px 12px; border: 0; border-bottom: 1px solid #ece9e1; text-align: left; background: transparent; cursor: pointer; }
.search-result:last-child { border-bottom: 0; }
.search-result:hover { background: #f7f5ee; }
.search-result b { display: block; margin-bottom: 3px; color: var(--forest); font-size: 11px; }
.search-result span { display: -webkit-box; overflow: hidden; color: var(--muted); font-size: 11px; line-height: 1.4; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.search-empty { padding: 18px 12px; color: var(--muted); text-align: center; font-size: 11px; }
.page-list-head { display: flex; justify-content: space-between; padding: 10px 18px 8px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.page-list { flex: 1; overflow: auto; padding: 0 10px 12px; }
.page-link { position: relative; width: 100%; display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 0; border-radius: 7px; color: var(--muted); background: transparent; cursor: pointer; text-align: left; }
.page-link:hover { color: var(--ink); background: #f0ede4; }
.page-link.active { color: var(--forest); background: var(--green-soft); font-weight: 700; }
.page-number { min-width: 32px; font-variant-numeric: tabular-nums; }
.page-preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: Georgia, serif; font-size: 11px; }
.status-dot { width: 7px; height: 7px; flex: 0 0 7px; margin-left: auto; border: 1px solid #aeb4af; border-radius: 50%; }
.status-dot.verified { border-color: #5d846e; background: #5d846e; }
.status-dot.issue { border-color: var(--red); background: var(--red); }
.sidebar-footer { display: flex; gap: 5px; padding: 10px; border-top: 1px solid var(--line); }
.text-button { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 7px; border: 0; border-radius: 7px; color: var(--muted); background: transparent; cursor: pointer; font-size: 11px; }
.text-button:hover { color: var(--forest); background: #eeebe2; }
.text-button svg { width: 16px; height: 16px; }

.main { min-width: 0; margin-left: var(--sidebar); }
.toolbar { position: sticky; z-index: 20; top: 72px; height: 58px; display: flex; align-items: center; justify-content: space-between; padding: 0 22px; border-bottom: 1px solid var(--line); background: rgba(244,240,231,.94); backdrop-filter: blur(12px); }
.page-controls, .view-controls { display: flex; align-items: center; gap: 7px; }
.icon-button { width: 34px; height: 34px; display: inline-grid; place-items: center; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--sheet); cursor: pointer; }
.icon-button:hover:not(:disabled) { border-color: #a9b4ad; background: white; }
.icon-button:disabled { opacity: .38; cursor: default; }
.page-controls > .icon-button { font: 25px/1 Georgia, serif; }
.page-field { margin: 0 4px; color: var(--muted); font-size: 11px; }
.page-field input { width: 48px; margin: 0 4px 0 7px; padding: 6px 4px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); background: var(--sheet); text-align: center; font-variant-numeric: tabular-nums; }
.segmented { display: flex; padding: 3px; border: 1px solid var(--line); border-radius: 8px; background: #ebe7de; }
.segmented button { padding: 6px 10px; border: 0; border-radius: 5px; color: var(--muted); background: transparent; cursor: pointer; font-size: 11px; }
.segmented button.active { color: var(--forest); background: white; box-shadow: 0 1px 4px rgba(30,42,36,.1); font-weight: 700; }
.divider { width: 1px; height: 24px; margin: 0 3px; background: var(--line); }
.zoom-label { min-width: 42px; color: var(--muted); text-align: center; font-size: 10px; font-variant-numeric: tabular-nums; }
.mobile-sidebar-button { display: none; margin-left: auto; color: var(--forest); background: white; }

.scope-banner { display: flex; align-items: center; gap: 9px; min-height: 39px; padding: 8px 22px; border-bottom: 1px solid #e2d5b9; color: #725b32; background: #f7ecd5; font-size: 11px; }
.scope-banner::before { content: "i"; width: 17px; height: 17px; display: grid; flex: 0 0 17px; place-items: center; border: 1px solid #a9884e; border-radius: 50%; font: italic 12px Georgia, serif; }
.page-view { height: calc(100vh - 169px); display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(390px, .95fr); gap: 1px; background: var(--line); }
.panel { min-width: 0; display: flex; flex-direction: column; background: var(--sheet); }
.panel-heading { height: 63px; display: flex; flex: 0 0 63px; align-items: center; justify-content: space-between; padding: 0 20px; border-bottom: 1px solid var(--line); background: var(--sheet); }
.panel-heading h2 { margin: 2px 0 0; font-family: Georgia, "Times New Roman", serif; font-size: 18px; font-weight: 500; }
.panel-kicker { color: var(--gold); font-size: 9px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.open-link { color: var(--forest-2); font-size: 11px; text-decoration: none; }
.open-link:hover { text-decoration: underline; }
.page-badge { padding: 5px 8px; border-radius: 5px; color: var(--forest); background: var(--green-soft); font-size: 10px; font-weight: 700; }
.canvas-stage { position: relative; flex: 1; min-height: 0; overflow: auto; display: grid; place-items: start center; padding: 22px; background-color: #343934; background-image: radial-gradient(rgba(255,255,255,.08) 1px, transparent 1px); background-size: 16px 16px; }
.canvas-stage canvas { display: block; max-width: none; background: white; box-shadow: 0 10px 28px rgba(0,0,0,.28); }
.canvas-loading { position: absolute; z-index: 2; top: 50%; left: 50%; display: flex; align-items: center; gap: 9px; padding: 9px 13px; border-radius: 99px; color: white; background: rgba(25,31,27,.82); transform: translate(-50%,-50%); font-size: 11px; }
.canvas-loading[hidden] { display: none; }
.canvas-loading span { width: 13px; height: 13px; border: 2px solid rgba(255,255,255,.35); border-top-color: white; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.transcription-scroll { flex: 1; min-height: 0; overflow: auto; padding: 27px clamp(22px, 4vw, 54px) 48px; }
.markdown { font-family: Georgia, "Times New Roman", serif; font-size: 15px; line-height: 1.63; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 { color: #1f352d; line-height: 1.25; }
.markdown h1 { font-size: 28px; }
.markdown h2 { margin-top: 28px; font-size: 23px; }
.markdown h3 { margin: 24px 0 10px; font-size: 18px; }
.markdown p { margin: 0 0 13px; }
.markdown ul, .markdown ol { margin: 8px 0 17px; padding-left: 22px; }
.markdown li { margin-bottom: 6px; padding-left: 3px; }
.markdown blockquote { margin: 17px 0; padding: 4px 0 4px 18px; border-left: 3px solid var(--gold); color: #4f5a54; }
.markdown blockquote p { margin: 5px 0; }
.markdown code { padding: 1px 4px; border-radius: 3px; color: #4f4430; background: #f1eadc; font: .88em Consolas, monospace; }
.markdown hr { height: 1px; margin: 24px 0; border: 0; background: var(--line); }
.markdown table { width: 100%; border-collapse: collapse; margin: 18px 0; font-family: Inter, sans-serif; font-size: 12px; }
.markdown th, .markdown td { padding: 8px; border: 1px solid var(--line); text-align: left; vertical-align: top; }
.markdown th { background: #f0ede5; }
.uncertain { padding: 1px 2px; border-radius: 2px; color: #85542f; background: #f6e4c1; }
.search-highlight { padding: 1px 2px; border-radius: 2px; color: inherit; background: #ffe178; }
.review-card { margin-top: 36px; padding: 20px; border: 1px solid var(--line); border-radius: 12px; background: #f9f7f1; font-family: Inter, sans-serif; }
.review-card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.review-card h3 { margin: 0; font-family: Georgia, serif; font-size: 17px; font-weight: 500; }
.review-card-head span { color: var(--muted); font-size: 9px; }
.review-actions { display: flex; gap: 8px; margin: 15px 0; }
.review-actions button { flex: 1; padding: 9px; border: 1px solid var(--line); border-radius: 7px; background: white; cursor: pointer; font-size: 11px; }
.review-actions button span { margin-right: 4px; font-weight: 800; }
.review-actions button[data-review-status="verified"].active { border-color: #6e927b; color: #315c45; background: var(--green-soft); }
.review-actions button[data-review-status="issue"].active { border-color: #c07b6d; color: #80382d; background: var(--red-soft); }
.note-label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 10px; font-weight: 700; }
.review-card textarea { width: 100%; resize: vertical; padding: 10px; border: 1px solid var(--line); border-radius: 7px; outline: 0; color: var(--ink); background: white; font-size: 12px; line-height: 1.45; }
.review-card textarea:focus { border-color: #82978d; box-shadow: 0 0 0 3px rgba(53,82,71,.1); }
.saved-message { height: 13px; margin: 7px 0 0!important; color: #698072; font: 9px Inter, sans-serif; text-align: right; }

.scroll-view { padding: 26px; }
.scroll-row { max-width: 1500px; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(390px, .95fr); gap: 1px; margin: 0 auto 25px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--line); box-shadow: 0 5px 18px rgba(31,42,36,.06); scroll-margin-top: 145px; }
.scroll-row.current { outline: 3px solid rgba(197,154,82,.5); outline-offset: 2px; }
.scroll-source, .scroll-copy { min-width: 0; background: var(--sheet); }
.scroll-label { height: 45px; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; }
.scroll-label b { color: var(--forest); font-size: 12px; }
.scroll-canvas-wrap { min-height: 540px; display: grid; place-items: center; overflow: auto; padding: 18px; background: #3a3e3a; }
.scroll-canvas-wrap canvas { max-width: 100%; height: auto; background: white; box-shadow: 0 5px 18px rgba(0,0,0,.25); }
.scroll-placeholder { color: rgba(255,255,255,.65); font-size: 11px; }
.scroll-copy .markdown { max-height: 760px; overflow: auto; padding: 24px 30px 38px; }

dialog { width: min(760px, calc(100% - 32px)); max-height: min(820px, calc(100vh - 32px)); overflow: auto; padding: 34px; border: 0; border-radius: 16px; color: var(--ink); background: var(--sheet); box-shadow: 0 25px 80px rgba(16,27,22,.35); }
dialog::backdrop { background: rgba(25,35,30,.72); backdrop-filter: blur(3px); }
.dialog-close { position: absolute; top: 13px; right: 13px; width: 34px; height: 34px; border: 0; border-radius: 50%; color: var(--muted); background: #f0ede6; cursor: pointer; font-size: 22px; }
dialog h2 { margin: 0; padding-right: 28px; font-family: Georgia, serif; font-size: 27px; font-weight: 500; }
.dialog-lead { margin: 10px 0 20px; color: var(--muted); line-height: 1.5; }
.about-copy { max-height: 320px; overflow: auto; padding: 18px; border: 1px solid var(--line); border-radius: 10px; background: #faf8f2; font-size: 13px; }
.about-copy h1 { display: none; }
.download-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 18px; }
.download-card { display: flex; flex-direction: column; gap: 4px; min-height: 82px; padding: 13px; border: 1px solid var(--line); border-radius: 9px; color: var(--forest); background: white; text-decoration: none; }
.download-card:hover { border-color: #91a399; box-shadow: 0 4px 13px rgba(30,42,36,.08); }
.download-card b { font-size: 11px; }
.download-card span { color: var(--muted); font-size: 9px; line-height: 1.35; }
.toast { position: fixed; z-index: 90; right: 20px; bottom: 20px; max-width: 360px; padding: 11px 15px; border-radius: 8px; color: white; background: var(--forest); box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s ease; font-size: 11px; }
.toast.show { opacity: 1; transform: none; }
.sidebar-scrim { display: none; }

@media (max-width: 1080px) {
  :root { --sidebar: 250px; }
  .brand { min-width: calc(var(--sidebar) - 22px); }
  .document-tab { max-width: 180px; padding-inline: 9px; font-size: 11px; }
  .page-view, .scroll-row { grid-template-columns: 1fr 1fr; }
  .transcription-scroll { padding-inline: 25px; }
}

@media (max-width: 820px) {
  .masthead { height: 64px; padding: 0 12px; }
  .brand { min-width: 0; }
  .brand small { display: none; }
  .brand b { font-size: 15px; }
  .brand-mark { width: 34px; height: 34px; }
  .document-tabs { flex: 1; justify-content: flex-end; overflow-x: auto; }
  .document-tab { flex: 0 0 auto; max-width: 160px; padding: 8px; font-size: 10px; }
  .mobile-sidebar-button { display: inline-grid; }
  .sidebar { top: 0; z-index: 70; width: min(320px, calc(100vw - 48px)); transform: translateX(-105%); transition: transform .22s ease; box-shadow: 10px 0 35px rgba(19,31,26,.2); }
  .sidebar.open { transform: none; }
  .close-sidebar { display: inline-grid; }
  .sidebar-scrim { position: fixed; z-index: 60; inset: 0; background: rgba(22,31,27,.55); }
  .sidebar-scrim.show { display: block; }
  .main { margin-left: 0; }
  .app-shell { padding-top: 64px; }
  .toolbar { top: 64px; height: auto; min-height: 55px; padding: 8px 12px; }
  .page-view { height: auto; min-height: calc(100vh - 158px); grid-template-columns: 1fr; }
  .source-panel { min-height: 70vh; }
  .transcription-panel { min-height: 70vh; }
  .canvas-stage { min-height: calc(70vh - 63px); }
  .scroll-row { grid-template-columns: 1fr; }
  .scroll-copy .markdown { max-height: none; }
}

@media (max-width: 600px) {
  .brand span:last-child { display: none; }
  .document-tabs { justify-content: flex-start; }
  .document-tab { max-width: 132px; }
  .toolbar { align-items: center; }
  .view-controls .divider, .zoom-label, #rotatePage, #zoomOut, #zoomIn { display: none; }
  .segmented button { padding-inline: 7px; font-size: 9px; }
  .page-field { font-size: 0; }
  .page-field input, .page-field span { font-size: 10px; }
  .scope-banner { padding-inline: 13px; }
  .scroll-view { padding: 14px 8px; }
  .scroll-canvas-wrap { min-height: 420px; }
  .download-grid { grid-template-columns: 1fr; }
  dialog { padding: 28px 20px; }
}

@media print {
  .masthead, .sidebar, .toolbar, .scope-banner, .source-panel, .review-card { display: none!important; }
  .main { margin: 0; }
  .page-view { display: block; height: auto; }
  .transcription-scroll { overflow: visible; }
}
