/* -- Site layout styles ------------------------------------ */
/* Nav, sidebar, preview box, code blocks, swatches, etc.    */

/* Prevent horizontal overflow on mobile */
html { overflow-x: clip; }

/* -- Scroll offset for fixed header ------------------------ */
html { scroll-padding-top: 4rem; }

/* -- Site header ------------------------------------------- */
.site-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  height: 3.5rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 1.5rem; gap: 1rem;
  background: oklch(from var(--background) l c h / 0.88);
  backdrop-filter: blur(14px);
}

/* -- Header brand (logo + version) ------------------------- */
.header-brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  text-decoration: none;
}
.header-brand-name {
  font-family: var(--font-display);
  font-size: 1.1875rem;
  font-weight: 500;
  letter-spacing: -0.03em;
  color: var(--foreground);
  white-space: nowrap;
}
.header-brand-version {
  white-space: nowrap;
}

/* -- Site sidebar ------------------------------------------ */
.site-sidebar {
  width: 14rem; flex-shrink: 0;
  border-right: 1px solid var(--sidebar-border);
  position: sticky; top: 3.5rem;
  height: calc(100vh - 3.5rem);
  background: var(--sidebar);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.sidebar-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1.25rem 0.75rem;
}
.sidebar-author {
  flex-shrink: 0;
  padding-bottom: 1rem;
}

/* -- Nav section heading ----------------------------------- */
.nav-heading {
  font-size: 0.75rem; font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--primary);
  padding: 0 0.75rem;
  margin: 0 0 0.375rem;
}

/* -- Header action button / link --------------------------- */
.header-action {
  display: flex; align-items: center; gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius-lg);
  font-size: 0.875rem;
  color: var(--muted-foreground);
  text-decoration: none;
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: color 150ms, background 150ms;
}
.header-action:hover {
  color: var(--foreground);
  background: var(--accent);
}
.theme-toggle-btn {
  width: 2.25rem; height: 2.25rem;
  padding: 0; justify-content: center;
  border: 1px solid var(--border);
  color: var(--foreground);
}

/* -- SPA view transition for main content ------------------ */
main {
  view-transition-name: main-content;
}

/* Old page fades out, new page fades in — subtle crossfade */
::view-transition-old(main-content) {
  animation: vt-fade-out 150ms ease-out both;
}
::view-transition-new(main-content) {
  animation: vt-fade-in 150ms ease-in 50ms both;
}

/* Keep header/sidebar stable — instant swap, no animation */
::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
}

@keyframes vt-fade-out {
  to { opacity: 0; }
}
@keyframes vt-fade-in {
  from { opacity: 0; }
}

/* -- Nav link ---------------------------------------------- */
.nav-link {
  display: block;
  padding: 0.3125rem 0.75rem;
  margin-bottom: 2px;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  color: var(--muted-foreground);
  text-decoration: none;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: var(--font-sans);
  transition: all 120ms;
  line-height: 1.6;
}
.nav-link:hover { color: var(--foreground); background: var(--accent); }
.nav-link.active { color: var(--primary); font-weight: 500; background: var(--accent); }
.nav-link.disabled {
  opacity: 0.4;
  pointer-events: none;
  cursor: default;
}

/* -- Nav filter input -------------------------------------- */
.nav-filter-input:focus {
  border-color: var(--ring);
  box-shadow: 0 0 0 2px oklch(from var(--ring) l c h / 0.18);
}
.nav-filter-input::placeholder {
  color: var(--muted-foreground);
  opacity: 0.65;
}

/* -- Built-with pills -------------------------------------- */
a.built-with-pill {
  text-decoration: none;
  cursor: pointer;
  transition: background 120ms, border-color 120ms;
}
a.built-with-pill:hover {
  background: var(--accent);
  border-color: var(--foreground);
}

/* -- Details chevron rotation ------------------------------ */
details[open] > summary svg:first-child {
  transform: rotate(90deg);
}

/* -- Spec modal -------------------------------------------- */
.spec-modal { max-width: 48rem; width: calc(100vw - 2rem); }
.spec-modal-content { padding: 1.5rem 2rem 2rem; }
.spec-modal-body { font-size: 0.875rem; line-height: 1.85; color: var(--foreground); }
.spec-modal-body h1 { font-size: 1.5rem; font-weight: 600; margin: 0 0 1rem; letter-spacing: -0.02em; }
.spec-modal-body h2 { font-size: 1.125rem; font-weight: 600; margin: 2rem 0 0.625rem; padding-bottom: 0.375rem; border-bottom: 1px solid var(--border); }
.spec-modal-body h3 { font-size: 1rem; font-weight: 600; margin: 1.5rem 0 0.5rem; }
.spec-modal-body p { margin: 0 0 0.75rem; }
.spec-modal-body ul, .spec-modal-body ol { margin: 0 0 0.75rem; padding-left: 1.5rem; }
.spec-modal-body li { margin-bottom: 0.25rem; }
.spec-modal-body code { font-family: var(--font-mono); font-size: 0.8125em; background: var(--muted); padding: 0.125em 0.375em; border-radius: var(--radius-sm); }
.spec-modal-body pre { background: var(--muted); border-radius: var(--radius-lg); padding: 1rem; margin: 0.5rem 0 1rem; overflow-x: auto; }
.spec-modal-body pre code { background: none; padding: 0; font-size: 0.8125rem; }
.spec-modal-body a { color: var(--primary); text-decoration: underline; text-underline-offset: 3px; }
.spec-modal-body hr { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }
.spec-modal-body table { width: 100%; border-collapse: collapse; margin: 0.5rem 0 1rem; font-size: 0.8125rem; }
.spec-modal-body th, .spec-modal-body td { text-align: left; padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border); }
.spec-modal-body th { font-weight: 600; background: var(--muted); }
[data-spec-href] { cursor: pointer; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--muted-foreground); }

/* -- Preview box ------------------------------------------- */
.preview {
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  min-height: 11rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.875rem;
  padding: 2.5rem 1.5rem;
  background-color: var(--background);
  background-image:
    radial-gradient(circle, var(--border) 1px, transparent 1px);
  background-size: 24px 24px;
  position: relative;
}

/* -- Code block -------------------------------------------- */
pre {
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 1.25rem 1.5rem;
  overflow-x: auto;
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.8;
}
code {
  font-family: var(--font-mono);
  font-size: 0.8125em;
  background: var(--muted);
  padding: 0.125rem 0.375rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
pre code { background: none; padding: 0; border: none; font-size: inherit; }

/* -- Shiki dual-theme: light default, dark via html.dark --- */
pre.shiki {
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 1.25rem 1.5rem;
  overflow: hidden;
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.8;
}
/* Nested pre inside a card/container — remove its own border/radius/bg */
pre.shiki[style*="border-radius:0"],
div[style*="overflow:hidden"] > pre.shiki,
div[style*="overflow:hidden"] > div > pre.shiki {
  border: none !important;
  border-radius: 0 !important;
  background: transparent !important;
}
pre.shiki code {
  white-space: pre-wrap;
  word-break: break-all;
}
pre.shiki,
pre.shiki span {
  color: var(--shiki-light) !important;
  background-color: transparent !important;
}
html.dark pre.shiki,
html.dark pre.shiki span {
  color: var(--shiki-dark) !important;
  background-color: transparent !important;
}
.dim { color: var(--muted-foreground); }

/* -- Doc tabs (preview/pattern/html switcher) -------------- */
.tab-list {
  display: inline-flex;
  background: var(--muted);
  border-radius: var(--radius-md);
  padding: 0.2rem;
  gap: 0.125rem;
  margin-bottom: 1rem;
}
.tab-btn {
  padding: 0.3rem 0.875rem;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 500;
  font-family: var(--font-sans);
  border: none;
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
  transition: all 150ms;
  line-height: 1.6;
}
.tab-btn[aria-selected="true"] {
  background: var(--background);
  color: var(--foreground);
  box-shadow: 0 1px 4px oklch(0 0 0 / 0.08), 0 0 0 1px var(--border);
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* -- Token swatch ------------------------------------------ */
.swatch-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.625rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  min-width: 0;
  overflow: hidden;
}

/* -- Copy button ------------------------------------------- */
.copy-btn {
  position: absolute;
  top: 0.625rem;
  right: 0.625rem;
  height: 1.875rem;
  padding: 0 0.625rem;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  background: var(--background);
  color: var(--muted-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 150ms;
  display: flex;
  align-items: center;
  gap: 0.375rem;
}
.copy-btn:hover { color: var(--foreground); }

/* -- API pill links (Web Platform APIs in spec details) ---- */
.api-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.75rem;
  color: var(--foreground);
  text-decoration: none;
  transition: background 150ms;
}
.api-pill:hover { background: var(--accent); }
.api-pill code { font-size: inherit; background: none; border: none; padding: 0; }
.api-pill svg { width: 10px; height: 10px; opacity: 0.4; flex-shrink: 0; }

/* -- Code collapse toggle ---------------------------------- */
.code-toggle-btn {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  width: fit-content;
  margin-left: auto;
  margin-top: 0.25rem;
  padding: 0 0.375rem;
  height: 1.5rem;
  font-size: 0.6875rem;
  font-family: var(--font-mono);
  background: transparent;
  color: var(--muted-foreground);
  border: none;
  cursor: pointer;
  transition: color 150ms;
}
.code-toggle-btn:hover { color: var(--foreground); }

.code-block-wrapper.code-collapsed { display: none; }

/* -- Collapse-all toolbar ---------------------------------- */
.code-collapse-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.75rem;
}
.code-collapse-all-btn {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0 0.625rem;
  height: 1.875rem;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  background: transparent;
  color: var(--muted-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color 150ms, background 150ms;
}
.code-collapse-all-btn:hover {
  color: var(--foreground);
  background: var(--accent);
}

/* -- Sticky page header ------------------------------------ */
.page-header {
  position: sticky;
  top: 3.5rem;
  z-index: 10;
  background: var(--background);
  padding: 1rem 0 1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}
.page-header > details {
  margin-bottom: 0 !important;
}
.page-header > :last-child {
  margin-bottom: 0 !important;
}

/* -- Theme selector popover -------------------------------- */
.theme-popover {
  position: fixed;
  inset: unset;
  top: 3.5rem;
  right: 0.75rem;
  width: 20rem;
  max-height: calc(100vh - 4.5rem);
  overflow-y: auto;
  margin: 0;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--popover);
  color: var(--popover-foreground);
  box-shadow: var(--shadow-lg);
}
.theme-popover::backdrop {
  background: transparent;
}
.theme-popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  padding: 0 0.25rem;
}
.theme-popover-title {
  font-size: 0.8125rem;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--foreground);
}
.theme-reset-btn {
  font-size: 0.6875rem;
  font-family: var(--font-mono);
  color: var(--muted-foreground);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  transition: color 150ms, background 150ms;
}
.theme-reset-btn:hover {
  color: var(--foreground);
  background: var(--accent);
}
.theme-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.375rem;
}
.theme-swatch {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: transparent;
  cursor: pointer;
  font-family: var(--font-sans);
  text-align: left;
  transition: border-color 150ms, background 150ms;
  color: var(--foreground);
  width: 100%;
}
.theme-swatch:hover {
  border-color: var(--foreground);
}
.theme-swatch.active {
  border-color: var(--primary);
  background: var(--accent);
}
.theme-swatch-label {
  font-size: 0.6875rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.theme-swatch-colors {
  display: flex;
  gap: 0.25rem;
}
.theme-swatch-dot {
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  border: 1px solid oklch(0 0 0 / 0.12);
  flex-shrink: 0;
}

/* -- Separator --------------------------------------------- */
.sep {
  height: 1px;
  background: var(--border);
  margin: 2rem 0;
}

/* -- GitHub star count in header --------------------------- */
.github-stars {
  font-size: 0.75rem;
  font-family: var(--font-mono);
  background: var(--muted);
  padding: 0.0625rem 0.375rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  min-width: 1.25rem;
  text-align: center;
}
.github-stars:empty { display: none; }

/* -- Site footer ------------------------------------------- */
.site-footer {
  padding: 2rem 1.5rem;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--muted-foreground);
  border-top: 1px solid var(--border);
}
.site-footer p { margin: 0; }
.site-footer-tagline {
  font-style: italic;
  margin: 0 0 0.25rem !important;
  color: var(--foreground);
  opacity: 0.7;
}
.site-footer a {
  color: var(--foreground);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--muted-foreground);
  transition: text-decoration-color 150ms;
}
.site-footer a:hover { text-decoration-color: var(--foreground); }
.site-footer-dot { color: var(--border); }

/* -- Table of contents (right sidebar) --------------------- */
.site-toc {
  width: 12rem;
  flex-shrink: 0;
  position: sticky;
  top: 3.5rem;
  height: calc(100vh - 3.5rem);
  overflow-y: auto;
  padding: 2rem 1rem 2rem 0;
}
.toc-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--foreground);
  margin: 0 0 0.5rem;
  padding: 0 0.5rem;
}
.toc-link {
  display: block;
  padding: 0.1875rem 0.5rem;
  font-size: 0.8125rem;
  color: var(--muted-foreground);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: color 150ms, border-color 150ms;
  line-height: 1.6;
}
.toc-link:hover { color: var(--foreground); }
.toc-link.active {
  color: var(--foreground);
  border-left-color: var(--primary);
}

/* Hide TOC on narrow screens */
@media (max-width: 80rem) {
  .site-toc { display: none; }
}

/* -- Mobile responsive ------------------------------------- */

/* Hamburger menu button (hidden on desktop) */
.sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: transparent;
  color: var(--foreground);
  cursor: pointer;
  flex-shrink: 0;
}

/* Sidebar overlay backdrop (hidden on desktop) */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  top: 3.5rem;
  z-index: 39;
  background: oklch(0 0 0 / 0.4);
}

@media (max-width: 48rem) {
  /* Show hamburger */
  .sidebar-toggle { display: flex; }

  /* Sidebar: off-canvas overlay on mobile */
  .site-sidebar {
    position: fixed;
    top: 3.5rem;
    left: 0;
    z-index: 40;
    width: 16rem;
    height: calc(100vh - 3.5rem);
    transform: translateX(-100%);
    transition: transform 250ms ease;
    box-shadow: var(--shadow-lg);
  }
  .site-sidebar.open {
    transform: translateX(0);
  }

  /* Show backdrop when sidebar open */
  .sidebar-backdrop.open {
    display: block;
  }

  /* Reduce main padding on mobile */
  main {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
  }

  /* Reduce header padding */
  .site-header {
    padding: 0 0.75rem;
    gap: 0.375rem;
  }

  /* Stack brand name + version vertically, shrink */
  .header-brand {
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
    min-width: 0;
  }
  .header-brand-name {
    font-size: 0.9375rem;
    line-height: 1.2;
  }
  .header-brand-version {
    font-size: 0.5625rem;
    padding: 0 0.25rem;
    line-height: 1.4;
  }

  /* Shrink header action buttons on mobile */
  .header-action.theme-toggle-btn {
    width: 2rem;
    height: 2rem;
  }
  .header-action.theme-toggle-btn svg {
    width: 13px;
    height: 13px;
  }

  /* Preview boxes: allow wrapping, reduce padding */
  .preview {
    padding: 1.5rem 1rem;
    gap: 0.625rem;
  }

  /* Code blocks: reduce padding, smaller font */
  pre, pre.shiki {
    padding: 0.875rem 1rem;
    font-size: 0.75rem;
  }

  /* Tables: scroll if needed */
  .spec-modal-body table {
    display: block;
    overflow-x: auto;
  }

  /* Page nav: single column on mobile */
  .page-nav {
    grid-template-columns: 1fr;
  }

  /* Sticky page header: reduce top offset for mobile */
  .page-header {
    padding: 0.75rem 0;
  }

  /* Hide "GitHub" text, keep icon */
  .header-action .github-label {
    display: none;
  }

  /* Theme popover: wider on mobile */
  .theme-popover {
    right: 0.25rem;
    width: calc(100vw - 0.5rem);
    max-width: 20rem;
  }

  /* Swatch rows */
  .swatch-row {
    flex-wrap: wrap;
  }

  /* Spec modal: full-width on mobile */
  .spec-modal {
    width: calc(100vw - 1rem);
  }
  .spec-modal-content {
    padding: 1rem 1.25rem 1.5rem;
  }
}

@media (max-width: 48rem) and (prefers-reduced-motion: reduce) {
  .site-sidebar {
    transition: none;
  }
}

/* -- Prev / Next page navigation --------------------------- */
.page-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}
.page-nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  text-decoration: none;
  color: var(--foreground);
  transition: border-color 150ms, background 150ms;
}
.page-nav-link:hover {
  border-color: var(--foreground);
  background: var(--accent);
}
.page-nav-link svg {
  flex-shrink: 0;
  color: var(--muted-foreground);
}
.page-nav-prev { justify-content: flex-start; }
.page-nav-next { justify-content: flex-end; text-align: right; }
.page-nav-label {
  display: block;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--muted-foreground);
  margin-bottom: 0.125rem;
}
.page-nav-title {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
}


