:root {
  --ink: #171612;
  --muted: #666157;
  --paper: #fffefa;
  --canvas: #e9e4da;
  --panel: #f5f1e8;
  --line: #bcb4a5;
  --accent: #16749a;
  --accent-soft: #dceef4;
  --sidebar-width: 330px;
  color-scheme: light;
  font-family: Arial, Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
}

button,
a {
  font: inherit;
}

button:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.site-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--paper);
  padding: 30px 24px;
  z-index: 20;
}

.brand-block {
  border-bottom: 2px solid var(--ink);
  padding: 0 4px 25px;
}

.brand {
  color: var(--ink);
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.055em;
  line-height: 1;
  text-decoration: none;
}

.brand-block p {
  margin: 14px 0 0;
  color: var(--muted);
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 14px;
  line-height: 1.45;
}

.theme-list {
  padding-top: 18px;
}

.theme-group {
  border-bottom: 1px solid var(--line);
}

.theme-group summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  list-style: none;
  padding: 16px 4px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

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

.theme-group summary::before {
  content: '+';
  order: 2;
  font-size: 20px;
  font-weight: 400;
  line-height: 1;
}

.theme-group[open] summary::before {
  content: '−';
}

.theme-count {
  order: 1;
  margin-left: auto;
  color: var(--muted);
  font-size: 11px;
}

.sheet-links {
  display: grid;
  gap: 3px;
  padding: 0 0 14px;
}

.sheet-link {
  width: 100%;
  border: 0;
  border-left: 3px solid transparent;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  padding: 9px 10px 9px 14px;
  text-align: left;
  font-size: 14px;
  line-height: 1.28;
}

.sheet-link:hover {
  background: var(--panel);
}

.sheet-link.is-active {
  border-left-color: var(--accent);
  background: var(--accent-soft);
  color: #0c4d67;
  font-weight: 700;
}

.main-content {
  min-width: 0;
  padding: 28px clamp(20px, 4vw, 64px) 48px;
}

.viewer-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  max-width: 900px;
  margin: 0 auto 18px;
}

.viewer-header > div {
  min-width: 0;
}

.current-theme {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.viewer-header h1 {
  margin: 0;
  font-size: clamp(24px, 3vw, 40px);
  letter-spacing: -0.045em;
  line-height: 1.02;
}

.pdf-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  border: 1px solid var(--ink);
  background: var(--paper);
  box-shadow: 4px 4px 0 var(--ink);
  color: var(--ink);
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-decoration: none;
}

.pdf-button:hover {
  background: var(--accent-soft);
}

.pdf-button svg {
  width: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: square;
  stroke-width: 1.8;
}

.pdf-button.is-disabled {
  opacity: 0.45;
  pointer-events: none;
}

.viewer {
  position: relative;
  width: min(100%, 900px);
  min-height: calc(100vh - 145px);
  margin: 0 auto;
  border: 1px solid var(--line);
  background:
    linear-gradient(rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0.78)),
    repeating-linear-gradient(0deg, transparent 0, transparent 25px, #d8d1c5 26px);
  box-shadow: 0 18px 48px rgba(61, 52, 39, 0.15);
  padding: clamp(12px, 3vw, 34px);
}

.viewer iframe {
  display: block;
  width: 100%;
  min-height: 820px;
  border: 0;
  background: var(--paper);
}

.viewer-status {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  color: var(--muted);
  font-family: Georgia, 'Times New Roman', serif;
}

.mobile-header,
.menu-backdrop {
  display: none;
}

@media (max-width: 760px) {
  .mobile-header {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 58px;
    border-bottom: 1px solid var(--line);
    background: var(--paper);
    padding: 0 16px;
  }

  .mobile-brand {
    color: var(--ink);
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.045em;
    text-decoration: none;
  }

  .menu-button {
    display: grid;
    gap: 4px;
    width: 42px;
    border: 1px solid var(--ink);
    background: transparent;
    padding: 9px;
  }

  .menu-button > span:not(.sr-only) {
    display: block;
    height: 2px;
    background: var(--ink);
  }

  .site-shell {
    display: block;
    min-height: calc(100vh - 58px);
  }

  .sidebar {
    position: fixed;
    top: 58px;
    bottom: 0;
    left: 0;
    width: min(88vw, 340px);
    height: calc(100vh - 58px);
    transform: translateX(-105%);
    transition: transform 180ms ease;
    box-shadow: 18px 0 45px rgba(30, 27, 22, 0.2);
  }

  .sidebar .brand-block {
    display: none;
  }

  .sidebar .theme-list {
    padding-top: 0;
  }

  .menu-open .sidebar {
    transform: translateX(0);
  }

  .menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 15;
    border: 0;
    background: rgba(23, 22, 18, 0.48);
  }

  .menu-open .menu-backdrop {
    display: block;
  }

  .main-content {
    padding: 20px 10px 28px;
  }

  .viewer-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    padding: 0 6px;
  }

  .viewer-header h1 {
    font-size: 23px;
    overflow-wrap: anywhere;
  }

  .pdf-button {
    padding: 9px 10px;
    box-shadow: 3px 3px 0 var(--ink);
  }

  .viewer {
    min-height: calc(100vh - 150px);
    padding: 5px;
  }

  .viewer iframe {
    min-height: 700px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar {
    transition: none;
  }
}
