/* One block per area of the page, in the order they appear in index.html.
   Class names are BEM (block__element--modifier). Styles are mobile first,
   and each block carries its own desktop rules in a nested @media. */

@layer components {
  /* ========== top bar ========== */
  .topbar {
    position: fixed;
    inset: 0 0 auto;
    z-index: 50;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "brand clock"
      "nav   nav";
    align-items: center;
    gap: 10px 16px;
    padding: 14px var(--gutter);
    background: color-mix(in oklab, var(--paper) 82%, transparent);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--rule-faint);
    font-family: var(--mono);
    font-size: var(--fs-mono-sm);
    letter-spacing: var(--track-xs);

    @media (width > 900px) {
      display: flex;
      justify-content: space-between;
      padding-block: 18px;
    }
  }

  .topbar__brand {
    grid-area: brand;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
  }

  /* "/ PORTFOLIO '26" only fits next to the clock from 480px up. */
  .topbar__suffix {
    display: none;

    @media (width > 480px) {
      display: inline;
    }
  }

  .topbar__mark {
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    background: var(--ink);
    color: var(--paper);
    font-size: var(--fs-mono-xs);
    font-weight: 700;
  }

  /* On phones the links drop to a second row instead of disappearing. */
  .topbar__nav {
    grid-area: nav;
    display: flex;
    gap: 28px;
    overflow-x: auto;
    scrollbar-width: none;
    text-transform: uppercase;

    a {
      position: relative;
      padding: 4px 0;
      color: var(--muted);
      white-space: nowrap;
      transition: color 0.2s ease;
    }
    a::after {
      content: "";
      position: absolute;
      left: 0;
      bottom: 0;
      width: 0;
      height: 1px;
      background: var(--ink);
      transition: width 0.25s ease;
    }
    a:hover {
      color: var(--ink);
    }
    a:hover::after {
      width: 100%;
    }
  }

  .topbar__clock {
    grid-area: clock;
    display: flex;
    white-space: nowrap;
    align-items: center;
    gap: 8px;
    color: var(--muted);
  }

  .topbar__dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--live);
    animation: pulse 2s infinite;
  }

  @keyframes pulse {
    0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--live) 60%, transparent); }
    70% { box-shadow: 0 0 0 8px transparent; }
    100% { box-shadow: 0 0 0 0 transparent; }
  }

  /* ========== hero ========== */
  .hero {
    padding: 160px 0 80px;
  }

  .hero__grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 48px;
    align-items: end;

    @media (width > 900px) {
      grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
      gap: 64px;
    }
  }

  .hero__eyebrow {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 36px;
  }
  .hero__eyebrow::before {
    content: "";
    width: 32px;
    height: 1px;
    background: var(--ink);
  }

  .hero__title {
    margin-bottom: 28px;
    font-size: clamp(64px, 9vw, 148px);
    line-height: 0.92;
    letter-spacing: -0.04em;
  }

  /* The full stop after the name, with a bar that swipes in under it. */
  .hero__stop {
    position: relative;
    display: inline-block;
  }
  .hero__stop::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 8px;
    z-index: -1;
    height: 8px;
    background: var(--ink);
    transform: scaleX(0);
    transform-origin: left;
    animation: swipe 1.1s cubic-bezier(0.7, 0.2, 0.2, 1) 0.4s forwards;
  }

  @keyframes swipe {
    to { transform: scaleX(1); }
  }

  .hero__meta {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
    margin-top: 48px;
    padding-top: 28px;
    border-top: 1px solid var(--rule-soft);
    letter-spacing: var(--track-sm);

    dd {
      margin-top: 6px;
      color: var(--ink);
      font-family: var(--sans);
      font-size: 18px;
      font-weight: 500;
      text-transform: none;
      letter-spacing: -0.01em;
    }

    @media (width > 900px) {
      grid-template-columns: repeat(3, auto);
      gap: 32px 56px;
    }
  }

  /* ========== portrait ========== */
  .portrait {
    position: relative;
    width: 100%;
    max-width: 320px;
    aspect-ratio: 1 / 1;
    justify-self: start;

    @media (width > 900px) {
      max-width: 460px;
      justify-self: end;
    }
  }

  .portrait__frame {
    position: absolute;
    inset: 0;
    overflow: hidden;
    background: var(--ink);
    filter: contrast(1.05);

    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      filter: grayscale(1) contrast(1.15);
      mix-blend-mode: screen;
      opacity: 0.96;
    }
  }

  .portrait__handle {
    position: absolute;
    top: -10px;
    right: -10px;
    padding: 8px 12px;
    background: var(--ink);
    color: var(--paper);
    font-size: var(--fs-mono-xs);
    letter-spacing: var(--track-md);
  }

  .portrait__status {
    position: absolute;
    bottom: -22px;
    left: -16px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--paper);
    border: 1px solid var(--ink);
    color: var(--ink);
    font-size: var(--fs-mono-xs);
    letter-spacing: var(--track-sm);

    @media (width > 900px) {
      left: -22px;
    }
  }
  .portrait__status::before {
    content: "";
    width: 8px;
    height: 8px;
    background: var(--ink);
  }

  /* ========== lede ========== */
  .lede {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
    align-items: start;
    margin-top: 90px;
    padding-top: 28px;
    border-top: 1px solid var(--rule-soft);

    @media (width > 900px) {
      grid-template-columns: minmax(0, 1fr) minmax(0, 2.2fr);
      gap: 48px;
    }
  }

  .lede__text {
    font-family: var(--serif);
    font-size: clamp(20px, 1.9vw, 28px);
    line-height: 1.4;
    letter-spacing: -0.01em;
    text-wrap: pretty;

    mark {
      padding: 0 6px;
      -webkit-box-decoration-break: clone;
      box-decoration-break: clone;
      background: var(--ink);
      color: var(--paper);
    }
  }

  /* ========== marquee ========== */
  /* index.html holds one copy of the topics. site.js clones it (hidden from
     screen readers) and starts the scroll, so without JavaScript the strip
     simply sits still. */
  .marquee {
    overflow: hidden;
    padding: 22px 0;
    background: var(--paper);
    border-block: 1px solid var(--ink);
    font-size: clamp(36px, 5vw, 72px);
    line-height: normal;
    white-space: nowrap;
  }

  .marquee__track {
    display: flex;
    width: max-content;
  }
  .marquee__track.is-running {
    animation: marquee 38s linear infinite;
  }

  .marquee__group {
    display: flex;
  }

  .marquee__item {
    padding-left: 32px;
  }
  .marquee__item::after {
    content: "✱";
    content: "✱" / "";
    margin: 0 32px 0 64px;
    color: var(--muted);
    font-style: normal;
  }

  @keyframes marquee {
    from { transform: translateX(0); }
    to { transform: translateX(-50%); }
  }

  /* ========== stats strip ========== */
  .stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-block: 1px solid var(--ink);

    @media (width > 900px) {
      grid-template-columns: repeat(4, minmax(0, 1fr));
    }
  }

  /* <dt> comes first in the markup for screen readers; column-reverse puts
     the big number on top. */
  .stats__item {
    display: flex;
    flex-direction: column-reverse;
    justify-content: flex-end;
    gap: 12px;
    padding: 36px 28px;
    background: var(--paper);
    border-right: 1px solid var(--rule-soft);

    &:nth-child(2n) {
      border-right: none;
    }

    @media (width > 900px) {
      &:nth-child(2n) {
        border-right: 1px solid var(--rule-soft);
      }
      &:last-child {
        border-right: none;
      }
    }
  }

  .stats__label {
    font-size: var(--fs-mono-xs);
  }

  .stats__label a {
    text-decoration: underline;
    text-underline-offset: 3px;

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

  .stats__value {
    display: flex;
    align-items: baseline;
    gap: 6px;
    font-size: clamp(48px, 5vw, 72px);
  }

  .stats__unit {
    color: var(--muted);
    font-family: var(--mono);
    font-size: 14px;
    letter-spacing: 0;
  }

  /* ========== section heading ========== */
  .section-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px 32px;
    margin-bottom: 56px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--ink);
  }

  .section-head__title {
    font-size: clamp(40px, 5vw, 72px);
  }

  .section-head__aside {
    letter-spacing: var(--track-md);

    a {
      color: var(--ink);
      font-weight: 600;
    }
    a:hover {
      text-decoration: underline;
    }
  }

  /* ========== repository cards ========== */
  /* Hover and the featured card invert the colours by swapping these three
     local properties. Children only read them, so no child needs its own
     :hover rule. */
  .repo-card {
    --card-bg: var(--paper);
    --card-fg: var(--ink);
    --card-muted: var(--muted);

    position: relative;
    display: flex;
    flex-direction: column;
    gap: 18px;
    min-height: 280px;
    padding: 28px 20px 24px;
    background: var(--card-bg);
    color: var(--card-fg);
    border-bottom: 1px solid var(--ink);
    transition: background-color 0.25s ease, color 0.25s ease;

    @media (width > 900px) {
      padding: 36px 32px 28px;
    }

    &:hover {
      --card-bg: var(--ink);
      --card-fg: var(--paper);
      --card-muted: var(--on-ink-soft);
    }

    /* The whole card is the link's hit area, so show focus on the card. */
    &:has(a:focus-visible) {
      outline: 2px solid var(--accent);
      outline-offset: -6px;
    }
  }

  .repo-card__head {
    display: flex;
    align-items: flex-start;
    gap: 18px;
  }

  .repo-card__title {
    min-width: 0;
    margin-right: auto;
    overflow-wrap: break-word;  /* long repo names wrap instead of widening the card */
    font-family: var(--sans);
    font-size: 22px;
    font-weight: 500;
    letter-spacing: -0.01em;
    line-height: 1.1;

    /* Stretched link: the title's link covers the whole card. */
    a::after {
      content: "";
      position: absolute;
      inset: 0;
    }
    a:focus-visible {
      outline: none;
    }

    @media (width > 900px) {
      font-size: 26px;
    }
  }

  /* Links inside a card sit above the stretched title link, so they stay clickable. */
  .repo-card__meta a {
    position: relative;
    z-index: 1;
    text-decoration: underline;
    text-underline-offset: 3px;
  }

  .repo-card__slash {
    margin: 0 4px;
    color: var(--muted);
    font-weight: 300;
  }

  .repo-card__pin {
    display: flex;
    align-items: center;
    gap: 6px;
    padding-top: 4px;
    color: var(--card-muted);
    font-size: var(--fs-mono-xs);
    white-space: nowrap;
  }
  .repo-card__pin::before {
    content: "★";
    color: var(--card-fg);
  }

  .repo-card__arrow {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border: 1px solid currentColor;
    border-radius: 50%;
    font-size: 14px;
    transition: transform 0.25s ease;
  }
  .repo-card:hover .repo-card__arrow {
    transform: rotate(-45deg);
  }

  .repo-card__desc {
    flex: 1;
    color: var(--card-muted);
    font-size: 15px;
    line-height: 1.55;
    text-wrap: pretty;
  }

  .repo-card__meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 22px;
    margin-top: auto;
    padding-top: 18px;
    border-top: 1px dashed color-mix(in oklab, currentColor 30%, transparent);
    color: var(--card-muted);
    font-size: var(--fs-mono-xs);
    letter-spacing: var(--track-sm);
  }

  .repo-card__lang {
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .repo-card__lang::before {
    content: "";
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--lang, var(--muted));
    outline: 1px solid var(--card-fg);
    outline-offset: 2px;
  }

  /* Language colours, the same ones GitHub uses. One line per language. */
  [data-lang="javascript"] { --lang: #f1e05a; }
  [data-lang="typescript"] { --lang: #3178c6; }
  [data-lang="python"] { --lang: #3572a5; }
  [data-lang="java"] { --lang: #b07219; }
  [data-lang="shell"] { --lang: #89e051; }
  [data-lang="html"] { --lang: #e34c26; }
  [data-lang="tex"] { --lang: #3d6117; }

  /* ---------- featured card (full width, always inverted) ---------- */
  .repo-card--featured {
    --card-bg: var(--ink);
    --card-fg: var(--paper);
    --card-muted: var(--on-ink-soft);

    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 32px;
    align-items: end;
    min-height: 320px;
    border-top: 1px solid var(--ink);

    @media (width > 900px) {
      grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
      gap: 64px;
    }

    .repo-card__pin {
      margin-bottom: 18px;
      padding-top: 0;
    }
    .repo-card__title {
      font-family: var(--serif);
      font-size: clamp(38px, 5vw, 64px);
      font-weight: 400;
      letter-spacing: -0.03em;
    }
    .repo-card__desc {
      max-width: 38ch;
      margin-top: 18px;
      font-size: 17px;
    }
    .repo-card__meta {
      gap: 12px 18px;
      padding-top: 0;
      border-top: none;
    }
  }

  .repo-card__cta {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-top: 32px;
    font-family: var(--mono);
    font-size: var(--fs-mono-sm);
    text-transform: uppercase;
    letter-spacing: var(--track-md);
  }

  /* ---------- grid of regular cards ---------- */
  .repo-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);

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

      > .repo-card:nth-child(odd) {
        border-right: 1px solid var(--ink);
      }

      /* An odd card count leaves the last card alone, so it takes the full row */
      > .repo-card:last-child:nth-child(odd) {
        grid-column: 1 / -1;
        border-right: 0;
      }
    }
  }

  .work-foot {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 12px 24px;
    margin-top: 28px;
    letter-spacing: var(--track-md);

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

  /* ========== stack ========== */
  .stack {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 56px;
    align-items: start;

    @media (width > 900px) {
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: 80px;
    }
  }

  .stack__heading {
    margin-bottom: 24px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--rule-soft);
    font-size: var(--fs-mono-xs);
  }

  .chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 36px;
  }

  .chip {
    padding: 8px 14px;
    background: var(--paper);
    color: var(--ink);
    border: 1px solid var(--ink);
    font-family: var(--mono);
    font-size: var(--fs-mono-sm);
    letter-spacing: var(--track-xs);
    transition: background-color 0.2s ease, color 0.2s ease;

    &:hover {
      background: var(--ink);
      color: var(--paper);
    }
  }
  .chip--solid {
    background: var(--ink);
    color: var(--paper);

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

  .principle {
    display: grid;
    grid-template-columns: 60px 1fr;
    gap: 24px;
    align-items: baseline;
    padding: 22px 0;
    border-bottom: 1px solid var(--rule-soft);

    &:last-child {
      border-bottom: none;
    }
  }

  .principle__title {
    margin-bottom: 6px;
    font-size: 24px;
    letter-spacing: -0.01em;
    line-height: 1.2;
  }

  .principle__text {
    color: var(--muted);
    font-size: 14px;
    line-height: 1.55;
    text-wrap: pretty;
  }

  /* ========== terminal ========== */
  .terminal {
    max-width: 880px;
    margin: 0 auto;
    overflow: hidden;
    background: var(--ink);
    color: var(--term-out);
    border: 1px solid var(--ink);
    border-radius: 4px;
    box-shadow: 12px 12px 0 0 var(--ink);
    font-family: var(--mono);
    font-size: 14px;
    line-height: 1.7;
  }

  .terminal__bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--term-bar);
    border-bottom: 1px solid var(--term-border);
  }

  .terminal__dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: var(--term-dot);
  }

  .terminal__title {
    margin-left: 12px;
    color: var(--term-title);
    font-size: var(--fs-mono-xs);
    letter-spacing: var(--track-sm);
  }

  /* A <pre>, so the spacing in index.html is the spacing on screen. */
  .terminal__body {
    padding: 24px 20px 28px;
    white-space: pre-wrap;

    @media (width > 900px) {
      padding: 28px 32px 36px;
    }
  }

  .terminal__prompt { color: var(--accent); }
  .terminal__cmd { color: var(--paper); }
  .terminal__arg { color: var(--term-arg); }

  .terminal__cursor {
    display: inline-block;
    width: 8px;
    height: 16px;
    margin-left: 2px;
    vertical-align: -3px;
    background: var(--accent);
    animation: blink 1s steps(2) infinite;
  }

  @keyframes blink {
    50% { opacity: 0; }
  }

  /* ========== contact ========== */
  .contact {
    margin-top: 80px;
    padding: 140px 0 60px;
    background: var(--ink);
    color: var(--paper);
  }

  .contact__label {
    margin-bottom: 28px;
    color: var(--on-ink-muted);
  }

  .contact__title {
    margin-bottom: 56px;
    font-size: clamp(72px, 11vw, 200px);
    line-height: 0.9;
    letter-spacing: -0.04em;
  }

  .contact__cta {
    display: inline-flex;
    align-items: center;
    gap: 16px;
    margin-top: 12px;
    padding: 22px 28px;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--mono);
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: var(--track-md);
    transition: transform 0.2s ease, box-shadow 0.2s ease;

    &:hover {
      transform: translate(-3px, -3px);
      box-shadow: 6px 6px 0 var(--accent);
    }
  }

  .contact__arrow {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--ink);
    color: var(--paper);
    font-size: 14px;
  }

  .contact__links {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 28px;
    margin-top: 48px;
    padding-top: 36px;
    border-top: 1px solid var(--on-ink-rule);

    @media (width > 900px) {
      grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr);
      gap: 48px;
    }

    a {
      display: block;
      padding: 6px 0;
      font-family: var(--sans);
      font-size: 18px;
      letter-spacing: -0.01em;
      overflow-wrap: anywhere;

      @media (width > 900px) {
        font-size: 22px;
      }
    }
    a:hover {
      color: var(--accent);
    }
  }

  .contact__heading {
    margin-bottom: 18px;
    color: var(--on-ink-muted);
    font-size: var(--fs-mono-xs);
  }

  /* ========== footer ========== */
  .footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 12px 24px;
    margin-top: 80px;
    padding-top: 28px;
    border-top: 1px solid var(--on-ink-rule);
    color: var(--on-ink-muted);
    font-size: var(--fs-mono-xs);
    letter-spacing: var(--track-md);
  }
}
