/* ─── tokens ──────────────────────────────────────────── */
:root {
  --bg:        #fbfaf7;
  --fg:        #1a1a1a;
  --muted:    #6b6b6b;
  --faint:    #a8a8a8;
  --rule:     #e8e6e0;
  --accent:   #b04a2f;       /* 砖红，克制 */
  --hover:    #f3f1ec;
  --mono:     ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --serif:    Georgia, "Source Han Serif SC", "Songti SC", serif;
  --sans:     -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
              "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --max:      720px;
  --toc-w:    180px;
  --gap:      48px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:     #161513;
    --fg:     #e8e4d8;
    --muted:  #8c8a82;
    --faint:  #5a584f;
    --rule:   #2a2823;
    --accent: #d68465;
    --hover:  #20201c;
  }
}

/* ─── reset ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent); }
h1, h2, h3 { font-weight: 600; letter-spacing: -0.005em; }
img { max-width: 100%; display: block; }
button, input, select { font: inherit; color: inherit; }

/* ─── public page ─────────────────────────────────────── */
.page {
  max-width: calc(var(--max) + var(--toc-w) + var(--gap));
  margin: 0 auto;
  padding: 72px 32px 96px;
  display: grid;
  grid-template-columns: minmax(0, var(--max)) var(--toc-w);
  grid-template-areas:
    "head head"
    "main toc"
    "foot foot";
  column-gap: var(--gap);
}

.site-head { grid-area: head; margin-bottom: 56px; }
.site-head h1 {
  font-family: var(--serif);
  font-size: 32px;
  margin: 0 0 4px;
  letter-spacing: -0.02em;
}
.site-head .sub { color: var(--muted); margin: 0; }

.content { grid-area: main; min-width: 0; }

.group { margin-bottom: 56px; }
.group:last-child { margin-bottom: 0; }
.group-head-pub {
  margin: 0 0 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--rule);
  scroll-margin-top: 24px;
}
.group-name {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
  color: var(--fg);
  margin: 0;
  letter-spacing: -0.01em;
  line-height: 1.2;
}
.group-desc {
  margin: 6px 0 0;
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.5;
}
/* anchor scroll target moved to the wrapper */
.group { scroll-margin-top: 24px; }

.links { list-style: none; margin: 0; padding: 0; }
.link { margin: 0; }
.link-row {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  align-items: baseline;
  column-gap: 10px;
  padding: 7px 8px;
  margin: 0 -8px;
  border-radius: 4px;
  transition: background-color 80ms ease;
}
.link-row:hover { background: var(--hover); }
.favicon {
  width: 16px; height: 16px;
  align-self: center;
  border-radius: 3px;
  opacity: 0.92;
}
.link-row .name {
  font-weight: 500;
  font-size: 15.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.link-row .note {
  color: var(--muted);
  font-size: 14px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.link-row .note::before { content: "— "; color: var(--faint); }
.link-row .host {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: -0.01em;
}

/* note 在第二列，需要单独栅格 */
.link-row { grid-template-columns: 18px minmax(0, auto) minmax(0, 1fr) auto; }
.link-row .name { grid-column: 2; }
.link-row .note { grid-column: 3; }
.link-row .host { grid-column: 4; }
.link-row:not(:has(.note)) .name { grid-column: 2 / span 2; }

.empty, .empty-mini { color: var(--muted); }
.empty-mini { font-size: 13px; margin: 0; }

/* ─── toc (desktop) ───────────────────────────────────── */
.toc {
  grid-area: toc;
  position: sticky;
  top: 56px;
  align-self: start;
  border-left: 1px solid var(--rule);
  padding-left: 20px;
}
.toc-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--faint);
  margin-bottom: 12px;
}
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 8px 0; }
.toc a {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13.5px;
  color: var(--muted);
  transition: color 100ms ease;
}
.toc a.active, .toc a:hover { color: var(--fg); }
.toc a.active .toc-count { color: var(--accent); }
.toc-count {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--faint);
}

@media (max-width: 880px) {
  .page {
    grid-template-columns: 1fr;
    grid-template-areas: "head" "main" "foot";
    padding: 48px 20px 64px;
  }
  .toc { display: none; }
}

/* ─── footer ──────────────────────────────────────────── */
.site-foot {
  grid-area: foot;
  margin-top: 72px;
  font-size: 12px;
  color: var(--faint);
  border-top: 1px solid var(--rule);
  padding-top: 20px;
  text-align: center;
}
.site-foot span { display: block; }
.site-foot a { color: var(--muted); }

/* ─── admin ───────────────────────────────────────────── */
body.admin { background: var(--bg); }
.admin-wrap {
  max-width: 980px;
  margin: 0 auto;
  padding: 32px 28px 64px;
}
.admin-head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 32px;
}
.admin-head h1 { font-family: var(--serif); font-size: 22px; margin: 0; }
.admin-head nav a { margin-left: 16px; color: var(--muted); font-size: 13px; }
.admin-head nav a:hover { color: var(--accent); }

.admin-section { margin-bottom: 40px; }
.admin-section > h2 {
  font-size: 16px; margin: 0 0 12px;
}
.group-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px;
  margin-bottom: 8px;
}
.group-head-left { min-width: 0; flex: 1; }
.group-head h2 { font-size: 15px; margin: 0; font-weight: 600; }
.group-desc-mini { margin: 2px 0 0; font-size: 12.5px; }
.group-head .actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.admin button.arrow {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--rule);
  padding: 2px 8px;
  font-size: 13px;
  line-height: 1;
}
.admin button.arrow:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); }
.admin button.arrow:disabled { opacity: 0.3; cursor: not-allowed; }

.row-form {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}

.admin input[type=text], .admin input:not([type]), .admin input[type=url], .admin input[type=number],
.admin input[type=password], .admin select {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 6px 8px;
  font-size: 13px;
  width: 100%;
  min-width: 0;
}
.admin input:focus, .admin select:focus {
  outline: none; border-color: var(--accent);
}

.admin button {
  background: var(--fg);
  color: var(--bg);
  border: none;
  border-radius: 3px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}
.admin button:hover { opacity: 0.85; }
.admin button.danger {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--rule);
}
.admin button.danger:hover { color: var(--accent); border-color: var(--accent); }
.admin a.cancel { color: var(--muted); font-size: 13px; }

.links-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  table-layout: fixed;
}
.links-table th, .links-table td {
  text-align: left;
  padding: 7px 8px;
  border-bottom: 1px solid var(--rule);
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.links-table th {
  font-weight: 500;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--rule);
}
.links-table .url-cell { font-family: var(--mono); font-size: 12px; }
.links-table .url-cell a { color: var(--muted); }
.links-table .url-cell a:hover { color: var(--accent); }
.links-table .actions { white-space: nowrap; }
.links-table .actions > * { margin-right: 8px; }
.links-table .actions > *:last-child { margin-right: 0; }
.links-table tr.editing td { background: var(--hover); }
.links-table tr.add-row td { background: color-mix(in srgb, var(--hover) 60%, transparent); }
.links-table tr.add-row input { background: var(--bg); }

.muted { color: var(--muted); }
.footer-tip { font-size: 12px; }

/* ─── login ───────────────────────────────────────────── */
.login-page { display: grid; place-items: center; min-height: 100vh; }
.login-card {
  width: 280px;
  padding: 32px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--bg);
}
.login-card h1 { font-size: 15px; margin: 0 0 16px; font-weight: 500; }
.login-card input { width: 100%; margin-bottom: 12px; }
.login-card button { width: 100%; padding: 8px; }
.login-card .err {
  color: var(--accent); font-size: 12px;
  margin: -8px 0 12px;
}
.login-card .hint { font-size: 12px; color: var(--faint); margin: 16px 0 0; text-align: center; }

/* ─── kind badge (admin) ──────────────────────────────── */
.kind-badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 3px;
  font-family: var(--mono);
  letter-spacing: 0.02em;
  border: 1px solid var(--rule);
  color: var(--muted);
  white-space: nowrap;
}
.kind-badge.kind-doc {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--rule));
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.links-table colgroup col.kind { width: 60px; }

/* ─── group foot (admin) ──────────────────────────────── */
.group-foot-actions {
  margin-top: 8px;
  padding-left: 8px;
}
.btn-link {
  display: inline-block;
  font-size: 13px;
  color: var(--muted);
  border: 1px dashed var(--rule);
  border-radius: 3px;
  padding: 4px 10px;
}
.btn-link:hover { color: var(--accent); border-color: var(--accent); }

/* ─── doc form (admin) ────────────────────────────────── */
.doc-form-section {
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 20px;
  background: color-mix(in srgb, var(--hover) 50%, transparent);
}
.doc-form .doc-form-row {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.doc-form label {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  color: var(--muted);
  gap: 4px;
  min-width: 140px;
}
.doc-form label.grow { flex: 1; min-width: 200px; }
.doc-form .doc-content-label { width: 100%; }
.doc-form textarea {
  width: 100%;
  min-height: 320px;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 10px 12px;
  font: 13.5px/1.6 var(--mono);
  resize: vertical;
}
.doc-form textarea:focus { outline: none; border-color: var(--accent); }
.doc-form-actions {
  margin-top: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
}

/* ─── doc indicator on public list ───────────────────── */
.link.is-doc .host {
  color: var(--accent);
  font-family: var(--sans);
  font-size: 11.5px;
  letter-spacing: 0;
  opacity: 0.85;
}

/* ─── article page ────────────────────────────────────── */
body.article-page { background: var(--bg); }
.article-wrap {
  max-width: var(--max);
  margin: 0 auto;
  padding: 56px 28px 80px;
}
.article-nav {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 32px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.article-nav a { color: var(--muted); }
.article-nav a:hover { color: var(--accent); }
.article-head {
  margin-bottom: 32px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--rule);
}
.article-head h1 {
  font-family: var(--serif);
  font-size: 30px;
  margin: 0 0 8px;
  line-height: 1.25;
  letter-spacing: -0.015em;
}
.article-note {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}
.article-body {
  font-size: 16px;
  line-height: 1.75;
}
.article-body h1, .article-body h2, .article-body h3,
.article-body h4, .article-body h5, .article-body h6 {
  font-family: var(--serif);
  margin: 1.8em 0 0.6em;
  line-height: 1.3;
}
.article-body h1 { font-size: 24px; }
.article-body h2 { font-size: 21px; padding-bottom: 4px; border-bottom: 1px solid var(--rule); }
.article-body h3 { font-size: 18px; }
.article-body h4, .article-body h5, .article-body h6 { font-size: 16px; color: var(--muted); }
.article-body p { margin: 0 0 1.1em; }
.article-body a { color: var(--accent); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; }
.article-body a:hover { text-decoration-thickness: 2px; }
.article-body ul, .article-body ol { padding-left: 1.6em; margin: 0 0 1.1em; }
.article-body li { margin: 0.2em 0; }
.article-body blockquote {
  margin: 1.2em 0;
  padding: 4px 16px;
  border-left: 3px solid var(--accent);
  color: var(--muted);
  background: var(--hover);
}
.article-body blockquote p { margin: 0.4em 0; }
.article-body code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--hover);
  padding: 1px 6px;
  border-radius: 3px;
}
.article-body pre {
  background: var(--hover);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 14px 16px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.55;
  margin: 0 0 1.2em;
}
.article-body pre code {
  background: transparent;
  padding: 0;
  font-size: inherit;
}
.article-body img {
  border-radius: 4px;
  margin: 0.6em 0;
}
.article-body hr {
  border: none;
  border-top: 1px solid var(--rule);
  margin: 2em 0;
}
.article-body table {
  border-collapse: collapse;
  margin: 0 0 1.2em;
  font-size: 14px;
  width: 100%;
  display: block;
  overflow-x: auto;
}
.article-body thead { background: var(--hover); }
.article-body th, .article-body td {
  border: 1px solid var(--rule);
  padding: 6px 12px;
  text-align: left;
  vertical-align: top;
}
.article-body th { font-weight: 600; }
.article-body tbody tr:nth-child(even) {
  background: color-mix(in srgb, var(--hover) 40%, transparent);
}

/* GitHub 风格提示框 */
.article-body blockquote.alert {
  border-left-width: 4px;
  padding: 12px 16px;
  background: var(--hover);
}
.article-body blockquote.alert::before {
  display: block;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
  text-transform: uppercase;
  font-family: var(--sans);
}
.article-body blockquote.alert-note     { border-left-color: #3b82f6; }
.article-body blockquote.alert-note::before     { content: "Note"; color: #3b82f6; }
.article-body blockquote.alert-tip      { border-left-color: #16a34a; }
.article-body blockquote.alert-tip::before      { content: "Tip"; color: #16a34a; }
.article-body blockquote.alert-important{ border-left-color: #8b5cf6; }
.article-body blockquote.alert-important::before{ content: "Important"; color: #8b5cf6; }
.article-body blockquote.alert-warning  { border-left-color: #d97706; }
.article-body blockquote.alert-warning::before  { content: "Warning"; color: #d97706; }
.article-body blockquote.alert-caution  { border-left-color: #dc2626; }
.article-body blockquote.alert-caution::before  { content: "Caution"; color: #dc2626; }

/* blockquote 内的块级内容（表格、段落、列表）保持紧凑 */
.article-body blockquote > p:first-of-type { margin-top: 0; }
.article-body blockquote > p:last-child    { margin-bottom: 0; }
.article-body blockquote table {
  margin: 0.6em 0;
  background: var(--bg);
}
.article-page .site-foot {
  margin-top: 64px;
  font-size: 12px;
  color: var(--faint);
  border-top: 1px solid var(--rule);
  padding-top: 20px;
  text-align: center;
}
.article-page .site-foot a { color: var(--muted); }

@media (max-width: 640px) {
  .article-wrap { padding: 36px 18px 56px; }
  .article-head h1 { font-size: 24px; }
  .article-body { font-size: 15px; }
}
