/* ── Design tokens ──────────────────────────────────────────────────────────── */
:root {
  /* Backgrounds */
  --bg-base:    #07090f;
  --bg-surface: #0d1120;
  --bg-raised:  #121929;
  --bg-overlay: #18253d;
  --bg-modal:   #0f1726;

  /* Borders */
  --border-dim:     rgba(255,255,255,.05);
  --border-default: rgba(255,255,255,.08);
  --border-strong:  rgba(255,255,255,.13);
  --border-orange:  rgba(232,119,34,.3);

  /* Brand – orange */
  --orange-600: #b8591a;
  --orange-500: #e87722;
  --orange-400: #f09040;
  --orange-300: #f5b578;
  --orange-tint: rgba(232,119,34,.10);
  --orange-glow: 0 0 24px rgba(232,119,34,.18);

  /* Brand – navy */
  --navy-600: #111b2e;
  --navy-500: #162540;
  --navy-400: #1e3358;
  --navy-300: #2a4878;

  /* Text */
  --text-primary:   #dce4f0;
  --text-secondary: #7a90ad;
  --text-muted:     #3d5070;
  --text-accent:    var(--orange-400);

  /* Radius */
  --radius-sm: 5px;
  --radius-md: 9px;
  --radius-lg: 14px;

  /* Shadows */
  --shadow-sm: 0 1px 4px rgba(0,0,0,.5);
  --shadow-md: 0 4px 20px rgba(0,0,0,.55);
  --shadow-lg: 0 12px 48px rgba(0,0,0,.65);

  --sidebar-width: 256px;
  --header-height: 60px;
}

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.7;
  color: var(--text-primary);
  background: var(--bg-base);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--orange-400); text-decoration: none; transition: color .15s; }
a:hover { color: var(--orange-300); }

code {
  font-family: 'SF Mono', 'Fira Code', ui-monospace, monospace;
  font-size: .85em;
  color: var(--orange-300);
  background: rgba(232,119,34,.1);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid rgba(232,119,34,.15);
}

/* Scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.18); }

/* ── Logo / brand ───────────────────────────────────────────────────────────── */
.logo-text {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 800;
  font-size: 1.55rem;
  color: var(--text-primary);
  letter-spacing: .03em;
  line-height: 1;
}
.logo-accent { color: var(--orange-500); }

/* ── Site header ────────────────────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
  background: rgba(7,9,15,.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-dim);
  box-shadow: 0 1px 0 rgba(232,119,34,.25), var(--shadow-sm);
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.header-brand { display: flex; align-items: baseline; gap: 8px; text-decoration: none; }
.header-subtitle {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 600;
  font-size: .78rem;
  color: var(--text-muted);
  letter-spacing: .14em;
}
.header-nav { display: flex; align-items: center; gap: 4px; }
.nav-link {
  font-size: .83rem;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 6px 13px;
  border-radius: var(--radius-sm);
  transition: color .15s, background .15s;
  cursor: pointer;
}
.nav-link:hover { color: var(--text-primary); background: rgba(255,255,255,.05); }
.nav-admin {
  background: var(--orange-500);
  color: #fff !important;
  font-weight: 600;
  letter-spacing: .02em;
}
.nav-admin:hover { background: var(--orange-400); color: #fff; }

/* ── Hero ───────────────────────────────────────────────────────────────────── */
.hero {
  background: linear-gradient(155deg, #05070d 0%, #0a1220 55%, #0d1828 100%);
  padding: 52px 24px 44px;
  position: relative;
  overflow: hidden;
}
/* Diagonal stripe pattern */
.hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    -55deg,
    transparent 0px,
    transparent 28px,
    rgba(232,119,34,.025) 28px,
    rgba(232,119,34,.025) 56px
  );
  pointer-events: none;
}
/* Bottom fade line */
.hero::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(232,119,34,.4) 30%, rgba(232,119,34,.4) 70%, transparent);
}
.hero-inner { max-width: 1400px; margin: 0 auto; position: relative; z-index: 1; }
.hero-stripe {
  width: 40px;
  height: 4px;
  background: var(--orange-500);
  border-radius: 2px;
  margin-bottom: 18px;
  box-shadow: var(--orange-glow);
}
.hero-title {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 800;
  font-size: clamp(2.2rem, 5vw, 3.8rem);
  color: var(--text-primary);
  letter-spacing: .01em;
  line-height: 1.05;
  margin-bottom: 16px;
}
.hero-title span { color: var(--orange-500); }
.hero-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.version-badge {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700;
  font-size: .92rem;
  background: var(--orange-500);
  color: #fff;
  padding: 3px 13px;
  border-radius: 20px;
  letter-spacing: .07em;
  box-shadow: var(--orange-glow);
}
.meta-sep { color: var(--text-muted); }
.last-updated { font-size: .85rem; color: var(--text-secondary); }
.ref-note {
  display: inline-flex;
  align-items: flex-start;
  gap: 8px;
  font-size: .82rem;
  color: var(--text-secondary);
  background: rgba(255,255,255,.03);
  border: 1px solid var(--border-dim);
  border-left: 3px solid rgba(232,119,34,.35);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  max-width: 600px;
  line-height: 1.55;
}
.ref-note code { font-size: .9em; }

/* ── Main layout ────────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  max-width: 1400px;
  margin: 0 auto;
  min-height: calc(100vh - var(--header-height));
}

/* ── Sidebar ────────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height));
  overflow-y: auto;
  border-right: 1px solid var(--border-dim);
  background: var(--bg-surface);
}
.sidebar-inner {
  padding: 20px 14px 32px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* Search */
.search-wrap { position: relative; display: flex; align-items: center; }
.search-icon {
  position: absolute;
  left: 10px;
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  pointer-events: none;
}
.search-input {
  width: 100%;
  padding: 8px 30px 8px 32px;
  background: var(--bg-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  font-size: .83rem;
  color: var(--text-primary);
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.search-input::placeholder { color: var(--text-muted); }
.search-input:focus {
  border-color: var(--orange-500);
  box-shadow: 0 0 0 3px rgba(232,119,34,.1);
}
.search-clear {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: .7rem;
  padding: 3px 5px;
  border-radius: 3px;
  line-height: 1;
  transition: color .15s;
}
.search-clear:hover { color: var(--text-primary); }

/* TOC */
.toc-heading {
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding-left: 6px;
  margin-bottom: 6px;
}
.toc-list { list-style: none; }
.toc-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  font-size: .8rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color .15s, background .15s;
  line-height: 1.4;
  cursor: pointer;
}
.toc-link:hover { color: var(--text-primary); background: rgba(255,255,255,.04); }
.toc-link.active { color: var(--orange-400); background: var(--orange-tint); font-weight: 600; }
.toc-num {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  background: var(--bg-overlay);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .68rem;
  font-weight: 700;
  color: var(--text-muted);
  font-family: 'Barlow Condensed', sans-serif;
  transition: background .15s, color .15s;
}
.toc-link.active .toc-num { background: var(--orange-500); color: #fff; }

.sidebar-changelog-link {
  font-size: .78rem;
  font-weight: 500;
  color: var(--text-muted);
  padding: 6px;
  display: block;
  text-align: center;
  transition: color .2s;
  border-top: 1px solid var(--border-dim);
  padding-top: 14px;
}
.sidebar-changelog-link:hover { color: var(--orange-400); }

/* ── Content area ───────────────────────────────────────────────────────────── */
.content {
  flex: 1;
  min-width: 0;
  padding: 36px 44px 80px;
}

/* ── Loading ────────────────────────────────────────────────────────────────── */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 0;
  gap: 16px;
  color: var(--text-muted);
}
.spinner {
  width: 32px;
  height: 32px;
  border: 2px solid var(--bg-overlay);
  border-top-color: var(--orange-500);
  border-radius: 50%;
  animation: spin .65s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.no-results { text-align: center; padding: 60px 0; color: var(--text-muted); }

/* ── Rule sections ──────────────────────────────────────────────────────────── */
.rule-section {
  margin-bottom: 52px;
  scroll-margin-top: calc(var(--header-height) + 24px);
}
.section-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-dim);
  position: relative;
}
.section-header::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 40px;
  height: 2px;
  background: var(--orange-500);
  border-radius: 2px;
  box-shadow: var(--orange-glow);
}
.section-num {
  flex-shrink: 0;
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 800;
  font-size: 2rem;
  color: var(--orange-500);
  line-height: 1;
  min-width: 36px;
}
.section-title {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700;
  font-size: 1.4rem;
  color: var(--text-primary);
  letter-spacing: .03em;
  line-height: 1.2;
}

/* ── Rule cards ─────────────────────────────────────────────────────────────── */
.rule-list { display: flex; flex-direction: column; gap: 6px; }

.rule-item {
  background: var(--bg-surface);
  border: 1px solid var(--border-dim);
  border-left: 3px solid var(--orange-500);
  border-radius: var(--radius-md);
  padding: 13px 16px 14px;
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.rule-item:hover {
  background: var(--bg-raised);
  border-color: var(--border-default);
  border-left-color: var(--orange-400);
  box-shadow: var(--shadow-sm);
}

.rule-item.depth-1 {
  border-left-color: var(--navy-400);
  margin-left: 22px;
  background: rgba(13,17,32,.6);
}
.rule-item.depth-1:hover { border-left-color: var(--navy-300); }

.rule-item.depth-2 {
  border-left-color: rgba(255,255,255,.12);
  margin-left: 44px;
  background: rgba(10,14,26,.5);
}
.rule-item.depth-3,
.rule-item.depth-4 {
  border-left-color: rgba(255,255,255,.07);
  margin-left: 66px;
  background: rgba(8,11,20,.5);
}

.rule-item.is-conditional { border-left-style: dashed; }
.rule-item.is-conditional .rule-id::before { content: '◌ '; }

/* rule internals */
.rule-header {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.rule-id {
  font-family: ui-monospace, 'SF Mono', monospace;
  font-size: .72rem;
  font-weight: 600;
  color: var(--orange-400);
  background: rgba(232,119,34,.08);
  border: 1px solid rgba(232,119,34,.15);
  padding: 2px 7px;
  border-radius: 4px;
  flex-shrink: 0;
  margin-top: 1px;
  letter-spacing: .04em;
}
.rule-tag {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  background: rgba(255,255,255,.05);
  border: 1px solid var(--border-default);
  padding: 2px 8px;
  border-radius: 4px;
  flex-shrink: 0;
  margin-top: 1px;
}
.rule-badges { display: flex; gap: 5px; flex-wrap: wrap; align-items: center; margin-top: 1px; }
.rule-text { font-size: .92rem; color: var(--text-primary); line-height: 1.7; }
.rule-note {
  margin-top: 7px;
  font-size: .79rem;
  color: var(--text-secondary);
  font-style: italic;
  padding-left: 10px;
  border-left: 2px solid var(--border-default);
}
.rule-note::before { content: 'Note: '; font-weight: 600; font-style: normal; color: var(--text-muted); }
.rule-children { margin-top: 10px; display: flex; flex-direction: column; gap: 5px; }

/* Search highlight */
.rule-item.search-match { border-color: var(--border-orange); background: var(--bg-raised); }
.rule-item.search-match .rule-id { border-color: rgba(232,119,34,.35); background: rgba(232,119,34,.12); }

/* ── Penalty badges ─────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 4px;
  line-height: 1.6;
  white-space: nowrap;
}
.badge-minor           { background: rgba(251,191,36,.1);  color: #fbbf24; border: 1px solid rgba(251,191,36,.2); }
.badge-medium          { background: rgba(232,119,34,.12); color: #f09040; border: 1px solid rgba(232,119,34,.22); }
.badge-major           { background: rgba(239,68,68,.12);  color: #f87171; border: 1px solid rgba(239,68,68,.22); }
.badge-dsq             { background: rgba(153,27,27,.25);  color: #fca5a5; border: 1px solid rgba(185,28,28,.3); }
.badge-qualifying-ban  { background: rgba(124,58,237,.12); color: #c4b5fd; border: 1px solid rgba(124,58,237,.22); }
.badge-racing-incident { background: rgba(59,130,246,.12); color: #93c5fd; border: 1px solid rgba(59,130,246,.22); }
.badge-penalty-point   { background: rgba(16,185,129,.1);  color: #6ee7b7; border: 1px solid rgba(16,185,129,.2); }
.badge-conditional     { background: rgba(255,255,255,.05); color: var(--text-secondary); border: 1px solid var(--border-dim); }

/* ── Changelog ──────────────────────────────────────────────────────────────── */
.changelog-section {
  margin-top: 72px;
  padding-top: 44px;
  border-top: 1px solid var(--border-dim);
  scroll-margin-top: calc(var(--header-height) + 24px);
}
.changelog-section .section-title { margin-bottom: 28px; }
.changelog-list { display: flex; flex-direction: column; gap: 12px; }
.changelog-entry {
  background: var(--bg-surface);
  border: 1px solid var(--border-dim);
  border-left: 3px solid var(--orange-500);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  transition: border-color .15s;
}
.changelog-entry:hover { border-color: var(--border-default); border-left-color: var(--orange-400); }
.changelog-meta { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.changelog-version {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700;
  font-size: .88rem;
  background: var(--bg-overlay);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
  padding: 2px 10px;
  border-radius: 4px;
  letter-spacing: .06em;
}
.changelog-date { font-size: .8rem; color: var(--text-muted); }
.changelog-note { font-size: .9rem; color: var(--text-primary); font-weight: 500; margin-bottom: 6px; }
.changelog-changes { list-style: none; display: flex; flex-direction: column; gap: 3px; }
.changelog-change {
  font-size: .8rem;
  color: var(--text-secondary);
  padding-left: 14px;
  position: relative;
}
.changelog-change::before { content: '›'; position: absolute; left: 2px; color: var(--orange-500); font-weight: 700; }
.change-type {
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .05em;
  padding: 1px 6px;
  border-radius: 3px;
  margin-right: 6px;
  text-transform: uppercase;
}
.change-type-edit   { background: rgba(59,130,246,.12);  color: #93c5fd; }
.change-type-add    { background: rgba(16,185,129,.12);  color: #6ee7b7; }
.change-type-delete { background: rgba(239,68,68,.12);   color: #f87171; }

/* ── Footer ─────────────────────────────────────────────────────────────────── */
.site-footer {
  background: var(--bg-surface);
  border-top: 1px solid var(--border-dim);
  padding: 18px 24px;
  color: var(--text-muted);
  font-size: .8rem;
}
.footer-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
}
.footer-brand { color: var(--text-secondary); font-weight: 600; }
.footer-sep { color: var(--border-default); }

/* ── Back to top ────────────────────────────────────────────────────────────── */
.back-to-top {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 40px;
  height: 40px;
  background: var(--bg-overlay);
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
  transition: background .2s, color .2s, border-color .2s, transform .15s;
  z-index: 50;
}
.back-to-top svg { width: 16px; height: 16px; }
.back-to-top:hover {
  background: var(--orange-500);
  border-color: var(--orange-500);
  color: #fff;
  transform: translateY(-2px);
}

/* ── Shared form elements ───────────────────────────────────────────────────── */
.form-label {
  display: block;
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  letter-spacing: .03em;
}
.form-input {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  font-size: .88rem;
  font-family: inherit;
  color: var(--text-primary);
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.form-input::placeholder { color: var(--text-muted); }
.form-input:focus {
  border-color: var(--orange-500);
  box-shadow: 0 0 0 3px rgba(232,119,34,.1);
  background: var(--bg-overlay);
}
.form-textarea { resize: vertical; min-height: 80px; }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 18px;
  font-size: .85rem;
  font-weight: 600;
  font-family: inherit;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s, box-shadow .15s;
  white-space: nowrap;
  text-decoration: none;
  line-height: 1;
  letter-spacing: .01em;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }

.btn-primary   { background: var(--orange-500); color: #fff; border-color: var(--orange-500); }
.btn-primary:hover:not(:disabled) { background: var(--orange-400); border-color: var(--orange-400); box-shadow: var(--orange-glow); }

.btn-secondary { background: var(--bg-overlay); color: var(--text-primary); border-color: var(--border-default); }
.btn-secondary:hover:not(:disabled) { background: var(--navy-400); border-color: var(--border-strong); }

.btn-ghost     { background: transparent; color: var(--text-secondary); border-color: var(--border-default); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-raised); color: var(--text-primary); border-color: var(--border-strong); }

.btn-danger    { background: rgba(185,28,28,.15); color: #f87171; border-color: rgba(239,68,68,.25); }
.btn-danger:hover:not(:disabled) { background: rgba(185,28,28,.3); border-color: rgba(239,68,68,.5); }

.btn-sm   { padding: 5px 11px; font-size: .78rem; }
.btn-full { width: 100%; justify-content: center; }

/* ── Modals ─────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
}
.modal-card {
  background: var(--bg-modal);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 28px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-card-sm { max-width: 380px; }
.modal-title {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
}
.modal-title-danger { color: #f87171; }
.modal-sub { font-size: .85rem; color: var(--text-secondary); margin-bottom: 20px; line-height: 1.6; }
.modal-body { display: flex; flex-direction: column; gap: 14px; margin-bottom: 24px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.required { color: #f87171; }

/* ── Utilities ──────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 960px) {
  .sidebar { display: none; }
  .content { padding: 24px 22px 60px; }
}
@media (max-width: 600px) {
  .hero { padding: 32px 18px 32px; }
  .hero-title { font-size: 2rem; }
  .header-inner { padding: 0 16px; }
  .nav-link { padding: 6px 10px; font-size: .78rem; }
  .rule-item.depth-1 { margin-left: 12px; }
  .rule-item.depth-2 { margin-left: 24px; }
  .rule-item.depth-3, .rule-item.depth-4 { margin-left: 36px; }
}

/* ── Reduced motion ─────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
