@layer reset, base, layout, utilities;
/* reset.css */
/* Based on https://piccalil.li/blog/a-more-modern-css-reset/ */
@layer reset {
  /* Box sizing rules */
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  /* Prevent font size inflation */
  html {
    -moz-text-size-adjust: none;
    -webkit-text-size-adjust: none;
    text-size-adjust: none;
  }

  /* Remove default margin in favour of better control in authored CSS */
  body,
  h1,
  h2,
  h3,
  h4,
  p,
  figure,
  blockquote,
  dl,
  dd {
    margin-block-end: 0;
  }

  /* Remove list styles on ul, ol elements with a list role, which suggests default styling will be removed */
  ul[role="list"],
  ol[role="list"] {
    list-style: none;
  }

  /* Set core body defaults */
  body {
    min-height: 100vh;
    line-height: 1.5;
    margin-block-start: 0;
    padding-block: 1rem;
    margin-inline: 0;
  }

  /* Set shorter line heights on headings and interactive elements */
  h1,
  h2,
  h3,
  h4,
  button,
  input,
  label {
    line-height: 1.1;
  }

  /* Balance text wrapping on headings */
  h1,
  h2,
  h3,
  h4 {
    text-wrap: balance;
  }

  /* A elements that don't have a class get default styles */
  a:not([class]) {
    text-decoration-skip-ink: auto;
    color: currentColor;
  }

  /* Make images easier to work with */
  img,
  picture {
    max-width: 100%;
    height: auto;
    display: block;
  }

  /* Inherit fonts for inputs and buttons */
  input,
  button,
  textarea,
  select {
    font-family: inherit;
    font-size: inherit;
  }

  /* Make sure textareas without a rows attribute are not tiny */
  textarea:not([rows]) {
    min-height: 10em;
  }

  /* Anything that has been anchored to should have extra scroll margin */
  :target {
    scroll-margin-block: 5ex;
  }
}


/* base.css */
@layer base {
  :root {
    /* color-scheme: dark light; */
    --paper: light-dark(#f6f3ec, #17181a);
    --ink: light-dark(#201c17, #e7e2d8);
    --ink-muted: light-dark(#6b6255, #9b9186);
    --accent: light-dark(#3c5a44, #86b594);
    --highlight: light-dark(#f5e9a8, #4a431f);
    --rule: light-dark(#d8d0bf, #34322d);

    --serif:
      "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia,
      serif;
    --mono:
      ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
    --page-x: 10.5%;
    --reading-width: 165mm;
    --a4-width: min(850px, calc(100vw - 2rem), calc(70.707dvh - 1.414rem));
    --a4-height: min(
      1202.143px,
      calc(141.429vw - 2.829rem),
      calc(100dvh - 2rem)
    );
    --a4-top: calc((100dvh - var(--a4-height)) / 2);
  }
}


/* layout.css */
@layer layout {
  html {
    scrollbar-gutter: stable;
  }

  body {
    background: var(--paper);
    color: var(--ink);
    font-family: var(--serif);
    font-size: 19px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;

    display: grid;
    grid-template-columns:
      minmax(1rem, 1fr) min(800px, calc(100% - 2rem))
      minmax(1rem, 1fr);
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
      ". nav ."
      ". main ."
      ". footer .";
    align-content: start;

    @media (max-width: 480px) {
      font-size: 17.5px;
    }
  }

  nav {
    grid-area: nav;
  }

  main {
    grid-area: main;
  }

  footer {
    grid-area: footer;
    margin-block-start: clamp(0.75rem, 3vw, 1.5rem);
    font-size: 1rem;
  }

  ::selection {
    background: var(--highlight);
    color: var(--ink);
  }

  h1,
  h2,
  h3,
  h4 {
    font-weight: 600;
  }

  h1 {
    line-height: 1.15;
    letter-spacing: -0.01em;
  }

  h2,
  h3,
  h4 {
    letter-spacing: 0.02em;
  }

  a,
  a:not([class]) {
    color: var(--accent);
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;

    &:hover {
      text-decoration-thickness: 2px;
    }

    &:focus-visible {
      outline: 2px solid var(--accent);
      outline-offset: 2px;
    }
  }

  nav {
    font-family: var(--mono);
    font-size: 0.82rem;
    letter-spacing: 0.02em;
  }

  code,
  kbd,
  samp,
  pre {
    font-family: var(--mono);
    font-size: 0.94em;
  }

  code,
  pre {
    background: var(--code);
  }

  hr {
    border: none;
    border-top: 1px solid var(--rule);
  }

  figcaption,
  small,
  time {
    color: var(--ink-muted);
    font-family: var(--mono);
  }
}


/* utilities.css */
@layer utilities {
  .visually-hidden {
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    height: 1px;
    overflow: hidden;
    position: absolute;
    white-space: nowrap;
    width: 1px;
  }

  .gallery {
    padding-block-start: 1rem;
    --photo-size: 16rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, var(--photo-size));
    justify-content: center;
    gap: 1rem;
    width: 100%;

    .cell {
      height: auto;
      aspect-ratio: 1;
      anchor-scope: --a;
      anchor-name: --a;

      .photo-container {
        /* Relates to the value of img 'sizes' property */
        width: var(--photo-size);
        height: var(--photo-size);
        position: absolute;
        position-anchor: --a;
        inset: anchor(inside);
        background-color: var(--paper);
        place-content: center;
        transition: inset 0.2s ease;
      }
      @media (prefers-reduced-motion: reduce) {
        .photo-container {
          transition: none;
        }
      }

      .photo {
        position: relative;
        height: 100%;
        margin: 0;
        padding: 1rem;
      }

      .photo picture,
      .photo img {
        display: block;
        width: 100%;
        height: 100%;
      }

      .photo img {
        object-fit: contain;
      }

      .photo figcaption {
        position: absolute;
        inset: auto 1rem 0;
        height: 1rem;
        line-height: 1rem;
        font-size: 0.75rem;
        text-align: center;
      }
    }
  }

  .image-full-width {
    /* Relates to the value of img 'sizes' property */
    --spacing: 1rem;
    width: calc(100vw - var(--spacing) * 2);
    margin-left: calc(50% - 50vw + var(--spacing));
    display: flex;
    justify-content: center;
    img {
      width: auto;
      max-height: calc(95svh - var(--spacing) * 2);
    }
  }

  /* #region finger frame */
  .finger-frame {
    margin: auto;
    width: 20rem;
    aspect-ratio: 3 / 2;
    position: relative;

    /* vars */
    --posX: 25%;
    --posY: 35%;
    --duration: 0.75s;
  }

  .finger-frame .finger {
    will-change: transform;
    transform-style: preserve-3D;
    transition: transform 1.2s ease-out;
    height: 55%;
    top: 25%;
    position: absolute;
  }

  .finger-frame .finger#left {
    left: 0;
    transform: translateX(var(--posX)) translateY(calc(var(--posY) * -1));
  }

  .finger-frame .finger#right {
    right: 0;
    transform: translateX(calc(var(--posX) * -1)) translateY(var(--posY))
      rotateX(0deg) rotateY(0deg) rotateZ(180deg);
  }

  .finger-frame:hover .finger#left {
    transition: transform var(--duration) ease-out;
    transform: rotate(-90deg);
  }

  .finger-frame:hover .finger#right {
    transition: transform calc(var(--duration) + 0.1s) ease-out; /* just a liiiittle bit slower... */
    transform: rotateX(180deg) rotateY(0deg) rotateZ(90deg);
  }
  /* #endregion */
}

