:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1c1e21;
  --text-muted: #6b7280;
  --border: #e4e7ec;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px rgba(16, 24, 40, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --text: #e6e8eb;
    --text-muted: #9aa4b2;
    --border: #2a2f3a;
    --accent: #60a5fa;
    --accent-hover: #93c5fd;
    --danger: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

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

a:hover {
  text-decoration: underline;
}

img {
  max-width: 100%;
}

.container {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ---------- header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 60px;
}

.brand {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.2px;
}

.brand:hover {
  text-decoration: none;
  color: var(--accent);
}

.nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav a,
.link-btn {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
}

.nav a:hover,
.link-btn:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.btn:hover {
  background: var(--surface-2);
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-danger {
  border-color: transparent;
  background: transparent;
  color: var(--danger);
}

.btn-danger:hover {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 13px;
}

/* ---------- home ---------- */

main {
  padding: 40px 0 64px;
  min-height: calc(100vh - 180px);
}

.hero {
  margin-bottom: 28px;
}

.hero h1 {
  margin: 0 0 8px;
  font-size: 28px;
  line-height: 1.3;
  letter-spacing: -0.3px;
}

.hero p {
  margin: 0;
  color: var(--text-muted);
  font-size: 15px;
}

.search {
  position: relative;
  margin-bottom: 24px;
}

.search input {
  width: 100%;
  padding: 11px 14px 11px 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  outline: none;
}

.search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.search::before {
  content: "⌕";
  position: absolute;
  top: 50%;
  left: 14px;
  transform: translateY(-52%);
  color: var(--text-muted);
  font-size: 19px;
  pointer-events: none;
}

.post-list {
  display: grid;
  gap: 14px;
}

.post-card {
  display: block;
  padding: 20px 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.post-card:hover {
  text-decoration: none;
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  transform: translateY(-2px);
}

.post-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.post-card h2 {
  margin: 0 0 6px;
  font-size: 19px;
  line-height: 1.45;
}

.post-card p {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 14.5px;
}

.post-meta {
  color: var(--text-muted);
  font-size: 13px;
}

.badge {
  flex: none;
  padding: 2px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.empty {
  padding: 56px 20px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  text-align: center;
}

/* ---------- article ---------- */

.article-header {
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.article-header h1 {
  margin: 0 0 10px;
  font-size: 32px;
  line-height: 1.35;
  letter-spacing: -0.5px;
}

.article-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.markdown {
  font-size: 16.5px;
  line-height: 1.85;
  overflow-wrap: break-word;
}

.markdown > :first-child {
  margin-top: 0;
}

.markdown h1,
.markdown h2,
.markdown h3,
.markdown h4 {
  margin: 1.6em 0 0.6em;
  line-height: 1.4;
  letter-spacing: -0.2px;
}

.markdown h1 {
  font-size: 1.7em;
}

.markdown h2 {
  font-size: 1.4em;
}

.markdown h3 {
  font-size: 1.18em;
}

.markdown p {
  margin: 0 0 1.1em;
}

.markdown ul,
.markdown ol {
  margin: 0 0 1.1em;
  padding-left: 1.5em;
}

.markdown li {
  margin: 0.3em 0;
}

.markdown blockquote {
  margin: 1.2em 0;
  padding: 4px 18px;
  border-left: 3px solid var(--accent);
  background: var(--surface-2);
  border-radius: 0 8px 8px 0;
  color: var(--text-muted);
}

.markdown code {
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 0.88em;
}

.markdown pre {
  margin: 1.2em 0;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  overflow-x: auto;
}

.markdown pre code {
  padding: 0;
  background: none;
  font-size: 0.86em;
  line-height: 1.65;
}

.markdown table {
  width: 100%;
  margin: 1.2em 0;
  border-collapse: collapse;
  font-size: 0.94em;
}

.markdown th,
.markdown td {
  padding: 8px 12px;
  border: 1px solid var(--border);
  text-align: left;
}

.markdown th {
  background: var(--surface-2);
}

.markdown hr {
  margin: 2em 0;
  border: 0;
  border-top: 1px solid var(--border);
}

.markdown img {
  border-radius: 10px;
}

.plain {
  white-space: pre-wrap;
}

/* ---------- comments ---------- */

.comments {
  margin-top: 52px;
  padding-top: 28px;
  border-top: 1px solid var(--border);
}

.comments h2 {
  margin: 0 0 18px;
  font-size: 19px;
}

.comment-list {
  display: grid;
  gap: 12px;
  margin-bottom: 26px;
}

.comment {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.comment-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}

.comment-author {
  font-size: 14px;
  font-weight: 600;
}

.comment-time {
  color: var(--text-muted);
  font-size: 12px;
}

.comment-body {
  margin: 0;
  font-size: 14.5px;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.comment-form {
  display: grid;
  gap: 12px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.comment-form h3 {
  margin: 0;
  font-size: 16px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

input[type="text"],
input[type="password"],
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.6;
  outline: none;
}

input[type="text"]:focus,
input[type="password"]:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

textarea {
  resize: vertical;
  min-height: 90px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.hint {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
}

.hp-field {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

/* ---------- login ---------- */

.auth-card {
  max-width: 400px;
  margin: 40px auto;
  padding: 32px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-card h1 {
  margin: 0 0 6px;
  font-size: 22px;
}

.auth-card > p {
  margin: 0 0 22px;
  color: var(--text-muted);
  font-size: 14px;
}

.auth-card form {
  display: grid;
  gap: 14px;
}

.error-text {
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

/* ---------- editor ---------- */

.editor-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 84px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.sidebar-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.sidebar-list {
  display: grid;
  gap: 2px;
  max-height: calc(100vh - 200px);
  overflow-y: auto;
}

.sidebar-item {
  display: block;
  width: 100%;
  padding: 7px 9px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.sidebar-item.active {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  font-weight: 600;
}

.editor-main {
  display: grid;
  gap: 14px;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.editor-toolbar .spacer {
  flex: 1;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 14px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.editor-body {
  display: grid;
  gap: 14px;
}

.editor-body.split {
  grid-template-columns: 1fr 1fr;
  align-items: start;
}

.editor-pane {
  display: grid;
  gap: 14px;
}

#content {
  min-height: 460px;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.75;
}

.preview {
  min-height: 460px;
  max-height: 70vh;
  overflow-y: auto;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.preview-empty {
  color: var(--text-muted);
  font-size: 14px;
}

/* ---------- toast ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 100;
  transform: translate(-50%, 16px);
  max-width: calc(100vw - 40px);
  padding: 10px 18px;
  border-radius: 999px;
  background: #1f2937;
  color: #fff;
  font-size: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

#toast.error {
  background: #b91c1c;
}

/* ---------- settings ---------- */

#list-status {
  min-height: 20px;
  margin: 0 0 12px;
}

.settings {
  padding: 0 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.settings summary {
  padding: 13px 0;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
}

.settings[open] {
  padding-bottom: 18px;
}

.password-form {
  display: grid;
  gap: 12px;
  max-width: 360px;
}

/* ---------- footer ---------- */

.site-footer {
  padding: 24px 0 40px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

.site-footer a {
  color: inherit;
}

/* ---------- responsive ---------- */

@media (max-width: 780px) {
  .editor-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    order: 2;
  }

  .sidebar-list {
    max-height: 220px;
  }

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

  .preview {
    min-height: 200px;
  }
}

@media (max-width: 560px) {
  main {
    padding-top: 26px;
  }

  .hero h1 {
    font-size: 23px;
  }

  .article-header h1 {
    font-size: 25px;
  }

  .post-card {
    padding: 16px 17px;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .auth-card {
    padding: 24px 20px;
  }
}
