/* ==========================================================================
   大王的代码日记 —— 全站样式
   站点不使用任何 JavaScript，所有交互（包括删除确认）都靠原生表单与
   CSS 完成，因此这里也不存在任何依赖 JS 的状态。
   ========================================================================== */

:root {
  --bg: #ffffff;
  --bg-soft: #f6f8fa;
  --bg-inset: #eef1f4;
  --fg: #1f2328;
  --fg-muted: #59636e;
  --fg-faint: #818b98;
  --border: #d1d9e0;
  --border-soft: #e4e8ec;
  --accent: #1f6feb;
  --accent-hover: #1a5fd0;
  --danger: #cf222e;
  --ok: #1a7f37;
  --radius: 8px;
  --radius-sm: 6px;
  --wrap: 760px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --bg-soft: #151b23;
    --bg-inset: #1c232c;
    --fg: #e6edf3;
    --fg-muted: #9198a1;
    --fg-faint: #6e7681;
    --border: #3d444d;
    --border-soft: #262c36;
    --accent: #4493f8;
    --accent-hover: #6cb0ff;
    --danger: #f85149;
    --ok: #3fb950;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC",
    "Noto Sans CJK SC", sans-serif;
  font-size: 16px;
  line-height: 1.75;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

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

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

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

/* 键盘用户跳过导航 */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: #fff;
  padding: 8px 16px;
  z-index: 100;
}

.skip-link:focus {
  left: 8px;
  top: 8px;
}

/* ---------------------------------------------------------------- 页头 */

.site-header {
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 20;
}

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

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

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

.site-nav {
  display: flex;
  gap: 4px;
}

.site-nav a {
  color: var(--fg-muted);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  transition: background 0.15s, color 0.15s;
}

.site-nav a:hover {
  background: var(--bg-soft);
  color: var(--fg);
  text-decoration: none;
}

.site-nav a.active {
  color: var(--accent);
  font-weight: 600;
}

/* ---------------------------------------------------------------- 页脚 */

.site-footer {
  margin-top: 64px;
  border-top: 1px solid var(--border-soft);
  background: var(--bg-soft);
  padding: 28px 0 36px;
}

.footer-inner {
  text-align: center;
}

.footer-line {
  margin: 0 0 6px;
  font-size: 14px;
  color: var(--fg-muted);
}

.footer-line .sep {
  margin: 0 6px;
  color: var(--fg-faint);
}

.beian a {
  color: var(--fg-muted);
}

.beian a:hover {
  color: var(--accent);
}

.beian-pending {
  color: var(--fg-faint);
}

.footer-note {
  margin: 12px auto 0;
  max-width: 560px;
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--fg-faint);
}

/* ---------------------------------------------------------------- 友链板块 */
/* 紧贴页脚上方，独立成一栏。与页脚的 --bg-soft 拉开一点层次：
   友链用白底 + 上边框，页脚用浅灰底。 */

.friend-links {
  margin-top: 64px;
  padding: 36px 0 40px;
  border-top: 1px solid var(--border-soft);
}

.friend-links-title {
  margin: 0 0 22px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--fg-muted);
  text-align: center;
}

.friend-group + .friend-group {
  margin-top: 22px;
}

.friend-group-title {
  margin: 0 0 12px;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--fg-faint);
  text-align: center;
}

.friend-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.friend-card a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 18px 8px 9px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--bg-soft);
  color: var(--fg);
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.friend-card a:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  text-decoration: none;
}

/* 圆形头像容器。首字垫在下面，头像加载成功就盖住它。 */
.friend-avatar {
  position: relative;
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--bg-inset);
}

.friend-avatar-initial {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 700;
  color: var(--fg-faint);
  user-select: none;
}

.friend-avatar img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.friend-name {
  font-size: 14.5px;
  font-weight: 600;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- 首页 */

.intro {
  padding: 48px 0 8px;
}

.intro-title {
  margin: 0 0 6px;
  font-size: 32px;
  line-height: 1.3;
  letter-spacing: -0.3px;
}

.intro-tagline {
  margin: 0 0 16px;
  font-size: 16px;
  color: var(--accent);
  font-weight: 500;
}

.intro-desc {
  margin: 0;
  color: var(--fg-muted);
  font-size: 15.5px;
  max-width: 620px;
}

.section {
  margin-top: 44px;
}

.section-title {
  margin: 0 0 18px;
  font-size: 15px;
  font-weight: 600;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-soft);
}

/* ---------------------------------------------------------------- 文章卡片 */

.post-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.post-card {
  padding: 18px 0;
  border-bottom: 1px solid var(--border-soft);
}

.post-card:last-child {
  border-bottom: none;
}

.post-card-title {
  margin: 0 0 6px;
  font-size: 19px;
  line-height: 1.5;
  font-weight: 600;
}

.post-card-title a {
  color: var(--fg);
}

.post-card-title a:hover {
  color: var(--accent);
  text-decoration: none;
}

.post-card-meta,
.post-meta {
  margin: 0 0 8px;
  font-size: 13.5px;
  color: var(--fg-faint);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.post-card-summary {
  margin: 0;
  color: var(--fg-muted);
  font-size: 15px;
  line-height: 1.7;
}

.more {
  margin-top: 22px;
  font-size: 15px;
}

.empty {
  color: var(--fg-faint);
  padding: 24px 0;
}

/* ---------------------------------------------------------------- 标签 */

.tag {
  display: inline-block;
  font-size: 13px;
  color: var(--fg-muted);
  background: var(--bg-inset);
  padding: 1px 9px;
  border-radius: 999px;
  line-height: 1.7;
}

.tag:hover {
  color: var(--accent);
  background: var(--bg-soft);
  text-decoration: none;
}

.tag-count {
  margin-left: 5px;
  color: var(--fg-faint);
  font-size: 12px;
}

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.tag-cloud-lg .tag {
  font-size: 14.5px;
  padding: 4px 14px;
}

/* ---------------------------------------------------------------- 页面标题 */

.page-title {
  margin: 40px 0 6px;
  font-size: 26px;
  line-height: 1.4;
}

.page-sub {
  margin: 0 0 24px;
  color: var(--fg-faint);
  font-size: 14.5px;
}

/* ---------------------------------------------------------------- 分页 */

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid var(--border-soft);
  font-size: 14.5px;
}

.page-btn {
  color: var(--accent);
}

.page-btn.disabled {
  color: var(--fg-faint);
  cursor: not-allowed;
}

.page-info {
  color: var(--fg-faint);
  font-size: 13.5px;
}

/* ---------------------------------------------------------------- 文章正文 */

.post-header {
  margin: 40px 0 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-soft);
}

.post-title {
  margin: 0 0 12px;
  font-size: 30px;
  line-height: 1.4;
  letter-spacing: -0.3px;
}

.prose {
  font-size: 16.5px;
  line-height: 1.85;
  color: var(--fg);
  word-wrap: break-word;
}

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

.prose h2 {
  margin: 44px 0 14px;
  font-size: 22px;
  line-height: 1.5;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-soft);
}

.prose h3 {
  margin: 32px 0 12px;
  font-size: 18.5px;
  line-height: 1.5;
}

.prose h4 {
  margin: 26px 0 10px;
  font-size: 16.5px;
}

.prose p {
  margin: 0 0 18px;
}

.prose ul,
.prose ol {
  margin: 0 0 18px;
  padding-left: 26px;
}

.prose li {
  margin-bottom: 7px;
}

.prose li > ul,
.prose li > ol {
  margin: 7px 0 0;
}

.prose blockquote {
  margin: 0 0 18px;
  padding: 2px 0 2px 18px;
  border-left: 3px solid var(--border);
  color: var(--fg-muted);
}

.prose hr {
  margin: 36px 0;
  border: none;
  border-top: 1px solid var(--border-soft);
}

.prose img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
}

/* 行内代码 */
.prose code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo,
    "Courier New", monospace;
  font-size: 0.88em;
  background: var(--bg-inset);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  word-break: break-word;
}

/* 代码块 */
.prose pre {
  margin: 0 0 20px;
  padding: 16px 18px;
  background: var(--bg-soft);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  overflow-x: auto;
  line-height: 1.65;
}

.prose pre code {
  background: none;
  padding: 0;
  font-size: 13.5px;
  border-radius: 0;
  white-space: pre;
  word-break: normal;
}

.prose table {
  width: 100%;
  margin: 0 0 20px;
  border-collapse: collapse;
  font-size: 15px;
  display: block;
  overflow-x: auto;
}

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

.prose th {
  background: var(--bg-soft);
  font-weight: 600;
}

.prose a {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.post-nav {
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--border-soft);
  font-size: 15px;
}

/* ---------------------------------------------------------------- 按钮 */

.btn {
  display: inline-block;
  padding: 9px 20px;
  font-size: 15px;
  font-family: inherit;
  font-weight: 500;
  line-height: 1.5;
  color: #fff;
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: center;
}

.btn:hover {
  background: var(--accent-hover);
  color: #fff;
  text-decoration: none;
}

.btn-ghost {
  background: transparent;
  color: var(--fg-muted);
  border-color: var(--border);
}

.btn-ghost:hover {
  background: var(--bg-soft);
  color: var(--fg);
}

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

.btn-danger:hover {
  background: var(--danger);
  opacity: 0.88;
}

.link-btn {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-size: 14px;
  color: var(--accent);
  cursor: pointer;
}

.link-btn:hover {
  text-decoration: underline;
}

.link-btn.danger {
  color: var(--danger);
}

/* ---------------------------------------------------------------- 表单 */

.narrow {
  max-width: 460px;
  margin: 0 auto;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.form-wide {
  max-width: 100%;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.field-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.field-row > .field {
  flex: 1 1 240px;
}

.field-row > .field-narrow {
  flex: 0 0 140px;
}

input[type="text"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.6;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

textarea {
  resize: vertical;
  line-height: 1.7;
}

textarea[name="body_md"] {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo,
    "Courier New", monospace;
  font-size: 14px;
  line-height: 1.75;
}

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

.inline-form {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.confirm-delete {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--fg-faint);
  cursor: pointer;
  white-space: nowrap;
}

.confirm-delete input {
  width: auto;
  margin: 0;
}

.hint {
  font-size: 13.5px;
  color: var(--fg-faint);
  line-height: 1.7;
}

/* ---------------------------------------------------------------- 提示条 */

.alert {
  margin: 20px 0;
  padding: 11px 15px;
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  border: 1px solid;
}

.alert-error {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 8%, transparent);
  border-color: color-mix(in srgb, var(--danger) 30%, transparent);
}

.alert-ok {
  color: var(--ok);
  background: color-mix(in srgb, var(--ok) 8%, transparent);
  border-color: color-mix(in srgb, var(--ok) 30%, transparent);
}

/* ---------------------------------------------------------------- 后台 */

.admin-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin: 24px 0 8px;
  padding: 10px 14px;
  background: var(--bg-soft);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
}

.admin-badge {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-muted);
  letter-spacing: 0.3px;
}

.admin-nav {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 14px;
}

.admin-nav a.active {
  color: var(--fg);
  font-weight: 600;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14.5px;
}

.admin-table th {
  text-align: left;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--fg-faint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

.admin-table td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}

.row-title {
  display: block;
  color: var(--fg);
  font-weight: 500;
}

.row-title:hover {
  color: var(--accent);
}

.row-slug {
  display: block;
  font-size: 12px;
  color: var(--fg-faint);
  font-family: "SFMono-Regular", Consolas, monospace;
}

.col-date {
  color: var(--fg-faint);
  white-space: nowrap;
  font-size: 13.5px;
}

.col-actions {
  white-space: nowrap;
  text-align: right;
}

.col-actions form {
  margin-left: 10px;
}

.status {
  display: inline-block;
  font-size: 12.5px;
  padding: 1px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

.status-pub {
  color: var(--ok);
  background: color-mix(in srgb, var(--ok) 12%, transparent);
}

.status-draft {
  color: var(--fg-faint);
  background: var(--bg-inset);
}

.danger-zone {
  margin-top: 56px;
  padding: 20px;
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--danger) 4%, transparent);
}

.danger-zone h2 {
  margin: 0 0 6px;
  font-size: 15px;
  color: var(--danger);
}

.danger-zone p {
  margin: 0 0 16px;
  font-size: 14px;
  color: var(--fg-muted);
}

/* ---------------------------------------------------------------- 错误页 */

.error-page {
  text-align: center;
  padding: 72px 0;
}

.error-badge {
  margin: 0 0 8px;
  font-size: 56px;
  font-weight: 700;
  line-height: 1;
  color: var(--border);
  letter-spacing: -2px;
}

.error-actions {
  margin-top: 28px;
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ---------------------------------------------------------------- 首页两栏 + TODO 侧栏 */

/* 文章页、关于页等仍是原来的 760px 单栏；
   只有首页在 TODO 有内容时才放宽容器，好并排放侧栏。 */
.wrap-wide {
  max-width: 1080px;
}

.home-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 32px;
  align-items: start;
}

/* has-side 由模板按"有没有 TODO 条目"决定。
   不靠 :has() 判断，是为了在 TODO 为空时网格真的只有一列，
   而不是留出一个永远空着的第二列。 */
.home-grid.has-side {
  grid-template-columns: minmax(0, 1fr) 264px;
}

.home-main {
  /* 网格项默认 min-width:auto，长 URL 或代码块会把整列撑破。 */
  min-width: 0;
}

.side-col {
  position: sticky;
  /* 站点头是 sticky top:0 且 min-height 60px，这里让开它。 */
  top: 76px;
  min-width: 0;
}

.todo-card {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--bg-soft);
  padding: 16px 18px;
}

.todo-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.todo-count {
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-faint);
  font-variant-numeric: tabular-nums;
}

.todo-list {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 14px;
  line-height: 1.6;
}

.todo-group {
  margin: 14px 0 6px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--fg-faint);
  letter-spacing: 0.08em;
}

.todo-group:first-child {
  margin-top: 0;
}

.todo-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 3px 0;
  color: var(--fg);
}

.todo-box {
  position: relative;
  flex: none;
  width: 14px;
  height: 14px;
  margin-top: 4px;
  border: 1.5px solid var(--border);
  border-radius: 3px;
}

/* 勾选态用纯 CSS 画对勾：全站零 JavaScript，也不引入图标字体。 */
.todo-item.is-done .todo-box {
  border-color: var(--ok);
  background: var(--ok);
}

.todo-item.is-done .todo-box::after {
  content: "";
  position: absolute;
  left: 3.5px;
  top: 0.5px;
  width: 4px;
  height: 8px;
  border: solid #fff;
  border-width: 0 1.8px 1.8px 0;
  transform: rotate(42deg);
}

.todo-item.is-done .todo-text {
  color: var(--fg-faint);
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

.todo-note {
  padding: 3px 0;
  color: var(--fg-muted);
}

/* ---------------------------------------------------------------- 响应式 */

@media (max-width: 640px) {
  body {
    font-size: 15.5px;
  }

  .wrap {
    padding: 0 16px;
  }

  /* 窄屏放不下两列：侧栏落到正文下方，并取消吸附。 */
  .home-grid.has-side {
    grid-template-columns: minmax(0, 1fr);
    gap: 24px;
  }

  .side-col {
    position: static;
  }

  /* 窄屏放不下并排的友链卡片：一行一个。 */
  .friend-card {
    width: 100%;
  }

  .friend-card a {
    max-width: none;
  }

  .intro {
    padding-top: 32px;
  }

  .intro-title {
    font-size: 26px;
  }

  .post-title {
    font-size: 24px;
  }

  .page-title {
    font-size: 22px;
  }

  .prose {
    font-size: 16px;
  }

  .prose h2 {
    font-size: 19.5px;
  }

  .header-inner {
    min-height: 54px;
  }

  .site-nav a {
    padding: 6px 9px;
    font-size: 14px;
  }

  .admin-table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  .admin-bar {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }
}

@media print {
  .site-header,
  .site-footer,
  .post-nav,
  .pagination,
  .admin-bar,
  .side-col {
    display: none;
  }
}
