/* ============================================================
   CSS VARIABLES
   ============================================================ */
:root {
  --color-bg:           #0f0f0f;
  --color-surface:      #1a1a1a;
  --color-surface-2:    #242424;
  --color-border:       #2e2e2e;
  --color-text-primary: #e8e8e8;
  --color-text-muted:   #888888;
  --color-link:         #7eb8f7;
  --color-link-active:  #e8e8e8;

  --color-faster:       #e05a2b;  /* orange-red: faster car theme */
  --color-slower:       #3daa78;  /* teal-green: slower car theme */

  --sidebar-width:        260px;
  --header-height:        52px;
  --section-heading-h:    3.5rem; /* height of sticky section heading — must match rendered size */

  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --radius:    6px;
  --transition: 200ms ease;
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

[hidden] { display: none !important; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: 1.5rem;
  font-size: 16px;
}

body {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text-primary);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--color-link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ============================================================
   MOBILE HEADER (hidden on desktop)
   ============================================================ */
.site-header {
  display: none;
  align-items: center;
  gap: 0.75rem;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0 1rem;
  z-index: 300;
}

.site-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text-primary);
  letter-spacing: 0.01em;
}

/* ============================================================
   HAMBURGER BUTTON
   ============================================================ */
.hamburger {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex-shrink: 0;
}

.hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--color-text-primary);
  border-radius: 2px;
  transition: transform var(--transition), opacity var(--transition);
}

.hamburger.hamburger--active span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.hamburger.hamburger--active span:nth-child(2) {
  opacity: 0;
}
.hamburger.hamburger--active span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* ============================================================
   PAGE LAYOUT (CSS Grid)
   ============================================================ */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.sidebar-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
}

/* ============================================================
   TABLE OF CONTENTS
   ============================================================ */
.toc {
  padding: 0.75rem 0 1.5rem;
  overflow-y: auto;
}

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

.toc > ul > li {
  margin-bottom: 0.25rem;
}

/* Top-level section links */
.toc > ul > li > a {
  display: block;
  padding: 0.35rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-muted);
  transition: color var(--transition);
}

.toc > ul > li > a:hover,
.toc > ul > li > a.toc-link--active {
  text-decoration: none;
}

/* Section-colored top-level links */
.toc-section--faster > a { color: var(--color-faster); opacity: 0.8; }
.toc-section--faster > a:hover,
.toc-section--faster > a.toc-link--active { opacity: 1; color: var(--color-faster); }

.toc-section--slower > a { color: var(--color-slower); opacity: 0.8; }
.toc-section--slower > a:hover,
.toc-section--slower > a.toc-link--active { opacity: 1; color: var(--color-slower); }

/* Nested tip links */
.toc > ul > li > ul {
  margin-bottom: 0.5rem;
}

.toc > ul > li > ul > li > a {
  display: block;
  padding: 0.25rem 1rem 0.25rem 1.75rem;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  transition: color var(--transition);
  line-height: 1.4;
}

.toc > ul > li > ul > li > a:hover {
  color: var(--color-text-primary);
  text-decoration: none;
}

.toc-section--faster > ul > li > a.toc-link--active {
  color: var(--color-faster);
  font-weight: 600;
}

.toc-section--slower > ul > li > a.toc-link--active {
  color: var(--color-slower);
  font-weight: 600;
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
  padding: 3rem 2.5rem 4rem;
  width: 100%;
}

.page-title {
  font-size: 2.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 1rem;
  color: var(--color-text-primary);
}

.page-intro {
  font-size: 1.05rem;
  color: var(--color-text-muted);
  line-height: 1.75;
  margin-bottom: 3rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--color-border);
}

/* ============================================================
   GUIDE SECTIONS
   ============================================================ */
.guide-section {
  margin-bottom: 3.5rem;
}

.section-heading {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--color-bg);
}

.guide-section--faster .section-heading { color: var(--color-faster); }
.guide-section--slower .section-heading { color: var(--color-slower); }

.section-intro {
  font-size: 0.95rem;
  color: var(--color-text-muted);
  margin-bottom: 1.75rem;
  line-height: 1.7;
}

/* ============================================================
   TIP CARDS
   ============================================================ */
.tip-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0;
  margin-bottom: 3rem;
  scroll-margin-top: 1.5rem;
}

.guide-section--faster .tip-card { border-left: 3px solid var(--color-faster); }
.guide-section--slower .tip-card { border-left: 3px solid var(--color-slower); }

.tip-heading {
  font-size: 1.1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.65rem 1.25rem;
  background: var(--color-surface-2);
  border-bottom: 1px solid var(--color-border);
  border-radius: calc(var(--radius) - 1px) calc(var(--radius) - 1px) 0 0;
  margin: 0;
  position: sticky;
  top: var(--section-heading-h);
  z-index: 1;
}

.guide-section--faster .tip-heading { color: var(--color-faster); }
.guide-section--slower .tip-heading { color: var(--color-slower); }

.tip-body {
  padding: 1.25rem 1.5rem 1.5rem;
}

.tip-explanation {
  font-size: 0.95rem;
  line-height: 1.75;
  color: var(--color-text-primary);
}

.tip-explanation strong {
  font-weight: 600;
  padding: 0.05em 0.25em;
  border-radius: 3px;
}

.guide-section--faster .tip-explanation strong {
  color: var(--color-faster);
  background: rgba(224, 90, 43, 0.14);
}

.guide-section--slower .tip-explanation strong {
  color: var(--color-slower);
  background: rgba(61, 170, 120, 0.14);
}

/* ============================================================
   VIDEO GRID
   ============================================================ */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(520px, 1fr));
  gap: 1rem;
  margin-top: 1.25rem;
}

.video-grid:empty {
  display: none;
}

.video-item {
  margin: 0;
}

.video-item video {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius) var(--radius) 0 0;
  background: #000;
  display: block;
}

.video-caption {
  padding: 0.5rem 0.75rem 0.6rem;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
}

/* Badge injected by data-type on the parent figure */
.video-item[data-type] .video-caption {
  padding-top: 0.65rem;
}

.video-item[data-type] .video-caption::before {
  display: block;
  width: fit-content;
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  border-radius: 20px;
  padding: 0.2em 0.65em;
  margin-bottom: 0.45rem;
}

.video-item[data-type="good"] .video-caption::before {
  content: "✓  Good example";
  color: #4ade80;
  background: rgba(74, 222, 128, 0.1);
  border: 1px solid rgba(74, 222, 128, 0.28);
}

.video-item[data-type="bad"] .video-caption::before {
  content: "✗  What not to do";
  color: #f87171;
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.28);
}

.video-item[data-type="info"] .video-caption::before {
  content: "●  Context";
  color: #60a5fa;
  background: rgba(96, 165, 250, 0.1);
  border: 1px solid rgba(96, 165, 250, 0.28);
}

.video-caption-title {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--color-text-primary);
  margin-bottom: 0.2rem;
}

.video-caption-desc {
  display: block;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  line-height: 1.5;
}


/* ============================================================
   TIP CALLOUTS
   ============================================================ */
.tip-callout {
  margin: 1.25rem 0 0.25rem;
  padding: 0.8rem 1.1rem;
  background: rgba(255, 255, 255, 0.04);
  border-left: 3px solid var(--color-border);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--color-text-primary);
}

.tip-callout--rule {
  border-left-color: #fbbf24;
  background: rgba(251, 191, 36, 0.06);
}

.tip-callout--warning {
  border-left-color: #f87171;
  background: rgba(248, 113, 113, 0.06);
}

.tip-callout--insight {
  border-left-color: #60a5fa;
  background: rgba(96, 165, 250, 0.06);
}

/* ============================================================
   SCROLL SENTINEL
   ============================================================ */
.scroll-sentinel {
  height: 1px;
}

/* ============================================================
   MOBILE OVERLAY BACKDROP
   ============================================================ */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 199;
}

.sidebar-overlay.sidebar-overlay--visible {
  display: block;
}

/* ============================================================
   SITE FOOTER
   ============================================================ */
.site-footer {
  text-align: center;
  padding: 2rem 1.5rem;
  border-top: 1px solid var(--color-border);
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.site-footer strong {
  color: var(--color-text-primary);
}

.footer-name {
  display: inline;
  vertical-align: middle;
  position: relative;
  top: -1px;
}

/* ============================================================
   RESPONSIVE — MOBILE (≤768px)
   ============================================================ */
@media (max-width: 768px) {
  html {
    scroll-padding-top: calc(var(--header-height) + 0.5rem);
  }

  .site-header {
    display: flex;
  }

  .layout {
    grid-template-columns: 1fr;
    padding-top: var(--header-height);
  }

  .sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    width: 280px;
    height: calc(100vh - var(--header-height));
    height: calc(100dvh - var(--header-height));
    z-index: 200;
    transform: translateX(-100%);
    transition: transform var(--transition);
  }

  .sidebar.sidebar--open {
    transform: translateX(0);
  }

  .main-content {
    padding: 2rem 1.25rem 3rem;
  }

  .page-title {
    font-size: 1.75rem;
  }

  .video-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 1.75rem;
  }

  .section-heading {
    top: var(--header-height);
  }

  .tip-heading {
    top: calc(var(--header-height) + var(--section-heading-h));
  }
}

/* ============================================================
   RESPONSIVE — DESKTOP (>768px)
   ============================================================ */
@media (min-width: 769px) {
  .site-header {
    display: none;
  }
}
