:root {
  --ink: #122033;
  --muted: #718097;
  --line: #dfe6ee;
  --paper: #fff;
  --bg: #f4f7fa;
  --bg-soft: #e8edf2;
  --accent: #2090a9;
  --accent-2: #3ca781;
  --navy: #123342;
  --toolbar-bg: #fbfcfd;
  --shadow-card: 0 16px 45px rgba(25, 47, 71, .08);
  --shadow-page: 0 5px 20px rgba(36, 54, 72, .19);
  --focus-ring: #2090a9;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --ink: #e7edf5;
  --muted: #93a3b8;
  --line: #24384a;
  --paper: #14212e;
  --bg: #0b141d;
  --bg-soft: #101d29;
  --accent: #38b6cf;
  --accent-2: #4fc796;
  --navy: #0a1620;
  --toolbar-bg: #101b26;
  --shadow-card: 0 16px 45px rgba(0, 0, 0, .35);
  --shadow-page: 0 5px 24px rgba(0, 0, 0, .5);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #e7edf5;
    --muted: #93a3b8;
    --line: #24384a;
    --paper: #14212e;
    --bg: #0b141d;
    --bg-soft: #101d29;
    --accent: #38b6cf;
    --accent-2: #4fc796;
    --navy: #0a1620;
    --toolbar-bg: #101b26;
    --shadow-card: 0 16px 45px rgba(0, 0, 0, .35);
    --shadow-page: 0 5px 24px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'DM Sans', sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background .25s ease, color .25s ease;
}

.topbar {
  height: 78px;
  background: var(--navy);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 max(5vw, 28px);
  border-bottom: 1px solid rgba(255, 255, 255, .09);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; }
.brand-mark { display: flex; align-items: flex-end; gap: 3px; width: 25px; height: 24px; }
.brand-mark span { display: block; width: 6px; border-radius: 2px; background: var(--accent); }
.brand-mark span:first-child { height: 13px; opacity: .75; }
.brand-mark span:nth-child(2) { height: 20px; }
.brand-mark span:last-child { height: 16px; opacity: .85; }
.brand-copy { display: flex; flex-direction: column; line-height: 1; }
.brand-copy strong { font-size: 15px; letter-spacing: .01em; }
.brand-copy small { font-size: 10px; color: #9baabd; letter-spacing: .12em; text-transform: uppercase; margin-top: 5px; }

.top-actions { display: flex; align-items: center; gap: 14px; }
.quiet-link { color: #acb8c7; font-size: 12px; text-decoration: none; }
.quiet-link:hover { color: #fff; }

.theme-toggle {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, .14);
  background: rgba(255, 255, 255, .04);
  color: #cfd9e4; cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.theme-toggle:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.theme-toggle svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

.download-button {
  display: flex; align-items: center; gap: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white; text-decoration: none; border-radius: 7px;
  padding: 11px 16px; font-size: 13px; font-weight: 700;
  box-shadow: 0 4px 14px rgba(32, 144, 169, .28);
  transition: transform .2s, box-shadow .2s, filter .2s;
}
.download-button:hover { filter: brightness(1.06); transform: translateY(-1px); box-shadow: 0 6px 18px rgba(32, 144, 169, .34); }
.download-button:active { transform: translateY(0); }
.download-button span:first-child { font-size: 20px; font-weight: 400; line-height: 10px; }

.page-shell { max-width: 1160px; margin: 0 auto; padding: 56px 36px 38px; }
.document-intro { margin-bottom: 43px; }
.eyebrow { color: var(--accent); font-size: 11px; text-transform: uppercase; letter-spacing: .16em; font-weight: 700; display: flex; align-items: center; gap: 9px; }
.status-dot, .live-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
@media (prefers-reduced-motion: no-preference) {
  .status-dot, .live-dot { animation: pulse 2.4s ease-in-out infinite; }
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
.slash { color: var(--muted); opacity: .6; margin-left: 2px; }
.document-intro h1 {
  font-family: Manrope, sans-serif;
  font-size: clamp(38px, 5vw, 64px);
  line-height: 1.04; letter-spacing: -.055em;
  margin: 18px 0 13px; color: var(--ink); font-weight: 800;
}
.document-intro h1 em { font-style: normal; color: var(--accent-2); }
.subtitle { font-size: 18px; color: var(--muted); letter-spacing: .01em; margin: 0 0 26px; }
.document-meta { display: flex; align-items: center; gap: 15px; color: var(--muted); font-size: 12px; flex-wrap: wrap; }
.meta-item b { color: var(--ink); font-size: 14px; }
.meta-divider { height: 14px; width: 1px; background: var(--line); }

.reader-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 11px;
  overflow: hidden;
  box-shadow: var(--shadow-card);
}
.reader-toolbar {
  min-height: 57px; display: flex; align-items: center; gap: 16px;
  padding: 9px 16px; border-bottom: 1px solid var(--line);
  background: var(--toolbar-bg);
}
.reader-label {
  display: flex; align-items: center; gap: 10px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .1em; font-size: 10px; font-weight: 700;
  margin-right: auto; white-space: nowrap;
}
.document-icon { font-size: 18px; color: var(--accent); line-height: 0; transform: rotate(180deg); }
.controls-group { display: flex; align-items: center; gap: 5px; }
.page-status { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.page-status input {
  width: 40px; height: 30px; border: 1px solid var(--line); border-radius: 5px;
  text-align: center; color: var(--ink); font: 600 12px 'DM Sans'; background: var(--paper);
  -moz-appearance: textfield;
}
.page-status input::-webkit-outer-spin-button,
.page-status input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.page-status input:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 1px; }

.tool-button {
  height: 30px; min-width: 30px; border: 1px solid var(--line); border-radius: 5px;
  background: var(--paper); color: var(--ink); font: 600 12px 'DM Sans'; cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.tool-button:hover:not(:disabled) { background: rgba(32, 144, 169, .12); border-color: var(--accent); color: var(--accent); }
.tool-button:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 1px; }
.tool-button:disabled { opacity: .38; cursor: not-allowed; }
.text-button { font-size: 18px; line-height: 1; }
.optional-button { padding: 0 9px; font-size: 11px; }
.icon-tool { font-size: 17px; line-height: 1; }
.zoom-label { width: 41px; text-align: center; color: var(--muted); font-size: 11px; }

.retry-button {
  border: 1px solid var(--accent); color: var(--accent); background: transparent;
  border-radius: 6px; padding: 8px 16px; font: 700 12px 'DM Sans'; cursor: pointer;
  transition: background .15s, color .15s;
}
.retry-button:hover { background: var(--accent); color: #fff; }
.error-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

.mode-controls { gap: 0; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; padding: 0; }
.mode-button { border: none; border-radius: 0; font-size: 11px; padding: 0 12px; }
.mode-button + .mode-button { border-left: 1px solid var(--line); }
.mode-button.is-active { background: var(--accent); color: #fff; }
.mode-button.is-active:hover { background: var(--accent); color: #fff; }

.browser-frame { width: 100%; height: 100%; border: 0; display: block; }

.mobile-toolbar-note { display: none; }
.pdf-frame-wrap {
  height: min(82vh, 950px); min-height: 650px; background: var(--bg-soft);
  position: relative; overflow: auto; scroll-behavior: smooth; touch-action: pan-y;
}
.canvas-stage { min-height: 100%; display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 28px 20px; }
.page-canvas {
  display: block; background: #fff; box-shadow: var(--shadow-page);
  max-width: 100%; height: auto; opacity: 0; transform: translateY(6px) scale(.995);
}
.page-canvas.is-visible { animation: page-in .22s ease-out forwards; }
@keyframes page-in { to { opacity: 1; transform: translateY(0) scale(1); } }
@media (prefers-reduced-motion: reduce) {
  .page-canvas { opacity: 1; transform: none; }
  .page-canvas.is-visible { animation: none; }
}

.loading {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  gap: 11px; color: var(--muted); font-size: 13px; background: var(--bg-soft); z-index: 3;
}
.loading[hidden], .error-state[hidden] { display: none; }
.loader {
  width: 17px; height: 17px; border: 2px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error-state {
  position: absolute; inset: 0; z-index: 4; display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 10px; color: var(--muted); font-size: 14px; text-align: center; padding: 20px;
}
.error-state strong { font-size: 16px; color: var(--ink); }
.error-state a { color: var(--accent); font-weight: 700; margin-top: 3px; text-decoration: none; }
.error-state a:hover { text-decoration: underline; }

.page-footer {
  display: flex; justify-content: space-between; color: var(--muted); font-size: 11px;
  letter-spacing: .03em; padding: 24px 2px 0;
}
.page-footer span:last-child { color: var(--muted); opacity: .8; font-style: italic; }

@media (max-width: 900px) {
  .reader-toolbar { flex-wrap: wrap; gap: 8px; }
  .reader-label { width: 100%; height: 22px; }
  .view-controls { margin-left: auto; }
  .pdf-frame-wrap { height: 75vh; }
}
@media (max-width: 640px) {
  .topbar { height: 64px; padding: 0 16px; }
  .brand-copy small, .quiet-link { display: none; }
  .top-actions { gap: 8px; }
  .download-button { padding: 10px 12px; font-size: 12px; }
  .download-button .download-label { display: none; }
  .page-shell { padding: 32px 15px 28px; }
  .document-intro { margin-bottom: 29px; }
  .eyebrow { font-size: 9px; letter-spacing: .12em; }
  .document-intro h1 { font-size: 39px; letter-spacing: -.06em; margin-top: 15px; }
  .desktop-break { display: none; }
  .subtitle { font-size: 15px; margin-bottom: 21px; }
  .document-meta { gap: 9px; font-size: 10px; flex-wrap: wrap; }
  .meta-divider { height: 11px; }
  .reader-toolbar { min-height: 88px; padding: 9px 10px; gap: 6px; }
  .reader-label { margin: 0; width: 100%; height: 22px; }
  .page-controls { order: 2; }
  .view-controls { order: 3; margin-left: auto; max-width: calc(100% - 104px); overflow-x: auto; scrollbar-width: none; }
  .view-controls::-webkit-scrollbar { display: none; }
  .optional-button { display: none; }
  .icon-tool { font-size: 16px; }
  .mobile-toolbar-note {
    display: flex; align-items: center; gap: 7px; height: 29px; padding: 0 13px;
    color: var(--muted); font-size: 10px; border-bottom: 1px solid var(--line);
  }
  .pdf-frame-wrap { min-height: 62vh; height: 72vh; }
  .canvas-stage { padding: 14px 7px; gap: 12px; }
  .page-footer { font-size: 10px; gap: 15px; line-height: 1.5; flex-direction: column; }
  .page-footer span:last-child { text-align: left; }
}
