/* Neo-Brutalism edition. Tokens and rules from assets/downloads/neo-brutalism-ui.md.
   Thick black borders, hard shadows with zero blur, three flat colors, dominant type.
   Breakpoints: 40rem (640px) = two-up lists; 64rem (1024px) = the whole page on one screen, a 12-column bento. */

@layer tokens, reset, base, layout, components, utilities;

@layer tokens {
  :root {
    /* Raw palette */
    --black: #000000;
    --paper: #fffdf5;
    --white: #ffffff;

    /* Color roles: 3 bold colors + black + a light ground */
    --color-bg: var(--paper);
    --color-surface: var(--white);
    --color-text: var(--black);
    --color-ink: var(--black);         /* borders, shadows, focus */
    --color-primary: #ff90e8;          /* pink, primary action: black text 10.4:1 */
    --color-secondary: #ffc900;        /* yellow, highlight: black text 13.6:1 */
    --color-tertiary: #90a8ed;         /* blue, information: black text 9.0:1 */
    --color-on-color: var(--black);    /* text on any bold fill is always black */
    --color-disabled: #d9d9d9;

    --font-display: "Archivo Black", "Space Grotesk", "Arial Black", sans-serif;
    --font-body: "Inter", "Roboto", system-ui, sans-serif;
    --font-mono: "Space Mono", "JetBrains Mono", ui-monospace, monospace;

    /* Type scale: headlines about 2x body or more */
    --step--1: 0.875rem;
    --step-0: 1rem;
    --step-1: 1.25rem;
    --step-2: 2rem;
    --step-3: 3rem;
    --step-4: 4.5rem;
    --leading-body: 1.55;
    --leading-tight: 1;

    /* Spacing: generous, to balance the heavy borders. In rem, so it scales with the type on desktop */
    --space-0: 0.25rem;                /* 4px, inside small controls only */
    --space-1: 0.5rem;                 /* 8px */
    --space-2: 0.75rem;                /* 12px */
    --space-3: 1rem;                   /* 16px */
    --space-4: 1.5rem;                 /* 24px */
    --space-5: 2rem;                   /* 32px */

    --border-width: 3px;
    --border-width-small: 2px;
    --shadow-offset: 4px;
    --radius: 0;                       /* one value everywhere */

    --gutter: var(--space-3);
    --target: 44px;                    /* minimum touch target */
    --duration: 100ms;                 /* fast and mechanical, no bounce */
  }

  /* Lines and shadows. A variable resolves where it is declared, so these are declared again
     on every element that changes --color-ink */
  :root,
  [data-theme="dark"],
  .tile.on-accent,
  .window.on-accent > * {
    --border: var(--border-width) solid var(--color-ink);
    --border-small: var(--border-width-small) solid var(--color-ink);
    --shadow: var(--shadow-offset) var(--shadow-offset) 0 0 var(--color-ink);
    --shadow-lg: 8px 8px 0 0 var(--color-ink);
  }

  /* Dark: the ground goes dark, lines and type turn to paper. Bold fills keep black text */
  [data-theme="dark"] {
    --color-bg: #121212;
    --color-surface: #1f1f1f;
    --color-text: var(--paper);        /* 17.9:1 on the dark ground */
    --color-ink: var(--paper);
  }

  /* Any area with a bold fill: black text, white surfaces, in both themes */
  .on-accent {
    --color-text: var(--black);
    --color-surface: var(--white);
    color: var(--color-text); /* children inherit the computed color, not the variable */
  }

  /* Colored tiles are light islands: black lines too. A colored window keeps the theme lines
     on its own edge, so its border and shadow stay visible on the dark ground; its content gets black lines */
  .tile.on-accent,
  .window.on-accent > * {
    --color-ink: var(--black);
  }
}

@layer reset {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  body,
  h1,
  h2,
  h3,
  p,
  ul,
  dl,
  dd,
  figure {
    margin: 0;
  }

  ul {
    padding: 0;
    list-style: none;
  }
}

@layer base {
  html {
    color-scheme: light;
  }

  [data-theme="dark"] {
    color-scheme: dark;
  }

  body {
    background: var(--color-bg);
    color: var(--color-text);
    font: 400 var(--step-0) / var(--leading-body) var(--font-body);
    -webkit-text-size-adjust: 100%;
  }

  a {
    color: inherit;
    text-decoration-thickness: 2px;
    text-underline-offset: 3px;
  }

  /* Inline links: a clear fill change, not a 1px nudge */
  a:hover {
    background: var(--color-secondary);
    color: var(--color-on-color);
  }

  /* Focus: an outline set apart from the normal border by its offset */
  :focus-visible {
    outline: 3px solid var(--color-ink);
    outline-offset: 4px;
  }
}

@layer layout {
  /* Mobile: one column of tiles */
  .board {
    display: grid;
    gap: var(--space-4);
    padding: var(--space-4) var(--gutter);
  }

  /* Desktop: header, marquee, board and footer fill the screen. The board uses the full width */
  @media (min-width: 64rem) {
    :root {
      --gutter: var(--space-5);
    }

    /* The whole page scales with the screen height: 16px at 1080px tall, 13px (the floor) at 900px.
       Below 900px the page scrolls a little instead of going smaller */
    html {
      font-size: clamp(0.8125rem, calc(1.667dvh - 0.125rem), 1rem);
    }

    body {
      display: flex;
      flex-direction: column;
      min-block-size: 100dvh;
    }

    .board {
      flex: 1;
      grid-template-columns: repeat(12, minmax(0, 1fr));
      grid-template-rows: auto auto; /* auto rows stretch: spare height is shared, no empty band */
      gap: var(--space-3);
      padding-block: var(--space-2);
    }

    /* Two rows. Top: who, what, where. Bottom: what I made, how this page is made */
    .tile--hero     { grid-area: 1 / 1 / 2 / span 5; }
    .tile--profile  { grid-area: 1 / 6 / 2 / span 3; }
    .tile--work     { grid-area: 1 / 9 / 2 / -1; }
    .tile--projects { grid-area: 2 / 1 / 3 / span 8; }
    .tile--system   { grid-area: 2 / 9 / 3 / -1; }
  }
}

@layer components {
  /* --- Skip link --- */
  .skip-link {
    position: absolute;
    inset-block-start: var(--space-1);
    inset-inline-start: var(--space-1);
    z-index: 10;
    padding: var(--space-2) var(--space-3);
    background: var(--color-secondary);
    color: var(--color-on-color);
    border: var(--border);
    font-weight: 700;
    transform: translateY(-200%);
  }

  .skip-link:focus {
    transform: none;
  }

  /* --- Icons: pixel art, so no anti-aliasing --- */
  .icon {
    inline-size: 1em;
    block-size: 1em;
    flex-shrink: 0;
    fill: currentColor;
    shape-rendering: crispEdges;
  }

  /* --- Header: a boxed bar --- */
  .site-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-2) var(--gutter);
    background: var(--color-bg);
    border-block-end: var(--border);
  }


  .wordmark {
    padding: var(--space-1) var(--space-2);
    background: var(--color-secondary);
    color: var(--color-on-color);
    border: var(--border);
    box-shadow: var(--shadow);
    font: var(--step-1) / 1 var(--font-display);
    text-decoration: none;
    text-transform: uppercase;
    transition: transform var(--duration) ease-out;
  }

  .wordmark:hover {
    background: var(--color-primary);
  }

  .wordmark:active {
    transform: translate(var(--shadow-offset), var(--shadow-offset));
    box-shadow: none;
  }

  /* --- Marquee --- */
  /* Mobile: the ticker takes its own row under the wordmark and the theme button */
  .marquee {
    flex: 1 1 100%;
    order: 3;
    min-inline-size: 0;
    overflow: hidden;
    border: var(--border);
    background: var(--color-ink);
    color: var(--color-bg);
    font: 700 var(--step--1) / 1 var(--font-mono);
    text-transform: uppercase;
    white-space: nowrap;
  }

  .marquee__track {
    display: flex;
    inline-size: max-content;
  }

  .marquee__text {
    padding-block: var(--space-1);
  }

  /* Desktop: the ticker runs between the wordmark and the theme button */
  @media (min-width: 64rem) {
    .marquee {
      flex: 1 1 0;
      order: 0;
    }
  }

  /* Four copies: after one copy width the strip looks the same as at the start, so the loop has no jump.
     Three copies always cover the visible strip, even on wide screens */
  @media (prefers-reduced-motion: no-preference) {
    .marquee__track {
      animation: marquee 45s linear infinite;
    }
  }

  @keyframes marquee {
    to {
      transform: translateX(-25%); /* one copy of four: the strip loops on an identical frame */
    }
  }

  /* --- Button --- */
  .btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    min-block-size: var(--target);
    padding: var(--space-3) var(--space-4);
    background: var(--color-primary);
    color: var(--color-on-color);
    border: var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    font: 700 var(--step-0) / 1 var(--font-body);
    text-decoration: none;
    cursor: pointer;
    transition: transform var(--duration) ease-out;
  }

  .btn--secondary {
    background: var(--color-surface);
    color: var(--color-text);
  }

  .btn--small {
    padding: var(--space-1) var(--space-2);
    border-width: var(--border-width-small);
    font-size: var(--step--1);
  }

  .btn:hover {
    background: var(--color-secondary);
    color: var(--color-on-color);
  }

  /* Press: the button moves into its own shadow */
  .btn:active {
    transform: translate(var(--shadow-offset), var(--shadow-offset));
    box-shadow: none;
  }

  .btn:disabled {
    background: var(--color-disabled);
    color: var(--color-on-color);
    border-style: dashed;
    box-shadow: none;
    transform: none;
    cursor: not-allowed;
  }

  .actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
  }

  .note {
    font: 400 var(--step--1) / 1.5 var(--font-mono);
  }

  /* Small monospace heading over a group */
  .label {
    font: 700 var(--step--1) / 1.4 var(--font-mono);
    text-transform: uppercase;
  }

  /* --- Tags: small boxes, monospace caps, a bold fill --- */
  .tags {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
  }

  .tag {
    display: inline-block;
    padding: var(--space-0) var(--space-1);
    background: var(--color-surface);
    color: var(--color-text);
    border: var(--border-small);
    font: 700 var(--step--1) / 1.3 var(--font-mono);
    text-transform: uppercase;
  }

  .tag--pink,
  .tag--yellow,
  .tag--blue {
    color: var(--color-on-color);
  }

  .tag--pink {
    background: var(--color-primary);
  }

  .tag--yellow {
    background: var(--color-secondary);
  }

  .tag--blue {
    background: var(--color-tertiary);
  }

  /* --- Tile: a bento cell. Flat, no shadow: tiles are not clickable --- */
  .tile {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-4);
    background: var(--color-surface);
    border: var(--border);
  }

  .tile-head {
    display: flex;
    align-items: center;
    gap: var(--space-2);
  }

  .tile-head__num {
    padding: var(--space-0) var(--space-1);
    background: var(--color-surface);
    color: var(--color-text);
    border: var(--border);
    font: 700 var(--step-0) / 1.2 var(--font-mono);
  }

  .tile-head__title {
    font: var(--step-2) / var(--leading-tight) var(--font-display);
    text-transform: uppercase;
  }

  /* --- Window: a key card with a retro title bar --- */
  .window {
    display: flex;
    flex-direction: column;
    background: var(--color-surface);
    border: var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
  }

  .window--pink {
    background: var(--color-primary);
  }

  .window--blue {
    background: var(--color-tertiary);
  }

  .window__bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-1) var(--space-3);
    background: var(--color-secondary);
    color: var(--color-on-color);
    border-block-end: var(--border);
    font: 700 var(--step--1) / 1.4 var(--font-mono);
  }

  /* A long file name gets cut, so the bar stays one line */
  .window__title {
    min-inline-size: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .window__bar .tag {
    flex-shrink: 0;
    white-space: nowrap;
  }

  .window__dots {
    display: flex;
    gap: var(--space-0);
  }

  .window__dots span {
    inline-size: 12px;
    block-size: 12px;
    background: var(--white);
    border: var(--border-width-small) solid var(--black);
  }

  /* --- Hero tile --- */
  .tile--hero {
    justify-content: center;
    gap: var(--space-4);
    background: var(--color-secondary);
  }

  .hero__top {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
  }

  /* Sticker: tilted 6°, past the skill's ±3° limit on purpose (site choice). In the flow, no offset */
  .sticker {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-2);
    background: var(--color-primary);
    color: var(--color-on-color);
    border: var(--border);
    font: 700 var(--step--1) / 1 var(--font-mono);
    text-transform: uppercase;
    transform: rotate(6deg);
  }

  .hero__title {
    font: clamp(2.5rem, 11vw, var(--step-4)) / var(--leading-tight) var(--font-display);
    text-transform: uppercase;
  }

  /* The surname sits in a pink block */
  .hero__mark {
    display: inline-block;
    margin-block-start: var(--space-1);
    padding-inline: var(--space-1);
    background: var(--color-primary);
    color: var(--color-on-color);
    border: var(--border);
  }

  .hero__lead {
    max-inline-size: 42ch;
    font-size: var(--step-1);
    line-height: 1.4;
  }

  /* Desktop: the name scales with the tile width. Tighter gaps keep the top row short */
  @media (min-width: 64rem) {
    .tile--hero {
      gap: var(--space-3);
    }

    .hero__title {
      font-size: min(var(--step-4), 5vw);
    }

    .hero__lead {
      font-size: var(--step-0);
    }
  }

  /* --- Profile window --- */
  .readout {
    display: grid;
    gap: var(--space-2);
    padding: var(--space-4);
    font: 400 var(--step--1) / 1.5 var(--font-mono);
  }

  /* Label beside the tags when the window is wide, above them when it is narrow */
  .readout__row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-2);
  }

  .readout dt {
    flex: 0 0 11ch;
  }

  .readout dd {
    flex: 1 1 14rem;
  }

  .readout dt {
    font-weight: 700;
    text-transform: uppercase;
  }

  /* --- Projects tile: four windows in a row on desktop --- */
  .tile--projects {
    background: var(--color-bg);
  }

  .projects {
    display: grid;
    flex: 1;
    gap: var(--space-4);
  }

  .project__body {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-1);
    padding: var(--space-4);
  }

  .project__title {
    font: var(--step-1) / 1.2 var(--font-display);
  }

  /* The link button sits at the card bottom, so buttons line up across the row */
  .project__body .btn {
    margin-block-start: auto;
  }

  @media (min-width: 40rem) {
    .projects {
      grid-template-columns: repeat(2, 1fr);
    }
  }

  @media (min-width: 64rem) {
    .projects {
      grid-template-columns: repeat(4, 1fr);
    }
  }

  /* --- Work tile: full grid borders, bold header row --- */
  .tile--work {
    background: var(--color-tertiary);
  }

  .work__role {
    font: var(--step-1) / 1.2 var(--font-display);
  }

  .work__role a {
    text-decoration-thickness: 3px;
  }

  .table-box {
    overflow-x: auto;
  }

  .table {
    inline-size: 100%;
    border-collapse: collapse;
    background: var(--color-surface);
    border: var(--border);
    font-size: var(--step--1);
  }

  .table__caption {
    padding-block-end: var(--space-1);
    font: 700 var(--step--1) / 1.4 var(--font-mono);
    text-align: start;
    text-transform: uppercase;
  }

  .table th,
  .table td {
    padding: var(--space-1) var(--space-2);
    border: var(--border-small);
    text-align: start;
    vertical-align: top;
  }

  .table thead th {
    background: var(--color-primary);
    color: var(--color-on-color);
    font-family: var(--font-mono);
    text-transform: uppercase;
  }

  .table__num {
    inline-size: 1%;
    font-family: var(--font-mono);
    white-space: nowrap;
  }

  /* --- System tile: pitch, color, live demo --- */
  /* Two columns only when the tile is wide enough for both (tablet). Desktop and phone: one column */
  .system {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
    gap: var(--space-3);
  }

  .system__part {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
  }

  .system__motto {
    font: var(--step-1) / 1.2 var(--font-display);
  }

  .swatches {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(5.5rem, 1fr));
    gap: var(--space-1);
    inline-size: 100%;
  }

  .swatch {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    min-block-size: 4rem;
    padding: var(--space-1);
    color: var(--color-on-color);
    border: var(--border);
  }

  .swatch--pink {
    background: var(--color-primary);
  }

  .swatch--yellow {
    background: var(--color-secondary);
  }

  .swatch--blue {
    background: var(--color-tertiary);
  }

  .swatch--ink {
    background: var(--black);
    color: var(--paper);
  }

  .swatch__name {
    font: var(--step-0) / 1.2 var(--font-display);
  }

  .swatch__ratio {
    font: 400 var(--step--1) / 1.4 var(--font-mono);
  }

  .counter {
    font-weight: 700;
  }

  /* --- Footer: an inverted box --- */
  .site-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-1) var(--space-3);
    padding: var(--space-2) var(--gutter);
    background: var(--color-ink);
    color: var(--color-bg);
  }

  .site-footer__name {
    font: var(--step-0) / 1.2 var(--font-display);
  }

  .site-footer__text {
    font: 400 var(--step--1) / 1.5 var(--font-mono);
  }
}

@layer utilities {
  .visually-hidden {
    position: absolute !important;
    inline-size: 1px !important;
    block-size: 1px !important;
    overflow: hidden !important;
    clip-path: inset(50%) !important;
    white-space: nowrap !important;
  }

  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      transition: none !important;
      animation: none !important;
    }
  }
}
