/**
 * data-centered.com — Unified Design System
 *
 * Sources:
 *   Palette + hero:  reading-roundup-r2-v7-arc-palette.html (Keith-approved)
 *   Body patterns:   agent-architecture-explainer.html (color highlights, badges, grids)
 *   Fonts:           Cabinet Grotesk (display) + Inter (body) + JetBrains Mono (code)
 *
 * Usage: <link rel="stylesheet" href="/css/core.css">
 *        then override --measure, add page-specific components in <style>
 */

/* ─── Tokens ─── */
:root {
  /* Surface */
  --bg: #0e0d13;
  --surface: #1a1824;
  --surface-2: #222030;
  --border: rgba(255, 255, 255, 0.08);
  --border-accent: rgba(255, 255, 255, 0.14);
  --divider: rgba(255, 255, 255, 0.06);

  /* Text */
  --ink: #f0ede6;
  --ink-secondary: #ebe8e3;
  --ink-muted: #b5b0a9;
  --ink-dim: #7a756e;
  --ink-faint: #3d3833;

  /* Accent — ARC triad */
  --accent-indigo: #8436e6;
  --accent-green: #257a4b;
  --accent-amber: #ad652c;

  /* Soft variants — for text on dark backgrounds */
  --indigo-soft: #b07df0;
  --green-soft: #82ad95;
  --amber-soft: #d6ba90;

  /* Extended palette — from agent-architecture-explainer */
  --cyan: #5ccfe6;
  --orange: #ffab70;
  --pink: #f778ba;
  --red: #e06c75;

  /* Brand gold (legacy compat — same value as accent-amber-soft) */
  --accent: #d4a84b;

  /* Typography */
  --display: 'Cabinet Grotesk', 'Sora', system-ui, sans-serif;
  --sans: 'Satoshi', 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --mono: 'JetBrains Mono', 'SF Mono', Monaco, Consolas, monospace;
  --hand: 'Caveat', cursive;

  /* Layout */
  --measure: 82rem;
  --gutter: 20px;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --header-h: 54px;

  /* Callouts */
  --note-bg: rgba(173, 101, 44, 0.08);
  --note-border: rgba(173, 101, 44, 0.3);

  /* Elevation (neumorphic-lite) */
  --shadow-raised: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 12px rgba(0, 0, 0, 0.15),
    -1px -1px 3px rgba(255, 255, 255, 0.02);
  --shadow-raised-hover: 0 4px 8px rgba(0, 0, 0, 0.3), 0 16px 32px rgba(0, 0, 0, 0.2),
    -2px -2px 4px rgba(255, 255, 255, 0.03);
}

/* ─── Light mode ─── */
[data-theme="light"] {
  /* Surface — warm paper, not sterile white */
  --bg: #f5f2ec;
  --surface: #eae7e0;
  --surface-2: #dfdcd5;
  --border: rgba(0, 0, 0, 0.08);
  --border-accent: rgba(0, 0, 0, 0.14);
  --divider: rgba(0, 0, 0, 0.06);

  /* Text */
  --ink: #1a1816;
  --ink-secondary: #2d2a26;
  --ink-muted: #5c5650;
  --ink-dim: #8a847d;
  --ink-faint: #c5bfb8;

  /* Accent — ARC triad (darker for light bg) */
  --accent-indigo: #6b24d6;
  --accent-green: #1d6b3f;
  --accent-amber: #955520;

  /* Soft variants — readable on light backgrounds */
  --indigo-soft: #7b3cc8;
  --green-soft: #2a7d4a;
  --amber-soft: #8b5a2b;

  /* Extended palette (adjusted for light bg) */
  --cyan: #1a8fa3;
  --orange: #c47420;
  --pink: #c4508a;
  --red: #c0414c;

  /* Brand gold */
  --accent: #a07820;

  /* Callouts */
  --note-bg: rgba(173, 101, 44, 0.06);
  --note-border: rgba(173, 101, 44, 0.25);

  /* Elevation (neumorphic-lite) */
  --shadow-raised: 0 1px 3px rgba(0, 0, 0, 0.06), 0 6px 16px rgba(0, 0, 0, 0.04);
  --shadow-raised-hover: 0 2px 6px rgba(0, 0, 0, 0.08), 0 12px 28px rgba(0, 0, 0, 0.06);

  /* Grid lines — dark on light */
  --grid-color: rgba(0, 0, 0, 0.04);
}

/* Grid bg adapts via custom property */
:root {
  --grid-color: rgba(255, 255, 255, 0.03);
}

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

/* ─── Base ─── */
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: clip;
  overflow-y: scroll;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.9375rem;
  font-weight: 400;
  line-height: 1.7;
  overflow-x: clip;
}

/* Dark mode textures (matches site-wide dark theme) */
:root:not([data-theme="light"]) body {
  background-image: url('../showcase/data-stories/textures/dark-leather.png');
  background-repeat: repeat;
}
:root:not([data-theme="light"]) #dc-nav {
  background-image: url('../showcase/data-stories/textures/dark-mosaic.png') !important;
  background-repeat: repeat !important;
}

/* Light mode textures — sand-wet body, marble-white nav */
[data-theme="light"] body {
  background-color: #f0e4c7;
  background-image: url('../showcase/data-stories/textures/sand-wet.svg');
  background-repeat: repeat;
}
[data-theme="light"] #dc-nav {
  background-color: #f5f2ec !important;
  background-image: url('../showcase/data-stories/textures/marble-white.svg') !important;
  background-repeat: repeat !important;
}

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

a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

::selection {
  background: rgba(132, 54, 230, 0.3);
  color: var(--ink);
}

/* ─── Container ─── */
.container {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

/* ─── Theme toggle ─── */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.5rem;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  color: var(--ink-dim);
  transition: all 0.2s;
}

.theme-toggle::before {
  content: '\25D0';
  /* auto: circle half */
}

.theme-toggle[data-mode="dark"]::before {
  content: '\263E';
  /* moon */
}

.theme-toggle[data-mode="light"]::before {
  content: '\2600';
  /* sun */
}

.theme-toggle:hover {
  border-color: var(--border-accent);
  color: var(--ink-muted);
}

/* ─── Navigation ─── */
.site-header {
  padding: 14px 0;
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--divider);
  height: var(--header-h);
  box-sizing: border-box;
}

@media (max-width: 768px) {
  .site-header {
    padding: 12px 0;
  }
}

.site-header.is-scrolled {
  backdrop-filter: blur(12px) saturate(180%);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  transition: backdrop-filter 0.3s ease, background 0.3s ease;
}

.site-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.site-brand {
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: 0.02em;
}

.site-brand:hover {
  text-decoration: none;
  color: var(--accent);
}

.nav-links {
  display: flex;
  gap: 1.5rem;
  list-style: none;
}

.nav-links a {
  font-family: var(--sans);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--ink-muted);
  text-decoration: none;
  letter-spacing: 0.02em;
  transition: color 0.15s;
}

.nav-links a:hover {
  color: var(--ink);
  text-decoration: none;
}

.nav-links a.active {
  color: var(--ink);
  position: relative;
}

.nav-links a.active::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--accent-indigo);
}

/* ─── Nav dropdown ─── */
.nav-dropdown {
  position: relative;
  display: flex;
  align-items: center;
}

.nav-dropdown-trigger {
  font-family: var(--sans);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--ink-muted);
  background: none;
  border: none;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: color 0.15s;
  padding: 0;
}

.nav-dropdown-trigger:hover,
.nav-dropdown.open .nav-dropdown-trigger {
  color: var(--ink);
}

.nav-dropdown-trigger.active {
  color: var(--ink);
}

.nav-dropdown-trigger::after {
  content: '';
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: 4px;
  vertical-align: 1px;
  border-left: 3.5px solid transparent;
  border-right: 3.5px solid transparent;
  border-top: 4px solid currentColor;
  transition: transform 0.2s;
}

.nav-dropdown.open .nav-dropdown-trigger::after {
  transform: rotate(180deg);
}

.nav-dropdown-menu {
  position: absolute;
  top: 100%;
  right: -12px;
  min-width: 200px;
  background: var(--bg);
  border: none;
  border-bottom: 1px solid var(--divider);
  border-left: 1px solid var(--divider);
  border-right: 1px solid var(--divider);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  z-index: 200;
  padding: 4px 0 6px;
  /* Clip-path reveal: start collapsed, expand down */
  clip-path: inset(0 0 100% 0);
  opacity: 0;
  transition: clip-path 0.25s cubic-bezier(0.16, 1, 0.3, 1),
              opacity 0.2s ease;
  pointer-events: none;
}

.nav-dropdown.open .nav-dropdown-menu {
  clip-path: inset(0 0 0 0);
  opacity: 1;
  pointer-events: auto;
}

.nav-dropdown-menu a {
  display: block;
  padding: 8px 16px;
  font-family: var(--sans);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--ink-muted);
  text-decoration: none;
  transition: background 0.1s, color 0.1s;
}

.nav-dropdown-menu a:hover {
  background: rgba(132, 54, 230, 0.06);
  color: var(--ink);
  text-decoration: none;
}

.nav-dropdown-menu .dropdown-group-label {
  display: block;
  padding: 8px 16px 4px;
  font-family: var(--sans);
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--ink-dim);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.nav-dropdown-menu .dropdown-group-label:not(:first-child) {
  margin-top: 4px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.nav-dropdown-menu .dropdown-item-sub {
  padding-left: 16px;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--ink-dim);
}

.nav-dropdown-menu .dropdown-item-sub:hover {
  color: var(--ink-muted);
}

.nav-dropdown-menu .dropdown-item-disabled {
  padding: 8px 16px;
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--ink-faint);
  cursor: default;
}

@media (max-width: 480px) {
  .nav-dropdown-trigger {
    font-size: 0.75rem;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  .nav-dropdown-menu {
    position: fixed;
    top: var(--header-h);
    left: 0;
    right: 0;
    min-width: unset;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    max-height: calc(100vh - var(--header-h));
    overflow-y: auto;
  }

  .nav-dropdown-menu a {
    min-height: 44px;
    display: flex;
    align-items: center;
  }
}

/* ─── Showcase variant (minimal header: brand + theme toggle) ─── */
.site-header--showcase .site-brand {
  font-family: var(--display, 'Cabinet Grotesk', system-ui, sans-serif);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* ─── Hero (unique classes from original block) ─── */
.hero-subtitle {
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--ink-secondary);
  max-width: 40rem;
}

.hero-date {
  font-family: var(--sans);
  font-size: 14px;
  color: var(--ink-dim);
  font-weight: 300;
}

/* ─── Section headers ─── */
.section-label {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 1rem;
}

h2 {
  font-family: var(--display);
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1.12;
  letter-spacing: -0.03em;
  color: var(--ink);
  margin-bottom: 0.75rem;
}

h3 {
  font-family: var(--display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 0.5rem;
}

/* ─── Stats row ─── */
.stats-row {
  display: flex;
  gap: 6px;
  padding: 16px 0;
  margin-bottom: 20px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.stats-row::-webkit-scrollbar {
  display: none;
}

.stat-chip {
  display: flex;
  align-items: baseline;
  gap: 5px;
  padding: 6px 0;
  white-space: nowrap;
  flex-shrink: 0;
}

.stat-chip+.stat-chip {
  padding-left: 12px;
  border-left: 1px solid var(--border-accent);
}

.stat-chip .num {
  font-family: var(--display);
  font-size: 1.1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.stat-chip .label {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

/* ─── Cards ─── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  transition: border-color 0.2s;
}

.card:hover {
  border-color: var(--border-accent);
}

.card-raised {
  background: var(--surface);
  border: none;
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-raised);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s;
}

.card-raised:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-raised-hover);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

/* ─── Badges (colored labels) ─── */
.badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.badge-indigo {
  background: rgba(132, 54, 230, 0.2);
  color: var(--indigo-soft);
}

.badge-green {
  background: rgba(37, 122, 75, 0.25);
  color: var(--green-soft);
}

.badge-amber {
  background: rgba(173, 101, 44, 0.2);
  color: var(--amber-soft);
}

.badge-cyan {
  background: rgba(92, 207, 230, 0.15);
  color: var(--cyan);
}

.badge-orange {
  background: rgba(255, 171, 112, 0.15);
  color: var(--orange);
}

.badge-pink {
  background: rgba(247, 120, 186, 0.15);
  color: var(--pink);
}

/* ─── Tags (smaller, for metadata) ─── */
.tag {
  display: inline-block;
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-sm);
  background: rgba(92, 207, 230, 0.1);
  color: var(--cyan);
  border: 1px solid rgba(92, 207, 230, 0.2);
}

.tag-complete {
  background: rgba(37, 122, 75, 0.15);
  color: var(--green-soft);
  border-color: rgba(37, 122, 75, 0.25);
}

/* ─── Pull quote (gradient border) ─── */
.pull-quote {
  padding: 24px 0 24px 20px;
  margin: 28px 0;
  border-left: 2px solid;
  border-image: linear-gradient(180deg, var(--accent-indigo), var(--accent-green), var(--accent-amber)) 1;
}

.pull-quote-text {
  font-family: var(--display);
  font-style: normal;
  font-weight: 700;
  font-size: 1.2rem;
  line-height: 1.35;
  color: var(--ink);
  opacity: 0.9;
}

/* ─── Margin notes (handwriting) ─── */
.margin-note {
  margin-top: 10px;
  padding: 10px 14px;
  background: var(--note-bg);
  border-left: 2px solid var(--note-border);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-family: var(--hand);
  font-size: 1.25rem;
  line-height: 1.45;
  color: var(--amber-soft);
  opacity: 0.9;
}

.margin-note::before {
  content: '// ';
  opacity: 0.5;
}

/* ─── Tables ─── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th {
  text-align: left;
  color: var(--ink-muted);
  font-family: var(--sans);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-accent);
}

td {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--ink-secondary);
}

tr:hover td {
  background: rgba(132, 54, 230, 0.03);
}

.mono {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--cyan);
}

/* ─── Wiring flow (pure CSS process diagram) ─── */
.wiring {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  margin: 1.5rem 0;
}

.wiring-flow {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  flex-wrap: wrap;
  margin: 1rem 0;
}

.wiring-node {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.75rem 1.25rem;
  text-align: center;
  min-width: 140px;
}

.wiring-node .node-label {
  font-size: 0.7rem;
  color: var(--ink-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.wiring-node .node-value {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--ink);
  margin-top: 0.2rem;
}

.wiring-node .node-path {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--ink-dim);
  margin-top: 0.25rem;
}

.wiring-arrow {
  color: var(--indigo-soft);
  font-size: 1.5rem;
  padding: 0 0.75rem;
  line-height: 1;
}

/* ─── Grid background (spreadsheet-style) ─── */
@keyframes grid-emerge {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

/* Grid overlay removed — replaced by dark-leather texture in dark mode */

/* ─── Footer ─── */
.site-footer {
  border-top: 1px solid var(--divider);
  margin-top: 4rem;
  padding: 2rem 0;
}

.footer-inner {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0 var(--gutter);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--ink-dim);
}

.footer-inner a {
  color: var(--ink-muted);
}

/* ─── Article reading column ─── */
.container:has(.article-header) {
  --measure: 42rem;
  font-size: 0.9rem;
  line-height: 1.75;
  padding-top: 2rem;
}

/* ─── Paragraph spacing for long-form content ─── */
.article-body p,
.container>section p {
  margin-bottom: 1rem;
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
  :root {
    --gutter: 24px;
    --measure: 540px;
  }

  .container {
    font-size: 0.92rem;
    line-height: 1.65;
  }

  .article-body p,
  .container>section p {
    font-size: 0.92rem;
  }

  .hero-title {
    font-size: 1.6rem;
  }

  .card-grid {
    grid-template-columns: 1fr;
  }

  .wiring-flow {
    flex-direction: column;
  }

  .wiring-arrow {
    transform: rotate(90deg);
    padding: 0.5rem 0;
  }

  .nav-links {
    gap: 1rem;
  }

  .footer-inner {
    flex-direction: column;
    gap: 0.5rem;
    text-align: center;
  }
}

@media (max-width: 480px) {
  .hero-title {
    font-size: 1.4rem;
  }

  .stats-row {
    gap: 4px;
  }

  .stat-chip .num {
    font-size: 0.95rem;
  }

  /* Global Nav Mobile Overrides */
  .nav-links {
    gap: 0.6rem;
  }

  .nav-links a {
    font-size: 0.75rem;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  .site-brand {
    font-size: 0.75rem;
  }
}

/* ── Hero Section (Standardized Template) ── */
.hero {
  padding: 8px 0 6px;
  border-bottom: 1px solid var(--divider);
  margin-bottom: 0;
}

.hero-label {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 4px;
}

.hero-title {
  font-family: var(--display);
  font-size: clamp(1.4rem, 4vw, 2.2rem);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.04em;
  color: var(--ink);
  margin-bottom: 4px;
}

.page-intro {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--ink-muted);
  line-height: 1.4;
  max-width: 42rem;
  margin-bottom: 6px;
}

.page-intro a {
  color: var(--green-soft);
}

.page-intro a:hover {
  color: var(--ink);
}

/* Stats chips in hero */
.hero-stats {
  display: flex;
  gap: 6px;
  padding: 4px 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.hero-stats::-webkit-scrollbar {
  display: none;
}

.stat-chip {
  display: flex;
  align-items: baseline;
  gap: 5px;
  padding: 6px 0;
  white-space: nowrap;
  flex-shrink: 0;
}

.stat-chip+.stat-chip {
  padding-left: 12px;
  border-left: 1px solid var(--border-accent);
}

.stat-chip .num {
  font-family: var(--display);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.stat-chip .label {
  font-family: var(--sans);
  font-size: 0.72rem;
  color: var(--ink-dim);
  letter-spacing: 0.04em;
}

/* ─── Reduced motion ─── */
@media (prefers-reduced-motion: reduce) {
  body::before {
    animation: none;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}