/* ALFHEIM article pages — 空无 direction, themed with Rose Pine Dawn and Kanagawa Wave. */

:root {
  color-scheme: light dark;
  /* Rose Pine Dawn */
  --bg: #faf4ed;
  --ink: #575279;
  --ink-2: #797593;
  --line: #dfdad9;
  --accent: #b4637a;
  --code-string: #286983;
  --read-progress: 0%;
  --sans: "Inter Tight", "Noto Sans SC", system-ui, sans-serif;
  --mono: "IBM Plex Mono", "Noto Sans SC", monospace;
  --measure: 640px;
}

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

:root[data-theme="dark"] {
  color-scheme: dark;
  /* Kanagawa Wave */
  --bg: #1f1f28;
  --ink: #dcd7ba;
  --ink-2: #938aa9;
  --line: #363646;
  --accent: #e46876;
  --code-string: #98bb6c;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    color-scheme: dark;
    /* Kanagawa Wave */
    --bg: #1f1f28;
    --ink: #dcd7ba;
    --ink-2: #938aa9;
    --line: #363646;
    --accent: #e46876;
    --code-string: #98bb6c;
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  min-width: 320px;
  scroll-behavior: smooth;
  background: var(--bg);
}

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-weight: 400;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  transition:
    background-color 0.8s ease,
    color 0.8s ease;
}

main {
  animation: page-in 0.9s ease both;
}

@keyframes page-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

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

button {
  color: inherit;
  font: inherit;
}

::selection {
  background: var(--ink);
  color: var(--bg);
}

a:focus-visible,
button:focus-visible,
summary:focus-visible {
  outline: 1px solid var(--ink);
  outline-offset: 3px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  top: -48px;
  left: 16px;
  z-index: 60;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 11px;
  transition: top 0.2s ease;
}

.skip-link:focus {
  top: 12px;
}

/* ---------- reading progress ---------- */

.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 50;
  width: var(--read-progress);
  height: 1px;
  background: var(--accent);
}

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

.site-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 24px;
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px;
}

.brand {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.26em;
  text-transform: uppercase;
}

.brand::after {
  content: ".";
  color: var(--accent);
}

.header-actions {
  display: flex;
  align-items: baseline;
  gap: 28px;
}

.back-link {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-2);
  transition: color 0.3s ease;
}

.back-link:hover {
  color: var(--ink);
}

.theme-toggle {
  padding: 4px;
  background: none;
  border: none;
  color: var(--ink-2);
  font-size: 12px;
  cursor: pointer;
  transition: color 0.3s ease;
}

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

/* ---------- article shell & header ---------- */

.article-shell {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0 24px;
}

.article-header {
  padding: 13vh 0 0;
}

.eyebrow {
  margin-bottom: 56px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink);
}

.article-title {
  margin-bottom: 36px;
  font-size: 34px;
  font-weight: 400;
  line-height: 1.6;
  text-wrap: pretty;
}

.article-deck {
  margin-bottom: 48px;
  color: var(--ink-2);
  font-size: 16px;
  line-height: 2;
  text-wrap: pretty;
}

.article-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 16px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.article-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.article-status::before {
  content: "";
  width: 5px;
  height: 5px;
  background: var(--ink-2);
}

.article-status[data-state="current"]::before {
  background: var(--accent);
}

/* ---------- revision summary & replacement notice ---------- */

.revision-summary {
  padding-top: 20px;
}

.revision-summary p {
  color: var(--ink-2);
  font-size: 13.5px;
  line-height: 1.9;
}

.revision-version {
  display: block;
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.replacement-notice {
  margin-top: 32px;
  padding: 16px 20px;
  border: 1px solid var(--line);
  border-left: 2px solid var(--accent);
  font-size: 14px;
  line-height: 1.9;
  color: var(--ink-2);
}

.replacement-notice strong {
  color: var(--ink);
  font-weight: 500;
}

.replacement-notice a {
  border-bottom: 1px solid var(--line);
  transition: border-color 0.3s ease;
}

.replacement-notice a:hover {
  border-color: var(--ink);
}

/* ---------- table of contents (built by article.js) ---------- */

.article-toc {
  padding: 64px 0 0;
}

.article-toc__kicker {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.article-toc ol {
  margin-top: 22px;
  list-style: none;
}

.article-toc__item {
  padding: 7px 0;
}

.article-toc__item--h3 {
  margin-left: 18px;
}

.article-toc__link {
  position: relative;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--ink-2);
  transition: color 0.3s ease;
}

.article-toc__item--h3 .article-toc__link {
  font-size: 10.5px;
}

.article-toc__link:hover {
  color: var(--ink);
}

.article-toc__link.is-active {
  color: var(--ink);
}

.article-toc__link.is-active::before {
  content: "";
  position: absolute;
  top: 50%;
  left: -14px;
  width: 4px;
  height: 4px;
  background: var(--accent);
  transform: translateY(-50%);
}

/* rail: appears once the inline toc scrolls out of view (wide screens) */

.article-toc--rail {
  position: fixed;
  top: 50%;
  left: max(16px, calc(50% - 608px));
  z-index: 40;
  display: none;
  width: 232px;
  max-height: calc(100vh - 176px);
  padding-top: 0;
  overflow-y: auto;
  scrollbar-width: none;
  --rail-fade: 64px;
  -webkit-mask-image: linear-gradient(
    to bottom,
    var(--rail-mask-top, #000),
    #000 var(--rail-fade),
    #000 calc(100% - var(--rail-fade)),
    var(--rail-mask-bottom, #000)
  );
  mask-image: linear-gradient(
    to bottom,
    var(--rail-mask-top, #000),
    #000 var(--rail-fade),
    #000 calc(100% - var(--rail-fade)),
    var(--rail-mask-bottom, #000)
  );
  opacity: 0;
  visibility: hidden;
  transform: translateY(calc(-50% + 4px));
  transition:
    opacity 0.4s ease,
    transform 0.4s ease,
    visibility 0.4s;
}

.article-toc--rail.can-scroll-up {
  --rail-mask-top: transparent;
}

.article-toc--rail.can-scroll-down {
  --rail-mask-bottom: transparent;
}

.article-toc--rail::-webkit-scrollbar {
  display: none;
}

@media (min-width: 1250px) {
  .article-toc--rail {
    display: block;
  }
}

.article-toc--rail.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(-50%);
}

.article-toc--rail .article-toc__item {
  padding: 5px 0;
}

.article-toc--rail .article-toc__link {
  display: block;
  font-size: 10px;
}

.article-toc--rail .article-toc__label {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  -webkit-mask-image: linear-gradient(
    to right,
    #000 0,
    #000 calc(100% - 32px),
    transparent 100%
  );
  mask-image: linear-gradient(
    to right,
    #000 0,
    #000 calc(100% - 32px),
    transparent 100%
  );
}

/* floating navigation */

.article-floating-actions {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  max-width: calc(100vw - 32px);
  pointer-events: none;
}

.article-back-to-top {
  display: flex;
  min-height: 35px;
  align-items: center;
  padding: 9px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
  transition:
    opacity 0.4s ease,
    transform 0.4s ease,
    visibility 0.4s,
    border-color 0.3s ease,
    color 0.3s ease;
}

.article-back-to-top.is-visible {
  pointer-events: auto;
  opacity: 1;
  visibility: visible;
  transform: none;
}

.article-back-to-top:hover {
  border-color: var(--ink);
  color: var(--ink);
}

@media (min-width: 1250px) {
  .article-floating-actions {
    right: auto;
    left: max(16px, calc(50% - 608px));
    width: 232px;
    justify-content: flex-start;
  }
}

/* trigger + dialog: narrow screens */

.article-toc-trigger {
  display: flex;
  min-height: 35px;
  align-items: baseline;
  gap: 10px;
  max-width: calc(100vw - 104px);
  padding: 9px 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  cursor: pointer;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
  transition:
    opacity 0.4s ease,
    transform 0.4s ease,
    visibility 0.4s,
    border-color 0.3s ease;
}

.article-toc-trigger.is-visible {
  pointer-events: auto;
  opacity: 1;
  visibility: visible;
  transform: none;
}

.article-toc-trigger:hover {
  border-color: var(--ink);
}

.article-toc-trigger__title {
  max-width: 44vw;
  overflow: hidden;
  color: var(--ink);
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (min-width: 1250px) {
  .article-toc-trigger {
    display: none;
  }
}

.article-toc-dialog {
  max-width: min(480px, calc(100vw - 48px));
  max-height: 70vh;
  margin: auto;
  padding: 22px 24px;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--ink);
}

.article-toc-dialog::backdrop {
  background: color-mix(in srgb, var(--ink) 18%, transparent);
}

.article-toc-dialog__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.article-toc-dialog__header p {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.article-toc-dialog__close {
  padding: 4px;
  background: none;
  border: none;
  color: var(--ink-2);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  transition: color 0.3s ease;
}

.article-toc-dialog__close:hover {
  color: var(--ink);
}

.article-toc-dialog__nav ol {
  list-style: none;
}

.article-toc-dialog__nav .article-toc__item {
  padding: 9px 0;
}

.article-toc-dialog__nav .article-toc__link {
  font-size: 12px;
}

/* ---------- article body ---------- */

.article-copy {
  padding: 72px 0 40px;
  font-size: 17px;
  line-height: 2.05;
}

.article-copy p {
  margin-bottom: 32px;
  text-wrap: pretty;
}

.article-copy h2 {
  margin: 88px 0 28px;
  font-size: 21px;
  font-weight: 500;
  line-height: 1.7;
  text-wrap: pretty;
}

.article-copy h3 {
  margin: 56px 0 20px;
  font-size: 16px;
  font-weight: 500;
}

.article-copy strong {
  font-weight: 500;
}

.article-copy a {
  border-bottom: 1px solid var(--line);
  transition: border-color 0.3s ease;
}

.article-copy a:hover {
  border-color: var(--ink);
}

.article-copy ul,
.article-copy ol {
  margin: 0 0 32px;
  padding-left: 1.4em;
}

.article-copy li {
  margin-bottom: 10px;
}

.article-copy .task-list {
  list-style: none;
  padding-left: 0;
}

.article-copy .task-list input {
  accent-color: var(--accent);
}

.article-copy code {
  font-family: var(--mono);
  font-size: 0.84em;
}

.article-quote {
  margin: 56px 0;
  padding-left: 24px;
  border-left: 1px solid var(--accent);
  color: var(--ink-2);
}

.article-quote p {
  margin: 0;
}

.article-quote--lead {
  color: var(--ink);
  font-size: 19px;
  line-height: 1.9;
}

.article-copy figure {
  margin: 48px 0;
}

.article-copy figure img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
}

.article-copy figcaption {
  margin-top: 10px;
  color: var(--ink-2);
  font-size: 12.5px;
  line-height: 1.6;
}

.article-copy table {
  display: block;
  width: max-content;
  max-width: 100%;
  margin: 56px 0;
  overflow-x: auto;
  border-collapse: collapse;
  font-size: 13.5px;
  line-height: 1.9;
}

.article-copy th {
  padding: 0 24px 14px 0;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-align: left;
  color: var(--ink-2);
  white-space: nowrap;
}

.article-copy td {
  padding: 13px 24px 13px 0;
  vertical-align: top;
}

.article-copy thead tr {
  border-bottom: 1px solid var(--line);
}

.article-copy tbody tr + tr {
  border-top: 1px solid var(--line);
}

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

.article-copy pre {
  margin: 48px 0;
  padding: 22px 26px;
  overflow-x: auto;
  border: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.85;
}

.article-copy pre code {
  font-size: inherit;
}

.code-block {
  position: relative;
  margin: 48px 0;
  border: 1px solid var(--line);
}

.code-block pre {
  margin: 0;
  padding: 22px 26px;
  border: 0;
  overflow-x: auto;
}

.code-block__toolbar {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.code-block:hover .code-block__toolbar,
.code-block:focus-within .code-block__toolbar {
  opacity: 1;
}

.code-block__language {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.code-block__copy {
  padding: 5px 9px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  transition:
    color 0.3s ease,
    border-color 0.3s ease;
}

.code-block__copy:hover:not(:disabled) {
  color: var(--ink);
  border-color: var(--ink);
}

.code-block__copy[data-state="success"] {
  color: var(--ink);
  border-color: var(--accent);
}

.code-block__copy[data-state="error"] {
  color: var(--ink);
  border-color: var(--accent);
}

/* pandoc skylighting token palette: ink base, quiet comments, weighted keywords */
.article-copy .sourceCode .al,
.article-copy .sourceCode .er,
.article-copy .sourceCode .wa {
  color: var(--ink);
  font-weight: 500;
}

.article-copy .sourceCode .an,
.article-copy .sourceCode .co,
.article-copy .sourceCode .cv,
.article-copy .sourceCode .do,
.article-copy .sourceCode .in {
  color: var(--ink-2);
  font-style: italic;
}

.article-copy .sourceCode .at,
.article-copy .sourceCode .dt,
.article-copy .sourceCode .va {
  font-weight: 500;
}

.article-copy .sourceCode .bn,
.article-copy .sourceCode .dv,
.article-copy .sourceCode .fl,
.article-copy .sourceCode .fu,
.article-copy .sourceCode .op,
.article-copy .sourceCode .ot {
  color: var(--ink);
}

.article-copy .sourceCode .bu,
.article-copy .sourceCode .cf,
.article-copy .sourceCode .im,
.article-copy .sourceCode .kw,
.article-copy .sourceCode .pp {
  color: var(--ink);
  font-weight: 500;
}

.article-copy .sourceCode .ch,
.article-copy .sourceCode .sc,
.article-copy .sourceCode .ss,
.article-copy .sourceCode .st,
.article-copy .sourceCode .vs {
  color: var(--code-string);
}

.article-copy .sourceCode .cn,
.article-copy .sourceCode .ex {
  font-weight: 500;
}

/* ---------- source card (legacy essays 001–006) ---------- */

.source-card {
  margin-top: 56px;
  padding-top: 26px;
  border-top: 1px solid var(--line);
}

.source-card h2 {
  margin-bottom: 14px;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.source-card p {
  color: var(--ink-2);
  font-size: 13.5px;
  line-height: 1.9;
}

.source-card p + p {
  margin-top: 6px;
}

.source-card a {
  border-bottom: 1px solid var(--line);
  transition: border-color 0.3s ease;
}

.source-card a:hover {
  border-color: var(--ink);
}

/* ---------- revision history & footer ---------- */

.revision-history {
  padding: 26px 0;
  border-top: 1px solid var(--line);
}

.revision-history summary {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-2);
  cursor: pointer;
  list-style: none;
  transition: color 0.3s ease;
}

.revision-history summary::-webkit-details-marker {
  display: none;
}

.revision-history summary::before {
  content: "+ ";
}

.revision-history[open] summary::before {
  content: "− ";
}

.revision-history summary:hover {
  color: var(--ink);
}

.revision-list {
  margin-top: 18px;
  list-style: none;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 2.2;
  color: var(--ink-2);
}

.revision-list strong {
  color: var(--ink);
  font-weight: 500;
}

.article-footer {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 16px;
  padding: 26px 0 15vh;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.article-footer a {
  transition: color 0.3s ease;
}

.article-footer a:hover {
  color: var(--ink);
}

/* ---------- responsive & motion ---------- */

@media (max-width: 640px) {
  .article-header {
    padding-top: 10vh;
  }

  .article-title {
    font-size: 28px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  main {
    animation: none;
  }

  body {
    transition: none;
  }
}

@media print {
  .site-header,
  .reading-progress,
  .article-toc,
  .article-floating-actions,
  .article-toc-trigger,
  .article-toc-dialog,
  .article-footer {
    display: none;
  }
}
