:root {
  --navy-900: #081522;
  --navy-800: #0b1b2b;
  --navy-700: #12293f;
  --gold: #c8a86b;
  --gold-soft: rgba(200, 168, 107, .35);
  --gold-faint: rgba(200, 168, 107, .16);
  --paper: #f7f2e8;
  --ink: #22303c;
  --text: #e9eef4;
  --muted: #94a8ba;
  --rail-thumb: 68px;
  --radius: 4px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  color: var(--text);
  font-family: var(--sans);
  background:
    radial-gradient(1200px 700px at 50% -15%, rgba(44, 82, 118, .5), transparent 62%),
    radial-gradient(900px 600px at 105% 105%, rgba(31, 63, 94, .38), transparent 62%),
    var(--navy-900);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

[hidden] { display: none !important; }

.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 100;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--gold);
  color: #14202b;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: top .15s ease;
}
.skip-link:focus { top: 12px; }

/* ---------- Header ---------- */

.topbar {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  min-height: 64px;
  padding: 9px clamp(12px, 3vw, 28px) 10px;
  border-bottom: 1px solid rgba(200, 168, 107, .2);
  background: linear-gradient(180deg, rgba(8, 21, 34, .86), rgba(8, 21, 34, .35));
  box-shadow: 0 1px 0 rgba(255, 255, 255, .03) inset;
  position: relative;
  z-index: 20;
}

.topbar::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  opacity: .55;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  line-height: 1.15;
}

.brand-name {
  font-family: var(--serif);
  font-size: 16px;
  letter-spacing: .06em;
  color: #fff;
}

.brand-place {
  font-size: 8.5px;
  font-weight: 600;
  letter-spacing: .24em;
  text-transform: uppercase;
  color: var(--gold);
  white-space: nowrap;
}

.titles {
  text-align: center;
  min-width: 0;
}

.eyebrow {
  margin: 0 0 3px;
  font-size: 8.5px;
  font-weight: 600;
  letter-spacing: .28em;
  text-transform: uppercase;
  color: var(--gold);
  white-space: nowrap;
}

.doc-title {
  margin: 0;
  font-family: var(--serif);
  font-size: 14px;
  font-weight: 400;
  letter-spacing: .04em;
  color: rgba(255, 255, 255, .88);
  white-space: nowrap;
}

.actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 13px;
  border: 1px solid var(--gold-soft);
  border-radius: 999px;
  background: transparent;
  color: rgba(255, 255, 255, .86);
  font: inherit;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  transition: background .18s ease, border-color .18s ease, color .18s ease;
}

.btn:hover {
  background: var(--gold-faint);
  border-color: rgba(200, 168, 107, .65);
  color: #fff;
}

.btn:focus-visible,
.nav:focus-visible,
.thumb:focus-visible,
.drawer-close:focus-visible,
.skip-link:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.btn[aria-pressed="true"] {
  background: var(--gold);
  border-color: var(--gold);
  color: #14202b;
}

.btn-icon {
  width: 34px;
  padding: 0;
  border-radius: 50%;
}

.btn-icon.is-active {
  background: var(--gold);
  border-color: var(--gold);
  color: #14202b;
}

.icon {
  width: 16px;
  height: 16px;
  display: block;
}

/* ---------- Viewer ---------- */

.viewer {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(8px, 1.6vh, 20px) clamp(48px, 5.5vw, 84px);
}

.stage {
  margin: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: pan-y pinch-zoom;
}

.stage img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius);
  background: #0a1521;
  box-shadow:
    0 28px 70px -20px rgba(0, 0, 0, .8),
    0 0 0 1px rgba(255, 255, 255, .045);
  opacity: 1;
  transition: opacity .22s ease;
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
}

.stage img.is-loading { opacity: .35; }

.nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 5;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 50%;
  background: rgba(8, 21, 34, .55);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: #fff;
  cursor: pointer;
  transition: background .18s ease, border-color .18s ease, opacity .18s ease;
}

.nav:hover {
  background: rgba(200, 168, 107, .18);
  border-color: rgba(200, 168, 107, .7);
}

.nav:disabled {
  opacity: .22;
  cursor: default;
  background: rgba(8, 21, 34, .35);
}

.nav-prev { left: clamp(8px, 1.6vw, 22px); }
.nav-next { right: clamp(8px, 1.6vw, 22px); }

.counter {
  position: absolute;
  left: clamp(12px, 2vw, 24px);
  bottom: clamp(10px, 2vh, 18px);
  z-index: 4;
  margin: 0;
  padding: 5px 11px;
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 999px;
  background: rgba(8, 21, 34, .66);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
  letter-spacing: .16em;
  color: #fff;
}

.counter-total {
  margin-left: 4px;
  color: var(--muted);
}

/* ---------- Thumbnail rail ---------- */

.rail {
  flex: 0 0 auto;
  border-top: 1px solid rgba(200, 168, 107, .16);
  background: linear-gradient(180deg, rgba(10, 24, 38, .55), rgba(6, 15, 25, .92));
  padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
}

.rail-track {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 clamp(10px, 3vw, 26px);
  scrollbar-width: none;
  scroll-snap-type: x proximity;
  overscroll-behavior-x: contain;
}

.rail-track::-webkit-scrollbar { display: none; }

.thumb {
  flex: 0 0 auto;
  width: var(--rail-thumb);
  height: var(--rail-thumb);
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--navy-700);
  opacity: .5;
  cursor: pointer;
  scroll-snap-align: center;
  transition: opacity .18s ease, border-color .18s ease, box-shadow .18s ease;
}

.thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb:hover { opacity: .82; }

.thumb[aria-current="page"] {
  opacity: 1;
  border-color: var(--gold);
  box-shadow:
    0 0 0 1px rgba(200, 168, 107, .35),
    0 10px 22px -10px rgba(0, 0, 0, .9);
}

/* ---------- Text drawer ---------- */

.drawer {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  grid-template-columns: 1fr min(440px, 100%);
}

.drawer-backdrop {
  grid-column: 1;
  grid-row: 1;
  background: rgba(3, 9, 15, .62);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  cursor: pointer;
}

.drawer-panel {
  grid-column: 2;
  grid-row: 1;
  position: relative;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: clamp(26px, 4vw, 42px) clamp(22px, 3vw, 38px) 40px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .5), transparent 180px),
    var(--paper);
  color: var(--ink);
  box-shadow: -24px 0 70px rgba(0, 0, 0, .45);
}

.drawer-close {
  position: absolute;
  top: 14px;
  right: 14px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid rgba(34, 48, 60, .16);
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: background .18s ease, border-color .18s ease;
}

.drawer-close:hover {
  background: rgba(34, 48, 60, .06);
  border-color: rgba(34, 48, 60, .35);
}

.drawer-eyebrow {
  margin: 0 0 8px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .28em;
  text-transform: uppercase;
  color: #9a7c45;
}

.drawer-panel h2 {
  margin: 0 0 20px;
  font-family: var(--serif);
  font-size: clamp(24px, 3vw, 30px);
  font-weight: 400;
  letter-spacing: .01em;
  color: #16232e;
}

.drawer-panel h2::after {
  content: "";
  display: block;
  width: 44px;
  height: 1px;
  margin-top: 16px;
  background: var(--gold);
}

.drawer-body {
  white-space: pre-line;
  font-family: var(--serif);
  font-size: 15.5px;
  line-height: 1.72;
  color: #33414d;
  overflow-wrap: break-word;
}

.drawer-body:empty { display: none; }

.drawer-note {
  margin: 28px 0 0;
  padding-top: 16px;
  border-top: 1px solid rgba(34, 48, 60, .12);
  font-size: 10.5px;
  line-height: 1.6;
  letter-spacing: .02em;
  color: #7c8894;
}

/* ---------- Fallbacks ---------- */

.noscript {
  position: fixed;
  inset: auto 0 0;
  z-index: 70;
  margin: 0;
  padding: 16px 20px;
  background: var(--paper);
  color: var(--ink);
  font-size: 14px;
  text-align: center;
}
.noscript a { color: #8a6d36; }

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
  .titles { display: none; }
  .topbar { grid-template-columns: 1fr auto; }
}

@media (max-width: 600px) {
  :root { --rail-thumb: 54px; }
  .topbar { min-height: 58px; padding: 8px 12px; }
  .brand-name { font-size: 14px; }
  .brand-place { font-size: 7.5px; letter-spacing: .18em; }
  .actions { gap: 6px; }
  .btn { height: 32px; padding: 0 10px; font-size: 9.5px; }
  .btn-icon { width: 32px; padding: 0; }
  .viewer { padding: 10px; }
  .nav { width: 34px; height: 34px; background: rgba(8, 21, 34, .72); }
  .nav-prev { left: 16px; }
  .nav-next { right: 16px; }
  .counter { left: 10px; bottom: 10px; }
  .rail { padding: 8px 0 calc(8px + env(safe-area-inset-bottom)); }
  .rail-track { gap: 6px; padding: 0 10px; }
  .drawer { grid-template-columns: 0 1fr; }
  .drawer-backdrop { display: none; }
  .drawer-panel { grid-column: 2; padding-top: calc(30px + env(safe-area-inset-top)); }
}

@media (max-height: 520px) and (orientation: landscape) {
  :root { --rail-thumb: 44px; }
  .topbar { min-height: 50px; padding-top: 5px; padding-bottom: 5px; }
  .viewer { padding-top: 4px; padding-bottom: 4px; }
  .rail { padding-top: 6px; padding-bottom: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: .001ms !important;
    animation-duration: .001ms !important;
  }
  .rail-track { scroll-behavior: auto; }
}

.drawer-link {
  margin: 18px 0 0;
  font-family: var(--sans);
  font-size: 10.5px;
  letter-spacing: .05em;
}

.drawer-link a {
  color: #8a6d36;
  text-decoration: none;
  border-bottom: 1px solid rgba(138, 109, 54, .35);
  padding-bottom: 2px;
}

.drawer-link a:hover { color: #5f4a21; }

@media (max-width: 900px) {
  .btn-wide { display: none; }
}

.viewer-back {
  position: absolute;
  right: clamp(12px, 2vw, 24px);
  bottom: clamp(10px, 2vh, 18px);
  z-index: 4;
  padding: 5px 11px;
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 999px;
  background: rgba(8, 21, 34, .66);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: var(--muted);
  font-family: var(--sans);
  font-size: 9.5px;
  letter-spacing: .1em;
  text-transform: uppercase;
  text-decoration: none;
  transition: color .18s ease, border-color .18s ease;
}

.viewer-back:hover {
  color: #fff;
  border-color: rgba(200, 168, 107, .6);
}
