:root {
  --serif: "Songti SC", "STSong", "Noto Serif CJK SC", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --body-text: #48554d;
  --bg: #f9f8f3;
  --bg-soft: #f5f6ee;
  --surface: #fffefb;
  --text: #263d36;
  --muted: #737e72;
  --accent: #3e7563;
  --accent-soft: rgba(62, 117, 99, 0.1);
  --active: #edf1e9;
  --border: #dddeda;
  --border-strong: #c7cec0;
  --radius: 6px;
  --shadow-sm: none;
  --shadow-md: none;
  --focus: 0 0 0 3px rgba(62, 117, 99, 0.18);
  --trans: 180ms ease;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--text);
  background: var(--bg);
  padding: 24px 16px 36px;
  line-height: 1.9;
}

.wrap {
  margin: 0 auto;
  animation: fadeIn 0.3s ease-out;
}

.wrap.is-catalog {
  max-width: 900px;
}

.wrap.is-doc-viewer {
  max-width: 1220px;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.top-nav {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 32px;
  flex-wrap: wrap;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
  line-height: 1.2;
  transition: background var(--trans), border-color var(--trans), color var(--trans);
}

.nav-external-icon {
  width: 12px;
  height: 12px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.72;
}

.nav-link:hover {
  background: var(--accent-soft);
}

.nav-link.active {
  color: var(--text);
  border-color: var(--border);
  background: var(--surface);
}

.nav-link:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.page-title {
  margin: 0 0 32px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
  font-family: var(--serif);
  font-size: 36px;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.hint-block {
  padding: 16px 18px;
}

.catalog-list {
  background: transparent;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}

.group-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0;
  padding: 10px 16px;
  border: 0;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  background: var(--bg-soft);
  cursor: pointer;
  text-align: left;
}

.group-toggle:hover {
  background: var(--active);
}

.group-toggle:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 1px var(--border-strong), var(--focus);
}

.group-caret {
  font-size: 12px;
  transition: transform var(--trans);
}

.group-toggle[aria-expanded="false"] .group-caret {
  transform: rotate(-90deg);
}

.doc-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.doc-list.is-collapsed {
  display: none;
}

.catalog-item {
  display: block;
  padding: 22px 18px;
  border-bottom: 1px solid var(--border);
  transition: background var(--trans), border-color var(--trans), box-shadow var(--trans);
  color: inherit;
  text-decoration: none;
}

.catalog-item:last-child {
  border-bottom: none;
}

.catalog-item:hover {
  background: var(--bg-soft);
}

.catalog-item:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 1px var(--border-strong), var(--focus);
}

.catalog-item-title {
  margin: 0 0 4px;
  color: var(--text);
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 500;
  line-height: 1.6;
}

.catalog-item-file {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-family: var(--mono);
}

.layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 32px;
  align-items: start;
}

button {
  font-family: inherit;
}

::selection {
  background: #dbe7d7;
}

.sidebar.card {
  border: 0;
  border-radius: 0;
  background: transparent;
}

.sidebar .group-toggle {
  background: transparent;
}

.sidebar .list-header-title,
.sidebar .doc-title {
  font-family: var(--serif);
}

.sidebar {
  position: sticky;
  top: 12px;
  max-height: calc(100dvh - 48px);
  overflow: auto;
}

.list-header {
  margin: 0;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.list-header-title {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.collapse-all-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--accent);
  font-size: 12px;
  line-height: 1.2;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: background var(--trans), border-color var(--trans), color var(--trans);
}

.collapse-all-btn:hover {
  background: var(--accent-soft);
  border-color: var(--border-strong);
}

.collapse-all-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.collapse-all-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.doc-btn {
  width: 100%;
  display: block;
  border: none;
  background: transparent;
  text-align: left;
  padding: 12px 14px;
  border-left: 2px solid transparent;
  cursor: pointer;
  color: var(--muted);
  transition: background var(--trans), color var(--trans);
}

.doc-btn:hover {
  background: var(--bg-soft);
  color: var(--text);
}

.doc-btn.active {
  border-left-color: var(--accent);
  background: var(--active);
  color: var(--accent);
}

.doc-btn:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 1px var(--border-strong), var(--focus);
}

.doc-title {
  margin: 0 0 3px;
  font-size: 14px;
  font-weight: 500;
}

.doc-file {
  margin: 0;
  opacity: 0.7;
  font-size: 11px;
  font-family: var(--mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.viewer {
  padding: 38px 44px;
  min-height: 700px;
  box-shadow: var(--shadow-md);
  font-size: 16px;
  color: var(--body-text);
  min-width: 0;
  overflow-wrap: anywhere;
}

.viewer.loading {
  opacity: 0.5;
}

.viewer.is-hidden {
  display: none;
}

.back-top {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--accent);
  border-radius: 999px;
  min-height: 38px;
  padding: 0 14px;
  font-size: 13px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity var(--trans), transform var(--trans), background var(--trans), border-color var(--trans);
}

.back-top.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.back-top:hover {
  background: var(--accent-soft);
}

.back-top:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

@media (max-width: 920px) {
  body {
    padding: 16px 12px 24px;
  }

  .layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 24px;
  }

  .sidebar {
    position: static;
    max-height: 42dvh;
  }

  .viewer {
    padding: 22px 18px;
    min-height: 55dvh;
  }

  .back-top {
    right: 12px;
    bottom: 12px;
  }
}

@media (max-width: 720px) {
  .page-title {
    font-size: 29px;
    padding-top: 24px;
    margin-bottom: 24px;
  }

  .catalog-item {
    padding: 18px 10px;
  }

  .catalog-item-title {
    font-size: 19px;
  }

  .top-nav {
    justify-content: flex-start;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
