:root {
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #6b7280;
  --accent: #b82417;
  --border: #e5e7eb;
  --code-bg: #f5f5f7;
  --surface: #fafafa;
  --max-width: 880px;
  --read-width: 720px;
  --header-height: 76px;
}

:root[data-theme="dark"] {
  --bg: #0f1115;
  --fg: #e6e6e6;
  --muted: #9ca3af;
  --accent: #e85d4f;
  --border: #23262d;
  --code-bg: #15171c;
  --surface: #14161b;
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

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

body {
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.15s ease, color 0.15s ease;
}

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

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

a:hover { text-decoration: underline; }

/* Skip-to-content link — visible only when focused (keyboard/screen-reader users) */
.skip-link {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  padding: 0.55rem 0.9rem;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  border-radius: 6px;
  transform: translateY(-150%);
  transition: transform 0.15s ease;
  z-index: 200;
}

.skip-link:focus {
  transform: translateY(0);
  outline: none;
  text-decoration: none;
}

/* Header */
.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: relative;
  z-index: 50;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  gap: 1rem;
}

.site-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  color: var(--fg);
  font-weight: 700;
  font-size: 1.3rem;
}

.site-brand:hover { text-decoration: none; }

.site-logo {
  width: 44px;
  height: 44px;
  display: block;
}

.site-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.site-nav a {
  color: var(--muted);
  font-size: 1.05rem;
}

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

/* Shared icon buttons */
.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 6px;
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover { background: var(--code-bg); }

.theme-toggle { font-size: 1rem; line-height: 1; }
.theme-icon-light, .theme-icon-dark { display: none; }
:root[data-theme="light"] .theme-icon-dark { display: inline; }
:root[data-theme="dark"] .theme-icon-light { display: inline; }

/* Hamburger */
.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
}

.nav-toggle-bar {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--fg);
  border-radius: 2px;
  transition: transform 0.22s ease, opacity 0.18s ease;
}

.site-header.is-open .nav-toggle-bar:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.site-header.is-open .nav-toggle-bar:nth-child(2) { opacity: 0; transform: scaleX(0); }
.site-header.is-open .nav-toggle-bar:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* Main */
.site-main {
  padding-top: 2rem;
  padding-bottom: 3rem;
  min-height: 70vh;
}

.intro { text-align: center; padding: 0; margin: -1.02rem 0 -1.28rem; }
.intro-logo {
  width: 168px;
  height: 168px;
  display: block;
  margin: 0 auto;
  filter: drop-shadow(0 6px 18px rgba(0, 0, 0, 0.12));
}

/* Home sections */
.home-section { margin-top: 2.5rem; }

.home-section > h2 {
  margin: 0 0 1rem;
  font-size: 1.25rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.4rem;
}

.about-body p { margin: 0 0 0.75rem; }
.about-body p:last-child { margin-bottom: 0; }

/* Social links */
.social-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.social-list a {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--fg);
  background: var(--surface);
  font-size: 0.95rem;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.social-list a:hover {
  background: var(--code-bg);
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}

.social-icon {
  width: 1.05em;
  height: 1.05em;
  flex-shrink: 0;
}

/* PGP */
.pgp-block {
  margin: 1rem 0 0;
  font-size: 0.8em;
  max-height: 420px;
  overflow: auto;
}

/* Home layout (main column + sidebar) */
.home-layout { margin-top: 0; }

/* Sidebar posts — appears on every page via the default layout. */
.sidebar-posts {
  max-width: var(--max-width);
  margin: 2.5rem auto 0;
  padding: 0 1.25rem;
}

.sidebar-posts-logo {
  display: block;
  text-align: center;
  margin-bottom: 0.85rem;
}

.sidebar-posts-logo img {
  width: 96px;
  height: 96px;
  display: inline-block;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.1));
}

/* On wide viewports, the posts sidebar floats in the empty margin to the left of the centered content. */
@media (min-width: 1440px) {
  .sidebar-posts {
    position: fixed;
    top: calc(var(--header-height) + 1.5rem);
    left: calc((100vw - var(--max-width)) / 2 - 260px - 1.5rem);
    width: 260px;
    max-width: 260px;
    max-height: calc(100vh - var(--header-height) - 3rem);
    overflow-y: auto;
    margin: 0;
    padding: 0;
  }

  .sidebar-posts-logo { margin-bottom: 0.51rem; }

  .sidebar-posts-logo img {
    width: 108px;
    height: 108px;
  }
}

/* Sidebar posts list (collapsible) */
.sidebar-posts-details { width: 100%; }

.sidebar-posts-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
  user-select: none;
  transition: color 0.15s ease;
}

.sidebar-posts-summary::-webkit-details-marker { display: none; }

.sidebar-posts-summary::after,
.post-toc-summary::after {
  content: '';
  display: inline-block;
  width: 0.7rem;
  height: 0.7rem;
  border-top: 2px solid var(--muted);
  border-right: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.2s ease;
  transform-origin: 50% 50%;
  flex-shrink: 0;
  margin-right: 0.15rem;
}

.sidebar-posts-details[open] .sidebar-posts-summary::after,
.post-toc-details[open] .post-toc-summary::after { transform: rotate(135deg); }

.sidebar-posts-summary:hover { color: var(--fg); }

.sidebar-post-list {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 0;
}

.sidebar-post-list li + li { border-top: 1px solid var(--border); }

.sidebar-post-list a {
  display: block;
  padding: 0.72rem 0;
  color: var(--fg);
}

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

.sidebar-post-list time {
  display: block;
  color: var(--muted);
  font-size: 0.94rem;
  font-variant-numeric: tabular-nums;
  margin-bottom: 0.18rem;
}

.sidebar-post-title { font-size: 1.32rem; line-height: 1.35; font-weight: 600; }

.see-all {
  display: inline-block;
  margin-top: 0.85rem;
  font-size: 0.9rem;
}

/* Full posts page */
.post-list-full {
  list-style: none;
  padding: 0;
  margin: 0;
}

.post-list-full li {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}

.post-list-full li:last-child { border-bottom: none; }

.post-list-full time {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
}

.post-list-full a { font-size: 2em; }

/* Post table of contents — shown in the right margin on wide viewports only */
.post-toc { display: none; }

@media (min-width: 1440px) {
  .post-toc[hidden] { display: none; }
  .post-toc {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: calc(var(--header-height) + 1.5rem);
    bottom: 1.5rem;
    left: calc((100vw + var(--max-width)) / 2 + 1.5rem);
    width: 240px;
    overflow: hidden;
  }
}

.post-toc-details {
  width: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1 1 auto;
}

.post-toc-nav {
  min-height: 0;
  flex: 1 1 auto;
  overflow-y: auto;
}

.post-toc-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-shrink: 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
  user-select: none;
  transition: color 0.15s ease;
}

.post-toc-summary::-webkit-details-marker { display: none; }

.post-toc-summary:hover { color: var(--fg); }

.post-toc-nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.post-toc-nav > ul { margin-top: 0.65rem; }

.post-toc-nav li {
  padding: 0.3rem 0;
}

/* Rail lives on the nested <ul> so per-item spacing doesn't affect it. */
.post-toc-nav ul ul {
  margin-left: 0.5rem;
  padding-left: 0.85rem;
  border-left: 2px solid var(--border);
}

.post-toc-nav a {
  color: var(--fg);
  font-size: 0.9rem;
  line-height: 1.3;
}

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

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

/* Hide the sidebar scrollbar — scrolling still works, just no visible bar. */
.sidebar-posts {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.sidebar-posts::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

/* Thin themed scrollbar on the post TOC dropdown */
.post-toc-nav {
  scrollbar-width: thin;
  scrollbar-color: var(--muted) transparent;
}

.post-toc-nav::-webkit-scrollbar {
  width: 6px;
}

.post-toc-nav::-webkit-scrollbar-track {
  background: transparent;
}

.post-toc-nav::-webkit-scrollbar-thumb {
  background: var(--muted);
  border-radius: 3px;
}

.post-toc-nav::-webkit-scrollbar-thumb:hover {
  background: var(--fg);
}

/* Post */
.post { max-width: var(--read-width); margin: 0 auto; }
.post-header { margin-bottom: 1.5rem; text-align: center; }
.post-title { margin: 0 0 0.25rem; font-size: 1.9rem; line-height: 1.25; }
.post-meta { color: var(--muted); margin: 0; font-size: 0.9rem; }

.post-content h2 { margin-top: 2rem; }
.post-content h3 { margin-top: 1.5rem; }

.post-content h1,
.post-content h2,
.post-content h3,
.post-content h4,
.post-content h5,
.post-content h6 {
  scroll-margin-top: 1.5rem;
}

.post-content img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
}

/* Share row at the bottom of a post */
.post-share {
  margin: 2.5rem 0 0;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.post-share-label {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.post-share-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.post-share-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--fg);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.post-share-btn:hover {
  background: var(--code-bg);
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}

.post-share-icon-copied { display: none; }

.post-share-copy.is-copied {
  border-color: var(--accent);
  color: var(--accent);
}

.post-share-copy.is-copied .post-share-icon-default { display: none; }
.post-share-copy.is-copied .post-share-icon-copied { display: inline-flex; }

blockquote {
  border-left: 3px solid var(--border);
  margin: 1rem 0;
  padding: 0.25rem 1rem;
  color: var(--muted);
}

code {
  background: var(--code-bg);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-size: 0.92em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

pre {
  background: var(--code-bg);
  padding: 1rem;
  border-radius: 8px;
  overflow-x: auto;
  border: 1px solid var(--border);
}

pre code {
  background: transparent;
  padding: 0;
  font-size: 0.88em;
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.9rem;
  padding: 1.5rem 0;
}

.site-footer p { margin: 0; }

/* Mobile */
@media (max-width: 640px) {
  body { font-size: 16px; }
  .intro-logo { width: 132px; height: 132px; }
  .post-title { font-size: 1.5rem; }

  .post-list-full li { padding: 0.8rem 0; }

  .post-list-full time { font-size: 0.85rem; }

  .nav-toggle { display: inline-flex; }

  .site-nav {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 1.25rem;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transform: translateY(-6px);
    transition: max-height 0.28s ease, opacity 0.2s ease, transform 0.25s ease, padding 0.2s ease;
  }

  .site-header.is-open .site-nav {
    max-height: calc(100vh - var(--header-height));
    opacity: 1;
    transform: translateY(0);
    padding: 0.35rem 1.25rem 0.75rem;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12);
    overflow-y: auto;
  }

  .site-nav > a {
    padding: 0.85rem 0.25rem;
    border-bottom: 1px solid var(--border);
    color: var(--fg);
    font-size: 1rem;
  }

  body > .sidebar-posts { display: none; }
}
