/* The Code Dungeon User Guide: one parchment leaf per page, charred and torn at the edges, on a dark table.
   Alegreya and Alegreya SC (as in the dungeon itself), Courier Prime for commands, one rust accent. */

:root {
  --table: #150e09;
  --char: #231104;
  --parchment: #ead9b2;
  --parchment-deep: #d6b984;
  --scorch: rgba(104, 50, 14, 0.55);
  --ink: #2a1d14;
  --faded: #6b5440;
  --rust: #a0441c;
  --rule: rgba(42, 29, 20, 0.28);
  --key: #f2e4c2;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--table);
  -webkit-text-size-adjust: 100%;
  /* the charred rim reaches past the page; it must never make the window scroll sideways */
  overflow-x: clip;
}

body {
  overflow-x: clip;
}

body {
  margin: 0;
  min-height: 100vh;
  padding: 2.5rem 16px 4rem;
  color: var(--ink);
  font-family: 'Alegreya', Georgia, serif;
  font-size: 1.25rem;
  line-height: 1.65;
  background:
    radial-gradient(ellipse at 50% 20%, rgba(120, 70, 30, 0.18), transparent 60%),
    var(--table);
}

.defs {
  position: absolute;
  width: 0;
  height: 0;
}

/* ---------- the book: contents column and the leaf ---------- */

.book {
  display: grid;
  /* in pixels, not rem: A- and A+ change the size of the words, never the width of the page or the column */
  grid-template-columns: clamp(300px, 28vw, 368px) minmax(0, 860px);
  gap: 44px;
  justify-content: center;
  align-items: start;
  max-width: 1320px;
  margin: 0 auto;
}

.leaf {
  position: relative;
  min-width: 0;
  padding: 4.25rem 4.5rem 3.5rem;
}

:is(.leaf, .toc) > .char,
:is(.leaf, .toc) > .paper {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* the burnt rim: a darker, rougher sheet just under the paper */
:is(.leaf, .toc) > .char {
  inset: -9px;
  background: var(--char);
  filter: url(#char);
  opacity: 0.92;
}

:is(.leaf, .toc) > .paper {
  background-color: var(--parchment);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' seed='3'/%3E%3CfeColorMatrix values='0 0 0 0 0.35 0 0 0 0 0.22 0 0 0 0 0.1 0 0 0 0.16 0'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23g)'/%3E%3C/svg%3E"),
    radial-gradient(ellipse at 50% 45%, transparent 52%, var(--parchment-deep) 86%, #b68449 100%);
  box-shadow:
    inset 0 0 46px var(--scorch),
    inset 0 0 10px rgba(40, 15, 3, 0.85);
  filter: url(#burn);
}

.ink {
  position: relative;
}

/* ---------- type ---------- */

h1,
h2,
.chapter-num,
.running,
.kicker,
.subtitle,
.turn {
  font-family: 'Alegreya SC', 'Alegreya', Georgia, serif;
}

h1 {
  margin: 0 0 1.75rem;
  font-size: 2.35rem;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0.01em;
}

h2 {
  margin: 2.4rem 0 0.6rem;
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.25;
}

h2::before {
  content: '';
  display: block;
  width: 2.5rem;
  height: 2px;
  margin-bottom: 0.55rem;
  background: var(--rust);
}

p {
  margin: 0 0 1rem;
}

/* the drop cap on a chapter's first paragraph */
.opening::first-letter {
  float: left;
  margin: 0.32rem 0.55rem 0 0;
  font-family: 'Alegreya SC', Georgia, serif;
  font-size: 3.7em;
  font-weight: 700;
  line-height: 0.78;
  color: var(--rust);
}

a {
  color: var(--rust);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

a:hover {
  text-decoration-thickness: 2px;
}

a:focus-visible {
  outline: 2px solid var(--rust);
  outline-offset: 3px;
}

strong {
  font-weight: 700;
}

kbd {
  display: inline-block;
  min-width: 1.5em;
  padding: 0 0.4em;
  font-family: 'Alegreya SC', Georgia, serif;
  font-size: 0.85em;
  line-height: 1.45;
  text-align: center;
  color: var(--ink);
  background: var(--key);
  border: 1px solid rgba(42, 29, 20, 0.55);
  border-radius: 3px;
  box-shadow: 0 2px 0 rgba(120, 85, 45, 0.6);
}

code {
  padding: 0.05em 0.3em;
  font-family: 'Courier Prime', 'Courier New', monospace;
  font-size: 0.92em;
  background: rgba(120, 80, 30, 0.13);
  border-radius: 2px;
  overflow-wrap: anywhere;
}

ul {
  margin: 0 0 1.2rem;
  padding: 0;
  list-style: none;
}

li {
  position: relative;
  margin: 0 0 0.55rem;
  padding-left: 1.35rem;
}

li::before {
  content: '';
  position: absolute;
  left: 0.2rem;
  top: 0.68em;
  width: 0.42rem;
  height: 0.42rem;
  background: var(--rust);
  transform: rotate(45deg);
}

table.keys {
  width: 100%;
  margin: 0.5rem 0 1.5rem;
  border-collapse: collapse;
}

table.keys th,
table.keys td {
  padding: 0.45rem 0.6rem 0.45rem 0;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px dotted var(--rule);
}

table.keys th {
  width: 38%;
  font-weight: 600;
}

/* ---------- running head, chapter head, turning the page ---------- */

.running {
  margin: 0 0 2.25rem;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
}

.running a {
  color: var(--faded);
  text-decoration: none;
}

.running a:hover {
  color: var(--rust);
}

.chapter-num {
  margin: 0 0 0.2rem;
  font-size: 1.05rem;
  letter-spacing: 0.12em;
  color: var(--rust);
}

.turn {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 1rem;
  align-items: end;
  margin-top: 3rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--rule);
  font-size: 0.95rem;
}

.turn a {
  text-decoration: none;
}

.turn a .name {
  display: block;
  font-family: 'Alegreya', Georgia, serif;
  font-size: 1.02rem;
  color: var(--ink);
}

.turn a:hover .name {
  text-decoration: underline;
}

.turn [rel='next'] {
  text-align: right;
}

.turn .to-contents {
  align-self: center;
  color: var(--faded);
}

/* ---------- the title page ---------- */

.title-page {
  margin: 0.5rem 0 3rem;
}

.kicker {
  margin: 0 0 0.3rem;
  font-size: 1rem;
  letter-spacing: 0.1em;
  color: var(--faded);
}

.title-page h1 {
  margin: 0;
  /* blackletter, as on the dungeon's own title page */
  font-family: 'UnifrakturMaguntia', 'Alegreya SC', Georgia, serif;
  font-size: clamp(3rem, 10vw, 4.8rem);
  font-weight: 400;
  line-height: 1.05;
}

.subtitle {
  margin: 0.4rem 0 0;
  font-size: 1.6rem;
  color: var(--rust);
}

.title-page .mark {
  margin: 1.4rem 0 0;
  font-size: 1.5rem;
  color: var(--rust);
}

/* the title page sits a little askew on the table, as a page put down by hand would */
.leaf:has(.title-page) {
  transform: rotate(-0.6deg);
}

.begin {
  margin-top: 2rem;
  font-family: 'Alegreya SC', Georgia, serif;
  font-size: 1.1rem;
}

/* ---------- the contents column: always beside the page, the chapter you're in marked ---------- */

.toc {
  position: sticky;
  top: 1.5rem;
  padding: 1.6rem 1.4rem 1.3rem 1.5rem;
  font-size: 1rem;
  line-height: 1.4;
}

/* only the list scrolls, inside the parchment, and only when it's taller than the window; the charred rim around it
   never makes the column scroll */
.toc > details {
  position: relative;
  max-height: calc(100vh - 3rem - 2.9rem);
  overflow-x: hidden;
  overflow-y: auto;
  padding-right: 0.3rem;
  scrollbar-width: thin;
  scrollbar-color: var(--rust) transparent;
  /* at the largest text sizes a long word must wrap, not run out of the column */
  overflow-wrap: anywhere;
}

.toc summary {
  display: none;
  cursor: pointer;
  font-family: 'Alegreya SC', Georgia, serif;
  font-size: 1.1rem;
  color: var(--rust);
}

.toc-title {
  margin: 0 0 1rem;
  font-family: 'Alegreya SC', Georgia, serif;
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.2;
}

.toc-title a {
  color: var(--ink);
  text-decoration: none;
}

.toc-title span {
  display: block;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--rust);
}

.toc-title a[aria-current='page'] span::after {
  content: ' ·  you are here';
  color: var(--faded);
}

.toc ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

.toc li {
  margin: 0;
  padding: 0;
}

.toc li::before {
  display: none;
}

.chapters > li > a {
  display: grid;
  grid-template-columns: 2.6rem 1fr;
  padding: 0.42rem 0.3rem 0.42rem 0.5rem;
  border-left: 3px solid transparent;
  border-bottom: 1px dotted var(--rule);
  color: var(--ink);
  text-decoration: none;
}

.chapters > li > a:hover .name {
  color: var(--rust);
  text-decoration: underline;
}

.toc .num {
  font-family: 'Alegreya SC', Georgia, serif;
  color: var(--rust);
  letter-spacing: 0.05em;
}

/* the chapter being read */
.chapters > li.here > a {
  border-left-color: var(--rust);
  background: rgba(160, 68, 28, 0.1);
  font-weight: 700;
}

.sections {
  padding: 0.3rem 0 0.5rem 3.1rem !important;
}

.sections a {
  display: block;
  padding: 0.18rem 0 0.18rem 0.7rem;
  border-left: 2px solid var(--rule);
  font-size: 0.92rem;
  color: var(--faded);
  text-decoration: none;
}

.sections a:hover {
  color: var(--rust);
}

/* the section in view */
.sections a.on {
  border-left-color: var(--rust);
  color: var(--ink);
  font-weight: 600;
}

.textsize {
  display: flex;
  gap: 0.4rem;
  margin-top: 1.2rem;
}

.textsize button {
  flex: 1;
  padding: 0.3rem 0;
  font-family: 'Alegreya SC', Georgia, serif;
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
  background: var(--key);
  border: 1px solid rgba(42, 29, 20, 0.55);
  border-radius: 3px;
  box-shadow: 0 2px 0 rgba(120, 85, 45, 0.6);
  cursor: pointer;
}

.textsize button:hover:not(:disabled) {
  border-color: var(--rust);
}

.textsize button:disabled {
  opacity: 0.45;
  cursor: default;
}

.textsize button[aria-pressed='true'] {
  background: #e6cf96;
}

.textsize button:focus-visible,
.toc summary:focus-visible {
  outline: 2px solid var(--rust);
  outline-offset: 2px;
}

/* ---------- narrower screens: the contents fold up above the page ---------- */

@media (max-width: 959px) {
  .book {
    grid-template-columns: minmax(0, 860px);
    gap: 1.75rem;
  }

  .toc {
    position: relative;
    top: 0;
  }

  .toc > details {
    max-height: none;
    overflow: visible;
  }

  .toc summary {
    display: list-item;
  }

  .toc details[open] summary {
    margin-bottom: 0.8rem;
  }
}

@media (max-width: 640px) {
  body {
    padding: 1.5rem 16px 2.5rem;
    font-size: 1.15rem;
  }

  .leaf {
    padding: 2.6rem 1.6rem 2.2rem;
  }

  h1 {
    font-size: 1.9rem;
  }

  table.keys th {
    width: 44%;
  }

  .turn {
    grid-template-columns: 1fr 1fr;
  }

  .turn .to-contents {
    grid-column: 1 / -1;
    grid-row: 1;
    justify-self: center;
  }
}

/* the dungeon's woodcut icons, in a line of text */
.ico {
  display: inline-block;
  width: 1.2em;
  height: 1.2em;
  vertical-align: -0.25em;
}

/* a line to paste into a terminal: the line itself, then its Copy button */
.command {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin: 0 0 1.4rem;
  padding: 0.8rem 1rem;
  background: rgba(42, 29, 20, 0.07);
  border-left: 4px solid #a0441c;
}
.command code {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
  background: none;
  padding: 0;
}
.command .copy {
  flex: none;
  font: 600 0.9rem 'Alegreya SC', Georgia, serif;
  color: #2a1d14;
  background: #ecdfc2;
  border: 2px solid #2a1d14;
  border-radius: 2px;
  padding: 0.2rem 0.7rem;
  cursor: pointer;
}
