/* ==========================================================================
   kevinkeiper.com 4.0 — tokens from design-system.md
   ========================================================================== */
:root {
  --ink: #111111;
  --paper: #F8F8F8;
  --muted: #666666;
  --line: #E0E0E0;
  --line-strong: #CCCCCC;

  --font-sans: 'General Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'Space Mono', 'SF Mono', monospace;

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 16px;
  --sp-4: 24px;
  --sp-5: 32px;
  --sp-6: 48px;
  --sp-7: 64px;
  --sp-8: 96px;
  --sp-9: 144px;

  --radius: 4px;
  --radius-sm: 2px;
  --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.08);

  /* Shared text/gallery measure on detail pages, so paragraph and
     gallery block edges align */
  --content-measure: 46rem;

  /* Short "tick" divider width — used everywhere except header/footer,
     which keep full-width hairlines */
  --divider-w: 64px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; height: auto; display: block; }
a { color: inherit; text-decoration: none; }
ul { list-style: none; margin: 0; padding: 0; }
h1, h2, h3, p, figure { margin: 0; }
h1, h2, h3 { text-wrap: balance; }
p { text-wrap: pretty; }
button, input, textarea { font-family: inherit; font-size: inherit; }

.wrap {
  max-width: 1400px;
  margin-inline: auto;
  padding-inline: var(--sp-4);
}

.section-label {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ==========================================================================
   Header
   ========================================================================== */
.site-header {
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--paper);
  z-index: 10;
}
.site-header__inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-block: var(--sp-3);
}
.site-header__name {
  font-weight: 700;
  letter-spacing: -0.01em;
}
.site-header__nav {
  display: flex;
  align-items: center;
  gap: var(--sp-5);
}
.site-header__link {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--muted);
  transition: color 0.15s ease;
}
.site-header__link:hover {
  color: var(--ink);
}
.site-header__cta {
  font-family: var(--font-mono);
  font-size: 13px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: var(--sp-1) var(--sp-3);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.site-header__cta:hover {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper);
}

/* ==========================================================================
   Hero — oversized, marquee eyebrow, huge type
   ========================================================================== */
.hero {
  padding-top: var(--sp-8);
}
.hero > .wrap {
  position: relative;
  padding-bottom: var(--sp-8);
}
.hero > .wrap::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: var(--sp-4);
  right: var(--sp-4);
  height: 0;
  border-top: 1px solid var(--line);
}
.hero__marquee {
  overflow: hidden;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding-block: var(--sp-3);
  margin-bottom: var(--sp-8);
}
.hero__marquee-track {
  display: flex;
  width: max-content;
  animation: marquee 28s linear infinite;
}
.hero__marquee-track span {
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  padding-inline: var(--sp-4);
  white-space: nowrap;
}
.hero__marquee-track span::after {
  content: '/';
  margin-left: var(--sp-4);
  color: var(--line-strong);
}
@keyframes marquee {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}
@media (prefers-reduced-motion: reduce) {
  .hero__marquee-track { animation: none; }
}

.hero__headline {
  font-size: clamp(3rem, 9vw, 8rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 0.95;
  margin-bottom: var(--sp-6);
  max-width: 20ch;
}
.hero__headline em {
  font-style: normal;
  color: var(--muted);
}
.hero__meta {
  display: flex;
  gap: var(--sp-8);
  flex-wrap: wrap;
  border-top: 1px solid var(--line);
  padding-top: var(--sp-5);
}
.hero__meta-item {
  max-width: 32ch;
}
.hero__meta-item .section-label {
  display: block;
  margin-bottom: var(--sp-2);
}
.hero__meta-item p {
  font-size: 1.0625rem;
  color: var(--muted);
}

/* ==========================================================================
   Case studies — full-width alternating rows, numbered, asymmetric
   ========================================================================== */
.case-studies {
  padding-block: calc(var(--sp-8) - 40px) var(--sp-8);
  scroll-margin-top: 57px;
}
.case-studies > .wrap > .section-label {
  display: block;
  margin-bottom: var(--sp-6);
}

.case-row {
  display: grid;
  grid-template-columns: 0.9fr 1.1fr;
  gap: var(--sp-7);
  align-items: center;
  padding-block: var(--sp-8);
  border-top: 1px solid var(--line);
  opacity: 0;
  transform: translateY(32px);
  transition: opacity 0.7s cubic-bezier(0.16,1,0.3,1), transform 0.7s cubic-bezier(0.16,1,0.3,1);
}
.case-row.is-visible { opacity: 1; transform: translateY(0); }
.case-row:first-of-type { border-top: none; }
.case-row:last-child { border-bottom: 1px solid var(--line); }
.case-row--reverse { grid-template-columns: 1.1fr 0.9fr; }
.case-row--reverse .case-row__media { order: 2; }
.case-row--reverse .case-row__body { order: 1; }

.case-row__index {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--line-strong);
  display: block;
  margin-bottom: var(--sp-3);
}

.case-row__media {
  display: block;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line-strong);
  background: #F6F6F6;
  transition: box-shadow 0.25s ease, transform 0.25s ease;
}
.case-row__media:hover {
  box-shadow: var(--shadow-hover);
}
.case-row__media img {
  width: 100%;
  height: auto;
  transition: transform 0.5s cubic-bezier(0.16,1,0.3,1);
}
.case-row__media:hover img {
  transform: scale(1.03);
}

.case-row__title {
  font-size: clamp(1.75rem, 3.5vw, 3rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.05;
  margin-bottom: var(--sp-4);
}
.case-row__desc {
  color: var(--muted);
  font-size: 1.125rem;
  line-height: 1.6;
  max-width: 48ch;
  margin-bottom: var(--sp-5);
}

/* Doc quote — a real excerpt from one of the project's own .md files */
.doc-quote {
  max-width: var(--content-measure);
  margin-top: var(--sp-5);
  border-left: 2px solid var(--line-strong);
  padding-left: var(--sp-4);
}
.doc-quote__file {
  display: block;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  margin-bottom: var(--sp-2);
}
.doc-quote__text {
  font-family: var(--font-mono);
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--ink);
}

/* Example exchange — real prompt/outcome pairs, used sparingly */
.exchange-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-5);
  margin-top: var(--sp-6);
  max-width: var(--content-measure);
}
.exchange {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--sp-4);
}
.exchange__prompt {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--ink);
  padding-left: var(--sp-3);
  border-left: 2px solid var(--line-strong);
  margin-bottom: var(--sp-3);
}
.exchange__prompt::before {
  content: '"';
}
.exchange__prompt::after {
  content: '"';
}
.exchange__result {
  font-size: 0.9375rem;
  color: var(--muted);
  line-height: 1.55;
}
.exchange__result strong {
  color: var(--ink);
  font-weight: 600;
}
@media (max-width: 767px) {
  .exchange-grid { grid-template-columns: 1fr; }
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}
.tag {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: var(--sp-1) var(--sp-2);
}

/* ==========================================================================
   Contact — one bold statement
   ========================================================================== */
.contact {
  padding-block: var(--sp-8);
}
.contact__grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: var(--sp-7);
  align-items: start;
}
.contact__headline {
  font-size: clamp(2rem, 5vw, 4rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.05;
  max-width: 16ch;
}

.contact-form {
  max-width: 480px;
}
.field { margin-bottom: var(--sp-4); }
.field label {
  display: block;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: var(--sp-2);
}
.field input,
.field textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: var(--sp-2) var(--sp-3);
  color: var(--ink);
  background: var(--paper);
  transition: border-color 0.15s ease;
}
.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--ink);
}
.field textarea { resize: vertical; }

.btn {
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--ink);
  color: var(--paper);
  border: 1px solid var(--ink);
  border-radius: var(--radius-sm);
  padding: var(--sp-3) var(--sp-5);
  cursor: pointer;
  transition: opacity 0.15s ease;
}
.btn:hover { opacity: 0.8; }

.form-status {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--muted);
  margin-top: var(--sp-3);
  min-height: 1.2em;
}

/* ==========================================================================
   Footer
   ========================================================================== */
.site-footer {
  border-top: 1px solid var(--line);
  padding-block: var(--sp-4);
}
.site-footer p {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
}

/* ==========================================================================
   Case study detail pages
   ========================================================================== */
.back-link {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  transition: color 0.15s ease;
}
.back-link:hover { color: var(--ink); }

.detail-hero {
  padding-block: var(--sp-8) var(--sp-6);
}
.detail-hero__eyebrow {
  margin-bottom: var(--sp-3);
}
.detail-hero__title {
  font-size: clamp(2.5rem, 6vw, 5rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
  margin-bottom: var(--sp-5);
  max-width: 20ch;
}
.detail-hero__desc {
  font-size: 1.1875rem;
  color: var(--muted);
  max-width: 60ch;
  margin-bottom: var(--sp-6);
}
.detail-hero__meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-7);
  border-top: 1px solid var(--line);
  padding-top: var(--sp-5);
}
.detail-hero__meta-item .section-label {
  display: block;
  margin-bottom: var(--sp-2);
}
.detail-hero__meta-item p {
  font-size: 1rem;
}
.detail-hero__meta-item p.is-placeholder {
  color: var(--line-strong);
  font-style: italic;
}

.detail-hero-row {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: var(--sp-7);
  align-items: start;
  margin-bottom: var(--sp-6);
}

.detail-lead-image {
  display: block;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #F6F6F6;
}
.detail-lead-image img {
  width: 100%;
  height: auto;
}
.detail-lead-image--crop {
  background: #fff;
}
.detail-lead-image--crop img {
  height: 405px;
  object-position: left 5px;
  object-fit: cover;
}

@media (max-width: 900px) {
  .detail-hero-row { grid-template-columns: 1fr; }
}

.detail-section {
  padding-block: var(--sp-8);
  border-bottom: 1px solid var(--line);
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 0.7s cubic-bezier(0.16,1,0.3,1), transform 0.7s cubic-bezier(0.16,1,0.3,1);
}
.detail-section.is-visible { opacity: 1; transform: translateY(0); }
.detail-section:last-of-type { border-bottom: none; }

.detail-section__title {
  font-size: clamp(1.5rem, 3vw, 2.25rem);
  font-weight: 700;
  letter-spacing: -0.01em;
  max-width: 24ch;
  margin-bottom: var(--sp-5);
}
.detail-section__row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-8);
  align-items: start;
}
@media (max-width: 767px) {
  .detail-section__row { grid-template-columns: 1fr; }
}

/* Centered feature — for the rare centerpiece artifact that earns
   more visual weight than the standard left/right row. Use sparingly. */
.detail-section--centered .wrap {
  text-align: center;
}
.detail-section--centered .detail-section__title {
  max-width: none;
  margin-inline: auto;
}
.detail-section--centered .detail-section__body {
  max-width: var(--content-measure);
  margin-inline: auto;
}
.detail-section--centered .detail-lead-image,
.detail-section--centered .detail-section__feature {
  margin-top: var(--sp-6);
  text-align: left;
}

.detail-section__body {
  font-size: 1.0625rem;
  color: var(--muted);
  line-height: 1.65;
  max-width: var(--content-measure);
}
.detail-section__body p + p { margin-top: var(--sp-4); }
.detail-section__body p.is-placeholder {
  color: var(--line-strong);
  font-style: italic;
}

.detail-gallery {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  align-items: start;
  gap: var(--sp-5);
  margin-top: var(--sp-6);
}
.detail-gallery--masonry {
  display: block;
  column-count: 2;
  column-gap: var(--sp-5);
}
.detail-gallery--masonry .detail-gallery__item {
  break-inside: avoid;
  margin-bottom: var(--sp-5);
}
.detail-gallery--4up {
  grid-template-columns: repeat(4, 1fr);
}
@media (max-width: 900px) {
  .detail-gallery--masonry { column-count: 1; }
  .detail-gallery--4up { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
  .detail-gallery--4up { grid-template-columns: 1fr; }
}

/* Single supporting image beside a paragraph (Problem/Hypothesis-style):
   width matches the paragraph's own measure, not the leftover column
   space — bigger images don't get to just fill whatever room is left. */
.detail-section__row .detail-lead-image,
.rail-content > div > .detail-lead-image {
  max-width: var(--content-measure);
}

/* Multi-up galleries (2-col grid or masonry) inside a rail section must
   stay within the paragraph's own measure too — same reasoning as the
   single-image rule above. --4up is exempt: it intentionally runs wider
   than the text column. */
.rail-content .detail-gallery:not(.detail-gallery--4up) {
  max-width: var(--content-measure);
}

/* ==========================================================================
   Sticky rail layout — left rail (title/context) stays pinned while the
   right column's content for that section scrolls past. Each .rail-row
   pairs one rail-item with its own rail-content; the sticky item is
   scoped to its own row, so the next row's item takes over naturally
   once its row starts.
   ========================================================================== */
.rail-wrap {
  padding-block: var(--sp-6) var(--sp-8);
}
.rail-row {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: var(--sp-7);
  padding-block: var(--sp-7);
  border-top: 1px solid var(--line);
}
.rail-row:last-child {
  border-bottom: 1px solid var(--line);
}
.rail-item {
  align-self: start;
  position: sticky;
  top: 57px; /* site-header's rendered height, so the index number sits flush under it, not the title */
  padding-top: var(--sp-3);
}
.rail-item__index {
  display: block;
  margin-bottom: var(--sp-2);
}
.rail-item .detail-section__title {
  font-size: 1.375rem;
  max-width: none;
  margin-bottom: 0;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.rail-item__icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  stroke: var(--ink);
}
.rail-content .detail-section__body {
  max-width: var(--content-measure);
}
.rail-content .detail-gallery {
  margin-top: var(--sp-6);
}
@media (max-width: 900px) {
  .rail-row { grid-template-columns: 1fr; gap: var(--sp-4); }
  .rail-item { position: static; }
}

/* ==========================================================================
   Lightbox — click any gallery/lead image (not ones already wrapped in
   a link, e.g. a PDF link) to view it enlarged.
   ========================================================================== */
.detail-gallery__item img:not(a img),
.detail-lead-image img {
  cursor: zoom-in;
}
.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 17, 17, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-6);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.lightbox-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}
.lightbox-frame {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 90vw;
  max-height: 90vh;
}
.lightbox-overlay img {
  max-width: 90vw;
  max-height: 82vh;
  width: auto;
  height: auto;
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  cursor: zoom-out;
}
.lightbox-caption {
  font-family: var(--font-mono);
  font-size: 13px;
  color: rgba(255, 255, 255, 0.75);
  text-align: center;
  max-width: 60ch;
  margin-top: var(--sp-4);
}
.lightbox-close {
  position: absolute;
  top: var(--sp-4);
  right: var(--sp-4);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.16);
}

.detail-gallery__item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #F6F6F6;
}
.detail-gallery__item img { width: 100%; height: auto; }
.detail-gallery__item--plain {
  border: none;
  border-radius: 0;
  background: none;
}
.detail-gallery__caption {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  margin-top: var(--sp-3);
  padding-inline: var(--sp-3);
  padding-bottom: var(--sp-3);
}

/* Tool badges — mono label + monochrome glyph, no brand color */
.tool-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
}
.tool-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.02em;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: var(--sp-2) var(--sp-3);
}
.tool-badge svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  stroke: var(--ink);
}
.tool-badge img {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  border-radius: 3px;
  object-fit: contain;
}

/* Certificate thumbnails — clickable, open the full certificate file */
.cert-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-4);
}
.cert-badge a {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  width: 140px;
}
.cert-badge img {
  width: 140px;
  height: auto;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.cert-badge a:hover img {
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}
.cert-badge span {
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.4;
  color: var(--muted);
}

/* Metrics */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--sp-5);
  margin-top: var(--sp-6);
}
.stat-tile {
  border-top: 1px solid var(--line-strong);
  padding-top: var(--sp-3);
}
.stat-tile__number {
  font-size: clamp(1.75rem, 3vw, 2.5rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
}
.stat-tile__label {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-top: var(--sp-2);
}

.detail-nav {
  padding-block: var(--sp-7);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-4);
}
.detail-nav a {
  font-family: var(--font-mono);
  font-size: 13px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: var(--sp-2) var(--sp-4);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.detail-nav a:hover {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper);
}

/* ==========================================================================
   Mobile
   ========================================================================== */
@media (max-width: 900px) {
  .case-row,
  .case-row--reverse {
    grid-template-columns: 1fr;
  }
  .detail-gallery { grid-template-columns: 1fr; }
  .case-row--reverse .case-row__media,
  .case-row--reverse .case-row__body {
    order: initial;
  }
  .contact__grid { grid-template-columns: 1fr; }
}
@media (max-width: 767px) {
  .wrap { padding-inline: var(--sp-3); }
  .hero { padding-block: var(--sp-6) var(--sp-6); }
  .hero__meta { gap: var(--sp-5); }
  .hero > .wrap::after { left: var(--sp-3); right: var(--sp-3); }
}
@media (max-width: 600px) {
  .site-header__inner { flex-wrap: wrap; row-gap: var(--sp-2); }
  .site-header__nav { width: 100%; justify-content: flex-end; gap: var(--sp-4); }
}
@media (max-width: 420px) {
  .hero__headline { font-size: clamp(2.25rem, 11vw, 8rem); overflow-wrap: break-word; }
  .detail-hero__title { overflow-wrap: break-word; }
}
