/* ---------- Tokens ---------- */
:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --text: #1d1c1a;
  --muted: #6b6862;
  --border: #e6e2da;
  --accent: #b4451f;
  --code-bg: #f3f1ec;
  --shadow: 0 1px 2px rgb(0 0 0 / .04), 0 8px 24px rgb(0 0 0 / .06);

  --maxw: 1100px;

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Charter, Georgia, serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141413;
    --surface: #1d1c1a;
    --text: #ecebe6;
    --muted: #a19e96;
    --border: #2f2d2a;
    --accent: #f08a5d;
    --code-bg: #232220;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141413;
  --surface: #1d1c1a;
  --text: #ecebe6;
  --muted: #a19e96;
  --border: #2f2d2a;
  --accent: #f08a5d;
  --code-bg: #232220;
  --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .35);
  color-scheme: dark;
}


/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.6 var(--sans);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
main { flex: 1; }
a { color: var(--accent); text-underline-offset: 2px; }
img { max-width: 100%; height: auto; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

.container {
  width: min(var(--maxw), calc(100% - 32px));
  margin-inline: auto;
}

.skip-link {
  position: absolute; left: 16px; top: -40px;
  background: var(--surface); color: var(--text);
  padding: 6px 12px; border-radius: 6px; z-index: 10;
}
.skip-link:focus { top: 12px; }

/* ---------- Header ---------- */
.site-header {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding-block: 28px 20px;
}
.brand {
  display: flex; align-items: center; gap: 14px;
  color: var(--text); text-decoration: none; min-width: 0;
}
.avatar {
  width: 56px; height: 56px; flex: none;
  border-radius: 50%; object-fit: cover;
  border: 2px solid var(--border);
  background: var(--code-bg);
}
.brand-name {
  font-size: 1.45rem; font-weight: 700; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.site-nav { display: flex; align-items: center; gap: 8px; flex: none; }
.site-nav a {
  color: var(--muted); text-decoration: none; font-weight: 500;
  padding: 6px 10px; border-radius: 8px;
}
.site-nav a:hover, .site-nav a[aria-current] { color: var(--text); }

.theme-toggle {
  display: grid; place-items: center;
  width: 38px; height: 38px; padding: 0;
  border: 1px solid var(--border); border-radius: 50%;
  background: var(--surface); color: var(--text); cursor: pointer;
}
.theme-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.theme-toggle .icon-moon { fill: currentColor; stroke: none; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

/* ---------- Post feed (vertical) ---------- */
.feed-section { max-width: 720px; padding-block: 16px 56px; }
.feed-head {
  margin: 0 0 16px; font-size: .85rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
}
.feed { list-style: none; margin: 0; padding: 0; display: grid; gap: 20px; }
.card { display: flex; }
.card-link {
  display: flex; flex-direction: column; gap: 8px; width: 100%;
  padding: 24px 24px 20px;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px;
  color: var(--text); text-decoration: none;
  box-shadow: var(--shadow);
  transition: transform .2s ease, border-color .2s ease;
}
.card-link:hover { transform: translateY(-3px); border-color: var(--accent); }
.card-image {
  margin: -24px -24px 8px; width: calc(100% + 48px); max-width: none;
  aspect-ratio: 16 / 9; object-fit: cover;
  border-radius: 15px 15px 0 0;
}
.card-date { font-size: .82rem; color: var(--muted); }
.card-title { margin: 0; font-size: 1.45rem; line-height: 1.3; letter-spacing: -.01em; }
.card-excerpt {
  margin: 0; color: var(--muted); font-size: .95rem;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.card-more { padding-top: 4px; color: var(--accent); font-weight: 600; font-size: .9rem; }
.card-all .card-link { border-style: dashed; box-shadow: none; }

.empty { color: var(--muted); }

/* ---------- Post ---------- */
.post { max-width: 720px; padding-block: 24px 56px; }
.post-title { font-size: clamp(1.9rem, 5vw, 2.7rem); line-height: 1.15; letter-spacing: -.02em; margin: 0 0 10px; }
.post-meta { color: var(--muted); font-size: .92rem; margin: 0 0 32px; }
.post-content { font-family: var(--serif); font-size: 1.14rem; line-height: 1.72; overflow-wrap: break-word; }
.post-content h2, .post-content h3, .post-content h4 { font-family: var(--sans); line-height: 1.25; margin: 2em 0 .6em; }
.post-content img { border-radius: 10px; }
.post-content blockquote {
  margin: 1.5em 0; padding: .2em 0 .2em 1.1em;
  border-left: 3px solid var(--accent); color: var(--muted);
}
.post-content blockquote > :first-child { margin-top: 0; }
.post-content blockquote > :last-child { margin-bottom: 0; }
.post-content hr { border: 0; border-top: 1px solid var(--border); margin: 2.5em 0; }
.post-content table { border-collapse: collapse; width: 100%; font-family: var(--sans); font-size: .95rem; display: block; overflow-x: auto; }
.post-content th, .post-content td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
code, pre { font-family: var(--mono); font-size: .86em; }
:not(pre) > code { background: var(--code-bg); padding: .12em .35em; border-radius: 5px; }
pre {
  background: var(--code-bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 16px; overflow-x: auto; line-height: 1.5;
}
.highlighter-rouge .highlight { background: none; }

.post-nav {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
  margin-top: 56px; padding-top: 24px; border-top: 1px solid var(--border);
}
.post-nav a {
  display: flex; flex-direction: column; gap: 2px;
  color: var(--text); text-decoration: none; font-weight: 600;
}
.post-nav a span { color: var(--muted); font-weight: 400; font-size: .85rem; }
.post-nav .next { grid-column: 2; text-align: right; }
.post-nav a:hover { color: var(--accent); }

/* ---------- Archives ---------- */
.archives { max-width: 720px; padding-block: 24px 56px; }
.archives h1 { font-size: 2rem; margin: 0 0 8px; }
.archive-year { font-size: 1rem; color: var(--muted); margin: 32px 0 8px; }
.archive-list { list-style: none; margin: 0; padding: 0; }
.archive-list li {
  display: flex; gap: 16px; align-items: baseline;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.archive-list time { flex: 0 0 4.2em; color: var(--muted); font-size: .9rem; font-variant-numeric: tabular-nums; }
.archive-list a { color: var(--text); text-decoration: none; }
.archive-list a:hover { color: var(--accent); text-decoration: underline; }

/* ---------- Footer ---------- */
.site-footer {
  display: flex; justify-content: space-between; gap: 16px;
  padding-block: 24px 32px; border-top: 1px solid var(--border);
  color: var(--muted); font-size: .88rem;
}
.site-footer a { color: var(--muted); }
.footer-links { display: flex; gap: 16px; }

/* ---------- Syntax highlighting (Rouge) ---------- */
.highlight .c, .highlight .c1, .highlight .cm, .highlight .cs { color: var(--muted); font-style: italic; }
.highlight .k, .highlight .kd, .highlight .kn, .highlight .kr, .highlight .kt, .highlight .nt { color: var(--accent); }
.highlight .s, .highlight .s1, .highlight .s2, .highlight .sb, .highlight .sh { color: #2f7d4f; }
.highlight .m, .highlight .mi, .highlight .mf, .highlight .no { color: #7a4fb8; }
.highlight .nf, .highlight .nc, .highlight .na { color: #1f6fb4; }
:root[data-theme="dark"] .highlight :is(.s, .s1, .s2, .sb, .sh) { color: #8fd19e; }
:root[data-theme="dark"] .highlight :is(.m, .mi, .mf, .no) { color: #c5a3ff; }
:root[data-theme="dark"] .highlight :is(.nf, .nc, .na) { color: #7cc0ff; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .highlight :is(.s, .s1, .s2, .sb, .sh) { color: #8fd19e; }
  :root:not([data-theme="light"]) .highlight :is(.m, .mi, .mf, .no) { color: #c5a3ff; }
  :root:not([data-theme="light"]) .highlight :is(.nf, .nc, .na) { color: #7cc0ff; }
}

/* ---------- Small screens ---------- */
@media (max-width: 639px) {
  body { font-size: 16px; }
  .site-header { padding-block: 18px 12px; }
  .avatar { width: 44px; height: 44px; }
  .brand { gap: 10px; }
  .brand-name { font-size: 1.15rem; line-height: 1.2; white-space: normal; }
  .site-nav a { padding: 6px 4px; }
  .card-link { padding: 18px; }
  .card-image { margin: -18px -18px 4px; width: calc(100% + 36px); }
  .card-title { font-size: 1.25rem; }
  .post-content { font-size: 1.06rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
}
