/* Cipher & Salt: 1776 apothecary. Native CSS, custom properties, nesting. */

:root {
  /* palette */
  --parchment: #efe4cc;
  --parchment-deep: #e4d4b0;
  --paper: #f7f0df;
  --ink: #2a1d14;
  --ink-soft: #5a4636;
  --oxblood: #7a1f1f;
  --brass: #9a7433;
  --verdigris: #3d6a5c;
  --rule: color-mix(in oklab, var(--ink) 22%, transparent);

  --bg: var(--parchment);
  --surface: var(--paper);
  --text: var(--ink);
  --muted: var(--ink-soft);
  --accent: var(--oxblood);
  --accent-2: var(--verdigris);

  /* type */
  --font-display: "IM Fell English", "Iowan Old Style", Georgia, serif;
  --font-caps: "IM Fell English SC", "IM Fell English", Georgia, serif;
  --font-body: "EB Garamond", "Iowan Old Style", Georgia, serif;
  --step--1: clamp(0.88rem, 0.85rem + 0.15vw, 0.95rem);
  --step-0: clamp(1.06rem, 1rem + 0.3vw, 1.2rem);
  --step-1: clamp(1.3rem, 1.15rem + 0.6vw, 1.6rem);
  --step-2: clamp(1.6rem, 1.3rem + 1.3vw, 2.3rem);
  --step-3: clamp(2.1rem, 1.5rem + 2.8vw, 3.8rem);

  /* space & shape */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --space-8: 4.5rem;
  --radius-1: 3px;
  --radius-2: 8px;
  --measure: 66ch;
  --page: 72rem;
  --gutter: clamp(1rem, 4vw, 2rem);
  --shadow: 0 1px 0 var(--rule), 0 10px 24px -18px color-mix(in oklab, var(--ink) 60%, transparent);

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1410;
    --surface: #251b15;
    --text: #eadcc0;
    --muted: #bba78a;
    --accent: #d27c6a;
    --accent-2: #8fbfae;
    --brass: #c9a35c;
    --rule: color-mix(in oklab, #eadcc0 18%, transparent);
  }
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: var(--step-0)/1.55 var(--font-body);
  font-variant-ligatures: common-ligatures discretionary-ligatures;
  text-rendering: optimizeLegibility;
  /* faint laid-paper texture, no images */
  background-image: repeating-linear-gradient(0deg, transparent 0 3px, color-mix(in oklab, var(--text) 3%, transparent) 3px 4px);
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
  &:hover { text-decoration-thickness: 2px; }
  &:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: var(--radius-1); }
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 400;
  line-height: 1.12;
  text-wrap: balance;
  margin: 0 0 var(--space-3);
}
h1 { font-size: var(--step-3); }
h2 { font-size: var(--step-2); }
h3 { font-size: var(--step-1); }
p { margin: 0 0 var(--space-4); text-wrap: pretty; }
em { font-style: italic; }

.small { font-size: var(--step--1); color: var(--muted); }
.eyebrow {
  font-family: var(--font-caps);
  letter-spacing: 0.08em;
  color: var(--brass);
  margin-bottom: var(--space-2);
  & a { color: inherit; }
}
.lede { font-size: var(--step-1); color: var(--muted); max-width: var(--measure); line-height: 1.4; }

.skip {
  position: absolute; left: -999px;
  &:focus { left: var(--space-4); top: var(--space-4); background: var(--surface); padding: var(--space-2) var(--space-4); z-index: 10; }
}

/* ---------- masthead ---------- */
.masthead {
  max-width: var(--page);
  margin-inline: auto;
  padding: var(--space-5) var(--gutter);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  align-items: center;
  justify-content: space-between;
  border-bottom: 3px double var(--rule);

  & .brand {
    display: flex; align-items: center; gap: var(--space-3);
    color: var(--text); text-decoration: none;
  }
  & .brand-name {
    font-family: var(--font-caps);
    font-size: var(--step-1);
    letter-spacing: 0.04em;
    & em { color: var(--accent); font-family: var(--font-display); }
  }
  & ul { list-style: none; margin: 0; padding: 0; display: flex; gap: var(--space-5); }
  & nav a { font-family: var(--font-caps); letter-spacing: 0.06em; color: var(--text); text-decoration: none; }
  & nav a:hover { color: var(--accent); }
}

.crumbs {
  max-width: var(--page);
  margin: var(--space-4) auto 0;
  padding-inline: var(--gutter);
  font-size: var(--step--1);
  & ol { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--space-2); }
  & li:not(:last-child)::after { content: "\2767"; margin-left: var(--space-2); color: var(--brass); }
  & a { color: var(--muted); text-decoration: none; }
  & a[aria-current] { color: var(--text); }
}

main {
  max-width: var(--page);
  margin-inline: auto;
  padding: var(--space-6) var(--gutter) var(--space-8);
  display: grid;
  gap: var(--space-8);
}

/* ---------- home ---------- */
.hero {
  text-align: center;
  padding-block: var(--space-6);
  display: grid;
  justify-items: center;
  & h1 { font-size: clamp(2.5rem, 1.6rem + 4.5vw, 5rem); max-width: 16ch; }
  & h1 em { color: var(--accent); }
  & .lede { margin-inline: auto; }
  & .hero-note {
    max-width: 52ch;
    padding: var(--space-3) var(--space-5);
    border-block: 1px solid var(--rule);
    font-style: italic;
  }
}

.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 17rem), 1fr));
  gap: var(--space-5);
}

/* ---------- recipe card ---------- */
.card {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-5);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-1);
  box-shadow: var(--shadow);
  position: relative;
  /* inner engraved frame */
  outline: 1px solid var(--rule);
  outline-offset: -7px;

  & header { display: grid; gap: var(--space-1); }
  & h3 { margin: 0; & a { color: var(--text); text-decoration: none; } & a::after { content: ""; position: absolute; inset: 0; } }
  & h3 a:focus-visible { outline: none; }
  &:has(h3 a:focus-visible) { outline: 2px solid var(--accent); }
  & > p { color: var(--muted); font-size: var(--step--1); flex: 1; margin: 0; }
  & footer { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-top: var(--space-3); }
  & .decipher-link { font-family: var(--font-caps); font-size: var(--step--1); letter-spacing: 0.06em; }
  &:hover { border-color: var(--brass); }
}

.card-chain {
  margin: 0;
  font-family: var(--font-caps);
  font-size: var(--step--1);
  letter-spacing: 0.08em;
  color: var(--brass);
  text-transform: lowercase;
}

.cipher {
  margin: 0;
  font-family: var(--font-caps);
  letter-spacing: 0.22em;
  color: color-mix(in oklab, var(--text) 38%, transparent);
  font-size: var(--step--1);
  &.big { font-size: var(--step-1); letter-spacing: 0.14em; line-height: 1.35; }
}

.seal {
  display: inline-block;
  font-family: var(--font-caps);
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  padding: 0.1rem 0.6rem;
  border: 1px solid currentColor;
  border-radius: 999px;
  color: var(--muted);
  white-space: nowrap;

  [data-status="documented"] &, &[data-status="documented"] { color: var(--accent-2); }
  [data-status="diy"] &, &[data-status="diy"] { color: var(--brass); }
  [data-status="reported"] &, &[data-status="reported"] { color: var(--text); }
  [data-status="unverified"] &, &[data-status="unverified"] { color: var(--accent); border-style: dashed; }
}

/* ---------- chain index ---------- */
.chain-index ul {
  list-style: none;
  margin: 0;
  padding: 0;
  columns: 2 16rem;
  column-gap: var(--space-7);
  & li { break-inside: avoid; border-bottom: 1px dotted var(--rule); }
  & a {
    display: flex; justify-content: space-between; align-items: baseline;
    padding: var(--space-3) 0;
    font-family: var(--font-display); font-size: var(--step-1);
    color: var(--text); text-decoration: none;
    &:hover span { color: var(--accent); }
  }
  & small { font-family: var(--font-body); font-size: var(--step--1); color: var(--muted); }
}

.chain-cards {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: var(--space-5);
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 20rem), 1fr));
  & article { padding: var(--space-5); background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-1); height: 100%; }
  & h2 { font-size: var(--step-1); }
}

.key dl, .key-list { margin: 0; }
.key dl {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr));
  & div { padding: var(--space-4); border-top: 1px solid var(--rule); }
  & dd { margin: var(--space-2) 0 0; color: var(--muted); font-size: var(--step--1); }
}

.page-head { display: grid; gap: var(--space-2); }

/* ---------- recipe page ---------- */
.recipe {
  max-width: 46rem;
  display: grid;
  gap: var(--space-6);
  & .aka { font-style: italic; color: var(--muted); }
}

.vault {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-2);
  box-shadow: var(--shadow);
  outline: 1px solid var(--rule);
  outline-offset: -8px;

  & summary {
    list-style: none;
    cursor: pointer;
    padding: var(--space-6) var(--space-5);
    display: grid;
    gap: var(--space-2);
    text-align: center;
    &::-webkit-details-marker { display: none; }
    &:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-2); }
  }
  & .vault-label { font-family: var(--font-caps); letter-spacing: 0.2em; color: var(--accent); }
  & .vault-hint { font-style: italic; color: var(--muted); font-size: var(--step--1); }

  &[open] {
    & .cipher, & .vault-hint { display: none; }
    & summary { padding-bottom: 0; }
  }

  & .deciphered { padding: 0 var(--space-5) var(--space-6); text-align: center; }
  & .deciphered h2 { font-size: var(--step-0); font-family: var(--font-caps); letter-spacing: 0.1em; color: var(--brass); }
}

/* swap the label text without JS; real text stays "Encrypted" for screen readers until opened */
.vault[open] .vault-label { font-size: 0; }
.vault[open] .vault-label::after { content: "Deciphered"; font-size: var(--step-0); }

.script {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--step-2);
  line-height: 1.25;
  & p { margin: 0; }
}

.steps {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
  display: grid;
  gap: var(--space-4);
  & li {
    counter-increment: step;
    display: grid;
    grid-template-columns: 2.5rem 1fr;
    gap: var(--space-3);
    &::before {
      content: counter(step, upper-roman) ".";
      font-family: var(--font-caps);
      color: var(--accent);
      text-align: right;
    }
  }
}

.notes {
  padding: var(--space-5);
  border-left: 3px solid var(--brass);
  background: color-mix(in oklab, var(--brass) 8%, transparent);
  & h2 { font-size: var(--step-1); }
  & ul { margin: 0; padding-left: 1.2em; display: grid; gap: var(--space-2); }
}

.prose {
  max-width: var(--measure);
  & h2 { margin-top: var(--space-6); }
  & dt { font-family: var(--font-caps); color: var(--accent); margin-top: var(--space-3); }
  & dd { margin: 0; }
}

/* ---------- footer ---------- */
.colophon {
  max-width: var(--page);
  margin-inline: auto;
  padding: var(--space-6) var(--gutter) var(--space-7);
  border-top: 3px double var(--rule);
  text-align: center;
  & .motto { font-family: var(--font-caps); letter-spacing: 0.1em; color: var(--brass); }
  & .small { max-width: 60ch; margin-inline: auto; }
}

@media (prefers-reduced-motion: no-preference) {
  .card { transition: border-color 0.2s, transform 0.2s; &:hover { transform: translateY(-2px); } }
}
