:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #21262d;
  --line: #30363d;
  --txt: #e6edf3;
  --txt2: #9da7b3;
  --txt3: #6e7681;
  --accent: #58a6ff;
  --ok: #3fb950;
  --warn: #f0b72f;
  --bad: #ff7b72;
  --info: #58a6ff;
  --sans:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  --r: 10px;
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--txt);
  font-family: var(--sans);
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
}
body.light {
  --bg: #f6f8fa;
  --bg2: #fff;
  --bg3: #eaeef2;
  --line: #d0d7de;
  --txt: #1f2328;
  --txt2: #57606a;
  --txt3: #8c959f;
}
button {
  font-family: inherit;
  cursor: pointer;
}
input,
textarea,
select {
  font-family: inherit;
  background: var(--bg);
  color: var(--txt);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 15px;
  width: 100%;
}
input:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.muted {
  color: var(--txt2);
}
.small {
  font-size: 12px;
}
.err {
  color: var(--bad);
  font-size: 13px;
  min-height: 18px;
}
.primary {
  background: var(--accent);
  color: #001;
  border: none;
  border-radius: 8px;
  padding: 11px 16px;
  font-size: 15px;
  font-weight: 600;
  width: 100%;
}
.btn {
  background: var(--bg3);
  color: var(--txt);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
}
.btn:hover {
  border-color: var(--accent);
}
.btn.sm {
  padding: 5px 10px;
  font-size: 13px;
}

/* 修复：hidden 属性必须真正隐藏，否则空的 #modal/#toast 遮罩会盖住登录框 */
[hidden] {
  display: none !important;
}

/* 登录 */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}
.login-card {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 24px;
  width: 330px;
  max-width: 100%;
  text-align: center;
}
.login-card .logo {
  font-size: 26px;
  color: var(--accent);
}
.login-card h1 {
  font-size: 20px;
  margin: 8px 0 2px;
}
.login-card input {
  margin-top: 12px;
  text-align: left;
}
.login-card .primary {
  margin-top: 14px;
}
.login-card .muted {
  margin: 10px 0 0;
}

/* 顶栏 */
#top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg2);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 600;
  white-space: nowrap;
}
.brand .dot {
  color: var(--accent);
}
#search {
  max-width: 300px;
}
.spacer {
  flex: 1;
}
.acting {
  background: var(--warn);
  color: #000;
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px;
  white-space: nowrap;
}
.profile {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg3);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 5px 12px;
  color: var(--txt);
  font-size: 14px;
  white-space: nowrap;
}

/* 布局 */
#appbody {
  display: flex;
  height: calc(100vh - 53px);
}
#rail {
  width: 88px;
  flex: 0 0 88px;
  background: var(--bg2);
  border-right: 1px solid var(--line);
  padding: 8px 6px;
  overflow-y: auto;
}
.railbtn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 100%;
  background: none;
  border: none;
  color: var(--txt2);
  padding: 10px 4px;
  border-radius: 10px;
  font-size: 12px;
}
.railbtn .ic {
  font-size: 18px;
}
.railbtn.active {
  background: var(--bg3);
  color: var(--accent);
}
#content {
  flex: 1;
  overflow: auto;
  padding: 16px;
  position: relative;
}

/* 图谱 */
#graphWrap {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}
#graphBar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--bg2);
  flex-wrap: wrap;
}
#graph {
  flex: 1;
  min-height: 300px;
}
/* 三栏图谱：结构树 + 图谱 + 详解/做题 */
#graphWrap.three {
  flex-direction: row;
}
#treePane {
  flex: 0 0 232px;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: var(--bg2);
  padding: 6px;
}
#graphCenter {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}
#nodePane {
  flex: 0 0 372px;
  overflow: auto;
  border-left: 1px solid var(--line);
  padding: 14px 16px;
}
@media (max-width: 860px) {
  #treePane {
    display: none;
  }
  #nodePane {
    flex: 0 0 46%;
  }
}
.tree-subj {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
}
.tree-subj:hover {
  background: var(--bg3);
}
.tree-subj .dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: 0 0 10px;
}
.tree-ch {
  padding: 6px 8px;
  font-weight: 600;
  font-size: 12.5px;
  cursor: pointer;
}
.tree-ch:hover {
  background: var(--bg3);
}
.tree-sec {
  padding: 4px 8px 4px 16px;
  color: var(--txt2);
  font-size: 12px;
}
.tree-node {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 22px;
  color: var(--txt2);
  font-size: 12.5px;
  cursor: pointer;
  border-radius: 6px;
}
.tree-node:hover {
  background: var(--bg3);
}
.tree-node.active {
  background: var(--accent);
  color: #fff;
}
.tree-node .m-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 8px;
}
.np-empty {
  color: var(--txt2);
  text-align: center;
  padding: 40px 12px;
  font-size: 13px;
}
.np-bread {
  font-size: 11.5px;
  color: var(--txt2);
}
.np-title {
  font-size: 18px;
  font-weight: 700;
  margin: 4px 0 8px;
  line-height: 1.3;
}
.np-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.np-tabs {
  flex-wrap: wrap;
}
.np-body {
  margin-top: 10px;
}
.legend {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--txt2);
  padding: 6px 12px;
  background: var(--bg2);
  border-top: 1px solid var(--line);
}
.legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: -1px;
}

/* 卡片/通用 */
.card {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.row {
  display: flex;
  gap: 10px;
  align-items: center;
}
.tag {
  display: inline-block;
  background: var(--bg3);
  border-radius: 6px;
  padding: 3px 9px;
  font-size: 12px;
  color: var(--txt2);
  margin: 2px 4px 2px 0;
}
.tag.ok {
  background: rgba(63, 185, 80, 0.15);
  color: var(--ok);
}
.tag.warn {
  background: rgba(240, 183, 47, 0.15);
  color: var(--warn);
}
.tag.bad {
  background: rgba(255, 123, 114, 0.15);
  color: var(--bad);
}
.tag.info {
  background: rgba(88, 166, 255, 0.15);
  color: var(--info);
}
h2 {
  font-size: 18px;
  margin: 0 0 12px;
}
h3 {
  font-size: 15px;
  margin: 14px 0 6px;
}
.bar {
  height: 7px;
  background: var(--bg3);
  border-radius: 4px;
  overflow: hidden;
}
.bar > i {
  display: block;
  height: 100%;
  background: var(--accent);
}
.grid {
  display: grid;
  gap: 12px;
}
.metric {
  background: var(--bg3);
  border-radius: 8px;
  padding: 12px;
}
.metric .n {
  font-size: 22px;
  font-weight: 600;
}
.metric .l {
  font-size: 12px;
  color: var(--txt2);
}

/* 知识点详解/试题 markdown */
.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 10px 0;
}
.tab {
  background: var(--bg3);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--txt2);
}
.tab.active {
  background: var(--accent);
  color: #001;
  border-color: var(--accent);
}
.md {
  line-height: 1.75;
  font-size: 14px;
}
.md h3,
.md h4 {
  color: var(--accent);
  margin: 12px 0 6px;
}
.md code {
  background: var(--bg3);
  padding: 1px 5px;
  border-radius: 4px;
}
.md table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
}
.md th,
.md td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  font-size: 13px;
}
.md ul,
.md ol {
  padding-left: 20px;
}
.md blockquote {
  border-left: 3px solid var(--accent);
  margin: 6px 0;
  padding: 2px 10px;
  color: var(--txt2);
}

/* 结果 */
.score {
  font-size: 30px;
  font-weight: 700;
  color: var(--accent);
}
.steplist .step {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 5px 0;
  font-size: 14px;
  border-bottom: 1px solid var(--line);
}

/* 弹层 */
.modal-card {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  width: 380px;
  max-width: 100%;
}
.modal-card h2 {
  margin-top: 0;
}
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg3);
  border: 1px solid var(--line);
  padding: 10px 18px;
  border-radius: 10px;
  z-index: 60;
  font-size: 14px;
}

/* 树 */
.tree {
  font-size: 13px;
}
.tree .ch {
  padding: 6px 4px;
  font-weight: 600;
  cursor: pointer;
}
.tree .nd {
  padding: 5px 4px 5px 18px;
  cursor: pointer;
  color: var(--txt2);
  display: flex;
  justify-content: space-between;
}
.tree .nd:hover {
  color: var(--txt);
}
.tree .nd .m {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 8px;
  margin-top: 5px;
}

@media (max-width: 680px) {
  #search {
    display: none;
  }
  #appbody {
    flex-direction: column-reverse;
    height: calc(100vh - 53px);
  }
  #rail {
    width: 100%;
    flex: 0 0 auto;
    display: flex;
    border-right: none;
    border-top: 1px solid var(--line);
    overflow-x: auto;
    padding: 4px;
  }
  .railbtn {
    flex: 0 0 64px;
    padding: 6px 2px;
  }
  #content {
    padding: 12px;
  }
}
