:root {
  color-scheme: light;
  --sidebar-width: 236px;
  --bg: #f7f5ef;
  --paper: #fffdf8;
  --ink: #202018;
  --muted: #706c61;
  --line: #ded8ca;
  --accent: #2c5f5d;
  --accent-strong: #163f3d;
  --gold: #a36f17;
  --code-bg: #eee8d9;
  --shadow: 0 18px 48px rgba(58, 48, 30, 0.14);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", Arial, sans-serif;
  line-height: 1.75;
}

body.resizing-sidebar {
  cursor: col-resize;
  user-select: none;
}

a {
  color: inherit;
}

.unlock-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.unlock-card {
  width: min(460px, 100%);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  box-shadow: var(--shadow);
  padding: 30px;
}

.unlock-card h1 {
  margin: 6px 0 12px;
  font-size: 28px;
  line-height: 1.25;
}

.unlock-copy {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
  margin: 0 0 18px;
}

.study-link {
  margin: -6px 0 18px;
}

.study-link a {
  color: var(--accent-strong);
  font-size: 14px;
  text-decoration: underline;
  text-underline-offset: 4px;
}

.unlock-label {
  display: block;
  color: var(--accent-strong);
  font-size: 13px;
  margin: 0 0 6px;
}

.unlock-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffaf0;
  color: var(--ink);
  font: inherit;
  margin: 0 0 12px;
  padding: 10px;
}

.unlock-status,
.unlock-error {
  color: #9a3a28;
  font-size: 13px;
  margin: 0 0 12px;
}

.unlock-status {
  color: var(--muted);
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 8px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  background: #efeadf;
  padding: 24px 14px 28px 16px;
}

.brand h1 {
  margin: 6px 0 16px;
  font-size: 21px;
  line-height: 1.25;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.nav-section {
  margin: 0 0 20px;
}

.nav-section-title {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.doc-link {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  align-items: start;
  gap: 8px;
  width: 100%;
  margin: 0 0 6px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  line-height: 1.35;
  padding: 8px;
  text-align: left;
}

.doc-link:hover,
.doc-link.active {
  border-color: #c8bdab;
  background: #fff9eb;
}

.doc-link-index {
  color: var(--gold);
  font-size: 12px;
  font-weight: 700;
  padding-top: 2px;
}

.doc-link-title {
  display: block;
  font-size: 13px;
}

.doc-link-desc {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  margin-top: 3px;
}

.system-guide {
  border: 1px solid #d6cbbb;
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.55);
  margin: 0 0 22px;
  padding: 12px;
}

.system-guide h2 {
  margin: 0 0 10px;
  color: var(--accent-strong);
  font-size: 14px;
}

.system-guide ol {
  margin: 0;
  padding-left: 18px;
}

.system-guide li {
  color: #423b31;
  font-size: 12px;
  line-height: 1.55;
  margin: 0 0 7px;
}

.workspace-nav {
  border-top: 1px solid #d8cdbb;
  margin: 0 0 20px;
  padding-top: 14px;
}

.workspace-nav h2 {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.workspace-buttons {
  display: grid;
  gap: 6px;
}

.workspace-link {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  padding: 8px;
  text-align: left;
}

.workspace-link:hover,
.workspace-link.active {
  border-color: #c8bdab;
  background: #fff9eb;
}

.workspace-link-title,
.workspace-link-desc {
  display: block;
}

.workspace-link-title {
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
}

.workspace-link-desc {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  margin-top: 3px;
}

.sidebar-resizer {
  position: sticky;
  top: 0;
  z-index: 5;
  width: 8px;
  height: 100vh;
  cursor: col-resize;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  background: linear-gradient(90deg, #e8e0d2, #f5f0e6);
}

.sidebar-resizer:hover,
.sidebar-resizer.dragging {
  background: #d8cdbb;
}

.reader {
  min-width: 0;
  padding: 34px clamp(24px, 6vw, 90px) 80px;
}

.reader-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin: 0 auto 28px;
  max-width: 980px;
}

.reader-toolbar h2 {
  margin: 4px 0 0;
  font-size: 26px;
  line-height: 1.3;
}

.toolbar-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 10px;
}

.raw-link {
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--accent-strong);
  flex: 0 0 auto;
  padding: 6px 10px;
  text-decoration: none;
}

.relock-button {
  border: 1px solid #9a3a28;
  border-radius: 6px;
  background: #fff8ef;
  color: #8d3122;
  cursor: pointer;
  flex: 0 0 auto;
  font: inherit;
  padding: 6px 10px;
}

.relock-button:hover {
  background: #f7e8dc;
}

.relock-button:disabled {
  cursor: wait;
  opacity: 0.68;
}

.notes-toggle {
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fffdf8;
  cursor: pointer;
  font: inherit;
  padding: 6px 10px;
}

.notes-toggle span {
  display: inline-block;
  min-width: 20px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  margin-left: 4px;
  padding: 1px 6px;
}

.doc-content {
  max-width: 980px;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  padding: clamp(22px, 4vw, 48px);
  box-shadow: 0 10px 32px rgba(65, 55, 35, 0.08);
}

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

.doc-content h1 {
  font-size: 30px;
  margin: 0 0 26px;
}

.doc-content h2 {
  border-top: 1px solid var(--line);
  font-size: 23px;
  margin: 36px 0 16px;
  padding-top: 28px;
}

.doc-content h3 {
  font-size: 19px;
  margin: 28px 0 12px;
}

.doc-content p,
.doc-content li {
  font-size: 16px;
  line-height: 1.9;
}

.doc-content blockquote {
  border-left: 4px solid var(--accent);
  color: #3d3930;
  margin: 22px 0;
  padding: 1px 0 1px 18px;
}

.doc-content pre {
  background: var(--code-bg);
  border-radius: 6px;
  overflow: auto;
  padding: 14px;
}

.doc-content code {
  background: var(--code-bg);
  border-radius: 4px;
  font-family: Consolas, "SFMono-Regular", monospace;
  padding: 2px 4px;
}

.doc-content pre code {
  background: transparent;
  padding: 0;
}

.doc-content.workbench-view {
  max-width: 1180px;
  border: 0;
  background: transparent;
  box-shadow: none;
  padding: 0;
}

.workbench-hero {
  border-bottom: 1px solid var(--line);
  margin: 0 0 24px;
  padding: 0 0 22px;
}

.workbench-hero h1 {
  margin: 4px 0 10px;
  font-size: 30px;
  line-height: 1.25;
}

.workbench-hero p {
  max-width: 820px;
  color: #3f3a30;
  font-size: 15px;
  line-height: 1.85;
  margin: 0;
}

.workbench-metrics,
.status-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.workbench-metrics span,
.status-chip {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
  padding: 10px 12px;
}

.workbench-metrics strong,
.status-chip strong {
  color: var(--accent-strong);
  margin-right: 5px;
}

.workbench-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.workbench-card,
.workbench-section,
.outbox-item,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 8px 22px rgba(65, 55, 35, 0.07);
}

.workbench-card {
  display: grid;
  gap: 10px;
  align-content: start;
  padding: 16px;
}

.workbench-card h2 {
  border: 0;
  font-size: 18px;
  margin: 0;
  padding: 0;
}

.workbench-card p {
  color: #4b4539;
  font-size: 14px;
  line-height: 1.65;
  margin: 0;
}

.workbench-card .small-button {
  justify-self: start;
}

.workbench-section {
  margin: 0 0 18px;
  padding: 18px;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin: 0 0 14px;
}

.section-head h2 {
  border: 0;
  font-size: 20px;
  margin: 2px 0 0;
  padding: 0;
}

.principle-list,
.roadmap-list {
  margin: 0;
  padding-left: 20px;
}

.principle-list li,
.roadmap-list li {
  color: #3f3a30;
  font-size: 15px;
  line-height: 1.8;
  margin-bottom: 8px;
}

.doc-shortcut-list {
  display: grid;
  gap: 8px;
}

.doc-shortcut {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffaf0;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  padding: 10px 12px;
  text-align: left;
}

.doc-shortcut:hover {
  border-color: var(--gold);
}

.doc-shortcut span,
.doc-shortcut small {
  display: block;
}

.doc-shortcut span {
  color: var(--accent-strong);
  font-size: 14px;
  font-weight: 700;
}

.doc-shortcut small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  margin-top: 3px;
}

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

.factory-form label {
  display: grid;
  gap: 6px;
}

.factory-form span {
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 700;
}

.factory-form input,
.factory-form select,
.factory-form textarea,
.status-select,
.draft-body {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffaf0;
  color: var(--ink);
  font: inherit;
  padding: 9px 10px;
}

.factory-form textarea,
.draft-body {
  line-height: 1.65;
  resize: vertical;
}

.wide-field,
.factory-actions {
  grid-column: 1 / -1;
}

.factory-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.factory-actions p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  margin: 0;
}

.outbox-list {
  display: grid;
  gap: 12px;
}

.outbox-item {
  padding: 14px;
}

.outbox-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px;
  gap: 14px;
  margin-bottom: 12px;
}

.outbox-head h3 {
  font-size: 17px;
  line-height: 1.35;
  margin: 0 0 4px;
}

.outbox-head p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
  margin: 0;
}

.draft-body {
  min-height: 180px;
  margin-bottom: 10px;
}

.outbox-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.small-button.danger {
  color: #9a3a28;
}

.empty-state {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
  padding: 16px;
}

.notes-panel {
  position: fixed;
  right: 0;
  top: 0;
  z-index: 35;
  width: min(390px, calc(100vw - 28px));
  height: 100vh;
  overflow: auto;
  border-left: 1px solid var(--line);
  background: #f1ede3;
  padding: 28px 20px;
  box-shadow: var(--shadow);
}

.notes-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.notes-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.notes-header h2 {
  margin: 4px 0 0;
  font-size: 22px;
  line-height: 1.3;
}

.notes-count {
  min-width: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--accent-strong);
  font-size: 13px;
  line-height: 1;
  padding: 7px 9px;
  text-align: center;
}

.icon-button {
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--paper);
  color: var(--muted);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 34;
  background: rgba(32, 30, 24, 0.18);
}

.notes-hint,
.notes-empty {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
  margin: 0 0 18px;
}

.notes-tools {
  display: flex;
  gap: 8px;
  margin: 0 0 16px;
}

.notes-empty {
  border: 1px dashed #c9beac;
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.55);
  padding: 14px;
}

.notes-list {
  display: grid;
  gap: 12px;
}

.note-card {
  border: 1px solid #d8cdbb;
  border-radius: 8px;
  background: var(--paper);
  cursor: pointer;
  padding: 14px;
}

.note-card:hover,
.note-card.active {
  border-color: var(--gold);
  box-shadow: 0 8px 20px rgba(80, 60, 25, 0.1);
}

.note-card-quote {
  border-left: 3px solid var(--gold);
  color: #4c4538;
  font-size: 13px;
  line-height: 1.65;
  margin: 0 0 10px;
  padding-left: 10px;
}

.note-card-body {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.7;
  margin: 0 0 12px;
  white-space: pre-wrap;
}

.note-card-actions {
  display: flex;
  gap: 8px;
}

.small-button,
.ghost-button,
.primary-button {
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
}

.small-button {
  border: 1px solid var(--line);
  background: #f7f1e6;
  color: var(--accent-strong);
  font-size: 12px;
  padding: 5px 8px;
}

.ghost-button {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  padding: 7px 11px;
}

.primary-button {
  border: 1px solid var(--accent-strong);
  background: var(--accent);
  color: #fffdf8;
  padding: 7px 13px;
}

.annotation-mark {
  border-bottom: 2px dotted var(--gold);
  background: rgba(195, 143, 40, 0.1);
  cursor: pointer;
  padding-bottom: 1px;
}

.annotation-mark:hover,
.annotation-mark.active {
  background: rgba(195, 143, 40, 0.22);
}

.annotation-composer,
.note-popover {
  position: fixed;
  z-index: 40;
  width: min(360px, calc(100vw - 28px));
  border: 1px solid #cfc3ae;
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
  padding: 14px;
}

.composer-title {
  margin: 0 0 8px;
  color: var(--accent-strong);
  font-weight: 700;
}

.composer-quote {
  max-height: 92px;
  overflow: auto;
  border-left: 3px solid var(--gold);
  color: #51483a;
  font-size: 13px;
  line-height: 1.55;
  margin: 0 0 10px;
  padding-left: 10px;
}

.annotation-composer textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffaf0;
  color: var(--ink);
  font: inherit;
  line-height: 1.55;
  padding: 10px;
}

.composer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

.note-popover h3 {
  margin: 0 0 8px;
  color: var(--accent-strong);
  font-size: 15px;
}

.note-popover blockquote {
  border-left: 3px solid var(--gold);
  color: #51483a;
  font-size: 13px;
  line-height: 1.55;
  margin: 0 0 10px;
  padding-left: 10px;
}

.note-popover p {
  font-size: 14px;
  line-height: 1.7;
  margin: 0 0 12px;
  white-space: pre-wrap;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: minmax(180px, 230px) 0 minmax(0, 1fr);
  }

  .sidebar {
    height: 100vh;
  }

  .sidebar-resizer {
    display: none;
  }

  .reader-toolbar {
    display: block;
  }

  .raw-link {
    display: inline-block;
  }
}

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    height: auto;
    position: static;
  }

  .reader {
    padding: 24px 14px 64px;
  }

  .toolbar-actions {
    margin-top: 12px;
  }

  .factory-form,
  .outbox-head {
    grid-template-columns: 1fr;
  }

  .factory-actions,
  .section-head {
    display: grid;
  }
}
