:root {
  --bg: #eef2ef;
  --panel: #ffffff;
  --panel-soft: #f7f9f6;
  --ink: #16201b;
  --muted: #64716b;
  --line: #d9e0da;
  --green: #78ad48;
  --forest: #245c38;
  --blue: #2c5f7f;
  --amber: #d89a33;
  --shadow: 0 18px 42px rgba(20, 31, 25, 0.15);
  --page-width: 900px;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
}

button,
input,
a {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.app {
  display: flex;
  min-height: 100dvh;
}

.sidebar {
  width: 372px;
  min-width: 372px;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--panel);
  z-index: 40;
}

.sidebar-head {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 16px;
  padding: 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
}

.cover-thumb {
  width: 92px;
  height: auto;
  border-radius: 6px;
  box-shadow: 0 10px 24px rgba(20, 31, 25, 0.18);
}

.report-id {
  min-width: 0;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 9px;
  border: 1px solid rgba(120, 173, 72, 0.35);
  border-radius: 999px;
  color: var(--forest);
  background: rgba(120, 173, 72, 0.12);
  font-size: 0.78rem;
  font-weight: 700;
}

h1 {
  margin: 10px 0 8px;
  font-size: 1.18rem;
  line-height: 1.2;
}

.report-id p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.35;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.summary-strip div {
  min-width: 0;
  padding: 10px 8px;
  border-radius: 8px;
  background: var(--panel-soft);
}

.summary-strip strong,
.summary-strip span {
  display: block;
  text-align: center;
}

.summary-strip strong {
  color: var(--forest);
  font-size: 1.08rem;
}

.summary-strip span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.75rem;
}

.side-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--line);
}

.tab-button,
.text-button,
.icon-button,
.menu-button,
.pdf-link {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  transition: border-color 0.18s ease, background 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.tab-button:hover,
.text-button:hover,
.icon-button:hover,
.menu-button:hover,
.pdf-link:hover {
  border-color: rgba(36, 92, 56, 0.45);
  background: rgba(120, 173, 72, 0.1);
}

.tab-button.is-active {
  border-color: rgba(36, 92, 56, 0.5);
  background: var(--forest);
  color: #ffffff;
}

.side-panel {
  display: none;
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 12px;
}

.side-panel.is-active {
  display: block;
}

.toc-link {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  width: 100%;
  min-height: 40px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--ink);
  text-decoration: none;
}

.toc-link:hover,
.toc-link.is-active {
  border-color: rgba(120, 173, 72, 0.35);
  background: rgba(120, 173, 72, 0.11);
}

.toc-link.level-1 {
  padding-left: 22px;
}

.toc-title {
  overflow-wrap: anywhere;
  font-size: 0.92rem;
  line-height: 1.25;
}

.toc-page {
  color: var(--muted);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.thumb-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.thumb-link {
  position: relative;
  display: block;
  border: 2px solid transparent;
  border-radius: 8px;
  overflow: hidden;
  background: #ffffff;
  box-shadow: 0 6px 16px rgba(20, 31, 25, 0.08);
}

.thumb-link:hover,
.thumb-link.is-active {
  border-color: var(--green);
}

.thumb-link img {
  display: block;
  width: 100%;
  height: auto;
}

.thumb-link span {
  position: absolute;
  right: 5px;
  bottom: 5px;
  min-width: 26px;
  padding: 2px 5px;
  border-radius: 999px;
  background: rgba(22, 32, 27, 0.82);
  color: #ffffff;
  text-align: center;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}

.reader {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 100dvh;
  overflow: auto;
}

.topbar {
  position: sticky;
  top: 0;
  display: grid;
  grid-template-columns: auto minmax(160px, 1fr) auto;
  gap: 14px;
  align-items: center;
  min-height: 74px;
  padding: 12px 18px;
  border-bottom: 1px solid rgba(217, 224, 218, 0.95);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(14px);
  z-index: 30;
}

.menu-button {
  display: none;
  padding: 0 14px;
  font-weight: 700;
}

.top-title {
  min-width: 0;
}

.top-title span,
.top-title strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-title span {
  color: var(--forest);
  font-size: 0.95rem;
  font-weight: 700;
}

.top-title strong {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.86rem;
}

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

.search-box {
  position: relative;
  display: block;
}

.search-box input {
  width: 230px;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  background: var(--panel-soft);
  color: var(--ink);
}

.search-box input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(44, 95, 127, 0.14);
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 5px;
}

.icon-button {
  width: 38px;
  padding: 0;
  font-size: 1.08rem;
  font-weight: 800;
}

.text-button {
  padding: 0 12px;
  font-weight: 700;
}

.page-jump {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--muted);
  white-space: nowrap;
}

.page-jump input {
  width: 58px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.pdf-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  padding: 0 12px;
  font-weight: 800;
  color: #ffffff;
  border-color: var(--forest);
  background: var(--forest);
}

.pdf-link:hover {
  color: #ffffff;
  background: #1d4d30;
}

.search-results {
  position: sticky;
  top: 74px;
  z-index: 20;
  margin: 14px auto 0;
  width: min(var(--page-width), calc(100% - 40px));
  max-height: 330px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.search-results-head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.result-list {
  padding: 6px;
}

.result-item {
  width: 100%;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.result-item:hover {
  border-color: rgba(44, 95, 127, 0.25);
  background: rgba(44, 95, 127, 0.08);
}

.result-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.92rem;
  font-weight: 800;
}

.result-title span:last-child {
  color: var(--blue);
  font-variant-numeric: tabular-nums;
}

.result-snippet {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
}

.pages {
  display: grid;
  gap: 26px;
  justify-items: center;
  padding: 26px 20px 44px;
}

.page-card {
  width: min(var(--page-width), calc(100vw - 420px));
  min-width: 320px;
  scroll-margin-top: 96px;
}

.page-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 36px;
  padding: 0 3px 8px;
  color: var(--muted);
  font-size: 0.86rem;
}

.page-meta strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--forest);
}

.page-meta span {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.page-image {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.noscript {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 360px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

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

@media (max-width: 1220px) {
  .topbar {
    grid-template-columns: minmax(130px, 1fr);
    align-items: start;
  }

  .controls {
    flex-wrap: wrap;
  }

  .search-box input {
    width: 260px;
  }

  .page-card {
    width: min(var(--page-width), calc(100vw - 420px));
  }
}

@media (max-width: 920px) {
  .app {
    display: block;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(372px, calc(100vw - 34px));
    min-width: 0;
    transform: translateX(-104%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }

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

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(22, 32, 27, 0.45);
    z-index: 35;
  }

  .menu-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .topbar {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 10px;
  }

  .controls {
    grid-column: 1 / -1;
  }

  .reader {
    height: 100dvh;
  }

  .search-results {
    top: 122px;
    width: calc(100% - 24px);
  }

  .pages {
    padding: 18px 12px 34px;
  }

  .page-card {
    width: min(var(--page-width), calc(100vw - 24px));
    min-width: 0;
  }
}

@media (max-width: 620px) {
  body {
    font-size: 15px;
  }

  .topbar {
    padding: 10px;
  }

  .controls {
    display: grid;
    grid-template-columns: 1fr auto;
    width: 100%;
  }

  .search-box {
    grid-column: 1 / -1;
  }

  .search-box input {
    width: 100%;
  }

  .zoom-controls {
    grid-column: 1 / 2;
  }

  .page-jump,
  .pdf-link {
    justify-self: end;
  }

  .page-jump {
    grid-column: 2 / 3;
    grid-row: 2 / 3;
  }

  .pdf-link {
    grid-column: 2 / 3;
    grid-row: 3 / 4;
  }

  .page-meta {
    align-items: start;
    flex-direction: column;
    gap: 3px;
  }
}

@media print {
  .sidebar,
  .topbar,
  .search-results,
  .sidebar-backdrop {
    display: none !important;
  }

  .reader {
    height: auto;
    overflow: visible;
  }

  .pages {
    padding: 0;
    gap: 0;
  }

  .page-card {
    width: 100%;
    min-width: 0;
    page-break-after: always;
  }

  .page-meta {
    display: none;
  }

  .page-image {
    box-shadow: none;
    border-radius: 0;
  }
}
