:root {
  color-scheme: light;
  --ink: #182026;
  --muted: #667380;
  --line: #d9e1e7;
  --panel: #ffffff;
  --wash: #f3f6f8;
  --accent: #1c7c7d;
  --accent-soft: #d9f1ed;
  --amber: #c97b16;
  --danger: #a6403a;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--wash);
}

button,
textarea {
  font: inherit;
}

select,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 12px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

.shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.rail {
  display: flex;
  flex-direction: column;
  gap: 24px;
  border-right: 1px solid var(--line);
  padding: 20px;
  background: #fff;
}

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

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-weight: 800;
}

.brand small,
.topbar p,
.dialog-head small {
  display: block;
  color: var(--muted);
}

.nav {
  display: grid;
  gap: 8px;
}

.nav button {
  text-align: left;
}

.nav .active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.stats {
  display: grid;
  gap: 10px;
  margin-top: auto;
  color: var(--muted);
}

.stats span {
  display: flex;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.workspace {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  padding: 22px 28px;
  background: #fff;
}

.topbar h1 {
  margin: 0 0 6px;
  font-size: 24px;
  letter-spacing: 0;
}

.topbar p {
  margin: 0;
  max-width: 760px;
}

.actions {
  display: flex;
  align-items: start;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.panes {
  display: grid;
  grid-template-columns: minmax(340px, 0.95fr) minmax(430px, 1.15fr) minmax(280px, 0.75fr);
  gap: 16px;
  min-height: 0;
  padding: 16px;
}

.view-panel {
  display: none;
}

.view-panel.active {
  display: grid;
}

.primary-pane,
.canvas-pane,
.inspector-pane,
.memory-view,
.settings-view {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
}

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 12px 14px;
  font-weight: 700;
}

.pane-head small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.pane-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

#mainPrompt,
#branchQuestion {
  width: 100%;
  min-height: 96px;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 14px;
  resize: vertical;
  outline: none;
}

.output {
  position: relative;
  min-height: 610px;
  overflow: auto;
  padding: 22px;
  line-height: 1.75;
  white-space: pre-wrap;
}

.output.hint-output {
  color: var(--muted);
  pointer-events: none;
  user-select: none;
}

.output-hint {
  display: grid;
  gap: 8px;
  max-width: 720px;
  opacity: 0.28;
  filter: blur(1.8px);
}

.output-hint strong {
  color: var(--ink);
  font-size: 18px;
}

.output-hint span {
  font-size: 14px;
}

.output-hint p {
  max-height: 260px;
  margin: 8px 0 0;
  overflow: hidden;
}

#mainPrompt:focus + .output.hint-output .output-hint {
  opacity: 0.13;
  filter: blur(2.8px);
}

.selectable::selection,
.branch-answer::selection {
  background: #ffe2a8;
}

.anchor-mark {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-bottom: 3px solid #e2a23a;
  background: #fff4d5;
  cursor: pointer;
}

.anchor-mark.reanchored {
  border-bottom-color: var(--accent);
  background: var(--accent-soft);
}

.anchor-mark.badge {
  border: 1px solid #e2a23a;
  border-radius: 6px;
  padding: 0 4px;
}

.anchor-mark.capsule {
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 0 7px;
}

.anchor-score {
  border-radius: 999px;
  padding: 0 5px;
  color: #fff;
  background: var(--accent);
  font-size: 11px;
  line-height: 1.5;
}

.quick-focus {
  border-bottom: 2px dotted var(--accent);
  color: #105f60;
  cursor: pointer;
  text-decoration: none;
}

.quick-focus:hover {
  background: var(--accent-soft);
}

.math-inline,
.math-display {
  font-family: "Times New Roman", Times, ui-serif, Georgia, serif;
  color: #101820;
}

.math-inline {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin: 0 2px;
  vertical-align: middle;
  white-space: nowrap;
}

.math-display {
  display: flex;
  width: fit-content;
  max-width: 100%;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin: 12px auto;
  overflow-x: auto;
  border: 1px solid #d8e5e4;
  border-radius: 8px;
  padding: 12px 16px;
  background: #fbfefd;
  font-size: 1.12em;
  line-height: 1.45;
  white-space: normal;
}

.math-line {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 1.45em;
  white-space: nowrap;
}

.math-frac {
  display: inline-grid;
  grid-template-rows: auto 1px auto;
  align-items: center;
  justify-items: center;
  margin: 0 3px;
  vertical-align: middle;
}

.math-frac::before {
  content: "";
  grid-row: 2;
  width: 100%;
  min-width: 22px;
  border-top: 1.5px solid currentColor;
}

.math-num {
  grid-row: 1;
  padding: 0 5px 2px;
  font-size: 0.9em;
}

.math-den {
  grid-row: 3;
  padding: 2px 5px 0;
  font-size: 0.9em;
}

.math-sqrt {
  display: inline-flex;
  align-items: flex-start;
  gap: 1px;
}

.math-radicand {
  display: inline-block;
  border-top: 1.5px solid currentColor;
  padding: 0 3px;
}

.math-inline sup,
.math-display sup,
.math-inline sub,
.math-display sub {
  font-size: 0.72em;
  line-height: 0;
}

.viewpoint-canvas {
  display: grid;
  align-content: start;
  gap: 14px;
  height: 100%;
  max-height: calc(100vh - 170px);
  overflow: auto;
  padding: 14px;
  background:
    linear-gradient(#edf3f4 1px, transparent 1px),
    linear-gradient(90deg, #edf3f4 1px, transparent 1px);
  background-size: 22px 22px;
}

.empty {
  display: grid;
  gap: 8px;
  color: var(--muted);
  padding: 18px;
}

.viewpoint-card {
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 8px 22px rgb(27 45 52 / 8%);
  overflow: hidden;
}

.viewpoint-card.active {
  border-color: var(--accent);
  box-shadow: 0 10px 28px rgb(28 124 125 / 18%);
}

.viewpoint-card.archived {
  opacity: 0.72;
}

.viewpoint-card.depth-1 {
  margin-left: 16px;
}

.viewpoint-card.depth-2 {
  margin-left: 32px;
}

.viewpoint-card.depth-3,
.viewpoint-card.depth-4,
.viewpoint-card.depth-5 {
  margin-left: 48px;
}

.viewpoint-head {
  display: flex;
  gap: 10px;
  align-items: start;
  justify-content: space-between;
  padding: 12px;
}

.node-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.node-title-row h3 {
  margin: 0;
  font-size: 16px;
  letter-spacing: 0;
}

.depth-pill,
.chip {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  color: var(--muted);
  background: #f7fafb;
  font-size: 12px;
}

.depth-pill {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
  font-weight: 800;
}

.chip.reanchor {
  color: #105f60;
  border-color: var(--accent);
  background: var(--accent-soft);
}

.crumbs {
  color: var(--muted);
  font-size: 13px;
}

.node-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.node-actions button,
.selection-menu button,
.icon-button {
  padding: 6px 9px;
}

.viewpoint-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 0 12px 10px;
}

.anchor-line,
.question-line {
  margin: 0 12px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--muted);
  background: #f8fafb;
  font-size: 13px;
}

.question-line {
  color: var(--ink);
  background: #fff;
}

.branch-answer {
  border-top: 1px solid var(--line);
  padding: 12px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.viewpoint-card.collapsed .branch-answer,
.viewpoint-card.collapsed .child-slot,
.viewpoint-card.collapsed .question-line {
  display: none;
}

.child-slot {
  display: grid;
  gap: 12px;
  padding: 0 10px 12px;
}

.inspector {
  display: grid;
  gap: 14px;
  max-height: calc(100vh - 170px);
  overflow: auto;
  padding: 14px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.metric-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.metric-grid strong,
.metric-grid span {
  display: block;
}

.metric-grid strong {
  font-size: 22px;
}

.metric-grid span,
.empty-note {
  color: var(--muted);
  font-size: 13px;
}

.record {
  display: grid;
  gap: 8px;
  margin: 0;
}

.record dt {
  color: var(--muted);
  font-size: 12px;
}

.record dd {
  min-width: 0;
  margin: 0;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
  overflow-wrap: anywhere;
}

.memory-view,
.settings-view {
  margin: 16px;
}

.memory-list {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.memory-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.memory-item.reanchored {
  background: var(--accent-soft);
}

.memory-item h3,
.memory-item p {
  margin: 0 0 6px;
}

.memory-item p {
  color: var(--muted);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(240px, 1fr));
  gap: 16px;
  padding: 16px;
}

.settings-grid label {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
  font-weight: 700;
}

.settings-grid select,
.settings-grid input[type="range"] {
  width: 100%;
}

.selection-menu {
  position: fixed;
  z-index: 10;
  display: flex;
  gap: 6px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 14px 32px rgb(21 36 45 / 16%);
  padding: 6px;
  background: #fff;
}

.selection-menu[hidden] {
  display: none;
}

dialog {
  width: min(560px, calc(100vw - 30px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
}

dialog::backdrop {
  background: rgb(12 18 24 / 36%);
}

.dialog-form {
  margin: 0;
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 16px;
}

.dialog-head h2 {
  margin: 4px 0 0;
  font-size: 18px;
}

menu {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin: 0;
  padding: 12px 16px 16px;
}

@media (max-width: 900px) {
  .shell,
  .panes {
    grid-template-columns: 1fr;
  }

  .rail {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .topbar {
    flex-direction: column;
  }

  .settings-grid,
  .memory-item {
    grid-template-columns: 1fr;
  }
}

/* Simplified reader interface */
.reader-shell {
  min-height: 100vh;
}

.reader-header {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  padding: 14px clamp(16px, 4vw, 44px);
  background: rgb(255 255 255 / 94%);
  backdrop-filter: blur(14px);
}

.reader-main {
  width: min(960px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0 38px;
}

.reader-panel.active {
  display: block;
}

.reader-panel .primary-pane {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.question-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: stretch;
  border-bottom: 1px solid var(--line);
}

.question-box #mainPrompt {
  min-height: 92px;
  border: 0;
  padding: 16px;
  line-height: 1.55;
  resize: vertical;
}

.question-box #imageBtn,
.question-box #askMainBtn {
  min-width: 112px;
  margin: 14px 0;
  font-weight: 700;
}

.question-box #imageBtn {
  color: var(--accent);
  border-color: var(--accent);
  background: #fff;
}

.question-box #askMainBtn {
  margin-right: 14px;
  margin-left: 10px;
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

.image-attachment {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  color: var(--ink);
  background: #f5fbfa;
  border-bottom: 1px solid var(--line);
}

.image-attachment[hidden] {
  display: none;
}

.attachment-preview {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
}

.attachment-preview img {
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.attachment-preview strong,
.attachment-preview small {
  display: block;
}

.attachment-preview small {
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-attachment button {
  flex: 0 0 auto;
  color: var(--muted);
  background: #fff;
}

.answer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.answer-head span {
  color: var(--ink);
  font-size: 15px;
  font-weight: 800;
}

.reader-panel .output {
  min-height: calc(100vh - 260px);
  padding: clamp(18px, 3vw, 30px);
  font-size: 16px;
  line-height: 1.82;
}

.reader-panel .output-hint {
  max-width: 680px;
  opacity: 0.22;
}

.anchor-mark {
  border-bottom-width: 2px;
  border-bottom-color: #d5962d;
  background: #fff8df;
}

.anchor-mark::after {
  content: "追问";
  margin-left: 4px;
  border: 1px solid #e2c470;
  border-radius: 999px;
  padding: 0 6px;
  color: #8a5a00;
  background: #fffdf2;
  font-size: 11px;
  line-height: 1.55;
}

.anchor-mark.reanchored {
  border-bottom-color: var(--accent);
  background: var(--accent-soft);
}

.anchor-mark.reanchored::after {
  content: "已记录";
  color: #105f60;
  border-color: #9ccdc7;
  background: #f3fffc;
}

.anchor-score {
  display: none;
}

.quick-focus {
  color: inherit;
  border-bottom: 0;
  cursor: text;
}

.selection-menu {
  z-index: 12;
}

.selection-menu button {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
  font-weight: 700;
}

.node-dialog .dialog-form {
  max-height: min(760px, calc(100vh - 44px));
  overflow: hidden;
}

.node-detail {
  display: grid;
  gap: 14px;
  max-height: min(520px, calc(100vh - 230px));
  overflow: auto;
  padding: 16px;
}

.node-detail p {
  margin: 0;
  color: var(--muted);
}

#nodeDialogAnswer {
  line-height: 1.7;
  white-space: pre-wrap;
}

.hidden-internals {
  display: none;
}

@media (max-width: 720px) {
  .reader-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .actions {
    width: 100%;
    justify-content: flex-start;
  }

  .question-box {
    grid-template-columns: 1fr;
  }

  .question-box #imageBtn,
  .question-box #askMainBtn {
    width: calc(100% - 28px);
    margin: 8px 14px;
  }

  .image-attachment {
    align-items: flex-start;
    flex-direction: column;
  }

  .answer-head {
    align-items: flex-start;
    flex-direction: column;
  }
}
