@layer components {
  /* decorative pixel images: empty alt, no interaction, kept crisp */
  .deco {
    display: inline-block;
    flex: none;
    max-inline-size: none;
    vertical-align: middle;
    image-rendering: pixelated;
    user-select: none;
    pointer-events: none;
  }

  .deco-cat-run {
    block-size: 32px;
    inline-size: auto;
    margin-inline-start: 0.5em;
  }

  .deco-cursor {
    block-size: 0.7em;
    inline-size: auto;
    margin-inline-start: 0.08em;
    vertical-align: baseline;
  }

  .deco-cat-desk {
    block-size: clamp(72px, 2.4em + 16px, 112px);
    inline-size: auto;
    margin-inline-start: 0.35em;
    vertical-align: bottom;

    /* mobile: the cat sits below the "Contact." text, centred like the heading */
    @media (max-width: 639.98px) {
      display: block;
      margin-inline: auto;
      margin-block-start: var(--space-sm);
    }
  }

  .wordmark {
    white-space: nowrap;
    font-size: var(--text-label);
    font-weight: var(--weight-semibold);
    line-height: 1.4;
    color: var(--color-ink);
    letter-spacing: 0.04em;
  }

  .site-nav ul {
    display: flex;
    gap: var(--space-md);
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .site-nav a {
    position: relative;
    display: inline-flex;
    align-items: center;
    min-block-size: 44px;
    font-size: var(--text-body);
    font-weight: var(--weight-regular);
    color: var(--color-ink-2);
    text-decoration: none;

    &::after {
      content: "";
      position: absolute;
      inset-inline: 0;
      inset-block-end: 8px;
      block-size: 1px;
      background: currentcolor;
      transform: scaleX(0);
      transform-origin: left;
      transition: transform var(--dur) var(--ease);
    }

    &:hover {
      color: var(--color-ink);
    }

    &:hover::after,
    &[aria-current="true"]::after {
      transform: scaleX(1);
    }

    &[aria-current="true"] {
      color: var(--color-accent);
    }
  }

  /* hamburger: hidden at >= 900px and in the no-JS state */
  .nav-toggle {
    display: none;
  }

  /* below 900px, no JS: nav is a full-width second row */
  @media (max-width: 899.98px) {
    html:not(.js) .wordmark {
      display: flex;
      align-items: center;
      min-block-size: 64px;
    }

    html:not(.js) .site-nav {
      flex-basis: 100%;
      min-block-size: 48px;
    }

    /* one fixed-height row (matches --header-h: 112px); extra links scroll sideways instead of wrapping */
    html:not(.js) .site-nav ul {
      flex-wrap: nowrap;
      overflow-x: auto;
      overflow-y: hidden;
      padding-block: 2px;
      scrollbar-width: none;
    }

    html:not(.js) .site-nav li {
      flex: none;
    }

    html:not(.js) .site-nav a {
      white-space: nowrap;
    }
  }

  /* hamburger (JS only), panel and overlay */
  @media (max-width: 899.98px) {
    html.js .nav-toggle {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      inline-size: 44px;
      block-size: 44px;
      padding: 0;
      border: 0;
      border-radius: var(--radius-sm);
      background: transparent;
      color: var(--color-ink);
      cursor: pointer;
      position: relative;

      &::before,
      &::after,
      & .nav-bars {
        content: "";
        position: absolute;
        inset-inline-start: 11px;
        inline-size: 22px;
        block-size: 2px;
        background: currentcolor;
        transform-origin: center;
        transition: transform var(--dur) var(--ease), opacity var(--dur) var(--ease);
      }

      &::before {
        inset-block-start: 14px;
      }

      & .nav-bars {
        inset-block-start: 21px;
      }

      &::after {
        inset-block-start: 28px;
      }

      &[aria-expanded="true"]::before {
        transform: translateY(7px) rotate(45deg);
      }

      &[aria-expanded="true"]::after {
        transform: translateY(-7px) rotate(-45deg);
      }

      &[aria-expanded="true"] .nav-bars {
        opacity: 0;
        transform: scaleX(0);
      }
    }

    html.js .site-nav {
      position: absolute;
      inset-inline: 0;
      inset-block-start: 100%;
      padding-block: var(--space-md);
      padding-inline: var(--gutter);
      background: var(--color-bg);
      border-block-start: 1px solid var(--color-line);
      box-shadow: var(--shadow-header);
      opacity: 0;
      transform: translateY(calc(-1 * var(--space-sm)));
      visibility: hidden;
      pointer-events: none;
      transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease), visibility 0s linear var(--dur);

      & ul {
        flex-direction: column;
        gap: 0;
      }

      & a {
        min-block-size: 48px;
      }

      &[data-open="true"] {
        opacity: 1;
        transform: none;
        visibility: visible;
        pointer-events: auto;
        transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
      }
    }
  }

  .nav-overlay {
    position: fixed;
    inset: 0;
    z-index: 40;
    background: var(--color-overlay);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    cursor: pointer;
    transition: opacity var(--dur) var(--ease), visibility 0s linear var(--dur);

    &[data-open="true"] {
      opacity: 1;
      visibility: visible;
      pointer-events: auto;
      transition: opacity var(--dur) var(--ease);
    }
  }

  @media (min-width: 900px) {
    .nav-overlay {
      display: none;
    }
  }

  @media (min-width: 900px) {
    .nav-toggle {
      display: none !important;
    }
  }

  /* cover ground: a full-width ivory band (edge to edge, user request) holding four
     decorative circles that sit on its bottom edge, left to right, smaller and stronger in colour */
  .cover-orbs {
    position: absolute;
    inset-block: 0;
    inset-inline: calc(50% - 50vw);
    z-index: -1;
    overflow: hidden;
    background: var(--color-cover-bg);
    pointer-events: none;

    /* each circle is placed by its centre: the first straddles the left edge at mid height,
       the next ones step down and to the right (user request, like the reference) */
    span {
      position: absolute;
      inline-size: calc(var(--orb-d) * var(--k));
      aspect-ratio: 1;
      inset-inline-start: calc(var(--orb-d) * var(--cx));
      inset-block-start: calc(50% + var(--orb-d) * var(--cy) + var(--dy, 0px));
      translate: -50% -50%;
      border-radius: 50%;
      background: var(--c);
    }

    span:nth-child(1) {
      --k: 1;
      --cx: 0;
      --cy: 0;
      --c: var(--color-gold);

      /* at least 30px lower than mid height, and always low enough that its bottom reaches the
         band's bottom edge, so no ivory strip shows under it at any screen size (user request) */
      inset-block-start: max(calc(50% + 60px), calc(100% - var(--orb-d) / 2 + 30px));
    }

    span:nth-child(2) {
      --k: 0.8;
      --cx: 0.55;
      --cy: 0.364;
      --c: var(--color-orb-2);
      --i: 1;
    }

    span:nth-child(3) {
      --k: 0.6;
      --cx: 1;
      --cy: 0.5;
      --c: var(--color-sage-soft);
      --i: 2;
    }

    span:nth-child(4) {
      --k: 0.45;
      --cx: 1.38;
      --cy: 0.66;
      --c: var(--color-sage-strong);
      --i: 3;

      /* only on narrow screens does the last circle reach the cover text */
      @media (width < 768px) {
        --c: var(--color-sage-soft);
      }
    }
  }

  .cover-sub {
    font-size: var(--text-label);
    line-height: 1.4;
    color: var(--color-ink-3);
  }

  .cover h1 {
    font-size: var(--text-display);
    font-weight: var(--weight-semibold);
    line-height: 1.05;
    letter-spacing: -0.03em;
    color: var(--color-ink);
  }

  .cover-intro {
    max-inline-size: 28em;
    font-size: 1.125rem;
    color: var(--color-ink-2);
    margin-inline: auto;
  }

  .cover-line {
    display: block;
  }

  .cover-line:nth-child(2) {
    --i: 1;
  }

  .cover-line:nth-child(3) {
    --i: 2;
  }

  /* entrance: once on load, only with JS, on screen, and when motion is allowed (fill-mode both keeps the end state) */
  @keyframes cover-rise {
    from {
      opacity: 0;
      transform: translateY(var(--rise, var(--space-lg)));
    }

    to {
      opacity: 1;
      transform: none;
    }
  }

  @keyframes cover-orb {
    from {
      opacity: 0;
    }

    to {
      opacity: 1;
    }
  }

  @media screen and (prefers-reduced-motion: no-preference) {
    html.js .cover-orbs span {
      animation: cover-orb var(--orb-dur) ease-out both;
      animation-delay: calc(var(--i, 0) * var(--orb-stagger));
    }

    /* the text enters at the same pace as the circles (user request): same duration and step */
    html.js .cover-line {
      animation: cover-rise var(--orb-dur) ease-out both;
      animation-delay: calc(var(--cover-text-start) + var(--i, 0) * var(--orb-stagger));
    }

    /* "Publishing," only: its 2s fade rises slowly at first, so it starts one step earlier and is
       already showing as the last circle completes; the lines after it keep their timing (user request) */
    html.js .cover-line:first-child {
      animation-delay: calc(var(--cover-text-start) - var(--orb-stagger));
    }

    html.js .cover-intro {
      --rise: var(--space-md);
      animation: cover-rise var(--orb-dur) ease-out both;
      animation-delay: calc(var(--cover-text-start) + 3 * var(--orb-stagger));
    }
  }

  /* keyword switch states: written by main.js only inside this media query (user revision 2026-11-22).
     The dial group (counter, line, word) turns along the circle like a dial: the leaving group rotates down
     to the left and fades near the end, the next one rises in from the right. The top line fades with a short
     slide and does not rotate. Transform and opacity only; nothing is hidden by attribute, display or
     visibility, and only the active step takes pointer input (the steps share one place). */
  @media screen and (min-height: 500px) and (prefers-reduced-motion: no-preference) {
    .keywords[data-switch="on"] .keyword-block {
      --turn: 32deg;

      .keyword-lead {
        transition: opacity var(--dur-switch) var(--ease), transform var(--dur-switch) var(--ease);
      }

      .keyword-dial {
        will-change: transform, opacity;
        /* leaving: the turn runs its full length, the fade comes at the end */
        transition: transform var(--dur-dial) var(--ease), opacity calc(var(--dur-dial) * 0.5) var(--ease) calc(var(--dur-dial) * 0.4);
      }

      &[data-state="next"] {
        .keyword-lead {
          opacity: 0;
          transform: translateY(var(--space-lg));
          pointer-events: none;
        }

        .keyword-dial {
          opacity: 0;
          transform: rotate(var(--turn));
        }
      }

      &[data-state="past"] {
        .keyword-lead {
          opacity: 0;
          transform: translateY(calc(-1 * var(--space-lg)));
          pointer-events: none;
        }

        .keyword-dial {
          opacity: 0;
          transform: rotate(calc(-1 * var(--turn)));
        }
      }

      &[data-state="active"] {
        .keyword-lead {
          opacity: 1;
          transform: none;
          pointer-events: auto;
        }

        /* arriving: it shows early in the turn */
        .keyword-dial {
          opacity: 1;
          transform: none;
          transition: transform var(--dur-dial) var(--ease), opacity calc(var(--dur-dial) * 0.5) var(--ease);
        }
      }
    }
  }

  .skip-link {
    position: fixed;
    inset-inline-start: 0;
    inset-block-start: 0;
    z-index: 100;
    display: inline-flex;
    align-items: center;
    min-block-size: 44px;
    padding: 8px 16px;
    transform: translateY(-100%);

    &:focus {
      transform: none;
      border-radius: var(--radius-sm);
      background: var(--color-accent);
      color: var(--color-bg);
      font-size: var(--text-body);
      font-weight: var(--weight-semibold);
    }
  }

  .eyebrow:has(.eyebrow-num) {
    color: var(--color-ink-3);
  }

  .eyebrow-num {
    color: var(--color-accent);
  }

  /* a step's top line: small and white over the circle in the static state, the big centred line
     above the circle while the switch runs */
  .keyword-lead {
    max-inline-size: 22em;
    margin: 0;
    font-size: var(--text-body);
    font-weight: var(--weight-semibold);
    line-height: 1.4;
    text-wrap: balance;

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

    a:focus-visible {
      outline-color: currentColor;
    }

    .keywords[data-switch="on"] & {
      max-inline-size: 16em;
      font-size: clamp(28px, 2.6vw + 16px, 52px);
      line-height: 1.3;
      letter-spacing: -0.03em;

      /* the Korean sentence breaks into two lines like the reference heading; project names may stay on one */
      &:not(:has(a)) {
        max-inline-size: 11em;
      }

      a {
        text-decoration-thickness: 2px;
        text-underline-offset: 0.16em;
        transition: color var(--dur) var(--ease);

        &:hover {
          color: var(--color-accent);
        }

        &:focus-visible {
          outline-color: var(--color-accent);
        }
      }
    }
  }

  .keyword-title {
    font-size: clamp(36px, 4vw + 20px, 64px);
    font-weight: var(--weight-semibold);
    line-height: 1.15;
    color: var(--color-bg);
  }

  /* project card */
  .project {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    padding: var(--space-md);
    background: var(--color-bg);
    border: 1px solid var(--color-line);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
    break-inside: avoid;
    transition:
      transform var(--dur) var(--ease),
      box-shadow var(--dur) var(--ease);

    @container company (min-width: 600px) {
      padding: var(--space-lg);
    }

    h3 {
      line-height: 1.4;
    }

    &:has(a, .shot-link):hover,
    &:has(a, .shot-link):focus-within {
      transform: translateY(-2px);
      box-shadow: var(--shadow-card-hover);
    }

    &:target {
      outline: 2px solid var(--color-accent);
      outline-offset: 2px;
    }

    @media (prefers-reduced-motion: reduce) {
      &:has(a, .shot-link):hover,
      &:has(a, .shot-link):focus-within {
        transform: none;
      }
    }
  }

  /* DOM keeps the title first; the ratio frame is shown first */
  .shot {
    order: -1;
    margin: 0;
    aspect-ratio: 16 / 10;
    display: flex;
    justify-content: center;
    overflow: hidden;
    background: var(--color-surface);
    border: 1px solid var(--color-line);
    border-radius: var(--radius-md);

    &[data-frame="app"]::before {
      content: "";
      block-size: 100%;
      aspect-ratio: 9 / 16;
      max-inline-size: 200px;
      background: var(--color-bg);
      border: 1px solid var(--color-line-strong);
      border-radius: var(--radius-md);
    }

    picture {
      display: block;
    }

    picture,
    img {
      inline-size: 100%;
      block-size: 100%;
      object-fit: cover;
      object-position: top;
    }

    /* the control around the image: <a> without JS, <button> with it */
    .shot-link {
      display: block;
      inline-size: 100%;
      block-size: 100%;
      padding: 0;
      margin: 0;
      border: 0;
      background: none;
      font: inherit;
      color: inherit;
      cursor: zoom-in;
      overflow: hidden;

      &:focus-visible {
        outline: none;
      }
    }

    /* project without a screenshot: icon + "No image", centred, not interactive */
    &[data-empty="no-image"] {
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: var(--space-sm);
      color: var(--color-ink-3);
      cursor: auto;

      .no-image-icon {
        flex: none;
        inline-size: 32px;
        block-size: 32px;
      }

      .no-image-label {
        font-size: var(--text-label);
        line-height: 1.2;
        color: var(--color-ink-3);
      }
    }

    /* filled app frame: a quiet 9:16 box, no device mockup */
    &[data-frame="app"]:has(.shot-link)::before {
      content: none;
    }

    &[data-frame="app"] .shot-link {
      inline-size: auto;
      block-size: 100%;
      aspect-ratio: 9 / 16;
      max-inline-size: 200px;
      margin-inline: auto;
      border: 1px solid var(--color-line-strong);
      border-radius: var(--radius-md);
    }

    &:has(.shot-link:focus-visible) {
      outline: 2px solid var(--color-accent);
      outline-offset: 2px;
    }

    @media (prefers-reduced-motion: no-preference) {
      .shot-link img {
        transition: transform var(--dur) var(--ease);
      }

      .shot-link:focus-visible img {
        transform: scale(1.02);
      }

      @media (hover: hover) {
        .shot-link:hover img {
          transform: scale(1.02);
        }
      }
    }
  }

  .meta {
    display: grid;
    gap: var(--space-sm);
    margin: 0;

    & > div {
      display: grid;
      grid-template-columns: 88px minmax(0, 1fr);
      gap: var(--space-sm);

      @container company (max-width: 359.98px) {
        grid-template-columns: minmax(0, 1fr);
        gap: 0;
      }
    }

    dt {
      font-size: var(--text-label);
      font-weight: var(--weight-semibold);
      line-height: 1.6;
      color: var(--color-ink-3);
    }

    dd {
      margin: 0;
      color: var(--color-ink-2);
      overflow-wrap: anywhere;
    }
  }

  .meta data {
    display: inline-block;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    background: var(--color-accent-tint);
    color: var(--color-accent);
    font-weight: var(--weight-semibold);
    font-variant-numeric: tabular-nums;
    line-height: 1.4;
  }

  .status-links {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-sm);
    margin-block-start: auto;
    padding-block-start: var(--space-md);
    border-block-start: 1px solid var(--color-line);
  }

  .status {
    margin: 0;
    padding: 4px 8px;
    border: 1px solid var(--color-line);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-ink-2);
    font-size: var(--text-label);
    font-weight: var(--weight-semibold);
    line-height: 1.4;
  }

  .links {
    margin: 0;

    a {
      display: inline-flex;
      align-items: center;
      gap: var(--space-sm);
      min-block-size: 44px;
      color: var(--color-accent);
      text-decoration: underline;
      overflow-wrap: anywhere;

      &::after {
        content: "";
        flex: none;
        inline-size: 8px;
        block-size: 8px;
        border-inline-end: 2px solid currentcolor;
        border-block-start: 2px solid currentcolor;
        transform: rotate(45deg);
      }
    }
  }

  .skills dt {
    font-size: var(--text-label);
    font-weight: var(--weight-semibold);
    color: var(--color-accent); /* user request 2026-11-17: Tech stack subheadings in the main color (5.43:1 on white) */
  }

  .skills dd {
    margin: var(--space-sm) 0 0;
  }

  .skills ul {
    list-style: none;
    margin: 0;
    padding: 0;
    color: var(--color-ink-2);
  }

  /* slider position dots: 8px dot inside a 44px hit area; built by js/main.js below 640px only */
  .skills-dots {
    display: flex;
    justify-content: center;
    margin-block-start: var(--space-sm);

    & button {
      inline-size: 44px;
      block-size: 44px;
      padding: 0;
      border: 0;
      background: none;
      cursor: pointer;
      display: grid;
      place-items: center;

      &::before {
        content: "";
        inline-size: 8px;
        block-size: 8px;
        border-radius: 50%;
        background: var(--color-line-strong);
      }

      &[aria-current="true"]::before {
        background: var(--color-accent);
      }
    }

    @media print {
      display: none;
    }
  }

  .contact-list dt {
    font-size: var(--text-label);
    font-weight: var(--weight-semibold);
    color: var(--color-ink-3);
  }

  .contact-list a {
    display: inline-flex;
    align-items: center;
    min-block-size: 44px;
    overflow-wrap: anywhere;
  }

  /* screenshot zoom dialog: native <dialog>, built by js/main.js. Never set display on the closed state. */
  .shot-dialog {
    position: fixed;
    inset: var(--space-md);
    inline-size: auto;
    block-size: auto;
    max-inline-size: none;
    max-block-size: none;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: #fff;
    overflow: hidden;

    @media (min-width: 640px) {
      inset: var(--space-lg);
    }

    &[open] {
      display: grid;
      grid-template-rows: auto minmax(0, 1fr);
    }

    &::backdrop {
      background: var(--color-overlay-strong);
    }
  }

  .shot-dialog-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    padding-block-end: var(--space-sm);
  }

  .shot-dialog-title {
    min-inline-size: 0;
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .shot-dialog-close {
    min-block-size: 44px;
    min-inline-size: 44px;
    padding-inline: var(--space-md);
    background: transparent;
    color: #fff;
    border: 1px solid rgb(255 255 255 / 0.5);
    border-radius: var(--radius-sm);
    font: inherit;
    font-weight: 600;
    cursor: pointer;

    &:hover,
    &:focus-visible {
      background: rgb(255 255 255 / 0.12);
    }

    &:focus-visible {
      outline: 2px solid #fff;
      outline-offset: 2px;
    }
  }

  .shot-dialog-scroll {
    display: grid;
    place-items: start center;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    border-radius: var(--radius-md);
    background: var(--color-surface);

    &:focus-visible {
      outline: 2px solid #fff;
      outline-offset: 2px;
    }

    picture {
      display: block;
      inline-size: 100%;
    }

    img {
      display: block;
      inline-size: 100%;
      max-inline-size: 1920px;
      block-size: auto;
      margin-inline: auto;
    }
  }

  .shot-dialog[data-frame="app"] .shot-dialog-scroll img {
    inline-size: min(100%, 480px);
  }

  html:has(dialog.shot-dialog[open]) {
    overflow: hidden;
  }

  @media (prefers-reduced-motion: no-preference) {
    .shot-dialog[open] {
      opacity: 1;
      transition: opacity var(--dur) var(--ease), display var(--dur) allow-discrete, overlay var(--dur) allow-discrete;

      @starting-style {
        opacity: 0;
      }
    }

    .shot-dialog[open]::backdrop {
      opacity: 1;
      transition: opacity var(--dur) var(--ease);

      @starting-style {
        opacity: 0;
      }
    }

    .shot-dialog-scroll {
      transition: transform var(--dur) var(--ease);
    }

    .shot-dialog[open] .shot-dialog-scroll {
      @starting-style {
        transform: scale(0.98);
      }
    }

    .shot-dialog[data-closing] {
      opacity: 0;
    }

    .shot-dialog[data-closing]::backdrop {
      opacity: 0;
    }

    .shot-dialog[data-closing] .shot-dialog-scroll {
      transform: scale(0.98);
    }
  }
}
