/* ============================================================================
   GRAPHITE — dark, done properly.
   Keeps the night look but fixes what made it tiring: a neutral cool graphite
   instead of warm brown-black, body text in a real text face at real contrast,
   mono kept for headings, metadata and code where it earns its keep. One cool
   jade accent. Dark by default; the light mode is chalk.
   ========================================================================== */

:root {
  color-scheme: dark;

  --bg:        #131619;
  --surface:   #191d21;
  --code-bg:   #171b1f;
  --wash:      #1c2126;

  --fg:        #e7eaed;
  --fg-mute:   #ccd3d8;
  --fg-dim:    #8b949c;

  --rule:      #262c32;
  --rule-soft: #1e2429;
  --faint:     #3d474e;

  --accent:      #57cfa5;
  --accent-soft: rgba(87, 207, 165, 0.13);

  --sans: 'Public Sans', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --sidebar: 13rem;
  --rail:    13rem;
  --measure: 70ch;
  --shell:   84rem;
}

:root[data-theme='light'] {
  color-scheme: light;

  --bg:        #f4f5f6;
  --surface:   #ffffff;
  --code-bg:   #ffffff;
  --wash:      #eaecee;

  --fg:        #15181b;
  --fg-mute:   #32383d;
  --fg-dim:    #6b737a;

  --rule:      #dbdfe2;
  --rule-soft: #e6e9eb;
  --faint:     #b3bac0;

  --accent:      #0d7a5c;
  --accent-soft: rgba(13, 122, 92, 0.10);
}

* { box-sizing: border-box; }

html {
  scrollbar-color: var(--rule) transparent;
  scrollbar-width: thin;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg-mute);
  font-family: var(--sans);
  font-size: 16.5px;
  line-height: 1.72;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--accent-soft); color: var(--fg); }

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

.skip-link {
  position: absolute;
  left: -9999px;
  background: var(--surface);
  color: var(--accent);
  padding: 0.6em 1em;
  border: 1px solid var(--rule);
  z-index: 20;
}
.skip-link:focus { left: 1rem; top: 1rem; }

/* ---------------------------------------------------------------- typography */

a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  transition: border-color 0.14s ease, color 0.14s ease;
}
a:hover { border-bottom-color: var(--accent); }

h1, h2, h3, h4 {
  font-family: var(--mono);
  color: var(--fg);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.025em;
  text-wrap: balance;
}

h1 { font-size: 1.72rem; margin: 0 0 0.7rem; }
h2 { font-size: 1.18rem; margin: 2.9em 0 0.7em; }
h3 { font-size: 1rem; margin: 2.1em 0 0.5em; }
h4 { font-size: 0.92rem; margin: 1.8em 0 0.4em; color: var(--fg-mute); }

/* markdown-native section marker, not terminal cosplay */
article h2 {
  padding-top: 1em;
  border-top: 1px solid var(--rule);
}
article h2::before {
  content: '#';
  color: var(--accent);
  font-weight: 400;
  margin-right: 0.6em;
}
article h3::before {
  content: '##';
  color: var(--fg-dim);
  font-weight: 400;
  margin-right: 0.55em;
  font-size: 0.9em;
}

/* One post repeats its title as an H1 in the body; the layout already
   renders it. Drop the duplicate rather than showing the title twice. */
article > h1 ~ h1 { display: none; }

article :is(h1, h2, h3, h4) { scroll-margin-top: 2rem; }

p, ul, ol { margin: 1.05em 0; }
article ul, article ol { padding-left: 1.3em; }
article li { margin: 0.35em 0; }
article li::marker { color: var(--accent); }
article li > p:first-child { margin-top: 0; }
article li > p:last-child  { margin-bottom: 0; }

strong { color: var(--fg); font-weight: 600; }
em { font-style: italic; color: var(--fg); }

article > :is(p, ul, ol, h3, h4, blockquote) { max-width: var(--measure); }

hr { border: 0; border-top: 1px solid var(--rule); margin: 2.8em 0; }

/* --------------------------------------------------------------------- code */

code {
  font-family: var(--mono);
  font-size: 0.83em;
  background: var(--wash);
  color: var(--fg);
  padding: 0.14em 0.4em;
  border-radius: 3px;
  word-break: break-word;
}

pre {
  margin: 0;
  padding: 1rem 1.2rem;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 0.775rem;
  line-height: 1.65;
  background: var(--code-bg);
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
}
pre code { background: none; padding: 0; font-size: inherit; white-space: pre; color: inherit; }

pre.astro-code,
pre.astro-code span { color: var(--shiki-dark); }
:root[data-theme='light'] pre.astro-code,
:root[data-theme='light'] pre.astro-code span { color: var(--shiki-light); }

.code-block {
  margin: 1.8em 0;
  border: 1px solid var(--rule);
  border-radius: 5px;
  overflow: hidden;
  background: var(--code-bg);
}
.code-toolbar {
  display: flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.42em 0.55em 0.42em 0.9em;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 0.66rem;
  user-select: none;
}
.code-lang { flex: 1; color: var(--fg-dim); letter-spacing: 0.05em; }
.code-btn {
  font: inherit;
  background: none;
  color: var(--fg-dim);
  border: 1px solid transparent;
  padding: 2px 8px;
  border-radius: 3px;
  cursor: pointer;
  transition: color 0.14s ease, background 0.14s ease;
}
.code-btn:hover { color: var(--accent); background: var(--accent-soft); }
.code-btn[aria-pressed='true'], .code-btn.is-ok { color: var(--accent); background: var(--accent-soft); }

.code-block.is-wrap pre,
.code-block.is-wrap pre code,
.code-block.is-wrap pre .line { white-space: pre-wrap; word-break: break-word; }
.code-block.is-wrap pre { overflow-x: visible; }

/* ------------------------------------------------------------------ figures */

img { max-width: 100%; height: auto; }

article p:has(> img) { margin: 1.9em 0; max-width: none; }
article img {
  display: block;
  border: 1px solid var(--rule);
  border-radius: 4px;
  cursor: zoom-in;
  transition: border-color 0.14s ease;
}
article img:hover { border-color: var(--accent); }

blockquote {
  margin: 1.5em 0;
  padding: 0.7em 1.1em;
  background: var(--surface);
  border-left: 2px solid var(--accent);
  border-radius: 0 4px 4px 0;
  color: var(--fg-mute);
}
blockquote p { margin: 0.35em 0; }

table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.6em 0;
  font-size: 0.88em;
  font-variant-numeric: tabular-nums;
}
th, td { border-bottom: 1px solid var(--rule); padding: 0.5em 0.85em 0.5em 0; text-align: left; }
th {
  color: var(--fg-dim);
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  border-bottom-color: var(--fg-dim);
}

kbd {
  font-family: var(--mono);
  font-size: 0.78em;
  background: var(--wash);
  border: 1px solid var(--rule);
  border-bottom-width: 2px;
  border-radius: 3px;
  padding: 0.1em 0.4em;
  color: var(--fg);
}

/* -------------------------------------------------------------------- shell */

.layout {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  column-gap: 3.2rem;
  max-width: var(--shell);
  margin: 0 auto;
  padding: 2.8rem 1.8rem 0;
}
.layout:has(aside.toc) {
  grid-template-columns: var(--sidebar) minmax(0, 1fr) var(--rail);
}
main { min-width: 0; padding-bottom: 4rem; }

.sidebar .side-section h4,
aside.toc h4 {
  margin: 0 0 0.7rem;
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--fg-dim);
}
.sidebar .side-section h4::before,
aside.toc h4::before { content: '// '; color: var(--faint); }

/* sidebar ------------------------------------------------------------------ */

.sidebar {
  position: sticky;
  top: 2.8rem;
  align-self: start;
  max-height: calc(100vh - 3.8rem);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
}

.brand {
  font-family: var(--mono);
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--fg);
  margin-bottom: 1.7rem;
}
.brand::after { content: '_'; color: var(--accent); margin-left: 0.06em; }

.sidebar nav ul { list-style: none; margin: 0; padding: 0; }
.sidebar nav a {
  display: block;
  font-family: var(--mono);
  font-size: 0.84rem;
  padding: 0.32em 0.6em;
  margin-left: -0.6em;
  border-radius: 3px;
  border-bottom: 0;
  color: var(--fg-dim);
  transition: color 0.14s ease, background 0.14s ease;
}
.sidebar nav a::before { content: '/'; color: var(--faint); margin-right: 0.45em; }
.sidebar nav a:hover { color: var(--fg); background: var(--wash); }
.sidebar nav a:hover::before { color: var(--accent); }
.sidebar nav a.active { color: var(--accent); background: var(--accent-soft); }
.sidebar nav a.active::before { color: var(--accent); }

.sidebar .side-section { margin-top: 2.1rem; }
.sidebar .side-section ul { list-style: none; margin: 0; padding: 0; }

.side-tags li {
  display: flex;
  justify-content: space-between;
  gap: 0.5em;
  padding: 0.15em 0;
  font-size: 0.8rem;
  color: var(--fg-mute);
}
.side-tags .count {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  color: var(--fg-dim);
}

.side-recent li { margin: 0.55em 0; }
.side-recent a {
  display: block;
  font-size: 0.81rem;
  line-height: 1.42;
  color: var(--fg-dim);
  border-bottom: 0;
  transition: color 0.14s ease;
}
.side-recent a:hover { color: var(--accent); }

.side-controls {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin: 2.1rem 0 1.5rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--rule);
}
.lang-switch { display: flex; gap: 0.3rem; }
.lang-switch a {
  font-family: var(--mono);
  font-size: 0.68rem;
  padding: 2px 8px;
  border: 1px solid var(--rule);
  border-radius: 3px;
  color: var(--fg-dim);
  transition: all 0.14s ease;
}
.lang-switch a:hover { color: var(--fg); border-color: var(--fg-dim); }
.lang-switch a.active { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

.theme-toggle {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  margin-left: auto;
  padding: 0;
  background: none;
  border: 0;
  color: var(--fg-dim);
  cursor: pointer;
  transition: color 0.14s ease;
}
.theme-toggle:hover { color: var(--accent); }
.theme-toggle svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
.theme-toggle .i-moon { fill: currentColor; stroke: none; }
:root[data-theme='light'] .theme-toggle .i-sun,
:root[data-theme='dark']  .theme-toggle .i-moon { display: none; }

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

main > h1 { margin-bottom: 1.8rem; }

.post-list { list-style: none; padding: 0; margin: 0; counter-reset: post; }
.post-list li + li { border-top: 1px solid var(--rule-soft); }

.post-list a {
  display: grid;
  grid-template-columns: 2.6rem minmax(0, 1fr);
  grid-template-areas: 'idx title' 'idx excerpt' 'idx meta';
  column-gap: 0.6rem;
  padding: 1.25rem 0.9rem;
  margin-inline: -0.9rem;
  border-bottom: 0;
  border-radius: 5px;
  transition: background 0.14s ease;
}
.post-list a::before {
  grid-area: idx;
  counter-increment: post;
  content: counter(post, decimal-leading-zero);
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--faint);
  padding-top: 0.4em;
  transition: color 0.14s ease;
}
.post-list a:hover { background: var(--wash); }
.post-list a:hover::before { color: var(--accent); }
.post-list a:hover .title { color: var(--accent); }

.post-list .title {
  grid-area: title;
  font-family: var(--mono);
  font-size: 0.98rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.4;
  color: var(--fg);
  transition: color 0.14s ease;
}
.post-list .excerpt {
  grid-area: excerpt;
  margin-top: 0.35rem;
  font-size: 0.87rem;
  line-height: 1.55;
  color: var(--fg-dim);
  max-width: 62ch;
}
.post-list .meta {
  grid-area: meta;
  margin-top: 0.5rem;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.03em;
  font-variant-numeric: tabular-nums;
  color: var(--fg-dim);
}

/* post header ------------------------------------------------------------- */

.post-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3em 0.9em;
  margin: 0 0 2.6rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.02em;
  color: var(--fg-dim);
}
.post-meta a { color: var(--fg-dim); border-bottom-color: var(--rule); }
.post-meta a:hover { color: var(--accent); }

.tag {
  display: inline-block;
  padding: 1px 7px;
  border: 1px solid var(--rule);
  border-radius: 3px;
  margin-right: 0.25em;
  color: var(--fg-dim);
}

/* rail -------------------------------------------------------------------- */

aside.toc {
  position: sticky;
  top: 2.8rem;
  align-self: start;
  max-height: calc(100vh - 4.2rem);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
  font-size: 0.78rem;
  line-height: 1.45;
}
aside.toc ul { list-style: none; margin: 0; padding: 0; }
aside.toc a {
  display: block;
  position: relative;
  padding: 0.32em 0 0.32em 0.95em;
  color: var(--fg-dim);
  border-bottom: 0;
  transition: color 0.14s ease;
}
aside.toc a::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--faint);
  transform: translateY(-50%);
  transition: background 0.14s ease, width 0.14s ease;
}
aside.toc a:hover { color: var(--fg); }
aside.toc a:hover::before { background: var(--fg-dim); }
aside.toc a.active { color: var(--accent); }
aside.toc a.active::before { background: var(--accent); width: 3px; }
aside.toc li.d3 a { padding-left: 2em; font-size: 0.94em; }
aside.toc li.d3 a::before { left: 1.05em; }

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

footer {
  max-width: var(--shell);
  margin: 0 auto;
  padding: 1.2rem 1.8rem 2.4rem;
  border-top: 1px solid var(--rule);
  display: flex;
  align-items: center;
  gap: 1rem;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--fg-dim);
}
footer .social { margin-left: auto; display: flex; gap: 0.9rem; }
footer .social a { color: var(--fg-dim); display: block; border-bottom: 0; }
footer .social a:hover { color: var(--accent); }
footer .social svg { width: 16px; height: 16px; fill: currentColor; display: block; }

/* lightbox ---------------------------------------------------------------- */

dialog.lightbox {
  border: 0; padding: 0; background: transparent;
  max-width: 95vw; max-height: 95vh; overflow: visible;
  opacity: 0; transform: scale(0.97);
  transition:
    opacity 0.24s ease, transform 0.24s cubic-bezier(0.22, 1, 0.36, 1),
    overlay 0.24s allow-discrete, display 0.24s allow-discrete;
}
dialog.lightbox[open] { opacity: 1; transform: scale(1); }
@starting-style { dialog.lightbox[open] { opacity: 0; transform: scale(0.97); } }

dialog.lightbox::backdrop {
  background: rgba(8, 10, 12, 0); backdrop-filter: blur(0);
  transition:
    background 0.24s ease, backdrop-filter 0.24s ease,
    overlay 0.24s allow-discrete, display 0.24s allow-discrete;
}
dialog.lightbox[open]::backdrop { background: rgba(8, 10, 12, 0.9); backdrop-filter: blur(4px); }
@starting-style { dialog.lightbox[open]::backdrop { background: rgba(8, 10, 12, 0); backdrop-filter: blur(0); } }

dialog.lightbox img {
  display: block; max-width: 95vw; max-height: 95vh; width: auto;
  border-radius: 4px; cursor: zoom-out;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.6);
}
.lightbox-close {
  position: absolute; top: -2.3rem; right: -0.2rem;
  background: none; border: 0;
  color: rgba(255, 255, 255, 0.6);
  font-family: var(--mono); font-size: 1.5rem; line-height: 1;
  padding: 0.2em 0.4em; cursor: pointer;
}
.lightbox-close:hover { color: #fff; }

@media (prefers-reduced-motion: reduce) {
  dialog.lightbox, dialog.lightbox::backdrop { transition-duration: 0.01s; }
}

/* responsive -------------------------------------------------------------- */

@media (max-width: 1120px) {
  .layout:has(aside.toc) { grid-template-columns: var(--sidebar) minmax(0, 1fr); }
  aside.toc { display: none; }
}

@media (max-width: 800px) {
  body { font-size: 16px; }
  .layout, .layout:has(aside.toc) {
    grid-template-columns: minmax(0, 1fr);
    row-gap: 1.6rem;
    padding: 1.6rem 1.15rem 0;
  }
  .sidebar {
    position: static;
    max-height: none;
    overflow: visible;
    padding-bottom: 1.3rem;
    border-bottom: 1px solid var(--rule);
  }
  .brand { margin-bottom: 1rem; }
  .sidebar nav ul { display: flex; gap: 0.4rem; }
  .sidebar .side-section { display: none; }
  .side-controls { margin: 1.2rem 0 0; padding-top: 1rem; }
  h1 { font-size: 1.42rem; }
  h2 { font-size: 1.1rem; }
  .post-list a { padding: 1.05rem 0.7rem; margin-inline: -0.7rem; }
  footer { padding: 1.1rem 1.15rem 2rem; }
  .lightbox-close { top: -2.1rem; right: 0; }
}
