/* Ma edition. Rules from assets/downloads/japanese-graphic-design.md.
   Kanso: sumi ink on washi paper, one vermilion seal. Ma: space is planned first.
   One focal point: the name. The seal is a small accent that bleeds off the top edge (datsuzoku). Yūgen: the cut part is left to the viewer.
   Fukinsei: the name low-left balances the seal top-right; column 9 of the bottom band stays empty.
   Grid (skill 3.4): on one screen the page is 12 × 8 square modules, like the square em-box of Japanese text.
   Every block starts and ends on a module line. The seal is 2 × 2 modules.
   Breakpoints: 48rem (768px) = two-column band; 64rem wide and 42rem high = the whole page on one screen. */

@layer tokens, base, layout, components;

@layer tokens {
  :root {
    /* Color: neutral base, one accent (shu, vermilion) */
    --color-paper: #f2f1ec;      /* washi, slightly cool */
    --color-ink: #1c1b19;        /* sumi: 15.2:1 on paper */
    --color-ink-soft: #5d5b55;   /* diluted sumi, secondary text: 6.0:1 on paper */
    --color-shu: #b8432d;        /* vermilion: 4.8:1 on paper */
    --color-on-shu: #f2f1ec;     /* 4.8:1 on the seal */

    --font-serif: "Newsreader", "Shippori Mincho", "Hiragino Mincho ProN", "Yu Mincho", Georgia, serif;
    --font-mincho: "Shippori Mincho", "Hiragino Mincho ProN", "Yu Mincho", serif;

    /* Type scale: few sizes, strong contrast between the name and the rest */
    --step--1: 0.8125rem;                                  /* 13px: labels */
    --step-0: 1rem;                                        /* 16px: body */
    --step-1: 1.25rem;                                     /* 20px: lead, project names */
    --step-kanji: 1.125rem;                                /* 18px: about 10% under the Latin names (skill 4.4) */
    --step-hero: clamp(2.75rem, 11vw, 4.5rem);             /* small screens */

    --leading-body: 1.6;
    --leading-ja: 1.8;          /* about 12% more than Latin (skill 4.4) */
    --leading-tight: 1;
    --tracking-label: 0.14em;
    --tracking-ja: 0.2em;

    /* Spacing: 8px module */
    --space-1: 0.5rem;
    --space-2: 1rem;
    --space-3: 1.5rem;
    --space-4: 2.5rem;
    --space-5: 4rem;

    --sheet-max: 96rem;
    --sheet-pad: clamp(1rem, 5vw, 4.5rem);
    --grid-gap: 1rem;
    --seal-size: min(26vw, 7.5rem);            /* small screens */
    --target: 44px;

    /* Square module for the one-screen layout: the largest square that fits 12 across and 8 down.
       --chrome = header (button target) + footer (one 13px line) + sheet padding and gaps (4 × space-3) */
    --chrome: calc(var(--target) + 1.3rem + 4 * var(--space-3));
    --m: min((min(100vw, var(--sheet-max)) - 2 * var(--sheet-pad)) / 12, (100dvh - var(--chrome)) / 8);

    --duration: 300ms;
  }

  /* Dark: the paper becomes sumi. The seal gets lighter to keep its contrast */
  [data-theme="dark"] {
    --color-paper: #191917;
    --color-ink: #e9e6de;        /* 14.1:1 on dark paper */
    --color-ink-soft: #a29e94;   /* 6.6:1 */
    --color-shu: #d6644c;        /* 4.9:1 */
    --color-on-shu: #191917;     /* 4.9:1 on the seal */
    color-scheme: dark;
  }
}

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

  body {
    margin: 0;
    background-color: var(--color-paper);
    color: var(--color-ink);
    font-family: var(--font-serif);
    font-size: var(--step-0);
    line-height: var(--leading-body);
    -webkit-font-smoothing: antialiased;
    overflow-x: clip;            /* the seal never causes horizontal scroll */
  }

  /* Kinsoku shori for every Japanese run (skill 4.6). No fake italic on Japanese (skill 4.3) */
  :lang(ja) {
    font-family: var(--font-mincho);
    font-style: normal;
    line-height: var(--leading-ja);
    line-break: strict;
    word-break: normal;
  }

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

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

  a {
    color: inherit;
    text-decoration-thickness: 1px;
    text-underline-offset: 0.25em;
  }

  a:hover {
    color: var(--color-shu);
  }

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

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

  @media (prefers-reduced-motion: no-preference) {
    a,
    .text-button {
      transition: color var(--duration);
    }
  }
}

@layer layout {
  /* Small screens: one column that scrolls */
  .sheet {
    position: relative;          /* the seal is placed against the sheet */
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: var(--space-4);
    max-inline-size: var(--sheet-max);
    margin-inline: auto;
    padding: var(--space-3) var(--sheet-pad);
  }

  .board {
    display: grid;
    gap: var(--space-4) var(--grid-gap);
    align-content: start;
  }

  .hero {
    display: grid;
    gap: var(--space-3);
  }

  .site-header,
  .site-footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-1) var(--space-3);
    font-size: var(--step--1);
    color: var(--color-ink-soft);
  }

  .site-header {
    position: relative;
    z-index: 1;                  /* stays above the seal */
    letter-spacing: var(--tracking-label);
    text-transform: uppercase;
  }

  /* Medium screens: the band has two columns */
  @media (min-width: 48rem) {
    .board {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .hero {
      grid-column: 1 / -1;
    }
  }

  /* One screen: the sheet fills the viewport. The board is 12 × 8 square modules, no gaps:
     the gutter is padding at the end of each block.
     Rows: 1-2 lead, 3 name, 4 empty (ma), 5-8 the band */
  @media (min-width: 64rem) and (min-height: 42rem) {
    .sheet {
      block-size: 100dvh;
      gap: var(--space-3);
      padding-block: var(--space-3);
      overflow: hidden;
    }

    .board {
      grid-template-columns: repeat(12, var(--m));
      grid-template-rows: repeat(8, var(--m));
      gap: 0;
      align-content: end;          /* spare height goes above the board */
      min-block-size: 0;
    }

    .hero {
      grid-column: 1 / -1;
      grid-row: 1 / span 4;
      grid-template-columns: subgrid;
      grid-template-rows: subgrid;
      gap: 0;
    }

    .chapter {
      padding-inline-end: var(--grid-gap);
    }

    .chapter--projects {
      grid-column: 1 / span 4;
      grid-row: 5 / span 4;
    }

    .chapter--work {
      grid-column: 5 / span 4;
      grid-row: 5 / span 4;
    }

    /* Column 9 stays empty: the pause before the last column (ma) */
    .chapter--method {
      grid-column: 10 / span 3;
      grid-row: 5 / span 2;
    }

    .chapter--contact {
      grid-column: 10 / span 3;
      grid-row: 7 / span 2;
    }
  }
}

@layer components {
  .skip-link {
    position: absolute;
    z-index: 2;
    inset-block-start: var(--space-1);
    inset-inline-start: var(--space-1);
    padding: var(--space-1) var(--space-2);
    background-color: var(--color-ink);
    color: var(--color-paper);
    translate: 0 -200%;
  }

  .skip-link:focus {
    translate: 0 0;
  }

  .text-button {
    min-block-size: var(--target);
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    cursor: pointer;
  }

  .text-button:hover {
    color: var(--color-shu);
  }

  /* Hero */
  .hero__lead {
    max-inline-size: 30ch;
    font-size: var(--step-1);
    line-height: 1.4;
    color: var(--color-ink-soft);
  }

  .hero__title {
    font-size: var(--step-hero);
    font-weight: 400;
    line-height: var(--leading-tight);
    letter-spacing: -0.02em;
    text-wrap: balance;
  }

  /* Stamp: the katakana reading beside the seal, like a signature beside a hanko.
     Small screens: first in the hero, at the end of the line */
  .stamp {
    display: flex;
    order: -1;
    justify-content: flex-end;
    align-items: flex-end;
    gap: var(--space-2);
    --seal: var(--seal-size);
  }

  .stamp__reading {
    font-size: var(--step--1);
    letter-spacing: var(--tracking-ja);
    line-height: 1;
    color: var(--color-ink-soft);
    writing-mode: vertical-rl;
  }

  /* Hanko seal. Rotated a little, with a rough edge: it is stamped by hand (wabi-sabi) */
  .seal {
    display: grid;
    place-items: end center;
    flex: none;
    inline-size: var(--seal);
    block-size: var(--seal);
    padding-block-end: calc(var(--seal) * 0.12);
    background-color: var(--color-shu);
    color: var(--color-on-shu);
    rotate: -2deg;
    /* Noise-displaced rectangle as alpha mask. The filter lives inside the mask image, so no page ID is referenced */
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.35' numOctaves='3' seed='7'/%3E%3CfeDisplacementMap in='SourceGraphic' scale='3'/%3E%3C/filter%3E%3Crect x='2' y='2' width='96' height='96' rx='2' fill='%23fff' filter='url(%23f)'/%3E%3C/svg%3E");
    mask-size: 100% 100%;
  }

  .seal__text {
    font-size: calc(var(--seal) * 0.22);
    font-weight: 800;
    line-height: 1.1;
    writing-mode: vertical-rl;
  }

  /* One screen: the name fills one module row; the stamp leaves the flow.
     Stamp: the reading in column 9, the seal on columns 10-11 (2 × 2 modules), column 12 empty */
  @media (min-width: 64rem) and (min-height: 42rem) {
    .hero__lead {
      grid-column: 1 / span 4;
      grid-row: 1 / span 2;
      padding-inline-end: var(--grid-gap);
    }

    .hero__title {
      grid-column: 1 / span 9;
      grid-row: 3;
      align-self: end;
      font-size: calc(var(--m) * 0.95);   /* the cap height stays inside one module */
      white-space: nowrap;
    }

    .stamp {
      --seal: calc(2 * var(--m));
      position: absolute;
      display: grid;
      grid-template-columns: var(--m) var(--seal);
      justify-items: center;
      align-items: start;
      gap: 0;
      inset-block-start: var(--space-3);
      inset-inline-start: calc(var(--sheet-pad) + 8 * var(--m));
    }

    /* Only the seal bleeds off the top edge, by half a module. The reading stays whole, level with the header */
    .seal {
      translate: 0 calc(var(--m) * -0.5 - var(--space-3));
    }
  }

  /* Chapter: kanji and Latin label, then the content */
  .chapter {
    display: grid;
    align-content: start;
    gap: var(--space-1);
    min-inline-size: 0;
  }

  .chapter__title {
    display: flex;
    align-items: baseline;
    gap: var(--space-1);
    font-size: var(--step--1);
    font-weight: 400;
    letter-spacing: var(--tracking-label);
    text-transform: uppercase;
    color: var(--color-ink-soft);
  }

  .chapter__kanji {
    font-size: var(--step-kanji);
    font-weight: 600;
    letter-spacing: var(--tracking-ja);
    color: var(--color-ink);
  }

  .chapter__text {
    max-inline-size: 34ch;
    font-size: 0.9375rem;
  }

  /* Projects: the name is the link */
  .works {
    display: grid;
    gap: var(--space-1);
  }

  .works__name {
    font-size: var(--step-1);
    line-height: 1.2;
    text-decoration: none;
  }

  .works__name:hover {
    text-decoration: underline;
  }

  .works__text {
    font-size: 0.9375rem;
    line-height: 1.4;
    color: var(--color-ink-soft);
  }

  /* Work facts: labels and values share a baseline */
  .facts {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    align-items: baseline;
    gap: var(--space-1) var(--space-3);
  }

  .facts__label {
    font-size: var(--step--1);
    letter-spacing: 0.08em;
    color: var(--color-ink-soft);
  }

  /* Contact */
  .contact {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-3);
  }
}
