/* Verbatim — palette taken from conservation materials:
   archival board (background), iron-gall ink (text), bookcloth (actions),
   a dark copy-stand surface for scans, and a violet editing pencil for human corrections. */

@font-face { font-family: "Hyperlegible"; font-weight: 400; font-style: normal; font-display: swap;
  src: url(fonts/atkinson-hyperlegible-latin-400-normal.woff2) format("woff2");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: "Hyperlegible"; font-weight: 400; font-style: normal; font-display: swap;
  src: url(fonts/atkinson-hyperlegible-latin-ext-400-normal.woff2) format("woff2");
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family: "Hyperlegible"; font-weight: 700; font-style: normal; font-display: swap;
  src: url(fonts/atkinson-hyperlegible-latin-700-normal.woff2) format("woff2");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: "Hyperlegible"; font-weight: 700; font-style: normal; font-display: swap;
  src: url(fonts/atkinson-hyperlegible-latin-ext-700-normal.woff2) format("woff2");
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family: "Hyperlegible"; font-weight: 400; font-style: italic; font-display: swap;
  src: url(fonts/atkinson-hyperlegible-latin-400-italic.woff2) format("woff2");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+2000-206F,U+FEFF,U+FFFD; }
@font-face { font-family: "Hyperlegible"; font-weight: 400; font-style: italic; font-display: swap;
  src: url(fonts/atkinson-hyperlegible-latin-ext-400-italic.woff2) format("woff2");
  unicode-range: U+0100-02BA,U+1E00-1E9F,U+A720-A7FF; }
@font-face { font-family: "Hyperlegible Mono"; font-weight: 400; font-style: normal; font-display: swap;
  src: url(fonts/atkinson-hyperlegible-mono-latin-400-normal.woff2) format("woff2");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+2000-206F,U+FEFF,U+FFFD; }
@font-face { font-family: "Hyperlegible Mono"; font-weight: 400; font-style: normal; font-display: swap;
  src: url(fonts/atkinson-hyperlegible-mono-latin-ext-400-normal.woff2) format("woff2");
  unicode-range: U+0100-02BA,U+1E00-1E9F,U+A720-A7FF; }

:root {
  --board: #E4E8E6;
  --sheet: #FBFCFB;
  --ink: #1D2836;
  --graphite: #59626C;
  --rule: #C9D0CD;
  --rule-soft: #DCE1DF;
  --table: #2A2F33;
  --table-ink: #C9D1D6;
  --bookcloth: #2E5B4F;
  --bookcloth-ink: #F4F8F6;
  --bookcloth-soft: #D7E5DF;
  --pencil: #6A4C9C;
  --pencil-soft: #ECE5F6;
  --amber: #8A5E0C;
  --amber-soft: #F6EBD3;
  --rust: #9E3A2C;
  --rust-soft: #F6DED9;
  --focus: #2F6FB3;
  --font: "Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --mono: "Hyperlegible Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --r-ctl: 6px;
  --r-dlg: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --board: #161A1D; --sheet: #1D2226; --ink: #E2E8E5; --graphite: #9CA6AD; --rule: #333C42; --rule-soft: #283035;
    --table: #0E1113; --table-ink: #AAB4BA; --bookcloth: #78B4A0; --bookcloth-ink: #0D1714; --bookcloth-soft: #22352F;
    --pencil: #B9A0E6; --pencil-soft: #2E2640; --amber: #DDA94A; --amber-soft: #3A2E15; --rust: #E58876;
    --rust-soft: #3D211C; --focus: #7DB3F0;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.45 var(--font);
  color: var(--ink);
  background: var(--board);
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
code { font-family: var(--mono); font-size: .92em; }
a { color: inherit; }

/* ---- controls ------------------------------------------------------------------------- */
.btn {
  font: inherit; font-size: 14px; line-height: 1; color: var(--ink);
  background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--r-ctl);
  padding: 9px 13px; cursor: pointer; white-space: nowrap; text-decoration: none; display: inline-flex;
  align-items: center; gap: 6px; min-height: 36px;
}
.btn:hover { border-color: var(--graphite); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--bookcloth); color: var(--bookcloth-ink); border-color: var(--bookcloth); font-weight: 700; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger-quiet { color: var(--rust); }
.btn.small { font-size: 13px; padding: 6px 10px; min-height: 30px; }
.btn.wide { width: 100%; justify-content: center; }
.btn.dark { background: rgba(255,255,255,.08); color: var(--table-ink); border-color: rgba(255,255,255,.16); }
.icon-btn {
  font: inherit; font-size: 18px; line-height: 1; background: none; border: 1px solid transparent; color: inherit;
  border-radius: var(--r-ctl); width: 36px; height: 36px; display: inline-grid; place-items: center; cursor: pointer;
}
.icon-btn svg { fill: currentColor; }
.icon-btn:hover { border-color: var(--rule); }
.icon-btn:disabled { opacity: .4; cursor: default; }
.icon-btn.dark { color: var(--table-ink); background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.16); width: 30px; height: 30px; }

input, textarea, select {
  font: inherit; color: var(--ink); background: var(--sheet); border: 1px solid var(--rule);
  border-radius: var(--r-ctl); padding: 8px 10px; width: 100%;
}
textarea { resize: vertical; }
label { display: block; font-size: 14px; color: var(--graphite); }
label > input, label > textarea { margin-top: 4px; color: var(--ink); }
.check { display: flex; align-items: center; gap: 8px; color: var(--ink); cursor: pointer; }
.check input { width: auto; margin: 0; accent-color: var(--bookcloth); }
.check.small { font-size: 13px; color: var(--graphite); }
.hint { font-size: 13px; color: var(--graphite); margin: 4px 0 0; }
.form-error { color: var(--rust); background: var(--rust-soft); border-radius: var(--r-ctl); padding: 8px 10px; font-size: 14px; }

/* ---- login ---------------------------------------------------------------------------- */
.login-body { display: grid; place-items: center; min-height: 100%; padding: 24px 16px; }
.login { width: 100%; max-width: 360px; }
.login h1 { font-size: 34px; letter-spacing: -.01em; margin-top: 12px; }
.login-sub { color: var(--graphite); margin: 6px 0 28px; }
.login form { display: grid; gap: 6px; }
.login form label[for] { margin-top: 10px; }
.login .check { margin-top: 14px; }
.login .btn { margin-top: 18px; min-height: 44px; font-size: 15px; }

/* ---- top bar -------------------------------------------------------------------------- */
.topbar {
  height: 56px; display: flex; align-items: center; gap: 10px; padding: 0 12px;
  border-bottom: 1px solid var(--rule); background: var(--board);
}
.collection-btn {
  font: inherit; font-weight: 700; font-size: 17px; color: var(--ink); background: none; border: 1px solid transparent;
  border-radius: var(--r-ctl); padding: 6px 8px; display: flex; align-items: center; gap: 6px; cursor: pointer;
  min-width: 0; max-width: 360px;
}
.collection-btn:hover { border-color: var(--rule); }
.collection-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.topbar-end { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.activity { font-size: 13px; color: var(--amber); white-space: nowrap; }
.user-btn {
  font: inherit; font-size: 14px; background: var(--sheet); color: var(--ink); border: 1px solid var(--rule);
  border-radius: 999px; padding: 6px 14px; cursor: pointer;
}
.menu-wrap { position: relative; }
.menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30; min-width: 260px; padding: 6px;
  background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--r-dlg);
  box-shadow: 0 10px 30px rgba(20, 30, 40, .18);
}
.menu.right { left: auto; right: 0; }
.menu a { display: block; padding: 9px 10px; border-radius: var(--r-ctl); cursor: pointer; text-decoration: none; font-size: 14px; }
.menu a:hover, .menu a:focus-visible { background: var(--board); }
.menu a.danger { color: var(--rust); }
.menu a[aria-disabled="true"] { opacity: .45; pointer-events: none; }

/* ---- workspace ------------------------------------------------------------------------ */
.workspace {
  height: calc(100% - 56px);
  display: grid; grid-template-columns: 270px minmax(0, 1fr) minmax(360px, 42%);
}
.only-narrow { display: none !important; }
.only-touch { display: none !important; }
@media (pointer: coarse) { .only-touch { display: inline-flex !important; } }

/* rail */
.rail { border-right: 1px solid var(--rule); display: flex; flex-direction: column; min-height: 0; background: var(--board); }
.rail-head { padding: 10px 12px; font-size: 13px; color: var(--graphite); display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; min-height: 48px; }
.rail-sel { display: flex; gap: 6px; }
.uploads { padding: 0 12px 10px; font-size: 13px; }
.bar { height: 4px; background: var(--rule-soft); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--bookcloth); transition: width .2s; }
.pages { list-style: none; margin: 0; padding: 0 8px 16px; overflow-y: auto; flex: 1; outline: none; }
.page {
  display: grid; grid-template-columns: 52px 1fr; gap: 10px; align-items: center; padding: 7px 8px 7px 10px;
  border-radius: var(--r-ctl); cursor: pointer; position: relative; user-select: none;
  border-left: 3px solid transparent;
}
.page:hover { background: var(--rule-soft); }
.page.selected { background: var(--sheet); box-shadow: inset 0 0 0 1px var(--rule); }
.page.current { background: var(--sheet); box-shadow: inset 0 0 0 2px var(--bookcloth); }
.page img { width: 52px; height: 64px; object-fit: cover; object-position: top; border-radius: 3px; background: var(--table); display: block; }
.page-label { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-state { font-size: 12.5px; color: var(--graphite); }
/* state is encoded in the left edge, so it can be scanned down the list */
.page[data-state="queued"], .page[data-state="running"] { border-left-color: var(--amber); }
.page[data-state="queued"] .page-state, .page[data-state="running"] .page-state { color: var(--amber); }
.page[data-state="error"] { border-left-color: var(--rust); }
.page[data-state="error"] .page-state { color: var(--rust); }
.page[data-state="done"] { border-left-color: var(--bookcloth); }
.page[data-edited="1"] { border-left-color: var(--pencil); }
.page[data-edited="1"] .page-state { color: var(--pencil); }
.rail-empty { padding: 24px 16px; text-align: center; color: var(--graphite); }
.rail-empty .btn { margin: 4px auto 10px; }

/* light table */
.table { background: var(--table); position: relative; min-width: 0; min-height: 0; overflow: hidden; }
.viewport { position: absolute; inset: 0; overflow: hidden; touch-action: none; cursor: grab; }
.viewport.dragging { cursor: grabbing; }
#page-img { position: absolute; left: 0; top: 0; transform-origin: 0 0; user-select: none; -webkit-user-drag: none;
  box-shadow: 0 6px 30px rgba(0,0,0,.45); image-rendering: auto; max-width: none; }
.table-empty { color: var(--table-ink); position: absolute; inset: 0; display: grid; place-items: center; font-size: 15px; padding: 16px; text-align: center; }
.zoom { position: absolute; left: 12px; bottom: 12px; display: flex; gap: 6px; align-items: center; }
.zoom-level { color: var(--table-ink); font-size: 12.5px; min-width: 44px; padding-left: 4px; }

/* transcription sheet */
.sheet { background: var(--sheet); display: flex; flex-direction: column; min-width: 0; min-height: 0; border-left: 1px solid var(--rule); }
.sheet-head { display: flex; gap: 10px; align-items: flex-start; padding: 14px 16px 8px; }
.sheet-title { min-width: 0; flex: 1; }
.sheet-title h2 { font-size: 19px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta { margin: 3px 0 0; font-size: 13px; color: var(--graphite); }
.meta .edited { color: var(--pencil); }
.sheet-actions { display: flex; gap: 6px; align-items: center; }
.note { margin: 0 16px 8px; padding: 8px 10px; font-size: 13.5px; border-radius: var(--r-ctl); background: var(--amber-soft); color: var(--amber); }
.note.error { background: var(--rust-soft); color: var(--rust); }
.conflict { margin: 0 16px 8px; padding: 10px; border-radius: var(--r-ctl); background: var(--amber-soft); font-size: 14px; display: grid; gap: 8px; }
.conflict p { margin: 0; }
.conflict div { display: flex; gap: 8px; }

.tabs { display: flex; gap: 2px; padding: 0 12px; border-bottom: 1px solid var(--rule-soft); }
.tabs [role="tab"] {
  font: inherit; font-size: 14px; color: var(--graphite); background: none; border: 0; border-bottom: 2px solid transparent;
  padding: 9px 8px 8px; cursor: pointer; margin-bottom: -1px;
}
.tabs [role="tab"][aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); font-weight: 700; }
#changes-count { color: var(--pencil); font-weight: 700; }
.panel { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: auto; }
#editor {
  flex: 1; border: 0; border-radius: 0; resize: none; padding: 16px 18px 24px; background: var(--sheet);
  font-size: 17px; line-height: 1.65; tab-size: 4; outline: none;
}
#editor.mono { font-family: var(--mono); font-size: 15.5px; }
#editor.nowrap { white-space: pre; overflow-wrap: normal; overflow-x: auto; }
#editor:disabled { color: var(--graphite); }
#editor:focus-visible { box-shadow: inset 0 0 0 2px var(--focus); }
.legend { font-size: 13px; color: var(--graphite); margin: 12px 18px 0; }
.diff { white-space: pre-wrap; overflow-wrap: anywhere; font-family: var(--font); font-size: 16.5px; line-height: 1.65; margin: 0; padding: 12px 18px 24px; }
ins { text-decoration: none; color: var(--pencil); background: var(--pencil-soft); border-bottom: 2px solid var(--pencil); border-radius: 2px; }
del { color: var(--graphite); text-decoration: line-through; text-decoration-thickness: 1.5px; }
.diff-empty { color: var(--graphite); font-family: var(--font); font-size: 14px; }
.history { list-style: none; margin: 0; padding: 8px 12px 16px; }
.history li { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 9px 8px; border-bottom: 1px solid var(--rule-soft); cursor: pointer; border-radius: var(--r-ctl); }
.history li:hover { background: var(--board); }
.history .h-what { font-size: 14px; }
.history .h-when { font-size: 13px; color: var(--graphite); text-align: right; }
.history .h-kind-edit .h-what, .history .h-kind-restore .h-what { color: var(--pencil); }
.history .h-current { font-size: 12.5px; color: var(--graphite); grid-column: 1 / -1; }
.rev-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 18px 0; }
.rev-head strong { margin-right: auto; }
.sheet-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; padding: 8px 16px; border-top: 1px solid var(--rule-soft); font-size: 13px; color: var(--graphite); }
.save-state { min-width: 120px; }
.save-state.bad { color: var(--rust); }
.counts { margin-right: auto; }

/* drop overlay, toast */
.drop-overlay { position: fixed; inset: 0; z-index: 50; background: rgba(46, 91, 79, .18); border: 3px dashed var(--bookcloth); display: grid; place-items: center; pointer-events: none; }
.drop-overlay p { background: var(--sheet); padding: 14px 22px; border-radius: var(--r-dlg); font-size: 18px; font-weight: 700; }
.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 60; background: var(--ink); color: var(--sheet);
  padding: 10px 16px; border-radius: var(--r-ctl); font-size: 14px; max-width: min(560px, calc(100% - 32px)); box-shadow: 0 8px 24px rgba(0,0,0,.25); }

/* dialogs */
.dlg { border: 1px solid var(--rule); border-radius: var(--r-dlg); padding: 18px 20px 20px; background: var(--sheet); color: var(--ink);
  width: min(560px, calc(100% - 24px)); max-height: calc(100% - 40px); overflow: auto; box-shadow: 0 20px 60px rgba(10, 20, 30, .3); }
.dlg.small { width: min(420px, calc(100% - 24px)); }
.dlg.wide { width: min(860px, calc(100% - 24px)); }
.dlg::backdrop { background: rgba(20, 28, 36, .45); }
.dlg h2 { font-size: 20px; }
.dlg h3 { font-size: 16px; margin: 18px 0 8px; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.dlg form label { margin-top: 10px; }
#confirm-text { white-space: pre-line; color: var(--graphite); }
.inline-form { display: flex; gap: 8px; margin-bottom: 12px; }
.collections { list-style: none; margin: 0; padding: 0; max-height: 60vh; overflow: auto; }
.collections li { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 11px 10px; border-radius: var(--r-ctl); cursor: pointer; border-bottom: 1px solid var(--rule-soft); }
.collections li:hover, .collections li.current { background: var(--board); }
.collections .c-name { font-weight: 700; }
.collections .c-stats { font-size: 13px; color: var(--graphite); grid-column: 1; }
.collections .c-actions { grid-row: 1 / 3; grid-column: 2; display: flex; gap: 4px; align-items: center; }
.collections .c-empty { cursor: default; color: var(--graphite); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 14px; }
.grid2 .check { align-self: end; padding-bottom: 8px; }
.users { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 8px; }
.users th { text-align: left; font-weight: 400; color: var(--graphite); font-size: 13px; padding: 6px 8px; border-bottom: 1px solid var(--rule); }
.users td { padding: 8px; border-bottom: 1px solid var(--rule-soft); vertical-align: middle; }
.users td:last-child { text-align: right; white-space: nowrap; }
.users .disabled td:first-child { color: var(--graphite); text-decoration: line-through; }
.new-user { border-top: 1px solid var(--rule); margin-top: 18px; }
.new-user .btn { margin-top: 12px; }
#apanel-server textarea { font-family: var(--mono); font-size: 13px; }
.check-result { white-space: pre-line; padding: 8px 10px; border-radius: var(--r-ctl); background: var(--bookcloth-soft); font-size: 14px; }
.check-result.bad { background: var(--rust-soft); color: var(--rust); }

/* ---- narrow screens: phones, small tablets -------------------------------------------- */
@media (max-width: 900px) {
  .only-narrow { display: flex !important; }
  .topbar { gap: 4px; padding: 0 6px; height: auto; min-height: 56px; flex-wrap: wrap; }
  .topbar-actions { order: 3; width: 100%; flex-wrap: wrap; padding: 0 2px 8px; gap: 6px; }
  .topbar-actions .btn { padding: 8px 10px; }
  .collection-btn { max-width: calc(100vw - 150px); font-size: 16px; }
  .activity { display: none; }
  body { display: flex; flex-direction: column; height: 100dvh; }
  .workspace { flex: 1; min-height: 0; height: auto; display: flex; flex-direction: column; }
  .rail { position: fixed; z-index: 40; top: 0; bottom: 0; left: 0; width: min(320px, 86vw); box-shadow: 0 0 40px rgba(0,0,0,.3);
    transform: translateX(-105%); transition: transform .2s ease; padding-top: env(safe-area-inset-top); }
  .rail.open { transform: none; }
  .seg { display: flex; gap: 0; margin: 8px 12px; border: 1px solid var(--rule); border-radius: var(--r-ctl); overflow: hidden; }
  .seg button { flex: 1; font: inherit; font-size: 14px; padding: 9px; background: var(--sheet); color: var(--graphite); border: 0; cursor: pointer; }
  .seg button[aria-selected="true"] { background: var(--ink); color: var(--sheet); font-weight: 700; }
  .table, .sheet { flex: 1; min-height: 0; height: auto; border-left: 0; }
  body[data-view="page"] .sheet { display: none; }
  body[data-view="text"] .table { display: none; }
  .grid2 { grid-template-columns: 1fr; }
  .menu { min-width: 230px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
