:root {
  --header-height: 64px;
  --sidebar-width: 340px;
  --bg: #f3f7fb;
  --panel: #ffffff;
  --text: #1d2939;
  --muted: #667085;
  --line: #d0d5dd;
  --accent: #1264a3;
  --accent-soft: #e6f4ff;
  --def-bg: #fff7e6;
  --formula-bg: #edf7ed;
  --principle-bg: #eaf2ff;
  --pitfall-bg: #fff0f0;
  --steps-bg: #eef9ff;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: radial-gradient(circle at 0 0, #e6f4ff 0, var(--bg) 42%), var(--bg);
  color: var(--text);
}

[id] { scroll-margin-top: calc(var(--header-height) + 14px); }
.hidden { display: none !important; }

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  display: grid;
  grid-template-columns: auto 1fr minmax(360px, 620px);
  gap: 14px;
  align-items: center;
  padding: 0 16px;
  color: #fff;
  z-index: 30;
  background: linear-gradient(120deg, #0f456f, #1264a3);
  box-shadow: 0 6px 16px rgba(15, 69, 111, 0.26);
}

.site-title {
  font-weight: 700;
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-wrap { position: relative; }

.search-controls {
  height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.36);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.92);
  color: #0b314f;
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  padding: 0 8px;
  gap: 8px;
}

.region-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  font-size: 13px;
  color: #1d3557;
}

#regionSelect {
  border: 1px solid #d0d5dd;
  border-radius: 6px;
  height: 28px;
  padding: 0 6px;
  background: #fff;
  color: #1d2939;
}

.search-sep {
  width: 1px;
  height: 22px;
  background: #d0d5dd;
}

#globalSearch {
  width: 100%;
  border: 0;
  height: 34px;
  background: transparent;
  color: #0b314f;
  padding: 0 2px;
  outline: none;
}

.search-panel {
  position: absolute;
  top: 46px;
  left: 0;
  right: 0;
  max-height: 58vh;
  overflow: auto;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 14px 30px rgba(16, 24, 40, 0.2);
  padding: 8px;
  z-index: 40;
}

.search-item {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
}

.search-item:hover {
  border-color: #b2ddff;
  background: #f5fbff;
}

.search-path { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.search-title { font-size: 14px; font-weight: 700; margin-bottom: 3px; }
.search-snippet { font-size: 13px; color: #344054; }

.sidebar-toggle {
  border: 1px solid rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-radius: 8px;
  height: 36px;
  width: 36px;
  cursor: pointer;
  font-size: 18px;
}

.sidebar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow: auto;
  z-index: 20;
  transform: translateX(-100%);
  transition: transform 0.24s ease;
  box-shadow: 12px 0 30px rgba(2, 10, 22, 0.22);
}

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

.sidebar-head {
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: #f9fafb;
  z-index: 1;
  padding: 12px;
}

.sidebar-head-title { font-weight: 700; font-size: 15px; margin-bottom: 8px; }

.collection-tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.collection-tab {
  border: 1px solid #d0d5dd;
  background: #fff;
  color: #344054;
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 13px;
  cursor: pointer;
}

.collection-tab.active {
  border-color: #53b1fd;
  background: #e9f5ff;
  color: #11467b;
  font-weight: 700;
}

.tree-nav { padding: 12px 10px 24px; }
.subject-index-list { display: grid; gap: 8px; }
.subject-index-item {
  width: 100%;
  border: 1px solid #d0d5dd;
  border-radius: 10px;
  background: #fff;
  color: #1d2939;
  cursor: pointer;
  font-size: 14px;
  text-align: left;
  padding: 10px 12px;
}

.subject-index-item:hover {
  border-color: #84caff;
  background: #f3f9ff;
  color: var(--accent);
}

.empty-note {
  border: 1px dashed #d0d5dd;
  border-radius: 10px;
  color: #667085;
  background: #fafafa;
  padding: 10px 12px;
  font-size: 13px;
}

.content { margin-top: var(--header-height); margin-left: 0; padding: 20px 24px 80px; }
.collection-block { margin-bottom: 22px; }
.collection-title { margin: 0 0 12px; font-size: 22px; color: #1f4f82; }
.subject-block, .chapter-block, .core-block, .detail-block { background: var(--panel); border: 1px solid #e4e7ec; border-radius: 12px; }
.subject-block { margin-bottom: 18px; box-shadow: 0 8px 24px rgba(16, 24, 40, 0.06); }
.subject-title-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0; padding: 14px 16px; background: linear-gradient(90deg, #eef8ff, #f8fbff); border-bottom: 1px solid #e4e7ec; }
.subject-title { margin: 0; font-size: 24px; }
.subject-collection-chip { border: 1px solid #b7d9f8; color: #195489; background: #eef7ff; border-radius: 999px; font-size: 12px; padding: 2px 10px; }
.chapter-block { margin: 14px 14px 18px; }
.chapter-title { margin: 0; padding: 12px 14px; border-bottom: 1px solid #e4e7ec; font-size: 20px; background: #fcfdff; }
.core-block { margin: 12px; }
.core-title { margin: 0; padding: 10px 12px; border-bottom: 1px solid #e4e7ec; font-size: 17px; background: #fff; }
.detail-block { margin: 10px; overflow: hidden; }
.detail-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: #fafafa; border-bottom: 1px solid #eceef2; padding: 8px 10px; }
.detail-title { margin: 0; font-size: 15px; }
.tag-list { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 11px; border-radius: 999px; border: 1px solid #d0d5dd; padding: 1px 8px; color: #475467; background: #fff; }
.detail-body {
  padding: 10px 12px 12px;
  line-height: 1.72;
  font-size: 14px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}
.detail-body p { margin: 8px 0; }
.detail-body ul, .detail-body ol { margin: 8px 0; padding-left: 22px; }
.detail-body pre { margin: 8px 0; padding: 10px; background: #0b2239; color: #f8fafc; overflow: auto; border-radius: 8px; }
.detail-body code { font-family: Consolas, "Courier New", monospace; background: #f2f4f7; border-radius: 4px; padding: 1px 5px; }
.detail-body pre code { background: transparent; padding: 0; }
.detail-body blockquote { margin: 8px 0; border-left: 4px solid #91caff; background: #f3f9ff; padding: 8px 10px; }
.detail-body table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 13px;
}
.detail-body th, .detail-body td { border: 1px solid #d0d5dd; padding: 6px 8px; }
.detail-body th { background: #f5f7fa; }
.kw { font-weight: 700; border-radius: 5px; padding: 0 4px; margin: 0 1px; }
.kw.definition { background: var(--def-bg); color: #8a5b00; }
.kw.formula { background: var(--formula-bg); color: #1d6f34; }
.kw.principle { background: var(--principle-bg); color: #1e4e8c; }
.kw.pitfall { background: var(--pitfall-bg); color: #9a1d1d; }
.kw.steps { background: var(--steps-bg); color: #0b5f79; }
.target-flash { animation: flash 1.2s ease; }
@keyframes flash { 0% { box-shadow: 0 0 0 0 rgba(18, 100, 163, 0.35); } 100% { box-shadow: 0 0 0 12px rgba(18, 100, 163, 0); } }
.sidebar-mask { display: none; position: fixed; inset: var(--header-height) 0 0 0; background: rgba(0, 0, 0, 0.34); z-index: 15; }
body.sidebar-open .sidebar-mask { display: block; }

@media (max-width: 980px) {
  :root { --sidebar-width: 300px; }
  .topbar { grid-template-columns: auto 1fr; grid-template-rows: 1fr 1fr; height: auto; min-height: var(--header-height); padding: 8px 12px; gap: 8px 10px; }
  .site-title { font-size: 15px; padding-right: 126px; }
  .search-wrap { grid-column: 1 / -1; }
  .search-controls { position: relative; grid-template-columns: 1fr; height: auto; padding: 6px; gap: 6px; }
  .region-control {
    position: absolute;
    top: -44px;
    right: 0;
    height: 32px;
    padding: 0 4px 0 8px;
    border: 1px solid rgba(255, 255, 255, 0.52);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    backdrop-filter: blur(2px);
  }
  .region-control label { display: none; }
  #regionSelect {
    min-width: 84px;
    height: 26px;
    border: 1px solid rgba(255, 255, 255, 0.7);
    background: rgba(255, 255, 255, 0.96);
  }
  .search-sep { display: none; }
  #globalSearch { border: 1px solid #d0d5dd; border-radius: 6px; background: #fff; padding: 0 8px; }
  .detail-body { touch-action: pan-x pan-y; }
  .detail-body table { min-width: 680px; }
  .detail-body th, .detail-body td { white-space: nowrap; }
  .subject-title { font-size: 20px; }
  .content { margin-left: 0; padding: calc(var(--header-height) + 8px) 12px 46px; }
}

@media (max-width: 420px) {
  .site-title { padding-right: 108px; }
  .region-control { top: -42px; }
  #regionSelect { min-width: 76px; }
}
