/* ==========================================================================
   RouterHubs Docs — CSS overrides for Starlight
   Strategy: only override CSS *tokens* and *component-level* styles.
   Never override Starlight's layout properties (display, position, grid,
   flex on .page/.sidebar/.main-frame). Starlight's layout uses position:fixed
   for header and sidebar — fighting it with grid/sticky breaks everything.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. CSS Token overrides
   Unlayered CSS wins over Starlight's @layer rules; set variables here.
   -------------------------------------------------------------------------- */
:root {
  /* Fonts */
  --sl-font: Inter, -apple-system, BlinkMacSystemFont, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;
  --sl-font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Brand accent — electric green, dark mode */
  --sl-color-accent-low: hsl(151 65% 8%);
  --sl-color-accent: hsl(151 100% 45%);
  --sl-color-accent-high: hsl(151 85% 65%);

  /* Neutral palette, dark mode */
  --sl-color-white: hsl(224 28% 96%);
  --sl-color-gray-1: hsl(225 19% 88%);
  --sl-color-gray-2: hsl(226 14% 76%);
  --sl-color-gray-3: hsl(229 12% 62%);
  --sl-color-gray-4: hsl(229 13% 44%);
  --sl-color-gray-5: hsl(230 19% 24%);
  --sl-color-gray-6: hsl(230 28% 16%);
  --sl-color-black: hsl(226 38% 7%);

  /* Header height — match main site's 52px (overrides Starlight's 3.5rem/4rem) */
  --sl-nav-height: 52px;

  /* Wider content column; Starlight default is 45rem */
  --sl-content-width: 60rem;

  /* Slightly narrower sidebar */
  --sl-sidebar-width: 17rem;

  /* Nav background via Starlight token (frosted glass) */
  --sl-color-bg-nav: hsl(226 38% 7% / 0.88);
}

:root[data-theme="light"] {
  /* Brand accent — green, light mode */
  --sl-color-accent-low: hsl(151 75% 90%);
  --sl-color-accent: hsl(151 94% 31%);
  --sl-color-accent-high: hsl(151 94% 24%);

  /* Neutral palette, light mode */
  --sl-color-white: hsl(224 24% 8%);
  --sl-color-gray-1: hsl(226 25% 16%);
  --sl-color-gray-2: hsl(229 16% 29%);
  --sl-color-gray-3: hsl(230 11% 44%);
  --sl-color-gray-4: hsl(229 10% 58%);
  --sl-color-gray-5: hsl(225 13% 75%);
  --sl-color-gray-6: hsl(220 20% 93%);
  --sl-color-gray-7: hsl(240 20% 98%);
  --sl-color-black: hsl(0 0% 100%);

  /* Nav background, light mode */
  --sl-color-bg-nav: hsl(0 0% 100% / 0.9);
}

/* --------------------------------------------------------------------------
   2. Base typography — let Starlight lay out; we just restyle text
   -------------------------------------------------------------------------- */
html {
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: var(--sl-color-text-accent, var(--sl-color-accent-high));
  text-decoration: none;
}

a:hover {
  color: var(--sl-color-accent-high);
}

h1, h2, h3, h4 {
  color: var(--sl-color-white);
  letter-spacing: 0;
  line-height: 1.2;
}

p, li, td, th {
  color: var(--sl-color-gray-2);
}

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

pre {
  overflow: auto;
  border: 1px solid var(--sl-color-gray-5);
  border-radius: 10px;
  background: var(--sl-color-gray-6);
  padding: 16px;
}

table {
  display: block;
  width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
}

th, td {
  border-bottom: 1px solid var(--sl-color-gray-6);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--sl-color-white);
  font-weight: 750;
}

/* --------------------------------------------------------------------------
   3. Starlight outer <header> — visual-only overrides
   Starlight keeps position:fixed; height:--sl-nav-height. We add blur + border.
   Starlight applies padding:12px 24px to this element — reset to 0 so the
   full 52px height is available to .docs-header-inner.
   -------------------------------------------------------------------------- */
.header {
  padding: 0 !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  backdrop-filter: blur(16px) saturate(1.5);
  -webkit-backdrop-filter: blur(16px) saturate(1.5);
}

:root[data-theme="light"] .header {
  border-bottom-color: rgba(0, 0, 0, 0.08);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

/* --------------------------------------------------------------------------
   4. Custom DocsHeader inner layout (docs-header-inner)
   Deliberately does NOT use the .header classname to avoid conflicts.
   -------------------------------------------------------------------------- */
.docs-header-inner {
  position: relative;
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  height: 100%;
  padding-inline: 32px;
}

/* Brand — matches main site exactly */
.docs-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  color: var(--sl-color-white);
  font-size: 16px;
  font-weight: 800;
  line-height: 24px;
  letter-spacing: -0.02em;
  white-space: nowrap;
  text-decoration: none;
}

.docs-brand:hover {
  color: var(--sl-color-white);
}

.docs-radar-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--sl-color-accent);
  box-shadow: 0 0 8px var(--sl-color-accent);
  animation: docs-pulse-dot 2s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes docs-pulse-dot {
  0%, 100% { opacity: 1; box-shadow: 0 0 8px var(--sl-color-accent); }
  50%       { opacity: 0.58; box-shadow: 0 0 4px var(--sl-color-accent); }
}

@media (prefers-reduced-motion: reduce) {
  .docs-radar-dot { animation: none; }
}

/* Left zone — flex:1 so brand sits at left edge */
.docs-header-left {
  display: flex;
  align-items: center;
  flex: 1;
}

/* Nav — absolutely centered in the header, independent of left/right widths */
.docs-main-nav {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
}

.docs-nav-link {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border-radius: 8px;
  color: var(--sl-color-gray-3);
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}

.docs-nav-link:hover {
  background: var(--sl-color-gray-6);
  color: var(--sl-color-white);
}

/* Active: color only, no background — matches main site */
.docs-nav-link.active {
  color: var(--sl-color-white);
}

/* Right-side actions — pushed to right edge */
.docs-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

/* Search button — compact to match toolbar feel */
site-search button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  border-radius: 8px;
  padding: 0 10px;
  font-size: 13px;
}

/* 提交收录 pill — matches main site .submit-link */
.docs-submit-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  border-radius: 999px;
  background: var(--sl-color-accent);
  color: var(--sl-color-black);
  padding: 0 14px;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
  text-decoration: none;
  transition: background 0.15s ease, transform 0.15s ease;
}

.docs-submit-link:hover {
  background: color-mix(in srgb, var(--sl-color-accent) 80%, #000);
  color: var(--sl-color-black);
  transform: translateY(-1px);
}

/* Theme toggle — matches main site exactly */
.docs-theme-toggle {
  position: relative;
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  width: 34px;
  height: 32px;
  border: 1px solid var(--sl-color-gray-5);
  border-radius: 8px;
  background: var(--sl-color-gray-6);
  color: var(--sl-color-gray-2);
  padding: 0;
  cursor: pointer;
  transition: border-color 0.2s ease, color 0.2s ease;
}

.docs-theme-toggle:hover {
  border-color: var(--sl-color-accent);
  color: var(--sl-color-accent);
}

.docs-theme-icon {
  grid-area: 1 / 1;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.docs-moon-icon {
  opacity: 0;
  transform: scale(0.82) rotate(-16deg);
}

:root[data-theme="dark"] .docs-theme-toggle .docs-sun-icon {
  opacity: 0;
  transform: scale(0.82) rotate(16deg);
}

:root[data-theme="dark"] .docs-theme-toggle .docs-moon-icon {
  opacity: 1;
  transform: scale(1) rotate(0);
}

/* --------------------------------------------------------------------------
   5. Sidebar navigation — visual styling only
   Starlight handles position:fixed and width via --sl-sidebar-width
   -------------------------------------------------------------------------- */
.sidebar-pane {
  padding: 18px 16px 28px;
}

.sidebar-content ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.sidebar-content li {
  margin: 2px 0;
}

.sidebar-content a {
  display: flex;
  align-items: center;
  min-height: 36px;
  border-radius: 8px;
  color: var(--sl-color-gray-2);
  padding: 6px 10px;
  font-size: 0.875rem;
  line-height: 1.35;
  transition: background 0.15s ease, color 0.15s ease;
}

.sidebar-content a:hover,
.sidebar-content a[aria-current="page"] {
  background: var(--sl-color-gray-6);
  color: var(--sl-color-white);
}

.sidebar-content details {
  margin-top: 12px;
}

.sidebar-content summary,
.sidebar-content [aria-expanded] {
  color: var(--sl-color-gray-3);
  font-size: 0.75rem;
  font-weight: 750;
  text-transform: none;
}

/* --------------------------------------------------------------------------
   6. Article content
   -------------------------------------------------------------------------- */
.sl-markdown-content :is(h1, h2, h3, h4) {
  letter-spacing: 0;
}

.sl-markdown-content a:not(:where(.not-content *)) {
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.sl-markdown-content table {
  font-size: 0.9rem;
}

.sl-markdown-content code:not(:where(.not-content *)) {
  border-radius: 6px;
}

/* Aside callouts — no side-stripe (banned pattern), full border + tinted bg */
.starlight-aside {
  border: 1px solid color-mix(in srgb, var(--sl-color-accent) 28%, transparent);
  border-radius: 10px;
  background: color-mix(in srgb, var(--sl-color-accent-low) 45%, transparent);
  margin: 18px 0;
  padding: 14px 16px;
}

.starlight-aside__title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 6px;
  color: var(--sl-color-accent-high);
  font-weight: 800;
}

.starlight-aside__content > :last-child {
  margin-bottom: 0;
}

.pagination-links a {
  border-radius: 8px;
}

/* --------------------------------------------------------------------------
   7. Mobile nav — horizontal scroll with fade hint
   -------------------------------------------------------------------------- */
@media (max-width: 50rem) {
  .docs-header-inner {
    flex-wrap: wrap;
    padding-inline: 16px;
    padding-block: 8px;
    height: auto;
    gap: 8px;
  }

  .docs-submit-link {
    display: none;
  }

  .docs-main-nav {
    /* reset absolute centering for mobile — flows in the wrap layout */
    position: static;
    transform: none;
    order: 3;
    flex-basis: 100%;
    justify-content: flex-start;
    overflow-x: auto;
    padding-bottom: 2px;
    padding-right: 32px;
    scrollbar-width: none;
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent 100%);
    mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent 100%);
  }

  .docs-main-nav::-webkit-scrollbar {
    display: none;
  }

  .docs-nav-link {
    min-height: 32px;
    padding-inline: 10px;
    font-size: 13px;
  }

  .sidebar-content a {
    min-height: 44px;
  }

  .sl-markdown-content table {
    font-size: 0.85rem;
  }

  th, td {
    padding: 8px 10px;
  }
}
