/* Akshara Proofing — Editorial Broadsheet Design System
 * Zero inline styles needed; works under strict CSP (style-src 'self').
 */

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url('/fonts/inter-normal-400-600-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url('/fonts/inter-normal-400-600-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+20AC, U+2122, U+2212;
}
@font-face {
  font-family: 'Newsreader';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('/fonts/newsreader-normal-400-700-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1E9F, U+1EF2-1EFF;
}
@font-face {
  font-family: 'Newsreader';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('/fonts/newsreader-normal-400-700-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+20AC, U+2122, U+2212;
}
@font-face {
  font-family: 'Newsreader';
  font-style: italic;
  font-weight: 400 700;
  font-display: swap;
  src: url('/fonts/newsreader-italic-400-700-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+20AC, U+2122, U+2212;
}
@font-face {
  font-family: 'Source Serif 4';
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url('/fonts/source-serif-4-normal-greek.woff2') format('woff2');
  unicode-range: U+0370-03FF;
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 400 500;
  font-display: swap;
  src: url('/fonts/jetbrains-mono-normal-400-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+1E00-1E9F;
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 400 500;
  font-display: swap;
  src: url('/fonts/jetbrains-mono-normal-400-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+2000-206F;
}

:root {
  --bg: #FCFBF8;
  --bg-alt: #F4F1EA;
  --surface: #FFFFFF;
  --ink: #111110;
  --ink-2: #2C2B28;
  --muted: #5C5953;
  --faint: #848078;
  --rule: #E2DDD3;
  --rule-strong: #1A1917;
  --accent: #B8321A;
  --accent-blue: #16358F;
  --verified: #1E6B47;
  --proofread: #9E6B24;
  --problem: #A12312;
  --machine: #4A5568;
  --font-serif: 'Newsreader', 'Source Serif 4', Georgia, serif;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

body.mode-night {
  --bg: #111113;
  --bg-alt: #18181B;
  --surface: #1E1E22;
  --ink: #F2EFE9;
  --ink-2: #D8D4CC;
  --muted: #A19D94;
  --faint: #75726B;
  --rule: #2D2D32;
  --rule-strong: #F2EFE9;
  --accent: #E26249;
  --accent-blue: #7CA4FF;
  --verified: #4ADE80;
  --proofread: #FBBF24;
  --problem: #F87171;
  --machine: #94A3B8;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { background: var(--bg); color: var(--ink); font-family: var(--font-sans); line-height: 1.55; min-height: 100vh; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }

/* Masthead & Mode Bar */
.top-strip {
  background: var(--bg-alt);
  border-bottom: 1px solid var(--rule);
  padding: 6px 24px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}
.role-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.role-pill {
  padding: 3px 9px;
  border: 1px solid var(--rule);
  background: var(--surface);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.role-pill.is-active {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}
.masthead {
  background: var(--bg);
  border-bottom: 1.5px solid var(--rule-strong);
  position: sticky;
  top: 0;
  z-index: 50;
}
.masthead-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.brand-group { display: flex; align-items: baseline; gap: 10px; cursor: pointer; }
.brand-title { font-family: var(--font-serif); font-size: 25px; font-weight: 600; letter-spacing: -0.02em; }
.brand-sub { font-family: var(--font-mono); font-size: 11px; color: var(--accent); letter-spacing: 0.08em; text-transform: uppercase; }
.nav-tabs { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.nav-btn {
  padding: 7px 13px;
  border: 1px solid var(--rule);
  background: var(--surface);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.nav-btn:hover { border-color: var(--ink); }
.nav-btn.is-active { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.wrap { max-width: 1440px; margin: 0 auto; padding: 28px 24px 64px; }
.kicker { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); display: block; margin-bottom: 6px; }
.h1-serif { font-family: var(--font-serif); font-size: clamp(28px, 3.6vw, 44px); font-weight: 500; line-height: 1.1; letter-spacing: -0.02em; }
.h2-serif { font-family: var(--font-serif); font-size: 26px; font-weight: 500; line-height: 1.2; }
.lead-copy { color: var(--muted); max-width: 72ch; margin-top: 10px; font-size: 15.5px; }

/* Read-only Banner & Alerts */
.banner-ro {
  background: #7F1D1D;
  color: #FEF2F2;
  padding: 10px 24px;
  font-family: var(--font-mono);
  font-size: 12px;
  text-align: center;
}
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 200;
  max-width: 440px;
  background: var(--ink);
  color: var(--bg);
  padding: 12px 16px;
  border-left: 4px solid var(--accent);
  font-size: 13.5px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.25);
}
.toast.is-err { border-left-color: #EF4444; }
.is-hidden { display: none !important; }

/* Badges */
.state-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 1px solid currentColor;
}
.state-machine { color: var(--machine); }
.state-proofread { color: var(--proofread); }
.state-verified { color: var(--verified); }
.state-problem { color: var(--problem); }

/* Stats Strip & Filter Bar */
.metrics-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-top: 1px solid var(--rule-strong);
  border-bottom: 1px solid var(--rule-strong);
  margin: 22px 0;
}
.metric-cell { padding: 14px 16px; border-right: 1px solid var(--rule); }
.metric-cell:last-child { border-right: none; }
.metric-label { font-family: var(--font-mono); font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.metric-val { font-family: var(--font-serif); font-size: 30px; font-weight: 600; margin-top: 2px; }

.toolbar-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.search-input {
  width: min(360px, 100%);
  padding: 8px 12px;
  border: 1px solid var(--rule-strong);
  background: var(--surface);
  font-size: 14px;
}
.btn-primary {
  padding: 8px 14px;
  background: var(--ink);
  color: var(--bg);
  border: 1px solid var(--ink);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.btn-primary:hover { background: var(--accent); border-color: var(--accent); color: #FFF; }
.btn-secondary {
  padding: 8px 13px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--rule-strong);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-verify { background: var(--verified); border-color: var(--verified); color: #FFF; }
.btn-verify:hover { filter: brightness(0.9); }
.btn-danger { border-color: var(--problem); color: var(--problem); }

/* Book Catalog Grid */
.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1px;
  background: var(--rule);
  border: 1px solid var(--rule-strong);
}
.book-card {
  background: var(--surface);
  padding: 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
}
.book-card-meta { display: flex; justify-content: space-between; font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.book-card-title { font-family: var(--font-serif); font-size: 20px; font-weight: 500; line-height: 1.25; cursor: pointer; }
.book-card-title:hover { color: var(--accent); }
.book-card-author { font-size: 13.5px; color: var(--muted); margin-top: 3px; }
.progress-meter { width: 100%; height: 6px; appearance: none; border: none; background: var(--bg-alt); }
.progress-meter::-webkit-progress-bar { background: var(--bg-alt); }
.progress-meter::-webkit-progress-value { background: var(--verified); }

/* Book Hub Layout */
.book-hub-grid {
  display: grid;
  grid-template-columns: 1.45fr 1fr;
  gap: 24px;
  margin-top: 20px;
}
.panel-box {
  background: var(--surface);
  border: 1px solid var(--rule-strong);
  padding: 18px;
  margin-bottom: 18px;
}
.panel-title { font-family: var(--font-mono); font-size: 11.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); border-bottom: 1px solid var(--rule); padding-bottom: 8px; margin-bottom: 12px; }
.page-pills {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: 6px;
}
.page-pill {
  padding: 6px 4px;
  border: 1px solid var(--rule);
  background: var(--bg);
  text-align: center;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11px;
}
.page-pill:hover { border-color: var(--ink); }
.page-pill.st-proofread { border-color: var(--proofread); background: rgba(158, 107, 36, 0.1); }
.page-pill.st-verified { border-color: var(--verified); background: rgba(30, 107, 71, 0.12); }
.page-pill.st-problem { border-color: var(--problem); background: rgba(161, 35, 18, 0.12); }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 3px 8px;
  border: 1px solid var(--rule);
  background: var(--bg-alt);
  font-family: var(--font-mono);
  font-size: 11.5px;
}

/* Side-by-Side Proofing Desk */
.desk-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--rule-strong);
  margin-bottom: 14px;
}
.desk-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}
.scan-pane, .editor-pane {
  background: var(--surface);
  border: 1px solid var(--rule-strong);
  display: flex;
  flex-direction: column;
}
.pane-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--rule);
  font-family: var(--font-mono);
  font-size: 11px;
}
.scan-viewport {
  position: relative;
  height: 700px;
  overflow: auto;
  background: #1B1B1E;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 14px;
}
.osd-canvas {
  width: 100%;
  height: 100%;
}
.scan-img {
  max-width: 100%;
  height: auto;
  background: #FAF5E8;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  transition: transform 0.15s ease;
}
.scan-img.zoom-100 { width: 92%; }
.scan-img.zoom-125 { width: 120%; max-width: none; }
.scan-img.zoom-150 { width: 150%; max-width: none; }
.scan-img.zoom-200 { width: 200%; max-width: none; }
.scan-img.rot-90 { transform: rotate(90deg); }
.scan-img.rot-180 { transform: rotate(180deg); }
.scan-img.rot-270 { transform: rotate(270deg); }
.scan-img.hi-contrast { filter: contrast(1.32) grayscale(0.25); }

.diacritic-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--rule);
  background: var(--bg);
}
.dia-btn {
  min-width: 28px;
  padding: 3px 6px;
  border: 1px solid var(--rule);
  background: var(--surface);
  cursor: pointer;
  font-family: var(--font-serif);
  font-size: 14px;
}
.dia-btn:hover { border-color: var(--accent); color: var(--accent); }
.markup-btn {
  padding: 3px 8px;
  border: 1px solid var(--rule-strong);
  background: var(--bg-alt);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11px;
}
.dp-editor {
  width: 100%;
  min-height: 520px;
  padding: 16px;
  border: 0;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.65;
  resize: vertical;
  outline: none;
}
.preview-box {
  min-height: 520px;
  max-height: 620px;
  overflow: auto;
  padding: 18px 20px;
  font-family: var(--font-serif);
  font-size: 18px;
  line-height: 1.7;
}
.preview-box p { margin-bottom: 1em; }
.preview-box .dp-sidenote {
  font-family: var(--font-sans);
  font-size: 12.5px;
  border-left: 3px solid var(--accent-blue);
  padding: 4px 10px;
  margin-bottom: 10px;
  background: var(--bg-alt);
}
.preview-box .dp-verse {
  font-style: italic;
  border-left: 2px solid var(--rule-strong);
  padding-left: 14px;
  white-space: pre-line;
  margin: 1em 0;
}
.preview-box .dp-illust {
  font-family: var(--font-mono);
  font-size: 12px;
  border: 1px dashed var(--rule-strong);
  padding: 8px 12px;
  margin: 1em 0;
  background: var(--bg-alt);
}
.preview-box .dp-footnote {
  font-size: 14.5px;
  color: var(--muted);
  border-top: 1px solid var(--rule);
  padding-top: 8px;
  margin-top: 12px;
}
.preview-box .dp-note {
  font-family: var(--font-mono);
  font-size: 11px;
  background: rgba(184, 50, 26, 0.12);
  color: var(--accent);
  padding: 1px 5px;
}
.preview-box .dp-unclear { border-bottom: 2px dotted var(--problem); }
.preview-box .dp-sc { font-variant: small-caps; letter-spacing: 0.04em; }
.preview-box table.dp-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-sans);
  font-size: 13px;
  margin: 1em 0;
  border: 1px solid var(--rule-strong);
}
.preview-box table.dp-table th,
.preview-box table.dp-table td {
  border: 1px solid var(--rule);
  padding: 6px 9px;
  text-align: left;
}
.preview-box table.dp-table th { background: var(--bg-alt); font-weight: 600; }

.diff-del { background: rgba(220, 38, 38, 0.16); text-decoration: line-through; padding: 0 2px; }
.diff-ins { background: rgba(22, 163, 74, 0.2); padding: 0 2px; font-weight: 500; }

.action-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px;
  background: var(--bg-alt);
  border-top: 1px solid var(--rule-strong);
}

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td { padding: 8px 10px; border-bottom: 1px solid var(--rule); text-align: left; }
.data-table th { font-family: var(--font-mono); font-size: 10.5px; text-transform: uppercase; color: var(--muted); }

/* Rulebook */
.rulebook-doc { max-width: 78ch; margin: 0 auto; background: var(--surface); border: 1px solid var(--rule-strong); padding: 34px 38px; font-family: var(--font-serif); font-size: 18px; line-height: 1.72; }
.rulebook-doc h2 { font-size: 23px; margin: 1.4em 0 0.5em; border-top: 1px solid var(--rule); padding-top: 12px; }
.rulebook-doc ul { margin-left: 1.4em; margin-bottom: 1em; }
.rulebook-doc li { margin-bottom: 0.45em; }

/* Dialogs */
.modal-dlg {
  margin: auto;
  width: min(560px, 94vw);
  background: var(--surface);
  color: var(--ink);
  border: 1.5px solid var(--ink);
  padding: 22px;
}
.modal-dlg::backdrop { background: rgba(0, 0, 0, 0.65); }
.field-label { display: block; font-family: var(--font-mono); font-size: 11px; text-transform: uppercase; color: var(--muted); margin-bottom: 5px; }
.field-ctrl { width: 100%; padding: 8px 10px; border: 1px solid var(--rule-strong); background: var(--bg); color: var(--ink); margin-bottom: 14px; }
.modal-error {
  border: 1px solid var(--problem);
  background: rgba(161, 35, 18, 0.08);
  color: var(--problem);
  padding: 8px 11px;
  font-size: 13px;
  margin-bottom: 12px;
}

.info-callout {
  background: var(--bg-alt);
  border-bottom: 1px solid var(--rule);
  padding: 10px 14px;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--ink-2);
}
.panel-box .info-callout {
  border: 1px solid var(--rule);
  margin-top: 10px;
}
.ln-link {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.ln-link:hover { color: var(--ink); }

.scan-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 12px;
  color: #E2DDD3;
  background: rgba(27, 27, 30, 0.72);
  pointer-events: none;
  z-index: 5;
}

.leaf-jump-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.leaf-jump-input {
  width: 110px;
  padding: 6px 10px;
  border: 1px solid var(--rule-strong);
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 12.5px;
}

.btn-primary:disabled,
.btn-secondary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.dp-editor[readonly] {
  background: var(--bg);
  color: var(--ink-2);
}

@media (max-width: 1024px) {
  .desk-split, .book-hub-grid { grid-template-columns: 1fr; }
  .metrics-row { grid-template-columns: repeat(2, 1fr); }
  .scan-viewport { height: 480px; }
}
