/* =============================================================
   adventuresofceritaqif — stylesheet

   Layers keep specificity predictable as the site grows:
   tokens  → the design variables (change these to retheme)
   base    → element defaults
   layout  → page skeleton (header / main / footer)
   components → reusable pieces (.note, .social, .eyebrow …)
   utilities  → tiny helpers, always last
   ============================================================= */

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

/* ---------- TOKENS ------------------------------------------ */
@layer tokens {
  :root {
    /* Colour — paper, ink, and one fountain-pen blue */
    --color-paper:       #f4f3ee;
    --color-paper-sunk:  #ecebe4;
    --color-ink:         #22242a;
    --color-ink-soft:    #6e7079;
    --color-rule:        #dcdad1;
    --color-accent:      #3e5f76;
    --color-accent-soft: #8aa5b6;

    /* Type — one reading face, one typewriter face for the apparatus,
       one hand for the single margin scribble */
    --font-prose:   "Newsreader", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
    --font-utility: "Courier Prime", "Courier New", ui-monospace, monospace;
    --font-hand:    "Caveat", "Bradley Hand", "Segoe Script", cursive;

    --step--2: 0.75rem;
    --step--1: 0.8125rem;
    --step-0:  clamp(1.0625rem, 1.02rem + 0.22vw, 1.1875rem);
    --step-1:  clamp(1.25rem, 1.18rem + 0.35vw, 1.4rem);
    --step-3:  clamp(2.05rem, 1.35rem + 3.1vw, 3.5rem);

    --leading-tight: 1.15;
    --leading-prose: 1.62;
    --tracking-label: 0.16em;

    /* Space */
    --space-2xs: 0.375rem;
    --space-xs:  0.625rem;
    --space-s:   1rem;
    --space-m:   1.5rem;
    --space-l:   2.5rem;
    --space-xl:  4rem;
    --space-2xl: 6rem;

    /* Layout */
    --content-width: 34rem;
    --margin-width:  9rem;
    --gutter: clamp(1.25rem, 5vw, 4rem);
    --page-width: calc(var(--content-width) + var(--margin-width) + 6rem);

    /* Misc */
    --radius-s: 2px;
    --radius-m: 6px;
    --rule: 1px solid var(--color-rule);
    --ease-out: cubic-bezier(0.2, 0.7, 0.3, 1);
    --dur-fast: 180ms;
    --dur-slow: 1100ms;
  }

  /* Late evening at the same desk. */
  @media (prefers-color-scheme: dark) {
    :root {
      --color-paper:       #17181b;
      --color-paper-sunk:  #1e2024;
      --color-ink:         #e7e3d9;
      --color-ink-soft:    #9a978f;
      --color-rule:        #2d2f34;
      --color-accent:      #93b6cb;
      --color-accent-soft: #6b8a9e;
    }
  }
}

/* ---------- BASE -------------------------------------------- */
@layer base {
  *, *::before, *::after { box-sizing: border-box; }

  html {
    color-scheme: light dark;
    -webkit-text-size-adjust: 100%;
  }

  body {
    margin: 0;
    min-height: 100svh;
    background-color: var(--color-paper);
    color: var(--color-ink);
    font-family: var(--font-prose);
    font-optical-sizing: auto;
    font-size: var(--step-0);
    font-weight: 380;
    line-height: var(--leading-prose);
    -webkit-font-smoothing: antialiased;
  }

  h1, h2, h3, p, ul, figure { margin: 0; }
  ul { list-style: none; padding: 0; }

  a { color: inherit; }

  time { font-variant-numeric: oldstyle-nums; }

  ::selection {
    background: color-mix(in srgb, var(--color-accent) 20%, transparent);
  }

  :focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 3px;
    border-radius: var(--radius-s);
  }
}

/* ---------- LAYOUT ------------------------------------------ */
@layer layout {
  .page {
    display: flex;
    flex-direction: column;
    min-height: 100svh;
    max-width: var(--page-width);
    margin-inline: auto;
    padding-inline: var(--gutter);
  }

  .site-header {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-s) var(--space-m);
    padding-block: var(--space-m) var(--space-s);
    border-bottom: var(--rule);
  }

  .site-main {
    flex: 1;
    display: flex;
    align-items: center;
    padding-block: clamp(var(--space-xl), 12vh, var(--space-2xl));
  }

  .site-footer {
    padding-block: var(--space-l) var(--space-m);
    border-top: var(--rule);
  }
}

/* ---------- COMPONENTS -------------------------------------- */
@layer components {

  /* Site title ------------------------------------------------ */
  .site-title {
    font-size: var(--step-1);
    font-weight: 420;
    letter-spacing: 0.005em;
    text-decoration: none;
    transition: color var(--dur-fast) var(--ease-out);
  }
  .site-title:hover { color: var(--color-accent); }

  /* Navigation ------------------------------------------------ */
  .site-nav__list {
    display: flex;
    gap: var(--space-m);
  }

  .site-nav__link {
    font-family: var(--font-utility);
    font-size: var(--step--1);
    letter-spacing: 0.04em;
    color: var(--color-ink-soft);
    text-decoration: none;
    padding-block: 0.15rem;
    border-bottom: 1px solid transparent;
    transition: color var(--dur-fast) var(--ease-out),
                border-color var(--dur-fast) var(--ease-out);
  }
  .site-nav__link:hover,
  .site-nav__link:focus-visible {
    color: var(--color-ink);
    border-bottom-color: var(--color-accent-soft);
  }

  /* The small aside that answers a click on a section that
     does not exist yet. */
  .nav-note {
    font-family: var(--font-utility);
    font-size: var(--step--2);
    color: var(--color-accent);
    margin-top: var(--space-xs);
    min-height: 1.2em;
    opacity: 0;
    transition: opacity 320ms var(--ease-out);
  }
  .nav-note.is-visible { opacity: 1; }

  /* The note (main content) ----------------------------------- */
  .note {
    display: grid;
    grid-template-columns: var(--margin-width) minmax(0, 1fr);
    width: 100%;
  }

  .note__margin {
    display: flex;
    flex-direction: column;
    gap: var(--space-s);
    padding-top: 0.7rem;
    padding-right: var(--space-m);
    text-align: right;
  }

  .note__body {
    border-left: var(--rule);
    padding-left: clamp(1.5rem, 3.5vw, 2.75rem);
    max-width: var(--content-width);
  }

  .note__meta {
    font-family: var(--font-utility);
    font-size: var(--step--2);
    color: var(--color-ink-soft);
    letter-spacing: 0.02em;
  }

  .note__aside {
    font-family: var(--font-hand);
    font-size: 1.15rem;
    line-height: 1.25;
    color: var(--color-accent-soft);
    transform: rotate(-1.6deg);
    margin-top: auto;
  }

  .note__title {
    font-size: var(--step-3);
    font-weight: 300;
    line-height: var(--leading-tight);
    letter-spacing: -0.015em;
    text-wrap: balance;
  }
  .note__title em {
    font-style: italic;
    font-weight: 300;
  }

  /* The one moving thing on the page: a pen stroke under the
     heading, drawn once on load. */
  .pen {
    display: block;
    width: min(10rem, 45%);
    height: 8px;
    margin-top: var(--space-m);
    overflow: visible;
    color: var(--color-accent);
  }
  .pen path {
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-dasharray: 170;
    stroke-dashoffset: 170;
    animation: draw-stroke var(--dur-slow) 500ms var(--ease-out) forwards;
  }

  .lede {
    margin-top: var(--space-m);
    color: color-mix(in srgb, var(--color-ink) 88%, var(--color-paper));
    text-wrap: pretty;
  }

  .note__closing {
    margin-top: var(--space-l);
    font-size: var(--step-1);
    font-style: italic;
    font-weight: 320;
    color: var(--color-ink-soft);
  }

  /* Small label ----------------------------------------------- */
  .eyebrow {
    font-family: var(--font-utility);
    font-size: var(--step--2);
    letter-spacing: var(--tracking-label);
    text-transform: uppercase;
    color: var(--color-ink-soft);
  }

  /* Social ---------------------------------------------------- */
  .elsewhere { margin-bottom: var(--space-l); }

  .social {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2xs);
    margin-top: var(--space-s);
    margin-left: -0.5rem;
  }

  .social__link {
    display: grid;
    place-items: center;
    width: 2.25rem;
    height: 2.25rem;
    color: var(--color-ink-soft);
    border-radius: var(--radius-m);
    transition: color var(--dur-fast) var(--ease-out),
                transform var(--dur-fast) var(--ease-out);
  }
  .social__link:hover {
    color: var(--color-accent);
    transform: translateY(-2px);
  }

  .icon {
    width: 1.125rem;
    height: 1.125rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.4;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  /* Colophon -------------------------------------------------- */
  .colophon {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: var(--space-2xs) var(--space-m);
  }

  .colophon__line {
    font-family: var(--font-utility);
    font-size: var(--step--2);
    color: var(--color-ink-soft);
  }

  /* Paper grain ------------------------------------------------ */
  .grain {
    position: fixed;
    inset: 0;
    z-index: 100;
    pointer-events: none;
    opacity: 0.05;
    mix-blend-mode: multiply;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  }
  @media (prefers-color-scheme: dark) {
    .grain { opacity: 0.045; mix-blend-mode: screen; }
  }
}

/* ---------- UTILITIES --------------------------------------- */
@layer utilities {

  .sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .skip-link {
    position: absolute;
    left: var(--space-s);
    top: -4rem;
    z-index: 200;
    padding: 0.5rem 0.9rem;
    background: var(--color-paper);
    border: var(--rule);
    border-radius: var(--radius-m);
    font-family: var(--font-utility);
    font-size: var(--step--1);
    text-decoration: none;
  }
  .skip-link:focus { top: var(--space-s); }

  .icon-sprite {
    position: absolute;
    width: 0; height: 0;
    overflow: hidden;
  }

  /* A quiet arrival: each element settles in once, then stops. */
  .reveal {
    opacity: 0;
    transform: translateY(6px);
    animation: settle 800ms var(--delay, 0ms) var(--ease-out) forwards;
  }

  /* Same arrival, but keeps the scribble's tilt. */
  .reveal--hand {
    transform: translateY(6px) rotate(-1.6deg);
    animation-name: settle-hand;
  }
}

/* ---------- MOTION ------------------------------------------ */
@keyframes settle {
  to { opacity: 1; transform: none; }
}

@keyframes settle-hand {
  from { opacity: 0; transform: translateY(6px) rotate(-1.6deg); }
  to   { opacity: 1; transform: rotate(-1.6deg); }
}

@keyframes draw-stroke {
  to { stroke-dashoffset: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.01ms !important;
  }
  .reveal { opacity: 1 !important; transform: none !important; }
  .reveal--hand { transform: rotate(-1.6deg) !important; }
  .pen path { stroke-dashoffset: 0 !important; }
  .social__link:hover { transform: none; }
}

/* ---------- RESPONSIVE --------------------------------------- */
@media (max-width: 46rem) {
  .note {
    grid-template-columns: 1fr;
  }

  .note__margin {
    flex-direction: row;
    align-items: baseline;
    flex-wrap: wrap;
    gap: var(--space-xs) var(--space-s);
    text-align: left;
    padding: 0 0 var(--space-s);
  }

  .note__aside { margin-top: 0; }

  .note__body {
    border-left: 0;
    padding-left: 0;
  }

  .site-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-xs);
  }

  .site-nav__list { margin-left: -0.1rem; }
}
