:root {
  --reader-font-size: 14px;
  --reader-font-family: Georgia, "Times New Roman", serif;
  --reader-width: 1180px;
  --reader-margin: 16px;
  --reader-line-height: 1.5;
  --paragraph-indent: 1.5cm;
  --bg: #f7f7f4;
  --paper: #ffffff;
  --surface: #f1f2ee;
  --ink: #242424;
  --muted: #686866;
  --border: #deded8;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --shadow: 0 18px 55px rgba(24, 24, 20, 0.12);
  --soft-shadow: 0 10px 30px rgba(24, 24, 20, 0.08);
}

body[data-theme="dark"] {
  --bg: #141517;
  --paper: #202226;
  --surface: #191b1f;
  --ink: #ededec;
  --muted: #aaa9a3;
  --border: #373a40;
  --accent: #7aa2ff;
  --accent-strong: #a9c1ff;
  --shadow: 0 18px 55px rgba(0, 0, 0, 0.34);
  --soft-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, color-mix(in srgb, var(--accent) 10%, transparent), transparent 28rem),
    var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.drawer-open {
  overflow: hidden;
}

a,
button,
input,
textarea,
select,
summary {
  outline-color: var(--accent);
  -webkit-tap-highlight-color: transparent;
}

.reading-progress {
  position: fixed;
  z-index: 20;
  top: 0;
  left: 0;
  width: 100%;
  height: 4px;
  background: transparent;
}

.reading-progress span {
  display: block;
  width: 0%;
  height: 100%;
  background: var(--accent);
  transition: width 100ms linear;
}

.focus-exit {
  position: fixed;
  z-index: 30;
  top: 14px;
  right: 14px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: var(--shadow);
  cursor: pointer;
}

.back-to-top {
  position: fixed;
  z-index: 19;
  right: 18px;
  bottom: 18px;
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: var(--shadow);
  cursor: pointer;
}

.mobile-nav {
  display: none;
}

.app-topbar {
  position: sticky;
  z-index: 18;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 14px 0;
  backdrop-filter: blur(18px);
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark span {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  color: #ffffff;
  background: var(--accent);
  font-size: 0.82rem;
  font-weight: 900;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.topbar-nav a,
.topbar-nav button {
  padding: 9px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  text-decoration: none;
  cursor: pointer;
}

.topbar-nav a:hover,
.topbar-nav button:hover,
.topbar-nav a:focus-visible,
.topbar-nav button:focus-visible {
  border-color: var(--border);
  color: var(--ink);
  background: color-mix(in srgb, var(--paper) 78%, transparent);
}

.topbar-nav button {
  color: #ffffff;
  background: var(--accent);
}

.topbar-nav #openSettings {
  color: var(--ink);
  background: var(--paper);
  border-color: var(--border);
}

body.focus-mode .reader-controls,
body.focus-mode .table-of-contents,
body.focus-mode .reading-progress,
body.focus-mode .app-topbar,
body.focus-mode .settings-backdrop,
body.focus-mode .mobile-nav,
body.focus-mode .back-to-top,
body.focus-mode .document-header,
body.focus-mode .document-tabs {
  display: none;
}

body.focus-mode .reader-shell {
  width: min(100%, calc(var(--reader-width) + (var(--reader-margin) * 2)));
  padding-top: clamp(32px, 7vw, 96px);
}

body.focus-mode .reading-layout {
  display: block;
}

body.focus-mode .markdown-body {
  max-width: var(--reader-width);
  margin: 0 auto;
}

button,
input,
select {
  font: inherit;
}

.reader-shell {
  width: min(1180px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(24px, 4vw, 56px) var(--reader-margin) clamp(56px, 8vw, 96px);
}

.library-panel,
.document-header,
.print-cover,
.document-tabs,
.table-of-contents,
.markdown-body {
  width: 100%;
  max-width: var(--reader-width);
  margin: 0 auto;
}

.reading-layout {
  display: block;
}

.drop-zone {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
}

.drop-zone {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(300px, 0.75fr);
  align-items: center;
  gap: clamp(18px, 4vw, 46px);
  min-height: min(720px, calc(100vh - 150px));
  padding: clamp(18px, 3vw, 30px);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  box-shadow: var(--soft-shadow);
  text-align: left;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

body[data-theme="dark"] .drop-zone {
  background: rgba(32, 34, 38, 0.78);
}

.drop-zone.is-over {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--paper));
  box-shadow: var(--shadow);
  transform: scale(0.995);
}

body[data-theme="dark"] .drop-zone.is-over {
  background: #1c2740;
}

.home-hero {
  max-width: 720px;
  padding: clamp(12px, 3vw, 28px);
}

.eyebrow,
.home-hero > span {
  display: block;
  margin-bottom: 12px;
  color: var(--accent);
  font-size: 0.86rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.home-hero h1 {
  margin: 0 0 16px;
  font-size: clamp(2.2rem, 5.5vw, 4.8rem);
  letter-spacing: -0.03em;
  line-height: 0.96;
}

.home-hero p {
  max-width: 660px;
  margin: 0;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.18rem);
  line-height: 1.6;
}

.home-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 12px;
  margin-top: 26px;
}

.home-actions .secondary-button {
  width: auto;
  padding: 12px 18px;
}

.primary-button {
  padding: 12px 18px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: #ffffff;
  background: var(--accent);
  box-shadow: 0 8px 20px color-mix(in srgb, var(--accent) 22%, transparent);
  cursor: pointer;
}

.home-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 30px 0 0;
  max-width: 560px;
}

.home-metrics div {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.home-metrics dt {
  margin: 0;
  color: var(--ink);
  font-size: 1.3rem;
  font-weight: 800;
}

.home-metrics dd {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.primary-button:hover,
.primary-button:focus-visible {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.home-preview {
  display: grid;
  gap: 14px;
}

.preview-window {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.preview-bar {
  display: flex;
  gap: 6px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.preview-bar span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--border);
}

.preview-content {
  padding: 22px;
}

.preview-content strong {
  display: block;
  margin-bottom: 8px;
}

.preview-content p {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.5;
}

.preview-line {
  height: 10px;
  width: 78%;
  margin-top: 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 18%, var(--border));
}

.preview-line.wide {
  width: 100%;
}

.preview-line.short {
  width: 46%;
}

.feature-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.feature-pills span {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: var(--paper);
  font-size: 0.86rem;
}

.library-panel {
  margin-top: 28px;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  box-shadow: var(--soft-shadow);
}

.section-heading {
  margin-bottom: 16px;
}

.section-heading span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.section-heading h2 {
  margin: 0;
  font-size: clamp(1.4rem, 3vw, 2rem);
}

.global-search {
  display: grid;
  gap: 7px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.global-search input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--ink);
  background: var(--paper);
}

.library-toolbar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0 8px;
}

.library-toolbar label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.86rem;
}

.library-toolbar select {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--ink);
  background: var(--paper);
}

.library-status {
  min-height: 1.2em;
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.9rem;
}

.library-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
}

.library-card {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px 14px;
  width: 100%;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: none;
  text-align: left;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.library-card:hover,
.library-card:focus-visible {
  border-color: var(--accent);
  box-shadow: var(--soft-shadow);
  transform: translateY(-1px);
}

.library-card strong {
  overflow-wrap: anywhere;
}

.library-card span {
  color: var(--muted);
  font-size: 0.86rem;
}

.library-open {
  display: grid;
  gap: 6px;
  width: 100%;
  padding: 0;
  border: 0;
  color: inherit;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.library-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.library-progress {
  display: inline-flex;
  width: fit-content;
  margin-top: 4px;
  padding: 4px 8px;
  border-radius: 999px;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  font-weight: 700;
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 7px;
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface);
  font-size: 0.78rem;
}

.library-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.library-actions button {
  min-height: 34px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  background: var(--paper);
  cursor: pointer;
}

.library-actions button:hover,
.library-actions button:focus-visible {
  border-color: var(--accent);
  color: var(--ink);
}

.library-card mark {
  padding: 0 2px;
  border-radius: 3px;
  color: #181818;
  background: #fde68a;
}

.settings-backdrop {
  position: fixed;
  z-index: 40;
  inset: 0;
  background: rgba(15, 18, 24, 0.38);
  backdrop-filter: blur(4px);
}

.app-modal {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 18, 24, 0.42);
  backdrop-filter: blur(6px);
}

.modal-card {
  position: relative;
  width: min(560px, 100%);
  padding: clamp(22px, 5vw, 34px);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.modal-card h2 {
  margin: 0 0 12px;
  font-size: clamp(1.8rem, 5vw, 3rem);
  line-height: 1;
}

.modal-card p {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.55;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
}

.onboarding-steps {
  display: grid;
  gap: 10px;
  margin: 0 0 22px;
  padding-left: 20px;
  color: var(--muted);
}

.reader-controls {
  position: fixed;
  z-index: 41;
  top: 0;
  right: 0;
  width: min(420px, 100%);
  height: 100vh;
  pointer-events: none;
  transform: translateX(100%);
  transition: transform 220ms ease;
}

.controls-panel {
  width: 100%;
  height: 100%;
  max-height: none;
  padding: 0 18px 18px;
  overflow: auto;
  border-left: 1px solid var(--border);
  border-radius: 0;
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.reader-controls.is-open {
  transform: translateX(0);
  pointer-events: auto;
}

.drawer-header {
  position: sticky;
  z-index: 2;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 0 -18px 8px;
  padding: 18px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--paper) 96%, transparent);
  backdrop-filter: blur(14px);
}

.drawer-header span {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.drawer-header h2 {
  margin: 0;
  font-size: 1.25rem;
}

.icon-button {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
  cursor: pointer;
}

.icon-button:hover,
.icon-button:focus-visible {
  border-color: var(--accent);
}

.control-group {
  padding: 0;
  border-bottom: 1px solid var(--border);
}

.control-group:last-child {
  border-bottom: 0;
}

.control-group summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 2px;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}

.control-group summary::-webkit-details-marker {
  display: none;
}

.control-group summary::after {
  content: "+";
  color: var(--muted);
  font-weight: 700;
}

.control-group[open] summary::after {
  content: "-";
}

.controls-panel label {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.controls-panel input[type="range"],
.controls-panel input[type="search"],
.controls-panel input[type="file"],
.controls-panel textarea,
.controls-panel select {
  grid-column: 1 / -1;
  width: 100%;
}

.controls-panel textarea,
.controls-panel input[type="search"] {
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--ink);
  background: var(--paper);
  resize: vertical;
}

.controls-panel select {
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--ink);
  background: var(--paper);
}

.controls-panel output {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.file-picker input {
  color: var(--ink);
  font-size: 0.88rem;
}

.recent-files {
  margin: -2px 0 12px;
  color: var(--muted);
  font-size: 0.86rem;
}

.recent-files strong {
  display: block;
  margin-bottom: 6px;
  color: var(--ink);
}

.recent-files ul {
  display: grid;
  gap: 4px;
  max-height: 86px;
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.recent-files li {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.secondary-button {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--ink);
  background: var(--paper);
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.secondary-button:hover,
.secondary-button:focus-visible {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 7%, var(--paper));
}

.compact-button {
  margin-bottom: 12px;
  padding: 7px 9px;
  font-size: 0.9rem;
}

.control-status {
  min-height: 1.2em;
  margin: -6px 0 8px;
  color: var(--muted);
  font-size: 0.85rem;
}

.actions-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.checkbox-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkbox-control input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.annotations-list {
  display: grid;
  gap: 8px;
  max-height: 150px;
  margin: 0 0 10px;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.annotations-list li {
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--muted);
  font-size: 0.84rem;
}

.annotations-list li:has(.annotation-actions button[data-action="resolve"]) {
  transition: border-color 0.2s ease, background 0.2s ease;
}

.annotations-empty {
  color: var(--muted);
  font-style: italic;
}

.annotations-list strong {
  display: block;
  color: var(--ink);
}

.annotation-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 7px;
}

.annotation-actions button {
  padding: 4px 7px;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--muted);
  background: var(--paper);
  cursor: pointer;
}

.annotation-actions button:hover,
.annotation-actions button:focus-visible {
  border-color: var(--accent);
  color: var(--ink);
}

.selection-menu {
  position: fixed;
  z-index: 70;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 7px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: color-mix(in srgb, var(--paper) 96%, transparent);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.selection-colors {
  display: flex;
  gap: 4px;
  padding-right: 6px;
  border-right: 1px solid var(--border);
}

.selection-colors button {
  width: 28px;
  min-height: 28px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 999px;
  background: var(--annotation-color);
}

.selection-colors button[data-selection-color="yellow"] {
  --annotation-color: #fef08a;
}

.selection-colors button[data-selection-color="green"] {
  --annotation-color: #bbf7d0;
}

.selection-colors button[data-selection-color="blue"] {
  --annotation-color: #bfdbfe;
}

.selection-colors button[data-selection-color="pink"] {
  --annotation-color: #fbcfe8;
}

.selection-colors button[data-selection-color="purple"] {
  --annotation-color: #ddd6fe;
}

.selection-colors button.is-active,
.selection-colors button:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 20%, transparent);
}

.selection-menu[hidden] {
  display: none;
}

.selection-menu button {
  min-height: 36px;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
}

.selection-menu button:hover,
.selection-menu button:focus-visible {
  color: var(--ink);
  background: var(--surface);
}

.selection-menu .selection-colors button {
  flex: 0 0 28px;
  width: 28px;
  min-height: 28px;
  padding: 0;
  border: 2px solid transparent;
  background: var(--annotation-color);
}

.selection-menu .selection-colors button:hover {
  background: var(--annotation-color);
}

.selection-menu .selection-colors button.is-active,
.selection-menu .selection-colors button:focus-visible {
  border-color: var(--accent);
  background: var(--annotation-color);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 20%, transparent);
}

.selection-menu [data-selection-action="remove"] {
  color: #b91c1c;
}

.selection-menu [data-selection-action="remove"]:hover,
.selection-menu [data-selection-action="remove"]:focus-visible {
  color: #7f1d1d;
  background: #fee2e2;
}

.annotation-popover {
  position: fixed;
  z-index: 72;
  width: min(300px, calc(100vw - 28px));
  padding: 16px 17px;
  border: 1px solid #e3c456;
  border-radius: 8px;
  color: #2f2610;
  background: #fff4b8;
  box-shadow: 0 18px 45px rgba(52, 43, 18, 0.2);
}

.annotation-popover[hidden] {
  display: none;
}

.annotation-popover::before {
  content: "";
  position: absolute;
  top: -8px;
  left: 22px;
  width: 14px;
  height: 14px;
  border-top: 1px solid #e3c456;
  border-left: 1px solid #e3c456;
  background: #fff4b8;
  transform: rotate(45deg);
}

.annotation-popover strong {
  display: block;
  margin-bottom: 7px;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.annotation-comment-list {
  display: grid;
  gap: 10px;
}

.annotation-comment-list article {
  display: grid;
  gap: 4px;
}

.annotation-comment-list span {
  color: rgba(47, 38, 16, 0.68);
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
}

.annotation-comment-list p {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 0.95rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.annotation-resolved-note {
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(47, 38, 16, 0.08);
  font-weight: 700;
}

.search-hit {
  border-radius: 3px;
  color: #181818;
  background: #fde68a;
}

.document-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
  padding: 18px 0;
  border-bottom: 1px solid var(--border);
}

.document-header span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.document-header h2 {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: clamp(1.4rem, 3vw, 2rem);
  line-height: 1.2;
}

.document-header p {
  max-width: 260px;
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
  text-align: right;
}

.print-cover {
  display: none;
}

.print-running-header,
.print-running-footer,
.print-appendix {
  display: none;
}

.table-of-contents {
  margin: 0 auto 30px;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 0.95rem;
}

.table-of-contents strong {
  display: block;
  margin-bottom: 10px;
}

.table-of-contents a {
  display: block;
  margin: 6px 0;
  color: var(--muted);
  text-decoration: none;
  line-height: 1.35;
}

.table-of-contents a:hover,
.table-of-contents a:focus-visible {
  color: var(--accent);
}

.table-of-contents .toc-level-2 {
  padding-left: 16px;
}

.table-of-contents .toc-level-3 {
  padding-left: 32px;
}

.document-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 22px;
}

.document-tabs button {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: var(--paper);
  cursor: pointer;
}

.document-tabs button.is-active {
  border-color: var(--accent);
  color: #ffffff;
  background: var(--accent);
}

.markdown-body {
  padding-top: 8px;
  padding-bottom: 20vh;
  font-family: var(--reader-font-family);
  font-size: var(--reader-font-size);
  line-height: var(--reader-line-height);
}

.markdown-body > :first-child {
  margin-top: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin: 1.7em 0 0.55em;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  line-height: 1.16;
  letter-spacing: -0.01em;
}

.markdown-body h1 {
  font-size: 2.45em;
}

.markdown-body h2 {
  padding-bottom: 0.25em;
  border-bottom: 1px solid var(--border);
  font-size: 1.75em;
}

.markdown-body h3 {
  font-size: 1.35em;
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body blockquote,
.markdown-body pre,
.markdown-body table {
  margin: 0 0 1.05em;
}

.markdown-body p {
  text-indent: var(--paragraph-indent);
  text-align: justify;
  text-justify: inter-word;
}

.markdown-body.align-left p {
  text-align: left;
  text-justify: auto;
}

.markdown-body a {
  color: var(--accent);
}

.markdown-link-blocked,
.markdown-media-blocked {
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-style: dotted;
}

.markdown-body img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  margin: 1.25em auto;
  box-sizing: border-box;
  object-fit: contain;
  border-radius: 8px;
}

.markdown-body p:has(img) {
  text-indent: 0;
}

.markdown-body blockquote {
  padding: 0.05em 0 0.05em 1em;
  border-left: 4px solid var(--accent);
  color: var(--muted);
}

.markdown-body code {
  padding: 0.14em 0.32em;
  border-radius: 5px;
  background: #eeeeea;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.88em;
}

body[data-theme="dark"] .markdown-body code {
  background: #2b2e34;
}

.markdown-body pre {
  position: relative;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  border-radius: 8px;
  background: #202124;
  color: #f6f6f4;
}

.markdown-body .code-language {
  display: block;
  margin-bottom: 10px;
  color: #a9adb5;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 0.78rem;
  text-transform: uppercase;
}

.markdown-body pre code {
  padding: 0;
  background: transparent;
  color: inherit;
}

.markdown-body .task-list-item {
  list-style: none;
}

.markdown-body .task-list-item input {
  margin-right: 8px;
}

.markdown-body .footnotes {
  margin-top: 2.5em;
  padding-top: 1em;
  border-top: 1px solid var(--border);
  font-size: 0.92em;
}

.markdown-body .footnotes h2 {
  font-size: 1.2em;
}

.reader-highlight {
  border-radius: 3px;
  background: var(--annotation-color, #fef08a);
}

.reader-highlight[data-has-comments="true"] {
  cursor: pointer;
  box-shadow: inset 0 -0.16em 0 color-mix(in srgb, var(--accent) 35%, transparent);
}

.annotation-anchor {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 1.18em;
  height: 1.18em;
  margin-left: 0.22em;
  padding: 0;
  border: 0;
  border-radius: 999px;
  color: #ffffff;
  background: var(--accent);
  box-shadow: 0 2px 7px color-mix(in srgb, var(--accent) 34%, transparent);
  cursor: pointer;
  vertical-align: 0.05em;
}

.annotation-anchor::before {
  content: "";
  width: 0.54em;
  height: 0.42em;
  border: 1.5px solid currentColor;
  border-radius: 0.16em;
}

.annotation-anchor::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0.22em;
  height: 0.22em;
  background: currentColor;
  clip-path: polygon(0 0, 100% 0, 0 100%);
  transform: translate(-80%, 10%);
}

.annotation-anchor:hover,
.annotation-anchor:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 30%, transparent);
  outline-offset: 2px;
}

.reader-highlight[data-color="green"] {
  --annotation-color: #bbf7d0;
}

.reader-highlight[data-color="blue"] {
  --annotation-color: #bfdbfe;
}

.reader-highlight[data-color="pink"] {
  --annotation-color: #fbcfe8;
}

.reader-highlight[data-color="purple"] {
  --annotation-color: #ddd6fe;
}

.reader-highlight[data-style="underline"] {
  border-radius: 0;
  color: inherit;
  background: transparent;
  text-decoration-line: underline;
  text-decoration-color: var(--annotation-color, var(--accent));
  text-decoration-thickness: 0.12em;
  text-underline-offset: 0.18em;
}

.reader-highlight[data-style="strike"] {
  color: inherit;
  background: transparent;
  text-decoration-line: line-through;
  text-decoration-color: var(--annotation-color, #b91c1c);
  text-decoration-thickness: 0.12em;
}

.reader-highlight[data-style="comment"] {
  border-radius: 0;
  color: inherit;
  background: transparent;
  text-decoration-line: underline;
  text-decoration-style: dotted;
  text-decoration-color: #f59e0b;
  text-decoration-thickness: 0.14em;
  text-underline-offset: 0.2em;
}

.reader-highlight[data-style="comment"][data-has-comments="true"] {
  box-shadow: none;
}

.markdown-body table {
  display: block;
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-collapse: collapse;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 0.9em;
}

.markdown-body th,
.markdown-body td {
  padding: 9px 11px;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.markdown-body th {
  background: #eeeeea;
}

body[data-theme="dark"] .markdown-body th {
  background: #2b2e34;
}

.markdown-body hr {
  height: 1px;
  margin: 2em 0;
  border: 0;
  background: var(--border);
}

@media (max-width: 720px) {
  :root {
    --reader-margin: 18px;
    --reader-font-size: 17px;
    --paragraph-indent: 0.8cm;
  }

  .app-topbar {
    position: sticky;
    align-items: flex-start;
    flex-direction: column;
    width: min(100% - 24px, 1180px);
    padding: 12px 0;
  }

  .topbar-nav {
    width: 100%;
    justify-content: flex-start;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .topbar-nav::-webkit-scrollbar {
    display: none;
  }

  .topbar-nav a,
  .topbar-nav button {
    flex: 0 0 auto;
    min-height: 44px;
    padding: 10px 13px;
  }

  .reader-shell {
    padding-top: 18px;
    padding-bottom: 96px;
  }

  .mobile-nav {
    position: fixed;
    z-index: 22;
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    left: 10px;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: color-mix(in srgb, var(--paper) 94%, transparent);
    box-shadow: var(--shadow);
    backdrop-filter: blur(14px);
  }

  .mobile-nav button {
    min-height: 44px;
    padding: 7px 4px;
    border: 0;
    border-radius: 8px;
    color: var(--muted);
    background: transparent;
    font-size: 0.78rem;
    cursor: pointer;
  }

  .mobile-nav button:hover,
  .mobile-nav button:focus-visible {
    color: var(--ink);
    background: var(--surface);
  }

  .selection-menu {
    top: auto !important;
    right: 10px;
    bottom: calc(74px + env(safe-area-inset-bottom));
    left: 10px !important;
    justify-content: center;
    overflow-x: auto;
  }

  .selection-colors {
    flex-basis: 100%;
    justify-content: center;
    padding-right: 0;
    padding-bottom: 6px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .selection-menu button {
    flex: 1 0 auto;
    min-height: 42px;
  }

  .annotation-popover {
    right: 14px !important;
    bottom: calc(88px + env(safe-area-inset-bottom));
    left: 14px !important;
    top: auto !important;
    width: auto;
  }

  .annotation-popover::before {
    display: none;
  }

  .drop-zone {
    grid-template-columns: 1fr;
    min-height: auto;
    padding: 16px;
  }

  .home-hero {
    padding: 8px;
  }

  .home-hero h1 {
    font-size: clamp(2rem, 11vw, 3.2rem);
  }

  .home-metrics {
    grid-template-columns: 1fr;
  }

  .home-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .home-actions .primary-button {
    justify-content: center;
    width: 100%;
    min-height: 46px;
  }

  .home-actions .secondary-button {
    justify-content: center;
    width: 100%;
    min-height: 46px;
  }

  .home-preview {
    display: none;
  }

  .library-panel {
    padding: 16px;
  }

  .document-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .document-header p {
    max-width: none;
    text-align: left;
  }

  .reader-controls {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: auto;
    height: min(86vh, 720px);
    padding: 0 10px max(10px, env(safe-area-inset-bottom));
    transform: translateY(100%);
  }

  .reader-controls.is-open {
    transform: translateY(0);
  }

  .reader-controls::before {
    content: "";
    position: absolute;
    top: 10px;
    left: 50%;
    z-index: 3;
    width: 42px;
    height: 4px;
    border-radius: 999px;
    background: var(--border);
    transform: translateX(-50%);
  }

  .controls-panel {
    height: 100%;
    padding: 0 14px max(16px, env(safe-area-inset-bottom));
    border-radius: 8px;
    border: 1px solid var(--border);
  }

  .drawer-header {
    margin: 0 -14px 8px;
    padding: 22px 14px 14px;
  }

  .control-group summary {
    min-height: 46px;
  }

  .controls-panel input[type="search"],
  .controls-panel input[type="file"],
  .controls-panel textarea,
  .controls-panel select,
  .secondary-button {
    min-height: 44px;
  }

  .actions-grid {
    grid-template-columns: 1fr;
  }

  .back-to-top {
    right: 12px;
    bottom: calc(max(12px, env(safe-area-inset-bottom)) + 70px);
    min-height: 44px;
  }

  .markdown-body {
    font-size: var(--reader-font-size);
    line-height: 1.58;
  }

  .markdown-body h1 {
    font-size: 2em;
  }

  .markdown-body h2 {
    font-size: 1.45em;
  }

  .table-of-contents {
    position: static;
    max-height: none;
    padding: 14px;
  }

  .reading-layout {
    display: block;
  }
}

@media print {
  :root {
    --bg: #ffffff;
    --paper: #ffffff;
    --ink: #111111;
    --muted: #555555;
    --border: #cccccc;
    --reader-font-size: 14px !important;
    --paragraph-indent: 1.5cm !important;
    --reader-width: 1180px !important;
    --reader-margin: 16px !important;
    --reader-line-height: 1.5 !important;
  }

  @page {
    size: A4;
    margin: 2cm;

    @top-left {
      content: var(--print-running-title, "");
      margin-bottom: 0.25cm;
      border-bottom: 1px solid var(--print-running-rule, transparent);
      color: #666666;
      font-family: Inter, Arial, sans-serif;
      font-size: 9pt;
      font-weight: 700;
    }

    @top-center,
    @top-right {
      content: "";
      margin-bottom: 0.25cm;
      border-bottom: 1px solid var(--print-running-rule, transparent);
    }

    @bottom-left {
      content: var(--print-running-brand, "");
      margin-top: 0.25cm;
      border-top: 1px solid var(--print-running-rule, transparent);
      color: #666666;
      font-family: Inter, Arial, sans-serif;
      font-size: 9pt;
    }

    @bottom-center,
    @bottom-right {
      content: "";
      margin-top: 0.25cm;
      border-top: 1px solid var(--print-running-rule, transparent);
    }
  }

  body,
  body.drawer-open {
    overflow: visible !important;
  }

  .reader-controls,
  .app-topbar,
  .settings-backdrop,
  .app-modal,
  .selection-menu,
  .annotation-popover,
  .annotation-anchor,
  .mobile-nav,
  .reading-progress,
  .focus-exit,
  .back-to-top,
  .drop-zone,
  .document-tabs {
    display: none !important;
  }

  body {
    color: #000000;
    background: #ffffff;
  }

  .reader-shell {
    width: 17cm;
    min-height: auto;
    padding: 0;
    margin: 0 auto;
  }

  .document-header,
  .print-cover,
  .print-running-header,
  .print-running-footer,
  .print-appendix,
  .table-of-contents,
  .markdown-body {
    max-width: none;
  }

  .print-cover {
    display: block;
    position: relative;
    min-height: 72vh;
    padding: 2.2cm 0 1.4cm;
    break-after: page;
  }

  .print-cover::before {
    content: "";
    display: block;
    width: 2.4cm;
    height: 0.12cm;
    margin-bottom: 1.2cm;
    background: #111111;
  }

  body[data-print-cover="academic"] .print-cover {
    text-align: center;
  }

  body[data-print-cover="academic"] .print-cover::before {
    margin-right: auto;
    margin-left: auto;
  }

  body[data-print-cover="minimal"] .print-cover {
    min-height: 44vh;
    padding-top: 1cm;
    border-bottom: 1px solid #dddddd;
  }

  body[data-print-cover="minimal"] .print-cover::before,
  body[data-print-cover="minimal"] .print-cover::after {
    display: none;
  }

  .print-appendix {
    display: block;
    break-before: page;
    padding-top: 0.5cm;
  }

  .print-appendix[hidden] {
    display: none !important;
  }

  .print-appendix h2 {
    margin: 0 0 1cm;
    font-size: 22pt;
  }

  .print-appendix article {
    margin-bottom: 0.8cm;
    break-inside: avoid;
  }

  .print-appendix h3 {
    margin: 0 0 0.25cm;
    font-size: 12pt;
  }

  .print-appendix blockquote {
    margin: 0 0 0.35cm;
    padding-left: 0.35cm;
    border-left: 3px solid #cccccc;
    color: #555555;
  }

  .print-appendix ol {
    margin: 0;
    padding-left: 0.55cm;
  }

  .print-cover::after {
    content: "";
    position: absolute;
    right: 0;
    bottom: 1.4cm;
    width: 35%;
    height: 1px;
    background: #cccccc;
  }

  .print-cover span {
    color: #4b5563;
    font-size: 9pt;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
  }

  .print-cover h1 {
    max-width: 15cm;
    margin: 0.7cm 0 0;
    color: #111111;
    font-size: 42pt;
    letter-spacing: -0.03em;
    line-height: 0.98;
  }

  .print-cover p {
    position: absolute;
    bottom: 1.15cm;
    left: 0;
    margin: 0;
    color: #4b5563;
    font-size: 10pt;
  }

  .document-header {
    display: none;
  }

  .table-of-contents {
    display: block;
    max-width: 17cm !important;
    margin: 0 auto 0.8cm;
    padding: 0.4cm 0;
    border: 0;
    border-bottom: 1px solid #dddddd;
    border-radius: 0;
    background: transparent;
    break-after: avoid;
  }

  .table-of-contents[hidden] {
    display: none !important;
  }

  .table-of-contents a {
    color: #000000 !important;
  }

  .markdown-body {
    max-width: 17cm !important;
    margin-right: auto;
    margin-left: auto;
    padding-top: 1.25cm;
    padding-bottom: 1.35cm;
    box-sizing: border-box;
    color: #000000 !important;
    font-size: 14px !important;
    line-height: 1.5 !important;
  }

  .markdown-body p {
    text-indent: 1.5cm !important;
    text-align: justify !important;
    text-justify: inter-word;
    orphans: 3;
    widows: 3;
  }

  .markdown-body :where(li, blockquote) {
    orphans: 3;
    widows: 3;
  }

  .markdown-body p:has(img) {
    text-indent: 0 !important;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .markdown-body img {
    display: block !important;
    width: auto !important;
    max-width: 100% !important;
    max-height: 24cm !important;
    height: auto !important;
    margin: 0.4cm auto !important;
    box-sizing: border-box;
    object-fit: contain;
    border-radius: 0;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .markdown-body :where(h1, h2, h3, h4, h5, h6, p, li, blockquote, strong, em, span, td, th, dd, dt),
  .print-appendix :where(h2, h3, p, li, blockquote, strong, span) {
    color: #000000 !important;
  }

  .markdown-body a {
    color: #000000 !important;
    text-decoration: underline;
  }

  .markdown-body pre {
    white-space: pre-wrap;
    border: 1px solid #cccccc;
    background: #f5f5f5;
    color: #111111;
  }
}
