/* docs.shonin.ai: same tokens as the landing (app/landing/layout.html), light and dark.
   The theme follows the system, unless the viewer chose one (data-theme on <html>). */
:root {
  --bg: #f9fafb; --surface: #ffffff; --text: #111827; --muted: #4b5563;
  --border: #e5e7eb; --accent: #0e7c66; --mint: #66e0be; --mark: #111827;
  --code-bg: #f3f4f6; --highlight: #e7f6f1;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --topbar: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1120; --surface: #111827; --text: #f9fafb; --muted: #9ca3af; --border: #273244;
    --accent: #66e0be; --mark: #1f2937; --code-bg: #161f30; --highlight: #12332c;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1120; --surface: #111827; --text: #f9fafb; --muted: #9ca3af; --border: #273244;
  --accent: #66e0be; --mark: #1f2937; --code-bg: #161f30; --highlight: #12332c;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--topbar) + 16px); }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.65 var(--font); }
a { color: var(--accent); }
a:focus-visible, button:focus-visible, input:focus-visible, pre:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: 16px; top: -48px; background: var(--surface); color: var(--text); padding: 8px 12px; border-radius: 6px; z-index: 20; }
.skip:focus { top: 8px; }

/* ---- Top bar */
.topbar { position: sticky; top: 0; z-index: 10; height: var(--topbar); display: flex; align-items: center; gap: 16px; padding: 0 16px; background: var(--bg); border-bottom: 1px solid var(--border); }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; font-size: 1.25rem; flex: none; }
.brand svg { width: 32px; height: 32px; }
.brand-docs { font-weight: 500; color: var(--muted); }
.topnav { display: flex; gap: 20px; margin-left: auto; }
.topnav a { color: var(--text); text-decoration: none; font-weight: 500; white-space: nowrap; }
.topnav a:hover { text-decoration: underline; text-underline-offset: 4px; }
.icon-button { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); cursor: pointer; flex: none; }
.icon-button svg { width: 20px; height: 20px; }
.menu-button { display: none; }
/* The icon shows the theme you switch to */
.theme-button .icon-sun { display: none; }
:root[data-effective-theme="dark"] .theme-button .icon-sun { display: block; }
:root[data-effective-theme="dark"] .theme-button .icon-moon { display: none; }

/* ---- Search */
.search { position: relative; flex: 1; max-width: 420px; margin-left: 24px; }
.search input { width: 100%; height: 40px; padding: 0 36px 0 12px; font: inherit; font-size: .95rem; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.search input::placeholder { color: var(--muted); }
.search input:focus + .search-key, .search input:not(:placeholder-shown) + .search-key { display: none; }
.search-key { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font: .8rem var(--mono); color: var(--muted); border: 1px solid var(--border); border-radius: 4px; padding: 0 6px; }
.search-results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; max-height: 70vh; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 12px 32px rgb(0 0 0 / .18); padding: 6px; margin: 0; list-style: none; }
.search-results a { display: block; padding: 8px 10px; border-radius: 6px; color: var(--text); text-decoration: none; }
.search-results a[aria-selected="true"], .search-results a:hover { background: var(--highlight); }
.search-results .result-title { font-weight: 600; }
.search-results .result-page { color: var(--muted); font-size: .85rem; }
.search-results .result-text { display: block; color: var(--muted); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-results mark { background: none; color: var(--accent); font-weight: 600; }
.search-results .empty { padding: 10px; color: var(--muted); }

/* ---- Three columns: sidebar, content, "On this page" */
.shell { display: grid; grid-template-columns: 260px minmax(0, 1fr) 220px; max-width: 1360px; margin: 0 auto; }
.sidebar, .toc { position: sticky; top: var(--topbar); align-self: start; max-height: calc(100vh - var(--topbar)); overflow-y: auto; padding: 24px 16px; font-size: .95rem; }
.sidebar { border-right: 1px solid var(--border); }
.sidebar ul, .toc ul { list-style: none; margin: 0 0 20px; padding: 0; }
.sidebar a { display: block; padding: 5px 10px; border-radius: 6px; color: var(--muted); text-decoration: none; }
.sidebar a:hover { color: var(--text); background: var(--surface); }
.sidebar a[aria-current="page"] { color: var(--text); background: var(--highlight); font-weight: 600; }
.nav-title { margin: 0 0 6px; padding: 0 10px; font-size: .75rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.toc { font-size: .875rem; }
.toc .nav-title { padding: 0; }
.toc li { margin: 0 0 6px; }
.toc .toc-3 { padding-left: 12px; }
.toc a { color: var(--muted); text-decoration: none; }
.toc a:hover, .toc a[aria-current="true"] { color: var(--accent); }

.content { padding: 32px 48px 64px; min-width: 0; outline: none; }
.prose { max-width: 760px; }
.eyebrow { margin: 0 0 4px; font-size: .8rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); }
.prose h1 { font-size: clamp(1.9rem, 4vw, 2.4rem); line-height: 1.2; letter-spacing: -.02em; margin: 0 0 16px; }
.prose h2 { font-size: 1.5rem; line-height: 1.3; margin: 40px 0 12px; padding-top: 8px; }
.prose h3 { font-size: 1.15rem; margin: 28px 0 8px; }
.prose h2, .prose h3 { position: relative; }
.anchor { position: absolute; left: -1.1em; padding-right: .3em; color: var(--muted); text-decoration: none; opacity: 0; }
h2:hover .anchor, h3:hover .anchor, .anchor:focus { opacity: 1; }
.prose p, .prose ul, .prose ol { margin: 0 0 16px; }
.prose li { margin: 4px 0; }
.prose li > p { margin: 0 0 8px; }
.prose code { font: .88em var(--mono); background: var(--code-bg); border: 1px solid var(--border); border-radius: 4px; padding: .1em .35em; overflow-wrap: anywhere; }
.code { position: relative; margin: 0 0 16px; }
.code pre { margin: 0; padding: 14px 16px; overflow-x: auto; background: var(--code-bg); border: 1px solid var(--border); border-radius: 8px; font: .88rem/1.6 var(--mono); }
.code pre code { background: none; border: 0; padding: 0; font: inherit; overflow-wrap: normal; }
.copy { position: absolute; top: 8px; right: 8px; font: .8rem var(--font); color: var(--muted); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 2px 10px; cursor: pointer; opacity: 0; }
.code:hover .copy, .copy:focus-visible, .copy[data-copied] { opacity: 1; }
@media (hover: none) { .copy { opacity: 1; } }
.table-wrap { overflow-x: auto; margin: 0 0 16px; }
.prose table { border-collapse: collapse; width: 100%; font-size: .95rem; }
.prose th, .prose td { text-align: left; vertical-align: top; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.prose th { font-weight: 600; }
.prose blockquote { margin: 0 0 16px; padding: 4px 16px; border-left: 3px solid var(--accent); color: var(--muted); }

.page-tools { max-width: 760px; margin-top: 40px; font-size: .9rem; }
.page-tools a { color: var(--muted); }
.pager { max-width: 760px; display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 24px; }
.pager a { display: block; padding: 14px 16px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); text-decoration: none; font-weight: 600; }
.pager a:hover { border-color: var(--accent); }
.pager span { display: block; font-size: .8rem; font-weight: 500; color: var(--muted); }
.pager-next { text-align: right; grid-column: 2; }

.footer { border-top: 1px solid var(--border); padding: 24px 16px 40px; color: var(--muted); font-size: .85rem; text-align: center; }
.footer a { color: var(--muted); }

/* ---- Narrower screens: no "On this page", then the sidebar becomes a drawer */
@media (max-width: 1180px) {
  .shell { grid-template-columns: 240px minmax(0, 1fr); }
  .toc { display: none; }
}
@media (max-width: 860px) {
  .menu-button { display: inline-flex; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; top: var(--topbar); left: 0; bottom: 0; width: min(300px, 85vw); max-height: none; background: var(--bg); z-index: 9; transform: translateX(-100%); transition: transform .2s ease; visibility: hidden; }
  .sidebar.open { transform: none; visibility: visible; box-shadow: 0 0 0 100vmax rgb(0 0 0 / .35); }
  .content { padding: 24px 16px 48px; }
  .search { margin-left: 0; }
  .search-key { display: none; }
}
/* Phones: menu, brand, links and theme on the first row, search on its own row */
@media (max-width: 600px) {
  :root { --topbar: 112px; }
  .topbar { flex-wrap: wrap; height: auto; min-height: var(--topbar); gap: 8px 12px; padding: 8px 16px; align-content: center; }
  .search { order: 5; flex: 1 0 100%; max-width: none; }
  .brand span:not(.brand-docs) { display: none; }
  .topnav { gap: 14px; font-size: .95rem; }
  .search-results { max-height: 60vh; }
  .pager { grid-template-columns: 1fr; }
  .pager-next { grid-column: 1; }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }
