/**
 * Base CSS layer with foundational resets and utility rules
 * Sets up box-sizing, removes default margins, and defines core typography styles
 */
@layer base {
  /*
   * Enforces consistent box sizing - widths include padding and borders
   * Ensures predictable layout calculations across all browsers
   */
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  /*
   * Removes default margin from all elements except dialog elements
   * Provides consistent base for custom spacing
   */
  *:not(dialog) {
    margin: 0;
  }

  /*
   * Enables smooth size interpolation for HTML element in browsers supporting it
   * Respects user's prefers-reduced-motion preference for accessibility
   */
  @media (prefers-reduced-motion: no-preference) {
    html {
      interpolate-size: allow-keywords;
    }
  }

  /*
   * Sets base typography - inherits line-height and enables smooth font rendering
   * Antialiased font improves readability on all devices
   */
  body {
    line-height: var(--base-line-height);
    -webkit-font-smoothing: antialiased;
  }

  /*
   * Ensures all media elements are responsive and block-level
   * Prevents horizontal overflow and maintains aspect ratios
   */
  img,
  picture,
  video,
  canvas,
  svg {
    display: block;
    max-width: 100%;
  }

  /*
   * Makes form elements inherit font settings from parent
   * Ensures consistent styling across forms
   */
  input,
  button,
  textarea,
  select {
    font: inherit;
  }

  /*
   * Disables pointer events on elements marked as aria-disabled
   * Prevents interaction with disabled links and buttons
   */
  a[aria-disabled="true"] {
    pointer-events: none;
  }
}
@layer layout {
  .stack {
    /* Stacks elements vertically with spacing between them */
    display: flex;
    flex-direction: column;
    justify-content: flex-start;

    & > * {
      margin-block: 0;
    }
    &:not(.marginless) > * + * {
      margin-block-start: var(--space, 1.5rem);
    }
  }
  .center-box {
    /* Centers a box horizontally with max-width */
    box-sizing: content-box;
    margin-inline: auto;
    max-inline-size: var(--measure);
  }
  .center-content {
    /* Centers content vertically */
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  .cluster {
    /* Wraps flex items with horizontal gap */
    display: flex;
    flex-wrap: wrap;
    gap: var(--space, 1rem);
  }
  .box {
    /* Themed box with light background */
    color: var(--color-dark);
    background-color: var(--color-light);
    padding: var(--s1);
    * {
      color: inherit;
    }
  }
  .with-sidebar {
    /* Container with sidebar layout on one side */
    display: flex;
    flex-wrap: wrap;
    gap: var(--s1);
  }
  .sidebar-start > :first-child {
    /* Sidebar on start side, main content second */
    flex-grow: 1;
  }
  .sidebar-start > :last-child {
    /* Sidebar on start side, main content last */
    flex-basis: 0;
    flex-grow: 999;
    min-inline-size: 50%;
  }
  .sidebar-end > :last-child {
    /* Sidebar on end side, main content last */
    flex-grow: 1;
  }
  .sidebar-end > :first-child {
    /* Sidebar on end side, main content first */
    flex-basis: 0;
    flex-grow: 999;
    min-inline-size: 50%;
  }
  .switcher {
    /* Flexible switcher with 3-column base */
    display: flex;
    flex-wrap: wrap;
    gap: var(--s1);
    & > * {
      flex-grow: 1;
      flex-basis: calc(((var(--measure) / 3) - 100%) * 999);
    }
  }
  /* Switcher: 2 items show side by side */
  .switcher-2 > :nth-last-child(n + 3),
  .switcher-2 > :nth-last-child(n + 3) ~ * {
    flex-basis: 100%;
  }
  /* Switcher: 3 items show side by side */
  .switcher-3 > :nth-last-child(n + 4),
  .switcher-3 > :nth-last-child(n + 4) ~ * {
    flex-basis: 100%;
  }
  /* Switcher: 4 items, small version */
  .switcher-4 > :nth-last-child(n + 5),
  .switcher-4 > :nth-last-child(n + 5) ~ *,
  .switcher-sm > :nth-last-child(n + 5),
  .switcher-sm > :nth-last-child(n + 5) ~ * {
    flex-basis: 100%;
  }
  /* Switcher: 5 items */
  .switcher-5 > :nth-last-child(n + 6),
  .switcher-5 > :nth-last-child(n + 6) ~ * {
    flex-basis: 100%;
  }
  /* Switcher: 6 items, medium version */
  .switcher-6 > :nth-last-child(n + 7),
  .switcher-6 > :nth-last-child(n + 7) ~ *,
  .switcher-md > :nth-last-child(n + 7),
  .switcher-md > :nth-last-child(n + 7) ~ * {
    flex-basis: 100%;
  }
  /* Switcher: 7 items */
  .switcher-7 > :nth-last-child(n + 8),
  .switcher-7 > :nth-last-child(n + 8) ~ * {
    flex-basis: 100%;
  }
  /* Switcher: 8 items */
  .switcher-8 > :nth-last-child(n + 9),
  .switcher-8 > :nth-last-child(n + 9) ~ * {
    flex-basis: 100%;
  }
  /* Switcher: 9 items, large version */
  .switcher-9 > :nth-last-child(n + 10),
  .switcher-9 > :nth-last-child(n + 10) ~ *,
  .switcher-lg > :nth-last-child(n + 10),
  .switcher-lg > :nth-last-child(n + 10) ~ * {
    flex-basis: 100%;
  }
  /* Switcher: 10 items */
  .switcher-10 > :nth-last-child(n + 11),
  .switcher-10 > :nth-last-child(n + 11) ~ * {
    flex-basis: 100%;
  }
  /* Switcher: 11 items */
  .switcher-11 > :nth-last-child(n + 12),
  .switcher-11 > :nth-last-child(n + 12) ~ * {
    flex-basis: 100%;
  }
  /* Switcher: 12 items, extra large version */
  .switcher-12 > :nth-last-child(n + 13),
  .switcher-12 > :nth-last-child(n + 13) ~ *,
  .switcher-xl > :nth-last-child(n + 13),
  .switcher-xl > :nth-last-child(n + 13) ~ * {
    flex-basis: 100%;
  }
  .grid {
    /* Responsive grid with auto-fit columns */
    display: grid;
    grid-gap: var(--space, 1rem);
  }
  @supports (width: min(250px, 100%)) {
    .grid {
      grid-template-columns: repeat(auto-fit, minmax(min(250px, 100%), 1fr));
    }
  }
  .cover {
    /* Full viewport height cover layout */
    display: flex;
    flex-direction: column;
    min-block-size: 100vh;
    padding: var(--space, 1rem);
    & > * {
      margin-block: var(--space, 1rem);
    }
    & > :first-child:not(.cover-content) {
      margin-block-start: 0;
    }
    & > :last-child:not(.cover-content) {
      margin-inline-end: 0;
    }
    & > .cover-content {
      margin-block: auto;
    }
  }
  .frame {
    /* Flexible aspect ratio container for media */
    aspect-ratio: var(--n) / var(--d);
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    & > img,
    & > video {
      inline-size: 100%;
      block-size: 100%;
      object-fit: cover;
    }
  }
  .reel {
    /* Horizontal scrolling media reel */
    display: flex;
    block-size: auto;
    overflow-x: auto;
    overflow-y: hidden;
    & > * {
      flex: 0 0 auto;
    }
    & > img {
      block-size: 100%;
      flex-basis: auto;
      width: auto;
    }
    & > * + * {
      margin-inline-start: var(--space, 1rem);
    }
  }
  .real::-webkit-scrollbar-track {
    /* Custom scrollbar styling */
    background-color: var(--color-scroll-track);
  }
  .reel::-webkit-scrollbar-thumb {
    /* Custom scrollbar thumb with gradient */
    background-color: var(--color-scroll-thumb);
    background-image: linear-gradient(
      var(--color-scroll-track) 0,
      var(--color-scroll-track) 0.25rem,
      var(--color-scroll-thumb) 0.25rem,
      var(--color-scroll-thumb) 0.75rem,
      var(--color-scroll-track) 0.75rem
    );
  }
  .reel.overflowing {
    /* Add padding when reel is overflowing */
    padding-block-end: var(--space, 1rem);
  }
  .imposter {
    /* Centered absolute position */
    position: absolute;
    inset-block-start: 50%;
    inset-inline-start: 50%;
    transform: translate(-50%, -50%);
  }
  .imposter.contain {
    /* Containable centered element with max size */
    --margin: 0px;
    overflow: auto;
    max-inline-size: calc(100% - (var(--margin, 0px) * 2));
    max-block-size: calc(100% - (var(--margin, 0px) * 2));
  }
  .icon {
    /* Base icon size using em/cap units */
    width: 0.75em;
    width: 1cap;
    height: 0.75em;
    height: 1cap;
  }
  .with-icon {
    /* Inline container for icon and text */
    display: inline-flex;
    align-items: baseline;
  }
  .with-icon .icon {
    /* Adds spacing to icon when used with with-icon */
    margin-inline-end: var(--space, 1rem);
  }
  .container {
    /* Enables container queries */
    container-name: var(--container-name, layout);
    container-type: inline-size;
  }
  .pos-rel {
    /* Position utilities */
    position: relative;
  }
  .pos-abs {
    /* Position utilities */
    position: absolute;
  }
  .pos-fix {
    /* Position utilities */
    position: fixed;
  }
  .pos-static {
    /* Position utilities */
    position: static;
  }
  .pos-sticky {
    /* Position utilities */
    position: sticky;
  }
  .min-w-sm {
    /* Min-width size utilities */
    min-width: calc(var(--measure) / 12);
  }
  .min-w-md {
    /* Min-width size utilities */
    min-width: calc(var(--measure) / 6);
  }
  .min-w-lg {
    /* Min-width size utilities */
    min-width: calc(var(--measure) / 2);
  }
  .min-w-xl {
    /* Min-width size utilities */
    min-width: calc(var(--measure));
  }
  .max-w-sm {
    /* Max-width size utilities */
    max-width: calc(var(--measure) / 12);
  }
  .max-w-md {
    /* Max-width size utilities */
    max-width: calc(var(--measure) / 6);
  }
  .max-w-lg {
    /* Max-width size utilities */
    max-width: calc(var(--measure) / 2);
  }
  .max-w-xl {
    /* Max-width size utilities */
    max-width: calc(var(--measure));
  }
  .square {
    /* Square aspect ratio (1:1) */
    aspect-ratio: 1 / 1;
  }
  .w-rectangle {
    /* Width-based aspect ratio container */
    aspect-ratio: var(--n) / var(--d);
  }
  .h-rectangle {
    /* Height-based aspect ratio container */
    aspect-ratio: var(--d) / var(--n);
  }
  .gutters {
    /* Container with horizontal gutters */
    padding-inline-start: var(--measure-gutter);
    padding-inline-end: var(--measure-gutter);
  }
  .gutter-l {
    /* Left gutter */
    padding-inline-start: var(--measure-gutter);
  }
  .gutter-r {
    /* Right gutter */
    padding-inline-end: var(--measure-gutter);
  }
  .justify\:start {
    /* Flexbox justify utilities */
    justify-content: flex-start;
  }
  .justify\:end {
    /* Flexbox justify utilities */
    justify-content: flex-start;
  }
  .justify\:space-between {
    /* Flexbox justify utilities */
    justify-content: space-between;
  }
  .justify\:space-around {
    /* Flexbox justify utilities */
    justify-content: space-around;
  }
  .justify\:center {
    /* Flexbox justify utilities */
    justify-content: center;
  }
  .align\:center {
    /* Flexbox align utilities */
    align-items: center;
  }
  .align\:baseline {
    /* Flexbox align utilities */
    align-items: baseline;
  }
  .align\:start {
    /* Flexbox align utilities */
    align-items: flex-start;
  }
  .align\:end {
    /* Flexbox align utilities */
    align-items: flex-end;
  }
  .align\:stretch {
    /* Flexbox align utilities */
    align-items: stretch;
  }
}
@layer theme {
  :root {
    /* Base measure for content width */
    --measure: 90ch;
    /* Gutter between measure edges */
    --measure-gutter: 1ch;
    /* Base line height for typography */
    --base-line-height: 1.5;
    /* Base spacing unit */
    --space: 1rem;
    /* Aspect ratio width for media */
    --n: 16;
    /* Aspect ratio height for media */
    --d: 9;
    /* Base layout unit ratio */
    --ratio: 1.5;
    /* Name for container queries */
    --container-name: theme;
    --s-5: calc(var(--s-4) / var(--ratio));
    --s-4: calc(var(--s-3) / var(--ratio));
    --s-3: calc(var(--s-2) / var(--ratio));
    --s-2: calc(var(--s-1) / var(--ratio));
    --s-1: calc(var(--s0) / var(--ratio));
    --s0: 1rem;
    --s1: calc(var(--s0) * var(--ratio));
    --s2: calc(var(--s1) * var(--ratio));
    --s3: calc(var(--s2) * var(--ratio));
    --s4: calc(var(--s3) * var(--ratio));
    --s5: calc(var(--s4) * var(--ratio));
    /* Light background color */
    --color-light: #eee;
    /* Dark text color */
    --color-dark: black;
    /* Muted text color */
    --color-muted: #5a848c;
    /* Border color */
    --color-border: #dfe1d6;
    /* Scrollbar track color */
    --color-scroll-track: #000;
    /* Scrollbar thumb color */
    --color-scroll-thumb: #fff;
    /* Header text color */
    --color-header: #247884;
    --transition: .2s cubic-bezier(.4, 0, .2, 1);
    --transition-fast: .12s cubic-bezier(.4, 0, .2, 1);
  }

  body {
    /* Serif font for main text */
    font-family: "Baskerville", "Noto Serif", "DejaVu Serif", serif;
    background: linear-gradient(135deg, #0e3641 6%, #002a36 77%);
    background:
      radial-gradient(at 40% 20%, #0e3641 0px, transparent 50%),
      radial-gradient(at 80% 0%, #002a36 0px, transparent 50%),
      radial-gradient(at 0% 50%, #6e4573 0px, transparent 50%),
      radial-gradient(at 80% 50%, #267788 0px, transparent 50%),
      radial-gradient(at 0% 100%, #002a36 0px, transparent 50%),
      radial-gradient(at 20% 40%, #0e3641 0px, transparent 50%);
    background-color: #1a1a2e;
    background-attachment: fixed;
  }

  p {
    text-indent: 0.66rem;
  }

  body > header {
    /* Header with margin */
    margin-block-start: var(--space, 1rem);
    margin-block-end: -1rem;
    h1 {
      color: #ccc2c0;
      .icon {
        color: #8b878d;
        margin-inline-start: calc(var(--space, 1rem) / 2);
        display: inline-flex;
      }
      & > a {
        color: #ccc2c0;
        text-decoration: none;
      }
      .fw-thick {
        color: #878e91;
      }
    }
  }
  header + main::before {
    /* Horizontal divider before main content */
    content: " ";
    display: block;
    border-block-start: 1px solid var(--color-border);
    margin-block-end: var(--space, 1rem);
    margin-inline: var(--space, 1rem);
  }

  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    /* Header text colors and fonts */
    color: var(--color-header, #000);
    font-family: "Open Sans", "Helvetica", "DejaVu Sans", sans-serif;
    /* Light font weight and optimal text rendering */
    font-style: normal;
    font-weight: 400;
    text-rendering: optimizeLegibility;
  }

  body > footer {
    /* Footer with max-width and border */
    max-width: 90ch;
    margin-block-end: 1rem;
    margin-inline-start: 1rem;
    margin-inline-end: 1rem;
    text-align: right;
    border-block-start: 1px solid var(--color-light);
  }

  header nav ul {
    /* Navigation list styling */
    list-style: none;
    margin-inline-end: var(--space, 1rem);
    font-size: small;
    & li > a {
      color: #8b878d;
      font-family: "Baskerville", "Noto Serif", "DejaVu Serif", serif;
      text-decoration: none;
      &:hover {
        color: #247884;
        text-decoration: underline;
      }
    }
  }

  .box {
    /* Themed box with gradient */
    background-color: #ffffff;
    /* background: linear-gradient(135deg, #f1f3e8 6%, #eeeeee 77%); */
    color: #333;
  }
  .muted {
    /* Muted text color utility */
    color: var(--color-muted);
  }
  .fw-thin {
    font-weight: lighter !important;
  }
  .fw-normal {
    font-weight: normal !important;
  }
  .fw-thick {
    font-weight: bold !important;
  }
}
@layer base, layout, theme;

body > footer .copyright {
  /* Footer copyright text */
  font-size: small;
  text-align: right;
  color: var(--color-muted);
}

.about-me {
  /* About section with right margin */
  margin-inline-end: var(--space, 1rem);
  &.box {
    /* Themed box with accent border */
    border-inline-start: var(--space, 1rem) solid var(--color-border);
    border-block-end: 1px solid var(--color-border);
    border-radius: calc(var(--space, 1rem) / 2) 0 0 calc(var(--space, 1rem) / 2);
  }
}

.articles {
  /* Articles section with left margin */
  margin-inline-start: var(--space, 1rem);
  &::before {
    /* Horizontal divider before article list */
    content: " ";
    display: block;
    border-block-start: 1px solid var(--color-border);
    margin-block-end: var(--space, 1rem);
    margin-inline-end: var(--space, 1rem);
  }
  & > ul {
    list-style: none;
    padding: 0;
  }
}

.article-summary {
  /* Individual article summary box */
  &.box {
    /* Themed article summary */
    color: #444;
    border-block-start: 1px solid var(--color-border);
    border-inline-end: var(--space, 1rem) solid var(--color-border);
    border-radius: 0 calc(var(--space, 1rem) / 2) calc(var(--space, 1rem) / 2) 0;
  }
  & .article-meta {
    /* Article metadata */
    font-size: small;
    color: var(--color-muted);
  }
  & header + section {
    /* Article body */
    font-size: small;
  }
  & > footer {
    text-align: right;
    font-size: small;
    & > a {
      /* Article footer link */
      color: var(--color-muted);
    }
  }
}

.resumè {
  & .box:nth-child(1) {
    /* Themed box with accent border */
    margin-inline-end: var(--space, 1rem);
    border-inline-start: var(--space, 1rem) solid var(--color-border);
    border-block-end: 1px solid var(--color-border);
    border-radius: calc(var(--space, 1rem) / 2) 0 0 calc(var(--space, 1rem) / 2);
  }
  & .box:nth-child(1n + 2) {
    margin-inline-start: var(--space, 1rem);
    border-block-start: 1px solid var(--color-border);
    border-inline-end: var(--space, 1rem) solid var(--color-border);
    border-radius: 0 calc(var(--space, 1rem) / 2) calc(var(--space, 1rem) / 2) 0;
  }
  .technical-skills > dl {
    /* Technical skills list styling */
    & dd ul {
      /* Skills tags container */
      list-style: none;
      display: flex;
      flex-wrap: wrap;
      gap: calc(var(--space, 1rem) / 2);
      li:has(+ li)::after {
        content: ", ";
      }
    }
    & dt {
      /* Skill name */
      font-weight: bolder;
    }
  }
  .experience > ul {
    /* Experience list */
    list-style: none;
    padding-inline-start: 0;
    & > li {
      padding-bottom: 1rem;
      border-bottom: 1px solid #fefefe;
    }
    .grid > h4 + span {
      color: var(--color-muted);
      font-size: 0.9rem;
    }
    .grid .cluster {
      justify-content: space-between;
      span {
        padding-top: 0.1em;
      }
    }
    .grid + p {
      padding-top: 0.5rem;
    }
    p,
    p + ul > li {
      font-size: 0.95rem;
    }
  }
}

.article {
  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    &:not(:first-child) {
      margin-block-start: 1rem;
    }
  }
}

.no-label {
  label:has(+ input[placeholder], + textarea[placeholder]) {
    display: none;
  }
}

label {
  color: var(--color-muted);
  font-size: small;
  font-family: "Open Sans", "Helvetica", "DejaVu Sans", sans-serif;
}

input:focus-visible,
textarea:focus-visible,
button:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 2px solid #0086ac;
}
input:user-valid,
textarea:user-valid,
select:user-valid {
  outline: 2px solid green;
}
input:user-invalid,
textarea:user-invalid,
select:user-invalid {
  outline: 2px solid red;
}
form:has(*:invalid) button[type="submit"] {
  pointer-events: none;
  color: #aaa;
  border-color: #eee;
}

input,
textarea {
  padding: var(--s-2);
  width: 100%;
  border-color: var(--color-border);
  border-style: solid;
  border-radius: calc(var(--space) / 4);
  font-family: "Open Sans", "Helvetica", "DejaVu Sans", sans-serif;
}

hr {
  border-color: var(--color-border);
  border-style: solid;
}
form fieldset {
  border: none;
}
form button {
  cursor: pointer;
  padding: var(--s-2);
  color: var(--color-muted);
  border-color: var(--color-muted);
  border-style: solid;
  border-radius: var(--space);
  font-family: "Open Sans", "Helvetica", "DejaVu Sans", sans-serif;
  font-size: small;
  font-weight: bold;
  background-color: color-mix(in srgb, var(--color-muted), transparent 90%);
  &:hover {
    background-color: color-mix(in srgb, var(--color-muted), transparent 80%);
    border-color: color-mix(in srgb, var(--color-muted), var(--color-dark) 10%);
    color: color-mix(in srgb, var(--color-muted), var(--color-dark) 10%);
  }
}
