/* ═══════════════════════════════════════════════════════════════
   HACKERPAD — Shared Design System
   All explainer pages link to this stylesheet.
   Source of truth: explained.hackpad.io/design-system
   ═══════════════════════════════════════════════════════════════ */

/* ── 1. Design Tokens ─────────────────────────────────────────── */
:root {
  /* Backgrounds */
  --bg:              #0a0e1a;
  --bg-surface:      #111827;
  --bg-surface-2:    #1a2235;
  --bg-inset:        #0d1117;

  /* Borders */
  --border:          #1e293b;
  --border-subtle:   #162032;

  /* Text */
  --text:            #e2e8f0;
  --text-dim:        #94a3b8;
  --text-muted:      #8a9bb0;

  /* Accent palette */
  --blue:            #3b82f6;
  --blue-light:      #60a5fa;
  --green:           #10b981;
  --green-light:     #34d399;
  --orange:          #f59e0b;
  --orange-light:    #fbbf24;
  --purple:          #a855f7;
  --purple-light:    #c084fc;
  --red:             #ef4444;
  --red-light:       #f87171;
  --cyan:            #06b6d4;
  --cyan-light:      #22d3ee;
  --pink:            #ec4899;
  --yellow:          #eab308;

  /* Typography */
  --font-display:    'Bricolage Grotesque', 'DM Sans', sans-serif;
  --font-body:       'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:       'JetBrains Mono', 'Fira Code', 'SF Mono', 'Cascadia Code', monospace;

  /* Spacing scale (4px base) */
  --sp-1:  4px;
  --sp-2:  8px;
  --sp-3:  12px;
  --sp-4:  16px;
  --sp-5:  20px;
  --sp-6:  24px;
  --sp-7:  28px;
  --sp-8:  32px;
  --sp-10: 40px;
  --sp-12: 48px;
  --sp-16: 64px;

  /* Radii */
  --radius-sm:   6px;
  --radius-md:   10px;
  --radius-lg:   12px;
  --radius-xl:   16px;
  --radius-full: 9999px;

  /* Layout */
  --max-width:   820px;
  --page-pad-x:  20px;
  --page-pad-y:  40px;

  /* Transitions */
  --ease:        0.2s ease;
  --ease-out:    cubic-bezier(0.16, 1, 0.3, 1);
}

/* ── 2. Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, color-mix(in srgb, var(--blue) 8%, transparent), transparent 70%),
    radial-gradient(ellipse 50% 50% at 85% 10%, color-mix(in srgb, var(--purple) 5%, transparent), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  padding: var(--page-pad-y) var(--page-pad-x) 80px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Grain texture overlay */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  pointer-events: none;
  opacity: 0.03;
  z-index: 10000;
}

.container {
  max-width: var(--max-width);
  margin: 0 auto;
}

/* ── 3. Page Header ───────────────────────────────────────────── */
.back-nav { margin-bottom: var(--sp-6); }
.back-nav__link {
  font-size: 0.875rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--ease);
}
.back-nav__link:hover { color: var(--text); }

.page-header {
  text-align: center;
  margin-bottom: var(--sp-8);
  position: relative;
}

.page-header::before {
  content: '';
  position: absolute;
  top: -100px;
  left: 50%;
  transform: translateX(-50%);
  width: 600px;
  height: 350px;
  background: radial-gradient(ellipse, color-mix(in srgb, var(--blue) 12%, transparent) 0%, transparent 70%);
  pointer-events: none;
  z-index: -1;
}

.page-header__eyebrow {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--blue);
  margin-bottom: var(--sp-2);
}

.page-header__title {
  font-family: var(--font-display);
  font-size: 2.6rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.2;
  margin-bottom: var(--sp-2);
  background: var(--title-gradient, linear-gradient(135deg, var(--blue-light), var(--purple-light)));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  width: fit-content;
  margin-inline: auto;
}

.page-header__subtitle {
  color: var(--text-muted);
  font-size: 17px;
}

/* ── 4. Section Structure ─────────────────────────────────────── */
.section {
  margin-bottom: var(--sp-16);
}

.section__eyebrow {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: var(--sp-3);
}

.section__title {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: var(--sp-6);
}

.section__desc {
  color: var(--text-dim);
  font-size: 16px;
  max-width: 600px;
  line-height: 1.7;
  margin-bottom: var(--sp-5);
}

/* Tighter spacing inside tab panels */
.content-panel .section { margin-bottom: var(--sp-8); }

/* ── 5. Tab Navigation ────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: var(--sp-7);
  padding: 0 var(--sp-1);
}

.tab {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 400;
  padding: 10px 20px;
  cursor: pointer;
  transition: all var(--ease);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.tab:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.tab[aria-selected="true"],
.tab.active {
  font-weight: 600;
  border-color: var(--tab-color, var(--blue));
  background: color-mix(in srgb, var(--tab-color, var(--blue)) 8%, transparent);
  color: var(--tab-color, var(--blue));
  box-shadow: 0 0 20px color-mix(in srgb, var(--tab-color, var(--blue)) 10%, transparent);
}

/* ── 6. Tab Content Panels ────────────────────────────────────── */
.content-panel {
  background: color-mix(in srgb, var(--bg-surface) 80%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--sp-7) var(--sp-6);
}

[data-panel] { display: none; }
[data-panel].active { display: block; animation: fadeUp 0.4s var(--ease-out) both; }

/* ── 7. Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  transition: border-color 0.3s ease, box-shadow 0.3s ease, transform 0.3s ease;
}

.card--accent {
  border-color: color-mix(in srgb, var(--card-color) 25%, transparent);
}

.card--accent:hover {
  border-color: color-mix(in srgb, var(--card-color) 45%, transparent);
  box-shadow: 0 4px 24px color-mix(in srgb, var(--card-color) 8%, transparent);
}

.card--stripe {
  position: relative;
  overflow: hidden;
}

.card--stripe::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--card-color);
}

/* ── 8. Code Blocks ───────────────────────────────────────────── */
pre, .code-block {
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-4) var(--sp-5);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.75;
  color: var(--text-dim);
  overflow-x: auto;
  margin: var(--sp-3) 0;
}

.hl-keyword  { color: var(--purple-light); }
.hl-string   { color: var(--green-light); }
.hl-number   { color: var(--orange-light); }
.hl-comment  { color: var(--text-muted); }
.hl-property { color: var(--blue-light); }
.hl-value    { color: var(--cyan-light); }
.hl-type     { color: var(--orange); }

code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--bg-surface-2);
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  color: var(--green-light);
}

pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
  color: inherit;
}

/* ── 9. Badges ────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.04em;
  padding: 3px 10px;
  border-radius: 4px;
  text-transform: uppercase;
  background: color-mix(in srgb, var(--badge-color) 12%, transparent);
  color: var(--badge-color);
  border: 1px solid color-mix(in srgb, var(--badge-color) 20%, transparent);
}

/* ── 10. Callouts / Tips ──────────────────────────────────────── */
.callout {
  padding: var(--sp-4) var(--sp-5);
  border-radius: var(--radius-md);
  font-size: 15px;
  line-height: 1.7;
  background: color-mix(in srgb, var(--callout-color) 6%, transparent);
  border: 1px solid color-mix(in srgb, var(--callout-color) 18%, transparent);
  color: var(--callout-color);
}

.callout strong { color: inherit; }

/* ── 11. Arrows / Connectors ──────────────────────────────────── */
.arrow {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--sp-2) 0;
}

.arrow__label {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: var(--sp-1);
}

/* ── 12. Flow Steps ───────────────────────────────────────────── */
.flow {
  display: flex;
  flex-direction: column;
  gap: 0;
  position: relative;
}

.flow::before {
  content: '';
  position: absolute;
  left: 21px;
  top: 22px;
  bottom: 22px;
  width: 2px;
  background: var(--border);
}

.flow-step {
  display: flex;
  gap: var(--sp-5);
  align-items: flex-start;
  position: relative;
}

.flow-step__num {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
  background: color-mix(in srgb, var(--step-color) 15%, transparent);
  color: var(--step-color);
  border: 1.5px solid color-mix(in srgb, var(--step-color) 40%, transparent);
}

.flow-step__content {
  flex: 1;
  padding-bottom: 36px;
}

.flow-step:last-child .flow-step__content {
  padding-bottom: 0;
}

.flow-step__title {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: var(--sp-2);
}

.flow-step__desc {
  font-size: 15px;
  color: var(--text-dim);
}

/* ── 13. Comparison Cards (Good / Bad) ────────────────────────── */
.comparison {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-5);
}

@media (max-width: 700px) {
  .comparison { grid-template-columns: 1fr; }
}

/* ── 14. Grids ────────────────────────────────────────────────── */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-3);
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-3);
}

.grid-auto {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--sp-3);
}

@media (max-width: 700px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* ── 15. Hierarchy / Pyramid ──────────────────────────────────── */
.hierarchy {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
}

.hierarchy__level {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: var(--radius-md);
  padding: var(--sp-4) var(--sp-5);
  transition: all var(--ease);
  background: color-mix(in srgb, var(--level-color) 6%, transparent);
  border: 1px solid color-mix(in srgb, var(--level-color) 22%, transparent);
}

/* ── 16. Timeline ─────────────────────────────────────────────── */
.timeline {
  display: flex;
  flex-direction: column;
  position: relative;
  padding-left: 24px;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 10px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: var(--border);
}

.timeline__item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 7px 0;
  font-size: 15px;
  color: var(--text-dim);
  position: relative;
}

.timeline__item::before {
  content: '';
  position: absolute;
  left: -17px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
}

.timeline__item--highlight::before {
  background: var(--item-color, var(--blue));
}

/* ── 17. Footer ───────────────────────────────────────────────── */
.page-footer {
  text-align: center;
  margin-top: var(--sp-12);
  padding-top: var(--sp-8);
  border-top: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

/* ── 19. Utility Classes ──────────────────────────────────────── */
.mono  { font-family: var(--font-mono); }
.dim   { color: var(--text-dim); }
.muted { color: var(--text-muted); }
.small { font-size: 14px; }
.center { text-align: center; }

.flex        { display: flex; }
.flex-col    { flex-direction: column; }
.flex-center { align-items: center; justify-content: center; }
.flex-wrap   { flex-wrap: wrap; }
.gap-1 { gap: var(--sp-1); } .gap-2 { gap: var(--sp-2); } .gap-3 { gap: var(--sp-3); }
.gap-4 { gap: var(--sp-4); } .gap-5 { gap: var(--sp-5); } .gap-6 { gap: var(--sp-6); }

.mt-2 { margin-top: var(--sp-2); } .mt-3 { margin-top: var(--sp-3); }
.mt-4 { margin-top: var(--sp-4); } .mt-5 { margin-top: var(--sp-5); } .mt-6 { margin-top: var(--sp-6); }
.mb-2 { margin-bottom: var(--sp-2); } .mb-3 { margin-bottom: var(--sp-3); }
.mb-4 { margin-bottom: var(--sp-4); } .mb-5 { margin-bottom: var(--sp-5); }

/* ── 20. Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── 21. Entrance Animations ─────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.page-header   { animation: fadeUp 0.8s var(--ease-out) both; }
.tabs          { animation: fadeUp 0.8s var(--ease-out) 0.1s both; }
.content-panel { animation: fadeUp 0.8s var(--ease-out) 0.2s both; }
.page-footer   { animation: fadeUp 0.8s var(--ease-out) 0.3s both; }

/* Scroll reveal (applied via JS for scrollable pages) */
.reveal-hidden {
  opacity: 0;
  transform: translateY(20px);
}

.reveal-visible {
  animation: fadeUp 0.8s var(--ease-out) both;
}
