/*
 * Padelon web styles: one file, no build step.
 *
 * Structure (cascade layers, lowest to highest priority):
 *   reset      -> neutralise browser defaults
 *   tokens     -> design tokens (color, type, space, radius, motion) as custom properties
 *   base       -> element defaults (body, headings, links, lists)
 *   layout     -> page-level structure (wrapper, stack, header/footer)
 *   components -> reusable blocks (button, card, prose)
 *   utilities  -> single-purpose overrides; always win thanks to layer order
 *
 * Conventions:
 *   - Colors in oklch(); variants derived with relative color syntax from a few base hues.
 *   - Light/dark via color-scheme + light-dark(); no duplicated @media blocks.
 *   - Fluid type and space with clamp(); logical properties (inline/block) throughout.
 *   - Low-specificity selectors (:where) so layers, not specificity, decide the cascade.
 */

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

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

  * {
    margin: 0;
  }

  html {
    -webkit-text-size-adjust: none;
    text-size-adjust: none;
  }

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

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

  :where(h1, h2, h3, p) {
    overflow-wrap: break-word;
  }
}

/* ----------------------------------------------------------------- tokens */
@layer tokens {
  :root {
    color-scheme: light dark;

    /* Brand hues (oklch hue angle). Court blue + padel ball yellow-green. */
    --hue-court: 255;
    --hue-ball: 118;

    /* Base colors */
    --court: oklch(45% 0.13 var(--hue-court));
    --ball: oklch(88% 0.2 var(--hue-ball));

    /* Semantic colors (light, dark) */
    --color-bg: light-dark(oklch(98.5% 0.005 var(--hue-court)), oklch(17% 0.03 var(--hue-court)));
    --color-surface: light-dark(oklch(100% 0 0), oklch(22% 0.035 var(--hue-court)));
    --color-text: light-dark(oklch(22% 0.03 var(--hue-court)), oklch(94% 0.01 var(--hue-court)));
    --color-text-muted: light-dark(
      oklch(from var(--color-text) calc(l + 0.25) c h),
      oklch(from var(--color-text) calc(l - 0.25) c h)
    );
    --color-border: light-dark(oklch(90% 0.01 var(--hue-court)), oklch(30% 0.03 var(--hue-court)));
    --color-accent: light-dark(var(--court), oklch(from var(--court) calc(l + 0.3) c h));
    --color-highlight: var(--ball);
    --color-on-highlight: oklch(20% 0.04 var(--hue-ball));
    --color-focus: oklch(from var(--color-accent) l c h / 0.6);

    /* Typography */
    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

    /* Fluid type scale: min at 360px viewport, max at 1240px */
    --step--1: clamp(0.83rem, 0.8rem + 0.15vw, 0.9rem);
    --step-0: clamp(1rem, 0.96rem + 0.2vw, 1.125rem);
    --step-1: clamp(1.2rem, 1.12rem + 0.4vw, 1.45rem);
    --step-2: clamp(1.44rem, 1.29rem + 0.7vw, 1.9rem);
    --step-3: clamp(1.73rem, 1.47rem + 1.2vw, 2.5rem);
    --step-4: clamp(2.07rem, 1.62rem + 2vw, 3.4rem);

    --leading-tight: 1.15;
    --leading-normal: 1.6;

    /* Fluid space scale */
    --space-3xs: clamp(0.25rem, 0.23rem + 0.1vw, 0.31rem);
    --space-2xs: clamp(0.5rem, 0.47rem + 0.15vw, 0.56rem);
    --space-xs: clamp(0.75rem, 0.7rem + 0.2vw, 0.88rem);
    --space-s: clamp(1rem, 0.95rem + 0.25vw, 1.13rem);
    --space-m: clamp(1.5rem, 1.42rem + 0.4vw, 1.69rem);
    --space-l: clamp(2rem, 1.89rem + 0.5vw, 2.25rem);
    --space-xl: clamp(3rem, 2.84rem + 0.75vw, 3.38rem);
    --space-2xl: clamp(4rem, 3.5rem + 2.3vw, 6rem);

    /* Shape and depth */
    --radius-s: 0.375rem;
    --radius-m: 0.75rem;
    --radius-pill: 999px;
    --shadow-1: 0 1px 2px oklch(0% 0 0 / 0.06), 0 4px 16px oklch(0% 0 0 / 0.06);

    /* Layout */
    --measure: 68ch;
    --wrapper-max: 72rem;
    --gutter: var(--space-s);

    /* Motion */
    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    --duration-fast: 150ms;
  }

  @media (prefers-reduced-motion: reduce) {
    :root {
      --duration-fast: 0ms;
    }
  }
}

/* ------------------------------------------------------------------- base */
@layer base {
  html {
    scroll-behavior: smooth;

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

  body {
    min-block-size: 100dvh;
    font-family: var(--font-sans);
    font-size: var(--step-0);
    line-height: var(--leading-normal);
    color: var(--color-text);
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
  }

  :where(h1, h2, h3) {
    line-height: var(--leading-tight);
    text-wrap: balance;
  }

  h1 {
    font-size: var(--step-4);
    letter-spacing: -0.02em;
  }

  h2 {
    font-size: var(--step-2);
  }

  h3 {
    font-size: var(--step-1);
  }

  p,
  li {
    text-wrap: pretty;
  }

  a {
    color: var(--color-accent);
    text-decoration-thickness: 0.08em;
    text-underline-offset: 0.18em;
    transition: color var(--duration-fast) var(--ease-out);

    &:hover {
      text-decoration-thickness: 0.14em;
    }
  }

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

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

/* ----------------------------------------------------------------- layout */
@layer layout {
  /* Centered column with responsive gutters */
  .wrapper {
    inline-size: min(100% - 2 * var(--gutter), var(--wrapper-max));
    margin-inline: auto;
  }

  /* Vertical rhythm: flow spacing between direct children */
  .stack > * + * {
    margin-block-start: var(--stack-space, var(--space-s));
  }

  .site-header,
  .site-footer {
    padding-block: var(--space-m);
  }

  .site-header .wrapper,
  .site-footer .wrapper {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-xs);
  }

  .site-footer {
    margin-block-start: var(--space-2xl);
    border-block-start: 1px solid var(--color-border);
    color: var(--color-text-muted);
    font-size: var(--step--1);
  }

  main {
    padding-block: var(--space-xl);
  }
}

/* ------------------------------------------------------------- components */
@layer components {
  .brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2xs);
    font-weight: 700;
    font-size: var(--step-1);
    color: var(--color-text);
    text-decoration: none;

    & svg {
      inline-size: 1.6em;
      block-size: 1.6em;
    }
  }

  .hero {
    --stack-space: var(--space-m);
    padding-block: var(--space-2xl);
    max-inline-size: 40rem;

    & .lede {
      font-size: var(--step-1);
      color: var(--color-text-muted);
    }
  }

  .button {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2xs);
    padding: var(--space-xs) var(--space-m);
    border-radius: var(--radius-pill);
    background: var(--color-highlight);
    color: var(--color-on-highlight);
    font-weight: 600;
    text-decoration: none;
    box-shadow: var(--shadow-1);
    transition:
      background-color var(--duration-fast) var(--ease-out),
      transform var(--duration-fast) var(--ease-out);

    &:hover {
      background: oklch(from var(--color-highlight) calc(l - 0.06) c h);
      transform: translateY(-1px);
    }

    &:active {
      transform: translateY(0);
    }
  }

  /* Long-form text (privacy policy, terms) */
  .prose {
    --stack-space: var(--space-s);
    max-inline-size: var(--measure);

    & :where(h2) {
      margin-block-start: var(--space-xl);
    }

    & :where(h3) {
      margin-block-start: var(--space-l);
    }

    & :where(ul, ol) {
      padding-inline-start: 1.25em;
    }

    & :where(li + li) {
      margin-block-start: var(--space-3xs);
    }

    & .meta {
      color: var(--color-text-muted);
      font-size: var(--step--1);
    }
  }
}

/* -------------------------------------------------------------- utilities */
@layer utilities {
  .visually-hidden {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .muted {
    color: var(--color-text-muted);
  }
}
