:root {
  --bg: #faf9f6;
  --card-bg: #fff;
  --accent: #8b4513;
  --accent-light: #f5efe6;
  --text: #2c2c2c;
  --text-light: #666;
  --border: #e8e0d4;
  --summary-bg: #fdf8f0;
  --key-bg: #f0e6d3;
  --tag-bg: #e8ddd0;
  --tag-text: #6b4c2a;
  --sidebar-width: 220px;
  --top-nav-height: 52px;
  --header-height: 48px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: "Noto Serif SC", "Source Han Serif SC", "STSong", Georgia, serif;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
}

/* ========== SIDEBAR (narrower) ========== */
.sidebar {
  position: fixed;
  top: var(--top-nav-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--card-bg);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 90;
  padding: 14px 0;
  transition: transform 0.3s ease;
}

.sidebar::-webkit-scrollbar { width: 3px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.sidebar-title {
  padding: 0 16px 10px;
  font-size: 0.72em;
  color: var(--text-light);
  letter-spacing: 0.12em;
  font-weight: 600;
}

.toc-list { list-style: none; }

.toc-item a {
  display: block;
  padding: 6px 16px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.82em;
  line-height: 1.45;
  border-left: 3px solid transparent;
  transition: all 0.2s;
}

.toc-item a:hover {
  background: var(--accent-light);
  color: var(--accent);
}

.toc-item a.active {
  border-left-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
  background: var(--accent-light);
}

.toc-item.level-2 a {
  padding-left: 30px;
  font-size: 0.78em;
  color: var(--text-light);
}

.toc-toggle {
  display: inline-block;
  width: 14px;
  text-align: center;
  font-size: 0.65em;
  color: var(--text-light);
  margin-right: 2px;
  cursor: pointer;
  transition: transform 0.2s;
}
.toc-toggle.collapsed { transform: rotate(-90deg); }

.toc-children {
  overflow: hidden;
  transition: max-height 0.3s ease;
}
.toc-children.collapsed { max-height: 0 !important; }

/* ========== MAIN CONTENT ========== */
.main-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
}

/* Page hero — compact */
.page-hero {
  margin-left: var(--sidebar-width);
  margin-top: var(--top-nav-height);
  padding: 16px 28px 18px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #f5efe6 0%, var(--bg) 100%);
}

.page-hero .hero-left {
  max-width: 1300px;
  margin: 0 auto;
}

.page-hero .hero-left h1 {
  font-size: 1.5em;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.12em;
  margin-bottom: 4px;
}

.page-hero .subtitle {
  font-size: 0.85em;
  color: var(--text-light);
  letter-spacing: 0.08em;
}


.page-hero .breadcrumb {
  font-size: 0.78em;
  color: var(--text-light);
  margin-bottom: 4px;
}
.page-hero .breadcrumb a { color: var(--accent); text-decoration: none; }
.page-hero .breadcrumb a:hover { text-decoration: underline; }

/* Hexagram group navigation */
.hex-nav {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 0;
  position: relative;
  z-index: 120;
}

.hex-nav-fallback {
  color: var(--text-light);
  font-size: 0.78em;
  letter-spacing: 0.1em;
}

.hex-nav-group {
  position: relative;
  min-width: 0;
}

.hex-nav-trigger {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  padding: 6px 8px;
  background: rgba(255,255,255,0.72);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: all 0.2s ease;
}

.hex-nav-trigger span,
.hex-nav-trigger strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hex-nav-trigger span {
  font-size: 0.68em;
  color: var(--text-light);
  line-height: 1.2;
}

.hex-nav-trigger strong {
  margin-top: 2px;
  font-size: 0.78em;
  font-weight: 600;
  color: var(--accent);
}

.hex-nav-group.active .hex-nav-trigger,
.hex-nav-group:hover .hex-nav-trigger,
.hex-nav-group:focus-within .hex-nav-trigger {
  background: var(--card-bg);
  border-color: rgba(139,69,19,0.35);
  box-shadow: 0 4px 14px rgba(139,69,19,0.08);
}

.hex-nav-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 168px;
  padding: 6px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 14px 30px rgba(80,50,20,0.14);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 0.16s ease, transform 0.16s ease, visibility 0.16s ease;
}

.hex-nav-group:nth-last-child(-n+2) .hex-nav-menu {
  left: auto;
  right: 0;
}

.hex-nav-group:hover .hex-nav-menu,
.hex-nav-group:focus-within .hex-nav-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.hex-nav-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 8px;
  border-radius: 4px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.78em;
  line-height: 1.35;
}

.hex-nav-item small {
  color: var(--text-light);
  font-size: 0.92em;
  white-space: nowrap;
}

.hex-nav-item:hover,
.hex-nav-item.current {
  background: var(--accent-light);
  color: var(--accent);
}

.hex-nav-item.disabled {
  color: #aaa;
  cursor: default;
}


/* ========== TOP NAV (64 hexagram global navigation) ========== */
.top-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 200;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 6px 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.home-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 12px;
  color: var(--accent);
  background: var(--accent-light);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.78em;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.home-link:hover {
  border-color: rgba(139,69,19,0.35);
  background: var(--card-bg);
}

.top-nav .hex-nav {
  max-width: 1360px;
  width: 100%;
  margin: 0;
}

.top-nav .hex-nav-trigger {
  min-height: 36px;
  padding: 3px 6px;
}

.top-nav .hex-nav-trigger span {
  font-size: 0.62em;
}

.top-nav .hex-nav-trigger strong {
  font-size: 0.7em;
  margin-top: 1px;
}
/* Expand/collapse all button */
.expand-all {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 130;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  font-size: 0.78em;
  color: var(--accent);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  box-shadow: 0 10px 24px rgba(80,50,20,0.14);
}
.expand-all:hover {
  background: var(--accent-light);
  border-color: var(--accent);
  transform: translateY(-1px);
}
.expand-all .icon { font-size: 0.85em; }

/* Content container */
.content-container {
  max-width: 1300px;
  margin: 0 auto;
  padding: 16px 20px 32px;
}

/* ========== SECTION HEADER (new — light + accordion toggle) ========== */
.section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  margin-top: 20px;
  font-size: 0.92em;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-light);
  border-left: 4px solid var(--accent);
  cursor: pointer;
  user-select: none;
  scroll-margin-top: 12px;
  transition: background 0.2s;
  border-radius: 0 4px 4px 0;
}
.section-header:hover {
  background: #efe5d6;
}
.section-header:first-child { margin-top: 0; }

/* Sub-section header (e.g. 2.1, 5.2) — slightly lighter */
.section-header.sub {
  margin-top: 0;
  border-left: 3px solid var(--border);
  background: transparent;
  font-size: 0.85em;
  font-weight: 500;
  color: var(--text-light);
  padding: 8px 18px 8px 22px;
}
.section-header.sub:hover {
  background: var(--accent-light);
}

/* Toggle arrow */
.section-header .toggle-arrow {
  display: inline-block;
  width: 16px;
  font-size: 0.7em;
  transition: transform 0.25s ease;
  flex-shrink: 0;
  color: var(--accent);
  opacity: 0.6;
}
.section-header.collapsed .toggle-arrow {
  transform: rotate(-90deg);
}
.section-header.sub .toggle-arrow {
  width: 14px;
  font-size: 0.6em;
}

/* ========== ROW (compact) ========== */
.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border-bottom: 1px solid var(--border);
  scroll-margin-top: 12px;
  overflow: hidden;
  transition: max-height 0.35s ease, opacity 0.25s ease, padding 0.35s ease;
}
.row.collapsed {
  max-height: 0;
  opacity: 0;
  border-bottom: none;
}

.left, .right {
  padding: 16px 18px;
}

.left {
  border-right: 1px solid var(--border);
  background: var(--card-bg);
  font-size: 0.84em;
  color: #444;
  line-height: 1.8;
}

.right {
  background: var(--summary-bg);
  padding: 16px 20px;
}

/* Transcript */
.left .timestamp {
  display: inline-block;
  font-size: 0.72em;
  color: var(--accent);
  background: var(--accent-light);
  padding: 2px 8px;
  border-radius: 3px;
  margin-bottom: 8px;
  font-family: "SF Mono", "Menlo", monospace;
}

.left .transcript {
  white-space: pre-wrap;
  word-break: break-all;
}

/* Notes */
.right h3 {
  font-size: 0.95em;
  color: var(--accent);
  margin-bottom: 8px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.right .point {
  margin-bottom: 8px;
  padding-left: 14px;
  position: relative;
  font-size: 0.83em;
  line-height: 1.6;
}

.right .point::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  width: 5px;
  height: 5px;
  background: var(--accent);
  border-radius: 50%;
}

.right .key {
  display: inline;
  background: var(--key-bg);
  padding: 1px 5px;
  border-radius: 3px;
  font-weight: 600;
  color: var(--accent);
}

.right .tag {
  display: inline-block;
  font-size: 0.74em;
  background: var(--tag-bg);
  color: var(--tag-text);
  padding: 1px 7px;
  border-radius: 3px;
  margin-right: 4px;
  margin-bottom: 2px;
}

.right .quote {
  border-left: 3px solid var(--accent);
  padding: 6px 12px;
  margin: 8px 0;
  background: rgba(139,69,19,0.04);
  font-style: italic;
  color: #555;
  font-size: 0.82em;
}

.right .warn {
  background: #fff3e0;
  border-left: 3px solid #e65100;
  padding: 6px 12px;
  margin: 8px 0;
  font-size: 0.82em;
  color: #bf360c;
}

.right .formula {
  font-family: "SF Mono", "Menlo", monospace;
  background: #f5f0e8;
  padding: 8px 12px;
  border-radius: 4px;
  margin: 8px 0;
  font-size: 0.82em;
  line-height: 1.6;
}

/* ========== SECTION GROUP (merged adjacent sections) ========== */
.section-group {
  border-left: 1px solid var(--border);
  margin-left: 12px;
}
.section-group .section-header {
  margin-top: 6px;
  border-left: none;
  background: transparent;
  padding: 7px 14px;
  font-size: 0.84em;
}
.section-group .section-header:first-child { margin-top: 0; }
.section-group .section-header:hover { background: var(--accent-light); }

/* ========== REDIRECT PAGE ========== */

.redirect-page a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

/* ========== FOOTER ========== */
.footer {
  text-align: center;
  padding: 24px 20px;
  color: var(--text-light);
  font-size: 0.76em;
  border-top: 1px solid var(--border);
  margin-top: 32px;
}

/* ========== MOBILE ========== */

/* ========== TAB BAR (summary/original toggle) ========== */
.tab-bar {
  display: flex;
  gap: 0;
  margin-left: var(--sidebar-width);
  padding: 0 28px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.tab-bar .tab {
  padding: 10px 24px;
  font-size: 0.85em;
  font-family: inherit;
  color: var(--text-light);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.04em;
}

.tab-bar .tab:hover {
  color: var(--accent);
  background: var(--accent-light);
}

.tab-bar .tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

/* ========== SUMMARY VIEW (knowledge framework) ========== */
.summary-view {
  margin-left: var(--sidebar-width);
  min-height: 60vh;
}

.summary-view .content-container {
  max-width: 900px;
}

.summary-section {
  margin-bottom: 32px;
}

.summary-section-title {
  font-size: 1.15em;
  font-weight: 700;
  color: var(--accent);
  padding: 10px 18px;
  margin-bottom: 16px;
  background: var(--accent-light);
  border-left: 4px solid var(--accent);
  letter-spacing: 0.06em;
}

.summary-topic {
  margin-bottom: 18px;
  padding-left: 18px;
}

.summary-topic-title {
  font-size: 0.92em;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.summary-point {
  padding: 5px 12px;
  margin-bottom: 4px;
  font-size: 0.88em;
  line-height: 1.65;
  border-left: 2px solid var(--border);
  color: var(--text);
}

.summary-point .key {
  color: var(--accent);
  font-weight: 600;
}

@media (max-width: 1024px) {
  .tab-bar { margin-left: 0; padding: 0 14px; }
  .summary-view { margin-left: 0; }
}

.menu-toggle {
  display: none;
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 110;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 1.1em;
  cursor: pointer;
  padding: 6px 10px;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 85;
}
.sidebar-overlay.active { display: block; }

@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
    top: var(--top-nav-height);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0,0,0,0.1);
  }
  .main-content { margin-left: 0; }
  .page-hero { margin-left: 0; }
  .menu-toggle { display: block; top: calc(var(--top-nav-height) + 8px); }
  .hex-nav { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .hex-nav-group:nth-child(4n) .hex-nav-menu {
    left: auto;
    right: 0;
  }
  .row { grid-template-columns: 1fr; }
  .left {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .right { padding: 16px 20px; }
}

@media (max-width: 900px) {
}

@media (max-width: 600px) {
  .page-hero h1 { font-size: 1.3em; }
  .hex-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hex-nav-menu {
    left: 0;
    right: auto;
    min-width: 150px;
  }
  .hex-nav-group:nth-child(even) .hex-nav-menu {
    left: auto;
    right: 0;
  }
  .expand-all {
    right: 14px;
    bottom: 14px;
    padding: 8px 12px;
  }
  .section-header { padding: 8px 14px; font-size: 0.85em; }
  .left, .right { padding: 14px; }
  .page-hero { padding: 16px 14px; }
  .content-container { padding: 10px 12px 24px; }
}
