/* ===== Reset & Base ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Source Han Sans SC", sans-serif;
  font-size: 15px;
  line-height: 1.8;
  color: #333;
  background: #f5f5f5;
}

a {
  color: #0078d4;
  text-decoration: none;
}

a:hover {
  color: #005a9e;
  text-decoration: underline;
}

/* ===== Header ===== */
.header {
  background: linear-gradient(135deg, #2e7d32, #43a047);
  color: #fff;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.header .logo {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #fff;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.header .logo:hover {
  text-decoration: none;
  opacity: 0.9;
}

.header .logo-icon {
  font-size: 24px;
}

.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-right a {
  color: rgba(255,255,255,0.85);
  font-size: 14px;
}

.header-right a:hover {
  color: #fff;
  text-decoration: none;
}

.site-search {
  position: relative;
  width: min(34vw, 360px);
}

.site-search-input {
  width: 100%;
  height: 34px;
  border: 1px solid rgba(255,255,255,0.35);
  border-radius: 18px;
  background: rgba(255,255,255,0.14);
  color: #fff;
  padding: 0 14px;
  outline: none;
  font: 14px/1.4 "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.site-search-input::placeholder {
  color: rgba(255,255,255,0.78);
}

.site-search-input:focus {
  background: #fff;
  border-color: #fff;
  color: #1f2933;
  box-shadow: 0 4px 16px rgba(0,0,0,0.16);
}

.site-search-results {
  display: none;
  position: absolute;
  top: 42px;
  right: 0;
  width: min(520px, calc(100vw - 32px));
  max-height: min(70vh, 520px);
  overflow-y: auto;
  background: #fff;
  border: 1px solid #dfe6dd;
  border-radius: 10px;
  box-shadow: 0 14px 36px rgba(0,0,0,0.18);
  padding: 8px;
  z-index: 1200;
}

.site-search-results.show {
  display: block;
}

.site-search-result {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  color: #333;
}

.site-search-result:hover {
  background: #f0f7f0;
  color: #1b5e20;
  text-decoration: none;
}

.site-search-result strong {
  display: block;
  font-size: 14px;
  line-height: 1.4;
  margin-bottom: 4px;
}

.site-search-result span,
.site-search-empty {
  display: block;
  color: #667085;
  font-size: 12px;
  line-height: 1.6;
}

.site-search-empty {
  padding: 12px;
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: #fff;
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px;
}

/* ===== Layout ===== */
.layout {
  display: flex;
  margin-top: 56px;
  min-height: calc(100vh - 56px);
}

/* ===== Sidebar ===== */
.sidebar {
  width: 280px;
  min-width: 280px;
  background: #fff;
  border-right: 1px solid #e0e0e0;
  position: fixed;
  top: 56px;
  bottom: 0;
  left: 0;
  overflow-y: auto;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

.sidebar-header {
  padding: 16px 20px;
  font-size: 14px;
  font-weight: 700;
  color: #2e7d32;
  border-bottom: 1px solid #e8e8e8;
  background: #fafafa;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sidebar-nav {
  padding: 8px 0;
}

.nav-group {
  border-bottom: 1px solid #f0f0f0;
}

.nav-group:last-child {
  border-bottom: none;
}

.nav-group-title {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  color: #444;
  cursor: pointer;
  transition: background 0.2s;
  user-select: none;
}

.nav-title-text {
  min-width: 0;
}

.nav-group-title:hover {
  background: #f5f5f5;
}

.nav-group-title .arrow {
  margin-left: auto;
  font-size: 10px;
  transition: transform 0.2s;
  color: #999;
}

.nav-group-title.active .arrow {
  transform: rotate(90deg);
}

.nav-group-title.current {
  color: #2e7d32;
  background: #e8f5e9;
}

.nav-sub {
  display: none;
  padding: 0;
  list-style: none;
}

.nav-sub.show {
  display: block;
}

.nav-sub li a {
  display: block;
  padding: 6px 20px 6px 40px;
  font-size: 13px;
  color: #666;
  transition: all 0.2s;
  border-left: 3px solid transparent;
}

.nav-sub li a:hover {
  background: #f0f7f0;
  color: #2e7d32;
  text-decoration: none;
}

.nav-sub li a.active {
  color: #2e7d32;
  background: #e8f5e9;
  border-left-color: #2e7d32;
  font-weight: 600;
}

/* ===== Main Content ===== */
.main-content {
  margin-left: 280px;
  flex: 1;
  padding: 32px 40px 60px;
  max-width: 900px;
}

.chapter-badge {
  display: inline-block;
  background: #2e7d32;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 3px 12px;
  border-radius: 4px;
  margin-bottom: 8px;
}

.chapter-title {
  font-size: 28px;
  font-weight: 700;
  color: #1a1a1a;
  margin-bottom: 8px;
  line-height: 1.3;
}

.chapter-meta {
  font-size: 13px;
  color: #999;
  margin-bottom: 12px;
  padding-bottom: 20px;
  border-bottom: 2px solid #e8f5e9;
}

.chapter-intro {
  font-size: 15px;
  color: #555;
  background: #f8fdf8;
  border-left: 4px solid #43a047;
  padding: 16px 20px;
  margin-bottom: 32px;
  border-radius: 0 4px 4px 0;
}

/* Section headings */
.section-heading {
  display: flex;
  align-items: center;
  margin: 40px 0 20px;
  padding-bottom: 10px;
  border-bottom: 2px solid #e0e0e0;
}

.section-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0097a7, #00acc1);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  padding: 4px 14px;
  border-radius: 4px;
  margin-right: 12px;
  white-space: nowrap;
}

.section-heading h2 {
  font-size: 22px;
  font-weight: 700;
  color: #00838f;
}

/* Sub-section headings */
.subsection-heading {
  font-size: 18px;
  font-weight: 700;
  color: #00838f;
  margin: 28px 0 14px;
}

.subsection-heading::before {
  content: "";
  display: inline-block;
  width: 4px;
  height: 18px;
  background: #00acc1;
  margin-right: 8px;
  vertical-align: middle;
  border-radius: 2px;
}

/* Text content */
.content-text {
  margin-bottom: 16px;
  line-height: 1.9;
  color: #444;
}

.content-text strong {
  color: #d32f2f;
}

.highlight {
  color: #d32f2f;
  font-weight: 600;
}

/* Lists */
.content-list {
  padding-left: 24px;
  margin-bottom: 16px;
}

.content-list li {
  margin-bottom: 6px;
  line-height: 1.8;
}

.param-list {
  list-style: none;
  padding: 0;
  margin-bottom: 16px;
}

.param-list li {
  padding: 6px 0 6px 24px;
  position: relative;
  line-height: 1.8;
}

.param-list li::before {
  content: "\2610";
  position: absolute;
  left: 0;
  color: #0097a7;
}

/* Code blocks */
.code-syntax {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-left: 4px solid #43a047;
  padding: 12px 16px;
  margin: 12px 0 16px;
  font-family: "Cascadia Mono", "Consolas", "Source Code Pro", "Fira Code", "Microsoft YaHei UI", monospace;
  font-size: 14px;
  color: #2e7d32;
  border-radius: 0 4px 4px 0;
  overflow-x: auto;
  white-space: pre-wrap;
}

.code-block {
  background: #263238;
  color: #eeffff;
  padding: 42px 20px 16px;
  border-radius: 6px;
  margin: 12px 0 20px;
  font-family: "Cascadia Mono", "Consolas", "Source Code Pro", "Fira Code", "Microsoft YaHei UI", monospace;
  font-size: 13px;
  line-height: 1.7;
  overflow-x: auto;
  position: relative;
  white-space: pre;
}

.code-copy-button {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 4px;
  background: rgba(255,255,255,0.09);
  color: #e8f5e9;
  font: 700 12px/1 "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;
  padding: 7px 10px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.code-copy-button:hover {
  background: rgba(255,255,255,0.16);
  border-color: rgba(255,255,255,0.32);
}

.code-copy-button.copied {
  background: #43a047;
  border-color: #66bb6a;
  color: #fff;
}

.code-block .line-num {
  color: #546e7a;
  user-select: none;
  display: inline-block;
  width: 28px;
  text-align: right;
  margin-right: 16px;
}

.code-block .comment {
  color: #546e7a;
}

.code-block .keyword {
  color: #c792ea;
}

.code-block .string {
  color: #c3e88d;
}

.code-block .function {
  color: #82aaff;
}

.code-block .builtin {
  color: #ffcb6b;
}

.code-title {
  font-size: 14px;
  font-weight: 700;
  color: #e65100;
  margin: 20px 0 4px;
}

.code-title::before {
  content: "\25B6";
  margin-right: 6px;
  font-size: 10px;
}

/* Result box */
.result-box {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  margin: 12px 0 20px;
  overflow: hidden;
}

.result-box-header {
  background: #ff8f00;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  padding: 6px 14px;
  display: inline-block;
  border-radius: 0 0 6px 0;
}

.result-box-content {
  padding: 12px 16px;
  font-family: "Cascadia Mono", "Consolas", "Microsoft YaHei UI", monospace;
  font-size: 13px;
  color: #333;
  background: #fafafa;
}

.result-box-content.result-output {
  white-space: pre;
  overflow-x: auto;
}

.chapter-output-pre .result-box-content {
  white-space: pre;
  overflow-x: auto;
}

.result-box-image {
  padding: 16px;
  background: #fafafa;
  text-align: center;
}

.result-box-image img {
  max-width: 100%;
  border: 1px solid #ddd;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.result-box-image .caption {
  margin-top: 8px;
  font-size: 12px;
  color: #888;
}

/* Tables */
.content-table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0 20px;
  font-size: 14px;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.content-table thead th {
  background: #e0f2f1;
  color: #00695c;
  font-weight: 700;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 2px solid #b2dfdb;
}

.content-table tbody td {
  padding: 9px 14px;
  border-bottom: 1px solid #e8e8e8;
  vertical-align: top;
}

.content-table tbody tr:hover {
  background: #f5f5f5;
}

.content-table code {
  background: #e8f5e9;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 13px;
  color: #2e7d32;
}

/* Note box */
.note-box {
  display: flex;
  gap: 10px;
  background: #fff3e0;
  border: 1px solid #ffe0b2;
  border-radius: 6px;
  padding: 12px 16px;
  margin: 12px 0 20px;
  font-size: 14px;
}

.note-box .note-icon {
  background: #ff8f00;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 3px;
  height: fit-content;
  white-space: nowrap;
}

/* Exercise box */
.exercise-box {
  background: #fff;
  border: 2px solid #ef5350;
  border-radius: 6px;
  margin: 24px 0;
  overflow: hidden;
}

.exercise-box-header {
  background: #ef5350;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  padding: 6px 16px;
  display: inline-block;
  border-radius: 0 0 6px 0;
}

.exercise-box-content {
  padding: 16px 20px;
}

/* Navigation footer */
.page-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 2px solid #e0e0e0;
}

.page-nav a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  font-size: 14px;
  color: #444;
  transition: all 0.2s;
}

.page-nav a:hover {
  border-color: #43a047;
  color: #2e7d32;
  text-decoration: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.page-nav .nav-label {
  font-size: 12px;
  color: #999;
}

.page-nav .nav-title {
  font-weight: 600;
}

/* ===== Footer ===== */
.footer {
  margin-left: 280px;
  background: #fff;
  border-top: 1px solid #e0e0e0;
  padding: 20px 40px;
  text-align: center;
  font-size: 13px;
  color: #999;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .menu-toggle {
    display: block;
  }

  .header {
    padding: 0 12px;
    gap: 8px;
  }

  .header .logo {
    font-size: 16px;
    letter-spacing: 0;
  }

  .header .logo-icon {
    display: none;
  }

  .header-right {
    flex: 1;
    min-width: 0;
    gap: 8px;
  }

  .header-right > a:not(.workbench-home-link) {
    display: none;
  }

  .workbench-home-link {
    flex: none;
    font-size: 12px;
    white-space: nowrap;
  }

  .site-search {
    width: 100%;
  }

  .site-search-results {
    position: fixed;
    top: 56px;
    left: 8px;
    right: 8px;
    width: auto;
    max-height: 60vh;
  }

  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 16px rgba(0,0,0,0.15);
  }

  .main-content {
    margin-left: 0;
    padding: 24px 16px 40px;
  }

  .footer {
    margin-left: 0;
  }

  .chapter-title {
    font-size: 22px;
  }

  .section-heading h2 {
    font-size: 18px;
  }

  .overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 99;
  }

  .overlay.show {
    display: block;
  }
}

/* inline code */
code {
  background: #e8f5e9;
  padding: 2px 6px;
  border-radius: 3px;
  font-family: "Cascadia Mono", "Consolas", "Source Code Pro", "Microsoft YaHei UI", monospace;
  font-size: 0.9em;
  color: #2e7d32;
}
