:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --text: #17212b;
  --muted: #667789;
  --line: #d8e0e8;
  --accent: #2f7d6d;
  --accent-2: #315f9f;
  --shadow: 0 18px 46px rgba(27, 37, 48, 0.12);
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--bg), #e9eef3);
  color: var(--text);
}

button,
select,
textarea {
  font: inherit;
}

.mobile-outline-toggle,
.outline-backdrop {
  display: none;
}

.app {
  width: min(1500px, calc(100vw - 28px));
  min-height: calc(100vh - 28px);
  margin: 14px auto;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #b66825);
  color: #fff;
  font-weight: 800;
}

h1 {
  margin: 0;
  font-size: 1.18rem;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.toolbar label {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-2);
  color: var(--muted);
}

.toolbar select {
  max-width: min(44vw, 260px);
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.toolbar button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 12px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

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

.layout:has(.source-pane:not([hidden])) {
  grid-template-columns: 230px minmax(0, 1fr) minmax(320px, 0.72fr);
}

.sidebar,
.content,
.source-pane {
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.sidebar,
.source-pane {
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr;
}

.sidebar {
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 24px);
}

.side-head {
  min-height: 46px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
}

.outline {
  overflow: auto;
  padding: 10px;
}

.outline a {
  display: block;
  padding: 7px 8px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.outline a:hover {
  background: #edf5f2;
  color: var(--accent);
}

.outline a.active {
  background: #e3f2ed;
  color: var(--accent);
  font-weight: 700;
  box-shadow: inset 3px 0 0 var(--accent);
}

.outline .h3 {
  padding-left: 20px;
  color: var(--muted);
}

.outline .h3.active {
  color: var(--accent);
}

.content {
  overflow: auto;
  padding: 22px 28px 42px;
  line-height: 1.72;
}

.content h1,
.content h2,
.content h3 {
  line-height: 1.28;
}

.content h1 {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.content img {
  display: block;
  max-width: 100%;
  margin: 12px 0 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.content table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
  font-size: 0.94rem;
}

.content th,
.content td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

.content th {
  background: #eef3f7;
}

.content blockquote {
  margin: 14px 0;
  padding: 10px 14px;
  border-left: 4px solid var(--accent);
  background: #f4fbf8;
  color: #33414d;
}

.content code {
  padding: 0.12em 0.35em;
  border-radius: 5px;
  background: #eef2f6;
  font-family: Consolas, "Cascadia Mono", monospace;
}

.content pre {
  overflow: auto;
  padding: 14px;
  border-radius: 8px;
  background: #17212b;
  color: #f3f6fa;
}

.mindmap-wrap {
  overflow: auto;
  margin: 16px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.mindmap-link {
  fill: none;
  stroke: #9db0c3;
  stroke-width: 2;
}

.mindmap-node rect {
  fill: #fff;
  stroke: #cad6e1;
}

.mindmap-node.root rect {
  fill: var(--accent);
  stroke: var(--accent);
}

.mindmap-node text {
  dominant-baseline: middle;
  fill: var(--text);
  font-size: 14px;
}

.mindmap-node.root text {
  fill: #fff;
  font-weight: 700;
}

textarea {
  width: 100%;
  height: 100%;
  min-height: 540px;
  resize: none;
  border: 0;
  outline: 0;
  padding: 16px;
  background: transparent;
  color: var(--text);
  line-height: 1.6;
  font-family: Consolas, "Cascadia Mono", monospace;
}

@media (max-width: 980px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .layout,
  .layout:has(.source-pane:not([hidden])) {
    grid-template-columns: 1fr;
  }

  .mobile-outline-toggle {
    position: fixed;
    left: 0;
    top: 42vh;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    min-height: 76px;
    border: 1px solid var(--line);
    border-left: 0;
    border-radius: 0 8px 8px 0;
    background: var(--accent);
    color: #fff;
    box-shadow: 0 10px 28px rgba(27, 37, 48, 0.22);
    cursor: pointer;
    writing-mode: vertical-rl;
    letter-spacing: 0;
    transition: transform 0.2s ease;
  }

  .outline-backdrop {
    position: fixed;
    inset: 0;
    z-index: 38;
    background: rgba(23, 33, 43, 0.32);
  }

  body.outline-open .outline-backdrop {
    display: block;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 45;
    width: min(82vw, 330px);
    min-height: 0;
    max-height: none;
    border-radius: 0 8px 8px 0;
    transform: translateX(calc(-100% - 2px));
    transition: transform 0.22s ease;
  }

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

  body.outline-open .mobile-outline-toggle {
    transform: translateX(min(82vw, 330px));
  }

  .outline {
    max-height: calc(100vh - 47px);
  }

  .content {
    padding: 18px 18px 38px;
  }
}
