:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1f2328;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --ok: #16a34a;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .07), 0 8px 24px rgba(0, 0, 0, .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --card: #1a1f26;
    --text: #e6e8eb;
    --muted: #9aa3ad;
    --border: #2b323b;
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
}

a { color: var(--accent); text-decoration: none; }

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}

.topbar .brand { font-weight: 700; color: var(--text); }
.topbar .path { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .status { margin-left: auto; font-size: 13px; color: var(--muted); white-space: nowrap; }
.topbar .status.saved { color: var(--ok); }
.topbar .status.error { color: var(--danger); }

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 20px;
}

.hero { text-align: center; margin: 48px 0 40px; }
.hero h1 { font-size: 32px; margin: 0 0 8px; }
.hero p { color: var(--muted); margin: 0; }

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.split.three { grid-template-columns: 1fr 1fr 1fr; }

@media (max-width: 800px) { .split, .split.three { grid-template-columns: 1fr; } }

.module {
  display: block;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 28px;
  text-align: center;
  color: var(--text);
  transition: transform .15s, border-color .15s;
}

.module:hover { transform: translateY(-3px); border-color: var(--accent); }
.module .icon { font-size: 44px; }
.module h2 { margin: 14px 0 6px; }
.module p { color: var(--muted); margin: 0; font-size: 14px; line-height: 1.6; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  max-width: 560px;
  margin: 0 auto;
}

.card h2 { margin-top: 0; }

label { display: block; font-size: 14px; color: var(--muted); margin: 16px 0 6px; }

input[type="text"], input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}

input:focus { outline: 2px solid var(--accent); border-color: transparent; }

.btn {
  display: inline-block;
  padding: 10px 20px;
  font-size: 15px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: background .15s;
}

.btn:hover { background: var(--accent-hover); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.secondary { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn.danger { background: var(--danger); }
.btn-row { display: flex; gap: 12px; margin-top: 20px; flex-wrap: wrap; }

.hint { font-size: 13px; color: var(--muted); margin-top: 8px; }
.msg { margin-top: 14px; font-size: 14px; }
.msg.error { color: var(--danger); }
.msg.ok { color: var(--ok); }

/* 笔记编辑器:占满整个视口 */
.editor-wrap { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

#editor {
  flex: 1;
  width: 100%;
  border: none;
  resize: none;
  padding: 20px;
  font-size: 15px;
  line-height: 1.7;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  background: var(--bg);
  color: var(--text);
}

#editor:focus { outline: none; }

/* 文件上传 */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.dropzone.dragover { border-color: var(--accent); background: rgba(37, 99, 235, .06); }
.dropzone .filename { color: var(--text); font-weight: 600; word-break: break-all; }

.progress { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; margin-top: 16px; display: none; }
.progress .bar { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.result-link {
  display: block;
  margin-top: 12px;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: ui-monospace, Consolas, monospace;
  word-break: break-all;
}

.file-info { display: flex; flex-direction: column; gap: 4px; margin: 16px 0; }
.file-info .name { font-size: 18px; font-weight: 600; word-break: break-all; }
.file-info .meta { color: var(--muted); font-size: 14px; }

details { margin-top: 24px; }
summary { cursor: pointer; color: var(--muted); font-size: 14px; }

/* ===== Markdown 模块 ===== */
.mode-switch { display: flex; gap: 4px; }
.mode-switch button {
  padding: 4px 12px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.mode-switch button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.md-body { flex: 1; display: grid; overflow: hidden; }
.md-body[data-mode="split"] { grid-template-columns: 1fr 1fr; }
.md-body[data-mode="edit"] .md-preview { display: none; }
.md-body[data-mode="preview"] #editor { display: none; }

.md-body #editor { height: 100%; border-right: 1px solid var(--border); }
.md-body[data-mode="edit"] #editor { border-right: none; }

.md-preview { overflow-y: auto; padding: 20px 28px; background: var(--card); }

@media (max-width: 768px) {
  .md-body[data-mode="split"] { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .md-body[data-mode="split"] #editor { border-right: none; border-bottom: 1px solid var(--border); }
}

/* ===== 页面锁 ===== */
.lock-btn {
  padding: 4px 12px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.lock-btn:hover { border-color: var(--accent); color: var(--accent); }
.lock-btn.on { color: var(--accent); border-color: var(--accent); }

.lock-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, .45);
}
.lock-overlay.opaque { background: var(--bg); }

.lock-card { width: 100%; max-width: 420px; }
.lock-card h3 { margin-top: 0; }
.lock-radio {
  display: block;
  margin: 8px 0;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
}
.lock-radio input { margin-right: 6px; }

#editor:read-only { opacity: .75; }

/* markdown 渲染样式 */
.markdown-body { line-height: 1.75; font-size: 15px; word-wrap: break-word; }
.markdown-body h1, .markdown-body h2 { border-bottom: 1px solid var(--border); padding-bottom: .3em; }
.markdown-body h1:first-child, .markdown-body h2:first-child { margin-top: 0; }
.markdown-body img { max-width: 100%; border-radius: 8px; }
.markdown-body pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  overflow-x: auto;
  font-size: 13.5px;
}
.markdown-body code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  background: var(--bg);
  padding: .15em .4em;
  border-radius: 4px;
  font-size: .9em;
}
.markdown-body pre code { background: none; padding: 0; }
.markdown-body blockquote {
  margin: 0 0 16px;
  padding: 2px 16px;
  color: var(--muted);
  border-left: 4px solid var(--border);
}
.markdown-body table { border-collapse: collapse; margin-bottom: 16px; display: block; overflow-x: auto; }
.markdown-body th, .markdown-body td { border: 1px solid var(--border); padding: 6px 13px; }
.markdown-body th { background: var(--bg); }
.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }
