:root {
  --bg: #f6f4ef;
  --panel: #fffdf9;
  --panel-alt: #f0ece3;
  --line: #e2dcd0;
  --text: #2c2822;
  --text-soft: #7d756a;
  --accent: #8a5a2b;
  --accent-soft: #f3e6d6;
  --danger: #b3492f;
  --shadow: 0 10px 30px rgba(70, 55, 35, 0.08);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191715;
    --panel: #211e1a;
    --panel-alt: #2a251f;
    --line: #37312a;
    --text: #ece6dc;
    --text-soft: #a2988a;
    --accent: #d8a066;
    --accent-soft: #33291f;
    --danger: #e0785c;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; cursor: pointer; }

.app {
  display: grid;
  grid-template-columns: 318px minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
}

/* ---------- 侧栏 ---------- */
.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 18px 16px 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.brand-icon {
  width: 18px;
  height: 22px;
  border-radius: 4px;
  border: 1.5px solid var(--accent);
  position: relative;
  flex: none;
}
.brand-icon::after {
  content: "";
  position: absolute;
  left: 3px;
  right: 3px;
  top: 7px;
  height: 1.5px;
  background: var(--accent);
  box-shadow: 0 5px 0 var(--accent);
  opacity: 0.6;
}

.btn-new, .btn-primary {
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  transition: transform 0.12s ease, filter 0.12s ease;
}
.btn-new:hover, .btn-primary:hover { filter: brightness(1.07); }
.btn-new:active, .btn-primary:active { transform: scale(0.97); }

.search { padding: 0 16px 10px; }

.search input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel-alt);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
  outline: none;
}
.search input:focus { border-color: var(--accent); }
.search input::-webkit-search-cancel-button { filter: grayscale(1); }

.note-list {
  list-style: none;
  margin: 0;
  padding: 4px 8px 12px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.note-item {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  border-radius: 11px;
  padding: 10px 12px;
  display: block;
  margin-bottom: 2px;
}
.note-item:hover { background: var(--panel-alt); }
.note-item[aria-current="true"] {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 28%, transparent);
}
.note-item .row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.note-item .name {
  font-size: 14px;
  font-weight: 550;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.note-item .time { font-size: 11px; color: var(--text-soft); flex: none; }
.note-item .snippet {
  margin-top: 3px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-soft);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.list-empty, .status {
  margin: 0;
  padding: 6px 20px 16px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-soft);
}
.status { padding-bottom: 18px; min-height: 16px; }
.status[data-tone="error"] { color: var(--danger); }

/* ---------- 编辑区 ---------- */
.editor {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 20px 28px 16px;
  background: var(--bg);
}

.editor-head {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
}

.btn-back {
  display: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 9px;
  flex: none;
}

.title-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 24px;
  font-weight: 650;
  letter-spacing: -0.01em;
  padding: 6px 2px;
  outline: none;
}
.title-input::placeholder { color: var(--text-soft); opacity: 0.7; }

.btn-delete {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text-soft);
  border-radius: 9px;
  padding: 6px 12px;
  font-size: 12.5px;
  flex: none;
}
.btn-delete:hover { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }

.content-input {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 760px;
  margin: 6px auto 0;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  line-height: 1.75;
  padding: 8px 2px;
  font-family: inherit;
}

.editor-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--text-soft);
}
.save-state { display: inline-flex; align-items: center; gap: 6px; }
.save-state::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.45;
}
.save-state[data-tone="saving"]::before { background: var(--accent); opacity: 1; }
.save-state[data-tone="error"] { color: var(--danger); }

/* ---------- 空白与门禁 ---------- */
.blank, .gate {
  display: grid;
  place-items: center;
  padding: 32px;
  text-align: center;
}
.blank-inner, .gate-inner { max-width: 360px; }
.blank-icon {
  width: 44px;
  height: 54px;
  margin: 0 auto 18px;
  border-radius: 8px;
  border: 1.5px solid color-mix(in srgb, var(--accent) 55%, transparent);
  position: relative;
}
.blank-icon::after {
  content: "";
  position: absolute;
  inset: 16px 8px auto 8px;
  height: 1.5px;
  background: color-mix(in srgb, var(--accent) 55%, transparent);
  box-shadow: 0 8px 0 color-mix(in srgb, var(--accent) 35%, transparent), 0 16px 0 color-mix(in srgb, var(--accent) 22%, transparent);
}
.blank h1, .gate h1 { font-size: 19px; margin: 0 0 8px; font-weight: 600; }
.blank p, .gate p { margin: 0 0 20px; font-size: 13.5px; line-height: 1.7; color: var(--text-soft); }

/* ---------- 视图切换 ---------- */
.app[data-view="list"] .editor { display: none; }
.app[data-view="list"] .blank { display: grid; }
.app[data-view="editor"] .editor { display: flex; }
.app[data-view="editor"] .blank { display: none; }
.app[data-view="gate"] .sidebar,
.app[data-view="gate"] .editor,
.app[data-view="gate"] .blank { display: none; }
.app[data-view="gate"] { grid-template-columns: 1fr; }
.app[data-view="gate"] .gate { display: grid; }
.app:not([data-view="gate"]) .gate { display: none; }

/* ---------- 窄屏 ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { border-right: none; }
  .app[data-view="editor"] .sidebar { display: none; }
  .editor { padding: 14px 16px 12px; }
  .btn-back { display: inline-flex; align-items: center; justify-content: center; }
  .title-input { font-size: 20px; }
  .content-input { font-size: 16px; }
  .app[data-view="list"] .blank { display: none; }
  .blank, .gate { padding: 24px; }
}
