:root {
  --bg: #F5F6F8;
  --card: #FFFFFF;
  --border: #DDE1E7;
  --text: #25272B;
  --text-muted: #5B606B;
  --accent: #526B91;
  --accent-soft: #e8edf4;
  --stage-bg: #ECEEF2;
  --radius: 10px;
  --maxw: 1100px;
  --gutter: 24px;
  --stage-h: min(70vh, 640px);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  line-height: 1.55;
  font-size: 15px;
}

a { color: inherit; }
img { max-width: 100%; }
/* Pulls a lone last word up beside the line above it instead of leaving it
   stranded; no-op in browsers that don't support it. */
p, .card-title, .case-title, .case-summary { text-wrap: pretty; }

.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

/* Skip link */
.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
  border-radius: 0 0 8px 0;
  z-index: 100;
}
.skip-link:focus { left: 0; }

/* ------------------------------- Header -------------------------------- */
/* The logo sits centred with generous space on every side; nav sits below. */
.site-header {
  border-bottom: 1px solid var(--border);
}
.header-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 36px;
  padding-bottom: 18px;
  gap: 22px;
}
.logo-link {
  display: block;
  line-height: 0;
  padding: 4px;
  border-radius: 8px;
}
.site-logo {
  display: block;
  height: 75px;
  width: auto;
}
.primary-nav {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 24px;
}
.primary-nav a {
  text-decoration: none;
  font-weight: 600;
  font-size: 0.86rem;
  color: var(--text-muted);
  padding: 4px 2px;
  border-bottom: 2px solid transparent;
}
.primary-nav a:hover,
.primary-nav a:focus-visible {
  color: var(--text);
  border-bottom-color: var(--accent);
}

/* -------------------------------- Intro -------------------------------- */
.intro {
  padding: 40px 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
}
.intro-text { max-width: 60ch; }
.intro-text h1 {
  font-size: 30px;
  line-height: 1.15;
  margin: 0 0 6px;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.intro-text .subline {
  color: var(--text-muted);
  font-size: 0.92rem;
  margin: 0 0 10px;
}
.intro-text .intro-line {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text);
}
.intro-portrait {
  flex: 0 0 auto;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--accent-soft);
}
/* Closer head-and-shoulders crop: cover-fit first (so the circle is always
   fully covered, no gaps), then zoom in with a transform. This portrait is
   the one approved exception to the no-crop rule below. */
.intro-portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 25%;
  transform: scale(1.35);
  transform-origin: center 28%;
  display: block;
}

/* --------------------------- Category tabs ----------------------------- */
.category-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 2px 0 22px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
@media (max-width: 760px) {
  .category-tabs {
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent 100%);
    mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent 100%);
  }
}
.category-tabs::-webkit-scrollbar { height: 5px; }
.category-tabs::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.tab-btn {
  flex: 0 0 auto;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.84rem;
  padding: 6px 13px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.tab-btn:hover { background: var(--card); border-color: var(--border); color: var(--text); }
.tab-btn[aria-selected="true"] {
  background: var(--accent-soft);
  color: var(--accent);
}

/* True masonry, positioned by JS (see layoutMasonry in app.js): each card is
   placed into whichever column is currently shortest, so cards sit just
   below the card above them with a consistent gap instead of every row
   snapping to its tallest card. Columns start equal (height 0), so the
   first N cards (N = column count) still land across row one in source
   order — the curated lead projects read first without a tall card bumping
   a later one out of the top row. Cards keep their normal DOM position for
   keyboard/tab order; only their visual placement is absolute. */
.project-grid {
  position: relative;
  padding-bottom: 40px;
}

.project-card {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  padding: 0;
  font: inherit;
  color: inherit;
  transition: box-shadow 0.15s ease, top 0.2s ease, left 0.2s ease;
}
.project-card:hover,
.project-card:focus-visible {
  box-shadow: 0 6px 18px rgba(37, 39, 43, 0.07);
}
@media (prefers-reduced-motion: reduce) {
  .project-card { transition: box-shadow 0.15s ease; }
}
/* Card previews show the whole image at its natural shape: no cropping. */
.card-thumb {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--stage-bg);
  line-height: 0;
}
/* Tall (portrait) previews are shown whole but capped, so one card can't
   dominate the grid; the remaining space shows the neutral backdrop. */
.card-thumb img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 380px;
  object-fit: contain;
}
.card-thumb.is-logo {
  background: #fff;
  padding: 14% 18%;
  border-bottom: 1px solid var(--border);
}
.play-badge {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(37, 39, 43, 0.72);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  line-height: 1;
}
.card-body { padding: 12px 14px 14px; }
.card-title { font-weight: 700; font-size: 0.92rem; margin: 0 0 3px; }
.card-desc { color: var(--text-muted); font-size: 0.8rem; margin: 0 0 8px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 3px 9px;
}
.empty-note { color: var(--text-muted); font-size: 0.88rem; padding: 16px 0; }

/* ------------------------------ Sections ------------------------------- */
.section {
  padding: 32px 0;
  border-top: 1px solid var(--border);
}
.section h2 { font-size: 1.15rem; margin: 0 0 6px; }
.section .section-sub {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 0 0 16px;
  max-width: 60ch;
}
.section .section-sub:last-child { margin-bottom: 0; }

.card-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.stub-card {
  display: block;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  padding: 0;
  background: var(--card);
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  transition: box-shadow 0.15s ease;
}
.stub-card:hover,
.stub-card:focus-visible { box-shadow: 0 6px 18px rgba(37, 39, 43, 0.07); }
/* Narrower cards than the main masonry grid, so the shared .card-thumb's
   380px cap would read too tall here; same contain-fit, shorter stage. */
.stub-card .card-thumb img { max-height: 160px; }
.stub-card-body { padding: 14px; }
.stub-card h3 { margin: 0 0 4px; font-size: 0.92rem; }
.stub-card p { margin: 0; color: var(--text-muted); font-size: 0.8rem; }

.profile-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 40px;
}
@media (max-width: 760px) { .profile-grid { grid-template-columns: 1fr; gap: 24px; } }
.profile-grid p { color: var(--text-muted); font-size: 0.9rem; max-width: 62ch; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  padding: 9px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 0.86rem;
}

.site-footer {
  border-top: 1px solid var(--border);
  padding: 22px 0 40px;
  color: var(--text-muted);
  font-size: 0.78rem;
}

/* ----------------------------- Case study ------------------------------ */
.case-study {
  position: fixed;
  inset: 0;
  background: var(--bg);
  overflow-y: auto;
  z-index: 50;
  padding-bottom: 56px;
}
.case-study[hidden] { display: none; }

.case-header {
  position: sticky;
  top: 0;
  background: rgba(245, 246, 248, 0.98);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 12px 0;
  z-index: 5;
}
.close-btn {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-weight: 700;
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--text);
}

.case-body { padding: 28px 0 0; }
.case-head { margin-bottom: 22px; }
.case-eyebrow {
  color: var(--accent);
  font-weight: 700;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 6px;
}
.case-title { font-size: 1.5rem; margin: 0 0 10px; font-weight: 800; line-height: 1.2; }
.case-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.case-summary { font-size: 0.95rem; color: var(--text-muted); max-width: 70ch; margin: 0; }
.status-pill {
  display: inline-block;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.75rem;
  padding: 2px 9px;
  border-radius: 999px;
}

.showcase { margin-bottom: 32px; }

.case-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 40px;
  padding-top: 26px;
  border-top: 1px solid var(--border);
}
@media (max-width: 820px) { .case-grid { grid-template-columns: 1fr; gap: 0; } }
.case-section { margin-bottom: 20px; }
.case-section h2 {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0 0 6px;
}
.case-section p { margin: 0; font-size: 0.92rem; max-width: 64ch; }
.demo-link-btn { margin: 2px 0 20px; font-size: 0.84rem; }
.case-link-top { margin: 2px 0 0; }
.btn-small { padding: 6px 12px; font-size: 0.78rem; }
.showcase-link { margin: -16px 0 32px; }
.case-link-note { font-size: 0.78rem; color: var(--text-muted); margin: 8px 0 0; max-width: 60ch; }

/* ------------------------------ Media viewer ---------------------------- */
/* One main item at its natural shape, with selectable thumbnails below.     */
.viewer-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--stage-bg);
  border-radius: var(--radius);
  padding: clamp(14px, 3vw, 32px);
  min-height: 160px;
}
.viewer-frame {
  display: flex;
  justify-content: center;
  max-width: 100%;
  line-height: 0;
}
.viewer-zoom {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0;
  border: 0;
  background: none;
  cursor: zoom-in;
  max-width: 100%;
  line-height: 0;
  border-radius: 6px;
}
.viewer-frame img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: var(--stage-h);
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(37, 39, 43, 0.08);
}
.viewer-frame video {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  background: transparent;
  object-fit: contain;
}
/* Logos: padded white panel so the mark never touches the edges. */
.viewer-frame.is-logo .viewer-zoom {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(37, 39, 43, 0.08);
  padding: clamp(32px, 7vw, 80px) clamp(36px, 9vw, 110px);
}
.viewer-frame.is-logo img {
  max-width: min(420px, 100%);
  max-height: 200px;
  box-shadow: none;
  border-radius: 0;
}

.viewer-caption { min-height: 1.5em; }
.media-caption {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 10px 0 0;
}
.ai-flag {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  color: #7a4b00;
  background: #ffe9c7;
  border-radius: 999px;
  padding: 1px 7px;
  margin-left: 6px;
  vertical-align: 1px;
}

.thumb-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}
.thumb {
  position: relative;
  flex: 0 0 auto;
  height: 68px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--stage-bg);
  overflow: hidden;
  cursor: pointer;
  line-height: 0;
  opacity: 0.7;
  transition: opacity 0.15s ease, border-color 0.15s ease;
}
.thumb:hover { opacity: 1; }
.thumb[aria-pressed="true"] {
  opacity: 1;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
/* Thumbnails keep each item's natural proportions (no cropping). */
.thumb img {
  display: block;
  height: 100%;
  width: auto;
  max-width: 220px;
  object-fit: contain;
}
.thumb.is-logo { background: #fff; padding: 10px 14px; }
.thumb-play {
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(37, 39, 43, 0.72);
  color: #fff;
  font-size: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* Process viewer is quieter and shorter than the main showcase. */
.process-section {
  margin-top: 16px;
  padding-top: 26px;
  border-top: 1px dashed var(--border);
}
.process-section h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0 0 4px;
}
.process-note { font-size: 0.82rem; color: var(--text-muted); margin: 0 0 14px; }
.viewer.is-compact { --stage-h: min(52vh, 440px); }
.viewer.is-compact .thumb { height: 56px; }

/* -------------------------------- Lightbox ------------------------------ */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(20, 21, 24, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 56px 24px 24px;
}
.lightbox[hidden] { display: none; }
.lightbox-figure {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 100%;
  max-height: 100%;
}
.lightbox-figure img {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 120px);
  width: auto;
  height: auto;
  border-radius: 6px;
}
.lightbox-figure.is-logo img {
  background: #fff;
  padding: clamp(32px, 8vw, 96px);
  max-height: calc(100vh - 120px);
  border-radius: 10px;
}
.lightbox-figure figcaption {
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.82rem;
  margin-top: 10px;
  text-align: center;
}
.lightbox-figure figcaption:empty { display: none; }
.lightbox-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 999px;
  padding: 7px 14px;
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
}
.lightbox-close:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* ------------------------------- Focus ---------------------------------- */
a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ------------------------------- Mobile --------------------------------- */
@media (max-width: 600px) {
  :root { --gutter: 18px; --stage-h: 62vh; }
  .header-inner { padding-top: 28px; padding-bottom: 14px; gap: 16px; }
  .site-logo { height: 60px; }
  .primary-nav { gap: 4px 18px; }
  .intro { padding: 28px 0 22px; gap: 16px; align-items: flex-start; }
  .intro-text h1 { font-size: 24px; }
  .intro-portrait { width: 84px; height: 84px; margin-top: 2px; }
  .case-body { padding-top: 22px; }
  .case-title { font-size: 1.3rem; }
  .viewer-stage { padding: 12px; }
  /* Horizontally scrollable thumbnail strip on phones. */
  .thumb-strip {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    padding-bottom: 6px;
    margin-right: calc(-1 * var(--gutter));
    padding-right: var(--gutter);
  }
  .thumb { scroll-snap-align: start; height: 60px; }
  .thumb img { max-width: 160px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ---------------------- YouTube click-to-load player ---------------------- */
/* Same footprint as the local video player: the box keeps the video's own
   aspect ratio and fits inside the stage height. */
.viewer-frame.is-youtube { width: 100%; }
.yt-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  line-height: normal;
}
.yt-embed {
  position: relative;
  max-width: 100%;
  border-radius: 6px;
  overflow: hidden;
  background: transparent; /* matches the local video player; YouTube's player paints its own black */
}
.yt-poster {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  display: block;
}
.yt-embed .yt-poster img {
  width: 100%;
  height: 100%;
  max-height: none;
  object-fit: contain;
  border-radius: 0;
  box-shadow: none;
}
.yt-play {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(37, 39, 43, 0.78);
  color: #fff;
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-left: 4px;
  transition: background 0.15s ease;
}
.yt-poster:hover .yt-play,
.yt-poster:focus-visible .yt-play { background: var(--accent); }
.yt-poster:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }
.yt-hint {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(37, 39, 43, 0.72);
  color: #fff;
  font-size: 0.75rem;
  white-space: nowrap;
}
.yt-iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}
.yt-fallback {
  margin-top: 10px;
  font-size: 0.8rem;
  color: var(--accent);
}
