:root {
  color-scheme: light;
  --bg: #f7f6f2;
  --panel: #ffffff;
  --text: #1c1c1c;
  --muted: #555555;
  --border: #d6d3cc;
  --accent: #0b5fa5;
  --accent-soft: #e1eef8;
  --note-info: #eef5f2;
  --note-important: #fff3d6;
  --note-critical: #ffe0e0;
  --shadow: rgba(0, 0, 0, 0.04);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

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

a:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.topbar {
  display: none;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar-title {
  font-weight: 600;
  font-size: 1rem;
}

#sidebarToggle {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.45rem 0.7rem;
  font-weight: 600;
  cursor: pointer;
}

.app {
  display: grid;
  grid-template-columns: minmax(260px, 320px) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 1.5rem 1.25rem;
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-header h1 {
  font-size: 1.35rem;
  margin: 0 0 0.25rem;
}

.sidebar-header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.search {
  margin-top: 1.25rem;
}

.search label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.search input {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  background: #fff;
}

.search-hint {
  margin-top: 0.4rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.toc {
  margin-top: 1.5rem;
  font-size: 0.92rem;
}

.toc-section {
  margin-bottom: 1.5rem;
}

.toc-link {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.5rem;
  align-items: baseline;
  text-decoration: none;
  color: inherit;
  padding: 0.25rem 0;
}

.toc-link:hover {
  color: var(--accent);
}

.toc-label {
  font-weight: 600;
}

.toc-type {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 0.1rem 0.35rem;
  border-radius: 999px;
}

.toc-header-block {
  margin-left: 0.5rem;
  margin-top: 0.5rem;
  padding-left: 0.65rem;
  border-left: 1px solid var(--border);
}

.toc-functions {
  list-style: none;
  padding-left: 0;
  margin: 0.4rem 0 0;
}

.toc-functions li {
  margin: 0.25rem 0;
}

.toc-signature {
  display: block;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

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

.search-result .toc-label {
  font-weight: 600;
}

.search-meta {
  font-size: 0.78rem;
  color: var(--muted);
}

.search-empty {
  padding: 0.6rem 0;
  color: var(--muted);
}

.toc-errors {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  color: #7a2c2c;
}

.toc-errors-title {
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.toc-errors ul {
  padding-left: 1rem;
  margin: 0;
}

.content {
  padding: 2rem 2.5rem 4rem;
}

.info-block {
  margin-top: 2.5rem;
  padding: 1.25rem 1.5rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.info-block h2 {
  margin-top: 0;
  font-size: 1.2rem;
}

.info-block p {
  margin: 0 0 0.8rem;
}

.info-block .info-created {
  margin-bottom: 0;
  font-weight: 600;
  color: var(--muted);
}

.error-banner {
  background: #fff1f1;
  border: 1px solid #f2c4c4;
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
}

.error-banner h2 {
  margin-top: 0;
}

.category {
  margin-bottom: 2.5rem;
}

.category > h2 {
  margin-top: 0;
  font-size: 1.7rem;
}

.header {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.header > h3 {
  margin-top: 0;
  font-size: 1.35rem;
}

.function-card {
  margin-top: 1.5rem;
  padding: 1.25rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 2px 6px var(--shadow);
}

.function-header {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: baseline;
}

.function-header h4 {
  margin: 0;
  font-size: 1.2rem;
}

.function-kind {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.45rem;
}

.summary {
  margin-top: 0.6rem;
}

.prose p {
  margin: 0 0 0.6rem;
}

.keywords {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  margin-top: 0.8rem;
}

.keywords-label {
  font-weight: 600;
  margin-right: 0.3rem;
}

.keyword {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  font-size: 0.8rem;
}

.section-block {
  margin-top: 1rem;
}

.section-block h5 {
  margin: 0 0 0.6rem;
  font-size: 1rem;
}

.warning {
  margin-top: 0.6rem;
  padding: 0.5rem 0.75rem;
  border-left: 4px solid #c95532;
  background: #fff3ee;
  font-weight: 600;
}

.param {
  margin-bottom: 0.8rem;
  padding-bottom: 0.8rem;
  border-bottom: 1px dashed var(--border);
}

.param:last-child {
  border-bottom: none;
}

.param-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: baseline;
  margin-bottom: 0.4rem;
}

.param-name {
  font-weight: 600;
}

.param-type {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.85rem;
  color: var(--muted);
}

.param-direction {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: #eee;
  color: #222;
  border-radius: 999px;
  padding: 0.1rem 0.4rem;
}

.return {
  margin-bottom: 0.6rem;
}

.return-type {
  font-weight: 600;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.2rem;
}

.note {
  border-left: 4px solid var(--border);
  background: #fafafa;
  padding: 0.65rem 0.8rem;
  border-radius: 6px;
  margin-bottom: 0.6rem;
}

.note-header {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.3rem;
}

.note-severity,
.note-topic {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  background: #eee;
}

.note.severity-important {
  border-left-color: #d7a600;
  background: var(--note-important);
}

.note.severity-critical {
  border-left-color: #c43030;
  background: var(--note-critical);
}

.note.severity-info {
  border-left-color: #3e7c62;
  background: var(--note-info);
}

.example {
  margin-bottom: 1rem;
}

.example-title {
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.copy-block {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #fdfdfc;
  margin-top: 0.4rem;
}

.copy-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.75rem;
  background: #f4f3ef;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.copy-label {
  font-weight: 600;
}

.copy-lang {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.copy-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.copy-button {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 6px;
  padding: 0.25rem 0.6rem;
  cursor: pointer;
  font-size: 0.8rem;
}

.copy-status {
  font-size: 0.75rem;
  color: var(--muted);
}

.copy-status.copy-success {
  color: #1a6a3a;
}

.copy-status.copy-error {
  color: #a33030;
}

.copy-block pre {
  margin: 0;
  padding: 0.75rem 0.9rem;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.85rem;
  white-space: pre;
  overflow-x: auto;
}

.internal-note {
  margin-top: 1rem;
  padding: 0.8rem 1rem;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: #fafafa;
}

.internal-note-label {
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

.flash {
  animation: flash 1.5s ease-out;
}

@keyframes flash {
  0% {
    box-shadow: 0 0 0 3px var(--accent-soft);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(0, 0, 0, 0);
  }
}

#sidebarBackdrop {
  display: none;
}

@media (max-width: 960px) {
  .topbar {
    display: flex;
  }

  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 340px);
    height: 100vh;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 10;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  #sidebarBackdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.25);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 9;
  }

  #sidebarBackdrop.visible {
    opacity: 1;
    pointer-events: auto;
  }

  .content {
    padding: 1.5rem 1.25rem 3rem;
  }
}
