/* Shared left rail: fixed back/name link, vertically centred nav, theme toggle */
:root { --rail-w: 200px; --rail-gap: 40px; --rail-x: max(24px, calc((100vw - 1160px) / 2)); }
.rail { position: fixed; z-index: 20; top: 0; bottom: 0; left: var(--rail-x); width: var(--rail-w);
  display: flex; flex-direction: column; justify-content: space-between; padding: var(--s-2xl) 0; }
.back { align-self: flex-start; display: inline-flex; align-items: center; gap: var(--s-sm); min-height: 32px; font-size: 14px; line-height: 16px; font-weight: 500; color: var(--fg-1); border-bottom: 1px solid transparent; transition: border-color .15s var(--ease-out); }
.back:hover { border-bottom-color: var(--fg); }
.back svg { transition: transform .2s var(--ease-out); }
.back:hover svg { transform: translateX(-3px); }
.side { flex: 1; display: flex; flex-direction: column; justify-content: center; }
.side-title { font-size: 13px; line-height: 18px; font-weight: 500; color: var(--muted); margin-bottom: var(--s-md); }
.side ul { border-top: 1px solid var(--line); }
.side .side-link { display: block; padding: var(--s-md) var(--s-md); border-bottom: 1px solid var(--line); border-left: 2px solid transparent; transition: border-color .15s var(--ease-out), background-color .15s var(--ease-out); }
.side .side-link b { display: block; font-size: 14px; line-height: 20px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase; color: var(--fg-2); transition: color .15s var(--ease-out); }
.side .side-link span { display: block; margin-top: 2px; font-size: 12px; line-height: 18px; color: var(--muted); }
.side .side-link:hover { background: var(--bg-1); }
.side .side-link:hover b { color: var(--fg); }
.side .side-link[aria-current] { border-left-color: var(--fg); background: var(--bg); }
.side .side-link[aria-current] b { color: var(--fg); font-weight: 700; }
.rail .toggle { align-self: flex-start; }

.menu-btn { display: none; }
@media (max-width: 960px) {
  /* Mobile top bar: pinned to the top while the page scrolls. Back on the left, theme and menu on the right. */
  html { scroll-padding-top: 84px; }
  .rail { position: fixed; left: 0; right: 0; bottom: auto; width: auto; padding: var(--s-md) var(--s-lg); flex-direction: row; align-items: center; gap: var(--s-sm);
    background: var(--bg); border-bottom: 1px solid var(--line); }
  .rail .toggle { order: 2; margin-left: auto; min-height: 44px; }
  .menu-btn { order: 3; display: inline-grid; place-items: center; width: 44px; height: 44px; margin-right: -10px; border-radius: var(--r-md); color: var(--fg); }
  .menu-btn:hover { background: var(--bg-1); }
  .menu-btn:focus-visible { outline: 2px solid var(--fg); outline-offset: 0; }
  .menu-btn .i-close { display: none; }
  .menu-btn[aria-expanded="true"] .i-open { display: none; }
  .menu-btn[aria-expanded="true"] .i-close { display: block; }
  .side { display: none; position: absolute; top: 100%; left: 0; right: 0; max-height: calc(100dvh - 76px); overflow-y: auto; overscroll-behavior: contain;
    padding: var(--s-sm) var(--s-lg) var(--s-xl); background: var(--bg); border-bottom: 1px solid var(--line); box-shadow: 0 16px 32px -16px rgba(0,0,0,.18); }
  .side.is-open { display: block; animation: menu-in .18s var(--ease-out); }
  @keyframes menu-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
  .side .side-link { padding: var(--s-md) var(--s-md); }
  .side .side-link b { font-size: 14px; }
  .menu-scrim { position: fixed; inset: 0; z-index: 19; background: rgba(0,0,0,.2); }
  .menu-scrim[hidden] { display: none; }
}
@media (max-width: 960px) and (prefers-reduced-motion: reduce) { .side.is-open { animation: none; } }

/* Indented submenu */
.side { overflow-y: auto; scrollbar-width: none; }
.side::-webkit-scrollbar { display: none; }
.side-sub { padding: var(--s-xs) 0 var(--s-md) var(--s-md); border-bottom: 1px solid var(--line); }
.side-sub a { display: flex; align-items: baseline; gap: 10px; padding: 5px 0 5px var(--s-md); font-size: 13px; line-height: 18px; color: var(--muted); transition: color .15s var(--ease-out), border-color .15s var(--ease-out); }
.side-sub a em { flex: none; font-style: normal; font-family: var(--font-mono); font-size: 10.5px; color: var(--muted-2); }
.side-sub a:hover { color: var(--fg); }
.side-sub a.is-on { color: var(--fg); font-weight: 600; }
.side-sub a.is-on em { color: var(--fg-1); }
.side li:has(.side-sub) > .side-link { border-bottom-color: transparent; }
