/* Each component keeps its narrow-screen rules directly under its own rules, never in a shared block at the end. */
@layer components {

  /* SURFACES */
  .wrap { max-width: var(--wrap-max); margin: 0 auto; padding: 30px 22px 110px; }
  .sec { margin: 0 0 44px; }
  .wrap > .sec:first-child { margin-top: 2px; }

  /* A card one step off the ground */
  .panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
  }

  /* HEADINGS */
  /* Label and description share a line: the label names the group, the sentence says what it is */
  .sechead {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 14px;
    margin: 0 0 14px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--line);
  }
  .sechead h2 {
    flex: 0 0 auto;
    margin: 0;
    color: var(--accent);
    font-family: var(--font-mono);
    font-size: var(--fs-label);
    letter-spacing: .8px;
    text-transform: uppercase;
  }
  .sechead p {
    flex: 1 1 260px;
    min-width: 0;
    margin: 0;
    color: var(--ink3);
    font-size: var(--fs-data);
    line-height: 1.45;
  }

  /* Subordinate to the section label: it divides one list rather than starting a new one, so no rule of its own */
  .group {
    margin: 26px 0 12px;
    color: var(--ink3);
    font-family: var(--font-mono);
    font-size: var(--fs-label);
    font-weight: 700;
    letter-spacing: .9px;
    text-transform: uppercase;
  }
  .group:first-child { margin-top: 0; }

  /* PILLS */
  /* The body every pill shares; each kind declares only what differs */
  .pill {
    background: var(--panel2);
    border: 1px solid var(--line);
    border-radius: var(--pill-r);
    padding: var(--pill-pad);
    font-family: var(--font-mono);
  }

  /* Denser than control pills, because a row of them sits under every title */
  .meta { display: flex; flex-wrap: wrap; gap: 6px; margin: 9px 0 0; padding: 0; list-style: none; }
  .meta .pill {
    padding: 2px 10px;
    color: var(--ink2);
    font-size: var(--fs-pill);
    letter-spacing: -.2px;
    white-space: nowrap;
  }
  .meta .ic { width: 13px; height: 13px; margin-right: 4px; color: var(--ink3); vertical-align: -2px; }
  /* Phone: role and tech are what a reader scans for, so the rest hide rather than shrink */
  @media (max-width: 560px) {
    .meta .pill:nth-child(n+3) { display: none; }
  }
  @media (max-width: 400px) {
    .meta .pill { padding: 2px 7px; }
    .meta .ic { width: 12px; height: 12px; margin-right: 3px; }
  }

  /* LINKS */
  /* Evidence that a title shipped, so they carry a control's weight. Spacing around the row belongs to whoever places it. */
  .links { display: flex; flex-wrap: wrap; gap: 8px; }

  /* --brand is set per type below; the fallback covers types without a brand colour, so no rule order is involved */
  .link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: color-mix(in srgb, var(--brand, var(--ink3)) 12%, var(--panel2));
    border-color: color-mix(in srgb, var(--brand, var(--ink3)) 28%, var(--line));
    color: var(--ink);
    font-size: var(--fs-data);
    font-weight: 600;
    line-height: 1.5;
    text-align: left;
  }
  .link:hover { border-color: var(--brand, var(--ink3)); text-decoration: none; }
  .link .ic { width: 16px; height: 16px; color: var(--brand, var(--ink3)); }

  .s-apple    { --brand: #e8eaed; }
  .s-play     { --brand: #3ddc84; }
  .s-ms       { --brand: #4ab0ff; }
  .s-nintendo { --brand: #e4000f; }
  .s-itch     { --brand: #fa5c5c; }
  .s-gitlab   { --brand: #fc6d26; }
  .s-linkedin { --brand: #0a66c2; }
  .s-cv       { --brand: #ffd24a; }

  /* BUTTONS */
  .cvbtn {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 6px;
    padding: 5px 11px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel2);
    color: var(--ink);
    font-size: var(--fs-data);
    font-weight: 600;
  }
  .cvbtn:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
  .cvbtn .ic { width: 15px; height: 15px; }
  /* Phone: the icon alone, the label stays in the markup for screen readers */
  @media (max-width: 560px) {
    .cvbtn { padding: 5px 8px; }
    .cvbtn span { display: none; }
  }

  /* A control that needs a script never shows without one */
  .disclosure { display: none; cursor: pointer; }
  .js .disclosure { display: inline-flex; }
  .disclosure .ic { transition: transform .2s; }
  .disclosure[aria-expanded="true"] .ic { transform: rotate(180deg); }

  /* BULLETS */
  /* The summary reads as a caption over the proof: bullet type without the marker, set off by a rule rather than by emphasis */
  .row-summary {
    margin: 0 0 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
    color: var(--ink2);
    font-size: var(--fs-bul);
    line-height: 1.55;
  }
  .bullets { display: flex; flex-direction: column; gap: 9px; margin: 0; padding: 0; list-style: none; }
  .bullets li {
    position: relative;
    padding-left: 20px;
    color: var(--ink2);
    font-size: var(--fs-bul);
    line-height: 1.55;
  }
  .bullets li::before {
    content: "";
    position: absolute;
    left: 4px;
    top: .62em;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    opacity: .85;
  }

  /* ADDRESS */
  /* One click selects the whole address, which is what a reader wants it for */
  .address {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--ink2);
    font-size: var(--fs-data);
    user-select: all;
  }
  .address .ic { width: 16px; height: 16px; color: var(--ink3); user-select: none; }

  /* MEDIA */
  /* Boxes set background-color and .media-missing sets background-image: separate properties, so neither overrides the other */
  .thumb, .logo { display: block; flex: 0 0 auto; overflow: hidden; background-color: var(--panel2); }
  .thumb { width: var(--thumb-w); height: var(--thumb-h); border-radius: 6px; }
  /* A shorter box than the thumb: a library is a smaller thing than a shipped title */
  .logo { width: var(--logo-s); height: var(--logo-s); border: 1px solid var(--line); border-radius: 8px; }
  .fit-cover, .fit-contain { display: block; width: 100%; height: 100%; }
  .fit-cover { object-fit: cover; }
  .fit-contain { object-fit: contain; }

  /* Missing image: same box, hatched, so the gap reads as missing content rather than a design choice */
  .media-missing {
    background-image: repeating-linear-gradient(45deg, transparent 0 8px, var(--line) 8px 9px);
  }

  /* CAROUSEL */
  .carousel { position: relative; }
  .carousel-viewport { overflow: hidden; border-radius: 8px; }
  .carousel-track { display: flex; }
  .carousel-slide { flex: 0 0 100%; min-width: 0; }
  .frame {
    display: grid;
    place-items: center;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    background-color: var(--media-bg);
    cursor: zoom-in;
  }
  .frame img { display: block; max-width: 100%; max-height: 100%; width: auto; height: auto; }
  /* Not loaded yet: hide the broken-image glyph, keep the dark frame */
  .frame img[data-src] { visibility: hidden; }

  .carousel-arrow {
    position: absolute;
    top: calc(50% - 9px);
    z-index: 3;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: var(--overlay);
    color: var(--ink);
    cursor: pointer;
    opacity: 0;
    transform: translateY(-50%);
    transition: opacity .15s;
  }
  .carousel-arrow .ic { width: 18px; height: 18px; }
  .carousel-arrow.prev { left: 8px; }
  .carousel-arrow.next { right: 8px; }
  .carousel:hover .carousel-arrow,
  .carousel:focus-within .carousel-arrow,
  .carousel-arrow:focus-visible { opacity: 1; }
  .carousel-arrow:focus-visible { --focus-off: 0; }

  .carousel-dots { display: flex; justify-content: center; gap: 7px; margin-top: 9px; }
  .carousel-dots button {
    width: 8px;
    height: 8px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--ink3);
    cursor: pointer;
    opacity: .45;
    transition: opacity .12s, transform .12s, background .12s;
  }
  .carousel-dots button.on { background: var(--accent); opacity: 1; transform: scale(1.35); }
  .carousel-dots button:focus-visible { --focus-off: 3px; }

  /* Touch: no hover to reveal the arrows, and fingers need bigger dots */
  @media (hover: none) {
    .carousel-arrow { opacity: .9; }
    .carousel-dots { gap: 10px; margin-top: 12px; }
    .carousel-dots button { width: 10px; height: 10px; }
  }
  /* Tablet and phone: a full-width shot owns the fold, so the carousel becomes a strip of thumbnails; tapping zooms */
  @media (max-width: 760px) {
    .carousel-track { gap: 8px; }
    .carousel-slide { flex: 0 0 42%; }
    .frame { border-radius: 6px; }
    .carousel-arrow, .carousel-dots { display: none; }
  }

  /* ROWS */
  .rows { display: flex; flex-direction: column; gap: 10px; }
  .rows + .group { margin-top: 30px; }

  /* The header padding is shared with the zoom layer, which must sit exactly over the thumb */
  .row { --row-pad: 12px; position: relative; overflow: hidden; }
  /* The height the chevron centres on: the 16:9 thumb for a game, the logo square for a library */
  .layout-game { --media-h: var(--thumb-h); }
  .layout-library { --media-h: var(--logo-s); }

  /* The whole header is the button. The title's cap-height sits on the image's top edge, so wrapping pills move nothing. */
  .row-head {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    width: 100%;
    padding: var(--row-pad);
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
  }
  .row-head:hover { background: var(--panel2); }
  .row-head:focus-visible { --focus-off: -2px; }

  /* Title zoom: a link stacked exactly over the thumb, above the header button; the icon says the picture is clickable */
  .thumb-zoom {
    position: absolute;
    z-index: 1;
    top: var(--row-pad);
    left: var(--row-pad);
    width: var(--thumb-w);
    height: var(--thumb-h);
    display: grid;
    place-items: end;
    padding: 6px;
    border-radius: 6px;
    color: var(--ink);
  }
  .thumb-zoom .ic {
    width: 26px;
    height: 26px;
    padding: 4px;
    border-radius: 50%;
    background: var(--overlay);
    opacity: 0;
    transition: opacity .15s;
  }
  .thumb-zoom:hover .ic, .thumb-zoom:focus-visible .ic { opacity: 1; }
  .thumb-zoom:focus-visible { --focus-off: 2px; }
  /* Touch has no hover, so the icon stays in sight */
  @media (hover: none) {
    .thumb-zoom .ic { opacity: .85; }
  }
  .row-text { flex: 1 1 auto; min-width: 0; }

  /* Tight leading, so the glyphs start at the box's top edge rather than half a line below it */
  .row-title {
    display: block;
    margin-top: -.02em;
    font-size: var(--fs-title);
    font-weight: 700;
    letter-spacing: .3px;
    line-height: 1.15;
  }

  /* Second level on the title line: smaller, lighter and in caps, so the name keeps priority */
  .row-sep, .row-tagline {
    color: var(--ink2);
    font-size: .72em;
    font-weight: 400;
    letter-spacing: .08em;
    text-transform: uppercase;
  }

  /* Centred on the image, not the text block, so it holds still as the pills wrap */
  .row-chevron {
    width: var(--chevron-s);
    height: var(--chevron-s);
    margin-top: calc((var(--media-h) - var(--chevron-s)) / 2);
    color: var(--ink2);
    transition: transform .22s ease;
  }
  .row-head[aria-expanded="false"] .row-chevron { color: var(--ink); }
  .row-head[aria-expanded="true"] .row-chevron { transform: rotate(180deg); }

  /* Animating grid rows from 0fr to 1fr opens the fold to its natural height, whatever that is */
  .row-fold { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .28s ease; }
  .row-fold.on { grid-template-rows: 1fr; }
  .row-fold > div { overflow: hidden; }
  .row-fold-body { padding: 16px 14px 18px; border-top: 1px solid var(--line); }
  .layout-library .row-fold-body .links { margin-top: 14px; }
  @media (prefers-reduced-motion: reduce) {
    .row-fold { transition: none; }
  }

  /* Game fold: media left, bullets right. The links sit at the column's base so both columns end on one line. */
  .row-columns {
    display: grid;
    grid-template-columns: minmax(0, 30fr) minmax(0, 70fr);
    align-items: start;
    gap: 22px;
  }
  .row-media { display: flex; flex-direction: column; align-self: stretch; }
  .row-media .links { margin-top: auto; padding-top: 14px; }
  @media (max-width: 760px) {
    .row-columns { grid-template-columns: 1fr; }
  }

  /* Phone: the chevron leaves the line for the corner, buying the text column back */
  @media (max-width: 560px) {
    .row { --row-pad: 10px; }
    .row-head { position: relative; gap: 12px; }
    .row-title { font-size: 16px; }
    .row-text { padding-right: 30px; }
    /* The tagline would wrap mid-phrase beside a phone-width name, so it goes rather than breaks */
    .row-sep, .row-tagline { display: none; }
    .row-chevron { position: absolute; top: 8px; right: 8px; margin-top: 0; }
  }

  /* NAV */
  /* Both bars cap their contents at the page width, so the nav lines up with the content below */
  .nav-inner {
    display: flex;
    align-items: center;
    width: 100%;
    max-width: var(--wrap-max);
    margin: 0 auto;
    padding: 0 22px;
  }
  .nav-top {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 60;
    display: flex;
    height: var(--top-h);
    background: var(--panel);
    border-bottom: 1px solid var(--line);
  }
  .nav-top .nav-inner { justify-content: space-between; gap: 16px; }
  @media (max-width: 560px) {
    .nav-inner { padding: 0 14px; }
  }

  .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    color: var(--ink);
    font-weight: 700;
  }
  .brand:hover { text-decoration: none; }
  .brand img { flex: 0 0 auto; width: 30px; height: 30px; object-fit: contain; }
  .brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  @media (max-width: 560px) {
    .brand-name { font-size: 15px; }
  }

  /* Outbound links: the CV button, then the social icons */
  .nav-links { display: flex; flex: 0 0 auto; align-items: center; gap: 2px; }
  .icon-link { display: block; padding: 7px; border-radius: 6px; color: var(--ink3); line-height: 0; }
  .icon-link .ic { width: 19px; height: 19px; }
  .icon-link:hover { background: var(--panel2); color: var(--ink); }
  .icon-link:focus-visible { --focus-off: -2px; }

  /* A step darker than the top bar: identity above sections, sections above content */
  .nav-tabs {
    position: fixed;
    top: var(--top-h);
    left: 0;
    right: 0;
    z-index: 59;
    height: var(--tabs-h);
    background: var(--nav2);
    border-bottom: 1px solid var(--line);
  }
  /* The tabs share the content band, each a full segment of the bar */
  .tab-list { height: 100%; list-style: none; }
  .tab-list li { flex: 1 1 0; min-width: 0; height: 100%; }
  .tab {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 100%;
    padding: 0 6px;
    color: var(--ink2);
    font-family: var(--font-mono);
    font-size: var(--fs-nav);
    letter-spacing: .2px;
    white-space: nowrap;
    transition: background .14s, color .14s;
  }
  .tab:hover { background: var(--panel2); color: var(--ink); text-decoration: none; }
  .tab .ic { width: 15px; height: 15px; }
  .tab:focus-visible { --focus-off: -2px; }
  .tab[aria-current="page"] { color: var(--ink); font-weight: 600; }
  /* The underline runs the whole slot, so the active tab reads as a segment of the bar */
  .tab[aria-current="page"]::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 2px;
    background: var(--accent);
  }
  /* Phone: the labels shorten rather than truncate */
  .tab-short { display: none; }
  @media (max-width: 560px) {
    .tab-full { display: none; }
    .tab-short { display: inline; }
  }

  /* LIGHTBOX —PhotoSwipe's own variables, set from our tokens */
  .pswp {
    --pswp-bg: var(--lightbox-bg);
    --pswp-icon-color: var(--ink);
    --pswp-icon-color-secondary: var(--lightbox-bg);
    --pswp-icon-stroke-color: transparent;
  }
  .pswp__button { opacity: .85; }
  .pswp__button:hover { opacity: 1; }
}
