/* ============================================================
   RELATIONAL DESIGN SYSTEM — Base Styles
   
   Reset, typography, component primitives, and utilities.
   Import after tokens.css.
   ============================================================ */


/* ────────────────────────────────────────────────────────────
   § 1. RESET & GLOBAL
   ──────────────────────────────────────────────────────────── */

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

html {
  font-size: 100%;  /* 16px base */
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
  color-scheme: light dark;
}

body {
  font-family: var(--rds-font-body);
  font-size: var(--rds-text-base);
  font-weight: var(--rds-weight-regular);
  line-height: var(--rds-leading-normal);
  color: var(--rds-text);
  background-color: var(--rds-bg);
  transition: background-color var(--rds-duration-slow) var(--rds-ease-default),
              color var(--rds-duration-slow) var(--rds-ease-default);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

::selection {
  background: var(--rds-accent-200);
  color: var(--rds-neutral-900);
}

.dark ::selection {
  background: var(--rds-accent-400);
  color: var(--rds-neutral-900);
}


/* ────────────────────────────────────────────────────────────
   § 2. TYPOGRAPHY
   ──────────────────────────────────────────────────────────── */

/* ── Display / Hero ────────────────────────────────────────── */

.rds-display-xl {
  font-family: var(--rds-font-display);
  font-size: clamp(var(--rds-text-4xl), 5vw + 1rem, var(--rds-text-6xl));
  font-weight: var(--rds-weight-regular);
  line-height: var(--rds-leading-tight);
  letter-spacing: var(--rds-tracking-tight);
  color: var(--rds-text);
}

.rds-display-lg {
  font-family: var(--rds-font-display);
  font-size: clamp(var(--rds-text-3xl), 4vw + 0.5rem, var(--rds-text-5xl));
  font-weight: var(--rds-weight-regular);
  line-height: var(--rds-leading-tight);
  letter-spacing: var(--rds-tracking-tight);
  color: var(--rds-text);
}

.rds-display {
  font-family: var(--rds-font-display);
  font-size: clamp(var(--rds-text-2xl), 3vw + 0.5rem, var(--rds-text-4xl));
  font-weight: var(--rds-weight-regular);
  line-height: var(--rds-leading-tight);
  letter-spacing: var(--rds-tracking-tight);
  color: var(--rds-text);
}

/* ── Headings — Source Sans 3 ──────────────────────────────── */

h1, .rds-h1 {
  font-family: var(--rds-font-display);
  font-size: clamp(var(--rds-text-2xl), 2.5vw + 0.5rem, var(--rds-text-3xl));
  font-weight: var(--rds-weight-regular);
  line-height: var(--rds-leading-snug);
  letter-spacing: var(--rds-tracking-tight);
  color: var(--rds-text);
  margin-bottom: var(--rds-space-6);
}

h2, .rds-h2 {
  font-family: var(--rds-font-body);
  font-size: var(--rds-text-xl);
  font-weight: var(--rds-weight-semibold);
  line-height: var(--rds-leading-snug);
  letter-spacing: var(--rds-tracking-normal);
  color: var(--rds-text);
  margin-bottom: var(--rds-space-4);
}

h3, .rds-h3 {
  font-family: var(--rds-font-body);
  font-size: var(--rds-text-lg);
  font-weight: var(--rds-weight-semibold);
  line-height: var(--rds-leading-snug);
  color: var(--rds-text);
  margin-bottom: var(--rds-space-3);
}

h4, .rds-h4 {
  font-family: var(--rds-font-body);
  font-size: var(--rds-text-md);
  font-weight: var(--rds-weight-semibold);
  line-height: var(--rds-leading-snug);
  color: var(--rds-text);
  margin-bottom: var(--rds-space-2);
}

h5, .rds-h5 {
  font-family: var(--rds-font-body);
  font-size: var(--rds-text-base);
  font-weight: var(--rds-weight-semibold);
  line-height: var(--rds-leading-snug);
  color: var(--rds-text-secondary);
  margin-bottom: var(--rds-space-2);
}

h6, .rds-h6 {
  font-family: var(--rds-font-body);
  font-size: var(--rds-text-sm);
  font-weight: var(--rds-weight-bold);
  line-height: var(--rds-leading-snug);
  letter-spacing: var(--rds-tracking-wider);
  text-transform: uppercase;
  color: var(--rds-text-muted);
  margin-bottom: var(--rds-space-2);
}

/* ── Body & Prose ──────────────────────────────────────────── */

p {
  margin-bottom: var(--rds-space-4);
  max-width: 65ch;  /* Optimal reading measure */
}

.rds-lead {
  font-size: var(--rds-text-md);
  line-height: var(--rds-leading-relaxed);
  color: var(--rds-text-secondary);
  max-width: 60ch;
}

.rds-body-sm {
  font-size: var(--rds-text-sm);
  line-height: var(--rds-leading-normal);
}

.rds-caption {
  font-size: var(--rds-text-xs);
  line-height: var(--rds-leading-normal);
  color: var(--rds-text-muted);
}

/* ── Overline / Label ──────────────────────────────────────── */

.rds-overline {
  font-family: var(--rds-font-body);
  font-size: var(--rds-text-xs);
  font-weight: var(--rds-weight-semibold);
  letter-spacing: var(--rds-tracking-widest);
  text-transform: uppercase;
  color: var(--rds-primary-500);
  margin-bottom: var(--rds-space-2);
}

.rds-label {
  font-family: var(--rds-font-body);
  font-size: var(--rds-text-sm);
  font-weight: var(--rds-weight-medium);
  color: var(--rds-text-secondary);
}

/* ── Code ──────────────────────────────────────────────────── */

code, kbd, samp, pre {
  font-family: var(--rds-font-mono);
  font-size: 0.875em;
}

code {
  background: var(--rds-bg-surface);
  padding: 0.15em 0.35em;
  border-radius: var(--rds-radius-sm);
  color: var(--rds-primary-500);
}

pre {
  background: var(--rds-bg-surface);
  border: 1px solid var(--rds-border);
  border-radius: var(--rds-radius-md);
  padding: var(--rds-space-4);
  overflow-x: auto;
  line-height: var(--rds-leading-relaxed);
}

pre code {
  background: none;
  padding: 0;
  border-radius: 0;
}

/* ── Links ─────────────────────────────────────────────────── */

a {
  color: var(--rds-link);
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 3px;
  transition: color var(--rds-duration-fast) var(--rds-ease-default),
              text-decoration-color var(--rds-duration-fast) var(--rds-ease-default);
}

a:hover {
  color: var(--rds-link-hover);
  text-decoration-color: currentColor;
}

a:focus-visible {
  outline: 2px solid var(--rds-focus-ring);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ── Lists ─────────────────────────────────────────────────── */

ul, ol {
  padding-left: var(--rds-space-5);
  margin-bottom: var(--rds-space-4);
}

li {
  margin-bottom: var(--rds-space-1);
}

li::marker {
  color: var(--rds-accent-500);
}

/* ── Blockquote ────────────────────────────────────────────── */

blockquote {
  border-left: 3px solid var(--rds-accent-400);
  padding: var(--rds-space-4) var(--rds-space-6);
  margin: var(--rds-space-6) 0;
  background: var(--rds-bg-surface);
  border-radius: 0 var(--rds-radius-md) var(--rds-radius-md) 0;
  font-style: italic;
  color: var(--rds-text-secondary);
}

blockquote p:last-child {
  margin-bottom: 0;
}

/* ── Horizontal Rule ───────────────────────────────────────── */

hr {
  border: none;
  border-top: 1px solid var(--rds-border);
  margin: var(--rds-space-8) 0;
}

/* ── Images ────────────────────────────────────────────────── */

img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* ── Tables ────────────────────────────────────────────────── */

table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--rds-space-6) 0;
  font-size: var(--rds-text-sm);
}

thead {
  border-bottom: 2px solid var(--rds-border-strong);
}

th {
  font-weight: var(--rds-weight-semibold);
  text-align: left;
  padding: var(--rds-space-3) var(--rds-space-4);
  color: var(--rds-text-secondary);
  font-size: var(--rds-text-xs);
  letter-spacing: var(--rds-tracking-wide);
  text-transform: uppercase;
}

td {
  padding: var(--rds-space-3) var(--rds-space-4);
  border-bottom: 1px solid var(--rds-border-subtle);
  vertical-align: top;
}

tbody tr:hover {
  background: var(--rds-bg-surface);
}


/* ────────────────────────────────────────────────────────────
   § 3. LAYOUT UTILITIES
   ──────────────────────────────────────────────────────────── */

.rds-container {
  width: 100%;
  max-width: var(--rds-container-xl);
  margin-inline: auto;
  padding-inline: var(--rds-gutter);
}

.rds-container-narrow {
  max-width: var(--rds-content-width);
  margin-inline: auto;
  padding-inline: var(--rds-gutter);
}

.rds-container-wide {
  max-width: var(--rds-container-2xl);
  margin-inline: auto;
  padding-inline: var(--rds-gutter);
}

.rds-section {
  padding-block: var(--rds-section-gap);
}

.rds-section-lg {
  padding-block: var(--rds-section-gap-lg);
}

.rds-grid {
  display: grid;
  gap: var(--rds-gutter);
}

.rds-grid-2 { grid-template-columns: repeat(2, 1fr); }
.rds-grid-3 { grid-template-columns: repeat(3, 1fr); }
.rds-grid-4 { grid-template-columns: repeat(4, 1fr); }

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

@media (min-width: 769px) and (max-width: 1024px) {
  .rds-grid-3 { grid-template-columns: repeat(2, 1fr); }
  .rds-grid-4 { grid-template-columns: repeat(2, 1fr); }
}

/* Sidebar layout */
.rds-layout-sidebar {
  display: grid;
  grid-template-columns: 1fr var(--rds-sidebar-width);
  gap: var(--rds-gutter-lg);
}

@media (max-width: 1024px) {
  .rds-layout-sidebar {
    grid-template-columns: 1fr;
  }
}


/* ────────────────────────────────────────────────────────────
   § 4. COMPONENT PRIMITIVES
   ──────────────────────────────────────────────────────────── */

/* ── Buttons ───────────────────────────────────────────────── */

.rds-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--rds-space-2);
  font-family: var(--rds-font-body);
  font-size: var(--rds-text-sm);
  font-weight: var(--rds-weight-semibold);
  line-height: 1;
  padding: var(--rds-space-3) var(--rds-space-5);
  border: 1px solid transparent;
  border-radius: var(--rds-radius-md);
  cursor: pointer;
  text-decoration: none;
  transition: all var(--rds-duration-fast) var(--rds-ease-default);
  white-space: nowrap;
}

.rds-btn:focus-visible {
  outline: 2px solid var(--rds-focus-ring);
  outline-offset: 2px;
}

.rds-btn-primary {
  background: var(--rds-btn-primary-bg);
  color: var(--rds-btn-primary-text);
}

.rds-btn-primary:hover {
  background: var(--rds-btn-primary-hover);
  color: var(--rds-btn-primary-text);
  text-decoration: none;
}

.rds-btn-secondary {
  background: var(--rds-btn-secondary-bg);
  color: var(--rds-btn-secondary-text);
  border-color: var(--rds-btn-secondary-border);
}

.rds-btn-secondary:hover {
  background: var(--rds-primary-50);
  color: var(--rds-btn-secondary-text);
  text-decoration: none;
}

.rds-btn-accent {
  background: var(--rds-btn-accent-bg);
  color: var(--rds-btn-accent-text);
}

.rds-btn-accent:hover {
  background: var(--rds-btn-accent-hover);
  color: var(--rds-btn-accent-text);
  text-decoration: none;
}

.rds-btn-ghost {
  background: transparent;
  color: var(--rds-text-secondary);
  border-color: transparent;
}

.rds-btn-ghost:hover {
  background: var(--rds-bg-surface);
  color: var(--rds-text);
  text-decoration: none;
}

.rds-btn-lg {
  font-size: var(--rds-text-base);
  padding: var(--rds-space-4) var(--rds-space-6);
  border-radius: var(--rds-radius-lg);
}

.rds-btn-sm {
  font-size: var(--rds-text-xs);
  padding: var(--rds-space-2) var(--rds-space-3);
  border-radius: var(--rds-radius-sm);
}


/* ── Cards ─────────────────────────────────────────────────── */

.rds-card {
  background: var(--rds-bg-elevated);
  border: 1px solid var(--rds-border);
  border-radius: var(--rds-radius-lg);
  padding: var(--rds-space-6);
  transition: box-shadow var(--rds-duration-normal) var(--rds-ease-default),
              border-color var(--rds-duration-normal) var(--rds-ease-default);
}

.rds-card:hover {
  box-shadow: var(--rds-shadow-md);
  border-color: var(--rds-border-strong);
}

.rds-card-flat {
  background: var(--rds-bg-surface);
  border: none;
  border-radius: var(--rds-radius-lg);
  padding: var(--rds-space-6);
}


/* ── Badges / Chips ────────────────────────────────────────── */

.rds-badge {
  display: inline-flex;
  align-items: center;
  font-family: var(--rds-font-body);
  font-size: var(--rds-text-xs);
  font-weight: var(--rds-weight-semibold);
  padding: var(--rds-space-1) var(--rds-space-3);
  border-radius: var(--rds-radius-full);
  white-space: nowrap;
}

/* Part-colored badges */
.rds-badge-part-i   { background: color-mix(in srgb, var(--rds-part-i) 15%, transparent);   color: var(--rds-part-i); }
.rds-badge-part-ii  { background: color-mix(in srgb, var(--rds-part-ii) 15%, transparent);  color: var(--rds-part-ii); }
.rds-badge-part-iii { background: color-mix(in srgb, var(--rds-part-iii) 15%, transparent); color: var(--rds-part-iii); }
.rds-badge-part-iv  { background: color-mix(in srgb, var(--rds-part-iv) 15%, transparent);  color: var(--rds-part-iv); }
.rds-badge-part-v   { background: color-mix(in srgb, var(--rds-part-v) 15%, transparent);   color: var(--rds-part-v); }

.rds-badge-neutral {
  background: var(--rds-bg-surface-alt);
  color: var(--rds-text-secondary);
}

.rds-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--rds-space-1);
  font-size: var(--rds-text-sm);
  font-weight: var(--rds-weight-medium);
  padding: var(--rds-space-1) var(--rds-space-3);
  border: 1px solid var(--rds-border);
  border-radius: var(--rds-radius-full);
  color: var(--rds-text-secondary);
  transition: all var(--rds-duration-fast) var(--rds-ease-default);
}

.rds-chip:hover {
  border-color: var(--rds-primary-300);
  color: var(--rds-primary-500);
  background: var(--rds-primary-50);
}


/* ── Form Inputs ───────────────────────────────────────────── */

.rds-input {
  font-family: var(--rds-font-body);
  font-size: var(--rds-text-base);
  padding: var(--rds-space-3) var(--rds-space-4);
  background: var(--rds-bg-elevated);
  border: 1px solid var(--rds-border);
  border-radius: var(--rds-radius-md);
  color: var(--rds-text);
  width: 100%;
  transition: border-color var(--rds-duration-fast) var(--rds-ease-default),
              box-shadow var(--rds-duration-fast) var(--rds-ease-default);
}

.rds-input::placeholder {
  color: var(--rds-text-faint);
}

.rds-input:focus {
  outline: none;
  border-color: var(--rds-primary-400);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--rds-primary-400) 20%, transparent);
}

.rds-input:hover:not(:focus) {
  border-color: var(--rds-border-strong);
}

textarea.rds-input {
  min-height: 120px;
  resize: vertical;
}

select.rds-input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236B6660' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: var(--rds-space-8);
}


/* ── Nav ───────────────────────────────────────────────────── */

.rds-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--rds-nav-height);
  background: color-mix(in srgb, var(--rds-bg) 85%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--rds-border-subtle);
  display: flex;
  align-items: center;
}

.rds-nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: var(--rds-container-xl);
  margin-inline: auto;
  padding-inline: var(--rds-gutter);
}

.rds-nav-links {
  display: flex;
  gap: var(--rds-space-6);
  list-style: none;
  padding: 0;
  margin: 0;
}

.rds-nav-links a {
  font-size: var(--rds-text-sm);
  font-weight: var(--rds-weight-medium);
  color: var(--rds-text-secondary);
  text-decoration: none;
  padding: var(--rds-space-2) 0;
  transition: color var(--rds-duration-fast) var(--rds-ease-default);
}

.rds-nav-links a:hover,
.rds-nav-links a[aria-current="page"] {
  color: var(--rds-text);
}


/* ── Framework Number Badge ────────────────────────────────── */

.rds-framework-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  font-family: var(--rds-font-body);
  font-size: var(--rds-text-sm);
  font-weight: var(--rds-weight-bold);
  font-variant-numeric: tabular-nums;
  border-radius: var(--rds-radius-md);
  color: var(--rds-neutral-0);
  flex-shrink: 0;
}


/* ── Gated Content Overlay ─────────────────────────────────── */

.rds-gated {
  position: relative;
  overflow: hidden;
  border-radius: var(--rds-radius-lg);
}

.rds-gated-blur {
  filter: blur(6px);
  user-select: none;
  pointer-events: none;
}

.rds-gated-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--rds-space-4);
  background: linear-gradient(
    to bottom,
    color-mix(in srgb, var(--rds-bg) 0%, transparent),
    color-mix(in srgb, var(--rds-bg) 70%, transparent) 30%,
    color-mix(in srgb, var(--rds-bg) 95%, transparent)
  );
  text-align: center;
  padding: var(--rds-space-8);
}


/* ────────────────────────────────────────────────────────────
   § 5. UTILITY CLASSES
   ──────────────────────────────────────────────────────────── */

/* Text alignment */
.rds-text-center { text-align: center; }
.rds-text-right  { text-align: right; }
.rds-text-left   { text-align: left; }

/* Text colors */
.rds-text-primary   { color: var(--rds-primary-500); }
.rds-text-accent    { color: var(--rds-accent-500); }
.rds-text-warm      { color: var(--rds-warm-500); }
.rds-text-secondary { color: var(--rds-text-secondary); }
.rds-text-muted     { color: var(--rds-text-muted); }

/* Flex utilities */
.rds-flex        { display: flex; }
.rds-flex-col    { flex-direction: column; }
.rds-items-center { align-items: center; }
.rds-justify-center { justify-content: center; }
.rds-justify-between { justify-content: space-between; }
.rds-gap-2 { gap: var(--rds-space-2); }
.rds-gap-4 { gap: var(--rds-space-4); }
.rds-gap-6 { gap: var(--rds-space-6); }
.rds-gap-8 { gap: var(--rds-space-8); }

/* Spacing */
.rds-mt-4  { margin-top: var(--rds-space-4); }
.rds-mt-8  { margin-top: var(--rds-space-8); }
.rds-mt-12 { margin-top: var(--rds-space-12); }
.rds-mb-4  { margin-bottom: var(--rds-space-4); }
.rds-mb-8  { margin-bottom: var(--rds-space-8); }
.rds-mb-12 { margin-bottom: var(--rds-space-12); }

/* Visibility */
.rds-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Tabular numbers for data */
.rds-tabular-nums {
  font-variant-numeric: tabular-nums lining-nums;
}
