@layer reset, theme, base, elements, layout, components, utilities;

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

  body,
  h1,
  h2,
  h3,
  h4,
  h5,
  h6,
  p,
  ul,
  ol,
  figure,
  blockquote,
  dl,
  dd {
    margin: 0;
  }

  ul[class],
  ol[class] {
    list-style: none;
    padding: 0;
  }

  img,
  picture {
    display: block;
    max-width: 100%;
  }

  img {
    height: auto;
  }

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

  button {
    background: transparent;
    border: 0;
    padding: 0;
  }
}

@layer theme {
  :root {
    /* 1. Primitive assignment colors in HEX */
    --hex-primary: #1f2937; /* Dark Background, Information Header Text, Quote Text */
    --hex-secondary: #f9faf8; /* Hero Main Text, Hero Logo Text */
    --hex-accent: #3882f6; /* Button, CtA Background */
    --hex-neutral: #e5e7eb; /* Hero Secondary Text, Header Link Text, Quote Section Background */

    /* 2. Working palette: OKLCH-normalised / derived colors */
    --palette-primary: oklch(from var(--hex-primary) l c h);
    --palette-secondary: oklch(from var(--hex-secondary) l c h);
    --palette-accent: oklch(from var(--hex-accent) l c h);
    --palette-neutral: oklch(from var(--hex-neutral) l c h);

    /* Project-specific color token.
    Derived from the assignment accent to provide a warm complementary color
    for emphasis and interaction contrast where the provided blue is insufficient. */
    --palette-complementary: oklch(from var(--hex-accent) l c 25);

    /* 3. Semantic colors */
    --color-bg-dark: var(--palette-primary);
    --color-bg-light: var(--palette-neutral);
    --color-bg-accent: var(--palette-accent);

    --color-surface-dark: var(--palette-primary);
    --color-surface-light: var(--palette-neutral);
    --color-surface-accent: var(--palette-accent);
    --color-surface-complementary: var(--palette-complementary);

    --color-text: var(--palette-primary);
    --color-text-light: var(--palette-neutral);
    --color-text-accent: var(--palette-accent);
    --color-text-complementary: var(--palette-complementary);
    --color-text-on-dark: var(--palette-secondary);
    --color-text-on-accent: var(--palette-secondary);
    --color-text-on-complementary: var(--palette-secondary);

    --color-border: var(--palette-primary);
    --color-border-light: var(--palette-neutral);
    --color-border-accent: var(--palette-accent);
    --color-border-complementary: var(--palette-complementary);

    --color-shadow: var(--palette-primary);

    --color-focus: var(--palette-complementary);

    /* Subtle UI chrome: dividers, separators, faint section lines.
    Not for text or primary interactive states. */
    --color-ui: var(--palette-neutral);

    /* Font families */
    --font-primary: 'Roboto', system-ui, sans-serif;

    /* Font sizes */
    --font-200: 0.8125rem; /* 13px */
    --font-300: clamp(0.875rem, 0.82rem + 0.25vw, 1rem); /* 14px–16px - small UI/body text */
    --font-400: clamp(1rem, 0.95rem + 0.3vw, 1.125rem); /* 16px–18px - body, links */
    --font-500: clamp(1.125rem, 1rem + 0.8vw, 1.5rem); /* 18px–24px - small headings/card titles */
    --font-600: clamp(1.75rem, 1.45rem + 1.4vw, 2.25rem); /* 28px–36px - section headings, quote */
    --font-700: clamp(2.25rem, 2rem + 1.5vw, 3rem); /* 36px–48px - hero heading */

    /* Font weights */
    --font-w-300: 300;
    --font-w-400: 400;
    --font-w-500: 500;
    --font-w-600: 600;
    --font-w-700: 700;
    --font-w-800: 800;
    --font-w-900: 900;

    /* Letter spacing */
    --tracking-300: 0.02em;
    --tracking-400: 0.03em;
    --tracking-500: 0.05em;

    /* Line heights */
    --leading-200: 1.1;
    --leading-300: 1.3;
    --leading-400: 1.5;

    /* Layout sizes
    Match the provided mockup widths at the default 16px browser font size,
    while allowing the layout to scale with user font-size preferences. */
    --size-container-wide: 64rem; /* 1024px - header, hero, CTA */
    --size-container-narrow: 51.25rem; /* 820px - cards, quote */

    /* Spacing */
    --space-100: 0.25rem; /* 4px */
    --space-200: 0.5rem; /* 8px */
    --space-300: 0.75rem; /* 12px */
    --space-400: 1rem; /* 16px */
    --space-500: 2rem; /* 32px */

    --space-section-y: clamp(4rem, 3rem + 5vw, 7.5rem);
    --space-chrome-y: 1.5rem; /* header/footer UI chrome spacing */

    --space-panel-x: clamp(2rem, 1rem + 6vw, 7.5rem);
    --space-panel-y: clamp(2rem, 1rem + 4vw, 3.75rem);

    --gutter: clamp(1rem, 0.5rem + 4vw, 1.5rem);

    --gap-layout: clamp(2rem, 1rem + 4vw, 3rem);
    --gap-grid: clamp(0.5rem, 0.25rem + 2vw, 2.5rem);

    /* Border radius */
    --radius-300: 0.25rem; /* 4px - small controls */
    --radius-400: 0.5rem; /* 8px - cards/small panels */
    --radius-500: 0.75rem; /* 12px - larger panels */

    /* Transitions */
    --t-200: 0.2s;
    --t-300: 0.3s;
    --ease-default: ease-in-out;
  }
}

@layer base {
  html {
    color-scheme: light;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
    scrollbar-gutter: stable;

    &:has(#join-dialog[open]) {
      overflow: hidden;
    }
  }

  body {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    color: var(--color-text);
    font-family: var(--font-primary);
    font-size: var(--font-400);
    font-weight: var(--font-w-400);
    line-height: var(--leading-400);
  }

  main {
    flex: 1;
  }

  :target {
    scroll-margin-block-start: calc(var(--space-chrome-y) + var(--space-400));
  }

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

    *,
    *::before,
    *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
      transition-delay: 0ms !important;
      scroll-behavior: auto !important;
    }
  }
}

@layer elements {
  img {
    font-style: italic;
  }

  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    line-height: var(--leading-200);
    text-wrap: balance;
  }

  p {
    text-wrap: pretty;
  }

  a {
    color: currentColor;
    text-decoration: none;
    transition:
      color var(--t-300, 0.3s) var(--ease-default, ease-in-out),
      text-decoration-color var(--t-300, 0.3s) var(--ease-default, ease-in-out);

    &:hover,
    &:active,
    &:focus-visible,
    &[aria-current='page'] {
      color: var(--color-text-complementary);
    }

    &:not([class]) {
      text-decoration: underline;
      text-decoration-skip-ink: auto;
    }
  }

  button {
    cursor: pointer;
  }

  button:focus-visible,
  a:focus-visible,
  input:focus-visible,
  textarea:focus-visible,
  select:focus-visible {
    outline: 2px dashed var(--color-focus);
    outline-offset: var(--space-100);
  }

  ::selection {
    background-color: var(--color-surface-complementary);
    color: var(--color-text-on-complementary);
  }
}

@layer layout {
  .container {
    width: min(var(--size-container-wide), 100% - (var(--gutter) * 2));
    margin-inline: auto;
  }

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

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

  .split {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--gap-layout);

    @media (width < 64rem) {
      flex-direction: column;
    }
  }

  .features-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    justify-content: center;
    justify-items: center;
    gap: var(--gap-grid);

    @media (width < 55rem) {
      grid-template-columns: repeat(2, minmax(0, 14rem));
    }

    @media (width < 30rem) {
      grid-template-columns: 1fr;
    }
  }

  .panel {
    padding: var(--space-panel-y) var(--space-panel-x);
    border-radius: var(--radius-500);
  }
}

@layer components {
  .site-header {
    padding-block: var(--space-chrome-y);
    background-color: var(--color-bg-dark);

    .split {
      flex-direction: row;
      flex-wrap: wrap;
      gap: var(--space-200);
      transition: gap var(--t-300) var(--ease-default);

      @media (width < 48rem) {
        &:has([aria-expanded='false']) {
          gap: 0;
        }
      }
    }
  }

  .site-footer {
    padding-block: var(--space-chrome-y);
    background-color: var(--color-bg-dark);
    color: var(--color-text-on-dark);
    font-size: var(--font-200);
    text-align: center;
    text-transform: uppercase;
    letter-spacing: var(--tracking-500);
  }

  .site-nav {
    color: var(--color-text-light);
    font-size: var(--font-300);
    font-weight: var(--font-w-600);

    .site-nav-list {
      --cluster-gap: 2rem;
    }

    @media (width < 48rem) {
      width: 100%;
      max-height: 50vh;
      padding: var(--space-500);
      border-radius: var(--radius-300);
      background-color: var(--color-bg-light);
      color: var(--color-text);
      transition:
        padding var(--t-300) var(--ease-default),
        max-height var(--t-300) var(--ease-default);
      overflow: hidden;

      .site-nav-list {
        justify-content: center;
        flex-direction: column;
      }
    }
  }

  .hero {
    padding-block-start: clamp(3rem, 2rem + 4vw, 5rem);
    padding-block-end: var(--space-section-y);
    background-color: var(--color-bg-dark);
    color: var(--color-text-on-dark);

    h1 {
      max-width: 100%;
      margin-block-end: var(--space-300);
      font-size: var(--font-700);
      font-weight: var(--font-w-900);
      line-height: var(--leading-200);
    }

    p {
      max-width: 45ch;
      margin-block-end: var(--space-400);
      color: var(--color-text-light);
    }

    .hero-content {
      flex: 1;
      width: 100%;
    }

    .hero-image {
      flex: 1;
      width: 100%;
      border-radius: var(--radius-300);
    }
  }

  .features {
    padding-block: var(--space-section-y);
    color: var(--color-text);

    .features-title {
      font-size: var(--font-600);
      font-weight: var(--font-w-900);
      text-align: center;
      margin-block-end: var(--space-500);
    }

    .card {
      max-width: 15rem;
      text-align: center;
    }

    .card-image {
      border-radius: var(--radius-400);
      border: 4px solid var(--color-border-accent);
      margin-block-end: var(--space-300);
      margin-inline: auto;
    }

    .card-title {
      font-size: var(--font-400);
      margin-block-end: var(--space-200);
    }

    .card-text {
      font-size: var(--font-300);
    }
  }

  .quote {
    padding-block: var(--space-section-y);
    background-color: var(--color-bg-light);
    color: var(--color-text);

    .quote-text {
      font-size: var(--font-600);
      font-weight: var(--font-w-300);
      font-style: italic;
      line-height: var(--leading-300);
      margin-block-end: var(--space-200);
    }

    .quote-source {
      font-size: var(--font-400);
      font-weight: var(--font-w-600);
      text-align: right;
      text-transform: capitalize;
    }
  }

  .cta {
    padding-block: var(--space-section-y);

    .panel {
      background-color: var(--color-surface-accent);
      color: var(--color-text-on-accent);
    }

    .cta-content {
      width: 100%;
    }

    .cta-title {
      font-size: var(--font-500);
      margin-block-end: var(--space-300);
    }

    .cta-text {
      max-width: clamp(45ch, 90%, 55ch);
      font-size: var(--font-400);
      line-height: var(--leading-300);
    }

    @media (width < 64rem) {
      .button {
        align-self: flex-start;
      }
    }
  }

  .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    position: relative; /* Required to contain the ripple */
    overflow: hidden; /* Keeps the ripple inside the rounded corners */
    padding: 0.7em 1.5em;
    font-size: var(--font-300);
    font-weight: var(--font-w-500);
    line-height: var(--leading-200);
    text-decoration: none;
    text-transform: capitalize;
    border: 1px solid transparent;
    border-radius: var(--radius-300);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition:
      background-color var(--t-300) var(--ease-default),
      color var(--t-300) var(--ease-default),
      border-color var(--t-300) var(--ease-default);

    &.button-primary {
      background-color: var(--color-surface-accent);
      color: var(--color-text-on-accent);
      border-color: var(--color-border-accent);
    }

    &.button-ghost {
      background-color: transparent;
      color: var(--color-text-on-dark);
      border-color: var(--color-border-light);
    }

    &::after {
      content: '';
      position: absolute;
      z-index: 0;
      top: 50%;
      left: 50%;
      width: 100%;
      aspect-ratio: 1/1;
      background-color: var(--color-surface-complementary);
      border-radius: 50%;
      transform: translate(-50%, -50%) scale(0);
      opacity: 0;
      pointer-events: none; /* Lets clicks pass through to the button */
      transition:
        background-color var(--t-300) var(--ease-default),
        transform var(--t-300) var(--ease-default),
        opacity var(--t-300) var(--ease-default);
    }

    &:active {
      border-color: var(--color-border-complementary);
      transition: border-color var(--t-300) var(--ease-default);
    }

    &:active::after {
      transform: translate(-50%, -50%) scale(2);
      opacity: 1;
    }

    &:focus-visible {
      background-color: var(--color-surface-complementary);
      color: var(--color-text-on-complementary);
      border-color: var(--color-border-complementary);
    }

    @media (hover: hover) {
      &:hover {
        background-color: var(--color-surface-complementary);
        color: var(--color-text-on-complementary);
        border-color: var(--color-border-complementary);
      }
    }

    .button-text {
      position: relative;
      z-index: 1;
    }
  }

  .site-nav-toggle {
    padding: var(--space-100);
    background-color: var(--color-surface-accent);
    border-radius: var(--radius-300);
    line-height: 0;
    transition: background-color var(--t-200) var(--ease-default);

    &:active {
      background-color: var(--color-surface-complementary);
    }

    .nav-icon {
      width: 2rem;
      height: 2rem;
      stroke: var(--color-text-on-accent);
      stroke-width: 2px;
    }

    .icon-close {
      display: none;
    }

    &[aria-expanded='true'] {
      background-color: var(--color-surface-complementary);

      .icon-menu {
        display: none;
      }

      .icon-close {
        display: block;
      }
    }

    @media (width >= 48rem) {
      display: none;
    }

    @media (width < 48rem) {
      &[aria-expanded='false'] + nav {
        max-height: 0;
        padding: 0;
      }
    }
  }

  .skip-link {
    position: absolute;
    top: -100%;
    left: var(--gutter);

    &:focus {
      top: var(--gutter);
    }
  }

  .join-modal {
    padding: var(--space-panel-y) var(--space-panel-x);
    background-color: var(--color-surface-dark);
    color: var(--color-text-on-dark);
    border-radius: var(--radius-500);
    border: 5px solid var(--color-border-complementary);

    .close-modal {
      position: absolute;
      top: var(--space-300);
      right: var(--space-300);
      width: 2.5rem;
      height: 2.5rem;
      stroke: var(--color-text-complementary);
      stroke-width: 3px;
    }

    .modal-title {
      margin-block-end: var(--space-200);
    }

    .modal-text {
      margin-block-end: var(--space-500);
    }

    &::backdrop {
      background-color: oklch(from var(--color-surface-dark) l c h / 0.9);
      backdrop-filter: blur(4px);
    }
  }

  .not-found {
    text-align: center;

    .container {
      display: flex;
      flex-direction: column;
      align-items: center;
    }

    .not-found-title {
      margin-block-end: var(--space-300);
      font-size: var(--font-700);
      font-weight: var(--font-w-900);
    }

    .not-found-subtitle {
      margin-block-end: var(--space-100);
      font-size: var(--font-500);
      font-weight: var(--font-w-800);
    }

    .not-found-text {
      max-width: 80ch;
    }
  }

  .not-found-instructions {
    padding-block-start: var(--space-panel-y);
    padding-block-end: var(--space-section-y);

    .panel {
      background-color: var(--color-surface-accent);
      color: var(--color-text-on-accent);
    }

    .not-found-next {
      margin-block-end: var(--space-300);
      font-size: var(--font-600);
    }

    .not-found-steps {
      list-style-type: square;

      li:not(:last-child) {
        margin-block-end: var(--space-200);
      }

      li::marker {
        color: var(--color-text);
      }
    }
  }
}

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

  .text-highlight {
    color: var(--color-text-complementary);
  }
}
