/* Constructivist edition. Tokens and rules from assets/downloads/constructivism-ui.md.
   The page is one poster sheet: it fills the viewport and does not scroll.
   Red, black and paper. One main diagonal at -12deg. One focal point: the name.
   Breakpoint: 64rem (1024px) = 12-column poster grid with the decorative layer. */

@layer tokens, reset, base, layout, components, variants;

@layer tokens {
  :root {
    /* Raw palette: red, black, paper. No other hues, no tints */
    --red: #c8102e;                    /* on paper 5.0:1; white text on red 5.9:1 */
    --black: #141414;                  /* on paper 15.5:1 */
    --paper: #f2ebdd;
    --white: #ffffff;

    /* Color roles. Areas remap these (see .inverse) */
    --color-bg: var(--paper);
    --color-text: var(--black);        /* also lines, shapes and focus rings */
    --color-muted: #5c5c5c;            /* secondary text on paper 5.6:1 */
    --color-accent: var(--red);
    --color-on-accent: var(--white);
    --color-inverse-bg: var(--black);
    --color-inverse-text: var(--paper);
    --color-inverse-muted: #b3ab9d;    /* secondary text on black 8.1:1 */

    --font-display: "Archivo", "Oswald", "Arial Narrow", sans-serif;
    --font-body: "Archivo", "Inter", "Helvetica Neue", Arial, sans-serif;

    /* Type scale. Poster sizes follow the smaller viewport side, so the sheet always fits */
    --step--1: 0.833rem;
    --step-0: clamp(0.9375rem, 2vh, 1.0625rem);
    --step-1: clamp(1.125rem, 3vh, 1.5rem);
    --step-2: clamp(1.5rem, 4.6vh, 2.25rem);
    --step-name: min(19vw, 11vh);
    --leading-body: 1.45;
    --leading-display: 0.85;
    --tracking-caps: 0.04em;
    --width-condensed: 75%;

    /* Angles: use only these values */
    --angle-diagonal: -12deg;
    --angle-counter: 12deg;            /* rare counter-axis: used by the sheet variants only */
    --angle-vertical: -90deg;

    /* Spacing: 8px base */
    --space-1: 8px;
    --space-2: 16px;
    --space-3: 24px;
    --space-4: 32px;
    --space-5: 48px;

    --line-thin: 2px;
    --line-thick: 12px;
    --target: 44px;                    /* minimum touch target */
    --gutter: var(--space-2);
    --duration: 400ms;
    --ease: cubic-bezier(0.2, 0, 0, 1);
  }

  @media (min-width: 64rem) {
    :root {
      --step-name: min(13vw, 18vh);
      --gutter: var(--space-5);
    }
  }

  /* Dark: paper type on black. Red stays; on black it carries large text and shapes only */
  [data-theme="dark"] {
    --color-bg: var(--black);
    --color-text: var(--paper);
    --color-muted: #b3ab9d;
    --color-inverse-bg: var(--paper);
    --color-inverse-text: var(--black);
    --color-inverse-muted: #5c5c5c;
  }

  /* Inverse area: the masthead and the colophon swap ground and type */
  .inverse {
    --color-bg: var(--color-inverse-bg);
    --color-text: var(--color-inverse-text);
    --color-muted: var(--color-inverse-muted);
    background-color: var(--color-bg);
    color: var(--color-text);
  }
}

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

  body,
  h1,
  h2,
  p,
  ul,
  ol {
    margin: 0;
  }

  ul,
  ol {
    padding: 0;
    list-style: none;
  }

  svg {
    display: block;
  }
}

@layer base {
  html {
    color-scheme: light;
  }

  [data-theme="dark"] {
    color-scheme: dark;
  }

  /* One sheet: masthead, poster, colophon. The poster row takes the free height */
  body {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    min-block-size: 100dvh;
    overflow-x: clip;                  /* rotated shapes never cause horizontal scroll */
    background-color: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-body);
    font-size: var(--step-0);
    line-height: var(--leading-body);
  }

  a {
    color: inherit;
  }

  :focus-visible {
    outline: 3px solid var(--color-text);
    outline-offset: 3px;
  }
}

@layer layout {
  .masthead,
  .colophon {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0 var(--space-3);
    padding: var(--space-1) var(--gutter);
    font-size: var(--step--1);
    font-weight: 800;
    letter-spacing: var(--tracking-caps);
    text-transform: uppercase;
  }

  .masthead {
    border-block-end: var(--line-thick) solid var(--color-accent);
  }

  .colophon {
    border-block-start: var(--line-thin) solid var(--color-accent);
    color: var(--color-muted);
  }

  /* Small screens: one column, content in reading order */
  .poster {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-2) var(--gutter);
    overflow: clip;
  }

  /* Small screens: the variant changes the order of the blocks */
  .poster__title { order: var(--order-title, 0); }
  .poster__lead { order: var(--order-lead, 0); }
  .poster__projects { order: var(--order-projects, 0); }
  .poster__contact { order: var(--order-contact, 0); }

  /* Desktop: 12-column grid, 3 rows. Each variant sets the area of each block
     (row-start / column-start / row-end / column-end), see "Compositions" */
  @media (min-width: 64rem) {
    .poster {
      display: grid;
      grid-template-columns: repeat(12, minmax(0, 1fr));
      grid-template-rows: minmax(0, 1fr) auto auto;
      gap: var(--space-3) var(--space-4);
      padding-block: var(--space-4);
    }

    .poster__label { grid-area: var(--area-label); }
    .poster__title { grid-area: var(--area-title); }
    .poster__lead { grid-area: var(--area-lead); }
    .poster__contact { grid-area: var(--area-contact); }
    .poster__projects { grid-area: var(--area-projects); }
  }

  /* Short landscape screens cannot hold the sheet: let the page scroll */
  @media (min-width: 64rem) and (min-height: 36rem) {
    body {
      block-size: 100dvh;
    }
  }
}

@layer components {
  .visually-hidden {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .skip-link {
    position: absolute;
    inset-block-start: var(--space-1);
    inset-inline-start: var(--space-1);
    z-index: 20;
    padding: var(--space-1) var(--space-2);
    background-color: var(--color-accent);
    color: var(--color-on-accent);
    font-weight: 800;
    transform: translateY(-200%);
  }

  .skip-link:focus-visible {
    transform: none;
  }

  .icon {
    flex: none;
    inline-size: 0.75em;
    block-size: 0.75em;
    fill: currentColor;
  }

  /* ---------- Masthead ---------- */

  .masthead__mark {
    font: 900 var(--step-1) / 1 var(--font-display);
    font-stretch: var(--width-condensed);
  }

  .masthead__issue {
    display: none;
  }

  .theme-toggle {
    min-block-size: var(--target);
    padding: 0 var(--space-2);
    border: var(--line-thin) solid var(--color-text);
    border-radius: 0;
    background: transparent;
    color: var(--color-text);
    font: inherit;
    text-transform: uppercase;
    cursor: pointer;
  }

  .theme-toggle:hover {
    background-color: var(--color-text);
    color: var(--color-bg);
  }

  @media (min-width: 40rem) {
    .masthead__issue {
      display: block;
    }
  }

  /* ---------- Decorative layer ---------- */

  .poster__shapes {
    position: absolute;
    inset: 0;
    pointer-events: none;
  }

  .poster__shapes > * {
    position: absolute;
  }

  /* Small screens: the layer is off. The title carries the wedge (see .poster__title::after) */
  .poster__shapes {
    display: none;
  }

  /* Desktop: one kit (wedge, circle, bar). Each variant sets position, size and angle
     in percent of the poster, see "Compositions" */
  @media (min-width: 64rem) {
    .poster__shapes {
      display: block;
    }

    /* The wedge points right before its turn: the only red shape */
    .poster__wedge {
      inset-block-start: var(--wedge-y);
      inset-inline-start: var(--wedge-x);
      inline-size: var(--wedge-w);
      block-size: var(--wedge-h);
      fill: var(--color-accent);
      transform: rotate(var(--wedge-r));
    }

    .poster__circle {
      inset-block-start: var(--circle-y);
      inset-inline-start: var(--circle-x);
      inline-size: var(--circle-size);
      aspect-ratio: 1;
      border-radius: 50%;
      background-color: var(--color-text);
    }

    .poster__bar {
      inset-block-start: var(--bar-y);
      inset-inline-start: var(--bar-x);
      inline-size: var(--bar-w);
      block-size: var(--bar-h);
      background-color: var(--color-text);
      transform: rotate(var(--bar-r));
      transform-origin: left center;
    }
  }

  /* ---------- Content ---------- */

  .poster__label,
  .poster__title,
  .poster__lead,
  .poster__projects,
  .poster__contact {
    position: relative;               /* above the decorative layer */
  }

  .poster__label {
    font-size: var(--step--1);
    font-weight: 800;
    letter-spacing: var(--tracking-caps);
    text-transform: uppercase;
  }

  /* Desktop: a vertical label that reads bottom to top, unless the variant lays it flat */
  @media (min-width: 64rem) {
    .poster__label {
      justify-self: var(--label-justify, start);
      align-self: start;
      writing-mode: var(--label-mode, vertical-rl);
      transform: rotate(var(--label-turn, 180deg));
    }
  }

  /* Focal point: the name as image. The variant sets its angle and its place in the area */
  .poster__title {
    display: grid;
    justify-items: start;
    justify-self: var(--title-justify, start);
    align-self: var(--title-align, center);
    padding-block: 6vh 2vh;
    font: 900 var(--step-name) / var(--leading-display) var(--font-display);
    font-stretch: var(--width-condensed);
    letter-spacing: -0.01em;
    text-transform: uppercase;
    transform: rotate(var(--title-angle));
    transform-origin: var(--title-origin, left bottom);
  }

  /* Small screens: a red wedge on the same axis points back at the surname */
  .poster__title::after {
    content: "";
    position: absolute;
    inset-block-end: 0;
    inset-inline-end: 0;
    inline-size: 22%;
    block-size: 0.6em;
    background-color: var(--color-accent);
    clip-path: polygon(100% 0, 0 50%, 100% 100%);
  }

  @media (max-width: 63.99rem) {
    .poster__title {
      margin-inline-start: 0.15em;    /* the rotation pushes the first letter to the left */
      padding-block: 6vh 0;
    }

    /* Fine print that the small sheet cannot hold */
    .poster__kit,
    .project__text {
      display: none;
    }

    /* Smaller secondary display type, so the sheet fits a phone screen */
    .poster__slogan {
      font-size: var(--step-1);
    }

    .poster .channel {
      font-size: var(--step-0);
    }

    .poster .btn {
      min-block-size: var(--target);
    }

    .colophon p + p {
      display: none;
    }
  }

  @media (min-width: 64rem) {
    .poster__title::after {
      content: none;
    }
  }

  /* Mixed scale: the surname is set smaller, reversed on a black block */
  .poster__last {
    margin-inline-start: 0.5em;
    padding-block: 0.08em 0.04em;     /* logical: the ends of the word keep their room in vertical Orbit too */
    padding-inline: 0.15em;
    background-color: var(--color-text);
    color: var(--color-bg);
    font-size: 0.5em;
  }

  .poster__lead {
    display: grid;
    gap: var(--space-1);
    max-inline-size: 60ch;
  }

  .poster__slogan {
    font: 900 var(--step-2) / 0.95 var(--font-display);
    font-stretch: var(--width-condensed);
    text-transform: uppercase;
  }

  .poster__key {
    color: var(--color-accent);
  }

  .poster__kit {
    color: var(--color-muted);
    font-size: var(--step--1);
    letter-spacing: var(--tracking-caps);
    text-transform: uppercase;
  }

  .link-inline {
    font-weight: 800;
    text-decoration-thickness: var(--line-thin);
    text-underline-offset: 0.15em;
  }

  .link-inline:hover {
    text-decoration-color: var(--color-accent);
  }

  /* ---------- Projects column ---------- */

  .poster__projects {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding-block-start: var(--space-2);
    border-block-start: var(--line-thick) solid var(--color-text);
  }

  .poster__heading {
    font: 900 var(--step-1) / 1 var(--font-display);
    font-stretch: var(--width-condensed);
    text-transform: uppercase;
  }

  .projects {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-2);
    counter-reset: project;
  }

  .project {
    counter-increment: project;
    padding-block-start: var(--space-1);
    border-block-start: var(--line-thin) solid var(--color-text);
  }

  .project::before {
    content: counter(project, decimal-leading-zero);
    margin-inline-end: var(--space-1);
    color: var(--color-muted);
    font-size: var(--step--1);
    font-weight: 800;
  }

  .project__link {
    display: inline-block;
    font-weight: 800;
    line-height: 1.2;
    letter-spacing: var(--tracking-caps);
    text-decoration: none;
    text-transform: uppercase;
    box-shadow: inset 0 calc(-1 * var(--line-thin)) 0 var(--color-text);
  }

  .project__link:hover {
    box-shadow: inset 0 -6px 0 var(--color-accent);
  }

  .project__text {
    margin-block-start: 4px;
    color: var(--color-muted);
    font-size: var(--step--1);
    line-height: 1.35;
  }

  /* Primary action: red fill, never rotated. Hover swaps red and black */
  .btn {
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    min-block-size: 48px;
    padding: 0 var(--space-2);
    background-color: var(--color-accent);
    color: var(--color-on-accent);
    font-weight: 800;
    letter-spacing: var(--tracking-caps);
    text-decoration: none;
    text-transform: uppercase;
  }

  .btn:hover {
    background-color: var(--color-text);
    color: var(--color-bg);
  }

  /* On red, a white inner ring keeps the focus visible */
  .btn:focus-visible {
    box-shadow: inset 0 0 0 3px var(--white);
  }

  @media (min-width: 64rem) {
    .projects {
      grid-template-columns: 1fr;
    }

    .project::before {
      display: block;
      font-size: var(--step-1);
      line-height: 1;
    }

    /* The buttons sit at the foot of the column, level with the contact row */
    .poster__action {
      margin-block-start: auto;
    }
  }

  .poster__action {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1) var(--space-2);
  }

  /* ---------- Contact row ---------- */

  .channels {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0 var(--space-2);
    border-block-start: var(--line-thin) solid var(--color-text);
  }

  .channel {
    display: flex;
    align-items: center;
    min-block-size: var(--target);
    font: 900 var(--step-1) / 1 var(--font-display);
    font-stretch: var(--width-condensed);
    text-decoration: none;
    text-transform: uppercase;
  }

  .channel:hover {
    color: var(--color-accent);
  }

  /* Secondary button: 2px border on paper. Hover fills it black. Never rotated */
  .variant-next {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    min-block-size: var(--target);
    padding: 0 var(--space-2);
    border: var(--line-thin) solid var(--color-text);
    border-radius: 0;
    background: transparent;
    color: var(--color-text);
    font: 800 var(--step-0) / 1 var(--font-body);
    letter-spacing: var(--tracking-caps);
    text-transform: uppercase;
    white-space: nowrap;
    cursor: pointer;
  }

  .variant-next:hover {
    background-color: var(--color-text);
    color: var(--color-bg);
  }

  .variant-name {
    color: var(--color-muted);
    font-size: var(--step--1);
    font-weight: 800;
    letter-spacing: var(--tracking-caps);
    text-transform: uppercase;
  }

  /* Short desktops: the project column cannot hold the descriptions and both buttons */
  @media (min-width: 64rem) and (max-height: 50rem) {
    .project__text {
      display: none;
    }
  }

  /* Narrow desktops: the two buttons must fit the 3-column projects area */
  @media (min-width: 64rem) and (max-width: 79.99rem) {
    .poster .btn,
    .variant-next {
      font-size: var(--step--1);
    }
  }
}

/* ---------- Compositions: one kit, five variants (Rodchenko, Construction on a plane) ----------
   Set by data-variant on .poster (js/main.js). All angles come from the angle tokens.
   Areas: row-start / column-start / row-end / column-end on the 12 x 3 desktop grid.
   Shape positions: percent of the poster. Phones change only the name angle and the order */
@layer variants {
  /* 1 Push: the name rises on the main diagonal, the wedge pushes in from the left */
  .poster[data-variant="1"] {
    --title-angle: var(--angle-diagonal);
  }

  /* 2 Balance: everything rests on the horizontal; projects move to the left */
  .poster[data-variant="2"] {
    --title-angle: 0deg;
  }

  /* 3 Fall: the name falls on the counter-axis; projects drop to the bottom row */
  .poster[data-variant="3"] {
    --title-angle: var(--angle-counter);
    --title-origin: right bottom;     /* phones: the name tilts up from its end, clear of the slogan */
    --order-projects: 2;
  }

  /* 4 Orbit: the name stands vertical; the circle takes the middle */
  .poster[data-variant="4"] {
    --title-angle: 0deg;
    --order-projects: -1;
  }

  /* 5 Strike: the wedge strikes from the right edge along the main axis */
  .poster[data-variant="5"] {
    --title-angle: var(--angle-diagonal);
    --order-lead: 2;
  }

  @media (min-width: 64rem) {
    .poster[data-variant="1"] {
      --area-label: 1 / 1 / 4 / 2;
      --area-title: 1 / 2 / 2 / 10;
      --area-lead: 2 / 5 / 3 / 10;
      --area-contact: 3 / 2 / 4 / 10;
      --area-projects: 1 / 10 / 4 / 13;
      --wedge-x: 0%;   --wedge-y: 56%; --wedge-w: 26%; --wedge-h: 30%; --wedge-r: var(--angle-diagonal);
      --circle-x: 56%; --circle-y: 30%; --circle-size: min(17vw, 24vh);
      --bar-x: 10%;    --bar-y: 62%;  --bar-w: 46%;   --bar-h: var(--line-thick); --bar-r: var(--angle-diagonal);
    }

    .poster[data-variant="2"] {
      --area-label: 1 / 12 / 4 / 13;
      --area-title: 1 / 4 / 2 / 12;
      --area-lead: 2 / 4 / 3 / 9;
      --area-contact: 3 / 4 / 4 / 13;
      --area-projects: 1 / 1 / 4 / 4;
      --label-justify: end;
      --title-align: end;
      --wedge-x: 74%;  --wedge-y: 58%; --wedge-w: 14%; --wedge-h: 20%; --wedge-r: var(--angle-vertical);
      --circle-x: 76%; --circle-y: 2%;  --circle-size: min(9vw, 14vh);
      --bar-x: 30%;    --bar-y: 6%;   --bar-w: 30%;   --bar-h: var(--line-thick); --bar-r: 0deg;
    }

    .poster[data-variant="3"] {
      --title-origin: left top;
      --area-label: 1 / 7 / 2 / 13;
      --label-mode: horizontal-tb;
      --label-turn: 0deg;
      --area-title: 1 / 1 / 2 / 12;
      --area-lead: 2 / 1 / 3 / 7;
      --area-contact: 2 / 7 / 3 / 13;
      --area-projects: 3 / 1 / 4 / 13;
      --label-justify: end;
      --title-align: start;
      --wedge-x: 68%;  --wedge-y: 12%; --wedge-w: 18%; --wedge-h: 22%; --wedge-r: calc(-180deg + var(--angle-counter));
      --circle-x: 56%; --circle-y: 10%; --circle-size: min(8vw, 12vh);
      --bar-x: 4%;     --bar-y: 1%;   --bar-w: 40%;   --bar-h: var(--line-thick); --bar-r: var(--angle-counter);
      --step-name: min(10vw, 13vh);
    }

    .poster[data-variant="4"] {
      --area-label: 1 / 4 / 2 / 10;
      --area-title: 1 / 1 / 4 / 4;
      --area-lead: 2 / 5 / 3 / 10;
      --area-contact: 3 / 4 / 4 / 10;
      --area-projects: 1 / 10 / 4 / 13;
      --label-mode: horizontal-tb;
      --label-turn: 0deg;
      --title-align: end;
      --wedge-x: 27%;  --wedge-y: 64%; --wedge-w: 6%;  --wedge-h: 12%; --wedge-r: -180deg;
      --circle-x: 40%; --circle-y: 10%; --circle-size: min(20vw, 32vh);
      --bar-x: 26%;    --bar-y: 4%;   --bar-w: var(--line-thick); --bar-h: 52%; --bar-r: 0deg;
      --step-name: min(10vw, 15vh);
    }

    .poster[data-variant="5"] {
      --area-label: 2 / 4 / 4 / 5;
      --area-title: 1 / 4 / 2 / 11;
      --area-lead: 2 / 7 / 3 / 13;
      --area-contact: 3 / 5 / 4 / 13;
      --area-projects: 1 / 1 / 4 / 4;
      --title-align: center;
      --wedge-x: 80%;  --wedge-y: 8%;  --wedge-w: 22%; --wedge-h: 24%; --wedge-r: calc(-180deg + var(--angle-diagonal));
      --circle-x: 32%; --circle-y: 60%; --circle-size: min(11vw, 16vh);
      --bar-x: 30%;    --bar-y: 44%;  --bar-w: 64%;   --bar-h: var(--line-thin); --bar-r: var(--angle-diagonal);
      --step-name: min(10vw, 13vh);
    }

    /* Orbit: the name reads bottom to top. Horizontal text turned by -90deg, not writing-mode:
       the view transition then turns one image the short way (+12deg to -90deg).
       The box stands on its bottom-left corner; translateY(100%) moves the turned name
       right by its own height, back into the area */
    .poster[data-variant="4"] .poster__title {
      align-self: end;
      padding: 0;
      transform: rotate(var(--angle-vertical)) translateY(100%);
      transform-origin: left bottom;
    }

    /* Fall: the name drops about 0.9em over its length; keep that room under it */
    .poster[data-variant="3"] .poster__title {
      padding-block: 0 0.9em;
    }

    /* Fall: the projects row spreads into four columns */
    .poster[data-variant="3"] .projects {
      grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .poster[data-variant="3"] .poster__projects {
      display: grid;
      grid-template-columns: 1fr auto;
      align-items: end;
    }

    .poster[data-variant="3"] .projects {
      grid-column: 1 / -1;
    }

    .poster[data-variant="3"] .poster__action {
      grid-row: 1;
      grid-column: 2;
    }
  }

  /* View transitions: each block moves to its new place in one step (js/main.js) */
  .poster__label { view-transition-name: poster-label; }
  .poster__title { view-transition-name: poster-title; }
  .poster__lead { view-transition-name: poster-lead; }
  .poster__projects { view-transition-name: poster-projects; }
  .poster__contact { view-transition-name: poster-contact; }
  .poster__circle { view-transition-name: poster-circle; }
  .poster__bar { view-transition-name: poster-bar; }

  ::view-transition-group(*) {
    animation-duration: var(--duration);
    animation-timing-function: var(--ease);
  }

  /* The wedge is not in the view transition: it animates as a matrix, and a matrix angle
     wraps at 180deg (192deg to 180deg spins 348deg). A CSS transition interpolates the
     rotate() values as numbers, so the wedge angles stay on one scale (-168, -180, -192).
     It moves in the live new page, so the old page snapshot must not show through */
  ::view-transition-old(root) {
    display: none;
  }

  ::view-transition-new(root) {
    animation: none;
  }

  @media (prefers-reduced-motion: no-preference) {
    .poster__wedge {
      transition-property: transform, inset-block-start, inset-inline-start, inline-size, block-size;
      transition-duration: var(--duration);
      transition-timing-function: var(--ease);
    }
  }

  /* ---------- Motion: one entrance, along the main axis ---------- */

  @media (prefers-reduced-motion: no-preference) {
    .poster__title {
      animation: enter-on-axis var(--duration) var(--ease) both;
    }

    @keyframes enter-on-axis {
      from {
        opacity: 0;
        translate: -8vw 1.7vw;         /* -8vw along x, tan(12deg) of it along y */
      }
    }
  }
}
