/* ═══════════════════════════════════════════════════════════
   Design tokens — light mode defaults
   ═══════════════════════════════════════════════════════════ */

:root {
  /* Surface colors */
  --color-bg: #f0f5f2;
  --color-text: #111111;
  --color-accent: #5b21b6;
  --accent-contrast: #ffffff;
  --color-dark: #1e3a2f;
  --color-border: #b8c9d9;
  --color-muted: #4a6070;
  --color-header: #c7caae;
  --prompt-user: #1e3a2f;
  --color-link: #7c3aed;
  --color-link-visited: #5b21b6;
  --footer-text: #1e3a2f;
  --accent-on-highlight: #5b21b6;
  --highlight-bg: #ede8f8;
  --highlight-text: #2d0e7a;

  /* Post content */
  --post-code-bg: #e8eff2;
  --post-pre-bg: #dce8e2;
  --post-pre-text: #1e3a2f;

  /* Type scale */
  --font-mono:
    ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    monospace;
  --font-sans:
    system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-display:
    ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Helvetica Neue",
    sans-serif;
  --font-reading: ui-serif, Georgia, Cambria, "Times New Roman", serif;

  /* Layout */
  --content-width: 820px;

  /* Micro-interactions */
  --transition-fast: 80ms ease;
  --transition-base: 150ms ease;
}

/* Serif/sans toggle */
:root[data-font="sans"] {
  --font-reading: var(--font-sans);
}

/* ═══════════════════════════════════════════════════════════
   Accessibility utilities
   ═══════════════════════════════════════════════════════════ */

.skip-link {
  position: absolute;
  top: -100%;
  left: 0;
  padding: 0.5rem 1rem;
  background: var(--color-text);
  color: var(--color-bg);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  z-index: 200;
  text-decoration: none;
}

.skip-link:focus {
  top: 0;
}

:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* Reset */

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

::selection {
  background: var(--highlight-bg);
  color: var(--highlight-text);
}

/* ═══════════════════════════════════════════════════════════
   Base / body
   ═══════════════════════════════════════════════════════════ */

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.7;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

/* ═══════════════════════════════════════════════════════════
   Masthead
   ═══════════════════════════════════════════════════════════ */

.site-header {
  background: var(--color-header);
  height: 48px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 100;
}

.site-header__inner {
  max-width: var(--content-width);
  margin: 0 auto;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
}

.site-wordmark {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-dark);
  text-decoration: none;
  letter-spacing: -0.01em;
  transition: color var(--transition-fast);
}

.site-wordmark:hover {
  color: var(--color-accent);
}

.site-header__actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.header-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0.35rem 0.4rem;
  color: var(--footer-text);
  transition: color var(--transition-fast);
  border-radius: 4px;
}

.header-btn:hover {
  color: var(--color-accent);
  background: rgba(0, 0, 0, 0.06);
}

.js-font-icon {
  font-size: 1.05rem;
  font-weight: 600;
}

.font-icon--serif {
  font-family: Georgia, "Times New Roman", serif;
}

.font-icon--sans {
  font-family: system-ui, -apple-system, sans-serif;
}

/* ═══════════════════════════════════════════════════════════
   Layout / main area
   ═══════════════════════════════════════════════════════════ */

main {
  width: 100%;
}

.main-inner {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
}

/* ═══════════════════════════════════════════════════════════
   Homepage intro
   ═══════════════════════════════════════════════════════════ */

.home-intro {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  margin-bottom: 2.5rem;
  padding-bottom: 2rem;
  border-bottom: 1px dashed var(--color-border);
}

.home-avatar-wrap {
  width: 160px;
  height: 160px;
  flex-shrink: 0;
  background: var(--color-border);
  border-radius: 3px;
  overflow: hidden;
  border: 2px solid var(--color-dark);
  box-shadow: 4px 4px 0 var(--color-dark);
}

.home-avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.home-intro__text {
  padding-top: 0.25rem;
}

.home-intro__text p {
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
  line-height: 1.65;
}

.home-intro__text p:last-child {
  margin-bottom: 0;
  color: var(--color-muted);
  font-size: 0.9rem;
}

.home-intro__text strong {
  color: var(--color-accent);
}

/* Terminal command prompt before intro */

.home-intro__cmd {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--color-muted);
  margin-bottom: 0.6rem;
}


/* ═══════════════════════════════════════════════════════════
   Post list section
   ═══════════════════════════════════════════════════════════ */

.posts-empty {
  font-size: 0.9rem;
  color: var(--color-muted);
  padding: 0.75rem 0;
  border-top: 1px dashed var(--color-border);
}

.posts-section-header {
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-muted);
  margin-bottom: 0.5rem;
}

.post-list {
  list-style: none;
}

.post-list__item {
  border-bottom: 1px dashed var(--color-border);
}

/* ── Post item ── */

.post-item {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.85rem 0;
  text-decoration: none;
  color: var(--color-text);
  transition: color var(--transition-fast);
}

.post-item:hover .post-item__title {
  color: var(--color-accent);
}

.post-item__title {
  font-size: 1rem;
  font-weight: 600;
  transition: color var(--transition-fast);
}

.post-item__meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--color-muted);
}

.post-item__meta-sep {
  opacity: 0.5;
}

.post-item__series {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--color-accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.15rem;
  opacity: 0.85;
}

.post-item__excerpt {
  font-size: 0.88rem;
  color: var(--color-muted);
  line-height: 1.5;
}

.post-item__tags {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
  margin-top: 0.1rem;
}

.post-item__tag {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--color-accent);
  background: var(--highlight-bg);
  padding: 0.1em 0.45em;
  border-radius: 3px;
  opacity: 0.85;
}

/* ═══════════════════════════════════════════════════════════
   Individual post — header
   ═══════════════════════════════════════════════════════════ */

.post-header {
  margin-bottom: 1.75rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px dashed var(--color-border);
}

.post-back {
  display: inline-block;
  margin-bottom: 1rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--color-muted);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.post-back:hover {
  color: var(--color-accent);
}

.post-series {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--color-accent);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 0.4rem;
}

.post-header h1 {
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  line-height: 1.2;
  margin-bottom: 0.4rem;
  letter-spacing: -0.01em;
}

.post-meta {
  color: var(--color-muted);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  margin-top: 0.4rem;
}

.post-meta__sep {
  color: var(--color-border);
}

.post-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.6rem;
}

.post-tag {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--color-accent);
  background: var(--highlight-bg);
  padding: 0.1em 0.45em;
  border-radius: 3px;
  opacity: 0.85;
}

.post-abstract {
  margin-top: 1.25rem;
  padding: 0.8rem 1rem 0.8rem 1.1rem;
  border-left: 3px solid var(--color-accent);
  background: var(--highlight-bg);
  color: var(--color-muted);
  font-style: italic;
  font-size: 0.93rem;
  line-height: 1.65;
  border-radius: 0 2px 2px 0;
}

/* ═══════════════════════════════════════════════════════════
   Individual post — content
   ═══════════════════════════════════════════════════════════ */

.post-content {
  font-family: var(--font-reading);
  font-size: 1.05rem;
  line-height: 1.75;
  margin-top: 1.5rem;
}

.post-content p,
.post-content ul,
.post-content ol {
  margin-bottom: 1.25rem;
}

.post-content li {
  margin-bottom: 0.3rem;
}

.post-content ul {
  padding-left: 1.5rem;
}

.post-content ol {
  padding-left: 1.5rem;
}

/* Accent-colored list markers */
.post-content ul li::marker,
.post-content ol li::marker {
  color: var(--color-accent);
  font-family: var(--font-mono);
  font-size: 0.85em;
}

/* Horizontal rules */
.post-content hr {
  border: none;
  border-top: 1px dashed var(--color-border);
  margin: 2rem 0;
}

.post-content h2 {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  margin: 2.25rem 0 0.65rem;
  letter-spacing: -0.01em;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--color-border);
  position: relative;
}

.post-content h3 {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  margin: 1.75rem 0 0.5rem;
  position: relative;
}

/* Heading anchors — flush left, link icon appears on hover */

.post-content .heading-anchor {
  color: inherit;
  text-decoration: none;
  transition: color var(--transition-fast);
}

.post-content .heading-anchor::after {
  content: "🔗";
  opacity: 0;
  font-size: 0.7em;
  margin-left: 0.4em;
  vertical-align: middle;
  transition: opacity var(--transition-fast);
}

.post-content h2:hover .heading-anchor::after,
.post-content h3:hover .heading-anchor::after,
.post-content .heading-anchor:focus-visible::after {
  opacity: 1;
}

.post-content .heading-anchor:hover,
.post-content .heading-anchor:focus-visible {
  color: var(--color-accent);
}

.post-content a {
  color: var(--color-link);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}

.post-content a:visited {
  color: var(--color-link-visited);
}

.post-content a:hover {
  text-decoration-thickness: 2px;
}

.post-content code {
  font-family: var(--font-mono);
  background: var(--post-code-bg);
  padding: 0.1em 0.35em;
  border-radius: 3px;
  font-size: 0.87em;
  border: 1px solid var(--color-border);
}

.post-content pre:not(.shiki) {
  background: var(--post-pre-bg);
  color: var(--post-pre-text);
  padding: 1.1rem 1.25rem;
  overflow-x: auto;
  margin-bottom: 1.25rem;
  border-radius: 4px;
  border: 1px solid var(--color-border);
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.55;
}

.post-content pre:not(.shiki) code {
  background: none;
  padding: 0;
  border: none;
  font-size: inherit;
  color: inherit;
}

.post-content .shiki {
  padding: 1.1rem 1.25rem;
  overflow-x: auto;
  margin-bottom: 1.25rem;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.55;
  border: 1px solid var(--color-border);
}

.post-content .shiki code {
  background: none;
  padding: 0;
  border: none;
  font-size: inherit;
}

.post-content blockquote {
  margin: 1.25rem 0;
  padding: 0.75rem 1rem;
  border-left: 3px solid var(--color-accent);
  background: var(--highlight-bg);
  color: var(--color-muted);
  font-style: italic;
  border-radius: 0 2px 2px 0;
}

/* Anchor target highlight — CSS-only, works with TOC links */
.post-content > h2:target,
.post-content > h3:target {
  color: var(--color-accent);
  background: var(--highlight-bg);
  padding-left: 0.5rem;
  margin-left: -0.5rem;
  border-radius: 2px;
  transition: background var(--transition-base);
}

/* Images / figures */
.post-content img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  border: 1px solid var(--color-border);
  display: block;
}

.post-content figure {
  margin: 1.5rem 0;
}

.post-content figcaption {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--color-muted);
  margin-top: 0.4rem;
  text-align: center;
}

/* Tables */
.post-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  margin-bottom: 1.25rem;
  font-family: var(--font-mono);
}

.post-content th {
  background: var(--highlight-bg);
  color: var(--color-accent);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 2px solid var(--color-accent);
}

.post-content td {
  padding: 0.4rem 0.75rem;
  border-bottom: 1px dashed var(--color-border);
  vertical-align: top;
}

.post-content tr:last-child td {
  border-bottom: none;
}

/* Keyboard shortcut callouts in post body */
.post-content kbd {
  font-family: var(--font-mono);
  background: var(--post-code-bg);
  border: 1px solid var(--color-border);
  border-bottom: 2px solid var(--color-muted);
  padding: 0.05em 0.4em;
  border-radius: 3px;
  font-size: 0.85em;
}

/* ═══════════════════════════════════════════════════════════
   Mermaid diagrams
   ═══════════════════════════════════════════════════════════ */

.mermaid-diagram {
  margin: 1.75rem 0;
  text-align: center;
  border: 1px dashed var(--color-border);
  border-radius: 4px;
  padding: 1.25rem 0.5rem;
  background: rgba(0, 0, 0, 0.01);
}

.mermaid-diagram svg {
  max-width: 100%;
  height: auto;
}

.mermaid-dark {
  display: none;
}

/* ═══════════════════════════════════════════════════════════
   Table of contents
   ═══════════════════════════════════════════════════════════ */

.post-toc {
  margin: 1.75rem 0;
  padding: 0.75rem 1rem 0.75rem 1.1rem;
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-accent);
  font-family: var(--font-mono);
  font-size: 0.83rem;
  background: var(--highlight-bg);
  border-radius: 0 4px 4px 0;
}

.post-toc__label {
  color: var(--color-accent);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 0.5rem;
}

.post-toc__list {
  list-style: decimal;
  padding-left: 1.3rem;
  margin: 0;
}

.post-toc__list li {
  margin-bottom: 0.2rem;
}

.post-toc__list a {
  color: var(--color-accent);
  text-decoration: none;
  opacity: 0.85;
}

.post-toc__list a:hover {
  text-decoration: underline;
  opacity: 1;
}

/* ═══════════════════════════════════════════════════════════
   References
   ═══════════════════════════════════════════════════════════ */

.post-references {
  margin-top: 2.25rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--color-border);
}

.post-content .post-references h2 {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-muted);
  margin: 0 0 0.6rem;
  border-bottom: none;
  padding-bottom: 0;
}

.post-references ol {
  padding-left: 1.4rem;
  font-family: var(--font-mono);
  font-size: 0.77rem;
  color: var(--color-muted);
}

.post-references li {
  margin-bottom: 0.25rem;
  word-break: break-all;
}

.post-references a {
  color: var(--color-muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.post-ref-link {
  color: var(--color-accent);
  text-decoration: none;
  font-family: var(--font-mono);
  font-size: 0.7em;
  vertical-align: super;
}

.post-ref-link:hover {
  text-decoration: underline;
}

/* ═══════════════════════════════════════════════════════════
   Footer
   ═══════════════════════════════════════════════════════════ */

.site-footer {
  background: var(--color-header);
  color: var(--footer-text);
  font-size: 0.82rem;
  font-family: var(--font-mono);
  border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.site-footer__inner {
  max-width: var(--content-width);
  margin: 0 auto;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 1.25rem 1.5rem;
}

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

.footer-link {
  color: var(--footer-text);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.footer-link:hover {
  color: var(--color-accent);
}

.footer-sep {
  color: var(--color-muted);
  opacity: 0.5;
  user-select: none;
}

.footer-copy {
  color: var(--color-muted);
  font-size: 0.78rem;
}

/* ═══════════════════════════════════════════════════════════
   Responsive — mobile
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 640px) {
  .main-inner {
    padding: 1.5rem 1rem 3rem;
  }

  .site-header__inner {
    padding: 0 1rem;
  }

  .site-footer__inner {
    flex-direction: column;
    align-items: flex-start;
    padding: 1rem;
    gap: 0.25rem;
  }

  .post-item {
    padding: 0.9rem 0;
  }
}

@media (max-width: 600px) {
  .home-intro {
    flex-direction: column;
    align-items: flex-start;
  }

  .home-avatar-wrap {
    width: 100px;
    height: 100px;
  }

  .home-intro__text {
    padding-top: 0;
  }
}

/* ═══════════════════════════════════════════════════════════
   Motion preferences
   ═══════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  .post-item,
  .post-item__title,
  .footer-link,
  .header-btn,
  .post-content .heading-anchor,
  .post-back {
    transition: none;
  }
}
