:root {
  --ink: #0e1014;
  --ink-soft: #161a22;
  --panel: rgba(255, 248, 246, 0.035);
  --line: rgba(244, 214, 206, 0.12);
  --text: #f3ebe6;
  --muted: #a89a93;
  --rose: #c45c4a;
  --rose-deep: #8f2f28;
  --rose-glow: rgba(196, 92, 74, 0.28);
  --gold: #d6b48a;
  --ok: #c6d5c0;
  --danger: #e8a090;
  --sidebar-w: 17.5rem;
  --max: 46rem;
  --display: "Cormorant Garamond", Georgia, serif;
  --sans: "Manrope", "Segoe UI", sans-serif;
}

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.7;
  font-weight: 450;
}

[hidden] {
  display: none !important;
}

.atmosphere {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse 70% 50% at 10% -10%, rgba(143, 47, 40, 0.35), transparent 55%),
    radial-gradient(ellipse 50% 40% at 90% 20%, rgba(214, 180, 138, 0.08), transparent 50%),
    radial-gradient(ellipse 60% 50% at 70% 100%, rgba(196, 92, 74, 0.12), transparent 55%),
    linear-gradient(180deg, #0e1014 0%, #12151c 50%, #0c0e12 100%);
}

.atmosphere::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.35;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.55'/%3E%3C/svg%3E");
  mix-blend-mode: overlay;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--rose);
  color: white;
  padding: 0.5rem 1rem;
  z-index: 100;
}

.skip-link:focus {
  left: 1rem;
  top: 1rem;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  z-index: 10;
  padding: 1.75rem 1.25rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  border-right: 1px solid var(--line);
  background: rgba(14, 16, 20, 0.72);
  backdrop-filter: blur(16px);
}

body.is-unlocked .sidebar {
  animation: rise 0.7s ease both;
}

.mark-viewer {
  margin: 0.65rem 0 0;
  font-size: 0.78rem;
  color: var(--gold);
  letter-spacing: 0.04em;
}

.sidebar-brand .mark {
  margin: 0;
  font-family: var(--display);
  font-size: 1.65rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--text);
}

.mark-sub {
  margin: 0.15rem 0 0;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold);
}

.mark-meta {
  margin: 0.45rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.toc {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  overflow: auto;
  flex: 1;
  padding-right: 0.25rem;
}

.toc a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.82rem;
  padding: 0.4rem 0.55rem;
  border-radius: 0.35rem;
  border-left: 2px solid transparent;
  transition: color 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

.toc a:hover,
.toc a.active {
  color: var(--text);
  background: var(--panel);
  border-left-color: var(--rose);
}

.sidebar-foot {
  margin: 0;
  font-size: 0.7rem;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.document {
  position: relative;
  z-index: 1;
  margin-left: var(--sidebar-w);
  padding: 3.5rem clamp(1.25rem, 4vw, 4rem) 5rem;
  max-width: calc(var(--sidebar-w) + var(--max) + 8rem);
}

body.is-unlocked .document {
  animation: rise 0.85s 0.08s ease both;
}

.cover {
  min-height: min(72vh, 38rem);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding-bottom: 3rem;
  margin-bottom: 2.5rem;
  border-bottom: 1px solid var(--line);
  max-width: var(--max);
}

.eyebrow {
  margin: 0 0 1rem;
  font-size: 0.75rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold);
}

body.is-unlocked .eyebrow {
  animation: fade-up 0.8s 0.15s ease both;
}

.cover h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(3.4rem, 9vw, 6.2rem);
  font-weight: 600;
  letter-spacing: 0.16em;
  line-height: 0.95;
  color: var(--text);
  text-shadow: 0 0 60px var(--rose-glow);
}

body.is-unlocked .cover h1 {
  animation: fade-up 0.9s 0.22s ease both;
}

.cover-title {
  margin: 1rem 0 0;
  font-family: var(--display);
  font-size: clamp(1.6rem, 3vw, 2.2rem);
  font-weight: 500;
  font-style: italic;
  color: #f0d2c8;
}

body.is-unlocked .cover-title {
  animation: fade-up 0.9s 0.3s ease both;
}

.cover-lede {
  margin: 1.25rem 0 0;
  max-width: 36rem;
  color: var(--muted);
  font-size: 1.02rem;
}

body.is-unlocked .cover-lede {
  animation: fade-up 0.9s 0.38s ease both;
}

.cover-meta {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin: 2.5rem 0 0;
  padding: 0;
}

body.is-unlocked .cover-meta {
  animation: fade-up 0.9s 0.46s ease both;
}

.cover-meta div {
  border-top: 1px solid var(--line);
  padding-top: 0.75rem;
}

.cover-meta dt {
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.cover-meta dd {
  margin: 0.3rem 0 0;
  font-family: var(--display);
  font-size: 1.2rem;
  color: var(--text);
}

.section {
  max-width: var(--max);
  padding: 2.75rem 0;
  border-bottom: 1px solid var(--line);
  scroll-margin-top: 1.5rem;
}

.section h2 {
  margin: 0 0 1.25rem;
  font-family: var(--display);
  font-size: clamp(1.85rem, 3vw, 2.35rem);
  font-weight: 600;
  letter-spacing: 0.02em;
  display: flex;
  align-items: baseline;
  gap: 0.85rem;
}

.num {
  font-size: 0.85rem;
  letter-spacing: 0.18em;
  color: var(--rose);
  font-family: var(--sans);
  font-weight: 600;
}

.section h3 {
  margin: 1.75rem 0 0.65rem;
  font-family: var(--display);
  font-size: 1.35rem;
  font-weight: 600;
  color: #f6e8e2;
}

.section p,
.section li {
  color: #ddd0c8;
}

.section strong {
  color: var(--text);
  font-weight: 600;
}

.clean {
  margin: 0.75rem 0 1rem;
  padding-left: 1.15rem;
}

.clean li {
  margin: 0.35rem 0;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin: 1.25rem 0;
}

.panel {
  padding: 1.15rem 1.2rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0.2rem;
}

.panel h3 {
  margin-top: 0;
  font-size: 1.15rem;
}

.panel p:last-child {
  margin-bottom: 0;
}

.hierarchy {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin: 1.5rem 0;
}

.rank {
  display: grid;
  grid-template-columns: 2.5rem 1fr;
  gap: 0.9rem;
  align-items: start;
  padding: 0.95rem 1rem;
  background: linear-gradient(90deg, rgba(196, 92, 74, 0.08), transparent 55%);
  border: 1px solid var(--line);
  border-left: 2px solid var(--rose);
  animation: fade-up 0.6s ease both;
}

.rank-level {
  font-family: var(--display);
  font-size: 1.35rem;
  color: var(--gold);
  line-height: 1.2;
}

.rank h3 {
  margin: 0 0 0.25rem;
  font-size: 1.15rem;
}

.rank p {
  margin: 0;
  font-size: 0.95rem;
}

.rank em {
  color: var(--muted);
  font-style: italic;
  font-weight: 500;
}

.principles {
  margin: 1rem 0 0;
  padding-left: 1.2rem;
}

.principles li {
  margin: 0.7rem 0;
}

.callout,
.note {
  margin: 1.25rem 0;
  padding: 1rem 1.15rem;
  border-radius: 0.2rem;
  background: rgba(214, 180, 138, 0.06);
  border: 1px solid rgba(214, 180, 138, 0.22);
  color: #e8d8c8;
}

.callout-strict {
  background: rgba(143, 47, 40, 0.18);
  border-color: rgba(196, 92, 74, 0.45);
  color: #f3ddd7;
}

.fineprint {
  font-size: 0.88rem;
  color: var(--muted) !important;
}

.data {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0 1.5rem;
  font-size: 0.92rem;
}

.data th,
.data td {
  text-align: left;
  vertical-align: top;
  padding: 0.75rem 0.7rem;
  border-bottom: 1px solid var(--line);
}

.data th {
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 600;
}

.data td {
  color: #ddd0c8;
}

.steps {
  margin: 0.75rem 0 1.25rem;
  padding-left: 1.2rem;
}

.steps li {
  margin: 0.45rem 0;
}

.badge {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 0.2rem;
  font-family: var(--sans);
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  vertical-align: middle;
}

.badge-high {
  color: var(--danger);
  border-color: rgba(232, 160, 144, 0.4);
}

.pills {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.75rem 0 1.25rem;
  padding: 0;
}

.pills li {
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  color: var(--text);
}

blockquote {
  margin: 0.85rem 0;
  padding: 0.75rem 1rem;
  border-left: 2px solid var(--rose);
  background: var(--panel);
  color: #f0e2db;
  font-style: italic;
}

blockquote.required {
  border-left-color: var(--gold);
  font-style: normal;
  font-family: var(--display);
  font-size: 1.15rem;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86em;
  padding: 0.1rem 0.35rem;
  border-radius: 0.2rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  color: #f0d7ce;
}

.glossary {
  margin: 0;
}

.glossary > div {
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--line);
}

.glossary dt {
  font-family: var(--display);
  font-size: 1.15rem;
  color: var(--text);
}

.glossary dd {
  margin: 0.25rem 0 0;
  color: var(--muted);
}

.doc-foot {
  max-width: var(--max);
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.88rem;
}

.doc-foot .mark {
  margin: 0 0 0.4rem;
  font-family: var(--display);
  letter-spacing: 0.16em;
  color: var(--text);
  font-size: 1.3rem;
}

.doc-foot p {
  margin: 0.2rem 0;
}

.document a {
  color: var(--gold);
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

.document a:hover {
  color: var(--text);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* —— Access gate —— */
.gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

body.is-unlocked .gate {
  display: none;
}

.gate-card {
  width: min(100%, 26rem);
  padding: 2rem 1.75rem 1.75rem;
  border: 1px solid var(--line);
  background: rgba(14, 16, 20, 0.88);
  backdrop-filter: blur(18px);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  animation: rise 0.65s ease both;
}

.gate-eyebrow {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
}

.gate-card h1 {
  margin: 0.65rem 0 0;
  font-family: var(--display);
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.gate-lede {
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.gate-form {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  margin-top: 1.5rem;
}

.gate-field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.gate-field span {
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.gate-field input {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  font: inherit;
  padding: 0.75rem 0.85rem;
  border-radius: 0.2rem;
  outline: none;
}

.gate-field input:focus {
  border-color: rgba(196, 92, 74, 0.65);
  box-shadow: 0 0 0 3px var(--rose-glow);
}

.gate-error {
  margin: 0;
  color: var(--danger);
  font-size: 0.88rem;
}

.gate-submit {
  appearance: none;
  border: 1px solid rgba(196, 92, 74, 0.55);
  background: linear-gradient(180deg, rgba(196, 92, 74, 0.35), rgba(143, 47, 40, 0.45));
  color: var(--text);
  font: inherit;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-size: 0.78rem;
  padding: 0.85rem 1rem;
  cursor: pointer;
  border-radius: 0.2rem;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.gate-submit:hover {
  border-color: rgba(196, 92, 74, 0.9);
  transform: translateY(-1px);
}

@media print {
  .gate {
    display: none !important;
  }
}

@media (max-width: 960px) {
  .sidebar {
    position: sticky;
    top: 0;
    width: 100%;
    height: auto;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .toc {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 0.25rem;
    padding-bottom: 0.35rem;
  }

  .toc a {
    white-space: nowrap;
    border-left: 0;
    border-bottom: 2px solid transparent;
  }

  .toc a:hover,
  .toc a.active {
    border-left-color: transparent;
    border-bottom-color: var(--rose);
  }

  .sidebar-foot {
    display: none;
  }

  .document {
    margin-left: 0;
    padding-top: 2rem;
  }

  .cover-meta {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

@media print {
  .atmosphere,
  .sidebar,
  .skip-link {
    display: none !important;
  }

  body {
    background: white;
    color: #111;
  }

  .document {
    margin: 0;
    padding: 0;
    max-width: none;
    animation: none;
  }

  .section,
  .cover,
  .panel,
  .rank,
  .callout,
  .note,
  blockquote {
    break-inside: avoid;
  }

  .section p,
  .section li,
  .data td,
  .cover-lede {
    color: #222 !important;
  }

  .cover h1,
  .section h2,
  .doc-foot .mark {
    color: #111;
    text-shadow: none;
  }

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