:root {
  /* Color system (Neutral) */
  --neutral-950: #0A0A0A; /* App background */
  --neutral-900: #1C1C1C; /* Sidebar/Panel */
  --neutral-875: #181818; /* Surfaces */
  --neutral-800: #2D2D2D; /* Selected / hover */
  --neutral-700: #393939; /* Active */
  --neutral-600: #4D4D4D; /* Stroke stronger */
  --neutral-400: #777777; /* Muted text */
  --neutral-0: #FFFFFF; /* Text / highlights */

  /* Brand */
  --brand-500: #3377FF;
  --brand-600: #2B67E6;
  --brand-700: #2358CC;
  --brand-100: rgba(51, 119, 255, 0.16);
  --brand-200: rgba(51, 119, 255, 0.22);

  /* Text levels */
  --text-strong: var(--neutral-0);
  --text: rgba(255, 255, 255, 0.92);
  --text-2: rgba(255, 255, 255, 0.78);
  --text-3: rgba(255, 255, 255, 0.60);
  --text-4: rgba(255, 255, 255, 0.46);

  --bg: var(--neutral-950);
  --muted: var(--text-3);

  /* UI tokens: spacing */
  --space-8: 8px;
  --space-12: 12px;
  --space-16: 16px;

  /* UI tokens: radius */
  --radius-12: 12px;
  --radius-16: 16px;

  /* UI tokens: stroke */
  --stroke-1: rgba(255, 255, 255, 0.08);
  --stroke-2: rgba(255, 255, 255, 0.12);
  --stroke-3: rgba(255, 255, 255, 0.16);

  /* UI tokens: type */
  --fs-h1: 22px; /* 大标题 */
  --fs-h2: 16px; /* 小标题 */
  --fs-title: 18px;
  --fs-body: 13px;
  --fs-note: 12px;

  /* Back-compat aliases */
  --border: var(--stroke-1);
  --glass: var(--neutral-875);
  --glass-2: var(--neutral-800);
  --radius: var(--radius-12);
  --sidebar-w: 280px;
  --panel-w: 360px;
}

html,
body {
  height: 100%;
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC",
    Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

* { box-sizing: border-box; }

#app {
  height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr var(--panel-w);
  overflow: hidden;
}

body.sidebar-collapsed #app { grid-template-columns: 0 1fr var(--panel-w); }
body.panel-collapsed #app { grid-template-columns: var(--sidebar-w) 1fr 0; }
body.sidebar-collapsed.panel-collapsed #app { grid-template-columns: 0 1fr 0; }

#sidebar {
  background: var(--neutral-900);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body.sidebar-collapsed #sidebar {
  width: 0;
  border: 0;
  pointer-events: none;
}

#main {
  position: relative;
  overflow: hidden;
}

#content {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

#panel {
  background: var(--neutral-900);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* levels-tones: shrink panel progressively before auto-collapse */
body[data-topic="levels-tones"] { --panel-w: clamp(280px, 26vw, 360px); }

body.panel-collapsed #panel {
  width: 0;
  border: 0;
  pointer-events: none;
}

.sidebar-header,
.panel-header {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  padding: var(--space-12);
  background: transparent;
}

.sidebar-header {
  justify-content: flex-start;
}

.brand {
  font-size: var(--fs-body);
  font-weight: 700;
  letter-spacing: 0.3px;
  color: var(--text-2);
  display: flex;
  align-items: center;
  min-width: 0;
}

.brand-logo-img {
  height: 32px;
  width: auto;
  display: block;
  margin-left: 12px;
  /* SVG is black; make it "scale white" */
  filter: brightness(0) invert(1);
}

.sidebar-body {
  padding: var(--space-12) var(--space-12) var(--space-16);
  overflow: auto;
}

.panel-title {
  font-size: var(--fs-body);
  font-weight: 650;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.panel-header {
  justify-content: space-between;
}

body.panel-header-hidden .panel-header { display: none; }

.panel-body {
  padding: var(--space-12) var(--space-12) var(--space-16);
  overflow: auto;
  scrollbar-gutter: stable;
}

.field {
  display: grid;
  gap: var(--space-8);
  margin: var(--space-12) 0 var(--space-16);
  padding: 0 var(--space-8);
}

.field-label {
  font-size: var(--fs-note);
  color: var(--muted);
}

select,
input[type="search"] {
  width: 100%;
  border: 0;
  background: var(--glass);
  color: var(--text);
  border-radius: var(--radius-12);
  padding: var(--space-12) 44px var(--space-12) var(--space-12);
  outline: none;
}

select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20'%3E%3Cpath d='M5 7.5l5 5 5-5' fill='none' stroke='%23FFFFFF' stroke-opacity='0.75' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 16px 16px;
}

select:focus,
input[type="search"]:focus {
  outline: 2px solid rgba(255, 255, 255, 0.18);
  outline-offset: 2px;
}

.toc details > summary {
  cursor: pointer;
  list-style: none;
  user-select: none;
  font-size: var(--fs-note);
  color: var(--muted);
  padding: var(--space-8);
}

.toc details > summary::-webkit-details-marker { display: none; }

.toc-list {
  display: grid;
  gap: var(--space-8);
  padding: var(--space-8);
}

.toc-group-title {
  margin: var(--space-12) var(--space-8) var(--space-8);
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.2px;
}

.toc-link {
  display: block;
  padding: 10px var(--space-12);
  border-radius: var(--radius-12);
  color: var(--text);
  text-decoration: none;
  border: 0;
  background: transparent;
  position: relative;
}

.toc-link:hover { background: var(--glass); }

.toc-link[aria-current="page"] {
  background: var(--neutral-800);
  font-weight: 750;
}

.icon-btn {
  appearance: none;
  border: 0;
  background: var(--glass);
  color: var(--text);
  border-radius: var(--radius-12);
  width: 34px;
  height: 34px;
  padding: 0;
  display: grid;
  place-items: center;
  cursor: pointer;
  user-select: none;
}

.icon-btn:hover { background: var(--glass-2); }
.icon-btn:active { transform: translateY(0.5px); }

.topbar {
  position: absolute;
  top: var(--space-12);
  left: var(--space-12);
  right: var(--space-12);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-12);
  z-index: 30;
  pointer-events: none;
}

.topbar .cluster {
  display: flex;
  gap: var(--space-8);
  pointer-events: auto;
}

#btnPanelOpen,
#btnPanelCloseHeader {
  display: none !important;
}

#topicActions .icon-btn {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-16);
  font-size: 18px;
}

body:not(.sidebar-collapsed) #btnSidebarOpen { display: none; }

@media (max-width: 980px) {
  :root { --sidebar-w: 260px; --panel-w: 340px; }
}

@media (max-width: 860px) {
  :root { --panel-w: 320px; }
}
