/* ─────────────────────────────────────────────────────────────
   markup — ancient-futurism, humanist, ethereal
   ───────────────────────────────────────────────────────────── */

:root {
  /* palette */
  --paper:      #f4eddd;
  --paper-2:    #ede4cf;
  --paper-3:    #e3d8bd;
  --ink:        #14110b;
  --ink-2:      #3a3228;
  --ink-3:      #695d4c;
  --mute:       #8f8168;
  --line:       rgba(20, 17, 11, 0.10);
  --line-2:     rgba(20, 17, 11, 0.18);
  --gold:       #9b6e2a;
  --gold-2:     #b8893c;
  --indigo:     #2f3a5a;
  --glow:       radial-gradient(1200px 700px at 80% -10%, rgba(184, 137, 60, 0.10), transparent 60%),
                radial-gradient(900px 600px at -10% 110%, rgba(47, 58, 90, 0.08), transparent 60%);
  --selection:  rgba(155, 110, 42, 0.22);

  /* typography */
  --serif: 'EB Garamond', 'Iowan Old Style', 'Palatino Linotype', 'Book Antiqua', Palatino, Georgia, serif;
  --mono:  'JetBrains Mono', 'Iosevka', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* spatial */
  --sidebar-w: 18rem;
  --reading-w: 68ch;
  --radius: 3px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:   #14120d;
    --paper-2: #1b1812;
    --paper-3: #232016;
    --ink:     #f1e9d3;
    --ink-2:   #d7cdb4;
    --ink-3:   #a59c83;
    --mute:    #7f7860;
    --line:    rgba(241, 233, 211, 0.10);
    --line-2:  rgba(241, 233, 211, 0.22);
    --gold:    #d2a14a;
    --gold-2:  #e3b968;
    --indigo:  #9db2e0;
    --glow:    radial-gradient(1200px 700px at 80% -10%, rgba(210, 161, 74, 0.08), transparent 60%),
               radial-gradient(900px 600px at -10% 110%, rgba(157, 178, 224, 0.06), transparent 60%);
    --selection: rgba(210, 161, 74, 0.28);
  }
}

/* reset */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.72;
  color: var(--ink-2);
  background: var(--paper);
  background-image: var(--glow);
  background-attachment: fixed;
  min-height: 100vh;
  font-feature-settings: "kern", "liga", "onum", "clig";
  font-variant-numeric: oldstyle-nums proportional-nums;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

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

/* atmospheric veil */
.veil {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    repeating-linear-gradient(
      0deg,
      transparent 0 2px,
      rgba(20,17,11,0.006) 2px 3px
    );
  mix-blend-mode: multiply;
  opacity: 0.6;
}
@media (prefers-color-scheme: dark) {
  .veil {
    background: repeating-linear-gradient(0deg, transparent 0 2px, rgba(241,233,211,0.012) 2px 3px);
    mix-blend-mode: screen;
  }
}

/* ─── sidebar ─── */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  padding: 2rem 1.4rem 1.4rem 1.8rem;
  border-right: 1px solid var(--line);
  overflow-y: auto;
  z-index: 3;
  background: linear-gradient(180deg, var(--paper) 0%, var(--paper) 60%, var(--paper-2) 100%);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  text-decoration: none;
  color: var(--ink);
  margin-bottom: 1.8rem;
}
.brand-mark {
  color: var(--gold);
  display: inline-flex;
  transition: transform 0.8s cubic-bezier(.2,.8,.2,1);
}
.brand:hover .brand-mark { transform: rotate(180deg); }
.brand-name {
  font-family: var(--serif);
  font-size: 1.22rem;
  letter-spacing: 0.03em;
  font-weight: 500;
  font-style: italic;
}

.tree {
  font-size: 0.94rem;
  line-height: 1.55;
}
.t-list { list-style: none; padding: 0; margin: 0; }
.t-list .t-list { padding-left: 0.9rem; border-left: 1px solid var(--line); margin-left: 0.4rem; }
.tree li { margin: 0.08rem 0; }

.t-a {
  display: flex;
  align-items: baseline;
  gap: 0.45rem;
  color: var(--ink-3);
  text-decoration: none;
  padding: 0.18rem 0.4rem;
  border-radius: var(--radius);
  transition: color 0.2s, background 0.2s;
}
.t-a:hover { color: var(--ink); background: var(--paper-2); }
.t-a.active {
  color: var(--ink);
  background: var(--paper-2);
  box-shadow: inset 2px 0 0 var(--gold);
}
.t-dot { color: var(--mute); font-weight: 500; }

.t-dir details summary {
  list-style: none;
  cursor: pointer;
  color: var(--ink-2);
  padding: 0.18rem 0.4rem;
  border-radius: var(--radius);
  user-select: none;
  display: flex; align-items: baseline; gap: 0.45rem;
  font-variant: small-caps;
  font-weight: 500;
  letter-spacing: 0.04em;
  font-size: 0.88rem;
}
.t-dir details summary::-webkit-details-marker { display: none; }
.t-dir details summary:hover { color: var(--ink); }
.t-sigil {
  color: var(--mute);
  transition: transform 0.3s;
  display: inline-block;
  width: 0.8em;
}
.t-dir details[open] > summary .t-sigil { color: var(--gold); transform: rotate(90deg); }

.sidebar-foot {
  margin-top: 2.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 0.5rem;
  color: var(--mute);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  font-variant: small-caps;
}
.sigil { color: var(--gold); }

/* nav toggle (mobile) */
.nav-toggle {
  display: none;
  position: fixed; top: 1rem; right: 1rem;
  width: 42px; height: 42px;
  border: 1px solid var(--line-2);
  background: var(--paper);
  border-radius: var(--radius);
  z-index: 10;
  cursor: pointer;
  padding: 0;
  align-items: center; justify-content: center;
  flex-direction: column; gap: 5px;
}
.nav-toggle span {
  width: 18px; height: 1px;
  background: var(--ink);
  display: block;
  transition: transform 0.3s, opacity 0.3s;
}
body.nav-open .nav-toggle span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
body.nav-open .nav-toggle span:nth-child(2) { opacity: 0; }
body.nav-open .nav-toggle span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* ─── reader ─── */
.reader {
  margin-left: var(--sidebar-w);
  padding: 4rem 3rem 6rem;
  min-height: 100vh;
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 14rem);
  grid-template-areas:
    "head head"
    "prose toc"
    "foot foot";
  column-gap: 3rem;
  max-width: 88rem;
}
.page-head { grid-area: head; margin-bottom: 2.4rem; }
.prose     { grid-area: prose; max-width: var(--reading-w); }
.toc       { grid-area: toc; }
.page-foot { grid-area: foot; }
.index     { grid-area: prose; max-width: var(--reading-w); }

/* breadcrumb */
.bc {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--ink-3);
  letter-spacing: 0.02em;
  display: flex; align-items: center; flex-wrap: wrap; gap: 0.15rem;
}
.bc a { color: var(--ink-3); text-decoration: none; transition: color 0.2s; }
.bc a:hover { color: var(--gold); }
.bc-root { color: var(--gold); font-size: 1rem; }
.bc-sep { color: var(--mute); margin: 0 0.25rem; }
.bc-leaf { color: var(--ink); }

.page-meta {
  margin-top: 0.6rem;
  display: flex; align-items: baseline; gap: 0.6rem;
  font-size: 0.76rem;
  color: var(--mute);
  font-variant: small-caps;
  letter-spacing: 0.1em;
}
.meta-v {
  font-family: var(--mono);
  font-size: 0.76rem;
  letter-spacing: 0;
  color: var(--ink-3);
  background: none;
  padding: 0;
  font-variant: normal;
  text-transform: none;
}

/* ─── prose ─── */
.prose { font-size: 1.08rem; line-height: 1.78; }
.prose > *:first-child { margin-top: 0; }
.prose > *:last-child { margin-bottom: 0; }

.prose p { margin: 0 0 1.1em; }
.prose a {
  color: var(--ink);
  text-decoration: none;
  background-image: linear-gradient(to right, var(--gold), var(--gold));
  background-size: 100% 1px;
  background-repeat: no-repeat;
  background-position: 0 100%;
  padding-bottom: 1px;
  transition: color 0.2s, background-size 0.3s;
}
.prose a:hover {
  color: var(--gold);
  background-size: 100% 1.5px;
}

.prose strong { color: var(--ink); font-weight: 600; }
.prose em { font-style: italic; color: var(--ink); }

/* headings */
.m-h {
  color: var(--ink);
  font-weight: 500;
  line-height: 1.25;
  margin: 2.2em 0 0.6em;
  position: relative;
  letter-spacing: -0.005em;
}
.m-h1 {
  font-size: 2.4rem;
  margin-top: 0.4em;
  font-weight: 400;
  letter-spacing: -0.015em;
  line-height: 1.12;
}
.m-h1::before {
  content: "";
  display: block;
  width: 3rem;
  height: 1px;
  background: linear-gradient(to right, var(--gold), transparent);
  margin-bottom: 1.2rem;
}
.m-h2 { font-size: 1.65rem; }
.m-h3 { font-size: 1.28rem; font-style: italic; font-weight: 400; color: var(--ink-2); }
.m-h4 { font-size: 1.08rem; font-variant: small-caps; letter-spacing: 0.08em; color: var(--ink-2); }
.m-h5, .m-h6 { font-size: 0.95rem; color: var(--ink-3); font-variant: small-caps; letter-spacing: 0.1em; }

.m-anchor {
  position: absolute;
  left: -1.4rem;
  color: var(--gold);
  opacity: 0;
  text-decoration: none;
  font-weight: 400;
  transition: opacity 0.2s;
  font-size: 0.7em;
  top: 0.4em;
}
.m-h:hover .m-anchor { opacity: 0.55; }
.m-anchor:hover { opacity: 1 !important; }

/* lists */
.prose ul, .prose ol { padding-left: 1.4em; margin: 0 0 1.1em; }
.prose ul li { list-style: none; position: relative; }
.prose ul li::before {
  content: "·";
  position: absolute;
  left: -1.1em;
  color: var(--gold);
  font-weight: 700;
}
.prose ol { list-style: none; counter-reset: li; }
.prose ol li {
  counter-increment: li;
  position: relative;
}
.prose ol li::before {
  content: counter(li, lower-roman) ".";
  position: absolute;
  left: -2em;
  width: 1.6em;
  text-align: right;
  color: var(--mute);
  font-variant: small-caps;
  font-size: 0.9em;
}
.prose li { margin: 0.35em 0; }
.prose li > ul, .prose li > ol { margin: 0.3em 0 0.5em; }

/* blockquote */
.m-quote {
  margin: 1.6em 0;
  padding: 0.2em 1.4em;
  border-left: 1px solid var(--gold);
  color: var(--ink-2);
  font-style: italic;
}
.m-quote p { margin: 0.6em 0; }

/* rule */
.m-rule {
  border: 0;
  height: 1px;
  background: none;
  margin: 3em auto;
  text-align: center;
  max-width: 12rem;
  position: relative;
}
.m-rule::before {
  content: "✦";
  color: var(--gold);
  background: var(--paper);
  padding: 0 0.7em;
  font-size: 0.9rem;
  position: absolute;
  top: -0.6em;
  left: 50%;
  transform: translateX(-50%);
}
.m-rule::after {
  content: "";
  display: block;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--line-2), transparent);
}

/* code */
.m-ci {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--paper-2);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 0.08em 0.38em;
  border-radius: var(--radius);
  font-feature-settings: "calt", "zero";
}

.m-code {
  margin: 1.6em -0.5rem;
  padding: 0;
  position: relative;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.m-code pre {
  margin: 0;
  padding: 1.2rem 1.4rem;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 0.86rem;
  line-height: 1.65;
}
.m-code code { font-family: inherit; }
.m-code-lang {
  position: absolute;
  top: 0.5rem;
  right: 0.7rem;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--mute);
  padding: 0.12rem 0.4rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
}

/* table */
.m-table-wrap { overflow-x: auto; margin: 1.6em 0; }
.m-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.96rem;
}
.m-table th, .m-table td {
  padding: 0.6em 0.9em;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
.m-table th {
  color: var(--ink);
  font-weight: 500;
  font-variant: small-caps;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--line-2);
}
.m-table tr:last-child td { border-bottom: none; }

/* images */
.m-img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  margin: 1.2em 0;
  display: block;
}

/* toc */
.toc {
  position: sticky;
  top: 2rem;
  align-self: start;
  margin-top: 4.5rem;
  border-left: 1px solid var(--line);
  padding: 0.2rem 0 0.2rem 1.2rem;
  font-size: 0.86rem;
  line-height: 1.6;
  max-height: calc(100vh - 4rem);
  overflow-y: auto;
}
.toc-label {
  font-variant: small-caps;
  letter-spacing: 0.12em;
  color: var(--mute);
  font-size: 0.74rem;
  margin-bottom: 0.6rem;
}
.toc-list { list-style: none; padding: 0; margin: 0; }
.toc-list li { margin: 0.25rem 0; }
.toc-list a {
  color: var(--ink-3);
  text-decoration: none;
  transition: color 0.2s;
  display: inline-block;
  padding: 0.05rem 0;
}
.toc-list a:hover { color: var(--gold); }
.toc-list a.active { color: var(--ink); font-weight: 500; }
.toc-3 { padding-left: 0.9rem; font-size: 0.82rem; }

/* foot */
.page-foot {
  display: flex; align-items: center; gap: 1rem;
  margin-top: 5rem;
  color: var(--mute);
  font-variant: small-caps;
  letter-spacing: 0.14em;
  font-size: 0.76rem;
  max-width: var(--reading-w);
}
.foot-rule { flex: 1; height: 1px; background: var(--line); }

/* ─── directory index ─── */
.ix-title {
  font-size: 2.6rem;
  font-weight: 400;
  color: var(--ink);
  margin: 0.3em 0 0.2em;
  letter-spacing: -0.015em;
  font-style: italic;
}
.ix-title::before {
  content: "";
  display: block;
  width: 3rem;
  height: 1px;
  background: linear-gradient(to right, var(--gold), transparent);
  margin-bottom: 1.2rem;
}
.ix-sub { color: var(--ink-3); font-style: italic; margin-bottom: 2.2rem; }
.ix-group { margin-bottom: 2.4rem; }
.ix-label {
  font-variant: small-caps;
  letter-spacing: 0.14em;
  color: var(--mute);
  font-size: 0.78rem;
  margin-bottom: 0.7rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--line);
}
.ix-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.1rem;
}
.ix-list a {
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
  padding: 0.5rem 0.7rem;
  color: var(--ink-2);
  text-decoration: none;
  border-radius: var(--radius);
  transition: background 0.2s, color 0.2s, transform 0.3s;
  font-size: 1.04rem;
}
.ix-list a:hover {
  background: var(--paper-2);
  color: var(--ink);
  transform: translateX(4px);
}
.ix-mk { color: var(--gold); width: 1.1rem; display: inline-block; }
.ix-dir .ix-mk { color: var(--indigo); }
.ix-empty { color: var(--mute); font-style: italic; }
.ix-empty code { font-family: var(--mono); font-size: 0.9em; color: var(--ink-2); }

/* scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 4px; }
*::-webkit-scrollbar-thumb:hover { background: var(--mute); }

/* reveal */
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.reader > * { animation: rise 0.7s cubic-bezier(.2,.8,.2,1) both; }
.reader > *:nth-child(2) { animation-delay: 0.05s; }
.reader > *:nth-child(3) { animation-delay: 0.1s; }
.reader > *:nth-child(4) { animation-delay: 0.15s; }

/* ─── responsive ─── */
@media (max-width: 1100px) {
  .reader {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "head" "prose" "foot";
  }
  .toc { display: none; }
}

@media (max-width: 760px) {
  :root { --sidebar-w: 16rem; }
  .nav-toggle { display: flex; }
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(.2,.8,.2,1);
    box-shadow: 0 0 60px rgba(0,0,0,0.12);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  .reader {
    margin-left: 0;
    padding: 3.5rem 1.25rem 4rem;
  }
  .m-h1 { font-size: 1.9rem; }
  .m-h2 { font-size: 1.4rem; }
  .m-h3 { font-size: 1.15rem; }
  .ix-title { font-size: 2rem; }
  .prose { font-size: 1.02rem; }
  .m-anchor { display: none; }
}

/* ─── syntax highlight (warm, subdued) ─── */
.hljs { color: var(--ink-2); background: transparent; }
.hljs-comment, .hljs-quote { color: var(--mute); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-built_in, .hljs-type, .hljs-literal {
  color: var(--gold); font-weight: 500;
}
.hljs-string, .hljs-regexp, .hljs-attr, .hljs-symbol, .hljs-bullet, .hljs-meta-string {
  color: #6d7f4f;
}
.hljs-number, .hljs-variable, .hljs-template-variable {
  color: #a36a32;
}
.hljs-title, .hljs-title.class_, .hljs-title.function_, .hljs-section, .hljs-name {
  color: var(--indigo); font-weight: 500;
}
.hljs-attribute, .hljs-property { color: #7b5a8a; }
.hljs-meta, .hljs-meta-keyword { color: var(--mute); }
.hljs-tag { color: var(--ink-3); }
.hljs-deletion { color: #a3463c; }
.hljs-addition { color: #4a7a45; }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 600; }

@media (prefers-color-scheme: dark) {
  .hljs-string, .hljs-regexp, .hljs-attr { color: #a8c07a; }
  .hljs-number, .hljs-variable { color: #d6a46a; }
  .hljs-attribute, .hljs-property { color: #c9a4d6; }
  .hljs-deletion { color: #e28a80; }
  .hljs-addition { color: #9cc78c; }
}
