:root {
  --top-gap: 76px;   /* one distance from the menu to the content, on every page */
  --ink: #111;
  --text: #2b2b2b;
  --muted: #6d6d6d;
  --line: #1a1a1a;
  --bg: #fff;
  --wrap: 1000px;   /* content column, same as roikuper.com: header, home image and footer share these edges */
  --gutter: 40px;
  --max-ratio: 1.5;   /* overwritten by build.py with the widest work's width/height */
  --media-h: min(68vh, 640px, calc(min(var(--wrap), 100vw - 2 * var(--gutter)) / var(--max-ratio)));
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Montserrat", "Helvetica Neue", Arial, sans-serif;
  font-weight: 400;
  font-size: 14px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; height: auto; }
h1, h2, p { margin: 0; }

.wrap {
  max-width: calc(var(--wrap) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 0 var(--gutter);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; }

/* ---------- header ---------- */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 56px 0 0;
}
.logo {
  font-weight: 400;
  font-size: 14px;
  letter-spacing: 0.25em;
  color: var(--ink);
  white-space: nowrap;
}
.site-nav { display: flex; gap: 26px; }
.site-nav a {
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  position: relative;
  padding: 2px 0;
}
.site-nav a::after {
  content: "";
  position: absolute; left: 0; right: 0; bottom: -2px;
  height: 1px; background: currentColor;
  transform: scaleX(0); transform-origin: left;
  transition: transform .25s ease;
}
.site-nav a:hover::after, .site-nav a.active::after { transform: scaleX(1); }
.menu-toggle { display: none; }
.page-label { display: none; }

/* ---------- footer ---------- */
.site-footer {
  margin-top: 120px;
  border-top: 1px solid var(--line);
  padding: 18px 0 56px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 16px;
  font-size: 13px;
  color: #444;
}
.site-footer a { color: var(--ink); }
.site-footer a:hover { text-decoration: underline; }

/* ---------- home ---------- */
.home main { display: flex; align-items: flex-start; justify-content: center; }
.home .site-footer { margin-top: 40px; }
/* one work inside a 1000×667 frame (as on roikuper.com), never cropped */
.hero { width: fit-content; max-width: 100%; margin: var(--top-gap) auto 0; }   /* shrinks to the image, so the title sits under its left edge */
.hero img { width: auto; height: auto; max-width: min(100%, 1000px); max-height: min(667px, calc(100svh - 240px)); }
.hero figcaption { padding-top: 16px; font-size: 13px; color: #333; }

/* ---------- text pages ---------- */
.text-page, .cv-page {
  max-width: 760px;
  margin: var(--top-gap) auto 0;
}
.text-page h1, .cv-page h1, .project-head h1 {
  font-size: 20px;
  font-weight: 400;
  color: #333;
  letter-spacing: -0.005em;
  margin-bottom: 48px;
}
.text-page p { margin-bottom: 1em; }
.intro { margin-bottom: 2em !important; color: var(--ink); }

.contact-block { margin-bottom: 44px; }
.contact-block h2, .cv-section h2 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink);
  margin-bottom: 14px;
}
.contact-block p { margin-bottom: 0; }
.contact-block a { border-bottom: 1px solid #bbb; }
.contact-block a:hover { border-color: var(--ink); }
.contact-logo { width: 200px; margin: 4px 0 16px -6px; }

/* ---------- CV ---------- */
.cv-page { max-width: 900px; }
.cv-section { margin-bottom: 52px; }
.cv-section dl { margin: 0; }
.cv-row {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 24px;
  padding: 3px 0;
}
.cv-row dt { color: var(--muted); font-variant-numeric: tabular-nums; }
.cv-row dd { margin: 0; }

/* ---------- projects grid ---------- */
/* Three equal columns; every image has exactly the column width (never cropped).
   In each row the images sit on one common bottom line, so titles align. */
.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  column-gap: clamp(40px, 8vw, 110px);
  row-gap: 150px;
  align-items: end;
  max-width: 940px;
  margin: var(--top-gap) auto 0;
}
.card { display: block; }
.card-img img, .card-img video {
  width: 100%;
  height: auto;
  transition: opacity .35s ease;
}
.card:hover .card-img img, .card:hover .card-img video { opacity: .8; }
.card h2 {
  font-size: 14px;
  font-weight: 400;
  color: var(--ink);
  margin-top: 30px;
  line-height: 1.3;
  min-height: 1.3em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card p { font-size: 13px; color: #333; margin-top: 6px; font-weight: 300; line-height: 1.5; min-height: 1.5em; }

/* ---------- project page ---------- */
.project { margin: var(--top-gap) auto 0; }
.project-head {
  display: flex; justify-content: space-between; align-items: baseline; gap: 24px;
  margin-bottom: 36px;
}
/* quiet, elegant: work name, and under it the technique / details in grey */
.project-head h1 { font-size: 15px; font-weight: 400; letter-spacing: .01em; color: var(--ink); margin: 0 0 4px; }
.project-sub { font-size: 13px; color: var(--muted); }
.text-toggle {
  font: inherit; font-size: 13px; font-weight: 400; color: var(--ink);
  background: none; border: 0; padding: 0 0 2px; cursor: pointer; white-space: nowrap;
  border-bottom: 1px solid #c4c4c4;
}
.text-toggle:hover { border-color: var(--ink); }
.thumbs[hidden], .project-text[hidden] { display: none; }

/* Viewer on the page: one work at a time, soft fade. The stage is the content column
   (same edges as the name and the menu); the arrows sit just outside it and never move.
   Every work has exactly the same height, chosen so even the widest work (--max-ratio)
   fits the column. Never cropped. */
.viewer {
  --stage-w: min(1300px, calc(100vw - 2 * var(--gutter) - 2 * var(--arrow-space)));   /* wider than the text column so works are larger */
  --arrow-space: 56px;
  --view-h: min(667px, calc(100svh - 300px), calc(var(--stage-w) / var(--max-ratio)));
  position: relative;
  width: var(--stage-w);
  margin: 0 0 0 calc(50% - var(--stage-w) / 2);   /* centred, may extend past the column */
  outline: none;
}
.viewer[hidden], .project-text[hidden] { display: none; }
.slide { display: none; margin: 0 auto; }
.slide.is-active { display: table; margin: 0 auto; animation: fade-in .2s ease; }
.slide.is-leaving { opacity: 0; transition: opacity .1s ease; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }   /* shrinks to the image: title/counter sit under its edges */
.slide img, .slide video {
  display: block;
  height: var(--view-h); width: auto; max-width: var(--stage-w);
}
.slide figcaption {
  display: table-caption; caption-side: bottom;
  padding-top: 14px; font-size: 13px; color: #444;
}
.slide .count { float: right; margin-left: 16px; color: var(--muted); font-variant-numeric: tabular-nums; }
.arrow {
  position: absolute; background: none; border: 0; cursor: pointer;
  color: #9a9a9a; transition: color .2s ease;
}
.arrow { top: calc(var(--view-h) / 2); transform: translateY(-50%); width: 44px; height: 80px; padding: 18px 12px; }
.arrow:hover { color: var(--ink); }
.arrow svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.2; }
.arrow.prev { left: calc(-1 * var(--arrow-space)); }   /* fixed: just outside the column */
.arrow.next { right: calc(-1 * var(--arrow-space)); }

.project-text { max-width: 640px; min-height: var(--view-h, 400px); }
.project-text p { margin-bottom: 1em; }

.pager {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 16px;
  margin-top: 140px;
  font-size: 14px;
}
.pager a:hover { text-decoration: underline; }
.pager a:last-child { text-align: right; }

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 48px; row-gap: 96px; margin-top: 120px; }
}

@media (max-width: 720px) {
  :root { --gutter: 16px; }
  .site-header { padding-top: 28px; flex-wrap: wrap; }
  .logo { font-size: 14px; letter-spacing: 0.22em; }
  .menu-toggle {
    display: flex; flex-direction: column; gap: 6px; justify-content: center;
    width: 36px; height: 36px; padding: 0 6px; margin-right: -6px;
    background: none; border: 0; cursor: pointer;
  }
  .menu-toggle span { display: block; height: 1.5px; background: var(--ink); transition: transform .25s; }
  .nav-open .menu-toggle span:first-child { transform: translateY(3.75px) rotate(45deg); }
  .nav-open .menu-toggle span:last-child { transform: translateY(-3.75px) rotate(-45deg); }
  .site-nav { display: none; width: 100%; flex-direction: column; gap: 10px; padding: 24px 0 8px; }
  .nav-open .site-nav { display: flex; }
  .site-nav a { font-size: 14px; }
  /* projects list on a phone: the header stays on top while scrolling, with the page name */
  .projects-list .site-header {
    position: sticky; top: 0; z-index: 10;
    background: var(--bg); padding-bottom: 14px;
  }
  .page-label { display: block; order: 3; width: 100%; font-size: 13px; color: var(--muted); margin-top: 2px; }
  .site-nav { order: 4; }

  .hero { margin-top: 56px; }
  .hero img { max-height: min(1000px, calc(100svh - 200px)); }
  .grid { grid-template-columns: 1fr; row-gap: 64px; margin-top: 56px; }
  .card h2 { margin-top: 14px; white-space: normal; }

  .text-page, .cv-page, .project { margin-top: 56px; }
  .text-page h1, .cv-page h1 { font-size: 18px; margin-bottom: 28px; }
  .project-head h1 { font-size: 15px; }
  .project-head { margin-bottom: 24px; }
  .project-head h1 { margin-bottom: 4px; }
  /* phone: viewer without arrows (swipe instead) */
  .viewer { --arrow-space: 0px; --view-h: min(calc(100svh - 240px), calc(100vw - 32px)); }
  .slide img, .slide video { max-width: calc(100vw - 32px); height: auto; max-height: var(--view-h); }
  .arrow { display: none; }
  .cv-row { grid-template-columns: 1fr; gap: 0; padding: 6px 0; }
  .cv-row dt:empty { display: none; }

  .site-footer { grid-template-columns: 1fr; gap: 6px; margin-top: 80px; padding-bottom: 32px; }
  .pager { grid-template-columns: 1fr 1fr; margin-top: 80px; }
  .pager a:nth-child(2) { grid-column: 1 / -1; grid-row: 2; text-align: center; }
}

:root { --max-ratio: 2.2564; }
