:root {
  --bg: #0d0e11;
  --page: #16181c;
  --page-2: #1d2025;
  --text: #f3f1ec;
  --muted: #a9adb4;
  --accent: #29a8e0;
  --bar-h: 64px;
  /* Nav bar plus the iPhone home-indicator area, so the buttons never sit under it. */
  --bar-total: calc(var(--bar-h) + env(safe-area-inset-bottom, 0px));
  --head: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  -webkit-text-size-adjust: 100%;
}

body { overflow-x: hidden; }

/* ---------- Stage: the book fits the visible screen ---------- */

.stage {
  height: calc(100vh - var(--bar-total));
  height: calc(100dvh - var(--bar-total));
  display: flex;
  /* "safe": if a page is taller than the screen (phone turned sideways), it starts at the top and scrolls. */
  align-items: safe center;
  justify-content: center;
  padding: 8px;
  overflow-x: hidden;
  overflow-y: auto;
}

/* One page (5:8), as big as fits, but never narrower than 330px so text stays readable
   (the stage scrolls instead), and capped at 540px so StPageFlip stays in single-page mode
   (it switches to a spread at width >= minWidth * 2 = 560). */
.book-wrap {
  width: min(96vw, max(calc((100vh - var(--bar-total) - 16px) * 0.625), 330px), 540px);
  width: min(96vw, max(calc((100dvh - var(--bar-total) - 16px) * 0.625), 330px), 540px);
}

/* Wide screens tall enough for a spread of at least 560 px: (528 - 80) * 1.25 = 560. */
@media (min-aspect-ratio: 6/5) and (min-height: 528px) {
  .book-wrap {
    width: min(96vw, calc((100vh - var(--bar-total) - 16px) * 1.25));
    width: min(96vw, calc((100dvh - var(--bar-total) - 16px) * 1.25));
  }
}

/* ---------- Pages ---------- */

.page {
  container-type: size; /* page-relative sizing (cqw) for everything inside */
  background: var(--page);
  color: var(--text);
  overflow: hidden;
  position: relative;
}

.page--cover, .page--back { background: #101114; }

/* Everything inside a page scales with the page width (cqw), with a floor for small phones. */
.pg {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: 7cqw 7cqw 8cqw;
  gap: 3cqw;
  font-size: max(14px, 3.5cqw);
  line-height: 1.45;
}

.pg h1, .pg h2, .pg h3 {
  font-family: var(--head);
  font-weight: 700;
  line-height: 0.98;
  margin: 0;
  letter-spacing: 0.005em;
}
.pg h2 { font-size: 10cqw; text-transform: uppercase; }
.pg h2 span, .pg h1 span { color: var(--accent); }
.pg h3 { font-size: 7cqw; text-transform: uppercase; }
.pg p { margin: 0; }

.eyebrow {
  font-size: max(11px, 2.6cqw);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 1.5cqw !important;
}

.rule { width: 12cqw; height: 0.8cqw; min-height: 3px; background: var(--accent); }

.folio {
  position: absolute;
  bottom: 3.5cqw;
  right: 6cqw;
  font-size: max(11px, 2.6cqw);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.page:nth-child(even) .folio { right: auto; left: 6cqw; }

/* ---------- Cover ---------- */

.pg-cover { padding: 0; gap: 0; }
.cover__photo { flex: 1 1 55%; min-height: 0; position: relative; }
.cover__photo::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(to bottom, rgba(16, 17, 20, 0) 55%, #101114 100%);
}
.cover__body { padding: 0 7cqw 9cqw; display: flex; flex-direction: column; gap: 3.5cqw; }
.cover__logo { width: 42cqw; height: auto; margin-top: -10cqw; position: relative; }
.cover__title { font-size: 15cqw; text-transform: uppercase; }
.cover__creds { color: var(--muted); font-size: max(14px, 3.4cqw); }

/* ---------- Text pages ---------- */

.lead { color: var(--muted); }

.creds, .services, .projects, .why { list-style: none; margin: 0; padding: 0; }

.creds { display: grid; gap: 1.8cqw; }
.creds li {
  border-left: 0.8cqw solid var(--accent);
  padding: 1.6cqw 0 1.6cqw 3.5cqw;
  background: var(--page-2);
  display: flex; flex-direction: column;
}
.creds strong { font-weight: 600; }
.creds span { color: var(--muted); font-size: max(14px, 0.9em); }

.mission {
  margin-top: auto !important;
  font-style: italic;
  color: var(--muted);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 2cqw;
}

.services { display: grid; gap: 1.2cqw; margin-top: 2cqw; }
.services li {
  display: flex; align-items: center; gap: 4cqw;
  padding: 3cqw 3.5cqw;
  background: var(--page-2);
  font-weight: 500;
}
.services svg {
  flex: 0 0 auto;
  width: 8cqw; height: 8cqw;
  fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
}

.projects { display: grid; gap: 2.6cqw; margin-top: 1cqw; }
.projects li {
  display: flex; flex-direction: column; gap: 0.6cqw;
  padding-bottom: 2.6cqw;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.projects .yr { color: var(--accent); font-weight: 600; font-size: 0.85em; letter-spacing: 0.05em; }
.projects strong { font-family: var(--head); font-size: 6.5cqw; text-transform: uppercase; line-height: 1; }
.projects span:last-child { color: var(--muted); }

/* ---------- Project pages ---------- */

.pg-project .head { display: flex; flex-direction: column; gap: 1.6cqw; }
.pg-project h2 { font-size: 9.5cqw; }
.pg-project h2 span { display: inline-block; font-size: 0.68em; line-height: 1.05; }
.meta { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 1.6cqw; margin-top: 1cqw !important; }
.chips span {
  background: var(--accent);
  color: #0b1a22;
  font-size: max(10px, 2.4cqw);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.8cqw 2cqw;
}

.photos { flex: 1 1 auto; min-height: 0; display: grid; gap: 2cqw; }
.photos picture, .cover__photo { display: block; overflow: hidden; background: var(--page-2); }
.photos img, .cover__photo img { width: 100%; height: 100%; object-fit: cover; display: block; }

.photos--stack { grid-template-rows: 1fr 1fr; }
.photos--grid4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.photos--feature { grid-template-columns: 1fr 1fr; grid-template-rows: 1.3fr 1fr; }
.photos--feature .wide { grid-column: 1 / -1; }
.photos--grid8 { grid-template-columns: 1fr 1fr; grid-template-rows: repeat(4, 1fr); gap: 1.6cqw; }

/* ---------- Back cover ---------- */

.pg-back { gap: 2.4cqw; }
.why { display: grid; gap: 1.6cqw; }
.why li { display: flex; flex-direction: column; color: var(--muted); font-size: max(14px, 0.92em); }
.why strong { color: var(--text); font-weight: 600; font-size: 1.08em; }
.why li { border-left: 0.6cqw solid var(--accent); padding-left: 2.4cqw; }
.contact { display: grid; gap: 1.6cqw; margin-top: auto; }
.btn {
  display: flex; align-items: center; justify-content: center; gap: 2.4cqw;
  min-height: 48px;
  padding: 0 4cqw;
  border: 1px solid rgba(41, 168, 224, 0.6);
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: max(14px, 3.6cqw);
  /* Buttons must stay tappable inside the flip-book (StPageFlip listens for swipes on pages). */
  position: relative; z-index: 2;
}
/* StPageFlip only lets a tap through when the target is the <a> itself, so icons must not catch it. */
.btn svg { pointer-events: none; width: 5.5cqw; height: 5.5cqw; min-width: 18px; min-height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; }
.btn--wa { background: var(--accent); border-color: var(--accent); color: #0b1a22; }
.btn--wa svg { fill: currentColor; stroke: none; }
.btn:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.address { color: var(--muted); font-size: max(14px, 0.9em); }
.small { color: var(--muted); font-size: max(10px, 2.4cqw); line-height: 1.5; }
.photo-credit { color: var(--muted); font-size: max(10px, 2.4cqw); }
.photo-credit:empty { display: none; }

/* Very small phones (≈320px wide): tighten text pages so nothing is cut off. */
@container (max-width: 320px) {
  .lead, .creds, .mission, .services, .projects, .why, .meta { font-size: 13px; }
  .creds, .projects { gap: 1.6cqw; }
  .projects li { padding-bottom: 2.4cqw; }
  .creds li { padding-top: 1cqw; padding-bottom: 1cqw; }
  .creds span, .why li, .address, .cover__creds { font-size: 13px; }
  .why { gap: 1cqw; }
  .btn { min-height: 44px; }
}

/* ---------- Nav bar ---------- */

.bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: var(--bar-total);
  padding: 0 12px env(safe-area-inset-bottom, 0px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(13, 14, 17, 0.92);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 14px;
}

.bar__btn {
  width: 48px; height: 44px;
  border-radius: 22px;
  border: 1px solid rgba(41, 168, 224, 0.5);
  background: transparent;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
}
.bar__btn:hover:not(:disabled) { background: rgba(41, 168, 224, 0.15); }
.bar__btn:disabled { opacity: 0.3; cursor: default; }
.bar__btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.bar__count { min-width: 56px; text-align: center; font-variant-numeric: tabular-nums; color: var(--muted); }
.bar__hint { color: var(--accent); font-size: 13px; }
.bar__hint[hidden] { display: none; }

@media (max-width: 380px) {
  .bar { gap: 10px; }
  .bar__hint { font-size: 12px; }
}

/* ---------- No JS / library failed: readable vertical scroll ---------- */

.no-js .stage { height: auto; display: block; padding: 0; }
.no-js .book-wrap { width: min(100%, 620px); margin: 0 auto; }
.no-js .page {
  aspect-ratio: 5 / 8;
  margin: 0 0 12px;
}
.no-js .bar { display: none; }
