:root {
  color-scheme: light;
  --ink: #213b33;
  --muted: #738179;
  --green: #176448;
  --green-dark: #104d37;
  --green-soft: #e9f2eb;
  --paper: #fafbf7;
  --canvas: #f5f7f0;
  --line: #dbe3d9;
  --white: #fff;
  --shadow: 0 8px 30px rgb(30 57 42 / 10%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
html { width: 100%; height: 100%; overflow: hidden; }
body {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-size: 14px;
}

[hidden] { display: none !important; }
button, input, output { font: inherit; }
button, a, input { -webkit-tap-highlight-color: transparent; }
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--white);
  color: var(--ink);
  cursor: pointer;
  line-height: 1.25;
  transition: background-color 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}
button:hover { border-color: #abc1b0; background: #f0f5ed; }
button:active { background: #e6efe4; }
button:disabled { opacity: .45; cursor: default; }
button.active, button[aria-pressed="true"] {
  border-color: var(--green);
  background: var(--green);
  color: var(--white);
}
button.active:hover, button[aria-pressed="true"]:hover { background: var(--green-dark); }
a { color: var(--green); text-underline-offset: 3px; }
button:focus-visible, a:focus-visible, input:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid #d1a551;
  outline-offset: 3px;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  min-height: 70px;
  gap: 20px;
  padding: 12px 26px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.brand { display: flex; align-items: center; min-width: 0; gap: 12px; }
.brand-mark {
  display: grid;
  flex: 0 0 36px;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid #bdcebd;
  border-radius: 10px;
  background: var(--green-soft);
  color: var(--green-dark);
  font-size: 16px;
  font-weight: 750;
  letter-spacing: -.5px;
}
.brand > div { min-width: 0; }
.brand h1 { margin: 0; font-size: 18px; font-weight: 700; line-height: 1.35; letter-spacing: -.25px; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: 12px; line-height: 1.4; }
.header-links { display: flex; flex: 0 0 auto; align-items: center; gap: 16px; font-size: 12px; }
.header-links a { padding: 8px 0; text-decoration: none; }
.header-links a:hover { text-decoration: underline; }

.toolbar {
  position: relative;
  z-index: 30;
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 16px;
  padding: 12px 26px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.view-controls {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #edf1e9;
}
.view-controls button {
  min-height: 32px;
  padding: 7px 12px;
  border-color: transparent;
  border-radius: 6px;
  background: transparent;
  white-space: nowrap;
  font-size: 12px;
}
.view-controls button:hover { background: #e0e8dd; }
.view-controls button.active, .view-controls button[aria-pressed="true"] { background: var(--green); color: white; }
.view-controls button.active:hover { background: var(--green-dark); }
.search-wrap { position: relative; flex: 1 1 320px; min-width: 0; max-width: 500px; }
#search-input {
  display: block;
  width: 100%;
  height: 40px;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--white);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.4;
}
#search-input::placeholder { color: #839087; opacity: 1; }
#search-input:focus { border-color: #639779; }
#series-button { flex: 0 0 auto; margin-left: auto; font-size: 12px; white-space: nowrap; }
.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 70;
  width: 100%;
  max-height: min(440px, 60vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid #cbd9cb;
  border-radius: 10px;
  background: var(--white);
  box-shadow: var(--shadow);
}
.search-result {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  min-height: 66px;
  padding: 12px 14px;
  border: 0;
  border-bottom: 1px solid #e8eee5;
  border-radius: 0;
  text-align: left;
}
.search-result:last-child { border-bottom: 0; }
.search-result .title, .search-result strong { color: var(--ink); font-size: 13px; font-weight: 650; line-height: 1.6; }
.search-result .excerpt {
  display: -webkit-box;
  margin-top: 3px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.search-results > p { margin: 0; padding: 16px; color: var(--muted); font-size: 13px; line-height: 1.7; }

.workspace {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background-color: var(--canvas);
  background-image: radial-gradient(circle, #d4dfd0 .75px, transparent .85px);
  background-position: 8px 8px;
  background-size: 22px 22px;
  isolation: isolate;
}
#mindmap-canvas {
  display: block;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: transparent;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}
#mindmap-canvas:active { cursor: grabbing; }
#mindmap-canvas .node { cursor: pointer; }
#mindmap-canvas .node:focus-visible { outline: none; }
#mindmap-canvas .node:focus-visible > rect { stroke: #d1a551; stroke-width: 3px; }
.canvas-help {
  position: absolute;
  top: 15px;
  left: 22px;
  z-index: 2;
  padding: 5px 8px;
  border-radius: 5px;
  background: rgb(245 247 240 / 88%);
  color: #7a887c;
  font-size: 11px;
  line-height: 1.5;
  pointer-events: none;
}
.canvas-tools {
  position: absolute;
  right: 20px;
  bottom: 16px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  border: 1px solid #d0ddcc;
  border-radius: 10px;
  background: rgb(255 255 255 / 96%);
  box-shadow: 0 3px 12px rgb(41 66 45 / 6%);
}
.canvas-tools button { min-width: 34px; min-height: 32px; padding: 5px 9px; border: 0; background: transparent; }
.canvas-tools button:hover { background: var(--green-soft); }
#zoom-in, #zoom-out { font-size: 21px; font-weight: 400; }
#zoom-value { min-width: 48px; color: #6d7c70; text-align: center; font-size: 11px; font-variant-numeric: tabular-nums; }
#reset-view { margin-left: 4px; border-left: 1px solid var(--line); border-radius: 0 6px 6px 0; font-size: 12px; }

.selection-bar {
  position: absolute;
  bottom: 46px;
  left: 20px;
  z-index: 4;
  width: min(560px, calc(100% - 250px));
  padding: 13px 16px;
  border: 1px solid #ccdcca;
  border-radius: 11px;
  background: rgb(255 255 255 / 97%);
  box-shadow: var(--shadow);
}
.selected-path { overflow: hidden; color: var(--muted); font-size: 11px; line-height: 1.5; text-overflow: ellipsis; white-space: nowrap; }
.selected-title { overflow: hidden; margin-top: 3px; font-size: 15px; font-weight: 650; line-height: 1.6; text-overflow: ellipsis; white-space: nowrap; }
.selection-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin-top: 10px; }
.selection-actions button, .selection-actions a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 11px;
  line-height: 1.3;
  text-decoration: none;
  white-space: nowrap;
}
.selection-actions a { background: var(--green-soft); color: var(--green); }
.selection-actions a:hover { border-color: #97b69d; background: #dfecdf; }

.detail-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  width: min(380px, 100%);
  min-height: 0;
  overflow: hidden;
  border-left: 1px solid #cddccc;
  background: var(--paper);
  box-shadow: -10px 0 30px rgb(40 65 45 / 8%);
}
.detail-panel > header {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 19px 22px 17px;
  border-bottom: 1px solid var(--line);
}
.detail-panel h2 { margin: 0; font-size: 17px; font-weight: 700; line-height: 1.5; }
#close-panel { flex: 0 0 auto; min-width: 36px; min-height: 36px; padding: 6px 10px; background: transparent; font-size: 13px; }
#detail-content { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 8px 24px 26px; font-size: 13px; line-height: 1.85; overflow-wrap: anywhere; }
#detail-content h3 { margin: 25px 0 10px; color: var(--green-dark); font-size: 14px; line-height: 1.65; }
#detail-content h4 { margin: 19px 0 8px; font-size: 13px; }
#detail-content p { margin: 12px 0; }
#detail-content ul, #detail-content ol { margin: 10px 0 16px; padding-left: 20px; }
#detail-content li { margin: 0 0 10px; padding-left: 3px; }
#detail-content li::marker { color: #6e9e75; }
#detail-content strong { color: var(--green-dark); font-weight: 650; }
#detail-content .muted, #detail-content .detail-note, #detail-content .panel-note { color: var(--muted); font-size: 12px; }
#detail-content .panel-note { margin-top: 22px; padding-top: 13px; border-top: 1px solid var(--line); }
#detail-content .detail-kicker { margin-top: 18px; color: var(--muted); font-size: 11px; letter-spacing: .05em; }
#detail-content a { overflow-wrap: anywhere; }
#detail-content button { margin: 6px 5px 6px 0; }

.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  min-height: 28px;
  gap: 16px;
  padding: 5px 24px;
  border-top: 1px solid var(--line);
  background: var(--paper);
  color: var(--muted);
  font-size: 10px;
  line-height: 1.6;
}
#map-status { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.statusbar > span:last-child { flex: 0 0 auto; }

@media (max-width: 1100px) {
  .app-header { padding-right: 20px; padding-left: 20px; }
  .toolbar { gap: 11px; padding-right: 20px; padding-left: 20px; }
  .view-controls button { padding-right: 10px; padding-left: 10px; }
  #series-button { padding-right: 10px; padding-left: 10px; }
}

@media (max-width: 760px) {
  .app-header { min-height: 66px; gap: 12px; padding: 11px 15px; }
  .brand { gap: 9px; }
  .brand h1 { font-size: 16px; }
  .header-links { gap: 8px; font-size: 11px; }
  .toolbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 9px; padding: 9px 14px 11px; }
  .view-controls { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 3px; }
  .view-controls button { min-height: 34px; }
  .search-wrap { width: 100%; max-width: none; }
  #search-input { font-size: 16px; }
  #series-button { min-height: 40px; margin-left: 0; font-size: 11px; }
  .canvas-help { top: 10px; left: 9px; padding: 4px 5px; font-size: 10px; }
  .selection-bar { bottom: 65px; left: 12px; width: calc(100% - 24px); max-width: 480px; padding: 11px 13px; }
  .canvas-tools { right: 12px; bottom: 12px; }
  .canvas-tools button { min-width: 36px; min-height: 36px; }
  .statusbar { min-height: 26px; padding: 4px 14px; gap: 8px; }
  .statusbar > span:last-child { display: none; }
}

@media (max-width: 480px) {
  .app-header { min-height: 64px; padding: 10px 12px; gap: 9px; }
  .brand-mark { flex-basis: 32px; width: 32px; height: 32px; border-radius: 8px; font-size: 14px; }
  .brand h1 { font-size: 15px; }
  .brand p { font-size: 10px; }
  .header-links { font-size: 10px; }
  .header-links a { max-width: 72px; padding: 10px 0; line-height: 1.5; text-align: right; }
  .toolbar { gap: 8px; padding: 8px 10px 10px; }
  .view-controls { padding: 2px; }
  .view-controls button { min-height: 40px; padding: 7px 4px; font-size: 11px; }
  #search-input { height: 40px; padding: 9px 10px; font-size: 16px; }
  #series-button { padding: 8px; font-size: 10px; }
  .search-results { width: min(360px, calc(100vw - 20px)); }
  .search-result { min-height: 68px; padding: 11px 12px; }
  .selection-bar { right: 10px; bottom: 65px; left: 10px; width: auto; max-width: none; padding: 10px 12px; }
  .selected-path { font-size: 10px; }
  .selected-title { font-size: 13px; }
  .selection-actions { gap: 6px; margin-top: 8px; }
  .selection-actions button, .selection-actions a { min-height: 40px; padding: 7px 9px; font-size: 10px; }
  .canvas-tools { right: 10px; bottom: 10px; padding: 3px; border-radius: 9px; }
  .canvas-tools button { min-width: 40px; min-height: 40px; }
  #zoom-value { min-width: 42px; }
  .detail-panel { width: 100%; border-left: 0; }
  .detail-panel > header { padding: 14px 18px; }
  .detail-panel h2 { font-size: 16px; }
  #close-panel { min-width: 40px; min-height: 40px; }
  #detail-content { padding: 3px 20px 24px; font-size: 13px; }
  .statusbar { min-height: 25px; padding: 4px 12px; font-size: 9px; }
}

@media (max-width: 350px) {
  .app-header { padding-right: 10px; padding-left: 10px; }
  .brand { gap: 7px; }
  .brand h1 { font-size: 14px; }
  .brand-mark { flex-basis: 28px; width: 28px; height: 30px; }
  .header-links a { max-width: 62px; }
  #series-button { padding-right: 7px; padding-left: 7px; }
  #search-input { font-size: 16px; }
  .canvas-help { font-size: 9px; }
  .selection-actions { gap: 5px; }
  .selection-actions button, .selection-actions a { padding-right: 7px; padding-left: 7px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
