/* Shared foundation for every page: tokens, base, type scale, layout rhythm, media
   surfaces, reveal motion, back/next links and the footer. Loaded before each page's
   own <style>, so a page only defines what is unique to it. The header capsule lives
   in css/header.css. */

/* ============ TOKENS ============
   Live in css/tokens.css, generated from design-skill/tokens.json (scripts/build-tokens.mjs).
   Every page links tokens.css before this file. Accent colours use --primary / --secondary /
   --tertiary (and their -rgb triplets) so the token game (js/token-game.js) can change them. */

/* ============ BASE ============ */
*, *::before, *::after { box-sizing: border-box; }
html { overflow-x: clip; scroll-behavior: smooth; scroll-padding-top: 88px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}
::selection { background: var(--selection); color: var(--ink); }
a { -webkit-tap-highlight-color: transparent; }
img, video { max-width: 100%; }
a:focus-visible, button:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: 4px; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

/* ============ LAYOUT ============ */
.wrap, .rp-wrap { margin: 0; padding-left: var(--gutter); padding-right: var(--gutter); }
.pad, .section { padding-top: var(--section-y); padding-bottom: var(--section-y); }
.section + .section { border-top: 1px solid var(--line-soft); }
.bg-sage { background: var(--bg-sage); }
.bg-deep { background: var(--bg-deep); }
.prose { max-width: 66ch; }

/* back link rows above the hero and above the footer */
.back-row { padding-top: var(--header-clear); }
.back-row--end { padding-top: 0; padding-bottom: 40px; }

/* ============ TYPE ============ */
h1 {
  font-family: var(--font-display); font-weight: 400;
  font-size: var(--fs-h1); line-height: 1.04; letter-spacing: -.04em;
  margin: 0 0 24px; max-width: 20ch; text-wrap: balance;
}
h2 {
  font-family: var(--font-display); font-weight: 300;
  font-size: var(--fs-h2); line-height: 1.1; letter-spacing: -.035em;
  margin: 0 0 20px; color: inherit; text-wrap: balance;
}
h3 {
  font-family: var(--font-display); font-weight: 400;
  font-size: var(--fs-h3); line-height: 1.3; letter-spacing: -.02em;
  margin: 0 0 12px; color: var(--ink);
}
/* Once a visitor picks a colour (js/brand.js sets data-brand on <html>), section titles and the home page's case
   titles take the picked primary. With no pick they keep the ink colour. Titles on dark bands set an inline white,
   which still wins; .tg-next is a small mono label, not a title. */
html[data-brand] h2:not(.tg-next),
html[data-brand] .rp-case__title { color: var(--primary); }
.eyebrow {
  font-family: var(--font-mono); font-size: var(--fs-label); font-weight: 500;
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--primary); margin-bottom: 20px;
}
.eyebrow--warm { color: var(--tertiary); }
.section-label {
  font-family: var(--font-mono); font-size: 11px; font-weight: 500;
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--label); margin-bottom: 16px;
}
.lead { font-size: var(--fs-lead); line-height: 1.6; color: var(--ink-2); max-width: 58ch; margin: 0; text-wrap: pretty; }
.body-lg, .body-text, .body-sm { font-size: var(--fs-body); line-height: 1.7; color: var(--body); text-wrap: pretty; }
.body-text { max-width: 66ch; }
.body-sm { line-height: 1.6; }
.body-lg strong, .body-text strong { font-weight: 600; color: var(--ink); }
.body-lg strong.accent { color: var(--primary); }
.body-text + .body-text { margin-top: 16px; }
.img-caption {
  font-family: var(--font-mono); font-size: var(--fs-caption); line-height: 1.55;
  letter-spacing: .02em; color: var(--label); margin: 12px 0 0; text-wrap: pretty;
}
.img-caption--center { text-align: center; }

/* ============ CASE STUDY HERO ============ */
.hero { position: relative; padding: clamp(40px, 6vw, 72px) 0 var(--block-gap); }
.meta, .meta-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 24px 32px; padding: 28px 0; margin: 40px 0 0;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.meta-lbl {
  font-family: var(--font-mono); font-size: 11px; font-weight: 500;
  letter-spacing: .1em; text-transform: uppercase; color: var(--label); margin-bottom: 8px;
}
.meta-val { font-size: 15px; line-height: 1.5; color: var(--ink); }

/* ============ MEDIA SURFACES ============ */
.cs-img, .media {
  display: block; width: 100%; height: auto;
  border-radius: var(--r-media); box-shadow: var(--shadow-media);
  outline: 1px solid var(--image-outline); outline-offset: -1px;
}
.cs-img--hero { box-shadow: var(--shadow-media-lg); margin: 0; }
.cs-img--sm, .cs-img--flat { box-shadow: 0 16px 40px -22px rgb(var(--ink-rgb) / .3); }

/* framed product image: a tinted panel around a screenshot (from the Scenario Catalog page) */
.showcase {
  position: relative; margin-top: var(--block-gap);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: clamp(26px, 5vw, 56px); border-radius: var(--r-box);
  background: rgba(236,230,212,.7); border: 1px solid rgb(var(--ink-rgb) / .06);
  box-shadow: var(--shadow-box);
}
.showcase img { display: block; width: 66.666%; height: auto; border-radius: var(--r-sm); }
.showcase--sage { background: rgb(var(--showcase-sage-rgb) / .7); }
/* a screen recording inside the frame, with its play/pause pill underneath */
.vid-box { position: relative; display: flex; flex-direction: column; align-items: center; width: 100%; }
.vid-box .vid-wrap { position: relative; width: 66.666%; line-height: 0; border-radius: var(--r-sm); overflow: hidden; box-shadow: 0 14px 30px -16px rgb(var(--ink-rgb) / .28); }
.vid-box .vid-wrap video { display: block; width: 100%; height: auto; }
.vid-box > .vid-ctrl {
  position: static; display: flex; justify-content: center; padding: 16px 0 0; background: none;
  opacity: 0; transition: opacity .25s;
}
.vid-box:hover > .vid-ctrl, .vid-box:focus-within > .vid-ctrl { opacity: 1; }
@media (hover: none) { .vid-box > .vid-ctrl { opacity: 1; } }
.vid-box .vid-btn {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: .08em; color: var(--ink);
  padding: 7px 18px; border-radius: 20px; cursor: pointer;
  background: rgb(var(--ink-rgb) / .06); border: 1px solid rgb(var(--ink-rgb) / .14);
  -webkit-backdrop-filter: none; backdrop-filter: none; transition: background-color .2s;
}
@media (hover: hover) { .vid-box .vid-btn:hover { background: rgb(var(--ink-rgb) / .12); } }
@media (max-width: 640px) { .showcase img, .vid-box .vid-wrap { width: 80%; } }

/* masking tape label pinned to a media corner ("Pending Patent", etc.) */
.tape-tag {
  position: absolute; top: -16px; left: 28px; z-index: 2;
  display: inline-block; padding: 7px 14px; border-radius: 3px;
  background: var(--bg-sage); color: var(--primary);
  border: 1px solid rgb(var(--primary-rgb) / .12);
  font-family: var(--font-mono); font-size: 10px; font-weight: 500;
  letter-spacing: .13em; text-transform: uppercase;
  box-shadow: 2px 4px 14px rgb(var(--primary-rgb) / .18), 0 1px 3px rgba(0,0,0,.1);
  transform: rotate(-3deg); transform-origin: top left; pointer-events: none;
}
.tape-tag__tape {
  position: absolute; top: -8px; left: 50%; transform: translateX(-50%);
  display: block; width: 32px; height: 13px; border-radius: 2px;
  background: rgb(var(--primary-rgb) / .1);
}

/* lift on hover, only where a real pointer can hover */
.img-hover, .cs-img { transition: transform .45s var(--ease), box-shadow .45s var(--ease); }
@media (hover: hover) {
  .img-hover:hover { transform: translateY(-4px); }
  .cs-img:hover { transform: translateY(-4px); box-shadow: var(--shadow-media-lg); }
}

/* ============ BUTTONS (page level; the header scopes its own) ============ */
.rp-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-family: var(--font-sans); font-size: 14px; font-weight: 500; line-height: 1;
  color: var(--ink-2); text-decoration: none;
  height: 40px; padding: 0 18px; border-radius: var(--r-sm);
  background: rgba(255,255,255,.6);
  border: 1px solid rgb(var(--ink-rgb) / .08);
  box-shadow: 0 4px 14px -7px rgb(var(--ink-rgb) / .22);
  transition-property: transform, background-color, box-shadow, color, filter;
  transition-duration: .25s; transition-timing-function: var(--ease);
}
.rp-btn--warm { background: var(--cta-bg); color: var(--on-primary); border-color: transparent; }
.rp-ext { font-size: 13px; display: inline-block; transition: transform .28s var(--ease); }
.rp-btn:active { transform: scale(.96); transition-duration: .15s; transition-timing-function: ease-out; }
@media (hover: hover) {
  .rp-btn:hover { transform: translateY(-2px); background: #fff; color: var(--ink); box-shadow: 0 14px 28px -10px rgb(var(--ink-rgb) / .32); }
  .rp-btn--warm:hover { background: var(--cta-bg); color: var(--on-primary); filter: brightness(1.08); }
  .rp-btn:hover .rp-ext { transform: translate(3px,-3px); }
}

/* ============ BACK / NEXT ============ */
.back {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--font-mono); font-size: var(--fs-label); letter-spacing: .06em;
  color: var(--primary); text-decoration: none;
  border-bottom: 1px solid rgb(var(--primary-rgb) / .3); padding-bottom: 3px;
  transition: border-color .25s;
}
.back:hover { border-bottom-color: rgb(var(--primary-rgb) / .9); }
.back__arrow, .next-link__arrow { display: inline-block; transition: transform .3s var(--ease); }
.back:hover .back__arrow { transform: translateX(-4px); }

.next-project { text-align: center; padding: clamp(56px, 7vw, 88px) 0; margin-top: var(--section-y); border-top: 1px solid var(--line-soft); }
.next-label {
  font-family: var(--font-mono); font-size: 11px; font-weight: 500;
  letter-spacing: .14em; text-transform: uppercase; color: var(--label); margin-bottom: 16px;
}
.next-link {
  display: inline-flex; align-items: center; gap: 10px;
  font-family: var(--font-display); font-size: clamp(22px, 3vw, 32px); font-weight: 400;
  letter-spacing: -.03em; color: var(--ink); text-decoration: none; text-wrap: balance;
  border-bottom: 2px solid rgb(var(--primary-rgb) / .3); padding-bottom: 4px;
  transition: border-color .25s, color .25s;
}
.next-link:hover { color: var(--primary); border-bottom-color: var(--primary); }
.next-link:hover .next-link__arrow { transform: translateX(5px); }

/* ============ FOOTER ============ */
.rp-footer { width: 100%; background: var(--bg-sand); border-top: 1px solid var(--line-soft); padding: 40px 0; }
.rp-footer__inner { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 20px; }
.rp-footer__name {
  font-family: var(--font-display); font-weight: 400; font-size: 18px; letter-spacing: -.02em;
  color: var(--ink-soft); text-decoration: none; transition: color .25s;
}
.rp-footer__name:hover { color: var(--primary); }
.rp-footer__nav { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.rp-fbtn {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 14px; font-weight: 500; color: var(--ink-2); text-decoration: none;
  height: 40px; padding: 0 18px; border-radius: var(--r-sm);
  background: rgba(255,255,255,.6); border: 1px solid rgb(var(--ink-rgb) / .08);
  transition-property: transform, background-color, box-shadow;
  transition-duration: .25s; transition-timing-function: var(--ease);
}
.rp-fbtn:active { transform: scale(.96); transition-duration: .15s; transition-timing-function: ease-out; }
@media (hover: hover) {
  .rp-fbtn:hover { transform: translateY(-2px); background: #fff; box-shadow: 0 12px 24px -12px rgb(var(--ink-rgb) / .3); }
}

/* reading progress (filled by js/header.js) */
#rp-prog {
  position: fixed; top: 0; left: 0; z-index: 200;
  height: 3px; width: 0%;
  background: var(--progress-bg);
  pointer-events: none;
}

/* ============ REVEAL ============
   Pages use one of three hooks; all share one motion: a 16px rise and fade.
   .rv / .rv2 / .rv3 run once on load, 100ms apart. The rest wait for
   IntersectionObserver to add .is-visible / .is-in / .visible.
   Under reduced motion everything only fades. */
@keyframes revealUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes revealFade { from { opacity: 0; } to { opacity: 1; } }
.rv, .rv2, .rv3 { animation: revealUp .8s var(--ease) both; }
.rv2 { animation-delay: .1s; }
.rv3 { animation-delay: .2s; }

.reveal, [data-reveal], .reveal-group > *, [data-reveal-group] > * {
  opacity: 0; transform: translateY(16px);
  transition: opacity .7s var(--ease), transform .7s var(--ease);
}
.reveal.is-visible, .reveal.is-in, [data-reveal].visible,
.reveal-group.is-visible > *, [data-reveal-group].visible > * { opacity: 1; transform: none; }
.reveal-group.is-visible > :nth-child(2), [data-reveal-group].visible > :nth-child(2) { transition-delay: .1s; }
.reveal-group.is-visible > :nth-child(3), [data-reveal-group].visible > :nth-child(3) { transition-delay: .2s; }
.reveal-group.is-visible > :nth-child(4), [data-reveal-group].visible > :nth-child(4) { transition-delay: .3s; }
.reveal-group.is-visible > :nth-child(n+5), [data-reveal-group].visible > :nth-child(n+5) { transition-delay: .4s; }

@media (prefers-reduced-motion: reduce) {
  .rv, .rv2, .rv3 { animation-name: revealFade; }
  .reveal, [data-reveal], .reveal-group > *, [data-reveal-group] > * { transform: none; transition: opacity .4s ease-out; }
}

/* ============ RESPONSIVE ============ */
@media (max-width: 640px) {
  :root { --gutter: 20px; --header-clear: 64px; }
  .meta, .meta-grid { grid-template-columns: 1fr 1fr; gap: 16px; }
  .rp-footer { padding: 32px 0; }
  .rp-footer__inner { flex-direction: column; align-items: flex-start; gap: 16px; }
  .rp-footer__nav { justify-content: flex-start; gap: 8px; }
  .rp-fbtn { height: 36px; padding: 0 14px; font-size: 13px; }
}
