:root {
  --ink: #05080c;
  --ink-soft: #0a1016;
  --panel: rgba(8, 12, 16, .94);
  --panel2: #0d141e;
  --paper: #cfc39f;
  --paper-deep: #a79773;
  --gold: #c5a059;
  --gold-bright: #edcf83;
  --gold-line: rgba(197, 160, 89, .32);
  --ivory: #ece7dc;
  --muted: #aaa59b;
  --faint: #969188;
  --display: 'Cinzel', Georgia, serif;
  --body: 'Inter', system-ui, sans-serif;
  --nav-height: 66px;
  --ease: cubic-bezier(.16, 1, .3, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { background: var(--ink); scroll-behavior: smooth; scroll-padding-top: calc(var(--nav-height) + 20px); }
body {
  margin: 0;
  min-width: 320px;
  color: var(--ivory);
  background:
    radial-gradient(circle at 50% -10%, rgba(197, 160, 89, .12), transparent 42%),
    linear-gradient(180deg, #071018 0, #05080c 28%, #030507 100%);
  font-family: var(--body);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

.page-grain {
  position: fixed;
  inset: -40%;
  z-index: 9999;
  pointer-events: none;
  opacity: .025;
  background-image: repeating-radial-gradient(circle, transparent 0 2px, #fff 3px, transparent 4px);
  background-size: 19px 23px;
  animation: grain 10s steps(8) infinite;
}

@keyframes grain {
  0% { transform: translate(-1%, -1%); }
  25% { transform: translate(1%, 0); }
  50% { transform: translate(0, 1%); }
  75% { transform: translate(-1%, 0); }
  100% { transform: translate(0, -1%); }
}

a { color: inherit; text-decoration: none; }
button, input { color: inherit; font: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--gold-bright);
  outline-offset: 3px;
}

.shell {
  width: min(1160px, calc(100% - 40px));
  margin: 0 auto;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-height);
  border-bottom: 1px solid var(--gold-line);
  background: rgba(3, 6, 10, .92);
  backdrop-filter: blur(16px);
  transition: background .3s, border-color .3s;
}
.topbar .shell {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--display);
  font-size: .75rem;
  letter-spacing: .22em;
  color: var(--gold-bright);
}
.brand img {
  width: 36px;
  height: 36px;
  object-fit: contain;
  filter: drop-shadow(0 0 9px rgba(197, 160, 89, .35));
}
.brand small {
  color: rgba(237, 207, 131, .6);
  font-size: .56rem;
  letter-spacing: .25em;
  margin-left: 2px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}
.top-nav-link {
  font-family: var(--display);
  font-size: .62rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 8px 10px;
  transition: color .2s;
}
.top-nav-link:hover { color: var(--gold-bright); }

.top-download-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--gold);
  background: rgba(197, 160, 89, .12);
  color: var(--gold-bright);
  font-family: var(--display);
  font-size: .62rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  clip-path: polygon(6px 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%, 0 6px);
  transition: background .2s, transform .2s, color .2s;
}
.top-download-btn:hover {
  background: rgba(197, 160, 89, .24);
  color: #fff;
  transform: translateY(-1px);
}

.official-languages {
  display: flex;
  align-items: center;
  border: 1px solid var(--gold-line);
  background: rgba(5, 8, 12, .8);
}
.official-languages button {
  appearance: none;
  border: 0;
  border-right: 1px solid var(--gold-line);
  background: transparent;
  color: var(--muted);
  padding: 7px 11px;
  font-family: var(--display);
  font-size: .6rem;
  letter-spacing: .1em;
  cursor: pointer;
  transition: color .15s, background .15s;
}
.official-languages button:last-child { border-right: 0; }
.official-languages button:hover,
.official-languages button.active {
  color: var(--gold-bright);
  background: rgba(197, 160, 89, .15);
}

/* Breadcrumbs */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 22px;
  font-family: var(--display);
  font-size: .62rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--faint);
}
.breadcrumb a { color: var(--muted); transition: color .2s; }
.breadcrumb a:hover { color: var(--gold-bright); }
.breadcrumb .bc-current { color: var(--gold); }

/* Hero */
.hero {
  position: relative;
  padding: 56px 0 44px;
  border-bottom: 1px solid var(--gold-line);
  overflow: hidden;
}
.hero-runes {
  position: absolute;
  right: 20px;
  top: 30px;
  display: flex;
  gap: 18px;
  color: rgba(237, 207, 131, .15);
  font-family: Georgia, serif;
  font-size: 2.2rem;
  pointer-events: none;
}
.kicker {
  margin: 0 0 14px;
  color: var(--gold);
  font-family: var(--display);
  font-size: .64rem;
  letter-spacing: .28em;
  text-transform: uppercase;
}
h1, h2, h3 { font-family: var(--display); font-weight: 500; }
h1 {
  max-width: 920px;
  margin: 0;
  font-size: clamp(2.3rem, 5.5vw, 4.2rem);
  line-height: 1.05;
  color: #f2ede3;
  letter-spacing: .02em;
}
.lead {
  max-width: 800px;
  margin: 20px 0 0;
  color: var(--muted);
  font-size: 1.02rem;
  line-height: 1.65;
}
.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 24px;
}
.badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border: 1px solid var(--gold-line);
  background: rgba(197, 160, 89, .05);
  color: var(--gold-bright);
  font-family: var(--display);
  font-size: .58rem;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.badge.api-badge {
  border-color: rgba(112, 183, 255, .35);
  color: #a9d0ff;
  background: rgba(50, 110, 200, .08);
}
.notice {
  margin-top: 24px;
  padding: 16px 20px;
  border-left: 3px solid var(--gold);
  background: rgba(197, 160, 89, .06);
  color: #d8caa7;
  font-size: .88rem;
  line-height: 1.6;
}

/* Document Layout */
.doc-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 52px;
  padding: 48px 0 100px;
}

/* Sidebar TOC */
.toc {
  position: sticky;
  top: calc(var(--nav-height) + 20px);
  align-self: start;
  max-height: calc(100vh - var(--nav-height) - 40px);
  overflow-y: auto;
  padding: 22px 18px;
  border: 1px solid var(--gold-line);
  background: rgba(9, 14, 20, .85);
  backdrop-filter: blur(12px);
  clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 10px, 100% 100%, 10px 100%, 0 calc(100% - 10px));
  scrollbar-width: thin;
  scrollbar-color: rgba(197, 160, 89, .3) transparent;
}
.toc::-webkit-scrollbar { width: 4px; }
.toc::-webkit-scrollbar-thumb { background: rgba(197, 160, 89, .3); border-radius: 2px; }

.toc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(197, 160, 89, .2);
}
.toc-head strong {
  font-family: var(--display);
  font-size: .72rem;
  letter-spacing: .14em;
  color: var(--gold-bright);
  text-transform: uppercase;
}
.toc-count {
  font-family: var(--display);
  font-size: .6rem;
  color: var(--muted);
}

.toc-search-wrap {
  position: relative;
  margin-bottom: 14px;
}
.toc-filter {
  width: 100%;
  padding: 7px 10px 7px 28px;
  border: 1px solid rgba(197, 160, 89, .25);
  background: rgba(4, 7, 11, .7);
  color: var(--ivory);
  font-size: .76rem;
}
.toc-filter::placeholder { color: var(--faint); font-size: .72rem; }
.toc-filter:focus { border-color: var(--gold-bright); outline: none; }
.toc-search-wrap .search-icon {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--gold);
  font-size: .78rem;
  pointer-events: none;
}

.toc-links {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.toc a {
  display: block;
  padding: 7px 10px;
  border-left: 2px solid transparent;
  color: var(--muted);
  font-size: .8rem;
  line-height: 1.45;
  transition: color .15s, border-color .15s, background .15s, padding-left .15s;
}
.toc a:hover {
  color: var(--gold-bright);
  background: rgba(197, 160, 89, .06);
  padding-left: 12px;
}
.toc a.active {
  color: var(--gold-bright);
  border-left-color: var(--gold-bright);
  background: rgba(197, 160, 89, .1);
  padding-left: 12px;
  font-weight: 500;
}
.toc a.hidden { display: none; }

.toc-top-btn {
  width: 100%;
  margin-top: 18px;
  padding: 8px 12px;
  border: 1px dashed rgba(197, 160, 89, .25);
  background: transparent;
  color: var(--muted);
  font-family: var(--display);
  font-size: .6rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color .2s, border-color .2s, background .2s;
}
.toc-top-btn:hover {
  color: var(--gold-bright);
  border-color: var(--gold);
  background: rgba(197, 160, 89, .06);
}

/* Document Article */
.document { min-width: 0; }
.document section {
  scroll-margin-top: calc(var(--nav-height) + 24px);
  padding: 0 0 38px;
  margin: 0 0 38px;
  border-bottom: 1px solid rgba(197, 160, 89, .16);
}
.document section:last-child { border-bottom: 0; margin-bottom: 0; }
.document h2 {
  margin: 0 0 18px;
  font-size: clamp(1.4rem, 2.5vw, 1.85rem);
  color: #f2ede3;
  letter-spacing: .02em;
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.document h3 {
  margin: 28px 0 10px;
  font-size: 1.05rem;
  color: var(--gold-bright);
  letter-spacing: .02em;
}
.document p {
  margin: 0 0 14px;
  color: #c2bdb2;
  font-size: .94rem;
  line-height: 1.72;
}
.document p:last-child { margin-bottom: 0; }
.document ul, .document ol {
  margin: 0 0 18px;
  padding-left: 1.5rem;
  color: #c2bdb2;
  font-size: .94rem;
}
.document li { margin-bottom: 8px; line-height: 1.65; }
.document li::marker { color: var(--gold); }
.document strong { color: var(--ivory); font-weight: 600; }
.document .term {
  padding: 16px 20px;
  margin: 16px 0;
  border: 1px solid rgba(197, 160, 89, .22);
  border-left: 3px solid var(--gold);
  background: rgba(197, 160, 89, .04);
}

.loading-state, .error-state {
  margin: 32px auto;
  color: var(--muted);
  font-size: .92rem;
  text-align: center;
}
.loading-state { animation: loading 1.2s ease-in-out infinite alternate; }
.error-state { color: #e07b7b; }

@keyframes loading {
  from { opacity: .45; }
  to { opacity: 1; }
}

/* Footer */
.footer {
  padding: 36px 0 50px;
  border-top: 1px solid var(--gold-line);
  background: #020304;
  color: var(--muted);
  font-size: .78rem;
}
.footer .shell {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 20px;
}
.footer-left {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.footer-brand-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--display);
  font-size: .7rem;
  letter-spacing: .16em;
  color: var(--gold-bright);
}
.footer-brand-title img { width: 24px; height: 24px; }
.footer-disclaimer {
  color: var(--faint);
  font-size: .72rem;
  margin: 0;
}
.footer-links {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
}
.footer-links a {
  color: var(--muted);
  font-size: .78rem;
  transition: color .2s;
}
.footer-links a:hover { color: var(--gold-bright); }

/* Responsive */
@media (max-width: 900px) {
  .doc-layout {
    grid-template-columns: 1fr;
    gap: 32px;
  }
  .toc {
    position: relative;
    top: auto;
    max-height: 380px;
  }
}

@media (max-width: 760px) {
  :root { --nav-height: 58px; }
  .topbar .shell { gap: 10px; }
  .top-nav-link { display: none; }
  .hero-runes { display: none; }
  .hero { padding: 36px 0 30px; }
  h1 { font-size: 2rem; }
  .footer .shell { grid-template-columns: 1fr; }
}

/* Print */
@media print {
  body { background: #fff !important; color: #111 !important; }
  .page-grain, .topbar, .toc, .hero-runes, .footer-links { display: none !important; }
  .doc-layout { display: block !important; padding: 0 !important; }
  .document section { page-break-inside: avoid; border-bottom: 1px solid #ccc !important; }
  .document h2, .document h3, .document p, .document li { color: #111 !important; }
}
