/* 备忘 · 样式
   目标：干净的纸面感，侧栏 + 编辑区；移动端单屏切换。 */

:root {
  --accent: #e06a34;
  --accent-soft: rgba(224, 106, 52, 0.12);
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #fbfaf8;
  --text: #1d1c1a;
  --text-2: #5f5b54;
  --muted: #9a948b;
  --line: rgba(0, 0, 0, 0.09);
  --line-strong: rgba(0, 0, 0, 0.16);
  --shadow: 0 1px 2px rgba(20, 16, 12, 0.05), 0 8px 24px rgba(20, 16, 12, 0.06);
  --radius: 14px;
  --sidebar-w: 318px;
  --bar-h: 56px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #f08a55;
    --accent-soft: rgba(240, 138, 85, 0.16);
    --bg: #131313;
    --surface: #1c1c1c;
    --surface-2: #212121;
    --text: #ece9e4;
    --text-2: #a8a29a;
    --muted: #7d7873;
    --line: rgba(255, 255, 255, 0.09);
    --line-strong: rgba(255, 255, 255, 0.18);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.32);
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

input, textarea {
  font: inherit;
  color: inherit;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

[hidden] { display: none !important; }

/* ---------- 密钥页 ---------- */

#gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
  z-index: 40;
}

.gate-card {
  width: min(360px, 100%);
  text-align: center;
}

.gate-icon {
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.gate-card h1 {
  font-size: 22px;
  margin: 18px 0 6px;
  letter-spacing: 0.02em;
}

.gate-sub, .gate-hint {
  color: var(--text-2);
  font-size: 13.5px;
  margin: 0 0 22px;
}

.gate-hint {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 12px;
}

#gateForm {
  display: grid;
  gap: 10px;
}

#gateInput {
  width: 100%;
  padding: 13px 15px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  font-size: 16px; /* 避免 iOS 聚焦缩放 */
  text-align: center;
  letter-spacing: 0.06em;
  outline: none;
}

#gateInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

#gateBtn {
  padding: 13px 15px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
}

#gateBtn:disabled { opacity: 0.6; }

.gate-err {
  margin: 12px 0 0;
  color: #d64545;
  font-size: 13px;
}

/* ---------- 主框架 ---------- */

#shell {
  height: 100dvh;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
}

#sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
  border-right: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 6px;
}

.side-head h1 {
  font-size: 20px;
  margin: 0;
  letter-spacing: 0.04em;
  font-weight: 650;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  color: var(--text-2);
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover { background: var(--line); color: var(--text); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn.on { color: var(--accent); background: var(--accent-soft); }

.icon-btn.primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(224, 106, 52, 0.35);
}

.icon-btn.primary:hover { background: var(--accent); filter: brightness(1.06); }
.icon-btn.primary svg { stroke-width: 2.2; }

.search-wrap {
  position: relative;
  margin: 6px 12px 2px;
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--muted);
  stroke-width: 2;
}

#search {
  width: 100%;
  padding: 8px 12px 8px 32px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--line);
  font-size: 14px;
  outline: none;
  -webkit-appearance: none;
}

#search:focus {
  border-color: var(--line-strong);
  background: var(--surface);
}

#search::-webkit-search-cancel-button { -webkit-appearance: none; }

.filters {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px 6px;
}

.chip {
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--text-2);
  background: transparent;
  border: 1px solid transparent;
}

.chip:hover { background: var(--line); }

.chip.active {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

.count {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- 列表 ---------- */

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

.note-item {
  position: relative;
  padding: 11px 12px 10px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.12s;
  border: 1px solid transparent;
}

.note-item:hover { background: var(--surface); }

.note-item.active {
  background: var(--surface);
  border-color: var(--line-strong);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.ni-top {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.ni-title {
  font-weight: 600;
  font-size: 14.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.ni-time {
  flex: none;
  font-size: 11.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.ni-snippet {
  margin-top: 3px;
  font-size: 13px;
  color: var(--text-2);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.ni-pin {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 6px;
  vertical-align: 1px;
}

.ni-actions {
  display: flex;
  gap: 4px;
  margin-top: 8px;
}

.ni-actions button {
  font-size: 12px;
  padding: 4px 9px;
  border-radius: 8px;
  background: var(--line);
  color: var(--text-2);
}

.ni-actions button:hover { background: var(--line-strong); color: var(--text); }
.ni-actions .danger { color: #d64545; }

.list-empty {
  flex: 1;
  display: grid;
  place-content: center;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  padding-bottom: 60px;
  gap: 8px;
}

.link-btn {
  color: var(--accent);
  font-size: 14px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.side-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}

.foot-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 9px;
  border-radius: 8px;
  font-size: 12px;
  color: var(--text-2);
}

.foot-btn:hover { background: var(--line); }

.foot-btn.status { margin-left: auto; }

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #43a047;
  flex: none;
}

.dot.busy { background: #f0a020; }
.dot.off { background: var(--muted); }
.dot.err { background: #d64545; }

.dot.busy { animation: pulse 1.1s ease-in-out infinite; }

@keyframes pulse {
  50% { opacity: 0.35; }
}

/* ---------- 主区 ---------- */

#main {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  padding-top: env(safe-area-inset-top);
}

.welcome {
  flex: 1;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  color: var(--text-2);
  gap: 6px;
  padding: 24px;
}

.welcome-icon { border-radius: 20px; opacity: 0.9; box-shadow: var(--shadow); }
.welcome h2 { font-size: 19px; margin: 16px 0 0; color: var(--text); }
.welcome p { margin: 4px 0 18px; font-size: 13.5px; }

.btn {
  padding: 10px 18px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
}

.btn:hover { filter: brightness(1.06); }

/* ---------- 编辑器 ---------- */

#editorView {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.editor-bar {
  height: var(--bar-h);
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.icon-btn.back { display: none; }

.save-state {
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.editor-actions {
  margin-left: auto;
  display: flex;
  gap: 2px;
}

.editor-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#editor {
  flex: 1;
  width: 100%;
  min-height: 0;
  border: 0;
  outline: none;
  resize: none;
  padding: 22px 26px calc(40px + env(safe-area-inset-bottom));
  background: transparent;
  font-size: 16px;
  line-height: 1.75;
  -webkit-text-size-adjust: 100%;
  tab-size: 2;
}

#editor::placeholder { color: var(--muted); }

.preview {
  flex: 1;
  overflow-y: auto;
  padding: 22px 26px calc(40px + env(safe-area-inset-bottom));
  font-size: 16px;
  line-height: 1.75;
  overflow-wrap: break-word;
  -webkit-overflow-scrolling: touch;
}

/* 桌面宽屏时限制行宽，读起来不累 */
@media (min-width: 1000px) {
  .preview > *, #editor { max-width: 760px; }
}

.preview > :first-child { margin-top: 0; }
.preview h1, .preview h2, .preview h3 { line-height: 1.35; margin: 1.4em 0 0.6em; }
.preview h1 { font-size: 1.5em; }
.preview h2 { font-size: 1.25em; }
.preview h3 { font-size: 1.1em; }
.preview p { margin: 0.7em 0; }
.preview ul, .preview ol { padding-left: 1.4em; margin: 0.7em 0; }
.preview li { margin: 0.25em 0; }
.preview blockquote {
  margin: 0.9em 0;
  padding: 2px 0 2px 14px;
  border-left: 3px solid var(--line-strong);
  color: var(--text-2);
}
.preview code {
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: var(--line);
  padding: 0.15em 0.4em;
  border-radius: 5px;
}
.preview pre {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  overflow-x: auto;
}
.preview pre code { background: none; padding: 0; font-size: 0.85em; }
.preview a { color: var(--accent); text-decoration: none; }
.preview a:hover { text-decoration: underline; }
.preview img {
  max-width: 100%;
  height: auto;
  border-radius: 10px;
  margin: 0.6em 0;
  display: block;
  background: var(--line);
}
.preview hr { border: 0; border-top: 1px solid var(--line); margin: 1.6em 0; }
.preview table { border-collapse: collapse; width: 100%; font-size: 0.94em; }
.preview th, .preview td { border: 1px solid var(--line); padding: 6px 9px; text-align: left; }
.preview input[type="checkbox"] { margin-right: 6px; }
.preview li:has(> input[type="checkbox"]) { list-style: none; margin-left: -1.3em; }

/* ---------- 底部菜单 ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: flex-end;
  background: rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(2px);
}

.sheet-panel {
  width: 100%;
  max-width: 460px;
  margin: 0 auto;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  display: grid;
  gap: 1px;
  animation: sheet-up 0.18s ease-out;
}

@keyframes sheet-up {
  from { transform: translateY(12px); opacity: 0.6; }
}

.sheet-panel button {
  text-align: left;
  padding: 14px 16px;
  border-radius: 10px;
  font-size: 15px;
}

.sheet-panel button:hover { background: var(--line); }
.sheet-panel .danger { color: #d64545; }
.sheet-panel .muted { color: var(--text-2); text-align: center; }

/* ---------- 提示 ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(26px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 50;
  background: rgba(28, 26, 24, 0.92);
  color: #fff;
  font-size: 13.5px;
  padding: 9px 16px;
  border-radius: 999px;
  max-width: min(90vw, 420px);
  text-align: center;
  animation: toast-in 0.16s ease-out;
  pointer-events: none;
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 6px); }
}

/* ---------- 移动端：单屏切换 ---------- */

@media (max-width: 820px) {
  :root { --bar-h: 52px; }

  #shell { grid-template-columns: 1fr; }

  #sidebar { border-right: 0; }

  #main { border: 0; }

  body[data-pane="list"] #main { display: none; }
  body[data-pane="note"] #sidebar { display: none; }

  .icon-btn.back { display: inline-grid; }
  .editor-bar { padding: 0 8px 0 6px; }

  #editor, .preview {
    padding: 16px 18px calc(32px + env(safe-area-inset-bottom));
    font-size: 16px;
  }

  .note-item { padding: 12px 12px 11px; }

  .side-head { padding: 12px 14px 4px; }
}

/* 窄屏横放时也别太挤 */
@media (max-width: 820px) and (orientation: landscape) {
  #editor, .preview { padding-top: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
