/* ==========================================================================
   writeups — stylesheet
   Palette and voice carried over from the GitHub profile: cold black,
   ice white, one accent per role (red = finding, blue = link, green = ok).
   Light and dark are both first-class; motion is opt-out aware.
   ========================================================================== */

/* --- 1. Tokens ----------------------------------------------------------- */

:root {
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", "JetBrains Mono", Menlo,
          Consolas, "Liberation Mono", monospace;

  --measure: 72ch;
  --rail: 15rem;
  --radius: 10px;
  --radius-sm: 6px;

  /* light */
  --bg: #e7ebf1;
  --panel: #f4f6f9;
  --panel-2: #eaeef4;
  --border: #cfd6e0;
  --border-soft: #dde3ea;
  --text: #1f2933;
  --muted: #5b6673;
  --accent: #1f2a37;
  --red: #c5301f;
  --blue: #1c5fc4;
  --green: #127a4a;
  --shadow: 0 1px 2px rgba(15, 23, 32, .06), 0 10px 28px -18px rgba(15, 23, 32, .35);
  --grid: rgba(31, 41, 51, .055);
  --veil: rgba(231, 235, 241, .88);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121821;
    --panel: #0b0f14;
    --panel-2: #161d27;
    --border: #232c38;
    --border-soft: #1c2430;
    --text: #d5dde8;
    --muted: #8d9aab;
    --accent: #e6edf6;
    --red: #ff5468;
    --blue: #46adff;
    --green: #3ddc97;
    --shadow: 0 1px 2px rgba(0, 0, 0, .45), 0 12px 32px -20px rgba(0, 0, 0, .9);
    --grid: rgba(213, 221, 232, .05);
    --veil: rgba(18, 24, 33, .88);
  }
}

:root[data-theme="dark"] {
  --bg: #121821;
  --panel: #0b0f14;
  --panel-2: #161d27;
  --border: #232c38;
  --border-soft: #1c2430;
  --text: #d5dde8;
  --muted: #8d9aab;
  --accent: #e6edf6;
  --red: #ff5468;
  --blue: #46adff;
  --green: #3ddc97;
  --shadow: 0 1px 2px rgba(0, 0, 0, .45), 0 12px 32px -20px rgba(0, 0, 0, .9);
  --grid: rgba(213, 221, 232, .05);
  --veil: rgba(18, 24, 33, .88);
}

/* --- 2. Base ------------------------------------------------------------- */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg);
  /* dot matrix, the same texture as the profile panels */
  background-image: radial-gradient(var(--grid) 1px, transparent 1px);
  background-size: 22px 22px;
  background-position: -1px -1px;
  color: var(--text);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.7;
  text-rendering: optimizeLegibility;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

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

img { max-width: 100%; height: auto; }
hr { border: 0; border-top: 1px solid var(--border); margin: 2.5rem 0; }

.skip {
  position: absolute; left: -9999px; top: 0;
  background: var(--panel); color: var(--text);
  padding: .6rem 1rem; border: 1px solid var(--border);
  border-radius: 0 0 var(--radius-sm) 0; z-index: 60;
}
.skip:focus { left: 0; }

/* --- 3. Header ----------------------------------------------------------- */

.site-head {
  position: sticky; top: 0; z-index: 50;
  background: var(--veil);
  backdrop-filter: saturate(140%) blur(8px);
  -webkit-backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--border);
}

.site-head__inner {
  max-width: 68rem; margin: 0 auto;
  padding: .7rem 1.25rem;
  display: flex; align-items: center; gap: 1rem;
}

.brand {
  font-family: var(--mono); font-size: .9rem;
  color: var(--text); white-space: nowrap;
  display: inline-flex; align-items: baseline;
}
.brand:hover { text-decoration: none; }
.brand__user { color: var(--muted); }
.brand__path { color: var(--accent); font-weight: 600; }
.brand__caret {
  display: inline-block; width: .55ch; height: .95em;
  margin-left: .4ch; background: var(--red);
  transform: translateY(.1em);
  animation: blink 1.2s steps(1, end) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.nav { margin-left: auto; display: flex; align-items: center; gap: .3rem; }
.nav a, .nav button {
  font-family: var(--mono); font-size: .78rem; line-height: 1;
  color: var(--muted); background: transparent;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: .5rem .6rem; cursor: pointer;
  display: inline-flex; align-items: center; gap: .4rem;
  transition: color .12s, background .12s, border-color .12s;
}
.nav a:hover, .nav button:hover {
  color: var(--accent); background: var(--panel-2);
  border-color: var(--border); text-decoration: none;
}
.nav svg { width: 15px; height: 15px; fill: currentColor; }
.nav .theme-toggle__label { font-variant: small-caps; letter-spacing: .04em; }

/* reading progress — a hairline along the header's bottom edge */
.progress {
  position: absolute; left: 0; bottom: -1px; height: 2px;
  width: 0; background: var(--red);
  transition: width .08s linear;
}

/* --- 4. Shell ------------------------------------------------------------ */

.wrap { max-width: 68rem; margin: 0 auto; padding: 0 1.25rem; width: 100%; }

.page { padding: 3rem 0 4rem; flex: 1 0 auto; }

@media (min-width: 64rem) {
  .page__grid.has-rail {
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--rail);
    gap: 3rem;
    align-items: start;
  }
}

.prose { max-width: var(--measure); min-width: 0; }

/* --- 5. Home ------------------------------------------------------------- */

.intro {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 3rem;
}
.intro__bar {
  display: flex; align-items: center; gap: .45rem;
  padding: .6rem .85rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}
.intro__dot { width: 11px; height: 11px; border-radius: 50%; }
.intro__title {
  margin-left: .5rem; font-family: var(--mono);
  font-size: .78rem; color: var(--muted);
}
.intro__body { padding: 1.5rem 1.6rem 1.7rem; }
.intro__cmd {
  font-family: var(--mono); font-size: .88rem;
  color: var(--muted); margin: 0 0 1.1rem;
}
.intro__cmd b { color: var(--green); font-weight: 600; }
.intro h1 {
  font-size: clamp(1.5rem, 1.1rem + 1.8vw, 2.1rem);
  line-height: 1.2; margin: 0 0 .7rem; letter-spacing: -.02em;
  color: var(--accent);
}
.intro__meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1.1rem;
}
.intro__meta-row .intro__cmd {
  margin: 0;
}
.intro__meta-row .lang-switch {
  margin: 0;
}
.intro p { margin: 0 0 .85rem; max-width: 62ch; }
.intro p:last-child { margin-bottom: 0; }
.intro__note {
  font-size: .9rem; color: var(--muted);
  border-left: 2px solid var(--red); padding-left: .85rem;
}

.section-head {
  display: flex; align-items: center; gap: .75rem;
  font-family: var(--mono); font-size: .8rem;
  color: var(--muted); margin: 0 0 1.25rem;
}
.section-head::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}
.section-head b { color: var(--accent); font-weight: 600; }

.filters { display: flex; flex-wrap: wrap; gap: .4rem; margin: 0 0 1.5rem; }
.filters button {
  font-family: var(--mono); font-size: .76rem; line-height: 1;
  padding: .45rem .7rem; cursor: pointer;
  color: var(--muted); background: var(--panel);
  border: 1px solid var(--border); border-radius: 999px;
  transition: color .12s, background .12s, border-color .12s;
}
.filters button:hover { color: var(--accent); border-color: var(--muted); }
.filters button[aria-pressed="true"] {
  color: var(--bg); background: var(--accent); border-color: var(--accent);
}

.entries { list-style: none; margin: 0; padding: 0; }
.entry {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  margin-bottom: 1.1rem;
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.entry:hover {
  border-color: var(--muted);
  box-shadow: var(--shadow);
}
@media (prefers-reduced-motion: no-preference) {
  .entry:hover { transform: translateY(-2px); }
}
.entry[hidden] { display: none; }
.entry__link { display: block; padding: 1.3rem 1.5rem; color: inherit; }
.entry__link:hover { text-decoration: none; }

.entry__meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem;
  font-family: var(--mono); font-size: .74rem; color: var(--muted);
  margin-bottom: .55rem;
}
.entry__meta .sep { color: var(--border); }
.entry__meta .is-green { color: var(--green); }
.entry h2 {
  font-size: 1.3rem; line-height: 1.3; margin: 0 0 .45rem;
  color: var(--accent); letter-spacing: -.01em;
  transition: color .12s;
}
.entry:hover h2 { color: var(--blue); }
.entry p {
  margin: 0 0 .9rem; color: var(--muted);
  font-size: .96rem; max-width: 64ch;
}

.tags { display: flex; flex-wrap: wrap; gap: .35rem; }
.tag {
  font-family: var(--mono); font-size: .7rem; line-height: 1;
  padding: .35rem .55rem; border-radius: var(--radius-sm);
  color: var(--muted); background: var(--panel-2);
  border: 1px solid var(--border-soft);
}
.tag::before { content: "#"; opacity: .5; }

.empty {
  font-family: var(--mono); font-size: .85rem; color: var(--muted);
  border: 1px dashed var(--border); border-radius: var(--radius);
  padding: 2rem; text-align: center;
}

/* --- 6. Post header ------------------------------------------------------ */

.post-head { margin-bottom: 2.25rem; }
.crumb {
  font-family: var(--mono); font-size: .78rem; color: var(--muted);
  margin-bottom: 1rem;
}
.post-head h1 {
  font-size: clamp(1.7rem, 1.2rem + 2.4vw, 2.5rem);
  line-height: 1.18; letter-spacing: -.025em;
  margin: 0 0 .9rem; color: var(--accent);
}
.post-head__lede {
  font-size: 1.07rem; color: var(--muted);
  margin: 0 0 1.4rem; max-width: 64ch;
}

.factbar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(6.5rem, 1fr));
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--panel); overflow: hidden;
}
.fact {
  padding: .75rem .9rem;
  border-right: 1px solid var(--border-soft);
}
.fact:last-child { border-right: 0; }
.fact__k {
  display: block; font-family: var(--mono); font-size: .67rem;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); margin-bottom: .2rem;
}
.fact__v {
  font-family: var(--mono); font-size: .88rem; color: var(--accent);
}
.fact__v.is-red { color: var(--red); }
.fact__v.is-green { color: var(--green); }

/* language switch — site chrome, not a stray widget */
.lang-switch {
  display: inline-flex; margin: 1.6rem 0 0;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--panel); overflow: hidden;
}
.lang-switch button {
  appearance: none; -webkit-appearance: none; border: 0;
  background: transparent; color: var(--muted);
  font-family: var(--mono); font-size: .78rem; line-height: 1;
  padding: .5rem .95rem; cursor: pointer;
  transition: background .12s, color .12s;
}
.lang-switch button + button { border-left: 1px solid var(--border); }
.lang-switch button:hover { color: var(--accent); background: var(--panel-2); }
.lang-switch button.active { color: var(--bg); background: var(--accent); }
.lang-vi { display: none; }
.wlang-vi .lang-en { display: none; }
.wlang-vi .lang-vi { display: block; }
span.lang-vi { display: none; }
.wlang-vi span.lang-en { display: none; }
.wlang-vi span.lang-vi { display: inline; }

/* --- 7. Prose ------------------------------------------------------------ */

.prose h2, .prose h3, .prose h4 {
  color: var(--accent); letter-spacing: -.01em; line-height: 1.3;
  scroll-margin-top: 5rem;
}
.prose h2 {
  font-size: 1.45rem; margin: 3rem 0 1rem;
  padding-bottom: .5rem; border-bottom: 1px solid var(--border);
}
.prose h3 { font-size: 1.15rem; margin: 2.2rem 0 .7rem; }
.prose h4 { font-size: 1rem; margin: 1.8rem 0 .5rem; }

.prose h2 .anchor, .prose h3 .anchor {
  font-family: var(--mono); font-weight: 400; font-size: .85em;
  color: var(--border); margin-left: .45rem;
  opacity: 0; transition: opacity .12s, color .12s;
}
.prose h2:hover .anchor, .prose h3:hover .anchor,
.prose .anchor:focus-visible { opacity: 1; }
.prose .anchor:hover { color: var(--blue); text-decoration: none; }

.prose p, .prose li { overflow-wrap: break-word; }
.prose ul, .prose ol { padding-left: 1.3rem; }
.prose li { margin: .35rem 0; }
.prose li::marker { color: var(--muted); }
.prose strong { color: var(--accent); font-weight: 650; }

/* inline code */
.prose :not(pre) > code {
  font-family: var(--mono); font-size: .86em;
  padding: .15em .4em; border-radius: var(--radius-sm);
  background: var(--panel-2); border: 1px solid var(--border-soft);
  color: var(--text); overflow-wrap: break-word;
}

/* code blocks */
.prose pre {
  position: relative;
  font-family: var(--mono); font-size: .855rem; line-height: 1.6;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border);
  border-left: 3px solid var(--muted);
  border-radius: var(--radius);
  padding: 1rem 1.1rem; margin: 1.4rem 0;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.prose pre code {
  font: inherit; background: none; border: 0; padding: 0; color: inherit;
}
.prose pre .cmt { color: var(--muted); }

.copy {
  position: absolute; top: .45rem; right: .45rem;
  font-family: var(--mono); font-size: .68rem; line-height: 1;
  padding: .35rem .5rem; cursor: pointer;
  color: var(--muted); background: var(--panel-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  opacity: 0; transition: opacity .12s, color .12s, border-color .12s;
}
.prose pre:hover .copy, .copy:focus-visible { opacity: 1; }
.copy:hover { color: var(--accent); }
.copy.done { color: var(--green); border-color: var(--green); opacity: 1; }

/* Rouge wraps highlighted code in two extra elements; keep one frame only,
   and label the block with its language. */
.prose .highlighter-rouge { position: relative; margin: 1.4rem 0; }
.prose .highlighter-rouge .highlight { background: none; margin: 0; }
.prose .highlighter-rouge pre { margin: 0; }
.prose .highlighter-rouge::after {
  position: absolute; top: .55rem; right: .75rem;
  font-family: var(--mono); font-size: .66rem; letter-spacing: .07em;
  text-transform: uppercase; color: var(--muted);
  opacity: .55; pointer-events: none; transition: opacity .12s;
}
.prose .language-bash::after { content: "bash"; }
.prose .language-sql::after { content: "sql"; }
.prose .language-python::after { content: "python"; }
.prose .language-text::after { content: "text"; }
.prose .language-php::after { content: "php"; }
.prose .highlighter-rouge:hover::after { opacity: 0; }

/* Rouge tokens, restrained: comments recede, strings and numbers read as data,
   keywords as structure, variables as the thing to watch. */
.highlight .c, .highlight .c1, .highlight .cm, .highlight .cs,
.highlight .cp, .highlight .cpf { color: var(--muted); font-style: italic; }
.highlight .k, .highlight .kc, .highlight .kd, .highlight .kn,
.highlight .kp, .highlight .kr, .highlight .kt { color: var(--blue); }
.highlight .s, .highlight .s1, .highlight .s2, .highlight .sb,
.highlight .sc, .highlight .sd, .highlight .se, .highlight .sh,
.highlight .si, .highlight .sx, .highlight .sr { color: var(--green); }
.highlight .m, .highlight .mi, .highlight .mf, .highlight .mh,
.highlight .mo, .highlight .il { color: var(--green); }
.highlight .nb, .highlight .nf, .highlight .nc, .highlight .nn,
.highlight .nt { color: var(--accent); }
.highlight .nv, .highlight .vg, .highlight .vi, .highlight .vc { color: var(--red); }
.highlight .err { color: var(--red); }
.highlight .gd { color: var(--red); }
.highlight .gi { color: var(--green); }

/* blockquote → callout. The lab-use warnings earn a louder frame. */
.prose blockquote {
  margin: 1.6rem 0; padding: 1rem 1.1rem 1rem 2.7rem;
  position: relative;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border);
  border-left: 3px solid var(--red);
  border-radius: var(--radius);
  font-size: .95rem;
}
.prose blockquote::before {
  content: "!"; position: absolute; left: 1rem; top: 1.1rem;
  font-family: var(--mono); font-weight: 700; color: var(--red);
  width: 1.15rem; height: 1.15rem; line-height: 1.05rem; text-align: center;
  border: 1.5px solid var(--red); border-radius: 50%;
  font-size: .72rem;
}
.prose blockquote > :first-child { margin-top: 0; }
.prose blockquote > :last-child { margin-bottom: 0; }

/* tables read like a report */
.prose table {
  width: 100%; border-collapse: collapse;
  margin: 1.5rem 0; font-size: .9rem;
  display: block; overflow-x: auto; /* no-JS fallback */
}
/* site.js wraps each table so it can scroll without shrinking to its content */
.prose .table-wrap {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  margin: 1.5rem 0;
}
.prose .table-wrap > table { display: table; margin: 0; overflow: visible; }
.prose th, .prose td {
  padding: .55rem .75rem; text-align: left;
  border: 1px solid var(--border);
}
.prose th {
  font-family: var(--mono); font-size: .76rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); background: var(--panel-2);
  white-space: nowrap;
}
.prose tbody tr:nth-child(even) { background: var(--panel); }

/* screenshots get a frame and their alt text as a caption */
.prose figure { margin: 1.9rem 0; }
.prose figure img {
  display: block; margin: 0 auto;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--panel); box-shadow: var(--shadow); cursor: zoom-in;
}
.prose figcaption {
  font-family: var(--mono); font-size: .76rem; color: var(--muted);
  text-align: center; margin-top: .75rem; padding: 0 1rem;
  line-height: 1.5;
}
.prose figcaption::before { content: "fig. "; opacity: .55; }
.prose p > img {
  display: block; margin: 1.6rem auto;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--panel); box-shadow: var(--shadow); cursor: zoom-in;
}

/* --- 8. Table of contents ------------------------------------------------ */

.toc { display: none; }
.toc[hidden] { display: none !important; }
@media (min-width: 64rem) {
  .toc {
    display: block; position: sticky; top: 4.75rem;
    max-height: calc(100vh - 7.5rem); overflow-y: auto;
    font-size: .85rem;
    border-left: 1px solid var(--border);
  }
  .toc__title {
    font-family: var(--mono); font-size: .68rem;
    text-transform: uppercase; letter-spacing: .09em;
    color: var(--muted); margin: 0 0 .7rem; padding-left: 1.1rem;
  }
  .toc ol { list-style: none; margin: 0; padding: 0; }
  .toc li { margin: 0; }
  .toc a {
    display: block; padding: .28rem 0 .28rem 1.1rem;
    margin-left: -1px;
    color: var(--muted); border-left: 2px solid transparent;
    line-height: 1.4;
  }
  .toc a:hover { color: var(--accent); text-decoration: none; }
  .toc .lvl-3 a { font-size: .94em; padding-left: 2rem; }
  .toc a.active {
    color: var(--accent); border-left-color: var(--red); font-weight: 550;
  }
}

/* --- 9. Post footer ------------------------------------------------------ */

.post-foot { margin-top: 3.5rem; }
.byline {
  font-family: var(--mono); font-size: .82rem; color: var(--muted);
  border-top: 1px solid var(--border); padding-top: 1.2rem;
}

.pager {
  display: grid; gap: .8rem; margin-top: 1.6rem;
  grid-template-columns: 1fr;
}
@media (min-width: 42rem) { .pager { grid-template-columns: 1fr 1fr; } }
.pager a {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--panel); padding: .85rem 1rem; color: inherit;
  transition: border-color .15s;
}
.pager a:hover { border-color: var(--muted); text-decoration: none; }
.pager a:hover .pager__t { color: var(--blue); }
.pager__k {
  display: block; font-family: var(--mono); font-size: .68rem;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); margin-bottom: .25rem;
}
.pager__t { font-size: .95rem; color: var(--accent); line-height: 1.4; transition: color .12s; }
.pager .next { text-align: right; }

/* --- 10. Site footer ----------------------------------------------------- */

.site-foot {
  border-top: 1px solid var(--border);
  background: var(--panel);
}
.site-foot__inner {
  max-width: 68rem; margin: 0 auto; padding: 2rem 1.25rem 2.5rem;
  font-family: var(--mono); font-size: .78rem; color: var(--muted);
  display: flex; flex-wrap: wrap; gap: 1rem 2.5rem;
  justify-content: space-between; align-items: flex-start;
}
.site-foot p { margin: 0 0 .4rem; }
.site-foot p:last-child { margin-bottom: 0; }
.site-foot .ethics { color: var(--red); }
.site-foot__links { display: flex; gap: 1.1rem; flex-wrap: wrap; }

.top {
  position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 40;
  width: 2.5rem; height: 2.5rem; cursor: pointer;
  display: grid; place-items: center;
  color: var(--muted); background: var(--panel);
  border: 1px solid var(--border); border-radius: 50%;
  box-shadow: var(--shadow);
  opacity: 0; visibility: hidden;
  transition: opacity .18s, color .12s, visibility .18s;
}
.top.show { opacity: 1; visibility: visible; }
.top:hover { color: var(--accent); }
.top svg { width: 16px; height: 16px; fill: currentColor; }

/* --- 11. Lightbox -------------------------------------------------------- */

.lightbox {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: 2rem;
  background: rgba(8, 11, 16, .9); cursor: zoom-out;
}
.lightbox[hidden] { display: none; }
.lightbox img {
  max-width: 100%; max-height: 100%;
  border: 1px solid var(--border); border-radius: var(--radius);
}

/* --- 12. 404 ------------------------------------------------------------- */

.notfound { font-family: var(--mono); padding: 4rem 0 6rem; max-width: 46rem; }
.notfound .code {
  color: var(--red); font-size: .8rem; letter-spacing: .12em;
  margin: 0 0 1rem;
}
.notfound pre {
  background: var(--panel); border: 1px solid var(--border);
  border-left: 3px solid var(--red); border-radius: var(--radius);
  padding: 1.2rem 1.3rem; font-size: .88rem; overflow-x: auto;
  line-height: 1.7;
}

/* --- 13a. Contents sheet (below the desktop rail) ----------------------- */

.toc-fab, .toc-scrim { display: none; }
@media (max-width: 63.99rem) {
  .toc-fab {
    position: fixed; left: 1rem; z-index: 40;
    bottom: max(1rem, env(safe-area-inset-bottom));
    display: inline-flex; align-items: center; gap: .55rem;
    height: 2.75rem; padding: 0 1.1rem 0 .9rem;
    font-family: var(--mono); font-size: .78rem; color: var(--muted);
    background: var(--panel); border: 1px solid var(--border);
    border-radius: 999px; box-shadow: var(--shadow); cursor: pointer;
    opacity: 0; visibility: hidden;
    transition: opacity .18s, visibility .18s, color .12s;
  }
  .toc-fab.show { opacity: 1; visibility: visible; }
  .toc-fab[hidden] { display: none; }
  .toc-fab:hover { color: var(--accent); }
  .toc-fab svg {
    width: 16px; height: 16px; fill: none; stroke: currentColor;
    stroke-width: 1.6; stroke-linecap: round;
  }
  .toc-scrim {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(5, 8, 12, .55);
    opacity: 0; visibility: hidden; transition: opacity .2s, visibility .2s;
  }
  .toc-scrim.show { opacity: 1; visibility: visible; }

  .toc {
    display: block; position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    max-height: 72vh; overflow-y: auto; overscroll-behavior: contain;
    padding: 1.1rem 1.25rem max(1.5rem, env(safe-area-inset-bottom));
    background: var(--panel); border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0; box-shadow: 0 -16px 48px rgba(0, 0, 0, .35);
    font-size: .95rem;
    transform: translateY(105%); visibility: hidden;
    transition: transform .24s ease, visibility .24s;
  }
  .toc.open { transform: none; visibility: visible; }
  .toc__title {
    font-family: var(--mono); font-size: .68rem;
    text-transform: uppercase; letter-spacing: .09em;
    color: var(--muted); margin: 0 0 .4rem;
  }
  .toc ol { list-style: none; margin: 0; padding: 0; }
  .toc li { margin: 0; }
  .toc a {
    display: block; padding: .72rem 0; line-height: 1.4;
    color: var(--text); border-bottom: 1px solid var(--border-soft);
  }
  .toc a:hover { text-decoration: none; color: var(--accent); }
  .toc .lvl-3 a { padding-left: 1.2rem; font-size: .92em; color: var(--muted); }
  .toc a.active { color: var(--accent); font-weight: 600; box-shadow: inset 3px 0 0 var(--red); padding-left: .8rem; }
  .toc .lvl-3 a.active { padding-left: 1.2rem; }
  html.toc-lock { overflow: hidden; }
}

/* --- 13b. Small screens and touch ---------------------------------------- */

@media (max-width: 40rem) {
  .site-head__inner, .wrap { padding-left: 1rem; padding-right: 1rem; }
  .post-head__lede { font-size: 1rem; }

  /* fact bar: two even columns, hairlines from the grid gap */
  .factbar { grid-template-columns: 1fr 1fr; gap: 1px; background: var(--border-soft); }
  .fact { background: var(--panel); border-right: 0; padding: .7rem .9rem; }
  .fact:last-child:nth-child(odd) { grid-column: 1 / -1; }

  /* tag filters: one swipeable row instead of five wrapped ones */
  .filters {
    flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
    margin: 0 -1rem 1.25rem; padding: 0 1rem .35rem; scrollbar-width: none;
  }
  .filters::-webkit-scrollbar { display: none; }
  .filters button { flex: 0 0 auto; padding: .7rem .95rem; }

  .entry__meta { gap: .3rem .9rem; }
  .entry__meta .sep { display: none; }

  .lang-switch button { padding: .72rem 1.15rem; }
  .site-foot__inner { padding-bottom: 5rem; }
  .site-foot__links { gap: 0 1.4rem; }
  .site-foot__links a { padding: .45rem 0; }
}

@media (hover: none) {
  /* no hover on touch: keep the copy button visible, move the language label aside */
  .copy { opacity: 1; padding: .5rem .65rem; }
  html .prose pre { padding-top: 2.6rem; }
  .prose .highlighter-rouge::after { right: auto; left: 1.15rem; top: .8rem; }
  .prose .highlighter-rouge:hover::after { opacity: .55; }
  .prose h2 .anchor, .prose h3 .anchor { display: none; }
  .entry:hover { transform: none; }
}

/* --- 13. Narrow screens -------------------------------------------------- */

@media (max-width: 30rem) {
  body { font-size: 16px; }
  .brand__user { display: none; }
  .nav a span, .nav .theme-toggle__label { display: none; }
  .nav a, .nav button { padding: .5rem; }
  .site-head__inner, .wrap { padding-left: 1rem; padding-right: 1rem; }
  .page { padding: 2rem 0 3rem; }
  .intro__body { padding: 1.2rem 1.1rem 1.4rem; }
  .entry__link { padding: 1.1rem 1.1rem; }
  .fact { padding: .65rem .8rem; }
  .prose pre { font-size: .8rem; padding: .9rem; }
  .prose blockquote { padding-left: 2.4rem; }
  .top { right: .9rem; bottom: max(.9rem, env(safe-area-inset-bottom)); }
}

/* --- 14. Motion & print -------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

@media print {
  .site-head, .site-foot, .toc, .top, .lang-switch, .copy,
  .filters, .pager, .toc-fab, .toc-scrim { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .prose { max-width: none; }
  .prose pre, .prose blockquote, .prose figure { break-inside: avoid; }
}
