:root {
  --bg: #ffffff;
  --bg-alt: #f8f9fa;
  --bg-sidebar: #f6f6f6;
  --border: #e4e7eb;
  --border-strong: #c8ccd1;
  --text: #202122;
  --text-muted: #54595d;
  --text-faint: #72777d;
  --link: #3366cc;
  --link-hover: #447ff5;
  --link-visited: #795cb2;
  --link-red: #ba0000;
  --accent: #111827;
  --accent-soft: #1f2937;
  --warn: #fef6e7;
  --success: #e6f4ea;
  --shadow: 0 1px 2px rgba(0,0,0,0.05);
  --radius: 4px;
  --max-width: 1100px;
  --serif: "Linux Libertine", "Georgia", "Cambria", "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
}

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; color: var(--link-hover); }
a.redlink { color: var(--link-red); }

/* ---------------- Header ---------------- */
.site-header {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: saturate(180%) blur(6px);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 24px;
  height: 60px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}
.brand:hover { text-decoration: none; color: var(--accent); }

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  font-family: var(--serif);
  font-weight: 700;
  font-size: 20px;
  line-height: 1;
}

.brand-name {
  font-family: var(--serif);
  font-size: 22px;
  letter-spacing: -0.01em;
}

.brand-accent { color: var(--link); }

.search-form {
  flex: 1;
  max-width: 560px;
  position: relative;
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
  transition: box-shadow 0.15s, border-color 0.15s;
}
.search-form:focus-within {
  border-color: var(--link);
  box-shadow: 0 0 0 3px rgba(51, 102, 204, 0.15);
}
.search-form input {
  flex: 1;
  padding: 8px 12px;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 14px;
  color: var(--text);
}
.search-form button {
  padding: 0 14px;
  background: var(--bg-alt);
  border: 0;
  border-left: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
}
.search-form button:hover { background: #eaecf0; color: var(--accent); }

.search-suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
  list-style: none;
  margin: 0;
  padding: 4px 0;
  max-height: 360px;
  overflow-y: auto;
  z-index: 60;
}
.search-suggestions li {
  padding: 8px 14px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  flex-direction: column;
}
.search-suggestions li:hover,
.search-suggestions li.active { background: var(--bg-alt); }
.search-suggestions li .sugg-title { color: var(--link); font-weight: 500; }
.search-suggestions li .sugg-snippet { color: var(--text-faint); font-size: 12px; margin-top: 2px; }
.search-suggestions li.create-new .sugg-title::before { content: "+ Create "; color: var(--text-muted); }

.auth-slot { display: flex; align-items: center; gap: 12px; }
.auth-slot .btn-login {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
}
.auth-slot .btn-login:hover { background: var(--accent-soft); text-decoration: none; }
.auth-slot .user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-muted);
}
.auth-slot .user img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
}
.auth-slot .user-menu {
  position: relative;
}
.auth-slot .user-menu button.user-btn {
  background: none; border: 0; padding: 0; cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  color: var(--text); font-size: 14px;
}
.auth-slot .user-menu .menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.1);
  min-width: 200px;
  padding: 6px 0;
  z-index: 60;
}
.auth-slot .user-menu .menu a,
.auth-slot .user-menu .menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 14px;
  font-size: 14px;
  color: var(--text);
  background: none;
  border: 0;
  cursor: pointer;
  text-decoration: none;
}
.auth-slot .user-menu .menu a:hover,
.auth-slot .user-menu .menu button:hover { background: var(--bg-alt); }
.auth-slot .user-menu .menu .label { color: var(--text-faint); font-size: 12px; padding: 6px 14px; }
.auth-slot .user-menu .menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }

/* ---------------- Main layout ---------------- */
main { padding: 24px 0 48px; min-height: 60vh; }

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
  margin-bottom: 18px;
}
.page-header h1 {
  font-family: var(--serif);
  font-size: 32px;
  margin: 0;
  font-weight: 400;
  line-height: 1.2;
}
.page-tabs { display: flex; gap: 0; }
.page-tabs a {
  padding: 6px 14px;
  font-size: 13px;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-bottom: 0;
  background: var(--bg-alt);
  border-top-left-radius: 4px;
  border-top-right-radius: 4px;
  margin-right: 2px;
}
.page-tabs a:hover { background: #eaecf0; text-decoration: none; }
.page-tabs a.active {
  background: var(--bg);
  color: var(--text);
  font-weight: 500;
  position: relative;
  top: 1px;
}

.meta-line {
  color: var(--text-faint);
  font-size: 12px;
  margin: 0 0 20px;
}

/* ---------------- Article content ---------------- */
.article {
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.7;
  color: var(--text);
  max-width: 780px;
}
.article h1 { font-size: 30px; font-weight: 400; margin-top: 0; }
.article h2 {
  font-size: 24px;
  font-weight: 400;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
  margin-top: 32px;
}
.article h3 { font-size: 19px; font-weight: 600; margin-top: 24px; }
.article p { margin: 14px 0; }
.article a { color: var(--link); }
.article code { font-family: var(--mono); font-size: 0.92em; background: var(--bg-alt); padding: 1px 5px; border-radius: 3px; }
.article pre {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  padding: 12px 14px;
  border-radius: var(--radius);
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.5;
}
.article pre code { background: none; padding: 0; }
.article blockquote {
  margin: 16px 0;
  padding: 4px 16px;
  border-left: 3px solid var(--border-strong);
  color: var(--text-muted);
}
.article ul, .article ol { padding-left: 28px; }
.article li { margin: 4px 0; }
.article img { max-width: 100%; height: auto; border-radius: var(--radius); }
.article hr { border: 0; border-top: 1px solid var(--border); margin: 24px 0; }
.article table { border-collapse: collapse; margin: 16px 0; }
.article th, .article td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.article th { background: var(--bg-alt); font-weight: 600; }

/* ---------------- Home ---------------- */
.home-hero {
  background: linear-gradient(180deg, #fafbfc 0%, #ffffff 100%);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 40px;
  text-align: center;
  margin-bottom: 28px;
}
.home-hero h1 {
  font-family: var(--serif);
  font-size: 42px;
  margin: 0 0 8px;
  font-weight: 400;
}
.home-hero p {
  color: var(--text-muted);
  font-size: 16px;
  max-width: 580px;
  margin: 0 auto 20px;
}
.home-hero .stats {
  display: inline-flex;
  gap: 24px;
  font-size: 13px;
  color: var(--text-faint);
}
.home-hero .stats strong { color: var(--text); font-weight: 600; }

.home-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 28px;
  align-items: start;
}
@media (max-width: 780px) {
  .home-grid { grid-template-columns: 1fr; }
}

.panel {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  overflow: hidden;
}
.panel-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-alt);
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panel-header .subtle { color: var(--text-faint); font-weight: 400; font-size: 12px; }
.panel-body { padding: 4px 0; }

.list-row {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.list-row:first-child { border-top: 0; }
.list-row .t-line { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.list-row .t-title { color: var(--link); font-weight: 500; font-size: 14px; }
.list-row .t-time { color: var(--text-faint); font-size: 12px; white-space: nowrap; }
.list-row .t-meta { color: var(--text-faint); font-size: 12px; }
.list-row .t-meta .editor { color: var(--text-muted); }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--bg-alt);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.1s, border-color 0.1s;
}
.btn:hover { background: #eaecf0; text-decoration: none; }
.btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn.primary:hover { background: var(--accent-soft); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ---------------- Editor ---------------- */
.editor-page { max-width: 900px; }
.editor-page .notice {
  background: var(--warn);
  border: 1px solid #f5d78e;
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 14px;
}
.editor-title-input {
  width: 100%;
  font-family: var(--serif);
  font-size: 28px;
  padding: 8px 0;
  border: 0;
  border-bottom: 1px solid var(--border);
  outline: 0;
  margin-bottom: 12px;
  background: transparent;
}
.editor-title-input:focus { border-color: var(--link); }
.editor-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: -1px;
}
.editor-tabs button {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-bottom: 0;
  background: var(--bg-alt);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  border-top-left-radius: 4px;
  border-top-right-radius: 4px;
}
.editor-tabs button.active {
  background: var(--bg);
  color: var(--text);
  font-weight: 500;
}
.editor-body {
  border: 1px solid var(--border);
  border-radius: 0 var(--radius) var(--radius) var(--radius);
  background: var(--bg);
  min-height: 320px;
}
.editor-textarea {
  display: block;
  width: 100%;
  min-height: 360px;
  padding: 16px;
  border: 0;
  outline: 0;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.6;
  resize: vertical;
  background: transparent;
  color: var(--text);
}
.editor-preview { padding: 16px 20px; }
.editor-preview.empty { color: var(--text-faint); font-style: italic; }
.editor-footer {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.editor-footer .summary-row {
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 13px;
  color: var(--text-muted);
}
.editor-footer .summary-row input {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: 14px;
}
.editor-footer .actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ---------------- History ---------------- */
.revision-row {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 14px;
  align-items: baseline;
}
.revision-row:first-child { border-top: 0; }
.revision-row .r-num {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-faint);
  width: 40px;
  text-align: right;
}
.revision-row .r-meta { flex: 1; font-size: 13px; }
.revision-row .r-meta .r-editor { font-weight: 500; color: var(--text); }
.revision-row .r-meta .r-summary { color: var(--text-muted); font-style: italic; margin-left: 4px; }
.revision-row .r-time { color: var(--text-faint); font-size: 12px; }

/* ---------------- States ---------------- */
.state {
  text-align: center;
  padding: 56px 20px;
  color: var(--text-muted);
}
.state h2 {
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 400;
  margin: 0 0 8px;
  color: var(--text);
}
.state p { margin: 0 0 16px; max-width: 520px; margin-left: auto; margin-right: auto; }
.state .actions { display: inline-flex; gap: 10px; }

.loading { padding: 48px 0; text-align: center; color: var(--text-faint); font-size: 14px; }
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--link);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--accent);
  color: #fff;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 14px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.18);
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.err { background: #b32424; }

/* ---------------- Footer ---------------- */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 20px 0;
  margin-top: 40px;
  font-size: 12px;
  color: var(--text-faint);
  text-align: center;
}
.site-footer a { color: var(--text-muted); }

/* ---------------- Utilities ---------------- */
.row { display: flex; gap: 12px; align-items: center; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; }

@media (max-width: 640px) {
  .header-inner { gap: 12px; }
  .brand-name { display: none; }
  .home-hero { padding: 28px 20px; }
  .home-hero h1 { font-size: 32px; }
  .page-header { flex-direction: column; align-items: flex-start; }
}
