/* Koyo docs shared stylesheet. Light and dark themes are defined entirely
   through CSS custom properties. The theme applied to <html data-theme> is
   decided by docs/theme.js before first paint. No emojis, no hard coded
   colors in rules below. One deliberate corner radius used everywhere. */

:root {
  --bg: #ffffff;
  --bg-soft: #f6f6fa;
  --surface: #ffffff;
  --surface-alt: #f1f1f7;
  --text: #191927;
  --text-muted: #56566b;
  --text-faint: #84849a;
  --border: #e4e4ee;
  --border-strong: #cfcfdd;

  --brand: #1800ad;
  --brand-hover: #13008a;
  --brand-contrast: #ffffff;
  --brand-soft: #edeaff;
  --link: #14009c;
  --link-hover: #100078;

  --code-bg: #f4f4f9;
  --code-text: #24243a;
  --shadow: 0 1px 2px rgba(20, 10, 60, 0.06), 0 8px 24px rgba(20, 10, 60, 0.08);
  --focus: rgba(24, 0, 173, 0.28);

  --syntax-keyword: #7c3aed;
  --syntax-string: #0a7a3c;
  --syntax-number: #b45309;
  --syntax-title: #1e40af;
  --syntax-attr: #0f766e;
  --syntax-comment: #6b7280;
  --syntax-builtin: #9d174d;
  --syntax-punct: #4b5563;

  --radius: 10px;
  --font:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono",
    monospace;
}

html[data-theme="dark"] {
  --bg: #0f0f18;
  --bg-soft: #131320;
  --surface: #15151f;
  --surface-alt: #1a1a26;
  --text: #ecedf5;
  --text-muted: #a3a4ba;
  --text-faint: #7b7c92;
  --border: #26263a;
  --border-strong: #34344c;

  --brand: #1800ad;
  --brand-hover: #5947f0;
  --brand-contrast: #ffffff;
  --brand-soft: rgba(24, 0, 173, 0.35);
  --link: #9b8dff;
  --link-hover: #b3a7ff;

  --code-bg: #171722;
  --code-text: #e6e6f3;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 32px rgba(0, 0, 0, 0.5);
  --focus: rgba(155, 141, 255, 0.4);

  --syntax-keyword: #b39cff;
  --syntax-string: #7ee2a8;
  --syntax-number: #ffce6b;
  --syntax-title: #9cc3ff;
  --syntax-attr: #6fd7cf;
  --syntax-comment: #8a8ba0;
  --syntax-builtin: #f2a7c0;
  --syntax-punct: #c7c8da;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--link);
  text-decoration: none;
}

a:hover {
  color: var(--link-hover);
  text-decoration: underline;
}

h1,
h2,
h3,
h4 {
  line-height: 1.25;
  margin: 0 0 0.5em;
}

h1 {
  font-size: 2rem;
  letter-spacing: -0.02em;
}

h2 {
  font-size: 1.35rem;
  letter-spacing: -0.01em;
}

h3 {
  font-size: 1.05rem;
}

p {
  margin: 0 0 1rem;
}

code,
kbd,
pre {
  font-family: var(--mono);
}

code {
  background: var(--code-bg);
  color: var(--code-text);
  padding: 0.12em 0.15em;
  border-radius: 6px;
  font-size: 0.88em;
  border: 1px solid var(--border);
}

pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  overflow-x: auto;
  line-height: 1.6;
  margin: 0 0 1.2rem;
  position: relative;
}

pre code {
  background: none;
  border: 0;
  padding: 0;
  font-size: 0.9rem;
}

.copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  height: 26px;
  padding: 0 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text-faint);
  font-size: 0.72rem;
  font-family: var(--font);
  line-height: 1;
}

.copy-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.copy-btn.copied {
  color: var(--link);
  border-color: var(--link);
}

/* Highlight.js token colors follow the theme's variables. */

.hljs-comment,
.hljs-quote {
  color: var(--syntax-comment);
  font-style: italic;
}

.hljs-keyword,
.hljs-selector-tag,
.hljs-literal,
.hljs-doctag,
.hljs-meta .hljs-keyword,
.hljs-section {
  color: var(--syntax-keyword);
}

.hljs-string,
.hljs-regexp,
.hljs-addition,
.hljs-meta .hljs-string {
  color: var(--syntax-string);
}

.hljs-number,
.hljs-symbol,
.hljs-bullet,
.hljs-attribute,
.hljs-link,
.hljs-variable.constant_,
.hljs-meta .hljs-number {
  color: var(--syntax-number);
}

.hljs-title,
.hljs-title.function_,
.hljs-title.class_,
.hljs-name {
  color: var(--syntax-title);
}

.hljs-attr,
.hljs-attribute,
.hljs-tag .hljs-attr,
.hljs-selector-class,
.hljs-selector-id,
.hljs-selector-attr,
.hljs-selector-pseudo {
  color: var(--syntax-attr);
}

.hljs-built_in,
.hljs-type,
.hljs-template-tag,
.hljs-template-variable,
.hljs-variable,
.hljs-property {
  color: var(--syntax-builtin);
}

.hljs-title,
.hljs-operator,
.hljs-punctuation,
.hljs-meta,
.hljs-deletion,
.hljs-emphasis {
  color: var(--syntax-punct);
}

.hljs-emphasis {
  font-style: italic;
}

.hljs-strong {
  font-weight: 700;
}

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

/* Header */

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 1.25rem;
  height: 58px;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 700;
  color: var(--text);
  font-size: 1.02rem;
  letter-spacing: -0.01em;
  margin-right: 0.5rem;
}

.brand:hover {
  color: var(--text);
  text-decoration: none;
}

.brand img {
  width: 26px;
  height: 26px;
  border-radius: 7px;
}

.header-spacer {
  flex: 1;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  color: var(--text-muted);
  border: 1px solid transparent;
}

.icon-btn:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.search-button {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  height: 38px;
  padding: 0 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text-muted);
  font-size: 0.9rem;
  min-width: 210px;
}

.search-button:hover {
  border-color: var(--border-strong);
  background: var(--bg-soft);
  color: var(--text);
}

.kbd {
  display: inline-block;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 0 0.35em;
  font-size: 0.72rem;
  color: var(--text-faint);
  background: var(--surface);
  margin-left: auto;
  white-space: nowrap;
}

.nav-toggle {
  display: none;
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  color: var(--text-muted);
  align-items: center;
  justify-content: center;
}

.nav-toggle:hover {
  background: var(--surface-alt);
  color: var(--text);
}

/* Shell grid */

.shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 3rem;
}

.sidebar {
  position: sticky;
  top: 74px;
  align-self: start;
  max-height: calc(100vh - 90px);
  overflow-y: auto;
  padding-right: 0.25rem;
}

.nav-group {
  margin-bottom: 1.5rem;
}

.nav-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin: 0 0 0.5rem;
  padding: 0 0.6rem;
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-list a {
  display: block;
  padding: 0.32rem 0.6rem;
  border-radius: 7px;
  color: var(--text-muted);
  font-size: 0.93rem;
  line-height: 1.4;
}

.nav-list a:hover {
  background: var(--surface-alt);
  color: var(--text);
  text-decoration: none;
}

.nav-list a.active {
  background: var(--brand-soft);
  color: var(--brand-hover);
  font-weight: 600;
}

/* Content */

.content {
  min-width: 0;
}

.content article {
  max-width: 780px;
}

.lede {
  font-size: 1.15rem;
  color: var(--text-muted);
}

.content section {
  margin: 2.4rem 0 0;
  scroll-margin-top: 80px;
}

.content h2 {
  padding-top: 0.4rem;
}

.content h2 a.anchor {
  color: var(--text);
}

.content h2 a.anchor:hover {
  color: var(--link);
  text-decoration: none;
}

.content h2 .hash {
  color: var(--text-faint);
  font-weight: 400;
  margin-left: 0.25rem;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.content h2:hover .hash {
  opacity: 1;
}

.rule {
  width: 56px;
  height: 4px;
  border-radius: 2px;
  background: var(--brand);
  margin: 0.2rem 0 1.4rem;
}

ul,
ol {
  margin: 0 0 1.2rem;
  padding-left: 1.4rem;
}

li {
  margin: 0.3rem 0;
}

/* Tables */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th,
td {
  text-align: left;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  background: var(--surface-alt);
  font-weight: 600;
}

tr:last-child td {
  border-bottom: 0;
}

/* Buttons and chips */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border-radius: var(--radius);
  padding: 0.6rem 1.15rem;
  font-weight: 600;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  color: var(--text);
  background: var(--surface);
}

.btn:hover {
  border-color: var(--border-strong);
  color: var(--text);
  text-decoration: none;
}

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-contrast);
}

.btn-primary:hover {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
  color: var(--brand-contrast);
}

.btn-secondary {
  background: var(--surface);
}

.chip {
  display: inline-block;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1em 0.6em;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--surface);
}

.chip.brand {
  border-color: var(--brand);
  color: var(--brand);
  background: var(--brand-soft);
}

.note {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-soft);
  padding: 0.85rem 1rem;
  margin: 1.2rem 0;
  font-size: 0.95rem;
}

.note p {
  margin: 0;
}

/* Footer */

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--bg-soft);
}

.footer-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.6rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  color: var(--text-faint);
  font-size: 0.85rem;
}

/* Landing hero */

.hero {
  text-align: center;
  padding: 3.5rem 0 2rem;
}

.hero-logo {
  width: 72px;
  height: 72px;
  background: white;
  border-radius: 100px;
  padding: 8px;
  margin-bottom: 1.4rem;
}

.hero h1 {
  font-size: 2.7rem;
  margin-bottom: 0.4rem;
}

.hero .lede {
  max-width: 620px;
  margin: 0 auto 1.6rem;
}

.hero-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 3rem;
}

.quickstart {
  text-align: left;
  max-width: 640px;
  margin: 0 auto;
}

.quickstart pre {
  margin: 0;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.1rem;
  margin: 2.4rem 0;
  text-align: left;
}

.feature-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 1.15rem 1.25rem;
}

.feature-card h3 {
  margin-bottom: 0.4rem;
}

.feature-card p {
  margin: 0;
  font-size: 0.92rem;
  color: var(--text-muted);
}

/* Search modal */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(10, 10, 20, 0.5);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 12vh 1rem 1rem;
}

html[data-theme="dark"] .modal-backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.search-panel {
  width: 100%;
  max-width: 600px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.search-input-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.search-input-row svg {
  flex: none;
  color: var(--text-faint);
}

.search-input {
  flex: 1;
  border: 0;
  background: none;
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  outline: none;
}

.search-results {
  max-height: 46vh;
  overflow-y: auto;
  padding: 0.4rem;
}

.search-result {
  display: block;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  color: var(--text);
}

.search-result:hover {
  background: var(--surface-alt);
  text-decoration: none;
}

.search-result.active {
  background: var(--brand-soft);
}

.search-result .sr-title {
  font-weight: 600;
  color: var(--text);
}

.search-result.active .sr-title {
  color: var(--brand-hover);
}

.search-result .sr-meta {
  font-size: 0.78rem;
  color: var(--text-faint);
  margin-top: 0.1rem;
}

.search-result .sr-excerpt {
  font-size: 0.86rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.search-empty {
  padding: 1rem 1.2rem;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.search-hints {
  display: flex;
  gap: 1rem;
  padding: 0.6rem 1rem;
  border-top: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 0.8rem;
}

/* Chat */

.chat-fab {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 60;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--brand);
  color: var(--brand-contrast);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
}

.chat-fab:hover {
  background: var(--brand-hover);
}

.chat-panel {
  position: fixed;
  right: 1.25rem;
  bottom: 5rem;
  z-index: 70;
  width: min(380px, calc(100vw - 2.5rem));
  height: min(520px, calc(100vh - 6rem));
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-panel[hidden] {
  display: none;
}

.chat-header {
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-header .chat-title {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.chat-header .chat-sub {
  font-weight: 400;
  font-size: 0.78rem;
  color: var(--text-faint);
  display: block;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.msg {
  max-width: 90%;
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius);
  font-size: 0.92rem;
  line-height: 1.55;
  word-break: break-word;
}

.msg.user {
  align-self: flex-end;
  background: var(--brand);
  color: var(--brand-contrast);
  white-space: pre-wrap;
}

.msg.assistant {
  align-self: flex-start;
  background: var(--surface-alt);
  color: var(--text);
}

.msg.assistant p {
  margin: 0 0 0.6rem;
}

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

.msg.assistant ul,
.msg.assistant ol {
  margin: 0 0 0.6rem;
  padding-left: 1.3rem;
}

.msg.assistant pre {
  margin: 0.6rem 0;
  background: var(--bg);
}

.msg.assistant code {
  background: var(--bg);
}

.msg.error {
  align-self: flex-start;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.86rem;
  white-space: pre-wrap;
}

.msg.banner {
  align-self: stretch;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text-muted);
  text-align: center;
  font-size: 0.88rem;
}

.chat-input-row {
  display: flex;
  gap: 0.6rem;
  padding: 0.75rem;
  border-top: 1px solid var(--border);
}

.chat-input {
  flex: 1;
  padding: 0.55rem 0.8rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.92rem;
  outline: none;
}

.chat-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--focus);
}

.chat-send {
  border-radius: var(--radius);
  background: var(--brand);
  color: var(--brand-contrast);
  padding: 0 1rem;
  font-weight: 600;
}

.chat-send:hover {
  background: var(--brand-hover);
}

.chat-send:disabled {
  opacity: 0.5;
  cursor: default;
}

/* Utility */

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

[hidden] {
  display: none !important;
}

/* Responsive */

@media (max-width: 880px) {
  .shell {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 90;
    width: min(300px, 84vw);
    background: var(--bg);
    border-right: 1px solid var(--border);
    padding: 4.5rem 1rem 2rem;
    margin: 0;
    transform: translateX(-102%);
    transition: transform 0.2s ease;
    max-height: none;
  }

  body.nav-open .sidebar {
    transform: none;
  }

  body.nav-open::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 80;
    background: rgba(10, 10, 20, 0.5);
  }

  .nav-toggle {
    display: inline-flex;
  }

  .search-button {
    min-width: 38px;
    justify-content: center;
  }

  .search-button .search-label {
    display: none;
  }

  .search-button .kbd {
    display: none;
  }

  .hero h1 {
    font-size: 2.1rem;
  }
}

@media (max-width: 560px) {
  .shell {
    padding: 1.5rem 1rem 2.5rem;
  }

  .hero {
    padding-top: 2rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}