/* 20dragons documentation — base styles.
   Light/dark via CSS custom properties, system preference + manual toggle
   (persisted in localStorage, see assets/js/main.js). Keep this file
   dependency-free and reasonably small. */

:root {
  --color-brand-gold: #b8892c;
  --color-brand-green: #146c43;

  --bg: #ffffff;
  --bg-raised: #f6f7f5;
  --bg-sidebar: #fafaf8;
  --border: #e3e6e1;
  --text: #1a1f1b;
  --text-secondary: #565f58;
  --link: #0f6b3f;
  --link-hover: #0b5230;
  --focus-ring: #1a73e8;

  --code-bg: #f3f4f1;
  --code-text: #24291f;
  --code-border: #dfe2db;

  --callout-note-bg: #eef6f1;
  --callout-note-border: #146c43;
  --callout-tip-bg: #fbf6e8;
  --callout-tip-border: #b8892c;
  --callout-important-bg: #eaf1fb;
  --callout-important-border: #1a5fb4;
  --callout-warning-bg: #fbecec;
  --callout-warning-border: #c22b2b;

  --header-h: 64px;
  --max-article-width: 46rem;

  color-scheme: light;
}

:root[data-theme="dark"],
:root:not([data-theme="light"]):not([data-theme="dark"]) {
  /* placeholder — real dark values applied below via media query and
     [data-theme="dark"] so both "system" and manual dark mode work. */
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1310;
    --bg-raised: #151b17;
    --bg-sidebar: #121714;
    --border: #263029;
    --text: #edf1ee;
    --text-secondary: #a8b3ac;
    --link: #57d99a;
    --link-hover: #7fe4b3;
    --focus-ring: #7fb8ff;

    --code-bg: #12241a;
    --code-text: #dfe8e1;
    --code-border: #23392c;

    --callout-note-bg: #12271c;
    --callout-note-border: #57d99a;
    --callout-tip-bg: #2a220f;
    --callout-tip-border: #d9ab4f;
    --callout-important-bg: #10203a;
    --callout-important-border: #6ea8f0;
    --callout-warning-bg: #2c1414;
    --callout-warning-border: #e37a7a;

    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0e1310;
  --bg-raised: #151b17;
  --bg-sidebar: #121714;
  --border: #263029;
  --text: #edf1ee;
  --text-secondary: #a8b3ac;
  --link: #57d99a;
  --link-hover: #7fe4b3;
  --focus-ring: #7fb8ff;

  --code-bg: #12241a;
  --code-text: #dfe8e1;
  --code-border: #23392c;

  --callout-note-bg: #12271c;
  --callout-note-border: #57d99a;
  --callout-tip-bg: #2a220f;
  --callout-tip-border: #d9ab4f;
  --callout-important-bg: #10203a;
  --callout-important-border: #6ea8f0;
  --callout-warning-bg: #2c1414;
  --callout-warning-border: #e37a7a;

  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.65 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow-x: hidden;
}

a { color: var(--link); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--link) 40%, transparent); text-underline-offset: 0.15em; }
a:hover { color: var(--link-hover); }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute;
  left: 0.5rem; top: -3rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.5rem 0.9rem;
  border-radius: 0.4rem;
  z-index: 100;
  transition: top 0.15s ease;
}
.skip-link:focus { top: 0.5rem; }

/* ---- Header ---------------------------------------------------------- */

.site-header {
  position: sticky; top: 0; z-index: 30;
  height: var(--header-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.site-header-inner {
  height: 100%;
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0 1rem;
  max-width: 90rem;
  margin: 0 auto;
}
.nav-toggle {
  display: none;
  flex-direction: column; justify-content: center; gap: 4px;
  width: 40px; height: 40px;
  background: transparent; border: 1px solid var(--border); border-radius: 0.4rem;
  cursor: pointer;
}
.nav-toggle-bar { width: 18px; height: 2px; background: var(--text); margin: 0 auto; }

.site-logo {
  display: flex; align-items: center; gap: 0.6rem;
  text-decoration: none; color: var(--text);
  flex-shrink: 0;
}
.site-logo img { height: 32px; width: auto; display: block; }
.site-logo-label {
  font-weight: 600; font-size: 0.95rem;
  color: var(--text-secondary);
  border-left: 1px solid var(--border);
  padding-left: 0.6rem;
}

.site-search { position: relative; flex: 1 1 auto; max-width: 26rem; margin-left: 1rem; }
.site-search-input {
  width: 100%;
  padding: 0.5rem 0.8rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text);
  font-size: 0.95rem;
}
.site-search-results {
  position: absolute; top: calc(100% + 0.4rem); left: 0; right: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  box-shadow: 0 12px 28px rgba(0,0,0,0.16);
  max-height: 22rem; overflow-y: auto;
  z-index: 40;
}
.site-search-results a {
  display: block;
  padding: 0.6rem 0.8rem;
  text-decoration: none;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.site-search-results a:last-child { border-bottom: none; }
.site-search-results a:hover, .site-search-results a.is-active-result { background: var(--bg-raised); }
.site-search-result-section { display: block; font-size: 0.75rem; color: var(--text-secondary); }
.site-search-result-snippet { display: block; font-size: 0.85rem; color: var(--text-secondary); margin-top: 0.15rem; }
.site-search-empty { padding: 0.8rem; color: var(--text-secondary); font-size: 0.9rem; }

.site-header-actions { display: flex; align-items: center; gap: 0.75rem; margin-left: auto; flex-shrink: 0; }
.header-link { font-size: 0.9rem; white-space: nowrap; }
.lang-select {
  background: var(--bg-raised); color: var(--text);
  border: 1px solid var(--border); border-radius: 0.4rem;
  padding: 0.35rem 0.5rem; font-size: 0.85rem;
}
.theme-toggle {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-raised); border: 1px solid var(--border); border-radius: 50%;
  cursor: pointer; color: var(--text);
}
.theme-toggle .icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

/* ---- Shell / layout ---------------------------------------------------- */

.docs-shell {
  max-width: 90rem;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 16rem minmax(0, 1fr);
  align-items: start;
}

.sidebar {
  position: sticky; top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 1.25rem 1rem 2rem;
}
.sidebar-sections { list-style: none; margin: 0; padding: 0; }
.sidebar-section { margin-bottom: 1.25rem; }
.sidebar-section-title {
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-secondary); margin: 0 0 0.4rem;
}
.sidebar-pages { list-style: none; margin: 0; padding: 0; }
.sidebar-link {
  display: block;
  padding: 0.4rem 0.6rem;
  border-radius: 0.4rem;
  color: var(--text);
  text-decoration: none;
  font-size: 0.92rem;
}
.sidebar-link:hover { background: var(--bg-raised); }
.sidebar-link.is-active {
  background: color-mix(in srgb, var(--link) 14%, transparent);
  color: var(--link);
  font-weight: 600;
}
.sidebar-backdrop { display: none; }

.article-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 14rem;
  gap: 2rem;
  padding: 2rem 1.5rem 4rem;
  align-items: start;
}
.article { max-width: var(--max-article-width); min-width: 0; }

.breadcrumbs { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 0.75rem; }
.breadcrumbs a { color: var(--text-secondary); }
.breadcrumbs span[aria-hidden] { margin: 0 0.35rem; }

.article-title { font-size: 2rem; line-height: 1.25; margin: 0 0 1.25rem; }

.article-body h2 { font-size: 1.4rem; margin: 2.2rem 0 0.75rem; scroll-margin-top: calc(var(--header-h) + 1rem); }
.article-body h3 { font-size: 1.15rem; margin: 1.8rem 0 0.6rem; scroll-margin-top: calc(var(--header-h) + 1rem); }
.article-body p { margin: 0 0 1rem; }
.article-body ul, .article-body ol { margin: 0 0 1rem; padding-left: 1.4rem; }
.article-body li { margin-bottom: 0.35rem; }
.article-body img { max-width: 100%; height: auto; border-radius: 0.5rem; }

.article-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 0 0 1.25rem;
  display: block;
  overflow-x: auto;
  font-size: 0.92rem;
}
.article-body th, .article-body td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.7rem;
  text-align: left;
  vertical-align: top;
}
.article-body th { background: var(--bg-raised); }

.article-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--code-bg);
  color: var(--code-text);
  padding: 0.1rem 0.35rem;
  border-radius: 0.3rem;
  font-size: 0.88em;
}

.code-block { position: relative; margin: 0 0 1.25rem; }
.code-block pre {
  background: var(--code-bg);
  color: var(--code-text);
  border: 1px solid var(--code-border);
  border-radius: 0.6rem;
  padding: 1rem 1rem;
  overflow-x: auto;
  font-size: 0.88rem;
  line-height: 1.55;
  margin: 0;
}
.code-block pre code { background: none; padding: 0; border-radius: 0; }
.code-block-lang {
  position: absolute; top: 0.5rem; right: 3rem;
  font-size: 0.72rem; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.code-copy-btn {
  position: absolute; top: 0.45rem; right: 0.5rem;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 0.35rem;
  font-size: 0.72rem; padding: 0.25rem 0.5rem;
  cursor: pointer;
}
.code-copy-btn:hover { background: var(--bg-raised); }

.callout {
  border-left: 4px solid;
  border-radius: 0.4rem;
  padding: 0.85rem 1rem;
  margin: 0 0 1.25rem;
}
.callout p:last-child { margin-bottom: 0; }
.callout-label {
  font-weight: 700; text-transform: uppercase;
  font-size: 0.75rem; letter-spacing: 0.04em;
  margin: 0 0 0.35rem;
}
.callout-note { background: var(--callout-note-bg); border-color: var(--callout-note-border); }
.callout-tip { background: var(--callout-tip-bg); border-color: var(--callout-tip-border); }
.callout-important { background: var(--callout-important-bg); border-color: var(--callout-important-border); }
.callout-warning { background: var(--callout-warning-bg); border-color: var(--callout-warning-border); }

blockquote:not(.callout) {
  margin: 0 0 1.25rem; padding-left: 1rem;
  border-left: 3px solid var(--border);
  color: var(--text-secondary);
}

.pager {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1rem;
  margin-top: 2.5rem; padding-top: 1.5rem; border-top: 1px solid var(--border);
}
.pager-link {
  display: block; text-decoration: none;
  border: 1px solid var(--border); border-radius: 0.6rem;
  padding: 0.75rem 0.9rem; color: var(--text);
}
.pager-next { text-align: right; }
.pager-direction { display: block; font-size: 0.75rem; color: var(--text-secondary); }
.pager-title { display: block; font-weight: 600; margin-top: 0.15rem; }

.toc { position: sticky; top: calc(var(--header-h) + 1.5rem); font-size: 0.85rem; }
.toc-title { font-weight: 600; margin: 0 0 0.5rem; color: var(--text-secondary); text-transform: uppercase; font-size: 0.72rem; letter-spacing: 0.04em; }
.toc-list { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--border); }
.toc-list li { margin: 0; }
.toc-list a {
  display: block; padding: 0.3rem 0 0.3rem 0.8rem;
  text-decoration: none; color: var(--text-secondary);
  border-left: 2px solid transparent; margin-left: -1px;
}
.toc-list a:hover { color: var(--link); }
.toc-list a.is-active { color: var(--link); border-left-color: var(--link); }
.toc-level-3 a { padding-left: 1.5rem; font-size: 0.82em; }

.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem 1.5rem 2.5rem;
  color: var(--text-secondary);
  font-size: 0.85rem;
}
.site-footer-inner { max-width: 90rem; margin: 0 auto; display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; justify-content: space-between; }
.site-footer-links { display: flex; gap: 1rem; }

/* ---- Responsive --------------------------------------------------------- */

@media (max-width: 1100px) {
  .article-wrap { grid-template-columns: minmax(0, 1fr); }
  .toc { display: none; }
}

@media (max-width: 860px) {
  .nav-toggle { display: flex; }
  .site-logo-label { display: none; }
  .site-search { display: none; }

  .docs-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: var(--header-h); left: 0; bottom: 0;
    width: 17rem; max-width: 85vw;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 35;
    box-shadow: 8px 0 24px rgba(0,0,0,0.15);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .sidebar-backdrop {
    display: block;
    position: fixed; inset: var(--header-h) 0 0 0;
    background: rgba(0,0,0,0.35);
    z-index: 32;
  }
  .article-wrap { padding: 1.5rem 1rem 3rem; }
  .article-title { font-size: 1.6rem; }
  .pager { grid-template-columns: 1fr; }
}
