/* ============================================================================
   SulyEye - reset, elements, layout primitives
   Everything here is direction-agnostic: no `left`, no `right`, no `margin-left`.
   Logical properties do the mirroring for Kurdish, so there is no second
   stylesheet to keep in sync.
   ========================================================================== */

@layer base {

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

  * {
    margin: 0;
  }

  html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
    scroll-padding-block-start: calc(var(--header-h) + 2rem);
  }

  @media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
  }

  body {
    min-block-size: 100svh;
    background-color: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: var(--step-0);
    line-height: var(--leading-normal);
    font-synthesis-weight: none;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: clip;
    /* Every colour swap crossfades instead of snapping, which is what makes the
       theme toggle feel like a light dimming rather than a page reload. */
    transition: background-color var(--dur-base) var(--ease-out-soft),
                color var(--dur-base) var(--ease-out-soft);
  }

  /* A whole-page film grain. It is the cheapest way to stop large flat colour
     fields from looking like a screenshot of a design tool. */
  body::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 9999;
    pointer-events: none;
    opacity: var(--grain-opacity);
    mix-blend-mode: overlay;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
  }

  img,
  picture,
  svg,
  video,
  canvas {
    display: block;
    max-inline-size: 100%;
    block-size: auto;
  }

  input,
  button,
  textarea,
  select {
    font: inherit;
    color: inherit;
  }

  p,
  h1, h2, h3, h4, h5, h6 {
    overflow-wrap: break-word;
  }

  h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-weight: 600;
    line-height: var(--leading-tight);
    letter-spacing: var(--tracking-tight);
    /* Fraunces is variable: a little optical sizing and "wonk" keeps headings
       from reading like a default serif. */
    font-variation-settings: "SOFT" 0, "WONK" 1, "opsz" 40;
    text-wrap: balance;
  }

  p { text-wrap: pretty; }

  a {
    color: inherit;
    text-decoration-color: color-mix(in oklab, currentColor 35%, transparent);
    text-underline-offset: 0.22em;
    text-decoration-thickness: 1px;
  }

  ul, ol { padding-inline-start: 1.25em; }

  hr {
    border: 0;
    border-block-start: 1px solid var(--line);
  }

  ::selection {
    background: color-mix(in oklab, var(--brand) 32%, transparent);
    color: var(--text);
  }

  :focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 3px;
    border-radius: var(--radius-xs);
  }

  /* Only paint a custom scrollbar where it can be made to match the theme. */
  @supports selector(::-webkit-scrollbar) {
    ::-webkit-scrollbar { inline-size: 11px; block-size: 11px; }
    ::-webkit-scrollbar-track { background: var(--bg-sunken); }
    ::-webkit-scrollbar-thumb {
      background: color-mix(in oklab, var(--brand) 45%, var(--bg-sunken));
      border-radius: var(--radius-pill);
      border: 3px solid var(--bg-sunken);
    }
    ::-webkit-scrollbar-thumb:hover { background: var(--brand); }
  }

  /* ---------------------------------------------------------------- layout */

  .shell {
    inline-size: min(100% - (var(--gutter) * 2), var(--shell));
    margin-inline: auto;
  }

  .shell--narrow { max-inline-size: var(--shell-narrow); }

  .section {
    padding-block: var(--section-y);
    position: relative;
  }

  .section--tight { padding-block: clamp(3rem, 2rem + 4vw, 5rem); }
  .section--sunken { background: var(--bg-sunken); }

  .stack > * + * { margin-block-start: var(--flow, var(--space-s)); }

  .cluster {
    display: flex;
    flex-wrap: wrap;
    gap: var(--gap, var(--space-s));
    align-items: center;
  }

  .grid-auto {
    display: grid;
    gap: var(--gap, var(--space-m));
    grid-template-columns: repeat(auto-fit, minmax(min(var(--min, 17rem), 100%), 1fr));
  }

  /* ------------------------------------------------------------ utilities */

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

  .skip-link {
    position: fixed;
    inset-block-start: var(--space-s);
    inset-inline-start: var(--space-s);
    z-index: var(--z-overlay);
    padding: 0.7rem 1.1rem;
    background: var(--brand);
    color: var(--text-on-brand);
    border-radius: var(--radius-s);
    font-weight: 600;
    transform: translateY(-160%);
    transition: transform var(--dur-base) var(--ease-spring);
  }

  .skip-link:focus-visible { transform: translateY(0); }

  .text-muted { color: var(--text-muted); }
  .text-soft { color: var(--text-soft); }
  .text-brand { color: var(--brand); }
  .text-accent { color: var(--accent); }
  .text-center { text-align: center; }
  .measure { max-inline-size: 62ch; }
  .measure-tight { max-inline-size: 46ch; }
  .mono { font-family: var(--font-mono); }

  /* An eyebrow: small mono label with a lit dot. Used to open most sections. */
  .eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.6em;
    font-family: var(--font-mono);
    font-size: var(--step--2);
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
    color: var(--text-muted);
  }

  :root[dir="rtl"] .eyebrow {
    text-transform: none;
    /* IBM Plex Mono carries no Arabic glyphs, so a Kurdish eyebrow would fall
       back to an unrelated system face at a size chosen for a monospace. */
    font-family: var(--font-sans);
    font-size: var(--step--1);
    font-weight: 600;
  }

  .eyebrow::before {
    content: "";
    inline-size: 6px;
    block-size: 6px;
    border-radius: 50%;
    background: var(--brand);
    box-shadow: 0 0 0 0 var(--brand-ring);
    animation: pulse-dot 2.8s var(--ease-in-out-soft) infinite;
  }

  @keyframes pulse-dot {
    0%, 100% { box-shadow: 0 0 0 0 var(--brand-ring); }
    50%      { box-shadow: 0 0 0 6px transparent; }
  }

  /* Display headline used at the top of sections. */
  .display {
    font-size: var(--step-5);
    font-variation-settings: "SOFT" 0, "WONK" 1, "opsz" 60;
  }

  .display--hero {
    font-size: var(--step-7);
    font-weight: 500;
  }

  .display em {
    font-style: italic;
    color: var(--brand);
    font-variation-settings: "SOFT" 40, "WONK" 1, "opsz" 60;
  }

  :root[dir="rtl"] .display em {
    font-style: normal;
    font-weight: 700;
  }

  .section-head {
    display: grid;
    gap: var(--space-s);
    max-inline-size: 54ch;
    margin-block-end: var(--space-xl);
  }

  .section-head--split {
    max-inline-size: none;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
    align-items: end;
    gap: var(--space-l);
  }

  @media (max-width: 62rem) {
    .section-head--split { grid-template-columns: 1fr; align-items: start; }
  }

  /* Thin ruled grid used as a backdrop on a couple of sections; it reads as
     draughting paper and gives the layout something to sit against. */
  .ruled {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image:
      linear-gradient(to right, var(--hairline-grid) 1px, transparent 1px),
      linear-gradient(to bottom, var(--hairline-grid) 1px, transparent 1px);
    background-size: 84px 84px;
    mask-image: radial-gradient(ellipse 70% 60% at 50% 40%, #000 20%, transparent 78%);
  }
}
