/* --- Base reset / tokens ---------------------------------------------- */

:root {
  --bg: #fafafa;
  --text: #1a1a1a;
  --muted: #6b6b6b;
  --rule: #e5e5e5;
  --link: #0b5fa5;
  --accent: #1a1a1a;
  --container: 680px;
  --rhythm: 24px;
  --rhythm-lg: 40px;
  --rhythm-xl: 64px;
  --thumb-nav-height: 56px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

a { color: var(--link); text-decoration: underline; text-underline-offset: 2px; }
a:visited { color: var(--link); }
a:hover { text-decoration-thickness: 2px; }

.skip-link {
  position: absolute;
  left: -9999px;
}
.skip-link:focus {
  position: static;
  display: inline-block;
  padding: 8px 12px;
  background: #fff;
}

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

/* --- Header / footer -------------------------------------------------- */

.site-header {
  padding: var(--rhythm-lg) 0 var(--rhythm);
  border-bottom: 1px solid var(--rule);
  margin-bottom: var(--rhythm-lg);
}
.site-title {
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--accent);
  text-decoration: none;
}
.site-tagline {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.site-footer {
  margin-top: var(--rhythm-xl);
  padding: var(--rhythm) 0 var(--rhythm-lg);
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-size: 0.9rem;
}
.site-footer p { margin: 4px 0; }
.site-footer a { color: var(--muted); }

/* --- Page heading ----------------------------------------------------- */

.page-heading {
  font-size: 1.6rem;
  font-weight: 600;
  margin: 0 0 var(--rhythm);
  letter-spacing: -0.01em;
}

/* --- Post list (home / tag) ------------------------------------------- */

.post-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.post-list > li {
  border-bottom: 1px solid var(--rule);
  padding: var(--rhythm) 0 var(--rhythm-lg);
}
.post-list > li:last-child { border-bottom: none; }

.post-card-title {
  font-size: 1.35rem;
  line-height: 1.25;
  margin: 0 0 8px;
  font-weight: 600;
  letter-spacing: -0.005em;
}
.post-card-title a { color: var(--accent); text-decoration: none; }
.post-card-title a:hover { text-decoration: underline; }

.post-meta {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 12px;
}
.post-meta time {
  font-variant: all-small-caps;
  letter-spacing: 0.04em;
}
.meta-sep { margin: 0 0.4em; }

.tag {
  display: inline-block;
  padding: 1px 8px;
  margin-right: 4px;
  border: 1px solid var(--rule);
  border-radius: 3px;
  font-size: 0.78rem;
  color: var(--muted);
  text-decoration: none;
}
.tag:hover { color: var(--accent); border-color: var(--accent); }

.post-excerpt { margin: 12px 0 8px; }
.post-card-more { margin: 8px 0 0; }
.more-link {
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  font-size: 0.95em;
}
.more-link:hover { color: var(--accent); text-decoration: underline; }

/* --- Single post ------------------------------------------------------ */

.post-header { margin-bottom: var(--rhythm-lg); }
.post-title {
  font-size: 2rem;
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin: 0 0 12px;
  font-weight: 600;
}

.post-actions {
  margin: 16px 0 0;
  display: flex;
  gap: 10px;
}
.btn {
  display: inline-block;
  padding: 6px 14px;
  border: 1px solid var(--text);
  border-radius: 3px;
  font-size: 0.85rem;
  text-decoration: none;
  color: var(--text);
  background: transparent;
}
.btn:hover { background: var(--text); color: var(--bg); }

.post-body {
  font-size: 1.05rem;
  text-align: justify;
  -webkit-hyphens: auto;
  hyphens: auto;
  hyphenate-limit-chars: 8 4 4;
}
.post-body .image-caption,
.post-body figcaption,
.post-body h1, .post-body h2, .post-body h3, .post-body h4 {
  text-align: initial;
  hyphens: manual;
}
.post-body .image-caption { text-align: center; }
.post-excerpt { text-align: justify; hyphens: auto; }
.post-body h2 { font-size: 1.4rem; margin-top: var(--rhythm-lg); letter-spacing: -0.005em; }
.post-body h3 { font-size: 1.15rem; margin-top: var(--rhythm); }
.post-body p, .post-body ul, .post-body ol, .post-body blockquote, .post-body pre, .post-body table {
  margin: 0 0 1em;
}
.post-body img { max-width: 100%; height: auto; display: block; margin: 1em auto; }
.post-body figure { margin: 1em 0; text-align: center; }
.post-body .image-caption {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: -0.5em;
}
.post-body blockquote {
  border-left: 2px solid var(--rule);
  margin-left: 0;
  padding: 0 0 0 1em;
  color: var(--muted);
}
.post-body code {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  background: #f1f1f1;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.92em;
}
.post-body pre {
  background: #f4f4f4;
  padding: 14px 16px;
  border-radius: 4px;
  overflow-x: auto;
  font-size: 0.9rem;
}
.post-body pre code { background: none; padding: 0; }
.post-body table { border-collapse: collapse; width: 100%; }
.post-body th, .post-body td {
  border: 1px solid var(--rule);
  padding: 8px 10px;
  text-align: left;
}
.post-body hr { border: 0; border-top: 1px solid var(--rule); margin: var(--rhythm-lg) 0; }

.post-footer {
  margin-top: var(--rhythm-xl);
  padding-top: var(--rhythm);
  border-top: 1px solid var(--rule);
  font-size: 0.9rem;
  color: var(--muted);
}
.post-footer a { color: var(--muted); }

/* --- Pagination ------------------------------------------------------- */

.pagination {
  margin: var(--rhythm-lg) 0 var(--rhythm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.9rem;
}
.pagination .page-link { text-decoration: none; color: var(--accent); }
.pagination .page-link.disabled { color: var(--muted); pointer-events: none; }
.page-numbers { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.page-num {
  display: inline-block;
  min-width: 26px;
  text-align: center;
  padding: 2px 6px;
  border-radius: 3px;
  text-decoration: none;
  color: var(--muted);
}
.page-num.current { color: var(--accent); border-bottom: 1px solid var(--accent); }
.ellipsis { color: var(--muted); }

/* --- Tags index ------------------------------------------------------- */

.tag-cloud {
  list-style: none;
  margin: var(--rhythm) 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  line-height: 1.8;
}
.tag-cloud a {
  text-decoration: none;
  color: var(--accent);
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
}
.tag-cloud a:hover { text-decoration: underline; }
.tag-count { color: var(--muted); font-size: 0.7em; }

/* --- Mobile thumb-zone bottom bar ------------------------------------- */

.thumb-nav { display: none; }

@media (max-width: 768px) {
  body { padding-bottom: calc(var(--thumb-nav-height) + env(safe-area-inset-bottom)); }
  .thumb-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--thumb-nav-height);
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: saturate(140%) blur(8px);
    -webkit-backdrop-filter: saturate(140%) blur(8px);
    border-top: 1px solid var(--rule);
    z-index: 100;
  }
  .thumb-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    text-decoration: none;
    color: var(--accent);
    font-size: 0.72rem;
    min-height: 44px;
  }
  .thumb-nav-item svg { width: 22px; height: 22px; }
  .thumb-nav-item:hover { color: var(--link); }
}

/* --- Stats page ------------------------------------------------------- */

.stats-section { margin: var(--rhythm-lg) 0; }
.stats-h2 {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  margin: 0 0 var(--rhythm);
}

.window-switcher {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 0.85rem;
  margin: 0 0 var(--rhythm-lg);
  padding-bottom: 12px;
  border-bottom: 1px solid var(--rule);
}
.window-switcher a { color: var(--muted); text-decoration: none; }
.window-switcher a:hover { color: var(--accent); text-decoration: underline; }
.window-switcher .current {
  color: var(--accent);
  font-weight: 600;
  border-bottom: 1px solid var(--accent);
}

.stats-headline dl {
  display: flex;
  flex-wrap: wrap;
  gap: 8px var(--rhythm-lg);
  margin: 0;
}
.stats-headline dl > div { min-width: 6rem; }
.stats-headline dt {
  color: var(--muted);
  font-size: 0.78rem;
  font-variant: all-small-caps;
  letter-spacing: 0.04em;
  margin: 0;
}
.stats-headline dd {
  margin: 2px 0 0;
  font-size: 1.6rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.stats-graph {
  width: 100%;
  height: auto;
  display: block;
  margin: 0 0 var(--rhythm);
}
.stats-graph .axis  { stroke: var(--rule); stroke-width: 1; }
.stats-graph .line  { stroke: var(--accent); stroke-width: 1.5; fill: none; }
.stats-graph .area  { fill: var(--accent); fill-opacity: 0.06; stroke: none; }
.stats-graph .label {
  font-size: 11px;
  fill: var(--muted);
  font-variant: all-small-caps;
  letter-spacing: 0.04em;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
.stats-table th, .stats-table td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--rule);
}
.stats-table th {
  font-weight: 600;
  font-size: 0.78rem;
  font-variant: all-small-caps;
  letter-spacing: 0.04em;
  color: var(--muted);
  border-bottom-color: var(--accent);
}
.stats-table .rank { color: var(--muted); width: 2rem; font-variant-numeric: tabular-nums; }
.stats-table .count { text-align: right; font-variant-numeric: tabular-nums; width: 5rem; }
.stats-table a { color: var(--accent); text-decoration: none; }
.stats-table a:hover { text-decoration: underline; }

/* --- Print (desktop screen view → paper) ----------------------------- */

@media print {
  :root { --bg: #fff; }
  body { background: #fff; padding-bottom: 0; font-size: 11pt; line-height: 1.5; }
  .container { max-width: none; padding: 0; }
  .site-header, .site-footer, .thumb-nav,
  .post-actions, .post-footer { display: none !important; }
  a { color: inherit; text-decoration: underline; }
  a[href^="http"]:after {
    content: " (" attr(href) ")";
    font-size: 0.85em;
    color: #555;
    word-break: break-all;
  }
  .post-body img { page-break-inside: avoid; }
  h1, h2, h3 { page-break-after: avoid; }
  pre, blockquote { page-break-inside: avoid; }
}
