/**
 * Shared chapter-rail styles for all PickBits University tracks.
 *
 * Two render modes (selected by rail.js based on the page):
 *   1. INLINE — the rail sits in a CSS grid alongside .vibe-content (hub pages).
 *      Sticky positioning keeps it pinned while the right pane scrolls.
 *   2. FIXED  — the rail is position:fixed at the left of the viewport on
 *      module-index and lesson pages, where there's no enclosing grid.
 *
 * Both modes share the visual treatment + the collapse/expand UI; only the
 * positioning differs. Per-track palette is set via CSS custom properties
 * on .vibe-rail--<track>.
 */

:root {
    --uni-rail-width: 240px;
    --uni-rail-collapsed-width: 38px;
    --uni-rail-top: 88px;          /* clears the fixed site header */
}

/* Per-track accent palette (cyan / yellow / green) ----------------------- */
.vibe-rail--vibe-coder       { --rail-accent: #00f4ff; --rail-accent-rgb: 0, 244, 255; }
.vibe-rail--vibe-management  { --rail-accent: #ffe600; --rail-accent-rgb: 255, 230, 0; }
.vibe-rail--field-guides     { --rail-accent: #00ff88; --rail-accent-rgb: 0, 255, 136; }

/* Defensive resets — many module-page <style> blocks set generic tag
   selectors (e.g. `nav { display: flex }` on module-01) that bleed into
   the rail because rail.js injects a <nav class="vibe-rail-nav"> at runtime.
   Scope under aside.vibe-rail to win on specificity (0,0,2,1 > page's 0,0,0,1).
   Only override what's actually problematic — leave existing rail rules
   for ul/li/a/etc. to do their thing. */
aside.vibe-rail nav.vibe-rail-nav {
    display: block;
    flex-direction: initial;
    justify-content: initial;
    align-items: initial;
    max-width: none;
    margin: 0;
    padding: 0;
}
aside.vibe-rail .vibe-rail-section {
    display: block;
}

/* INLINE mode (hub pages) ------------------------------------------------- */
.vibe-layout {
    max-width: 1200px;
    margin: 2rem auto 0;
    padding: 0 1rem;
    display: grid;
    grid-template-columns: var(--uni-rail-width) 1fr;
    gap: 2.5rem;
    align-items: start;
}
.vibe-content { min-width: 0; }

.vibe-rail {
    position: sticky;
    top: var(--uni-rail-top);
    align-self: start;
    max-height: calc(100vh - var(--uni-rail-top) - 22px);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(var(--rail-accent-rgb, 0, 244, 255), 0.3) transparent;
}

/* PAGE mode (module-index + lesson pages) — rail and content are SIBLINGS
   inside a max-width centered grid (.uni-page-layout), matching the hub's
   .vibe-layout. The rail uses sticky positioning so it scrolls with the
   article. The track CTA is injected AFTER this layout (full-width sibling). */
.uni-page-layout {
    max-width: 1200px;
    margin: 2rem auto 0;
    padding: 0 1rem;
    display: grid;
    grid-template-columns: var(--uni-rail-width) 1fr;
    gap: 2.5rem;
    align-items: start;
}
.uni-page-layout > .vibe-rail {
    position: sticky;
    top: var(--uni-rail-top);
    align-self: start;
    max-height: calc(100vh - var(--uni-rail-top) - 22px);
    overflow-y: auto;
    background: transparent;
}
/* The page's <article> / <main> normally has its own max-width + margin:auto
   to center on the page. Inside the grid's right column those rules over-
   constrain it, so neutralize them — the grid column already handles width. */
.uni-page-layout > article,
.uni-page-layout > main {
    max-width: none;
    margin: 0;
    min-width: 0;
}

/* FIXED-mode fallback — used only when a page has no <article>/<main> to
   wrap. Pinned to the viewport's content gutter (not the corner). */
.vibe-rail--fixed {
    position: fixed;
    top: var(--uni-rail-top);
    /* max((vw - 1280px) / 2, 16px) — center the page up to 1280px and align
       the rail with that gutter; on narrower viewports clamp to a 16px gutter. */
    left: max(16px, calc((100vw - 1280px) / 2));
    width: var(--uni-rail-width);
    height: calc(100vh - var(--uni-rail-top) - 22px);
    overflow-y: auto;
    z-index: 90;                   /* below site header (z 1000), above content */
    padding: 0.75rem 0.75rem 1rem 0.75rem;
    /* Subtle dark background + accent border so the rail is clearly readable
       on every track and clearly distinct from the page-content area. */
    background: rgba(10, 10, 20, 0.6);
    backdrop-filter: blur(4px);
    border-right: 1px solid rgba(var(--rail-accent-rgb, 0, 244, 255), 0.18);
    border-radius: 0 4px 4px 0;
}
/* Body shift: leave room for the rail on the left. The shift = the rail's
   left offset + the rail's width + a comfortable gap to the article body. */
body.uni-rail-fixed {
    padding-left: calc(max(16px, (100vw - 1280px) / 2) + var(--uni-rail-width) + 1.5rem);
    transition: padding-left 0.18s ease;
}

.vibe-rail::-webkit-scrollbar { width: 6px; }
.vibe-rail::-webkit-scrollbar-thumb {
    background: rgba(var(--rail-accent-rgb, 0, 244, 255), 0.3);
    border-radius: 3px;
}

/* Toggle (collapse/expand) ----------------------------------------------- */
.vibe-rail-toggle {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 26px;
    height: 26px;
    background: transparent;
    border: 1px solid rgba(var(--rail-accent-rgb, 0, 244, 255), 0.3);
    border-radius: 3px;
    color: rgba(var(--rail-accent-rgb, 0, 244, 255), 0.85);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    z-index: 2;
    transition: all 0.15s;
}
.vibe-rail-toggle:hover {
    background: rgba(var(--rail-accent-rgb, 0, 244, 255), 0.1);
    border-color: rgba(var(--rail-accent-rgb, 0, 244, 255), 0.6);
    color: var(--rail-accent);
}
.vibe-rail-toggle .icon-collapsed { display: none; }
.vibe-rail.collapsed .vibe-rail-toggle .icon-expanded { display: none; }
.vibe-rail.collapsed .vibe-rail-toggle .icon-collapsed { display: inline; }

/* Collapsed state -------------------------------------------------------- */
/* min-height + overflow:visible keep the toggle button reachable in INLINE
   (sticky) mode, where hiding the inner would otherwise collapse the aside
   to 0px height and the absolutely-positioned toggle would be clipped. */
.vibe-rail.collapsed {
    width: var(--uni-rail-collapsed-width);
    min-height: 42px;
    overflow: visible;
}
.vibe-rail.collapsed .vibe-rail-inner { display: none; }
body.uni-rail-collapsed.uni-rail-fixed { padding-left: var(--uni-rail-collapsed-width); }
body.uni-rail-collapsed .vibe-layout,
body.uni-rail-collapsed .uni-page-layout { grid-template-columns: var(--uni-rail-collapsed-width) 1fr; gap: 1.25rem; }

/* Inner contents --------------------------------------------------------- */
.vibe-rail-inner {
    padding-top: 0.5rem;
    padding-right: 0.5rem;
    padding-bottom: 0.5rem;
}
.vibe-rail--fixed .vibe-rail-inner { padding-right: 0.25rem; }

.vibe-rail-heading {
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.7rem;
    color: rgba(var(--rail-accent-rgb, 0, 244, 255), 0.7);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    margin: 0 1.75rem 1rem 0;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(var(--rail-accent-rgb, 0, 244, 255), 0.15);
}

.vibe-rail-section { margin-bottom: 1.25rem; }
.vibe-rail-part {
    display: block;
    font-family: 'Rajdhani', sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.35rem 0 0.35rem 0.6rem;
    border-left: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
}
.vibe-rail-part:hover { color: var(--rail-accent); }
.vibe-rail-part.active { color: var(--rail-accent); border-left-color: var(--rail-accent); }

.vibe-rail-section ul {
    list-style: none;
    padding: 0;
    margin: 0.2rem 0 0;
}
/* Tree layout: each rail item is a block with a hanging indent. The number
   prefix sits at the start of the first line; long labels wrap and the
   continuation lines indent under the label text. No flex, no shrink fights. */
.vibe-rail-section ul a {
    display: block;
    font-family: 'Rajdhani', sans-serif;
    font-size: 0.78rem;
    color: rgba(224, 224, 224, 0.65);
    text-decoration: none;
    /* padding-left = .vibe-rail-num width (2em) + its margin-right (0.5em);
       text-indent = -(padding-left) so first-line content starts at the
       block's content edge and wrapped lines align under the label text. */
    padding: 0.3rem 0.4rem 0.3rem 2.5em;
    text-indent: -2.5em;
    border-left: 2px solid transparent;
    line-height: 1.35;
    overflow-wrap: break-word;
    transition: color 0.15s, background-color 0.15s, border-color 0.15s;
}
.vibe-rail-section ul a:hover {
    color: var(--rail-accent);
    background: rgba(var(--rail-accent-rgb, 0, 244, 255), 0.04);
    border-left-color: rgba(var(--rail-accent-rgb, 0, 244, 255), 0.4);
}
.vibe-rail-section ul a.active,
.vibe-rail-section ul a.current {
    color: var(--rail-accent);
    background: rgba(var(--rail-accent-rgb, 0, 244, 255), 0.07);
    border-left-color: var(--rail-accent);
}

.vibe-rail-num {
    display: inline-block;
    width: 2em;
    margin-right: 0.5em;
    text-indent: 0;
    text-align: left;
    /* Keep numbers like "1.1" and "4.5" on a single line — at 0.7rem monospace
       the period can otherwise be a wrap point inside the inline-block. */
    white-space: nowrap;
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.7rem;
    color: rgba(var(--rail-accent-rgb, 0, 244, 255), 0.65);
    vertical-align: baseline;
}
/* The label span (added so older callsites had a flex item) is now just inline
   text in the new tree layout. Kept as a no-op selector for clarity. */
.vibe-rail-label { display: inline; }
.vibe-rail-section ul a.active .vibe-rail-num,
.vibe-rail-section ul a.current .vibe-rail-num { color: var(--rail-accent); }

.vibe-rail-coming {
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.75rem;
    color: rgba(255, 230, 0, 0.7);
    padding: 0.25rem 0 0.25rem 0.6rem;
    border-left: 2px solid rgba(255, 230, 0, 0.25);
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
}
.vibe-rail-coming .vibe-rail-num { color: rgba(255, 230, 0, 0.85); }

/* Nested guides — small indented list under each module's <li>.
   Hidden by default; only the currently-selected module reveals its
   expansion guides (LI gets `.vibe-rail-li--expanded`). Keeps the rail
   readable when a track has many modules with deep guide lists. */
.vibe-rail-nav li > .vibe-rail-guides { display: none; }
.vibe-rail-nav li.vibe-rail-li--expanded > .vibe-rail-guides { display: block; }

.vibe-rail-guides {
    list-style: none;
    margin: 0.15rem 0 0.35rem 0;
    padding: 0;
}
.vibe-rail-guides li { margin: 0; }
.vibe-rail-guide {
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
    padding: 0.2rem 0.4rem 0.2rem 2.5em;
    color: rgba(224, 224, 224, 0.5);
    text-decoration: none;
    font-size: 0.78rem;
    line-height: 1.3;
    border-left: 2px solid transparent;
    transition: color 0.15s, background-color 0.15s, border-color 0.15s;
}
.vibe-rail-guide-bullet {
    color: rgba(var(--rail-accent-rgb, 0, 244, 255), 0.5);
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.85rem;
    line-height: 1;
    flex-shrink: 0;
}
.vibe-rail-guide-label { flex: 1; }
.vibe-rail-guide:hover {
    color: var(--rail-accent);
    background: rgba(var(--rail-accent-rgb, 0, 244, 255), 0.04);
    border-left-color: rgba(var(--rail-accent-rgb, 0, 244, 255), 0.3);
}
.vibe-rail-guide:hover .vibe-rail-guide-bullet { color: var(--rail-accent); }
.vibe-rail-guide.active,
.vibe-rail-guide.current {
    color: var(--rail-accent);
    background: rgba(var(--rail-accent-rgb, 0, 244, 255), 0.07);
    border-left-color: var(--rail-accent);
}
.vibe-rail-guide.active .vibe-rail-guide-bullet,
.vibe-rail-guide.current .vibe-rail-guide-bullet { color: var(--rail-accent); }

/* Brief flash on the in-page guide LI when activated from the rail. */
.vibe-guide-flash {
    animation: vibe-guide-flash 1.6s ease-out;
}
@keyframes vibe-guide-flash {
    0%   { background: rgba(var(--rail-accent-rgb, 0, 244, 255), 0); }
    20%  { background: rgba(var(--rail-accent-rgb, 0, 244, 255), 0.18); }
    100% { background: rgba(var(--rail-accent-rgb, 0, 244, 255), 0); }
}

/* Guide pane — fetches a standalone .html guide and renders its <article>
   inline in the right column. The standalone .html stays alive for SEO + deep
   links; the hub uses fetch+inject so visitors stay in the SPA-style flow. */
.guide-pane {
    padding: 1.5rem 0 3rem;
    min-height: 600px;
}
.guide-pane[hidden] { display: none; }
/* While a guide is open, collapse the rest of the right column so empty
   .modules-grid / .section-header wrappers don't push the guide pane down. */
.vibe-content[data-guide-open="1"] > *:not(.guide-pane) { display: none !important; }
/* In single-pane mode the .module-card children of a non-target grid are all
   display:none, but the grid wrapper still contributes its margin-bottom and
   gap — leaving dead vertical space between visible parts. Collapse any grid
   that has no .is-active card. */
.vibe-content[data-rail-mode="single"] .modules-grid:not(:has(.module-card.is-active)),
.vibe-content[data-rail-mode="single"] .vm-modules-grid:not(:has(.module-card.is-active)) {
    display: none;
}
.guide-back {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.85rem;
    margin-bottom: 1.5rem;
    color: var(--rail-accent, #00f4ff);
    text-decoration: none;
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    border: 1px solid rgba(var(--rail-accent-rgb, 0, 244, 255), 0.35);
    border-radius: 4px;
    transition: background 0.15s, border-color 0.15s;
}
.guide-back:hover {
    background: rgba(var(--rail-accent-rgb, 0, 244, 255), 0.08);
    border-color: var(--rail-accent, #00f4ff);
}
.guide-pane-loading,
.guide-pane-error {
    padding: 3rem 1.5rem;
    text-align: center;
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.9rem;
    color: rgba(224, 224, 224, 0.7);
    border: 1px dashed rgba(var(--rail-accent-rgb, 0, 244, 255), 0.25);
    border-radius: 6px;
}
.guide-pane-error { color: #ff6b6b; border-color: rgba(255, 107, 107, 0.35); }
.guide-pane-error a { color: var(--rail-accent, #00f4ff); border-bottom: 1px dotted; text-decoration: none; }

/* Strip nested page-chrome that the standalone <article> may have included. */
.guide-pane-article > nav.breadcrumb,
.guide-pane-article > .breadcrumb,
.guide-pane-article > .back-link { display: none; }

/* Article hero — pulled from the standalone page's sibling <section> so the
   SPA pane shows the title + meta, not just the body. Restyled in-pane to
   read as a compact header (the standalone version is a full-bleed
   gradient hero, which would look out of place inside the right column). */
.guide-pane-article .article-hero {
    margin: 0 0 1.75rem;
    padding: 0 0 1.25rem;
    border-bottom: 1px solid rgba(0, 244, 255, 0.18);
    text-align: left;
    background: none;
}
.guide-pane-article .article-hero .breadcrumb {
    display: block;
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(157, 0, 255, 0.85);
    margin-bottom: 0.6rem;
}
.guide-pane-article .article-hero .breadcrumb a {
    color: rgba(157, 0, 255, 0.95);
    border-bottom: none;
    text-decoration: none;
}
.guide-pane-article .article-hero .breadcrumb a:hover { color: var(--cyber-purple, #9d00ff); }
.guide-pane-article .article-hero h1 {
    font-family: 'Share Tech Mono', monospace;
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #fff;
    margin: 0 0 0.4rem;
}
.guide-pane-article .article-hero h1 span {
    color: var(--cyber-blue, #00f4ff);
}
.guide-pane-article .article-hero .article-meta {
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    color: var(--cyber-blue, #00f4ff);
    margin: 0;
}

/* Article typography for the in-pane SPA view.
   Standalone guide pages style their content with bare-element selectors
   (h1, h2, p, pre…) defined in their inline <style>. Those rules don't
   travel with the fetched <article>, so without scoping the hub's globals
   would win — giving us 40px centered headings and no max-width on the
   body. Mirror the standalone look here, scoped to .guide-pane-article. */
.guide-pane-article {
    max-width: 760px;
    margin: 0 auto;
    padding: 0 0.5rem;
    font-family: 'Rajdhani', 'Segoe UI', Tahoma, sans-serif;
    color: var(--text-color, #e0e0e0);
    line-height: 1.7;
    text-align: left;
}
.guide-pane-article h1 {
    font-family: 'Share Tech Mono', monospace;
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #fff;
    text-align: left;
    margin: 0 0 1rem;
}
.guide-pane-article h2 {
    font-family: 'Share Tech Mono', monospace;
    font-size: 1.15rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--cyber-green, #00ff88);
    text-align: left;
    margin: 2rem 0 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(0, 255, 136, 0.3);
}
.guide-pane-article h3 {
    font-family: 'Share Tech Mono', monospace;
    font-size: 1rem;
    font-weight: 600;
    color: var(--cyber-blue, #00f4ff);
    text-align: left;
    margin: 1.5rem 0 0.75rem;
}
.guide-pane-article h4 {
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.9rem;
    color: var(--cyber-yellow, #ffe600);
    text-align: left;
    margin: 1.25rem 0 0.5rem;
}
.guide-pane-article p {
    font-size: 0.95rem;
    margin: 0 0 1rem;
}
.guide-pane-article ul,
.guide-pane-article ol {
    margin: 0 0 1rem 1.5rem;
    padding: 0;
}
.guide-pane-article li { margin-bottom: 0.5rem; }
.guide-pane-article a {
    color: var(--cyber-blue, #00f4ff);
    text-decoration: none;
    border-bottom: 1px dotted rgba(0, 244, 255, 0.5);
}
.guide-pane-article a:hover { border-bottom-style: solid; }
.guide-pane-article code {
    background: rgba(0, 244, 255, 0.1);
    border: 1px solid rgba(0, 244, 255, 0.2);
    padding: 0.1rem 0.35rem;
    border-radius: 2px;
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.85em;
    color: var(--cyber-blue, #00f4ff);
}
.guide-pane-article pre {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(157, 0, 255, 0.2);
    border-radius: 4px;
    padding: 1rem;
    margin: 1rem 0;
    overflow-x: auto;
    font-size: 0.8rem;
    line-height: 1.55;
}
.guide-pane-article pre code {
    background: none;
    border: none;
    padding: 0;
    color: var(--text-color, #e0e0e0);
    font-size: inherit;
}
.guide-pane-article blockquote {
    margin: 1rem 0;
    padding: 0.5rem 1rem;
    border-left: 3px solid var(--cyber-purple, #9d00ff);
    background: rgba(157, 0, 255, 0.05);
    color: rgba(224, 224, 224, 0.85);
}
.guide-pane-article hr {
    border: none;
    border-top: 1px solid rgba(0, 244, 255, 0.18);
    margin: 2rem 0;
}
/* Common content boxes the standalone pages use. */
.guide-pane-article .highlight-box {
    background: linear-gradient(135deg, rgba(0, 255, 136, 0.1), rgba(0, 244, 255, 0.05));
    border: 1px solid rgba(0, 255, 136, 0.3);
    border-radius: 4px;
    padding: 1rem;
    margin: 1.5rem 0;
}
.guide-pane-article .highlight-box h4 { color: var(--cyber-green, #00ff88); margin-top: 0; }
.guide-pane-article .warning-box {
    background: linear-gradient(135deg, rgba(255, 230, 0, 0.1), rgba(255, 107, 107, 0.05));
    border: 1px solid rgba(255, 230, 0, 0.3);
    border-radius: 4px;
    padding: 1rem;
    margin: 1.5rem 0;
}
.guide-pane-article .warning-box h4 { color: var(--cyber-yellow, #ffe600); margin-top: 0; }
.guide-pane-article .quick-ref {
    background: rgba(10, 10, 20, 0.8);
    border: 1px solid rgba(157, 0, 255, 0.3);
    border-radius: 4px;
    padding: 1.25rem;
    margin-top: 2rem;
}
.guide-pane-article .quick-ref h3 { color: var(--cyber-purple, #9d00ff); margin-top: 0; }

/* Mobile — hide rail, reset body shift -------------------------------------- */
@media (max-width: 1024px) {
    .vibe-layout { grid-template-columns: 1fr; gap: 0; }
    .uni-page-layout { display: block; padding: 0; margin-top: 0; }
    .vibe-rail { display: none; }
    body.uni-rail-fixed { padding-left: 0; }
    body.uni-rail-collapsed.uni-rail-fixed { padding-left: 0; }
}
