/* Slime Login docs — light and dark are both defined up front, so the page never
   borrows a colour from whatever is behind it. */

:root {
  --bg: #ffffff;
  --bg-soft: #f6f8fa;
  --bg-code: #f4f6f8;
  --fg: #1b1f23;
  --fg-soft: #57606a;
  --border: #e1e4e8;
  --brand: #2f9e44;
  --brand-soft: #e9f7ec;
  --link: #2b8a3e;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06);
}

:root[data-theme="dark"],
:root[data-theme="auto"] {
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] { color-scheme: dark; }
  :root[data-theme="auto"] {
    --bg: #12161c;
    --bg-soft: #171c23;
    --bg-code: #1a1f27;
    --fg: #e6edf3;
    --fg-soft: #9aa7b2;
    --border: #262c35;
    --brand: #51cf66;
    --brand-soft: #16301d;
    --link: #69db7c;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12161c;
  --bg-soft: #171c23;
  --bg-code: #1a1f27;
  --fg: #e6edf3;
  --fg-soft: #9aa7b2;
  --border: #262c35;
  --brand: #51cf66;
  --brand-soft: #16301d;
  --link: #69db7c;
  --shadow: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ------------------------------------------------------------------ top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .7rem 1.2rem;
  background: var(--brand);
  color: #fff;
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: .5rem;
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  /* The logo is square with a transparent background, so it needs no plate
     behind it - just a fixed box so the topbar height never shifts. */
  width: 28px;
  height: 28px;
  object-fit: contain;
  flex-shrink: 0;
  display: block;
}

.menu-toggle, .theme-toggle {
  background: transparent;
  border: 0;
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
  padding: .2rem .4rem;
  border-radius: .3rem;
}
.menu-toggle:hover, .theme-toggle:hover { background: rgba(255, 255, 255, .18); }
.menu-toggle { display: none; }

/* ------------------------------------------------------------------ search */

.search { position: relative; margin-left: auto; width: min(22rem, 40vw); }

#search-input {
  width: 100%;
  padding: .45rem .8rem;
  border: 0;
  border-radius: .4rem;
  background: rgba(255, 255, 255, .2);
  color: #fff;
  font-size: .9rem;
}
#search-input::placeholder { color: rgba(255, 255, 255, .75); }
#search-input:focus { outline: 2px solid rgba(255, 255, 255, .6); background: rgba(255, 255, 255, .3); }

#search-results {
  position: absolute;
  top: 2.4rem;
  right: 0;
  width: min(30rem, 80vw);
  max-height: 60vh;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: .5rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
}

#search-results a {
  display: block;
  padding: .6rem .9rem;
  border-bottom: 1px solid var(--border);
  color: var(--fg);
}
#search-results a:last-child { border-bottom: 0; }
#search-results a:hover { background: var(--bg-soft); text-decoration: none; }
#search-results .r-title { font-weight: 600; color: var(--link); }
#search-results .r-text { font-size: .8rem; color: var(--fg-soft); }
#search-results .r-empty { padding: .8rem .9rem; color: var(--fg-soft); font-size: .85rem; }

/* ------------------------------------------------------------------ layout */

.layout {
  display: grid;
  grid-template-columns: 16rem minmax(0, 1fr) 14rem;
  gap: 2rem;
  max-width: 84rem;
  margin: 0 auto;
  padding: 1.6rem 1.2rem 4rem;
  align-items: start;
}

.sidebar { position: sticky; top: 4.2rem; max-height: calc(100vh - 5rem); overflow-y: auto; }
.sidebar ul { list-style: none; margin: 0 0 1.1rem; padding: 0; }
.sidebar li { margin: 0; }
.sidebar a {
  display: block;
  padding: .28rem .6rem;
  border-left: 2px solid transparent;
  color: var(--fg-soft);
  font-size: .9rem;
}
.sidebar a:hover { color: var(--fg); text-decoration: none; }
.sidebar a.active {
  color: var(--brand);
  border-left-color: var(--brand);
  background: var(--brand-soft);
  font-weight: 600;
}
.nav-section {
  margin: 1.1rem 0 .35rem;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--fg-soft);
}

.content { min-width: 0; }
.content--centered { max-width: 40rem; margin: 4rem auto; text-align: center; }

.toc { position: sticky; top: 4.2rem; font-size: .85rem; }
.toc-title {
  margin: 0 0 .4rem;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--fg-soft);
}
.toc ul { list-style: none; margin: 0; padding: 0 0 0 .2rem; }
.toc ul ul { padding-left: .8rem; }
.toc a { color: var(--fg-soft); display: block; padding: .15rem 0; }
.toc a:hover { color: var(--brand); text-decoration: none; }

/* ------------------------------------------------------------------ content */

.content h1 { font-size: 2rem; margin: 0 0 1.2rem; letter-spacing: -.02em; }
.content h2 {
  font-size: 1.35rem;
  margin: 2.2rem 0 .8rem;
  padding-bottom: .3rem;
  border-bottom: 1px solid var(--border);
}
.content h3 { font-size: 1.1rem; margin: 1.6rem 0 .6rem; }
.content p { margin: .8rem 0; }
.content li { margin: .25rem 0; }

.content .headerlink {
  margin-left: .4rem;
  opacity: 0;
  color: var(--fg-soft);
  font-weight: 400;
}
.content h1:hover .headerlink,
.content h2:hover .headerlink,
.content h3:hover .headerlink { opacity: 1; }

.content code {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: .25rem;
  padding: .1rem .35rem;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: .85em;
}

.content pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: .5rem;
  padding: .9rem 1rem;
  overflow-x: auto;          /* wide code scrolls inside itself, never the page */
  line-height: 1.45;
}
.content pre code { background: none; border: 0; padding: 0; font-size: .82rem; }

.copy-button {
  position: absolute;
  top: .4rem;
  right: .4rem;
  padding: .15rem .5rem;
  border: 1px solid var(--border);
  border-radius: .3rem;
  background: var(--bg);
  color: var(--fg-soft);
  font-size: .72rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s;
}
.content pre:hover .copy-button, .copy-button:focus { opacity: 1; }
.copy-button:hover { color: var(--brand); border-color: var(--brand); }

.content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: .88rem;
  display: block;
  overflow-x: auto;
}
.content th, .content td {
  border: 1px solid var(--border);
  padding: .45rem .7rem;
  text-align: left;
  vertical-align: top;
}
.content th { background: var(--bg-soft); font-weight: 700; }

.content blockquote {
  margin: 1rem 0;
  padding: .1rem 1rem;
  border-left: 3px solid var(--brand);
  background: var(--bg-soft);
  color: var(--fg-soft);
}

.content img { max-width: 100%; }
.content hr { border: 0; border-top: 1px solid var(--border); margin: 2rem 0; }

/* ------------------------------------------------------------------ admonitions */

.admonition, details.admonition {
  margin: 1.1rem 0;
  padding: .8rem 1rem;
  border: 1px solid var(--border);
  border-left: 4px solid var(--fg-soft);
  border-radius: .4rem;
  background: var(--bg-soft);
  font-size: .92rem;
}
.admonition > :first-child { margin-top: 0; }
.admonition > :last-child { margin-bottom: 0; }

.admonition-title {
  margin: -.8rem -1rem .6rem;
  padding: .45rem 1rem;
  font-weight: 700;
  font-size: .85rem;
  background: rgba(127, 127, 127, .12);
  border-radius: .3rem .3rem 0 0;
}
details.admonition > summary.admonition-title { cursor: pointer; margin-bottom: 0; }
details.admonition[open] > summary.admonition-title { margin-bottom: .6rem; }

.admonition.note, .admonition.info    { border-left-color: #4098d7; }
.admonition.tip, .admonition.success  { border-left-color: var(--brand); }
.admonition.warning                   { border-left-color: #e0a800; }
.admonition.danger, .admonition.failure, .admonition.error { border-left-color: #e03131; }
.admonition.question, .admonition.example { border-left-color: #8b5cf6; }

/* ------------------------------------------------------------------ tabs */

.tabbed-set { margin: 1.1rem 0; }
.tabbed-set > input { position: absolute; opacity: 0; pointer-events: none; }

.tabbed-labels {
  display: flex;
  flex-wrap: wrap;
  gap: .2rem;
  border-bottom: 1px solid var(--border);
}
.tabbed-labels > label {
  padding: .4rem .9rem;
  font-size: .85rem;
  font-weight: 600;
  color: var(--fg-soft);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tabbed-labels > label:hover { color: var(--fg); }

.tabbed-content { padding-top: .8rem; }
.tabbed-block { display: none; }
.tabbed-block > :first-child { margin-top: 0; }

/* Each checked radio lights its own label and shows its own block. */
.tabbed-set > input:nth-of-type(1):checked ~ .tabbed-labels > label:nth-of-type(1),
.tabbed-set > input:nth-of-type(2):checked ~ .tabbed-labels > label:nth-of-type(2),
.tabbed-set > input:nth-of-type(3):checked ~ .tabbed-labels > label:nth-of-type(3),
.tabbed-set > input:nth-of-type(4):checked ~ .tabbed-labels > label:nth-of-type(4),
.tabbed-set > input:nth-of-type(5):checked ~ .tabbed-labels > label:nth-of-type(5) {
  color: var(--brand);
  border-bottom-color: var(--brand);
}
.tabbed-set > input:nth-of-type(1):checked ~ .tabbed-content > .tabbed-block:nth-of-type(1),
.tabbed-set > input:nth-of-type(2):checked ~ .tabbed-content > .tabbed-block:nth-of-type(2),
.tabbed-set > input:nth-of-type(3):checked ~ .tabbed-content > .tabbed-block:nth-of-type(3),
.tabbed-set > input:nth-of-type(4):checked ~ .tabbed-content > .tabbed-block:nth-of-type(4),
.tabbed-set > input:nth-of-type(5):checked ~ .tabbed-content > .tabbed-block:nth-of-type(5) {
  display: block;
}

/* ------------------------------------------------------------------ landing page bits */

.slime-hero { padding: 1.4rem 0 .6rem; text-align: center; border-bottom: 1px solid var(--border); margin-bottom: 1.6rem; }
.slime-hero h1 { margin-bottom: .4rem; }
.slime-hero p { color: var(--fg-soft); max-width: 38rem; margin: 0 auto 1rem; }

.slime-badges { display: flex; flex-wrap: wrap; gap: .4rem; justify-content: center; }
.slime-badge {
  padding: .18rem .7rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  background: var(--brand);
  color: #fff;
}
.slime-badge--muted { background: var(--bg-soft); color: var(--fg-soft); border: 1px solid var(--border); }

.slime-grid, .grid.cards > ul, .grid.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 1rem;
  margin: 1.4rem 0;
  padding: 0;
  list-style: none;
}
.slime-card, .grid.cards > ul > li {
  border: 1px solid var(--border);
  border-radius: .5rem;
  padding: 1rem 1.1rem;
  transition: border-color .2s, transform .2s;
}
.slime-card:hover, .grid.cards > ul > li:hover { border-color: var(--brand); transform: translateY(-2px); }
.slime-card h3, .grid.cards > ul > li > p:first-child { margin-top: 0; font-size: .95rem; font-weight: 700; }
.slime-card p { margin: 0; font-size: .85rem; color: var(--fg-soft); }

.md-button {
  display: inline-block;
  margin: .3rem .4rem .3rem 0;
  padding: .45rem 1rem;
  border: 1px solid var(--brand);
  border-radius: .4rem;
  color: var(--brand);
  font-size: .88rem;
  font-weight: 600;
}
.md-button:hover { background: var(--brand); color: #fff; text-decoration: none; }
.md-button--primary { background: var(--brand); color: #fff; }
.md-button--primary:hover { filter: brightness(1.08); }

/* ------------------------------------------------------------------ footer */

.footer {
  border-top: 1px solid var(--border);
  padding: 1.2rem;
  text-align: center;
  color: var(--fg-soft);
  font-size: .82rem;
}

.nav-backdrop { display: none; }
.drawer-head { display: none; }
.drawer-toc { display: none; }
.search-toggle { display: none; }

/* ------------------------------------------------------------------ small screens */

@media (max-width: 1100px) {
  .layout { grid-template-columns: 15rem minmax(0, 1fr); }
  .toc { display: none; }
}

@media (max-width: 800px) {
  /* ---- top bar ---------------------------------------------------------- */

  .topbar {
    flex-wrap: wrap;
    gap: .25rem;
    padding: .35rem .5rem;
    padding-left: max(.5rem, env(safe-area-inset-left));
    padding-right: max(.5rem, env(safe-area-inset-right));
  }

  /* 44px is the smallest target a thumb hits reliably; these were about 30. */
  .menu-toggle,
  .theme-toggle,
  .search-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: .5rem;
    font-size: 1.15rem;
    -webkit-tap-highlight-color: transparent;
  }
  .menu-toggle:active,
  .theme-toggle:active,
  .search-toggle:active { background: rgba(255, 255, 255, .2); }

  .brand { margin-right: auto; min-width: 0; }
  /* The name fits again now that search has collapsed to an icon. */
  .brand span:not(.brand-mark) {
    display: block;
    font-size: .95rem;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Search gets its own full-width row instead of fighting for space. */
  .search {
    display: none;
    order: 10;
    flex-basis: 100%;
    width: 100%;
    margin: 0 0 .3rem;
  }
  .topbar.search-open .search { display: block; }
  #search-input { padding: .6rem .8rem; font-size: 1rem; }
  #search-results {
    top: 3rem;
    right: 0;
    left: 0;
    width: auto;
    max-height: 65vh;
  }
  #search-results a { padding: .8rem .9rem; }

  /* ---- the drawer ------------------------------------------------------- */

  .layout { grid-template-columns: minmax(0, 1fr); padding-top: 1rem; }

  .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(0, 0, 0, .5);
    opacity: 0;
    visibility: hidden;
    transition: opacity .2s ease, visibility .2s ease;
  }
  body.nav-open .nav-backdrop { opacity: 1; visibility: visible; }

  /* Off-canvas rather than inserted above the article: opening the menu used
     to push the page down and leave the reader staring at empty space. */
  .sidebar {
    display: block;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 50;
    width: min(20rem, 84vw);
    max-height: none;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    background: var(--bg);
    border-right: 1px solid var(--border);
    box-shadow: 0 0 40px rgba(0, 0, 0, .3);
    padding: 0 .4rem max(1rem, env(safe-area-inset-bottom));
    padding-left: max(.4rem, env(safe-area-inset-left));
    transform: translateX(-100%);
    transition: transform .24s ease;
  }
  .sidebar.open { transform: translateX(0); }

  .drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 1;
    margin: 0 -.4rem .4rem;
    padding: .35rem .5rem;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
  }
  .drawer-title {
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--fg-soft);
  }
  .drawer-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: .5rem;
    background: transparent;
    color: var(--fg);
    font-size: 1.1rem;
    cursor: pointer;
  }
  .drawer-close:active { background: var(--bg-soft); }

  .sidebar a {
    padding: .7rem .7rem;
    border-left-width: 3px;
    border-radius: .3rem;
    font-size: .98rem;
  }
  .sidebar ul { margin-bottom: .5rem; }
  .nav-section { margin: 1rem 0 .3rem; padding: 0 .7rem; }

  .drawer-toc { display: block; }
  .drawer-toc:not(:empty) {
    margin-top: .8rem;
    padding-top: .3rem;
    border-top: 1px solid var(--border);
  }
  .drawer-toc ul { list-style: none; margin: 0 0 .4rem; padding: 0; }
  .drawer-toc ul ul { padding-left: .8rem; }
  .drawer-toc .toc-title {
    margin: .8rem 0 .3rem;
    padding: 0 .7rem;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--fg-soft);
  }
  .drawer-toc a {
    display: block;
    padding: .65rem .7rem;
    border-left: 2px solid transparent;
    color: var(--fg-soft);
    font-size: .92rem;
  }

  /* A phone has no hover, so a hover-only copy button is simply invisible. */
  .copy-button { opacity: 1; padding: .35rem .6rem; font-size: .75rem; }

  body.nav-open { overflow: hidden; }
}

/* Someone who asked for less motion gets the drawer without the slide. */
@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .nav-backdrop { transition: none; }
}
