/* ==========================================================================
   Design System chrome — index, section, item, contribute, focus pages.
   Composes canonical DS tokens + components. No raw values.
   ========================================================================== */

/* ── Topbar ─────────────────────────────────────────────────────────────── */
.ds-topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
  padding: var(--space-3) var(--space-6);
  background-color: var(--surface-page-translucent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
}

.ds-topbar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: 1;
  min-width: 0;
}

.ds-topbar__home {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  text-decoration: none;
  color: var(--text-primary);
}

.ds-topbar__home .material-symbols-rounded {
  color: var(--accent-primary);
  font-size: 22px;
}

.ds-topbar__title {
  font-size: var(--text-base);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-tight);
}

.ds-topbar__sep {
  color: var(--text-tertiary);
  display: inline-flex;
  align-items: center;
}

.ds-topbar__sep .material-symbols-rounded { font-size: 16px; }

.ds-topbar__crumb {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  text-decoration: none;
}

.ds-topbar__crumb--current {
  color: var(--text-primary);
  font-weight: var(--weight-medium);
}

.ds-topbar__nav {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.ds-topbar__nav-item {
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  text-decoration: none;
  transition: background-color var(--duration-fast), color var(--duration-fast);
}

.ds-topbar__nav-item:hover {
  background-color: var(--surface-hover);
  color: var(--text-primary);
}

.ds-topbar__nav-item--active {
  background-color: var(--accent-subtle);
  color: var(--accent-primary);
}

.ds-topbar__themes {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.ds-topbar__themes-label {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  font-weight: var(--weight-semibold);
  margin-right: var(--space-1);
}

/* Theme swatches — each button carries its own data-theme so var(--accent-primary)
   resolves against that theme's --brand-600. Active swatch gets a focus ring. */
.ds-theme-form { display: inline-flex; margin: 0; }

.ds-theme-btn {
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
  background: var(--brand-600);
  cursor: pointer;
  transition: transform var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out);
}

.ds-theme-btn:hover { transform: scale(1.1); }

.ds-theme-btn--active {
  box-shadow: 0 0 0 2px var(--surface-base), 0 0 0 4px var(--accent-primary);
}

/* ── Page wrapper ───────────────────────────────────────────────────────── */
.ds-page {
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: var(--space-6) var(--space-6) var(--space-12);
  display: flex;
  flex-direction: column;
  gap: var(--space-8);
}

/* ── Hero ───────────────────────────────────────────────────────────────── */
.ds-hero {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.ds-hero__row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.ds-hero__title {
  font-size: var(--text-3xl);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-tight);
  color: var(--text-primary);
  margin: 0;
}

.ds-hero__lede {
  font-size: var(--text-base);
  color: var(--text-secondary);
  line-height: var(--leading-relaxed);
  max-width: 70ch;
  margin: 0;
}

.ds-hero__counts {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-top: var(--space-2);
}

.ds-hero__count {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-3) var(--space-4);
  background-color: var(--surface-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  text-decoration: none;
  min-width: 120px;
  transition: border-color var(--duration-fast), background-color var(--duration-fast);
}

.ds-hero__count:hover {
  border-color: var(--accent-primary);
  background-color: var(--accent-subtle);
}

.ds-hero__count-num {
  font-size: var(--text-3xl);
  font-weight: var(--weight-bold);
  color: var(--accent-primary);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.ds-hero__count-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
}

.ds-hero__actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

/* ── Section blocks (index page) ───────────────────────────────────────── */
.ds-section-block {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.ds-section-block__header {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border-subtle);
}

.ds-section-block__title {
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  margin: 0;
}

.ds-section-block__desc {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin: 0;
}

/* ── Card grid ──────────────────────────────────────────────────────────── */
.ds-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--space-3);
}

.ds-card {
  display: flex;
}

.ds-card__link {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-4);
  background-color: var(--surface-overlay);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  text-decoration: none;
  color: inherit;
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast), background-color var(--duration-fast);
}

.ds-card__link:hover {
  border-color: var(--accent-primary);
  box-shadow: var(--shadow-md);
  background-color: var(--surface-base);
}

.ds-card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-2);
}

.ds-card__title {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  margin: 0;
  line-height: var(--leading-snug);
}

.ds-card__status {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: var(--weight-bold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  background-color: var(--surface-sunken);
  color: var(--text-secondary);
  white-space: nowrap;
}

.ds-card__status--locked {
  background-color: var(--accent-muted);
  color: var(--accent-primary);
}

.ds-card__status--proposed {
  background-color: var(--status-warning-bg, #fffbeb);
  color: var(--status-warning, #d97706);
}

.ds-card__status--composed {
  background-color: var(--accent-subtle);
  color: var(--accent-primary);
}

.ds-card__desc {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: var(--leading-snug);
  margin: 0;
  flex: 1;
}

.ds-card__foot {
  display: flex;
  justify-content: flex-end;
}

.ds-card__open {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--accent-primary);
}

.ds-card__open .material-symbols-rounded { font-size: 14px; }

/* ── Item detail ────────────────────────────────────────────────────────── */
.ds-item {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-6);
}

@media (min-width: 1024px) {
  .ds-item { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
}

.ds-item__h2 {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  margin: 0 0 var(--space-3);
}

.ds-item__h3 {
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  color: var(--text-secondary);
  margin: 0 0 var(--space-2);
}

.ds-item__live {
  background-color: var(--surface-overlay);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}

.ds-item__live-canvas {
  background-color: var(--surface-base);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  border: 1px dashed var(--border-subtle);
  min-height: 80px;
}

.ds-item__pending {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  align-items: center;
  text-align: center;
  padding: var(--space-6);
  color: var(--text-tertiary);
}

.ds-item__pending-title {
  font-weight: var(--weight-semibold);
  color: var(--text-secondary);
  margin: 0;
}

.ds-item__pending-body {
  font-size: var(--text-sm);
  margin: 0;
  max-width: 50ch;
}

.ds-item__meta {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.ds-item__block {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.ds-item__sources {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.ds-item__sources code {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  background-color: var(--surface-raised);
  padding: 2px var(--space-1);
  border-radius: var(--radius-sm);
}

.ds-item__related {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.ds-item__related li {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ds-item__related a {
  font-size: var(--text-sm);
  color: var(--accent-primary);
  text-decoration: none;
  font-weight: var(--weight-medium);
}

.ds-item__related a:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ds-item__related-sub {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

.ds-item__status-detail {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: var(--leading-relaxed);
  margin: 0;
}

/* ── Focus mode ─────────────────────────────────────────────────────────── */
.ds-focus-body {
  background-color: var(--surface-neutral);
  margin: 0;
}

.ds-focus-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.ds-focus-bar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  background-color: var(--surface-page-translucent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
}

.ds-focus-bar__title {
  flex: 1;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  letter-spacing: var(--tracking-tight);
}

.ds-focus-bar__status {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: var(--weight-bold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
}

.ds-focus-page .ds-item__live {
  border: none;
  border-radius: 0;
  flex: 1;
  padding: var(--space-6);
  background-color: var(--surface-neutral);
}

.ds-focus-page .ds-item__live-canvas {
  background-color: var(--surface-base);
  border: 1px solid var(--border-subtle);
  min-height: 60vh;
}

.ds-focus-page .ds-item__h2 { display: none; }

/* ── Prose (contribute page) ────────────────────────────────────────────── */
.ds-prose {
  max-width: 70ch;
  font-size: var(--text-base);
  color: var(--text-primary);
  line-height: var(--leading-relaxed);
}

.ds-prose h2 {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  margin: var(--space-6) 0 var(--space-2);
  padding-bottom: var(--space-1);
  border-bottom: 1px solid var(--border-subtle);
}

.ds-prose p { margin: 0 0 var(--space-3); }
.ds-prose ol, .ds-prose ul { margin: 0 0 var(--space-3) var(--space-5); }
.ds-prose li { margin-bottom: var(--space-1); }
.ds-prose li ul, .ds-prose li ol { margin-top: var(--space-1); }

.ds-prose code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  color: var(--accent-primary);
  background-color: var(--surface-raised);
  padding: 1px 4px;
  border-radius: var(--radius-sm);
}

.ds-prose strong { color: var(--text-primary); font-weight: var(--weight-semibold); }
.ds-prose a { color: var(--accent-primary); text-decoration: underline; text-underline-offset: 2px; }
.ds-prose a:hover { color: var(--accent-hover); }

/* ── Sibling pager rails (Back / Next within a section) ─────────────────
   Fixed to the viewport sides, vertically centered. Plain text links —
   icon + sibling name, always visible. Hidden below 1280px so they don't
   collide with the centered content column. */
.ds-pager-rail {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: var(--z-sticky);
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  text-decoration: none;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  transition: color var(--duration-fast) var(--ease-out);
}

/* prev sits to the right of the workspace sidebar (which is fixed-left and
   would otherwise cover it). next sits at the viewport's right edge. */
.ds-pager-rail--prev { left: calc(var(--sidebar-width) + var(--space-4)); }
.ds-pager-rail--next { right: var(--space-4); }

.sidebar--collapsed .ds-pager-rail--prev {
  left: calc(var(--sidebar-collapsed) + var(--space-4));
}

.ds-pager-rail:hover { color: var(--accent-primary); }

.ds-pager-rail .material-symbols-rounded {
  font-size: 20px;
  color: inherit;
}

@media (max-width: 1279px) {
  .ds-pager-rail { display: none; }
}

/* ── Foundations · Token blocks ─────────────────────────────────────────
   Each block demos a token family by APPLYING the token to a swatch.
   - Spacing: token applied inline to swatch width/height.
   - Radius:  token applied inline to swatch border-radius (tile-sized fill).
   - Shadow:  token applied inline to swatch box-shadow (card-sized surface). */
.ds-token-block {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}

.ds-token-block:last-child { margin-bottom: 0; }

.ds-token-block__title {
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  color: var(--text-secondary);
  margin: 0;
}

.ds-token-block__row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-5);
}

.ds-token {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
}

.ds-token__label {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

/* Base swatch — Spacing applies width/height inline via var(--space-N);
   no base dimensions here so the token IS the demo. */
.ds-token__swatch { flex-shrink: 0; }

/* Radius swatch — fixed tile size + fill so the corner curve reads at scale. */
.ds-token__swatch--radius {
  width: 64px;
  height: 40px;
  background-color: var(--surface-raised);
  border: 1px solid var(--border-default);
}

/* Shadow swatch — card-sized surface so the elevation reads against the canvas. */
.ds-token__swatch--shadow {
  width: 96px;
  height: 64px;
  background-color: var(--surface-base);
  border-radius: var(--radius-md);
}
