/* ==========================================================================
   Design tokens
   ========================================================================== */
:root {
  --bg: #faf8f5;
  --surface: #ffffff;
  --fg: #22252a;
  --fg-soft: #4a4f57;
  --muted: #7a808a;
  --border: #e7e2da;
  --accent: #0f7a6c;
  --accent-soft: #e3f2ef;
  --accent-fg: #ffffff;
  --code-bg: #f3f1ed;
  --shadow: 0 1px 2px rgb(34 37 42 / 4%), 0 4px 16px rgb(34 37 42 / 5%);
  --radius: 14px;
  --font-sans: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP",
    "Yu Gothic UI", "Meiryo", system-ui, -apple-system, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "Menlo", "Consolas", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1b1e23;
    --fg: #e8e6e3;
    --fg-soft: #c3c6cc;
    --muted: #8c929c;
    --border: #2c3038;
    --accent: #4fc4b2;
    --accent-soft: #19332f;
    --accent-fg: #0f1513;
    --code-bg: #0f1114;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 25%);
  }
}

/* ==========================================================================
   Base
   ========================================================================== */
*, *::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: var(--font-sans);
  font-size: 16px;
  line-height: 1.9;
  letter-spacing: 0.02em;
  font-feature-settings: "palt" 0;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

main { flex: 1; padding-block: 2.5rem 4rem; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

.container { width: 100%; max-width: 44rem; margin-inline: auto; padding-inline: 20px; }

/* ==========================================================================
   Header / Footer
   ========================================================================== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  -webkit-backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; height: 60px; }

.brand { display: inline-flex; align-items: center; gap: .6rem; color: var(--fg); }
.brand:hover { text-decoration: none; }
.brand-icon { border-radius: 8px; }
.brand-name { font-weight: 700; font-size: 1.1rem; letter-spacing: .04em; }

.site-nav { display: flex; align-items: center; gap: .25rem; font-size: .9rem; }
.site-nav a {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .35rem .75rem; border-radius: 999px; color: var(--fg-soft);
}
.site-nav a:hover { background: var(--accent-soft); color: var(--accent); text-decoration: none; }
.site-nav a[aria-current="page"] { color: var(--accent); font-weight: 600; }

.site-footer { border-top: 1px solid var(--border); color: var(--muted); font-size: .85rem; }
.footer-inner { display: flex; justify-content: space-between; gap: 1rem; padding-block: 1.75rem; flex-wrap: wrap; }
.footer-inner a { color: var(--muted); }
.footer-inner a:hover { color: var(--accent); }

/* ==========================================================================
   Shared pieces
   ========================================================================== */
.intro { margin-bottom: 2.5rem; }
.intro-title { font-size: clamp(1.75rem, 5vw, 2.25rem); line-height: 1.3; margin: 0 0 .5rem; letter-spacing: .03em; }
.intro-text { color: var(--fg-soft); margin: 0; }

.section-title {
  font-size: .8rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted); margin: 0 0 1rem; scroll-margin-top: 80px;
}

.post-meta { margin: 0; color: var(--muted); font-size: .85rem; display: flex; gap: .5rem; flex-wrap: wrap; }

.tag-list, .tag-cloud { list-style: none; padding: 0; margin: .75rem 0 0; display: flex; flex-wrap: wrap; gap: .4rem; }
.tag {
  display: inline-block; padding: .1rem .7rem; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  font-size: .8rem; line-height: 1.8;
}
.tag:hover { text-decoration: none; filter: brightness(.97); }
.tag .count { opacity: .7; margin-left: .2rem; font-size: .75rem; }

.button {
  display: inline-block; padding: .55rem 1.25rem; border-radius: 999px;
  background: var(--accent); color: var(--accent-fg); font-weight: 600;
}
.button:hover { text-decoration: none; filter: brightness(1.05); }

/* ==========================================================================
   Post list (home)
   ========================================================================== */
.post-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 1rem; }
.post-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.4rem 1.5rem;
  box-shadow: var(--shadow);
  transition: transform .15s ease, border-color .15s ease;
}
.post-card:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.post-card-title { font-size: 1.2rem; line-height: 1.5; margin: .2rem 0 .4rem; }
.post-card-title a { color: var(--fg); }
/* Make the whole card clickable while keeping tag links usable */
.post-card-title a::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); }
.post-card .tag-list { position: relative; z-index: 1; }
.post-card-summary { color: var(--fg-soft); font-size: .92rem; margin: 0; line-height: 1.8; }
.empty { color: var(--muted); }

/* ==========================================================================
   Tags page
   ========================================================================== */
.tag-cloud { margin: 0 0 2.5rem; }
.tag-section { margin-bottom: 2.25rem; }
.compact-list { list-style: none; padding: 0; margin: 0; border-top: 1px solid var(--border); }
.compact-list li { display: flex; gap: 1rem; padding: .7rem .25rem; border-bottom: 1px solid var(--border); align-items: baseline; }
.compact-list time { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.compact-list a { color: var(--fg); }
.compact-list a:hover { color: var(--accent); }

/* ==========================================================================
   Post page
   ========================================================================== */
.post-header { margin-bottom: 2.5rem; padding-bottom: 1.75rem; border-bottom: 1px solid var(--border); }
.post-title { font-size: clamp(1.7rem, 5vw, 2.3rem); line-height: 1.4; margin: .4rem 0 0; letter-spacing: .03em; }

.prose { font-size: 1.02rem; overflow-wrap: anywhere; }
.prose > :first-child { margin-top: 0; }
.prose p, .prose ul, .prose ol, .prose blockquote, .prose table, .prose pre, .prose figure { margin: 0 0 1.5em; }
.prose h1, .prose h2, .prose h3, .prose h4 { line-height: 1.5; letter-spacing: .03em; scroll-margin-top: 80px; }
.prose h1 { font-size: 1.6rem; margin: 2.5em 0 .8em; }
.prose h2 {
  font-size: 1.4rem; margin: 2.4em 0 .8em; padding-left: .8rem;
  border-left: 4px solid var(--accent);
}
.prose h3 { font-size: 1.15rem; margin: 2em 0 .6em; }
.prose h4 { font-size: 1rem; margin: 1.8em 0 .5em; }
.prose ul, .prose ol { padding-left: 1.5em; }
.prose li + li { margin-top: .3em; }
.prose li::marker { color: var(--accent); }
.prose img { max-width: 100%; height: auto; border-radius: 10px; display: block; margin-inline: auto; }
.prose hr { border: 0; height: 1px; background: var(--border); margin: 3em 0; }
.prose blockquote {
  padding: .9rem 1.2rem; border-left: 4px solid var(--border);
  background: var(--surface); border-radius: 0 10px 10px 0; color: var(--fg-soft);
}
.prose blockquote > :last-child { margin-bottom: 0; }
.prose table { width: 100%; border-collapse: collapse; font-size: .92rem; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--border); padding: .5rem .8rem; text-align: left; }
.prose th { background: var(--code-bg); }

/* Code */
code, pre { font-family: var(--font-mono); font-size: .88em; }
.prose :not(pre) > code {
  background: var(--code-bg); border: 1px solid var(--border);
  padding: .1em .4em; border-radius: 6px;
}
.prose pre, .prose .highlight {
  border-radius: 10px;
}
.prose pre {
  padding: 1rem 1.2rem; overflow-x: auto; line-height: 1.65;
  border: 1px solid var(--border); background: var(--code-bg);
}
.prose div.highlight { margin-bottom: 1.5em; }
.prose div.highlight pre { margin: 0; }

/* Pager */
.post-pager { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 3.5rem; }
.pager-link {
  display: flex; flex-direction: column; gap: .2rem;
  padding: 1rem 1.2rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface);
}
.pager-link:hover { text-decoration: none; border-color: var(--accent); }
.pager-link.next { text-align: right; grid-column: 2; }
.pager-label { font-size: .8rem; color: var(--muted); }
.pager-title { color: var(--fg); font-weight: 600; }
.back-link { margin-top: 2.5rem; font-size: .9rem; }

/* 404 */
.not-found { text-align: center; padding-block: 3rem; }
.not-found-code { font-size: 4.5rem; font-weight: 800; color: var(--accent); margin: 0; line-height: 1; letter-spacing: .05em; }
.not-found .intro-text { margin-bottom: 1.75rem; }

/* ==========================================================================
   Small screens
   ========================================================================== */
@media (max-width: 560px) {
  body { font-size: 15.5px; }
  .container { padding-inline: 16px; }
  .brand-name { font-size: 1rem; }
  .site-nav a { padding: .35rem .55rem; }
  .site-nav a span { display: none; }
  .post-card { padding: 1.2rem 1.15rem; }
  .post-pager { grid-template-columns: 1fr; }
  .pager-link.next { grid-column: auto; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .post-card { transition: none; }
  .post-card:hover { transform: none; }
}

/* Let the pre block own the code background (Rouge sets its own) */
.prose .highlight, .prose .highlight .w { background-color: transparent; }
