/* Algocraft System Design — shared shell
   Common topnav, card, control, and lesson-layout styles used by every
   system-design sub-page (5 case studies + 20 concept pages), plus the
   mobile breakpoints those pages previously had none of. */

/* ── Topnav / breadcrumb bar ── */
#ac-topnav {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 99999;
  background: rgba(7, 8, 15, .95);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(255, 255, 255, .08);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 22px;
  height: 46px;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#ac-topnav a { color: #60a5fa; text-decoration: none; font-size: 13px; font-weight: 500; display: inline-flex; align-items: center; gap: 5px; transition: color .15s; }
#ac-topnav a:hover { color: #93c5fd; }
.ac-sep { color: rgba(148, 163, 184, .3); font-size: 14px; }
.ac-cur { color: #e2e8f0; font-size: 13px; font-weight: 500; }
.ac-logo { font-size: 14px; font-weight: 800; color: #f8fafc !important; }
.ac-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #a78bfa; margin-right: 4px; }
body { padding-top: 46px !important; }

/* ── Shared control-panel primitives (used by the 20 concept pages) ── */
.card { background: rgba(12, 12, 24, 0.95); border: 1px solid rgba(99, 102, 241, 0.15); border-radius: 12px; padding: 16px; }
.toggle-btn { padding: 6px 14px; border-radius: 8px; border: 1px solid rgba(99, 102, 241, 0.25); background: transparent; color: #94a3b8; cursor: pointer; font-size: 13px; font-weight: 500; transition: all .2s; }
.toggle-btn.active { background: rgba(99, 102, 241, 0.2); border-color: #6366f1; color: #a5b4fc; }
.ctrl-label { font-size: 11px; font-weight: 700; letter-spacing: .1em; color: #6366f1; text-transform: uppercase; margin-bottom: 8px; }

/* ── Shared scrollbar treatment for sticky/scrollable sidebars ── */
aside::-webkit-scrollbar, [style*="overflow-y:auto"]::-webkit-scrollbar { width: 4px; }
aside::-webkit-scrollbar-track, [style*="overflow-y:auto"]::-webkit-scrollbar-track { background: transparent; }
aside::-webkit-scrollbar-thumb, [style*="overflow-y:auto"]::-webkit-scrollbar-thumb { background: rgba(99, 102, 241, 0.28); border-radius: 4px; }
aside::-webkit-scrollbar-thumb:hover, [style*="overflow-y:auto"]::-webkit-scrollbar-thumb:hover { background: rgba(99, 102, 241, 0.55); }

/* ── Lesson layout: sidebar controls + main content ──
   Concept pages set this inline as style="display:grid;grid-template-columns:300px 1fr;gap:24px"
   (a few pages use 160/240/260/280px instead of 300px for the sidebar column).
   .sd-lesson-grid is the same shape for any page migrated to the class form. */
.sd-lesson-grid {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 24px;
}

/* ══════════════════════════════════════════════════════════════════
   Mobile responsiveness — the actual fix.
   Below ~900px the fixed 300px sidebar no longer fits next to content,
   so every lesson stacks to a single column and the sidebar stops being
   sticky/scroll-locked. Below ~560px the denser inner simulation grids
   (cache tiers, server grids, etc.) drop to fewer columns so nothing
   overflows horizontally on a phone.
   ══════════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  #ac-topnav { padding: 0 14px; gap: 7px; }
  #ac-topnav a span:not(.ac-dot) { display: none; }

  /* Classic CSS Grid overflow trap: an implicit grid track defaults to
     min-width:auto, so a child with intrinsic content width (e.g. a long
     unbroken description) can force the whole track wider than the
     viewport. Letting grid items shrink fixes it without touching markup. */
  .grid > * { min-width: 0; }

  .sd-lesson-grid,
  [style*="grid-template-columns:160px 1fr"], [style*="grid-template-columns: 160px 1fr"],
  [style*="grid-template-columns:240px 1fr"], [style*="grid-template-columns: 240px 1fr"],
  [style*="grid-template-columns:260px 1fr"], [style*="grid-template-columns: 260px 1fr"],
  [style*="grid-template-columns:280px 1fr"], [style*="grid-template-columns: 280px 1fr"],
  [style*="grid-template-columns:300px 1fr"], [style*="grid-template-columns: 300px 1fr"] {
    grid-template-columns: 1fr !important;
  }
  .sd-lesson-grid > *,
  [style*="grid-template-columns:160px 1fr"] > *, [style*="grid-template-columns: 160px 1fr"] > *,
  [style*="grid-template-columns:240px 1fr"] > *, [style*="grid-template-columns: 240px 1fr"] > *,
  [style*="grid-template-columns:260px 1fr"] > *, [style*="grid-template-columns: 260px 1fr"] > *,
  [style*="grid-template-columns:280px 1fr"] > *, [style*="grid-template-columns: 280px 1fr"] > *,
  [style*="grid-template-columns:300px 1fr"] > *, [style*="grid-template-columns: 300px 1fr"] > * {
    min-width: 0;
  }

  /* Sidebar itself may be <aside> or a plain sticky-positioned <div> —
     target the sticky behavior directly rather than the tag. */
  [style*="position:sticky"], [style*="position: sticky"] {
    position: static !important;
    top: auto !important;
    max-height: none !important;
    overflow-y: visible !important;
  }

  /* The breadcrumb bar itself can overflow its own fixed-width box on very
     narrow screens (long page titles + the "All Designs" link) — contain
     that inside the bar instead of letting it push the whole page wide. */
  #ac-topnav { overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  #ac-topnav::-webkit-scrollbar { display: none; }
}

@media (max-width: 640px) {
  .max-w-7xl { padding-left: 16px !important; padding-right: 16px !important; }

  /* Header icon/title rows and tag-pill rows are hand-written as inline
     `display:flex` with no wrap — safe to let them wrap generically once
     the row no longer fits (the breadcrumb bar opts out; it scrolls instead). */
  [style*="display:flex"]:not(#ac-topnav) { flex-wrap: wrap; }

  [style*="grid-template-columns:1fr 2fr 1fr"] { grid-template-columns: 1fr !important; }
  [style*="grid-template-columns:1fr auto 1fr"] { grid-template-columns: 1fr !important; }
  [style*="grid-template-columns:1fr 1fr 1fr"] { grid-template-columns: 1fr 1fr !important; }

  /* repeat(auto-fit,minmax(...)) is already responsive by design — leave it.
     Any other repeat(N,...) (3/4/5/6 fixed columns) is not, so fold it down. */
  [style*="grid-template-columns:repeat("]:not([style*="auto-fit"]) {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

@media (max-width: 480px) {
  body { padding-top: 42px !important; }
  #ac-topnav { height: 42px; padding: 0 10px; }
  .card { padding: 12px; }
}
