/* ============================================================
   Demo Site — Archival Editorial
   ============================================================
   Aesthetic: Technical journal meets court transcript.
   Source Serif 4 for prose, JetBrains Mono for code/numbers.
   Restrained palette. Impeccable vertical rhythm.
   ============================================================ */

/* --- Font Faces (self-hosted, no external CDN) --- */
@font-face {
  font-family: 'Source Serif 4';
  src: url('fonts/SourceSerif4-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Source Serif 4';
  src: url('fonts/SourceSerif4-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Source Serif 4';
  src: url('fonts/SourceSerif4-Italic.woff2') format('woff2');
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: 'JetBrains Mono';
  src: url('fonts/JetBrainsMono-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'JetBrains Mono';
  src: url('fonts/JetBrainsMono-Medium.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

/* --- Custom Properties (Light Mode) --- */
:root {
  /* Palette: warm parchment base, deep ink text */
  --bg: #faf8f5;
  --bg-card: #ffffff;
  --bg-gutter: #f3f0eb;
  --text: #1a1a1a;
  --text-secondary: #6b6560;
  --text-tertiary: #9b9590;
  --border: #e5e0d8;
  --border-strong: #c8c0b5;
  --rule: #1a1a1a;

  /* Phase accent colors — muted, editorial */
  --phase-1: #2563a0;   /* Planning: deep blue */
  --phase-2: #1a7f6e;   /* Formal Workflow: teal */
  --phase-3: #2d7a3a;   /* Implementation: forest */
  --phase-4: #b5760a;   /* PR & Review: amber */
  --phase-5: #7c4dbd;   /* Wrap-up: muted purple */

  /* Diff colors */
  --diff-add-bg: #eaf5ec;
  --diff-add-border: #a3d9a5;
  --diff-remove-bg: #fceced;
  --diff-remove-border: #e8a9ab;
  --diff-remove-marker: #c53030;

  /* Typography */
  --font-serif: 'Source Serif 4', 'Georgia', 'Times New Roman', serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Consolas', monospace;

  /* Spacing scale (based on 1.5rem baseline) */
  --space-xs: 0.375rem;
  --space-sm: 0.75rem;
  --space-md: 1.5rem;
  --space-lg: 3rem;
  --space-xl: 6rem;
}

/* --- Dark Mode --- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111110;
    --bg-card: #1a1918;
    --bg-gutter: #151413;
    --text: #e8e4df;
    --text-secondary: #a09890;
    --text-tertiary: #706860;
    --border: #2a2825;
    --border-strong: #3d3a35;
    --rule: #e8e4df;

    --phase-1: #5b9bd5;
    --phase-2: #4db8a4;
    --phase-3: #5dba6a;
    --phase-4: #dda040;
    --phase-5: #a07de0;

    --diff-add-bg: #132a16;
    --diff-add-border: #2d5a30;
    --diff-remove-bg: #2a1315;
    --diff-remove-border: #5a2d30;
    --diff-remove-marker: #fc8181;
  }
}

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

/* --- Base --- */
html {
  font-size: 17px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-serif);
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
}

a {
  color: var(--text);
  text-decoration-color: var(--border-strong);
  text-underline-offset: 0.15em;
  transition: text-decoration-color 0.2s ease;
}

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

code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--bg-gutter);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}

pre {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.5;
  overflow-x: auto;
  background: var(--bg-gutter);
  padding: var(--space-md);
  border-radius: 3px;
  border: 1px solid var(--border);
}

pre code {
  background: none;
  padding: 0;
}

/* --- Headings in prose --- */
.card-prose h1,
.card-prose h2,
.card-prose h3,
.card-prose h4 {
  font-family: var(--font-serif);
  font-weight: 700;
  margin-top: var(--space-md);
  margin-bottom: var(--space-sm);
}

.card-prose p {
  margin-bottom: var(--space-sm);
}

.card-prose ul, .card-prose ol {
  margin-bottom: var(--space-sm);
  padding-left: 1.5em;
}

.card-prose li {
  margin-bottom: 0.25em;
}

.card-prose strong {
  font-weight: 700;
}

.card-prose em {
  font-style: italic;
}

/* --- Site Header --- */
.site-header {
  max-width: 52rem;
  margin: 0 auto;
  padding: var(--space-xl) var(--space-md) var(--space-lg);
}

.header-rule {
  width: 4rem;
  height: 3px;
  background: var(--rule);
  margin-bottom: var(--space-lg);
}

.header-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: var(--space-sm);
}

.site-header h1 {
  font-family: var(--font-serif);
  font-size: 2.4rem;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin-bottom: var(--space-sm);
}

.subtitle {
  font-size: 1.15rem;
  color: var(--text-secondary);
  line-height: 1.5;
  max-width: 36rem;
}

.header-meta {
  margin-top: var(--space-md);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-tertiary);
  display: flex;
  gap: var(--space-sm);
  align-items: center;
}

.meta-sep {
  color: var(--border-strong);
}

/* --- Timeline Spine --- */
.timeline-spine {
  position: relative;
}

.timeline-spine::before {
  content: '';
  position: absolute;
  left: calc(50% - 26rem + 2.75rem);
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--border);
}

@media (max-width: 56rem) {
  .timeline-spine::before {
    left: 2.75rem;
  }
}

/* --- Site Content --- */
.site-content {
  max-width: 52rem;
  margin: 0 auto;
  padding: 0 var(--space-md) var(--space-lg);
}

/* --- Phase Divider --- */
.phase-divider {
  padding: var(--space-xl) 0 var(--space-lg);
  position: relative;
}

.phase-divider::before {
  content: '';
  display: block;
  width: 100%;
  height: 1px;
  background: var(--border-strong);
  margin-bottom: var(--space-lg);
}

.phase-number {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: var(--space-xs);
}

.phase-title {
  font-family: var(--font-serif);
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.phase-count {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-tertiary);
  margin-top: var(--space-xs);
}

/* Phase intro — rendered between the phase heading and its first exchange */
.phase-intro {
  margin-top: var(--space-md);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.phase-intro blockquote {
  margin: 0;
  padding: var(--space-sm) var(--space-md);
  border-left: 2px solid var(--border-strong);
  background: var(--bg-card);
  border-radius: 0 3px 3px 0;
}

.phase-intro blockquote p {
  margin: 0;
  line-height: 1.6;
}

/* Phase-specific accent colors on dividers */
.phase-divider#phase-1 .phase-number { color: var(--phase-1); }
.phase-divider#phase-2 .phase-number { color: var(--phase-2); }
.phase-divider#phase-3 .phase-number { color: var(--phase-3); }
.phase-divider#phase-4 .phase-number { color: var(--phase-4); }
.phase-divider#phase-5 .phase-number { color: var(--phase-5); }

/* --- Exchange Card --- */
.exchange-card {
  display: grid;
  grid-template-columns: 3.5rem 1fr;
  gap: var(--space-md);
  padding: var(--space-lg) 0;
  border-bottom: 1px solid var(--border);
  position: relative;
}

.exchange-card:last-child {
  border-bottom: none;
}

/* Left border accent per phase */
.exchange-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: var(--space-lg);
  bottom: var(--space-lg);
  width: 2px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.exchange-card.phase-1::before { background: var(--phase-1); }
.exchange-card.phase-2::before { background: var(--phase-2); }
.exchange-card.phase-3::before { background: var(--phase-3); }
.exchange-card.phase-4::before { background: var(--phase-4); }
.exchange-card.phase-5::before { background: var(--phase-5); }

/* --- Card Gutter (exchange number) --- */
.card-gutter {
  padding-top: 0.15rem;
}

.exchange-number {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-tertiary);
  display: block;
  text-align: center;
}

/* --- Card Body --- */
.card-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-xs);
}

.phase-badge {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.15em 0.6em;
  border-radius: 2px;
  border: 1px solid;
}

.phase-badge--1 { color: var(--phase-1); border-color: var(--phase-1); }
.phase-badge--2 { color: var(--phase-2); border-color: var(--phase-2); }
.phase-badge--3 { color: var(--phase-3); border-color: var(--phase-3); }
.phase-badge--4 { color: var(--phase-4); border-color: var(--phase-4); }
.phase-badge--5 { color: var(--phase-5); border-color: var(--phase-5); }

.card-date {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-tertiary);
}

.card-title {
  font-family: var(--font-serif);
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: var(--space-md);
}

.card-prose {
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--text-secondary);
}

.card-prose a {
  color: var(--text-secondary);
}

/* --- Artifact List --- */
.card-artifacts {
  margin-top: var(--space-md);
  padding-top: var(--space-md);
  border-top: 1px solid var(--border);
}

.artifacts-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: var(--space-sm);
}

.artifact-list {
  list-style: none;
  padding: 0;
}

.artifact-ref {
  display: flex;
  align-items: baseline;
  gap: var(--space-sm);
  padding: 0.3rem 0;
  font-size: 0.8rem;
  border-bottom: 1px solid var(--border);
}

.artifact-ref:last-child {
  border-bottom: none;
}

.artifact-seq {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-tertiary);
  background: var(--bg-gutter);
  padding: 0.1em 0.4em;
  border-radius: 2px;
  flex-shrink: 0;
}

.artifact-category {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.artifact-name {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Footer --- */
.site-footer {
  max-width: 52rem;
  margin: 0 auto;
  padding: 0 var(--space-md) var(--space-xl);
}

.footer-rule {
  width: 4rem;
  height: 1px;
  background: var(--border-strong);
  margin-bottom: var(--space-lg);
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-md);
  margin-bottom: var(--space-md);
}

.footer-links a {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-tertiary);
  text-decoration: none;
  letter-spacing: 0.03em;
}

.footer-links a:hover {
  color: var(--text);
}

.footer-colophon {
  font-size: 0.8rem;
  color: var(--text-tertiary);
  font-style: italic;
}

/* --- Staggered Card Entrance (CSS-only, progressive) --- */
@keyframes card-enter {
  from {
    opacity: 0;
    transform: translateY(1.5rem);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.exchange-card {
  animation: card-enter 0.4s ease both;
}

@media (prefers-reduced-motion: reduce) {
  .exchange-card {
    animation: none;
  }

  .artifact-toggle,
  .progress-phase,
  a {
    transition: none;
  }
}

/* --- Responsive --- */
@media (max-width: 56rem) {
  html { font-size: 16px; }

  .site-header {
    padding: var(--space-lg) var(--space-md) var(--space-md);
  }

  .site-header h1 {
    font-size: 1.8rem;
  }

  .exchange-card {
    grid-template-columns: 2.5rem 1fr;
    gap: var(--space-sm);
  }
}

@media (max-width: 36rem) {
  .site-header h1 {
    font-size: 1.5rem;
  }

  .subtitle {
    font-size: 1rem;
  }

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

  .card-gutter {
    display: flex;
    gap: var(--space-sm);
    align-items: center;
  }

  .exchange-number {
    text-align: left;
  }

  .card-title {
    font-size: 1.15rem;
  }
}

/* --- Artifact Panel --- */
.artifact-panel {
  border: 1px solid var(--border);
  border-radius: 3px;
  margin-bottom: var(--space-xs);
}

.artifact-panel:last-child {
  margin-bottom: 0;
}

.artifact-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  width: 100%;
  min-height: 2.75rem; /* 44px touch target */
  padding: 0.5rem 0.75rem;
  background: var(--bg-gutter);
  border: none;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-secondary);
  text-align: left;
  transition: background 0.15s ease;
}

.artifact-toggle:hover {
  background: var(--border);
}

.artifact-toggle[aria-expanded="true"] {
  border-bottom: 1px solid var(--border);
}

.artifact-toggle-icon {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-tertiary);
  flex-shrink: 0;
  width: 1em;
  text-align: center;
  transition: transform 0.2s ease;
}

.artifact-toggle .artifact-seq {
  background: none;
  padding: 0;
}

.artifact-toggle .artifact-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.artifact-version {
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.artifact-has-diff {
  font-size: 0.6rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--phase-3);
  border: 1px solid var(--phase-3);
  padding: 0.05em 0.4em;
  border-radius: 2px;
  flex-shrink: 0;
}

.artifact-content {
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.artifact-content[hidden] {
  display: none;
}

/* View toggle controls (diff vs full) */
.artifact-view-controls {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-gutter);
}

.view-toggle {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.2em 0.5em;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.view-toggle:hover {
  color: var(--text-secondary);
  border-color: var(--border-strong);
}

.view-toggle--active {
  color: var(--text);
  border-color: var(--text);
  background: var(--bg-card);
}

.diff-from {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--text-tertiary);
  margin-left: auto;
}

/* Artifact code block */
.artifact-code {
  margin: 0;
  padding: 0.75rem;
  background: var(--bg-gutter);
  border: none;
  border-radius: 0;
  font-size: 0.75rem;
  line-height: 1.55;
  max-height: 30rem;
  overflow: auto;
}

.artifact-code code {
  background: none;
  padding: 0;
  font-size: inherit;
}

/* --- Diff Block --- */
.diff-block {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.55;
  max-height: 30rem;
  overflow: auto;
}

.diff-line {
  display: flex;
  padding: 0 0.75rem;
  min-height: 1.55em;
}

.diff-marker {
  flex-shrink: 0;
  width: 1.5em;
  text-align: center;
  color: var(--text-tertiary);
  user-select: none;
}

.diff-text {
  flex: 1;
  white-space: pre-wrap;
  word-break: break-all;
}

.diff-line--add {
  background: var(--diff-add-bg);
}

.diff-line--add .diff-marker {
  color: var(--phase-3);
}

.diff-line--remove {
  background: var(--diff-remove-bg);
}

.diff-line--remove .diff-marker {
  color: var(--diff-remove-marker);
}

.diff-line--hunk {
  background: var(--bg-gutter);
  color: var(--text-tertiary);
  font-style: italic;
  padding-top: 0.25em;
  padding-bottom: 0.25em;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.diff-line--hunk .diff-marker {
  color: var(--text-tertiary);
}

.diff-line--header {
  color: var(--text-tertiary);
  font-weight: 500;
}

/* --- Progress Bar / Phase Navigation --- */
.progress-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 0;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* Slight transparency so content peeks through the blur */
@supports (backdrop-filter: blur(8px)) {
  .progress-bar {
    background: color-mix(in srgb, var(--bg) 85%, transparent);
  }
}

.progress-bar-inner {
  max-width: 52rem;
  margin: 0 auto;
  display: flex;
  padding: 0 var(--space-md);
}

.progress-phase {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.6rem 0.75rem;
  text-decoration: none;
  border-bottom: 2px solid transparent;
  transition: border-color 0.2s ease, opacity 0.2s ease;
  opacity: 0.5;
}

.progress-phase:hover {
  opacity: 0.8;
}

.progress-phase.is-active {
  opacity: 1;
  border-bottom-color: currentcolor;
}

.progress-phase.is-active.phase-active--1 { border-bottom-color: var(--phase-1); }
.progress-phase.is-active.phase-active--2 { border-bottom-color: var(--phase-2); }
.progress-phase.is-active.phase-active--3 { border-bottom-color: var(--phase-3); }
.progress-phase.is-active.phase-active--4 { border-bottom-color: var(--phase-4); }
.progress-phase.is-active.phase-active--5 { border-bottom-color: var(--phase-5); }

.progress-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.progress-dot--1 { background: var(--phase-1); }
.progress-dot--2 { background: var(--phase-2); }
.progress-dot--3 { background: var(--phase-3); }
.progress-dot--4 { background: var(--phase-4); }
.progress-dot--5 { background: var(--phase-5); }

.progress-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  color: var(--text-secondary);
  white-space: nowrap;
}

.progress-count {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--text-tertiary);
}

@media (max-width: 56rem) {
  .progress-label {
    display: none;
  }

  .progress-phase {
    padding: 0.5rem 0.6rem;
  }

  .progress-count {
    font-size: 0.55rem;
  }
}

@media (max-width: 36rem) {
  .progress-bar-inner {
    justify-content: center;
  }
}
