:root {
  color-scheme: light;
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-muted: #f0f0ec;
  --ink: #1f1f1d;
  --muted: #77736b;
  --line: #e1ded7;
  --accent: #2f6f73;
  --accent-dark: #24595c;
  --danger: #a0443c;
}

* {
  box-sizing: border-box;
}

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

body.has-nav-open {
  overflow: hidden;
}

button,
textarea {
  font: inherit;
}

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

.sidebar {
  border-right: 1px solid var(--line);
  background: #f0f0ec;
  padding: 28px 20px;
}

.brand,
.toolbar-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.toolbar-title {
  align-items: center;
}

.brand h1,
.toolbar h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

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

.panel {
  margin-top: 28px;
}

.panel-title {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

.chapter-item {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  padding: 10px 12px;
  border-radius: 6px;
  text-align: left;
  cursor: pointer;
}

.chapter-item.active {
  border-color: var(--accent);
  background: #eef5f4;
}

.project-item {
  font-weight: 700;
}

.stats {
  display: grid;
  gap: 14px;
  color: var(--muted);
  font-size: 13px;
}

.stats div {
  display: grid;
  gap: 4px;
}

.stats strong {
  color: var(--ink);
  font-size: 14px;
  overflow-wrap: anywhere;
}

.editor-wrap {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  padding: 24px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 6px;
  padding: 9px 14px;
  cursor: pointer;
}

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

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

button.primary:hover {
  background: var(--accent-dark);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.icon-button {
  display: inline-grid;
  width: 38px;
  height: 38px;
  place-items: center;
  flex: 0 0 auto;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

.nav-open,
.nav-close,
.nav-overlay {
  display: none;
}

.mode-switch {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-muted);
  padding: 3px;
}

.mode-switch button {
  border: 0;
  background: transparent;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 700;
}

.mode-switch button.active {
  background: var(--surface);
  color: var(--accent-dark);
  box-shadow: 0 1px 4px rgba(31, 31, 29, 0.08);
}

.reader-view {
  display: grid;
  align-content: start;
  gap: 22px;
  min-height: 0;
}

.reader-view[hidden],
.author-view[hidden] {
  display: none;
}

.reader-content {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 22px 10px 42px;
  color: #242421;
  font-size: 18px;
  line-height: 2;
}

.reader-content p {
  margin: 0 0 1.35em;
  overflow-wrap: anywhere;
}

.reader-content .system-line,
.reader-content .system-block,
.reader-content .empty-reader {
  color: var(--muted);
  font-size: 15px;
}

.reader-content .system-block {
  margin: 0 0 1.35em;
  border-left: 3px solid var(--line);
  padding: 10px 0 10px 14px;
  line-height: 1.8;
}

.chapter-nav {
  display: flex;
  justify-content: center;
  gap: 12px;
  width: min(100%, 760px);
  margin: 0 auto;
  padding-bottom: 22px;
}

.chapter-nav button {
  min-width: 112px;
}

.author-view {
  display: grid;
  min-height: 0;
}

.shell.reader-mode .author-action {
  display: none;
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.28fr) minmax(320px, 0.72fr);
  gap: 16px;
  min-height: 0;
}

.editor-grid.notes-collapsed {
  grid-template-columns: minmax(0, 1fr) minmax(180px, 220px);
}

.editor-grid[hidden],
.outline-wrap[hidden] {
  display: none;
}

.outline-wrap {
  display: grid;
  min-height: 0;
}

.editor-pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: #fafafa;
  padding: 11px 16px;
}

.pane-head h3 {
  margin: 0;
  font-size: 15px;
  line-height: 1.2;
}

.pane-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.pane-toggle {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  padding: 5px 8px;
  font-size: 12px;
  font-weight: 700;
}

.pane-toggle:hover {
  border-color: var(--line);
  color: var(--ink);
}

.notes-pane.collapsed {
  grid-template-rows: auto;
}

.notes-pane.collapsed .pane-head {
  border-bottom: 0;
}

.notes-pane.collapsed #notesEditor {
  display: none;
}

#editor,
#notesEditor,
#outlineEditor {
  width: 100%;
  min-height: 0;
  resize: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 22px;
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", "Helvetica Neue", Arial, sans-serif;
  outline: none;
  white-space: pre-wrap;
}

#editor {
  font-size: 15px;
  line-height: 1.75;
}

#notesEditor,
#outlineEditor {
  background: #fcfcfb;
  color: #2f2f2b;
  font-size: 14px;
  line-height: 1.75;
}

.editor-pane:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(29, 111, 120, 0.12);
}

.footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.dirty {
  color: var(--danger);
}

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

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    width: min(86vw, 320px);
    height: 100dvh;
    overflow-y: auto;
    border-right: 1px solid var(--line);
    border-bottom: 0;
    padding: 18px;
    transform: translateX(-100%);
    transition: transform 180ms ease;
    box-shadow: 16px 0 28px rgba(31, 31, 29, 0.12);
  }

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

  .nav-overlay {
    position: fixed;
    inset: 0;
    z-index: 20;
    background: rgba(31, 31, 29, 0.3);
  }

  .nav-overlay.open {
    display: block;
  }

  .nav-open,
  .nav-close {
    display: inline-grid;
  }

  .editor-wrap {
    min-height: 100vh;
    padding: 16px;
  }

  .toolbar-title {
    justify-content: flex-start;
  }

  .editor-grid {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(52vh, 1fr) minmax(36vh, 0.72fr);
  }

  .editor-grid.notes-collapsed {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(68vh, 1fr) auto;
  }

  .notes-pane.collapsed {
    grid-template-rows: auto;
  }

  .toolbar,
  .footer {
    align-items: stretch;
    flex-direction: column;
  }

  .actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .mode-switch {
    width: 100%;
  }

  .mode-switch button {
    flex: 1 1 0;
  }

  .reader-content {
    padding: 12px 2px 30px;
    font-size: 17px;
    line-height: 2;
  }

  .chapter-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding-bottom: 16px;
  }

  .chapter-nav button {
    min-width: 0;
  }

  #editor,
  #notesEditor,
  #outlineEditor {
    padding: 16px;
  }
}
