/* 让 hidden 属性真正生效：避免 .auth-view/.main 等 display 规则把隐藏元素又显示出来 */
[hidden] { display: none !important; }

:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --panel-2: #f7f8fa;
  --text: #1f2328;
  --muted: #6c727c;
  --border: #e3e6ea;
  --accent: #2563eb;
  --accent-soft: #e5edff;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --ok: #16a34a;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 8px 24px rgba(16, 24, 40, .06);
  --radius: 12px;
  --sidebar-w: 248px;
}
html[data-theme="dark"] {
  --bg: #0d1017;
  --panel: #161a23;
  --panel-2: #1c212d;
  --text: #e7e9ee;
  --muted: #9aa2af;
  --border: #262c39;
  --accent: #6ea2ff;
  --accent-soft: #1d2c4a;
  --danger: #f87171;
  --danger-soft: #3a1d22;
  --ok: #4ade80;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
}
button { font: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ---------- 通用 ---------- */
.primary { background: var(--accent); border: 1px solid transparent; color: #fff; border-radius: 8px; padding: 8px 14px; }
.primary:hover { filter: brightness(1.08); }
.primary.block { width: 100%; padding: 11px; font-size: 15px; }
.ghost { background: transparent; border: none; color: var(--muted); border-radius: 8px; padding: 6px 10px; }
.ghost:hover { background: var(--panel-2); color: var(--text); }
.small { padding: 5px 10px; border-radius: 8px; font-size: 13px; background: var(--panel-2); border: 1px solid var(--border); color: var(--text); }
.small:hover { border-color: var(--accent); color: var(--accent); }
.small.danger { color: var(--danger); }
.small.danger:hover { border-color: var(--danger); background: var(--danger-soft); }
.icon-btn { background: transparent; border: none; color: var(--muted); font-size: 18px; width: 36px; height: 36px; border-radius: 8px; }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.muted { color: var(--muted); }
.px-deco { display: none; } /* 航海像素主题的装饰元素，默认隐藏 */
.error { color: var(--danger); font-size: 13px; margin: 8px 0 0; }
.link-btn { background: none; border: none; color: var(--accent); margin-top: 12px; font-size: 14px; }

/* ---------- 登录 ---------- */
.auth-view { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px; background: radial-gradient(1200px 500px at 20% -10%, var(--accent-soft), transparent), var(--bg); }
.auth-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border); border-radius: 18px; padding: 32px 28px; box-shadow: var(--shadow); }
.auth-logo { text-align: center; margin-bottom: 12px; }
.auth-card h1 { margin: 0 0 6px; text-align: center; font-size: 22px; }
.auth-sub { text-align: center; color: var(--muted); margin: 0 0 22px; font-size: 13px; }
.auth-card input { width: 100%; margin-bottom: 12px; padding: 11px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); }
.auth-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.auth-card .link-btn { width: 100%; text-align: center; }

/* ---------- 主布局 ---------- */
.main { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transition: transform .22s ease;
  z-index: 30;
}
.sidebar-head { padding: 14px 16px 10px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 17px; }
.brand svg { border-radius: 7px; }
.list-nav { flex: 1; overflow-y: auto; padding: 4px 8px; }
.nav-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 8px 10px; border: none; background: transparent; border-radius: 9px;
  color: var(--text); text-align: left; position: relative;
}
.nav-item:hover { background: var(--panel-2); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-icon { width: 18px; text-align: center; font-size: 15px; }
.nav-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-count { font-size: 12px; color: var(--muted); background: var(--panel-2); border-radius: 10px; padding: 1px 7px; }
.nav-item.active .nav-count { background: var(--accent); color: #fff; }
.nav-del { visibility: hidden; border: none; background: none; color: var(--muted); border-radius: 6px; font-size: 14px; padding: 0 4px; }
.nav-item:hover .nav-del { visibility: visible; }
.nav-del:hover { color: var(--danger); }
.nav-add { margin: 4px 8px; }
.sidebar-foot { padding: 10px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 6px 4px; }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; }
.user-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--muted); }
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 25; }

/* ---------- 内容区 ---------- */
.content { flex: 1; display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); grid-template-rows: auto 1fr; min-width: 0; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 6px; padding: 8px 14px; border-bottom: 1px solid var(--border); background: var(--panel); }
#menuBtn { display: none; }
.search-box { flex: 1; position: relative; max-width: 520px; }
.search-icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 15px; }
.search-box input { width: 100%; padding: 8px 12px 8px 32px; border: 1px solid var(--border); border-radius: 9px; background: var(--panel-2); }
.search-box input:focus { outline: none; border-color: var(--accent); background: var(--panel); }
.list-panel { border-right: 1px solid var(--border); background: var(--panel); display: flex; flex-direction: column; min-width: 0; }
.panel-head { padding: 14px 16px 10px; display: flex; align-items: center; gap: 8px; }
.panel-title-wrap { flex: 1; display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.panel-title-wrap h2 { margin: 0; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.count { color: var(--muted); font-size: 12px; }
.notes-list { flex: 1; overflow-y: auto; padding: 2px 8px 14px; }
.note-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 6px; cursor: pointer; position: relative;
  display: flex; flex-direction: column; gap: 3px;
}
.note-card:hover { border-color: var(--accent); background: var(--accent-soft); }
.note-card.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.note-top { display: flex; align-items: center; gap: 6px; }
.note-pin { color: var(--accent); font-size: 12px; }
.note-title-line { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-title-line.empty { color: var(--muted); font-weight: 400; }
.note-preview { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.note-dot { opacity: .6; }
.note-listname { margin-left: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 120px; }
.progress { display: inline-flex; align-items: center; gap: 4px; color: var(--ok); }
.empty { color: var(--muted); text-align: center; padding: 48px 20px; }

/* ---------- 编辑器 ---------- */
.editor-panel { background: var(--panel); display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.editor-empty { margin: auto; text-align: center; color: var(--muted); padding: 30px; }
.editor-empty-icon { font-size: 40px; margin-bottom: 10px; }
.editor { display: flex; flex-direction: column; height: 100%; }
.editor-head { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-bottom: 1px solid var(--border); }
.editor-head select { max-width: 180px; padding: 5px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); }
.save-state { color: var(--muted); font-size: 12px; margin-left: auto; }
.editor-body { flex: 1; overflow-y: auto; }
.note-title { width: 100%; border: none; outline: none; background: transparent; font-size: 21px; font-weight: 700; padding: 18px 22px 8px; color: var(--text); }
.note-content {
  flex: 1;
  width: calc(100% - 36px);
  margin: 4px 18px 20px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  background: var(--panel);
  color: var(--text);
  line-height: 1.6;
  resize: vertical;
}
.note-content:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.blocks { padding: 4px 18px 20px; }
.block { display: flex; align-items: flex-start; gap: 9px; padding: 3px 4px; border-radius: 8px; }
.block:hover { background: var(--panel-2); }
.block-btn {
  flex: none; width: 22px; height: 22px; margin-top: 4px;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; background: transparent; color: var(--muted); border-radius: 6px; font-size: 14px;
}
.block-btn:hover { background: var(--border); color: var(--text); }
.check {
  flex: none; width: 22px; height: 22px; margin-top: 5px;
  border: 1.6px solid var(--muted); border-radius: 6px; background: transparent;
  display: inline-flex; align-items: center; justify-content: center; color: transparent; font-size: 13px;
}
.block.done .check { background: var(--accent); border-color: var(--accent); color: #fff; }
.check::after { content: "✓"; }
.text-marker { flex: none; width: 22px; height: 22px; margin-top: 5px; color: var(--muted); text-align: center; font-size: 18px; line-height: 22px; }
.block-input {
  flex: 1; border: none; outline: none; background: transparent; resize: none;
  padding: 8px 0 6px; min-height: 22px; line-height: 1.5; overflow: hidden;
}
.block.done .block-input { color: var(--muted); text-decoration: line-through; }
.block .row-actions { display: none; gap: 2px; align-items: center; }
.block:hover .row-actions, .block:focus-within .row-actions { display: flex; }
.editor-tools { display: flex; gap: 8px; padding: 4px 18px 24px; }
.editor-tools .small { background: var(--panel-2); }
.editor-tools .small:hover { background: var(--accent-soft); }
.blocks-hint { color: var(--muted); font-size: 13px; padding: 6px 6px 0; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: #111; color: #fff; padding: 9px 16px; border-radius: 20px; font-size: 13px;
  box-shadow: var(--shadow); z-index: 60; max-width: 80vw;
}
html[data-theme="dark"] .toast { background: #fff; color: #111; }

/* ---------- 新建清单信封 ---------- */
.dialog-backdrop { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 20px; background: rgba(15, 23, 42, .48); backdrop-filter: blur(2px); }
.envelope-dialog { position: relative; width: min(100%, 420px); height: 286px; margin: 0; border: 0; background: transparent; box-shadow: none; }
.letter-sheet { position: absolute; z-index: 2; inset: 14px 26px 28px; display: flex; flex-direction: column; padding: 23px 28px 18px; border: 2px solid #9c7139; border-radius: 3px; background: repeating-linear-gradient(0deg, transparent 0 27px, rgba(125, 86, 39, .1) 28px), #fff8df; color: #392715; box-shadow: 0 8px 18px rgba(0, 0, 0, .24); animation: letter-open .22s ease-out both; }
.letter-heading { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.letter-heading h2 { margin: 0; font-size: 21px; color: #513617; }
.letter-mark { display: grid; width: 28px; height: 28px; place-items: center; border: 2px solid #a5783c; border-radius: 50%; background: #d9a441; color: #fff9e8; font-size: 20px; font-weight: 700; line-height: 1; }
.letter-label { margin-bottom: 6px; color: #79582c; font-size: 13px; font-weight: 600; }
.letter-sheet input { width: 100%; padding: 8px 2px 7px; border: 0; border-bottom: 2px solid #a5783c; border-radius: 0; outline: none; background: transparent; color: #392715; font-size: 16px; }
.letter-sheet input::placeholder { color: #a8906b; }
.letter-sheet input:focus { border-color: #714b1e; box-shadow: 0 3px 0 -1px rgba(113, 75, 30, .18); }
.letter-sheet .error { margin: 6px 0 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: auto; }
.envelope-flap { display: none; }
.envelope-front { position: absolute; z-index: 1; right: 0; bottom: 0; left: 0; height: 102px; overflow: hidden; border: 2px solid #9b692d; border-radius: 3px; background: #d7a34c; box-shadow: 0 6px 0 #754e1e; pointer-events: none; }
.envelope-front::before, .envelope-front::after { content: ""; position: absolute; top: -72px; width: 62%; height: 154px; border: 2px solid rgba(111, 71, 24, .42); background: rgba(232, 190, 99, .28); }
.envelope-front::before { left: -26%; transform: rotate(34deg); }
.envelope-front::after { right: -26%; transform: rotate(-34deg); }
@keyframes letter-open { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ---------- 响应式 ---------- */
@media (max-width: 899px) {
  #menuBtn { display: inline-flex; }
  .sidebar { position: fixed; top: 0; left: 0; bottom: 0; transform: translateX(-105%); box-shadow: var(--shadow); }
  .main.sidebar-open .sidebar { transform: translateX(0); }
  .content { display: block; }
  .list-panel { height: 100%; border-right: none; }
  .editor-panel { position: fixed; inset: 0; z-index: 20; transform: translateX(100%); transition: transform .22s ease; box-shadow: var(--shadow); }
  .main.editor-open .editor-panel { transform: translateX(0); }
  #backBtn { display: inline-flex; }
  .note-title { padding: 14px 16px 6px; }
  .blocks { padding: 2px 12px 16px; }
  .editor-tools { padding: 2px 12px 20px; }
  .topbar { padding-top: max(8px, env(safe-area-inset-top)); }
  .search-box { min-width: 0; }
  .editor-panel { overflow-y: auto; padding-bottom: env(safe-area-inset-bottom); }
  .editor { min-height: 100%; }
  .toast { bottom: max(26px, calc(env(safe-area-inset-bottom) + 12px)); }
  .dialog-backdrop { padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom)); overflow-y: auto; align-items: start; }
  .envelope-dialog { flex: none; margin: auto 0; }
}
@media (max-width: 430px) {
  .topbar { gap: 3px; padding-right: 6px; padding-left: 6px; }
  .topbar .icon-btn { flex: 0 0 32px; width: 32px; height: 32px; padding: 0; font-size: 16px; }
  .search-box input { min-width: 0; }
}
@media (min-width: 900px) {
  #backBtn { display: none; }
}
@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] { --bg: #0d1017; --panel: #161a23; --panel-2: #1c212d; --text: #e7e9ee; --muted: #9aa2af; --border: #262c39; --accent: #6ea2ff; --accent-soft: #1d2c4a; --danger: #f87171; --danger-soft: #3a1d22; --ok: #4ade80; --shadow: 0 1px 3px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35); }
}