:root {
  color-scheme: light;
  --bg: #ffffff;
  --sidebar: #f6f6f5;
  --sidebar-border: #e6e3df;
  --text: #242220;
  --muted: #7a7773;
  --soft: #efedea;
  --hover: #ece8e4;
  --accent: #e85d75;
  --accent-soft: #f9e2e7;
  --green: #3f8f64;
  --blue: #356ea5;
  --code: #f2f3f5;
  --shadow: 0 14px 34px rgba(40, 34, 30, 0.14);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(246, 246, 245, 0.96)),
    url("data:image/svg+xml,%3Csvg width='120' height='120' viewBox='0 0 120 120' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 119h120M1 0v120' stroke='%23e5e1dc' stroke-width='1'/%3E%3C/svg%3E");
}

.login-panel {
  width: min(360px, calc(100vw - 32px));
  display: grid;
  gap: 14px;
  padding: 28px;
  border: 1px solid var(--sidebar-border);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.login-mark,
.avatar {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  color: #fff;
  background: var(--accent);
  font-weight: 700;
}

.login-panel h1 {
  margin: 4px 0 0;
  font-size: 24px;
  line-height: 1.2;
}

.login-panel p {
  margin: -8px 0 6px;
  color: var(--muted);
  font-size: 14px;
}

.login-panel label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.login-panel input {
  height: 38px;
  padding: 0 10px;
  color: var(--text);
  border: 1px solid var(--sidebar-border);
  border-radius: 6px;
  outline: none;
}

.login-panel input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.login-panel button {
  height: 38px;
  border-radius: 6px;
  color: #fff;
  background: var(--accent);
  font-weight: 600;
}

.login-error {
  min-height: 18px;
  color: #b22d45;
  font-size: 13px;
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 220px;
  overflow: hidden;
}

.sidebar {
  display: flex;
  min-width: 0;
  flex-direction: column;
  border-right: 1px solid var(--sidebar-border);
  background: var(--sidebar);
}

.space-switcher {
  height: 58px;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 30px;
  gap: 10px;
  align-items: center;
  padding: 12px 12px 10px;
}

.space-switcher strong,
.space-switcher span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.space-switcher strong {
  font-size: 14px;
  line-height: 1.2;
}

.space-switcher span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.sidebar-actions {
  display: grid;
  grid-template-columns: repeat(4, 32px);
  gap: 10px;
  padding: 4px 12px 8px;
}

.icon-button {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: #5d5955;
  background: transparent;
}

.icon-button:hover,
.tree-button:hover,
.text-button:hover {
  background: var(--hover);
}

.search-box {
  height: 34px;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  margin: 2px 12px 8px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
}

.search-box:focus-within {
  border-color: var(--accent);
}

.search-box input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 13px;
}

.page-tree {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 4px 4px 16px;
}

.tree-row {
  position: relative;
  min-height: 30px;
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) 58px;
  align-items: center;
  gap: 2px;
  padding-right: 4px;
  border-radius: 4px;
  color: #3c3935;
}

.tree-row:hover {
  background: var(--hover);
}

.tree-row.active {
  background: var(--accent-soft);
  color: #9d263b;
}

.tree-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.tree-indent {
  padding-left: calc(var(--depth) * 18px);
}

.tree-caret,
.tree-button {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
}

.tree-actions {
  display: none;
  grid-template-columns: 24px 24px;
  gap: 2px;
}

.tree-row:hover .tree-actions,
.tree-row.active .tree-actions {
  display: grid;
}

.trash-empty,
.empty-state {
  padding: 18px 16px;
  color: var(--muted);
  font-size: 13px;
}

.main-pane {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: #fff;
}

.topbar {
  height: 45px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 0 18px;
  border-bottom: 1px solid #f0eeeb;
}

.breadcrumbs {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.breadcrumbs span {
  color: #55514d;
}

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

.save-state {
  min-width: 48px;
  color: var(--green);
  font-size: 12px;
  text-align: right;
}

.save-state.saving {
  color: var(--blue);
}

.save-state.error {
  color: #b22d45;
}

.text-button {
  height: 30px;
  padding: 0 10px;
  border-radius: 6px;
  color: #4f4b47;
  background: transparent;
  font-size: 13px;
}

.block-type-select {
  width: 94px;
  height: 30px;
  padding: 0 24px 0 9px;
  border: 1px solid transparent;
  border-radius: 6px;
  outline: 0;
  color: #4f4b47;
  background: #f7f6f4;
  font-size: 13px;
}

.block-type-select:focus {
  border-color: #d9d5d0;
  background: #fff;
}

.block-type-select:disabled,
.topbar-icon:disabled {
  opacity: 0.45;
  cursor: default;
}

.topbar-icon {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: #6a655f;
  background: transparent;
  font-size: 14px;
}

.topbar-icon:hover {
  background: var(--soft);
  color: var(--text);
}

.editor-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 42px clamp(28px, 8vw, 110px) 90px;
}

.page-title {
  width: min(100%, 860px);
  min-height: 58px;
  margin: 0 0 14px;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  font-size: 40px;
  font-weight: 700;
  line-height: 1.18;
}

.page-title::placeholder {
  color: #b8b2ad;
}

.blocks {
  width: min(100%, 860px);
  display: grid;
  gap: 2px;
}

.block-row {
  position: relative;
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: 66px minmax(0, 1fr);
  align-items: start;
  min-height: 30px;
  border-radius: 4px;
  padding-left: calc(var(--indent, 0) * 28px);
}

.block-row:focus-within,
.block-row.active-block {
  background: rgba(232, 93, 117, 0.04);
}

.block-tools {
  display: grid;
  grid-template-columns: 20px 20px 20px;
  gap: 2px;
  padding-top: 4px;
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.block-row:hover .block-tools,
.block-row:focus-within .block-tools {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
}

.block-tool {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  background: transparent;
  color: #aaa39e;
  font-size: 11px;
  line-height: 20px;
}

.block-tool:hover {
  background: var(--soft);
  color: #4f4b47;
}

.block-content {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 30px;
  padding: 3px 2px;
  border: 0;
  outline: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.72;
  font-size: 16px;
}

.block-content:empty::before {
  content: attr(data-placeholder);
  color: #b8b2ad;
}

.block-content.h1 {
  margin-top: 18px;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.35;
}

.block-content.h2 {
  margin-top: 14px;
  font-size: 23px;
  font-weight: 700;
  line-height: 1.4;
}

.block-content.h3 {
  margin-top: 10px;
  font-size: 19px;
  font-weight: 700;
}

.block-content.bullet {
  padding-left: 22px;
}

.block-content.bullet::before {
  content: "•";
  position: absolute;
  margin-left: -18px;
  color: #48433f;
}

.block-content.quote {
  margin: 5px 0;
  padding-left: 14px;
  border-left: 3px solid #c9c2ba;
  color: #5d5955;
}

.block-content.code {
  margin: 5px 0;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--code);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  line-height: 1.55;
}

.todo-wrap {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: start;
}

.todo-wrap input {
  width: 16px;
  height: 16px;
  margin: 9px 6px 0 0;
  accent-color: var(--accent);
}

.todo-wrap.done .block-content {
  color: var(--muted);
  text-decoration: line-through;
}

.image-block {
  width: 100%;
  max-width: 760px;
  padding: 8px 0 10px;
}

.image-block img {
  max-width: 100%;
  border-radius: 6px;
  border: 1px solid var(--sidebar-border);
}

.image-caption {
  min-height: 24px;
  padding-top: 4px;
  color: var(--muted);
  font-size: 13px;
  outline: 0;
}

.append-block {
  width: min(calc(100% - 66px), 794px);
  height: 34px;
  margin: 16px 0 0 66px;
  padding: 0 10px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.append-block:hover {
  background: var(--soft);
  color: var(--text);
}

.outline-pane {
  border-left: 1px solid #f0eeeb;
  background: #fff;
  padding: 64px 14px 20px;
  overflow: auto;
}

.outline-header {
  margin-bottom: 10px;
  color: #a19b95;
  font-size: 13px;
}

.outline {
  display: grid;
  gap: 2px;
}

.outline a {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr);
  align-items: center;
  padding: 5px 8px;
  border-radius: 4px;
  color: #6a655f;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.outline a:hover {
  background: var(--soft);
  color: var(--text);
}

.outline a.level-2 {
  padding-left: 18px;
}

.outline a.level-3 {
  padding-left: 28px;
}

.outline-caret {
  color: #b2aba4;
  font-size: 10px;
}

.command-menu {
  position: fixed;
  z-index: 20;
  width: 210px;
  padding: 6px;
  border: 1px solid var(--sidebar-border);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.command-menu button {
  width: 100%;
  height: 32px;
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  align-items: center;
  border-radius: 5px;
  background: transparent;
  color: #403c38;
  text-align: left;
}

.command-menu button:hover {
  background: var(--soft);
}

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

  .outline-pane {
    display: none;
  }
}

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

  .sidebar {
    display: none;
  }

  .editor-scroll {
    padding: 26px 18px 80px;
  }

  .page-title {
    font-size: 32px;
  }
}
