@layer layout {
  main > section,
  body > footer,
  .header-bar {
    inline-size: min(100% - 2 * var(--gutter), var(--wrap-max));
    margin-inline: auto;
  }

  body {
    padding-block-start: var(--header-h);
  }

  .site-header {
    position: fixed;
    inset-block-start: 0;
    inset-inline: 0;
    z-index: 50;
    background: var(--color-bg);
    box-shadow: var(--shadow-header);
  }

  /* the extra 2px keeps the shadow line from showing at the top edge; focus inside always reveals */
  .site-header[data-hidden="true"]:not(:focus-within) {
    transform: translateY(calc(-100% - 2px));
  }

  html.js .site-header {
    transition: transform var(--dur-header) var(--ease);
  }

  .header-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    min-block-size: 64px;

    @media (min-width: 900px) {
      min-block-size: 72px;
    }
  }

  .cover {
    /* largest circle diameter; the visible half is reserved under the text */
    --orb-d: min(60vw, 760px);
    position: relative;
    isolation: isolate;
    min-block-size: min(100svh - var(--header-h), 880px);
    display: grid;
    place-content: center;
    justify-items: center;
    text-align: center;
    padding-block: var(--space-2xl);
    gap: var(--space-lg);
  }

  /* contact: surface panel; the ground reaches one gutter past the wrap, so the content keeps the wrap edges */
  #contact {
    position: relative;
    isolation: isolate;

    &::before {
      content: "";
      position: absolute;
      inset-block: 0;
      inset-inline: calc(-1 * var(--gutter));
      z-index: -1;
      background: var(--color-surface);
      border-radius: var(--radius-lg);
    }
  }

  /* keywords (2026-11-22): four steps, each a top line and a dial group (counter, thin line, white word)
     on a deep sage half-circle. Static state (no JS, reduced motion, short viewport, print): the half-circle
     sits behind all four steps, stacked, each with its top line (white here) above its word. */
  .keywords {
    isolation: isolate;
    padding-block: var(--space-2xl) 0;
    text-align: center;
  }

  .keywords-stage {
    --line: clamp(48px, 6vw + 24px, 120px);
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    justify-items: center;
  }

  .keywords-stage > * {
    min-inline-size: 0;
  }

  /* the per-step counter and line, and SCROLL DOWN, belong to the switch only */
  .keyword-count,
  .keyword-line,
  .keywords-scroll {
    display: none;
  }

  /* full-bleed band behind the steps: the circle is wider than the wrap, so the band clips it itself
     (overflow: clip creates no scroll container, and the band is not a sticky ancestor) */
  .keywords-circle {
    grid-column: 1;
    grid-row: 2 / span 5;
    z-index: -1;
    position: relative;
    align-self: stretch;
    inline-size: 100vw;
    margin-inline: calc(50% - 50vw);
    margin-block-start: var(--space-2xl);
    overflow: clip;
    /* the band is sized by the steps it sits behind; the circle reads its height */
    container-type: size;

    /* static state: one thin white line dropping from the top of the circle (painted over the disc) */
    &::before {
      content: "";
      position: absolute;
      z-index: 1;
      inset-block-start: 0;
      inset-inline-start: calc(50% - 0.5px);
      inline-size: 1px;
      block-size: var(--line);
      background: var(--color-bg);
    }
  }

  .keywords-disc {
    /* 1.6 band heights at least, so only the top of the circle shows behind the stacked steps */
    --disc: max(94vw, 160cqh);
    position: absolute;
    inset-block-start: 0;
    inset-inline-start: 50%;
    inline-size: var(--disc);
    aspect-ratio: 1;
    margin-inline-start: calc(var(--disc) / -2);
    border-radius: 50%;
    background: var(--color-sage-deep);
  }

  .keyword-block {
    grid-column: 1;
    display: grid;
    justify-items: center;
    gap: var(--space-xs);
    padding-block: var(--space-md);
    padding-inline: var(--gutter);
    color: var(--color-bg);

    &:nth-child(4) {
      grid-row: 3;
      padding-block-start: calc(var(--space-2xl) + var(--line) + var(--space-lg));
    }

    &:nth-child(5) {
      grid-row: 4;
    }

    &:nth-child(6) {
      grid-row: 5;
    }

    &:nth-child(7) {
      grid-row: 6;
      padding-block-end: var(--space-3xl);
    }
  }

  /* keyword switch: a tall track with a sticky one-screen stage; 0.5 screen per step, 2 screens in total.
     Every width (user request 2026-11-22); short viewports keep the static state.
     Rows: eyebrow, top line (takes the spare height), the counter strip, the circle band.
     The band follows the reference: about 48% of the screen, the circle about 94vw across; narrow screens get a
     relatively wider circle (3 band heights) so the word fits and only the top of the circle shows.
     The stage bleeds to the screen edges and clips (overflow: clip, no scroll container, so sticky still works):
     the dial groups rotate along the circle and leave the screen there. */
  @media screen and (min-height: 500px) and (prefers-reduced-motion: no-preference) {
    .keywords[data-switch="on"] {
      /* quick 261122-tgl / 261122 hold: after step 4 the stage stays pinned for 0.7 of a step more
         (user request: a short pause after AI 활용 before the page scrolls on). js/main.js KW_TAIL matches 0.7. */
      block-size: calc(100svh + 4.7 * 50svh);
      padding-block: 0;

      /* quick 261122-tgl: phones get more track per step (0.7 screen), so one flick does not pass two steps */
      @media (width < 640px) {
        block-size: calc(100svh + 4.7 * 70svh);
      }

      .keywords-stage {
        --band: max(min(48svh, 28vw), 260px, 40svh);
        --line: min(calc(var(--band) * 0.24), 140px);
        --count-h: 96px;
        /* pagination "(n/4)": 18px at every width (user revision 2026-11-22) */
        --count-size: 1.125rem;
        --disc: max(94vw, 3 * var(--band));
        position: sticky;
        inset-block-start: 0;
        block-size: 100svh;
        inline-size: 100vw;
        margin-inline: calc(50% - 50vw);
        overflow: clip;
        grid-template-rows: auto minmax(0, 1fr) var(--count-h) var(--band);
        padding-block-start: calc(var(--header-h) + var(--space-lg));
      }

      /* decoration: never in the way of a click */
      .keywords-circle {
        pointer-events: none;
        grid-area: 4 / 1;
        margin-block-start: 0;
        container-type: normal;

        &::before {
          display: none;
        }
      }

      .keywords-disc {
        --disc: inherit;
      }

      /* each step joins the stage grid: the top line above, the dial group over the counter strip and the band */
      .keyword-block {
        display: contents;
      }

      .keyword-lead {
        grid-area: 2 / 1;
        align-self: center;
        padding-inline: var(--gutter);
        color: var(--color-ink);
      }

      /* the dial group turns about the centre of the circle: one radius below the top of the arc.
         It holds no controls and never takes pointer input: turned by ±32deg about that far centre, a full-width
         group swings up over the top-line row and would swallow clicks on the project links (bug 2026-11-22). */
      .keyword-dial {
        pointer-events: none;
        grid-area: 3 / 1 / 5 / 2;
        position: relative;
        align-self: stretch;
        justify-self: stretch;
        display: grid;
        grid-template-rows: var(--count-h) minmax(0, 1fr);
        justify-items: center;
        transform-origin: 50% calc(var(--count-h) + var(--disc) / 2);
      }

      .keyword-count {
        display: block;
        grid-row: 1;
        align-self: start;
        margin: 0;
        font-size: var(--count-size);
        font-variant-numeric: tabular-nums;
        letter-spacing: 0.04em;
        line-height: 1.6;
        color: var(--color-ink);
      }

      /* one thin line: ink from under the counter to the arc, white inside the circle */
      .keyword-line {
        display: block;
        position: absolute;
        inset-block-start: calc(var(--count-size) * 1.6 + var(--space-sm));
        inset-inline-start: calc(50% - 0.5px);
        inline-size: 1px;
        block-size: calc(var(--count-h) - var(--count-size) * 1.6 - var(--space-sm) + var(--line));
        background: linear-gradient(
          to bottom,
          var(--color-ink) 0 calc(var(--count-h) - var(--count-size) * 1.6 - var(--space-sm)),
          var(--color-bg) 0
        );
      }

      .keyword-title {
        grid-row: 2;
        align-self: center;
        margin-block-start: calc(var(--line) / 2);
        padding-inline: var(--gutter);
      }

      .keywords-scroll {
        display: block;
        position: absolute;
        inset-inline: 0;
        inset-block-end: var(--space-lg);
        margin: 0;
        font-size: 0.75rem;
        font-weight: var(--weight-semibold);
        letter-spacing: 0.16em;
        color: var(--color-bg);
      }
    }
  }

  /* company sections: the section is the size container for its card grid */
  .company {
    container: company / inline-size;
    padding-block: var(--space-2xl);
    border-block-start: 1px solid var(--color-line);

    @media (min-width: 1024px) {
      padding-block: var(--space-3xl);
    }
  }

  .project-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-md);
    align-items: stretch;
    margin-block-start: var(--space-xl);

    & > * {
      min-inline-size: 0;
    }

    @container company (min-width: 600px) {
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: var(--space-lg);
    }

    @container company (min-width: 920px) {
      grid-template-columns: repeat(3, minmax(0, 1fr));
    }
  }

  /* section rhythm (company, keywords, cover and contact set their own spacing) */
  main > section:not(.cover, .keywords, .company, #contact) {
    padding-block: var(--space-2xl);

    @media (min-width: 1024px) {
      padding-block: var(--space-3xl);
    }
  }

  main > section > .eyebrow + h2,
  .period,
  .company-desc {
    margin-block-start: var(--space-sm);
  }

  .period {
    font-size: var(--text-label);
    color: var(--color-ink-3);
  }

  .company-desc {
    max-inline-size: 36em;
    color: var(--color-ink-2);
  }

  /* skills tiles */
  .skills {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-md);
    margin-block: var(--space-xl) 0;

    & > div {
      min-inline-size: 0;
      padding: var(--space-lg);
      background: var(--color-surface);
      border-radius: var(--radius-md);
    }

    /* user request 2026-11-17: below 640px the tiles become a one-card-per-screen swipe slider (native scroll-snap) */
    @media screen and (width < 640px) {
      grid-auto-flow: column;
      grid-auto-columns: 100%;
      grid-template-columns: none;
      align-items: start;
      overflow-x: auto;
      overscroll-behavior-x: contain;
      scroll-snap-type: x mandatory;
      /* quick 261122-tgl: the browser picks the dominant axis, so a vertical page scroll that starts here stays vertical */
      touch-action: pan-x pan-y;
      scrollbar-width: none;

      &::-webkit-scrollbar {
        display: none;
      }

      & > div {
        scroll-snap-align: start;
        /* one swipe moves at most one card */
        scroll-snap-stop: always;
      }
    }

    @media (min-width: 640px) {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    @media (min-width: 1024px) {
      grid-template-columns: repeat(3, minmax(0, 1fr));
      gap: var(--space-lg);
    }
  }

  /* career heading: user request 2026-11-17, the company list is gone, so the heading leads straight into GI Data */
  main > section#career {
    padding-block-end: 0;
  }

  /* the first company reads as the first entry under the heading: no divider, a shorter lead-in */
  #career + .company {
    padding-block-start: var(--space-xl);
    border-block-start: 0;

    @media (min-width: 1024px) {
      padding-block-start: var(--space-2xl);
    }
  }

  /* contact panel */
  #contact {
    margin-block: var(--space-2xl);
    padding-block: var(--space-2xl);
    text-align: center;

    @media (min-width: 1024px) {
      margin-block: var(--space-3xl);
      padding-block: var(--space-3xl);
      text-align: start;
    }

    & > p:not(.eyebrow) {
      margin-block-start: var(--space-md);
      color: var(--color-ink-2);
    }
  }

  .contact-list {
    margin: var(--space-lg) 0 0;

    dd {
      margin: 0;
    }
  }

  .contact-phone:not([hidden]) {
    display: block;
    color: var(--color-ink);
  }

  body > footer {
    padding-block: var(--space-2xl);
    border-block-start: 1px solid var(--color-line);
    text-align: start;

    small {
      font-size: var(--text-label);
      color: var(--color-ink-3);
    }
  }
}
