/* =========================
   TOKENS
========================= */

:root {
  /* Fluid type scale (names --fs-1…--fs-8 are also used by the header nav) */
  --fs-display: clamp(2rem, 1.5rem + 2vw, 2.75rem);
  --fs-1: clamp(1.75rem, 1.4rem + 1.4vw, 2.25rem);
  --fs-2: clamp(1.375rem, 1.2rem + 0.8vw, 1.75rem);
  --fs-3: clamp(1.1875rem, 1.1rem + 0.4vw, 1.375rem);
  --fs-4: clamp(1.0625rem, 1rem + 0.25vw, 1.1875rem);
  --fs-5: 1rem;
  --fs-6: 0.875rem;
  --fs-7: 1rem;
  --fs-8: 0.875rem;
  --fs-9: 0.75rem;

  --lh-tight: 1.12;
  --lh-snug: 1.3;
  --lh-base: 1.6;

  --tracking-tight: -0.015em;

  --measure: 68ch;
}

/* =========================
   HAFFER
========================= */

@font-face {
  font-family: "Haffer";
  src: url("../fonts/HafferMedium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Haffer";
  src: url("../fonts/HafferMediumItalic.woff2") format("woff2");
  font-weight: 500;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: "Haffer";
  src: url("../fonts/HafferXHBold.woff2") format("woff2");
  font-weight: 800;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Haffer";
  src: url("../fonts/HafferXHBoldItalic.woff2") format("woff2");
  font-weight: 800;
  font-style: italic;
  font-display: swap;
}

/* =========================
   SAANS
========================= */

@font-face {
  font-family: "Saans";
  src: url("../fonts/SaansRegular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Saans";
  src: url("../fonts/SaansRegularItalic.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: "Saans";
  src: url("../fonts/SaansMedium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Saans";
  src: url("../fonts/SaansBold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* =========================
   JETBRAINS MONO (self-hosted, OFL)
   Variable weight 100-800, Latin subset from Google Fonts (v24).
   The italic is only downloaded if some text actually uses it.
========================= */

@font-face {
  font-family: "JetBrains Mono";
  src: url("../fonts/JetBrainsMono-Latin.woff2") format("woff2");
  font-weight: 100 800;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "JetBrains Mono";
  src: url("../fonts/JetBrainsMono-Italic-Latin.woff2") format("woff2");
  font-weight: 100 800;
  font-style: italic;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* =========================
   METRIC-MATCHED FALLBACKS
   Arial resized to Saans/Haffer proportions (width via size-adjust,
   vertical metrics via the overrides), so text keeps its place while the
   web fonts load and the swap doesn't move the layout.
   Values measured from the real fonts (canvas measureText vs Arial).
   Used in --font-body / --font-display (styles.css).
========================= */

@font-face {
  font-family: "Saans Fallback";
  src: local("Arial"), local("ArialMT");
  size-adjust: 98%;
  ascent-override: 98%;
  descent-override: 20%;
  line-gap-override: 0%;
}

@font-face {
  font-family: "Haffer Fallback";
  src: local("Arial"), local("ArialMT");
  font-weight: 100 600;
  size-adjust: 99.2%;
  ascent-override: 95%;
  descent-override: 24%;
  line-gap-override: 0%;
}

@font-face {
  font-family: "Haffer Fallback";
  src: local("Arial Bold"), local("Arial-BoldMT");
  font-weight: 700 900;
  size-adjust: 100.7%;
  ascent-override: 95%;
  descent-override: 24%;
  line-gap-override: 0%;
}

/* Courier New has the same 0.6em advance as JetBrains Mono: only the
   vertical metrics are matched (JetBrains: ascent 1020, descent 300 /1000).
   Values from the font tables, not measured in the browser. */
@font-face {
  font-family: "JetBrains Mono Fallback";
  src: local("Courier New"), local("CourierNewPSMT");
  ascent-override: 102%;
  descent-override: 30%;
  line-gap-override: 0%;
}

/* =========================
   BASE
========================= */

body {
  font-family: var(--font-body);
  font-size: var(--fs-7);
  line-height: var(--lh-snug);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

.content-wrapper {
  line-height: var(--lh-base);
}

/* =========================
   HEADINGS
========================= */

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--font-display);
  line-height: var(--lh-tight);
  font-weight: 800;
  letter-spacing: var(--tracking-tight);
  margin-bottom: 0.6em;
  text-wrap: balance;
}

h1 {
  font-size: var(--fs-1);
  > span {
    display: block;
    margin-top: 0.6em;
    font-family: var(--font-body);
    font-size: max(0.4em, 1rem);
    font-weight: 400;
    letter-spacing: 0;
    line-height: var(--lh-snug);
    color: var(--text-muted);
  }
}

h2 {
  font-size: var(--fs-2);
}

h3 {
  font-size: var(--fs-3);
}

h4 {
  font-size: var(--fs-4);
  font-weight: 500;
  letter-spacing: -0.01em;
}

h5 {
  font-family: var(--font-body);
  font-size: var(--fs-5);
  font-weight: 700;
  letter-spacing: 0;
  line-height: var(--lh-snug);
}

h6 {
  font-family: var(--font-body);
  font-size: var(--fs-6);
  font-weight: 500;
  letter-spacing: 0;
  line-height: var(--lh-snug);
  color: var(--text-muted);
}

/* =========================
   TEXT BLOCKS
========================= */

p {
  margin-bottom: 1em;
  text-wrap: pretty;
}

.lead {
  font-family: var(--font-body);
  font-size: var(--fs-4);
  font-weight: 400;
  line-height: 1.5;
  color: var(--text-muted);
  text-wrap: balance;
}

span {
  font: inherit;
}

/* =========================
   INLINE TEXT
========================= */

strong,
b {
  font-weight: 700;
}

em,
i {
  font-style: italic;
}

u {
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

small {
  font-size: 0.8em;
}

sub,
sup {
  font-size: 0.65em;
  line-height: 0;
  position: relative;
}

sub {
  bottom: -0.25em;
}

sup {
  top: -0.45em;
}

q {
  font-style: italic;
  quotes: auto;
  /* Spanish typography: angle quotes first, English ones nested */
  &:lang(es) {
    quotes: "\00AB" "\00BB" "\201C" "\201D";
  }
  &::before {
    content: open-quote;
  }
  &::after {
    content: close-quote;
  }
}

abbr[title] {
  text-decoration: underline dotted;
  text-underline-offset: 0.2em;
  cursor: help;
}

dfn {
  font-weight: 500;
  font-style: italic;
}

time {
  font: inherit;
  font-variant-numeric: tabular-nums;
}

del,
s {
  text-decoration: line-through;
}

ins {
  text-decoration: underline;
}

/* =========================
   LINKS (global base)
========================= */

a {
  font-family: var(--font-mono);
  text-decoration: none;
  letter-spacing: 0.03em;
  font-size: 0.95em;
}

/* zero specificity (:where): a link that sets its own border-radius keeps
   it on focus, so the ring follows the same shape as its hover */
:where(a:focus-visible) {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 0.25em;
}

/* =========================
   CODE (global base)
========================= */

code,
kbd,
samp,
pre {
  font-family: var(--font-mono);
}

/* =========================
   FORM ELEMENTS
========================= */

button,
label,
input,
textarea,
fieldset,
legend {
  font-family: var(--font-body);
}

/* =========================================================
   CONTENT DECORATION
   Scoped to .content-wrapper so header, aside and modal
   keep their own styling.
========================================================= */

.content-wrapper {
  /* ---------- Links ---------- */
  a {
    color: inherit;
    font-family: inherit;
    font-size: inherit;
    letter-spacing: inherit;
    font-weight: 500;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-decoration-color: color-mix(in srgb, var(--accent-color) 35%, transparent);
    text-underline-offset: 0.22em;
    transition: text-decoration-color 0.2s ease;
    &:hover {
      text-decoration-color: var(--accent-color);
    }
  }

  /* inline links in running text: theme color (blue light / green dark) */
  p a {
    color: var(--link-color);
    text-decoration-color: color-mix(in srgb, var(--link-color) 45%, transparent);
    &:hover {
      text-decoration-color: var(--link-color);
    }
  }

  /* ---------- Highlight ---------- */
  mark {
    color: inherit;
    background: color-mix(in srgb, var(--accent-color) 12%, transparent);
    border-radius: 0.25em;
    padding: 0.05em 0.25em;
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
  }

  /* ---------- Edits ---------- */
  del {
    color: var(--text-muted);
    text-decoration-color: color-mix(in srgb, var(--accent-color) 45%, transparent);
  }

  /* ---------- Secondary text ---------- */
  small {
    color: var(--text-muted);
  }

  ins {
    text-decoration-color: color-mix(in srgb, var(--accent-color) 45%, transparent);
    text-underline-offset: 0.2em;
  }

  /* ---------- Citation ---------- */
  cite {
    font-style: italic;
    color: var(--text-muted);
  }

  /* ---------- Inline code / kbd / samp ---------- */
  code,
  kbd,
  samp {
    font-size: 0.86em;
    padding: 0.12em 0.4em;
    border-radius: 0.45em 0.15em 0.45em 0.15em;
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
  }

  code {
    background: var(--surface-color);
    border: 1px solid var(--line-color);
  }

  kbd {
    font-weight: 500;
    background: var(--form-surface);
    border: 1px solid var(--line-color);
    border-bottom-width: 3px;
  }

  samp {
    border: 1px dashed color-mix(in srgb, var(--accent-color) 30%, transparent);
  }

  /* ---------- Blockquote ---------- */
  blockquote {
    margin-block: 1.5rem;
    padding: 0.25em 0 0.25em 1.25rem;
    border-left: 2px solid color-mix(in srgb, var(--accent-color) 35%, transparent);
    font-family: var(--font-display);
    font-size: var(--fs-4);
    font-style: italic;
    font-weight: 500;
    line-height: var(--lh-snug);
    text-wrap: balance;
    p {
      margin-bottom: 0.5rem;
      text-wrap: inherit;
    }
    cite {
      display: block;
      font-family: var(--font-body);
      font-size: var(--fs-8);
      font-weight: 400;
      &::before {
        content: "\2014\00a0";
      }
    }
  }

  /* ---------- Lists ---------- */
  ul,
  ol {
    padding-left: 1.4em;
    margin-bottom: 1em;
  }

  li {
    margin-bottom: 0.35em;
    padding-left: 0.3em;
  }

  ul > li::marker,
  ol > li::marker {
    color: var(--text-muted);
  }

  ol > li::marker {
    font-variant-numeric: tabular-nums;
  }

  /* nested lists: tight to their parent item */
  li > ul,
  li > ol {
    margin-block: 0.35em 0;
  }

  /* ---------- Code block ---------- */
  pre {
    position: relative;
    margin-block: 1rem 1.5rem;
    padding: 2.5rem 1.25rem 1.25rem;
    overflow-x: auto;
    font-size: var(--fs-8);
    line-height: 1.65;
    tab-size: 2;
    background: var(--surface-color);
    border: 1px solid var(--line-color);
    border-radius: var(--radius-card);
    /* no label: no room reserved for it */
    &:not([data-lang]) {
      padding-top: 1.25rem;
    }
    &[data-lang]::before {
      content: attr(data-lang);
      position: absolute;
      top: 0.75rem;
      left: 1.25rem;
      font-size: var(--fs-9);
      color: var(--text-muted);
    }
    code {
      padding: 0;
      font-size: inherit;
      background: none;
      border: none;
      border-radius: 0;
    }
  }

  /* ---------- Divider ---------- */
  hr {
    margin-block: 2.5rem;
    border: none;
    border-top: 1px solid var(--line-color);
  }

  /* ---------- Details ---------- */
  /* Accordion: a card surface with hairline rows (same language as
     .skill-area and the principles list). Add name="…" to the
     <details> of a group to keep only one open at a time. */
  .details-group {
    max-inline-size: var(--measure);
    padding-inline: 1.25rem;
    background: var(--surface-color);
    border: 1px solid var(--line-color);
    border-radius: var(--radius-card);
  }

  .details-group details {
    border-block-end: 1px solid var(--line-color);
    &:last-of-type {
      border-block-end: none;
    }
    /* any content below the summary, not only paragraphs */
    > :not(summary) {
      font-size: var(--fs-6);
      color: var(--text-muted);
    }
    > :last-child:not(summary) {
      margin-bottom: 0;
      padding-bottom: 1rem;
    }
  }

  .details-group summary {
    position: relative;
    padding-block: 1rem;
    padding-right: 2rem;
    font-weight: 500;
    text-wrap: balance;
    cursor: pointer;
    list-style: none;
    &::-webkit-details-marker {
      display: none;
    }
    /* plus / minus marker */
    &::before,
    &::after {
      content: "";
      position: absolute;
      top: 50%;
      right: 0.25rem;
      width: 0.75rem;
      height: 1.5px;
      border-radius: 2px;
      background: var(--text-muted);
      @media (prefers-reduced-motion: no-preference) {
        transition:
          transform 0.25s ease-in-out,
          background-color 0.2s ease;
      }
    }
    &::after {
      transform: rotate(90deg);
    }
    &:hover::before,
    &:hover::after {
      background: var(--accent-color);
    }
    &:focus-visible {
      outline: 2px solid var(--focus-ring);
      outline-offset: 2px;
      border-radius: 0.25em;
    }
  }

  .details-group details[open] summary {
    &::before,
    &::after {
      background: var(--accent-color);
    }
    &::after {
      transform: rotate(0deg);
    }
  }

  /* Smooth open/close where supported (::details-content); elsewhere it
     simply opens instantly. */
  @media (prefers-reduced-motion: no-preference) {
    .details-group {
      interpolate-size: allow-keywords;
    }
    .details-group details::details-content {
      block-size: 0;
      overflow: clip;
      transition:
        block-size 0.3s ease,
        content-visibility 0.3s allow-discrete;
    }
    .details-group details[open]::details-content {
      block-size: auto;
    }
  }
}

/* =========================
   UTILITIES
========================= */

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
