:root {
  color-scheme: light;
  --bg: #f3f4ef;
  --panel: #ffffff;
  --panel-soft: #f8f8f4;
  --ink: #18211b;
  --muted: #697067;
  --line: #d8ddd1;
  --accent: #1f6f64;
  --accent-ink: #ffffff;
  --code: #101915;
  --shadow: 0 12px 30px rgba(30, 42, 32, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 74px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.eyebrow,
.page-kicker {
  margin: 0 0 3px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

.app-header h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-filter {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.section-filter select,
.filter-box input,
button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--ink);
}

.section-filter select {
  min-width: 72px;
  padding: 7px 8px;
}

button {
  min-height: 34px;
  padding: 7px 12px;
  cursor: pointer;
}

button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

.manual-workspace {
  display: grid;
  grid-template-columns: minmax(240px, 310px) minmax(0, 1fr) minmax(300px, 36vw);
  height: calc(100vh - 74px);
  min-height: 560px;
}

.manual-sidebar,
.reader-shell,
.source-panel {
  min-height: 0;
  overflow: auto;
}

.manual-sidebar {
  border-right: 1px solid var(--line);
  background: var(--panel-soft);
  padding: 16px;
}

.filter-box {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.filter-box input {
  width: 100%;
  padding: 9px 10px;
  background: var(--panel);
}

.page-count {
  margin: 12px 0;
  color: var(--muted);
  font-size: 12px;
}

.page-list {
  display: grid;
  gap: 5px;
}

.page-link {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px 10px;
  width: 100%;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.page-link:hover,
.page-link.active {
  border-color: var(--line);
  background: var(--panel);
}

.page-link.active {
  border-color: rgba(31, 111, 100, 0.45);
}

.page-link strong {
  overflow: hidden;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-link span {
  color: var(--muted);
  font-size: 12px;
}

.page-link small {
  grid-column: 1 / -1;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-shell {
  padding: 20px clamp(18px, 3vw, 42px) 40px;
}

.reader-toolbar {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin: -20px calc(clamp(18px, 3vw, 42px) * -1) 18px;
  padding: 18px clamp(18px, 3vw, 42px) 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(243, 244, 239, 0.95);
  backdrop-filter: blur(10px);
}

.reader-toolbar h2 {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(25px, 4vw, 42px);
  line-height: 1;
  text-transform: lowercase;
}

.page-summary {
  max-width: 760px;
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.35;
}

.status-badge {
  flex: 0 0 auto;
  display: inline-grid;
  min-width: 68px;
  min-height: 28px;
  place-items: center;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.status-badge.error {
  border-color: #b8423a;
  color: #9e2f28;
}

.manual-preview {
  max-width: 900px;
  margin: 0 auto;
}

.render-sheet {
  width: min(100%, var(--page-width, 210mm));
  aspect-ratio: auto;
  min-height: auto;
  margin: 0 auto 18px;
  padding: 0;
  background: transparent;
  box-shadow: none;
}

.sheet-header,
.sheet-footer {
  display: none;
}

.sheet-body {
  min-height: auto;
}

.role-block p,
.role-block h1,
.role-block h2,
.role-block ul,
.role-block ol,
.role-block pre,
.role-block blockquote,
.role-block table {
  margin: 0;
}

.role-block ul,
.role-block ol {
  padding-left: 0;
}

.role-block a,
.source-header span {
  color: var(--accent);
}

.source-panel {
  border-left: 1px solid var(--line);
  background: #151c18;
  color: #e8eee4;
}

.source-panel[hidden] {
  display: none;
}

.source-header {
  position: sticky;
  top: 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  background: #151c18;
}

.source-header h2 {
  margin: 0;
  font-size: 15px;
}

.source-header span {
  overflow: hidden;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-panel pre {
  margin: 0;
  padding: 16px;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.48;
  white-space: pre-wrap;
}

body:not(.show-source) .manual-workspace {
  grid-template-columns: minmax(240px, 310px) minmax(0, 1fr) 0;
}

body:not(.show-source) .source-panel {
  display: none;
}

.diagnostics {
  padding: 16px;
  border: 1px solid #deb1ad;
  border-radius: 6px;
  background: #fff1ef;
  color: #8d2f27;
}

@media (max-width: 980px) {
  .manual-workspace,
  body:not(.show-source) .manual-workspace {
    grid-template-columns: 1fr;
    height: auto;
  }

  .manual-sidebar,
  .source-panel {
    max-height: 42vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .reader-shell {
    min-height: 70vh;
  }
}

@media (max-width: 640px) {
  .app-header,
  .reader-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .header-actions {
    justify-content: space-between;
  }
}
