/* The Velan Codex: a dark tome. */

:root {
  --ink: #0d0b09;
  --leaf: #15120e;
  --leaf-2: #1c1813;
  --leaf-3: #241f18;
  --rule: #3a3125;
  --rule-soft: #2a241b;
  --text: #e9dfc9;
  --dim: #a6987d;
  --gold: #c9a45c;
  --gold-bright: #e6c47c;
  --accent: var(--gold);
  --serif: "EB Garamond", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --display: "Cormorant Garamond", "EB Garamond", Georgia, serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --measure: 46rem;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(120% 70% at 50% 0%, #1d1812 0%, transparent 60%),
    radial-gradient(80% 50% at 50% 100%, #120f0b 0%, transparent 70%),
    var(--ink);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--serif);
  font-size: 1.125rem;
  line-height: 1.65;
  min-height: 100vh;
}

a { color: var(--gold-bright); text-decoration-color: color-mix(in srgb, var(--gold) 45%, transparent); text-underline-offset: 0.18em; }
a:hover { color: #fff3d6; text-decoration-color: currentColor; }
a:focus-visible, button:focus-visible, input:focus-visible { outline: 2px solid var(--gold-bright); outline-offset: 2px; border-radius: 3px; }

.skip { position: absolute; left: -999px; }
.skip:focus { left: 1rem; top: 1rem; background: var(--leaf-2); padding: 0.5rem 1rem; z-index: 10; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Top bar and section strip */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: 72rem;
  margin: 0 auto;
  padding: 1rem 1rem 0.5rem;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text);
  text-decoration: none;
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.35rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.brand .mark { width: 2rem; height: 2rem; fill: none; stroke: var(--gold); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.brand .mark circle { fill: #fff; stroke: none; }
.search-form input, .big-search input {
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--leaf-2);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 0.45rem 1rem;
  width: min(16rem, 42vw);
}
.search-form input::placeholder, .big-search input::placeholder { color: var(--dim); }

.sections {
  max-width: 72rem;
  margin: 0 auto;
  padding: 0 1rem;
  border-bottom: 1px solid var(--rule-soft);
}
.sections ul {
  display: flex;
  gap: 0.25rem;
  list-style: none;
  margin: 0;
  padding: 0.25rem 0 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.sections ul::-webkit-scrollbar { display: none; }
.sections a {
  display: block;
  padding: 0.45rem 0.7rem 0.55rem;
  font-family: var(--display);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--dim);
  text-decoration: none;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.sections a:hover { color: var(--text); }
.sections a[aria-current] { color: var(--gold-bright); border-bottom-color: var(--gold); }

/* The leaf: one page of the tome */

.leaf {
  max-width: 72rem;
  margin: 1.5rem auto 2rem;
  padding: clamp(1.25rem, 4vw, 3rem) clamp(1rem, 5vw, 4rem);
  background: linear-gradient(180deg, var(--leaf) 0%, #13100c 100%);
  border: 1px solid var(--rule-soft);
  border-radius: 6px;
  box-shadow: 0 30px 80px -40px #000, inset 0 0 0 1px #00000040, inset 0 0 120px #00000055;
  position: relative;
}
.leaf::before {
  content: "";
  position: absolute;
  inset: 0.6rem;
  border: 1px solid color-mix(in srgb, var(--gold) 16%, transparent);
  border-radius: 3px;
  pointer-events: none;
}

.page-head { max-width: var(--measure); margin: 0 auto 2rem; text-align: center; }
.crumbs { font-size: 0.95rem; color: var(--dim); display: flex; justify-content: center; flex-wrap: wrap; gap: 0.5rem; }
.crumbs a { color: var(--dim); text-decoration: none; }
.crumbs a:hover { color: var(--text); }
.kind {
  margin: 0.75rem 0 0;
  font-family: var(--display);
  font-variant: small-caps;
  letter-spacing: 0.14em;
  font-size: 1.05rem;
  color: var(--accent);
}
h1, h2, h3, h4 { font-family: var(--display); font-weight: 600; line-height: 1.15; color: #f3e8cf; }
h1 { font-size: clamp(2.3rem, 7vw, 3.6rem); margin: 0.1em 0 0.15em; letter-spacing: 0.01em; }
.page-head h1::after {
  content: "";
  display: block;
  width: 9rem;
  height: 10px;
  margin: 0.6rem auto 0;
  background:
    radial-gradient(circle, var(--accent) 0 3px, transparent 3.5px) center / 10px 10px no-repeat,
    linear-gradient(90deg, transparent, var(--accent) 40%, transparent 46%, transparent 54%, var(--accent) 60%, transparent) center / 100% 1px no-repeat;
  opacity: 0.8;
}
.subtitle { color: var(--dim); font-style: italic; margin: 0.5rem 0 0; }
h2 { font-size: 1.85rem; margin: 2.2em 0 0.5em; padding-bottom: 0.2em; border-bottom: 1px solid var(--rule-soft); }
h3 { font-size: 1.4rem; margin: 1.8em 0 0.4em; }
h2:first-child, h3:first-child { margin-top: 0; }

.prose { max-width: var(--measure); margin: 0 auto; }
.prose p, .prose li { hyphens: auto; }
.prose img { max-width: 100%; height: auto; border-radius: 4px; }
.prose ul, .prose ol { padding-left: 1.3em; }
.prose li { margin: 0.25em 0; }
.prose li::marker { color: var(--gold); }
.prose strong { color: #f6ecd5; font-weight: 600; }
.prose em { color: #efe3c8; }
.lead { font-size: 1.25rem; color: #efe4cc; }
.note, .dim, .source { color: var(--dim); }
.note { font-size: 0.98rem; }
.source { font-size: 0.92rem; font-style: italic; margin-top: 0.75rem; }
.empty { color: var(--dim); font-style: italic; border: 1px dashed var(--rule); border-radius: 6px; padding: 1rem 1.25rem; }
code { font-family: var(--mono); font-size: 0.82em; background: var(--leaf-3); padding: 0.1em 0.35em; border-radius: 4px; color: #e7d6ae; overflow-wrap: anywhere; }
pre { background: #0f0d0a; border: 1px solid var(--rule); border-radius: 6px; padding: 1rem; overflow-x: auto; font-size: 0.95rem; line-height: 1.5; }
pre code { background: none; padding: 0; }
a.xref { color: inherit; text-decoration-style: dotted; text-decoration-color: color-mix(in srgb, var(--gold) 70%, transparent); }
a.xref:hover { color: var(--gold-bright); }

/* Drop cap on story chapters */
.prose.dropcap > p:first-child::first-letter {
  float: left;
  font-family: var(--display);
  font-size: 3.6em;
  line-height: 0.85;
  padding: 0.08em 0.1em 0 0;
  color: var(--gold);
}

.badge {
  display: inline-block;
  font-family: var(--display);
  font-variant: small-caps;
  letter-spacing: 0.1em;
  font-size: 1rem;
  padding: 0.1rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--rule);
}
.prose > .badge { margin-bottom: 1rem; }
.infobox .source { margin: 0.75rem 0 0; }
.badge.idea { color: #f0c987; border-color: #6b5530; background: #2a2114; }

/* Pages with an infobox */

.with-aside { display: grid; grid-template-columns: minmax(0, 1fr) 17rem; gap: 2.5rem; max-width: 66rem; margin: 0 auto; align-items: start; }
.with-aside .prose { margin: 0; order: 1; }
.infobox {
  order: 2;
  position: sticky;
  top: 1rem;
  background: var(--leaf-2);
  border: 1px solid var(--rule);
  border-top: 3px solid var(--accent);
  border-radius: 6px;
  padding: 1rem;
}
.infobox > svg, .infobox > img { display: block; width: 100%; height: auto; margin-bottom: 0.5rem; border-radius: 4px; }
.infobox .sigil { max-width: 9rem; margin: 0 auto 0.5rem; }

dl.facts { margin: 0; display: grid; gap: 0.5rem; }
dl.facts div { display: grid; grid-template-columns: 8.5rem minmax(0, 1fr); gap: 0.75rem; border-bottom: 1px solid var(--rule-soft); padding-bottom: 0.4rem; }
.infobox dl.facts div { grid-template-columns: 1fr; gap: 0; }
dl.facts dt { color: var(--dim); font-variant: small-caps; letter-spacing: 0.06em; }
dl.facts dd { margin: 0; }
.swatch { display: inline-block; width: 0.9em; height: 0.9em; border-radius: 50%; margin-right: 0.4em; vertical-align: -0.1em; border: 1px solid #0006; }

/* Tables */

.table-wrap { overflow-x: auto; margin: 1rem 0; border: 1px solid var(--rule); border-radius: 6px; }
table { border-collapse: collapse; width: 100%; font-size: 1rem; line-height: 1.45; }
th, td { text-align: left; vertical-align: top; padding: 0.55rem 0.75rem; border-bottom: 1px solid var(--rule-soft); }
thead th { font-family: var(--display); font-size: 1.05rem; font-weight: 600; color: var(--gold-bright); background: var(--leaf-2); }
tbody tr:last-child td, tbody tr:last-child th { border-bottom: 0; }
tbody th { font-weight: 500; color: var(--dim); }

/* Cards */

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 1rem; margin: 1rem 0 1.5rem; }
.with-aside .cards { grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr)); }
.card {
  display: flex;
  flex-direction: column;
  background: var(--leaf-2);
  border: 1px solid var(--rule);
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  overflow: hidden;
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
}
.card:hover { color: var(--text); border-color: color-mix(in srgb, var(--accent) 70%, var(--rule)); transform: translateY(-2px); box-shadow: 0 10px 30px -18px var(--accent); }
.card-visual:empty { display: none; }
.card-visual { background: #100d0a; border-bottom: 1px solid var(--rule-soft); display: grid; place-items: center; aspect-ratio: 2 / 1; }
.card-visual svg, .card-visual img { width: 100%; height: 100%; object-fit: cover; }
.card-visual:has(.sigil) { aspect-ratio: auto; height: 7rem; }
.card-visual .sigil { width: 5.5rem; height: 5.5rem; }
.card-text { padding: 0.75rem 1rem 1rem; }
.card h3 { margin: 0; font-size: 1.35rem; color: #f3e8cf; }
.card p { margin: 0.35rem 0 0; font-size: 0.98rem; color: var(--dim); line-height: 1.45; }
.card .card-meta { color: var(--accent); font-variant: small-caps; letter-spacing: 0.06em; }
.cards.chapters .card-text { border-left: 3px solid var(--rule); }
.cards.chapters .card:hover .card-text { border-left-color: var(--gold); }

/* Spells */

.spell-sheet { display: grid; grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr)); gap: 0.75rem; margin: 1.5rem 0; padding: 0; }
.spell-sheet a { display: block; background: #100d0a; border: 1px solid var(--rule); border-radius: 6px; text-align: center; color: var(--text); text-decoration: none; padding-bottom: 0.5rem; transition: border-color 0.2s; }
.spell-sheet a:hover { border-color: var(--accent); }
.spell-sheet svg { width: 100%; height: auto; display: block; }
.spell-sheet span { font-family: var(--display); font-weight: 600; font-size: 1.2rem; }
.spell-sheet figcaption { grid-column: 1 / -1; font-size: 0.95rem; color: var(--dim); }

figure.thumbs { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin: 1.5rem 0; }
figure.thumbs > div { background: #100d0a; border: 1px solid var(--rule); border-radius: 8px; padding: 0.5rem; text-align: center; }
figure.thumbs .hand { font-family: var(--display); font-variant: small-caps; letter-spacing: 0.12em; color: var(--dim); }
figure.thumbs svg { width: 100%; height: auto; display: block; }
figure.thumbs figcaption { grid-column: 1 / -1; font-size: 0.95rem; color: var(--dim); }
.replay { font: inherit; font-size: 0.9rem; color: var(--gold-bright); background: none; border: 1px solid var(--rule); border-radius: 999px; padding: 0.1rem 0.75rem; cursor: pointer; margin-left: 0.25rem; }
.replay:hover { border-color: var(--gold); }

.draw { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw var(--draw, 1.5s) cubic-bezier(0.45, 0.05, 0.35, 1) 0.25s forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) { .draw { animation: none; stroke-dashoffset: 0; } }

.bars { display: grid; gap: 0.4rem; margin: 0.75rem 0 1rem; }
.bar { display: grid; grid-template-columns: 7rem minmax(0, 1fr) 4.5rem; gap: 0.75rem; align-items: center; font-size: 1rem; }
.bar-label { color: var(--dim); text-transform: capitalize; }
.bar-track { height: 0.6rem; background: var(--leaf-3); border-radius: 999px; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 999px; }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; }

/* Quotations from the Codex */

.from-codex { margin-bottom: 1.5rem; }
blockquote.mention { margin: 0 0 1rem; padding: 0.75rem 1rem; background: var(--leaf-2); border-left: 3px solid var(--accent); border-radius: 0 6px 6px 0; }
blockquote.mention p { margin: 0; }
blockquote.mention .source { margin: 0.4rem 0 0; }
dl.row-quote { margin: 0; display: grid; gap: 0.2rem; }
dl.row-quote div { display: grid; grid-template-columns: 8rem minmax(0, 1fr); gap: 0.75rem; }
dl.row-quote dt { color: var(--dim); font-variant: small-caps; letter-spacing: 0.04em; }
dl.row-quote dd { margin: 0; }

.missing-figure { border: 1px dashed var(--rule); border-radius: 6px; padding: 1rem; color: var(--dim); font-style: italic; }
.missing-figure span { display: block; font-style: normal; font-variant: small-caps; letter-spacing: 0.08em; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: 1rem; }
.gallery.single { grid-template-columns: minmax(0, 32rem); margin: 1.5rem 0; }
.gallery figure { margin: 0; background: var(--leaf-2); border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; }
.gallery img { display: block; width: 100%; height: auto; }
.gallery figcaption { padding: 0.5rem 0.75rem; font-size: 0.95rem; color: var(--dim); }
.gallery figcaption strong { color: var(--text); font-weight: 500; }

/* Home */

.cover { text-align: center; max-width: 40rem; margin: 1rem auto 2rem; }
.cover h1 { font-size: clamp(2.8rem, 10vw, 5rem); margin: 0.1em 0; }
.cover .lead { color: var(--dim); }
.cover-meta { font-size: 0.95rem; color: var(--dim); font-style: italic; }
.gaps { background: var(--leaf-2); border: 1px solid var(--rule); border-radius: 6px; padding: 1rem 1.5rem; margin-top: 2.5rem; }
.gaps h2 { margin-top: 0.5rem; border: 0; }

/* Full Codex */

.toc { background: var(--leaf-2); border: 1px solid var(--rule); border-radius: 6px; padding: 1rem 1.5rem; margin: 1.5rem 0 2rem; }
.toc h2 { margin: 0 0 0.5rem; border: 0; font-size: 1.4rem; }
.toc ol { margin: 0; padding-left: 1.25rem; }
.toc ol ol { font-size: 0.98rem; }
.open-page { font-family: var(--serif); font-size: 0.9rem; font-weight: 400; margin-left: 0.5rem; vertical-align: middle; }
.codex-chapter { scroll-margin-top: 1rem; }
[id] { scroll-margin-top: 1rem; }

/* Search and index */

.big-search label { display: block; font-family: var(--display); font-size: 1.3rem; margin-bottom: 0.4rem; }
.big-search input { width: 100%; font-size: 1.2rem; padding: 0.7rem 1.1rem; }
#results { margin: 1rem 0 2rem; }
.result { display: block; padding: 0.75rem 0; border-bottom: 1px solid var(--rule-soft); text-decoration: none; color: var(--text); }
.result strong { font-family: var(--display); font-size: 1.3rem; color: var(--gold-bright); }
.result .dim { margin-left: 0.5rem; font-size: 0.95rem; }
.result p { margin: 0.2rem 0 0; color: var(--dim); font-size: 1rem; }
.result mark { background: #5a4520; color: #fff3d6; border-radius: 2px; padding: 0 0.1em; }
.letters { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 1rem; }
.letters a { display: inline-grid; place-items: center; width: 2.1rem; height: 2.1rem; border: 1px solid var(--rule); border-radius: 4px; text-decoration: none; font-family: var(--display); font-weight: 600; }
.az ul { list-style: none; padding: 0; columns: 2 16rem; }
.az li { break-inside: avoid; }

/* Pager and footer */

.pager { display: flex; justify-content: space-between; gap: 1rem; max-width: var(--measure); margin: 3rem auto 0; padding-top: 1.25rem; border-top: 1px solid var(--rule-soft); }
.pager a { text-decoration: none; display: flex; flex-direction: column; font-family: var(--display); font-size: 1.2rem; font-weight: 600; }
.pager a span { font-family: var(--serif); font-size: 0.85rem; font-weight: 400; color: var(--dim); font-variant: small-caps; letter-spacing: 0.1em; }
.pager .next { text-align: right; margin-left: auto; }
.colophon { max-width: 72rem; margin: 0 auto 2rem; padding: 0 1rem; text-align: center; font-size: 0.9rem; color: var(--dim); }

/* Phones */

@media (max-width: 52rem) {
  .with-aside { grid-template-columns: 1fr; gap: 1.5rem; }
  .infobox { order: 0; position: static; display: grid; grid-template-columns: 8rem minmax(0, 1fr); gap: 1rem; align-items: start; }
  .infobox > svg, .infobox > img { margin: 0; }
  .infobox .sigil { margin: 0; }
}

@media (max-width: 36rem) {
  body { font-size: 1.0625rem; }
  .topbar { flex-wrap: wrap; }
  .search-form { flex: 1 1 100%; }
  .search-form input { width: 100%; }
  .leaf { margin: 0.75rem 0.5rem 1.5rem; border-radius: 4px; }
  .leaf::before { inset: 0.35rem; }
  h2 { font-size: 1.6rem; }
  .infobox { grid-template-columns: 1fr; }
  .infobox > svg, .infobox > img { max-width: 20rem; margin: 0 auto; }
  dl.facts div, dl.row-quote div { grid-template-columns: 1fr; gap: 0; }
  .bar { grid-template-columns: 5.5rem minmax(0, 1fr) 4rem; gap: 0.5rem; }
  figure.thumbs { gap: 0.5rem; }

  /* Tables become stacked cards, each cell labelled by its column. */
  .table-wrap { border: 0; overflow: visible; }
  .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td, .table-wrap th { display: block; }
  .table-wrap thead { display: none; }
  .table-wrap tr { background: var(--leaf-2); border: 1px solid var(--rule); border-radius: 6px; margin-bottom: 0.75rem; padding: 0.5rem 0.75rem; }
  .table-wrap td, .table-wrap tbody th { border: 0; padding: 0.2rem 0; }
  .table-wrap tbody th { font-family: var(--display); font-size: 1.15rem; color: var(--gold-bright); }
  .table-wrap td[data-label]:not([data-label=""])::before { content: attr(data-label); display: block; color: var(--dim); font-size: 0.85rem; font-variant: small-caps; letter-spacing: 0.06em; }
}

/* Concept art, prompts and the 3D viewer */

.gallery details { margin-top: 0.35rem; }
.gallery summary { cursor: pointer; color: var(--gold-bright); font-size: 0.9rem; }
.gallery details p { font-size: 0.88rem; line-height: 1.45; margin: 0.35rem 0 0; }
.gallery.textures img { aspect-ratio: 1; object-fit: cover; }
.cover-art { margin: -0.5rem 0 1.5rem; border-radius: 6px; overflow: hidden; border: 1px solid var(--rule); position: relative; }
.cover-art img { display: block; width: 100%; height: auto; max-height: 26rem; object-fit: cover; }
.cover-art figcaption { position: absolute; right: 0.75rem; bottom: 0.5rem; font-size: 0.85rem; color: #fff; text-shadow: 0 1px 4px #000; }
.model-viewer { margin: 1rem 0 1.5rem; }
.mv-stage { position: relative; height: clamp(18rem, 55vh, 32rem); background: radial-gradient(70% 80% at 50% 40%, #2a231b 0%, #100d0a 100%); border: 1px solid var(--rule); border-radius: 8px; overflow: hidden; touch-action: none; }
.mv-stage canvas { display: block; width: 100% !important; height: 100% !important; }
.mv-status { position: absolute; inset: auto 0 1rem; text-align: center; color: var(--dim); font-style: italic; margin: 0; }
.mv-controls { display: flex; flex-wrap: wrap; gap: 0.75rem; justify-content: space-between; margin-top: 0.6rem; }
.mv-modes, .mv-clips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.mv-modes[hidden], .mv-clips[hidden] { display: none; }
.model-viewer button { font: inherit; font-size: 0.95rem; color: var(--text); background: var(--leaf-2); border: 1px solid var(--rule); border-radius: 999px; padding: 0.2rem 0.85rem; cursor: pointer; }
.model-viewer button:hover { border-color: var(--gold); }
.model-viewer button[aria-pressed="true"] { background: #3a2f1f; border-color: var(--gold); color: var(--gold-bright); }
.model-viewer figcaption { font-size: 0.92rem; color: var(--dim); margin-top: 0.4rem; }
.chains td svg { width: 7.5rem; height: auto; display: block; }
body[data-section="art"] .leaf > .prose { max-width: 64rem; }
body[data-section="art"] .gallery { grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr)); }
