:root {
  color-scheme: dark light;

  /* Default: dark mode */
  --bg: #111318;
  --surface: #1a1f29;
  --text: #e6eaf2;
  --muted: #a7b0c0;
  --border: #2a3140;
  --link: #8ab4ff;
  --link-hover: #b3ccff;
  --accent: #7cc6ff;
  --emphatic: #ff7b72;
  --code-bg: #161b22;
  --quote-border: #3a4458;

  /* Common */
  --max-width: 140ch;
  --radius: 10px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #fcfcfd;
    --surface: #ffffff;
    --text: #1c2430;
    --muted: #5f6b7a;
    --border: #d9e0e8;
    --link: #1557d6;
    --link-hover: #003ea8;
    --accent: #0066cc;
    --emphatic: #d64545;
    --code-bg: #f3f5f7;
    --quote-border: #c7d2df;
  }
}

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

html {
  font-size: 16px;
}

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 1rem/1.7 system-ui, sans-serif;
}

header {
  padding: 3rem 0 1rem;
  border-bottom: 3px solid var(--border);
  border-radius: 3px;
}

main, header, footer {
  width: min(100% - 2rem, var(--max-width));
  margin: 0 auto;
}

article,
section,
header,
footer {
  min-width: 0;
}

h1,
h2,
h3,
h4,
h5 {
  line-height: 1.25;
  margin: 2rem 0 0.75rem;
  color: var(--accent);
}

h1 {
  font-size: clamp(2rem, 5vw, 3rem);
  margin-top: 0;
}

h1 a {
  text-decoration: none;
  color: inherit;
}

h2 {
  font-size: 1.6rem;
}

h3 {
  font-size: 1.25rem;
}

p,
ul,
ol,
blockquote,
pre,
table {
  margin: 0 0 1.25rem;
}

.post-meta,
p.post-author,
p.post-date {
  color: var(--muted);
  font-size: 0.95rem;
}

.post-meta {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  margin: 0 0 2rem;
}

.post-meta .post-date::before {
  content: "|";
  margin-right: 0.6rem;
  color: var(--border);
}

p.post-author {
  margin: 0 0 0.25rem;
  clear: none;
}

p.post-date {
  margin: 0 0 2rem;
  clear: none;
}

.post-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-top: 2.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.post-nav-prev,
.post-nav-next {
  flex: 1;
  max-width: 100%;
  font-size: 0.95rem;
  color: var(--muted);
}

.post-nav-next {
  text-align: right;
}

a {
  color: var(--link);
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.15em;
}

a:hover,
a:focus-visible {
  color: var(--link-hover);
}

img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

blockquote {
  margin-left: 0;
  padding: 0.75rem 1rem;
  border-left: 4px solid var(--quote-border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 0 var(--radius) var(--radius) 0;
}

code,
pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95em;
}

code {
  background: var(--code-bg);
  padding: 0.15em 0.4em;
  border-radius: 0.4em;
}

pre {
  background: var(--code-bg);
  padding: 1rem;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

pre code {
  background: transparent;
  padding: 0;
}

pre.irc {
  text-align: left;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.cell-input pre, .cell-output pre {
  border: 0;
  padding: 0;
}

.cell-output pre {
  background: transparent;
}

.cell-input,
.cell-output {
  border-radius: var(--radius);
  padding: 0.25rem 0.85rem;
  margin: 1rem 0;
}

.cell-input,
.cell-output,
blockquote {
  max-height: 50vh;
  overflow-y: auto;
}

.cell-output:has(> div.animation),
blockquote blockquote {
  max-height: initial;
}

.cell-input {
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  background: var(--code-bg);
}

.cell-output {
  position: relative;
  border-left: 4px solid var(--quote-border);
  background: var(--surface);
}

.cell-output::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 4px;
  border-top: 1px dashed var(--border);
  border-right: 1px dashed var(--border);
  border-bottom: 1px dashed var(--border);
  border-top-right-radius: var(--radius);
  border-bottom-right-radius: var(--radius);
  pointer-events: none;
}

.cell-input pre,
.cell-output pre {
  margin: 0.65rem 0;
}

.cell-input > :first-child,
.cell-output > :first-child {
  margin-top: 0.6rem;
}

.cell-input > :last-child,
.cell-output > :last-child {
  margin-bottom: 0.6rem;
}

.motd {
  width: min(100% - 2rem, var(--max-width));
  margin: 0 auto 0;
  padding: 0.5rem 1rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-style: italic;
}

.motd span[title] {
  text-decoration: dotted underline;
  cursor: help;
}

.header-link {
  margin-left: 0.8rem;
  /* color: var(--muted); */
  font-size: 0.9rem;
}

.copyright {
  width: min(100% - 2rem, var(--max-width));
  margin: 1rem auto 0;
  padding: 1rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-style: italic;
}

table {
  margin: 1rem auto;
  border-collapse: collapse;
  border: 1px solid var(--border);
}

th,
td {
  text-align: left;
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
}

th {
  background: var(--surface);
}

.table2d td:first-child {
  background: var(--surface);
  font-weight: bold;
}

input,
textarea,
button {
  font: inherit;
}

button {
  background: var(--accent);
  color: #fff;
  border: 0;
  padding: 0.7rem 1rem;
  border-radius: 0.6rem;
  cursor: pointer;
}

button:hover,
button:focus-visible {
  opacity: 0.92;
}

.emphatic {
  color: var(--emphatic);
  font-weight: bold;
  font-style: italic;
}

.spoiler-free-open {
  margin: 0 0 10rem 0;
  min-height: 100vh;
}

.math.display {
  margin: 0 2rem auto;
}

details {
  margin: 1rem 0;
  padding: 0.65rem 0.9rem;
  border: 1px solid var(--border);
  border-left: 3px solid var(--quote-border);
  border-radius: var(--radius);
  background: color-mix(in oklab, var(--surface) 40%, transparent);
}

details > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
  margin: -0.1rem 0 0.4rem;
}

/* Don't display first element below the marker */
details > summary > :first-child {
  display: inline-block;
}

/* Match spacing of the marker */
details > summary > :not(:first-child) {
  margin-left: 1rem;
}

/* Keep spacing tidy */
details > :last-child {
  margin-bottom: 0;
}

details details {
  margin: 0.8rem 0 0.25rem;
  border-left-color: var(--border);
  background: transparent;
}

details details details {
  border-left-style: dotted;
}

.post-index {
  list-style: none;
  inline-size: fit-content;
  max-inline-size: 100%;
  margin: 0 auto 0 0;
}

.post-index li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
}

.post-index .post-date {
  color: var(--muted);
  font-size: 0.9rem;
  white-space: nowrap;
  flex-shrink: 0;
}

figure {
  text-align: center;
}

figure img {
  display: initial;
  max-height: 60vh;
}

figure img.bigimg {
  max-height: initial;
}

.heading-anchor {
  color: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: baseline;
}

.heading-anchor::after {
  content: "\00B6";
  margin-left: 0.45rem;
  font-size: 0.9em;
  opacity: 0;
  transition: opacity 120ms ease;
}

h3:hover .heading-anchor,
h4:hover .heading-anchor,
h5:hover .heading-anchor,
h6:hover .heading-anchor,
.heading-anchor:focus-visible {
  text-decoration: none;
}

h3:hover .heading-anchor::after,
h4:hover .heading-anchor::after,
h5:hover .heading-anchor::after,
h6:hover .heading-anchor::after,
.heading-anchor:focus-visible::after {
  opacity: 0.8;
}
