/* lxb.me — 稿纸.
 *
 * The site is Chinese long-form technical writing, so the page is built like
 * manuscript paper: a quiet sheet, a hairline margin down the left, and dates
 * hanging in that margin the way notes are written beside a paragraph. The
 * margin is the one flourish; everything else stays out of the way.
 *
 * Type is split three ways by job:
 *   LXGW WenKai Screen  display + all CJK. Only ships weight 400, so hierarchy
 *                       is built from size and face, never from bold CJK —
 *                       synthetic bold on a brush face looks like a smudge.
 *   Inter               Latin body text.
 *   JetBrains Mono      anything that is data: dates, nav, tags, counts.
 *
 * Replaces the Suckless theme's colors.css/style.css entirely; the theme's
 * templates and element ids are kept.
 */

/* ---------------------------------------------------------------- tokens - */

:root {
  --is-dark: 0;

  --paper: #fdfcfa;
  --paper-raised: #f6f4ef;
  --ink: #1b1c20;
  --ink-soft: #71727a;
  --rule: #e6e3dc;
  --link: #2b4a7d;      /* 蓝黑墨水 */
  --seal: #a63a2e;      /* 朱砂 — current page, tag hashes, nothing else */

  --font-body: Inter, "LXGW WenKai Screen", system-ui, sans-serif;
  --font-display: "LXGW WenKai Screen", Inter, serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;

  --measure: 42rem;     /* ~38 CJK characters per line */
  --margin-col: 7rem;   /* the manuscript margin */
  --gutter: 1.5rem;
  --page: 52rem;        /* margin-col + measure + both gutters */
  --bar: 3.5rem;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --is-dark: 1;
    --paper: #15161a;
    --paper-raised: #1c1e23;
    --ink: #d8d5ce;
    --ink-soft: #8b8c94;
    --rule: #2a2c33;
    --link: #8fb0e0;
    --seal: #d4705f;
  }
}

:root[data-theme="dark"] {
  --is-dark: 1;
  --paper: #15161a;
  --paper-raised: #1c1e23;
  --ink: #d8d5ce;
  --ink-soft: #8b8c94;
  --rule: #2a2c33;
  --link: #8fb0e0;
  --seal: #d4705f;
}

/* ------------------------------------------------------------------ base - */

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

html {
  overflow-y: scroll;
  scroll-padding-top: calc(var(--bar) + 1rem);
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.85;
  /* CJK needs strict line breaking; long Latin tokens still need to wrap. */
  line-break: strict;
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: var(--link);
  text-underline-offset: 0.2em;
  text-decoration-thickness: from-font;
}

a:hover {
  color: var(--seal);
}

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

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

#header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}

/* The one vertical axis the whole page hangs off: the header brand, the body
   text and the footer all start on this line. Only dates break left of it. */
.bar {
  max-width: var(--page);
  margin-inline: auto;
  padding-left: calc(var(--margin-col) + var(--gutter));
  padding-right: var(--gutter);
}

#header .bar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  height: var(--bar);
}

#headerLink {
  font-family: var(--font-display);
  font-size: 1.3rem;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}

#headerLink:hover {
  color: var(--seal);
}

#menu {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: flex-end;
  gap: 1.5rem;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

#menu::-webkit-scrollbar {
  display: none;
}

#menu .left,
#menu .right {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

#menu .right {
  margin-left: auto;
}

#menu a {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  color: var(--ink-soft);
  text-decoration: none;
  white-space: nowrap;
  padding: 0.35rem 0;
  border-bottom: 1px solid transparent;
}

#menu a:hover {
  color: var(--ink);
}

/* The theme marks the current nav item by wrapping its label in <b>. */
#menu a:has(b) {
  color: var(--ink);
  border-bottom-color: var(--seal);
}

#menu b {
  font-weight: 500;
}

#theme-toggle {
  flex: none;
  padding: 0.25rem;
  border: 0;
  background: none;
  color: var(--ink-soft);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

#theme-toggle:hover {
  color: var(--ink);
}

/* --------------------------------------------------------------- layout - */

#content {
  display: flex;
  align-items: flex-start;
  max-width: var(--page);
  margin-inline: auto;
}

#nav {
  flex: none;
  width: 12rem;
  padding: 3rem 0 3rem var(--gutter);
}

/* The theme always emits #nav, and Tera leaves whitespace inside it even when
   the section has no secondary nav — so :empty never matches. Key off whether
   it actually produced links. */
#nav:not(:has(a)) {
  display: none;
}

#nav ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

#nav a {
  display: block;
  padding: 0.3rem 0;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--ink-soft);
  text-decoration: none;
}

#nav a:hover,
#nav a:has(b) {
  color: var(--ink);
}

#nav b {
  font-weight: 500;
}

#main {
  flex: 1;
  min-width: 0;
  padding: 3rem var(--gutter) 5rem calc(var(--margin-col) + var(--gutter));
}

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

h1,
h2,
h3,
h4 {
  font-family: var(--font-display);
  /* WenKai ships weight 400 only — never ask the browser to fake a bold. */
  font-weight: 400;
  line-height: 1.4;
  margin: 2.5em 0 0.6em;
}

h1 {
  font-size: 1.9rem;
  margin-top: 0;
}

h2 {
  font-size: 1.4rem;
}

h3 {
  font-size: 1.15rem;
}

h4 {
  font-size: 1rem;
  color: var(--ink-soft);
}

p {
  margin: 1.15em 0;
  max-width: var(--measure);
}

/* :not() keeps the id specificity here from overriding .post-list below. */
#main > ul:not(.post-list),
#main > ol:not(.post-list) {
  max-width: var(--measure);
  padding-left: 1.4em;
}

li {
  margin: 0.4em 0;
}

hr {
  max-width: var(--measure);
  margin: 3em 0;
  border: 0;
  border-top: 1px solid var(--rule);
}

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

code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  font-variant-ligatures: none;
}

:not(pre) > code {
  padding: 0.1em 0.35em;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: 3px;
}

pre {
  max-width: var(--measure);
  margin: 1.6em 0;
  padding: 1rem 1.15rem;
  overflow-x: auto;
  border: 1px solid var(--rule);
  border-radius: 4px;
  line-height: 1.65;
  tab-size: 4;
}

pre code {
  font-size: 0.82rem;
  padding: 0;
  background: none;
  border: 0;
}

/* -------------------------------------------------------------- elements - */

blockquote {
  max-width: var(--measure);
  margin: 1.6em 0;
  padding-left: 1.15em;
  border-left: 2px solid var(--rule);
  color: var(--ink-soft);
}

blockquote p {
  margin: 0.5em 0;
}

.quote footer {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin-top: 0.5em;
}

.quote footer::before {
  content: "— ";
}

.table-wrap {
  max-width: var(--measure);
  margin: 1.6em 0;
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.92rem;
}

th,
td {
  padding: 0.5em 0.8em;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--rule);
}

th {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  color: var(--ink-soft);
  border-bottom-color: var(--ink-soft);
}

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

figure {
  max-width: var(--measure);
  margin: 1.8em 0;
}

figcaption {
  margin-top: 0.5em;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-soft);
}

details {
  max-width: var(--measure);
  margin: 1.4em 0;
  padding: 0.6em 0.9em;
  border: 1px solid var(--rule);
  border-radius: 4px;
}

summary {
  cursor: pointer;
}

/* ------------------------------------------------- article meta and tags - */

.post-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.9rem;
  margin: -0.3rem 0 2.5rem;
  padding-bottom: 1.2rem;
  border-bottom: 1px solid var(--rule);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.post-meta a {
  color: var(--ink-soft);
  text-decoration: none;
}

.post-meta a:hover {
  color: var(--seal);
}

.post-meta-tags a {
  margin-right: 0.6rem;
}

.post-meta-tags a:last-child {
  margin-right: 0;
}

/* ------------------------------------------- post list — the margin rule - */

/* No top border: the archive splits posts into several consecutive .post-list
   blocks (one per year), and a top rule would double up against the previous
   block's last item border. */
.post-list {
  max-width: calc(var(--measure) + var(--margin-col));
  /* Pulled left so the date column lands in #main's left padding — the entry
     titles stay on the page's vertical axis and only the dates hang out. */
  margin: 0 0 0 calc(-1 * var(--margin-col));
  padding: 0;
  list-style: none;
}

.post-item {
  display: grid;
  grid-template-columns: var(--margin-col) 1fr;
  gap: 0;
  margin: 0;
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--rule);
}

.post-item time {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--ink-soft);
  /* Sit on the title's baseline rather than the top of its line box. */
  padding-top: 0.35em;
  font-variant-numeric: tabular-nums;
}

.post-item .post-title {
  font-family: var(--font-display);
  font-size: 1.2rem;
  line-height: 1.5;
  color: var(--ink);
  text-decoration: none;
}

.post-item .post-title:hover {
  color: var(--seal);
}

.post-item .post-summary {
  grid-column: 2;
  margin-top: 0.3rem;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.post-item .post-summary p {
  margin: 0;
}

.post-tags {
  grid-column: 2;
  margin-top: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
}

.post-tags a {
  color: var(--ink-soft);
  text-decoration: none;
  margin-right: 0.7rem;
}

.post-tags a:hover {
  color: var(--seal);
}

.pagination {
  display: flex;
  gap: 1.5rem;
  margin-top: 2rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

/* The archive template groups posts into <section class="blog-year"> blocks. */
.blog-year {
  display: contents;
}

@supports selector(body:has(.blog-year:target)) {
  body:has(.blog-year:target) .blog-year {
    display: none;
  }

  body:has(.blog-year:target) .blog-year:target {
    display: block;
  }
}

/* ------------------------------------------------- homepage — 扉页/colophon - */

/* The avatar hangs in the manuscript margin like a seal; the name lands on the
   page's vertical axis with everything else. */
.hero {
  display: grid;
  grid-template-columns: var(--margin-col) 1fr;
  align-items: center;
  gap: 0;
  margin: 0 0 2.5rem calc(-1 * var(--margin-col));
}

.hero-avatar {
  width: 72px;
  height: 72px;
  border-radius: 2px;
  border: 1px solid var(--rule);
}

.hero h1 {
  margin: 0;
  font-size: 1.75rem;
  line-height: 1.2;
}

.hero-handle {
  display: flex;
  gap: 0.9rem;
  margin: 0.35rem 0 0;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.hero-handle a {
  color: var(--ink-soft);
  text-decoration: none;
}

.hero-handle a:hover {
  color: var(--seal);
}

/* Ledger sections: label in the margin, body on the axis — the same grid the
   post list uses for its dates. */
.ledger {
  display: grid;
  grid-template-columns: var(--margin-col) 1fr;
  gap: 0;
  margin: 0 0 0 calc(-1 * var(--margin-col));
  padding: 1.6rem 0;
  border-top: 1px solid var(--rule);
}

.ledger-label {
  margin: 0;
  padding-top: 0.15em;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 400;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
}

.ledger-body {
  min-width: 0;
}

.ledger-note {
  margin: 0.7rem 0 0;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink-soft);
}

.tally {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.4rem;
  margin: 0;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.tally b {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 1.05rem;
  color: var(--ink);
}

/* Bars are all one colour and differ only in length — seven languages cannot
   be told apart by shades of ink, but they can by width. */
.lang-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.lang-row {
  display: grid;
  grid-template-columns: 5.5rem 1fr 3rem;
  align-items: center;
  gap: 0.75rem;
  margin: 0 0 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--ink-soft);
}

.lang-bar {
  height: 5px;
  background: var(--rule);
  border-radius: 2px;
  overflow: hidden;
}

.lang-bar > span {
  display: block;
  height: 100%;
  background: var(--ink-soft);
}

.lang-row:first-child .lang-bar > span {
  background: var(--seal);
}

.lang-pct {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Contribution calendar: 53 columns of 7 days, filled column by column. */
.calendar {
  display: grid;
  grid-template-rows: repeat(7, 9px);
  grid-auto-flow: column;
  grid-auto-columns: 9px;
  gap: 3px;
  overflow-x: auto;
  padding-bottom: 0.3rem;
}

.calendar i {
  border-radius: 2px;
  background: var(--rule);
}

.calendar .lv1 { background: color-mix(in srgb, var(--ink-soft) 35%, var(--rule)); }
.calendar .lv2 { background: color-mix(in srgb, var(--ink-soft) 65%, var(--rule)); }
.calendar .lv3 { background: var(--ink-soft); }
.calendar .lv4 { background: var(--seal); }

.repo-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.repo-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.7rem;
  margin: 0 0 0.9rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.repo-row > a {
  font-size: 0.85rem;
  color: var(--ink);
  text-decoration: none;
}

.repo-row > a:hover {
  color: var(--seal);
}

.repo-row > time {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
}

.repo-desc {
  flex-basis: 100%;
  margin: 0.1rem 0 0;
  font-family: var(--font-body);
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--ink-soft);
}

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

#site-footer {
  border-top: 1px solid var(--rule);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--ink-soft);
}

#site-footer .bar {
  padding-top: 2rem;
  padding-bottom: 3rem;
}

#site-footer p {
  margin: 0;
  max-width: none;
}

#mobile-utility-footer {
  display: none;
}

.hidden {
  display: none;
}

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

@media (max-width: 900px) {
  :root {
    --margin-col: 4.5rem;
    --gutter: 1.25rem;
  }

  #nav {
    display: none;
  }

  #header .bar {
    gap: 1rem;
  }
}

/* Below this the manuscript margin has no room left, so the date moves inline
   above the title and every column collapses onto the one axis. */
@media (max-width: 560px) {
  :root {
    --margin-col: 0rem;
  }

  body {
    font-size: 16px;
  }

  #main {
    padding: 2rem var(--gutter) 4rem;
  }

  .post-list,
  .hero,
  .ledger {
    margin-left: 0;
  }

  .hero {
    grid-template-columns: 72px 1fr;
    gap: 1rem;
  }

  .ledger {
    grid-template-columns: 1fr;
    gap: 0.6rem;
  }

  .post-item {
    grid-template-columns: 1fr;
    gap: 0.3rem;
  }

  .post-item time {
    padding-top: 0;
  }

  .post-item .post-summary,
  .post-tags {
    grid-column: 1;
  }

  h1 {
    font-size: 1.6rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
