/* 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;
  }

  /* 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-linkedin { --brand: #0a66c2; }
  .s-youtube  { --brand: #ff0033; }
  .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); }

  /* 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 */
  /* The box sets background-color and .media-missing sets background-image: separate properties, so neither overrides the other */
  .thumb { display: block; flex: 0 0 auto; overflow: hidden; width: var(--thumb-w); height: var(--thumb-h); border-radius: 6px; background-color: var(--panel2); }
  .thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
  /* 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);
  }

  /* VIDEO */
  /* One 16:9 box. The YouTube facade shows a poster and our play button until pressed. */
  .video { position: relative; aspect-ratio: 16 / 9; overflow: hidden; border-radius: var(--radius); background: var(--media-bg); }
  .video > img, .video > video, .video > iframe { display: block; width: 100%; height: 100%; border: 0; object-fit: cover; }
  .video > video { object-fit: contain; }
  .video-play {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    width: 72px;
    height: 72px;
    margin: auto;
    border: 0;
    border-radius: 50%;
    background: var(--accent);
    color: var(--on-accent);
    box-shadow: 0 4px 24px rgba(0, 0, 0, .5);
    cursor: pointer;
    transition: transform .15s ease, background .15s ease;
  }
  .video-play .ic { width: 30px; height: 30px; margin-left: 4px; }
  .video-play:hover { transform: scale(1.08); background: var(--accent2); }
  .video-play:focus-visible { --focus-off: 4px; }

  /* Set by video.js only once a load outlasts its grace delay, so fast loads never flash it */
  .video.loading::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    width: 48px;
    height: 48px;
    margin: auto;
    border: 4px solid color-mix(in srgb, var(--accent) 25%, transparent);
    border-top-color: var(--accent);
    border-radius: 50%;
    pointer-events: none;
    animation: video-spin .8s linear infinite;
  }
  @keyframes video-spin { to { transform: rotate(1turn); } }

  /* CLIPS */
  /* One <video> per clip, stacked; video.js shows one at a time, swapping on the new clip's first frame */
  .clips { position: relative; }
  .clips .video > video { position: absolute; inset: 0; opacity: 0; pointer-events: none; }
  .clips .video > video.on { opacity: 1; pointer-events: auto; }

  /* The arrows centre on the video, not on the video plus the dots below it */
  .clip-arrow {
    position: absolute;
    top: calc(50% - 9px);
    z-index: 3;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    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;
  }
  .clip-arrow .ic { width: 22px; height: 22px; }
  .clip-arrow.prev { left: 8px; }
  .clip-arrow.next { right: 8px; }
  .clips:hover .clip-arrow,
  .clips:focus-within .clip-arrow,
  .clip-arrow:focus-visible { opacity: 1; }
  .clip-arrow:focus-visible { --focus-off: 0; }

  .clip-dots { display: flex; justify-content: center; gap: 7px; margin-top: 9px; }
  .clip-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;
  }
  .clip-dots button.on { background: var(--accent); opacity: 1; transform: scale(1.35); }
  .clip-dots button:focus-visible { --focus-off: 3px; }

  /* Touch: no hover to reveal the arrows, and fingers need bigger dots */
  @media (hover: none) {
    .clip-arrow { opacity: .9; }
    .clip-dots { gap: 10px; margin-top: 12px; }
    .clip-dots button { width: 10px; height: 10px; }
  }

  /* PRODUCTIONS */
  /* Compact, static cards in a two-column grid; icons label the lines */
  .prod-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  @media (max-width: 760px) {
    .prod-grid { grid-template-columns: 1fr; }
  }
  .prod { display: flex; align-items: flex-start; gap: 14px; padding: 12px; }
  .prod-icon { display: block; flex: 0 0 auto; width: 96px; height: 96px; overflow: hidden; border-radius: 12px; background-color: var(--panel2); }
  .prod-icon img { display: block; width: 100%; height: 100%; object-fit: cover; }
  .prod-text { flex: 1 1 auto; min-width: 0; }
  .prod-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
  .prod-name { color: var(--ink); font-size: 17px; font-weight: 700; line-height: 1.25; }
  .prod-year { color: var(--ink3); font: 600 var(--fs-pill)/1 var(--font-mono); white-space: nowrap; }
  .prod-spec { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 9px; margin: 8px 0 0; font-size: var(--fs-data); line-height: 1.35; }
  .prod-spec dt { display: flex; align-items: center; }
  .prod-spec dd { margin: 0; color: var(--ink2); }
  .prod-spec .ic { width: 16px; height: 16px; color: var(--accent); }

  /* ROWS */
  .rows { display: flex; flex-direction: column; gap: 10px; }
  .row { --row-pad: 12px; position: relative; overflow: hidden; }

  /* 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; }
  .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(--thumb-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: 14px; border-top: 1px solid var(--line); }
  @media (prefers-reduced-motion: reduce) {
    .row-fold { transition: none; }
  }

  /* 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; }
  }
}
