/* ─── Tokens ─────────────────────────────────────────── */
:root {
  --ink: #000;
  --ink-soft: #5e5e5e;
  --ink-faint: #a3a3a3;
  --rule: #e4e4e4;
  --paper: #fff;

  --serif: "Instrument Serif", "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;

  /* Hero scales with width and height so the sentence always fits one screen */
  --hero: clamp(38px, min(6.4vw, 10vh), 96px);
  --gutter: clamp(16px, 7vw, 104px);

  --ease: cubic-bezier(0.22, 0.75, 0.15, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.25, 1);
}

*,
*::before,
*::after { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100svh;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
em { font-style: italic; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }

.sr {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

:focus-visible { outline: 1px solid var(--ink); outline-offset: 6px; border-radius: 4px; }

/* ─── Header ─────────────────────────────────────────── */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: clamp(20px, 5vh, 44px) var(--gutter) 0;
}

.logo img {
  width: clamp(64px, 6.6vw, 96px);
  transition: transform 0.6s var(--ease);
  transform-origin: 30% 80%;
}
.logo:hover img { transform: rotate(-6deg); }

.links { display: flex; gap: clamp(18px, 2.4vw, 32px); }

.links a,
.back,
.motto {
  font-family: var(--serif);
  font-size: clamp(20px, 1.8vw, 25px);
  letter-spacing: -0.04em;
  line-height: 1.4;
}

/* Underline that draws in from the left */
.links a,
.back,
.p-link {
  background: linear-gradient(currentColor, currentColor) 0 100% / 0 1px no-repeat;
  transition: background-size 0.5s var(--ease);
}
.links a:hover,
.back:hover,
.p-link:hover { background-size: 100% 1px; }

/* ─── Stage ──────────────────────────────────────────── */
.stage {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  min-height: 0;
  padding: 0 var(--gutter);
}

.hero,
.project { grid-area: 1 / 1; }

body[data-view="home"] .project,
body[data-view="project"] .hero { display: none; }

/* ─── Hero sentence ──────────────────────────────────── */
.hero {
  align-self: center;
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: var(--hero);
  line-height: 1.36;
  letter-spacing: -0.005em;
  text-align: center;
}

.line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  column-gap: 0.18em;
  animation: rise 0.9s var(--ease) both;
}
.line:nth-child(2) { animation-delay: 0.07s; }
.line:nth-child(3) { animation-delay: 0.14s; }

/* Drawings: sized in em so they scale with the type */
.br { display: none; }  /* line breaks used only on phones */

.glyph {
  position: relative;
  display: inline-grid;
  place-items: center;
  margin-block: -0.32em;  /* drawings overlap the line box instead of stretching it */
  transition: opacity 0.4s var(--ease), filter 0.4s var(--ease);
}
.glyph img {
  height: var(--h);
  width: auto;
  transition: transform 0.55s var(--ease);
  user-select: none;
  -webkit-user-drag: none;
}
.glyph--girl  { --h: 1.62em; }
.glyph--pig   { --h: 1.06em; }
.glyph--cat   { --h: 1.04em; }
.glyph--faces { --h: 1.22em; }
.glyph--hands { --h: 1.24em; }

/* Caption under each drawing on hover/focus */
.glyph::after {
  content: attr(data-label);
  position: absolute;
  top: 100%;
  left: 50%;
  translate: -50% 0;
  margin-top: 0.1em;
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.01em;
  color: var(--ink-soft);
  white-space: nowrap;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.35s var(--ease), transform 0.45s var(--ease);
  pointer-events: none;
}

@media (hover: hover) {
  .glyph:hover img { transform: rotate(-5deg) scale(1.07); }
  .glyph:hover::after { opacity: 1; transform: none; }

  /* When one drawing is in focus, the others step back */
  .hero:has(.glyph:hover) .glyph:not(:hover) { opacity: 0.28; filter: grayscale(1); }
}
.glyph:focus-visible::after,
.glyph.is-open::after { opacity: 0; }

/* While the profile card is open, the rest of the sentence recedes */
.line > * { transition: opacity 0.5s var(--ease), filter 0.5s var(--ease); }
body:has(.card:popover-open) .line > :not(.is-open) { opacity: 0.12; filter: grayscale(1); }

.glyph.is-open img { transform: rotate(-5deg) scale(1.07); }

/* ─── Profile card ───────────────────────────────────── */
.card {
  position: fixed;
  inset: auto;
  top: var(--y, 50%);
  left: var(--x, 50%);
  width: min(340px, calc(100vw - 32px));
  margin: 0;
  padding: 26px 28px 22px;
  border: 1px solid var(--ink);
  border-radius: 2px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 30px 60px -30px rgb(0 0 0 / 0.25);
  transform-origin: var(--ox, 0) var(--oy, 0);

  opacity: 0;
  scale: 0.94;
  translate: 0 -6px;
  transition:
    opacity 0.3s var(--ease),
    scale 0.45s var(--ease),
    translate 0.45s var(--ease),
    display 0.45s allow-discrete,
    overlay 0.45s allow-discrete;
}
.card:popover-open { opacity: 1; scale: 1; translate: 0 0; }
@starting-style {
  .card:popover-open { opacity: 0; scale: 0.94; translate: 0 -6px; }
}
.card::backdrop { background: transparent; }

.card-kicker {
  margin: 0 0 14px;
  font-family: var(--serif);
  font-size: 22px;
  letter-spacing: -0.02em;
}

.card dl { margin: 0; }
.card dl > div {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--rule);
}
.card dt {
  font-family: var(--serif);
  font-style: italic;
  font-size: 17px;
  line-height: 1.3;
  color: var(--ink-soft);
}
.card dd {
  margin: 0;
  font-family: var(--serif);
  font-size: 21px;
  line-height: 1.2;
  letter-spacing: -0.02em;
}
.card dd span {
  display: block;
  margin-top: 4px;
  font-family: var(--sans);
  font-size: 13px;
  letter-spacing: 0;
  color: var(--ink-soft);
}
.skills i { font-style: normal; color: var(--ink-faint); padding: 0 0.1em; }

.card-more {
  display: inline-block;
  margin-top: 14px;
  font-family: var(--serif);
  font-size: 19px;
  letter-spacing: -0.02em;
}
.card-more span { display: inline-block; transition: translate 0.4s var(--ease); }
.card-more:hover span { translate: 4px 0; }

.card-close {
  position: absolute;
  top: 14px;
  right: 16px;
  width: 28px;
  height: 28px;
  font-size: 22px;
  line-height: 1;
  color: var(--ink-soft);
  transition: rotate 0.4s var(--ease), color 0.2s;
}
.card-close:hover { rotate: 90deg; color: var(--ink); }

/* ─── Project view ───────────────────────────────────── */
.project {
  align-self: center;
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  column-gap: clamp(32px, 6vw, 112px);
  align-items: start;
  width: 100%;
  max-width: 1240px;
  max-height: 100%;
  margin: 0 auto;
  padding: clamp(12px, 3vh, 32px) 0 36px;
  min-height: 0;

  /* If a project is longer than the screen, it scrolls within the stage, never the page */
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(#000 calc(100% - 32px), transparent);
          mask-image: linear-gradient(#000 calc(100% - 32px), transparent);
}
.project::-webkit-scrollbar { display: none; }

.project > *,
.p-details > div { animation: rise 0.8s var(--ease) both; animation-delay: calc(var(--i, 0) * 70ms + 120ms); }

.p-intro { position: sticky; top: 0; }

.emblem {
  height: clamp(72px, 13vh, 128px);
  width: auto;
  margin-bottom: clamp(12px, 3vh, 28px);
  view-transition-name: glyph;
}

.p-index {
  margin: 0 0 6px;
  font-family: var(--serif);
  font-size: 20px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}
.p-index em { color: var(--ink); }

.p-title {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(44px, min(5vw, 8.5vh), 76px);
  line-height: 0.98;
  letter-spacing: -0.025em;
  text-wrap: balance;
}

.p-meta {
  margin: 12px 0 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 21px;
  letter-spacing: -0.02em;
}

.p-summary {
  margin: clamp(14px, 3vh, 24px) 0 0;
  max-width: 34em;
  font-size: 15.5px;
  line-height: 1.6;
  color: var(--ink-soft);
  text-wrap: pretty;
}

.p-link {
  display: inline-block;
  margin-top: clamp(14px, 3vh, 24px);
  font-family: var(--serif);
  font-size: 21px;
  letter-spacing: -0.02em;
}

.p-details { margin: 0; }

.p-details > div {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) 3.4fr;
  gap: 20px;
  padding: clamp(12px, 2.4vh, 22px) 0;
  border-top: 1px solid var(--rule);
}
.p-details > div:last-child { border-bottom: 1px solid var(--rule); }

.p-details dt {
  font-family: var(--serif);
  font-style: italic;
  font-size: 21px;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.p-details dd {
  margin: 0;
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--ink-soft);
  text-wrap: pretty;
}
.p-details dd p { margin: 0; }

.steps {
  display: grid;
  gap: 6px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}
.steps li {
  display: grid;
  grid-template-columns: 1.6em 5.6em 1fr;
  gap: 8px;
  counter-increment: step;
}
.steps li::before {
  content: counter(step, decimal-leading-zero);
  font-size: 11px;
  line-height: 2.1;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}
.steps b { font-weight: 500; color: var(--ink); }

.tools {
  font-family: var(--serif);
  font-size: 21px !important;
  line-height: 1.3 !important;
  letter-spacing: -0.02em;
  color: var(--ink) !important;
}
.tools i { font-style: normal; color: var(--ink-faint); padding: 0 0.15em; }

/* About / CV view: same grid, with the original CV rows on the right */
.p-summary + .p-summary { margin-top: 12px; }

.p-skills {
  margin: clamp(14px, 3vh, 24px) 0 0;
  font-family: var(--serif);
  font-size: 21px;
  letter-spacing: -0.02em;
}
.p-skills i,
.tags i { font-style: normal; color: var(--ink-faint); padding: 0 0.15em; }

.cv > div { grid-template-columns: minmax(110px, 1fr) 3.4fr; }
.cv dt { font-variant-numeric: tabular-nums; white-space: nowrap; }
.cv h3 {
  margin: 0 0 6px;
  font-family: var(--serif);
  font-weight: 400;
  font-size: 25px;
  line-height: 1.15;
  letter-spacing: -0.03em;
  color: var(--ink);
}
.cv .tags {
  margin-top: 10px;
  font-family: var(--serif);
  font-size: 19px;
  letter-spacing: -0.02em;
  color: var(--ink);
}

/* Strip: the profile drawing sits slightly apart from the projects */
.strip button[data-project="about"] { margin-right: clamp(4px, 1vw, 14px); }

/* Draft projects: a quiet placeholder */
.project.is-draft { grid-template-columns: 1fr; text-align: center; justify-items: center; max-width: 640px; }
.is-about .emblem { height: clamp(84px, 15vh, 150px); }
.project.is-draft .emblem { margin-inline: auto; }
.project.is-draft .p-title { font-style: italic; }

/* ─── Footer ─────────────────────────────────────────── */
.foot {
  padding: 0 var(--gutter) clamp(18px, 4.5vh, 40px);
}

.foot-home,
.foot-project {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  min-height: 52px;
}

.foot-home { justify-content: center; }

body[data-view="home"] .foot-project,
body[data-view="project"] .foot-home { display: none; }

.motto { margin: 0; }


.foot-home,
.foot-project { animation: fade 1s var(--ease) 0.35s both; }

.strip { display: flex; align-items: flex-end; gap: clamp(14px, 2vw, 26px); }

.strip button {
  position: relative;
  display: grid;
  place-items: end center;
  height: 44px;
  opacity: 0.3;
  filter: grayscale(1);
  transition: opacity 0.35s var(--ease);
}
.strip button img { height: 38px; width: auto; transition: transform 0.5s var(--ease); }
.strip button:hover { opacity: 0.85; }
.strip button:hover img { transform: translateY(-3px) rotate(-4deg); }
.strip button[aria-current="true"] { opacity: 1; filter: none; }
.strip button[aria-current="true"]::after {
  content: "";
  position: absolute;
  bottom: -9px;
  left: 50%;
  width: 4px;
  height: 4px;
  margin-left: -2px;
  border-radius: 50%;
  background: var(--ink);
}

/* ─── Motion ─────────────────────────────────────────── */
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
}
@keyframes fade {
  from { opacity: 0; }
}
@keyframes leave {
  to { opacity: 0; transform: translateY(-10px); }
}
@keyframes leave-x {
  to { opacity: 0; transform: translateX(var(--dx)); }
}

/* View transitions: the old page lifts away, the new one rises in on its own,
   and the selected drawing travels between the hero and the project header. */
::view-transition-old(root) { animation: leave 0.32s var(--ease-in-out) both; }
::view-transition-new(root) { animation: none; }
html[data-dir="next"] { --dx: -18px; }
html[data-dir="prev"] { --dx: 18px; }
html[data-dir="next"]::view-transition-old(root),
html[data-dir="prev"]::view-transition-old(root) { animation-name: leave-x; }

::view-transition-group(glyph) { animation-duration: 0.7s; animation-timing-function: var(--ease); }
::view-transition-old(glyph),
::view-transition-new(glyph) { height: 100%; width: auto; object-fit: contain; }

/* Only the drawing that was clicked takes part in the shared transition */
.glyph.is-active img { view-transition-name: glyph; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after,
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ─── Smaller screens ────────────────────────────────── */
@media (max-width: 900px) {
  .project {
    grid-template-columns: 1fr;
    align-self: stretch;
    row-gap: 28px;
  }
  .p-intro { position: static; }
}

@media (max-width: 640px) {
  :root { --hero: clamp(34px, 10.6vw, 48px); }

  /* One continuous sentence instead of three fixed lines */
  .hero {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    column-gap: 0.16em;
    row-gap: 0.12em;
    line-height: 1.18;
    animation: rise 0.9s var(--ease) both;
  }
  .line { display: contents; }
  .br { display: block; flex-basis: 100%; height: 0; }
  .emblem { height: 76px; }
  .glyph { margin-block: -0.2em; }
  .glyph--girl  { --h: 1.35em; }
  .glyph--faces,
  .glyph--hands { --h: 1.05em; }

  .links { gap: 16px; }
  .links a { font-size: 19px; }
  .motto { font-size: 19px; }

  .p-details > div { grid-template-columns: 1fr; gap: 6px; }
  .steps li { grid-template-columns: 1.6em 1fr; }
  .steps li span { grid-column: 2; }

  .back { font-size: 20px; white-space: nowrap; }
  .back-text { display: none; }
  .is-about .emblem { height: 84px; }
  .strip { gap: 12px; }
  .strip button img { height: 28px; }

  /* Profile card becomes a bottom sheet */
  .card {
    top: auto !important;
    bottom: 12px;
    left: 12px !important;
    width: calc(100vw - 24px);
    transform-origin: 50% 100%;
    translate: 0 16px;
  }
  @starting-style { .card:popover-open { translate: 0 16px; } }
}
