/* Monospace and square; a narrow column held together by hairlines.
   Colours come from gruvbox. Each one is light-dark(light, dark), so the
   page follows color-scheme: the system setting, or the toggle's choice. */
:root {
  color-scheme: light dark;
  --bg:    light-dark(#fbf1c7, #282828);
  --bg-2:  light-dark(#f2e5bc, #32302f);
  --ink:   light-dark(#3c3836, #ebdbb2);
  --body:  light-dark(#504945, #d5c4a1);
  --muted: light-dark(#7c6f64, #928374);
  --rule:  light-dark(#d5c4a1, #3c3836);
  --purple: #7f5ab6;
  --dots:  light-dark(#bdae93, #5a524c);
  --blue:  light-dark(#458588, #83a598);
  --mono: "SF Mono", ui-monospace, Menlo, "JetBrains Mono", Consolas, "Liberation Mono", "PingFang SC", "Hiragino Sans GB", monospace;
}
* { box-sizing: border-box; border-radius: 0; }
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
html { background: var(--bg); color: var(--ink); }
body { margin: 0; font: 15px/1.7 var(--mono); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
.sheet { width: min(640px, 100% - 48px); margin-inline: auto; padding: 166px 0 64px; }

/* The homepage and the post list sit a little above the middle of the screen. */
body.centred { min-height: 100vh; display: grid; place-items: center; padding-bottom: 14vh; }
body.centred .sheet { margin-inline: 0; }

h1 { font-size: 30px; line-height: 1.2; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 12px; text-wrap: balance; }
/* Break Chinese headings at spaces and punctuation, not in the middle of a word. */
h1, .prose h2, .prose h3, .prose h4 { word-break: keep-all; overflow-wrap: anywhere; }
.bio { color: var(--body); margin: 0 0 20px; text-wrap: balance; }
.links { display: flex; gap: 20px; margin-bottom: 56px; }
.links a { color: var(--body); padding: 1px 4px; margin: 0 -4px; }
.links a:hover { background: var(--ink); color: var(--bg); }
/* The padding is the hover block; the negative margin keeps each glyph on the text grid. */
.links .icon-link { display: inline-flex; padding: 6px; margin: -6px; }
.links .icon-link svg { display: block; }

/* The picture across the top of the page: a Chladni figure in dots, picked
   by the page's date (see base.html), and lines of sound over it. Both
   drawings are masks, so they take the theme colours; both repeat across, so
   they fill any width, and both fade out downwards inside the SVG.
   Generated by scripts/banner.py. */
.masthead { position: absolute; inset: 0 0 auto; height: 150px; z-index: -1; pointer-events: none; }
.masthead > div {
  position: absolute; inset: 0;
  mask-repeat: repeat-x; mask-position: top center; mask-size: auto 150px;
}
.masthead .dots { background: var(--dots); mask-image: var(--figure); }
.masthead .wave { background: var(--blue); mask-image: url("banner/wave.svg"); }

/* Floats in the bottom-right corner, over the text if need be. */
.theme-toggle {
  position: fixed; bottom: 24px; right: 24px; z-index: 10; display: grid; place-items: center;
  width: 36px; height: 36px; padding: 0; color: var(--body); background: var(--bg);
  border: 1px solid var(--rule); cursor: pointer;
}
.theme-toggle[hidden] { display: none; }
.theme-toggle:hover { background: var(--ink); color: var(--bg); }
.theme-toggle:focus-visible { outline: 1px solid var(--ink); outline-offset: 2px; }
.theme-toggle svg { display: none; }
.theme-toggle[data-next="light"] .icon-sun, .theme-toggle[data-next="dark"] .icon-moon { display: block; }

.section-title { font-size: 15px; font-weight: 400; color: var(--muted); margin: 0 0 12px; }
.section + .section { margin-top: 48px; }
.more { display: inline-block; margin-top: 16px; color: var(--body); padding: 1px 4px; margin-left: -4px; }
.more:hover { background: var(--ink); color: var(--bg); }
.empty { color: var(--muted); margin: 0; }

/* One ruled row per item. On hover the item's colour sweeps in from the left. */
.section-title + .row, main > .row:first-child { border-top: 1px solid var(--rule); }
.row {
  --fill: var(--ink); --on: var(--bg);
  position: relative; isolation: isolate; display: grid; align-items: center; gap: 20px;
  padding: 18px 12px; margin: 0 -12px; border-bottom: 1px solid var(--rule);
}
.row::before {
  content: ""; position: absolute; inset: -1px 0; z-index: -1; background: var(--fill);
  transform: scaleX(0); transform-origin: left center; transition: transform .38s cubic-bezier(.2, .7, .1, 1);
}
.row:hover::before, .row:focus-visible::before { transform: scaleX(1); }
.row:focus-visible { outline: none; }
.row > span { transition: color .2s .08s, transform .38s cubic-bezier(.2, .7, .1, 1); }
.row .go { color: var(--muted); text-align: right; }
.row:hover .go { transform: translateX(4px); }
.row:hover > span { color: var(--on); }

.project { grid-template-columns: 140px 1fr 20px; }
.project .name { display: flex; align-items: center; gap: 12px; font-weight: 700; }
.project .desc { color: var(--body); }
.mark { width: 10px; height: 10px; flex: none; background: var(--fill); transition: background .2s .08s; }
.project:hover .mark { background: var(--on); }
.pocketeer .mark { transform: rotate(45deg) scale(.85); }
.decklet { --fill: var(--purple); --on: #fff; }

.post-row { grid-template-columns: 110px 1fr 20px; padding-block: 14px; }
.post-row .date { color: var(--muted); font-variant-numeric: tabular-nums; }
.post-row .title { text-wrap: pretty; }

/* A post's table of contents: in the left margin, level with the text, and
   then held at the top as the page scrolls. Hidden where the margin is too
   narrow for it. */
body.post { position: relative; }
.toc { position: absolute; top: 166px; bottom: 64px; left: 24px; width: min(240px, (100vw - 640px) / 2 - 64px); }
.toc nav {
  position: sticky; top: 32px; max-height: calc(100vh - 64px); overflow-y: auto;
  font-size: 13px; line-height: 1.6; scrollbar-width: none;
}
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc ul ul { padding-left: 2ch; margin-bottom: 6px; }
.toc a { display: block; color: var(--muted); padding: 2px 6px; margin: 0 -6px; word-break: keep-all; overflow-wrap: anywhere; }
.toc a.active { color: var(--ink); }
.toc a:hover, .toc a.active:hover { background: var(--ink); color: var(--bg); }   /* after .active, so hover wins */
.prose h2, .prose h3, .prose h4 { scroll-margin-top: 24px; }
@media (max-width: 1199px) { .toc { display: none; } }

/* A post. */
.crumbs { display: flex; gap: 8px; color: var(--muted); margin-bottom: 56px; }
.crumbs a { color: var(--body); padding: 1px 4px; margin: 0 -4px; }
.crumbs a:hover { background: var(--ink); color: var(--bg); }
.post-head { margin-bottom: 40px; padding-bottom: 24px; border-bottom: 1px solid var(--rule); }
.post-head .date { color: var(--muted); margin: 0; }

.prose { color: var(--body); line-height: 1.8; }
.prose > * { margin: 0 0 20px; }
/* Body text is justified, as in a printed book, and English words may break
   with a hyphen at the end of a line (by the page's lang). */
.prose p, .prose li { text-align: justify; -webkit-hyphens: auto; hyphens: auto; }
.prose h2, .prose h3, .prose h4 { color: var(--ink); line-height: 1.4; margin: 48px 0 16px; text-wrap: balance; }
.prose h2 { font-size: 19px; }
.prose h3, .prose h4 { font-size: 15px; }
.prose strong { color: var(--ink); }
.prose a { color: var(--ink); text-decoration: underline; text-decoration-color: var(--muted); text-underline-offset: 3px; padding: 0 2px; margin: 0 -2px; }
.prose a:hover { background: var(--ink); color: var(--bg); text-decoration: none; }
.prose ul, .prose ol { padding-left: 2.5ch; }
.prose li + li { margin-top: 6px; }
.prose li::marker { color: var(--muted); }
.prose blockquote { border-left: 1px solid var(--muted); padding-left: 16px; margin-left: 0; }
.prose hr { border: 0; border-top: 1px solid var(--rule); margin: 40px 0; }
.prose img { display: block; max-width: 100%; height: auto; }
/* A diagram drawn in black on a transparent ground: set it on a light plate
   so it reads in dark mode too. The link opens it full size. */
.prose a.plate { display: block; padding: 16px; margin: 0; background: #fbf1c7; border: 1px solid var(--rule); }
.prose a.plate:hover { background: #fbf1c7; }
.prose a.plate img { width: 100%; }
.prose table { border-collapse: collapse; width: 100%; display: block; overflow-x: auto; }
.prose th, .prose td { text-align: left; padding: 6px 16px 6px 0; border-bottom: 1px solid var(--rule); }
.prose th { color: var(--ink); font-weight: 700; }

.prose :not(pre) > code { color: var(--ink); background: var(--bg-2); border: 1px solid var(--rule); padding: 0 4px; font-size: 0.93em; }
.code { position: relative; border: 1px solid var(--rule); }
.prose pre {
  padding: 14px 16px; background: var(--bg-2) !important;
  color-scheme: inherit !important; /* giallo sets its own; follow the toggle instead */
  overflow-x: auto; white-space: pre; font-size: 13.5px; line-height: 1.65;
}
.prose > pre { border: 1px solid var(--rule); }
.code > pre { margin: 0; }
.prose pre code { font: inherit; }
.copy {
  position: absolute; top: 0; right: 0; font: 12px/1 var(--mono); color: var(--muted);
  background: var(--bg-2); border: 0; border-left: 1px solid var(--rule); border-bottom: 1px solid var(--rule);
  padding: 6px 8px; cursor: pointer;
}
.copy:hover { background: var(--ink); color: var(--bg); }

/* Footnotes: number and text on one line, set smaller, below a hairline. */
.prose sup { line-height: 0; }
.prose .footnote-definition { display: flex; align-items: baseline; gap: 12px; margin: 0 0 10px; font-size: 13px; line-height: 1.7; }
.prose :not(.footnote-definition) + .footnote-definition { margin-top: 48px; padding-top: 24px; border-top: 1px solid var(--rule); }
.prose .footnote-definition-label { flex: none; min-width: 2ch; color: var(--muted); font-size: inherit; vertical-align: baseline; line-height: inherit; }
.prose .footnote-definition p { margin: 0; }

.post-foot { margin-top: 64px; padding-top: 24px; border-top: 1px solid var(--rule); display: flex; justify-content: space-between; }
.post-foot a { color: var(--body); padding: 1px 4px; margin: 0 -4px; }
.post-foot a:hover { background: var(--ink); color: var(--bg); }

/* Giallo's line wrappers. */
.giallo-l { display: inline-block; min-height: 1lh; width: 100%; }
.giallo-ln { display: inline-block; user-select: none; margin-right: 0.4em; padding: 0.4em; min-width: 3ch; text-align: right; opacity: 0.8; }

@media (max-width: 560px) {
  .sheet { padding: 160px 0 48px; }
  h1 { font-size: 26px; }
  .project { grid-template-columns: 1fr 20px; gap: 4px 16px; }
  .project .desc { grid-column: 1; grid-row: 2; }
  .project .go { grid-column: 2; grid-row: 1; }
  .post-row { grid-template-columns: 1fr 20px; gap: 2px 16px; }
  .post-row .title { grid-column: 1; grid-row: 2; }
  .post-row .go { grid-column: 2; grid-row: 1 / 3; }
}
@media (prefers-reduced-motion: reduce) {
  .row::before, .row > span, .mark { transition: none; }
}
