@layer tokens, base, components, utilities;

/* ------------------------------ */
/* TOKENS                         */
/* ------------------------------ */
@layer tokens {
  :root{
    --m-bg: var(--wp--preset--color--bg, #ffffff);
    --m-surface: var(--wp--preset--color--surface, #f6f7fb);
    --m-text: var(--wp--preset--color--text, #101828);
    --m-muted: var(--wp--preset--color--muted, #667085);
    --m-accent: var(--wp--preset--color--accent, #2563eb);

    --m-radius-sm: var(--wp--custom--radius--sm, 10px);
    --m-radius-md: var(--wp--custom--radius--md, 16px);
    --m-radius-lg: var(--wp--custom--radius--lg, 24px);

    --m-shadow-sm: var(--wp--custom--shadow--sm, 0 2px 10px rgba(16,24,40,.08));
    --m-shadow-md: var(--wp--custom--shadow--md, 0 8px 30px rgba(16,24,40,.12));

    --m-s1: 0.5rem;
    --m-s2: 0.75rem;
    --m-s3: 1rem;
    --m-s4: 1.5rem;
    --m-s5: 2rem;
    --m-s6: 3rem;
    --m-s7: 4rem;
  }
}

/* ------------------------------ */
/* BASE                           */
/* ------------------------------ */
@layer base {
  html { scroll-behavior: smooth; }
  body { background: var(--m-bg); color: var(--m-text); }
  img, video { max-width: 100%; height: auto; }

  a { color: inherit; }
  a:hover { text-decoration: none; }

  :focus-visible{
    outline: 2px solid var(--m-accent);
    outline-offset: 3px;
    border-radius: 6px;
  }

  /* Gutenberg Button reset (avoid button-in-button) */
  .wp-block-button { background: transparent; padding: 0; border: 0; }
  .wp-block-button__link{
    background: transparent;
    padding: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    text-decoration: none;
  }
}

/* ------------------------------ */
/* COMPONENTS: layout helpers      */
/* ------------------------------ */
@layer components {
  /* Use WP global layout sizes (controlled by theme.json settings.layout) */
  .l-container{
    width: min(var(--wp--style--global--wide-size, 1200px), 100% - 2 * var(--m-s4));
    margin-inline: auto;
  }
  .l-container--narrow{
    width: min(var(--wp--style--global--content-size, 720px), 100% - 2 * var(--m-s4));
    margin-inline: auto;
  }

  .l-stack > * + * { margin-top: var(--m-s4); }
  .l-stack--tight > * + * { margin-top: var(--m-s2); }

  .l-grid{ display: grid; gap: var(--m-s4); }

  /* Robust grid: no “last card becomes wider” */
  .l-grid--3{
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  }
}

/* ------------------------------ */
/* COMPONENTS: Buttons (Block Styles) */
/* ------------------------------ */
@layer components {
  .wp-block-button.is-style-modularis-primary .wp-block-button__link,
  .wp-block-button.is-style-modularis-ghost .wp-block-button__link,
  .wp-block-button.is-style-modularis-text .wp-block-button__link{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    padding: .85rem 1.05rem;
    border-radius: var(--m-radius-md);
    font-weight: 600;
    line-height: 1;
    border: 1px solid transparent;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    transition: transform .12s ease, box-shadow .12s ease, background-color .12s ease, border-color .12s ease, color .12s ease, opacity .12s ease;
    will-change: transform;
  }

  /* Primary */
  .wp-block-button.is-style-modularis-primary .wp-block-button__link{
    background: var(--m-accent);
    color: #fff;
    box-shadow: var(--m-shadow-sm);
  }
  .wp-block-button.is-style-modularis-primary .wp-block-button__link:hover{
    /* Visible hover: slightly lighter/darker depending on palette */
    background: color-mix(in oklab, var(--m-accent), white 10%);
    box-shadow: var(--m-shadow-md);
    transform: translateY(-1px);
  }
  .wp-block-button.is-style-modularis-primary .wp-block-button__link:active{
    transform: translateY(0);
    opacity: .95;
  }

  /* Ghost */
  .wp-block-button.is-style-modularis-ghost .wp-block-button__link{
    background: transparent;
    color: var(--m-text);
    border-color: color-mix(in oklab, var(--m-text), transparent 75%);
  }
  .wp-block-button.is-style-modularis-ghost .wp-block-button__link:hover{
    border-color: color-mix(in oklab, var(--m-text), transparent 55%);
    background: color-mix(in oklab, var(--m-surface), transparent 35%);
    box-shadow: var(--m-shadow-sm);
    transform: translateY(-1px);
  }
  .wp-block-button.is-style-modularis-ghost .wp-block-button__link:active{
    transform: translateY(0);
    opacity: .95;
  }

  /* Text link */
  .wp-block-button.is-style-modularis-text .wp-block-button__link{
    background: transparent;
    border-color: transparent;
    padding: 0;
    border-radius: 0;
    color: var(--m-accent);
  }
  .wp-block-button.is-style-modularis-text .wp-block-button__link:hover{
    text-decoration: underline;
    opacity: .9;
  }
}

/* ------------------------------ */
/* COMPONENTS: Cards / Navbar / Hero */
/* ------------------------------ */
@layer components {
  .c-card{
    background: var(--m-surface);
    border-radius: var(--m-radius-lg);
    padding: var(--m-s5);
    box-shadow: var(--m-shadow-sm);
    border: 1px solid color-mix(in oklab, var(--m-text), transparent 90%);
  }
  .c-card__kicker{
    color: var(--m-muted);
    font-weight: 600;
    letter-spacing: .02em;
    text-transform: uppercase;
    font-size: .85rem;
  }
  .c-card__title{
    font-size: clamp(1.15rem, 1.1rem + 0.5vw, 1.5rem);
    font-weight: 700;
    margin: .35rem 0 .5rem;
  }
  .c-card__text{ color: var(--m-muted); }

  /* Navbar */
  .c-nav{
    position: sticky;
    top: 0;
    z-index: 50;
    background: color-mix(in oklab, var(--m-bg), transparent 12%);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid color-mix(in oklab, var(--m-text), transparent 90%);
  }
  .c-nav__inner{
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--m-s3) 0;
    gap: var(--m-s4);
    flex-wrap: wrap; /* important for mobile */
  }

  .c-brand{
    display: inline-flex;
    align-items: center;
    gap: .65rem;
    font-weight: 800;
    letter-spacing: .01em;
    text-decoration: none;
  }
  .c-brand__mark{
    width: 36px;
    height: 36px;
    border-radius: 12px;
    background: var(--m-accent);
    box-shadow: var(--m-shadow-sm);
    flex: 0 0 auto;
  }

  /* Navigation: use WP overlay on mobile, inline on desktop */
  .c-nav__menu{
    flex: 1 1 auto;
    display: flex;
    justify-content: center;
  }
  .c-nav__cta{
    display: flex;
    gap: var(--m-s3);
    flex: 0 0 auto;
  }

  /* Mobile fixes: stop CTA breaking into tiny pills */
  @media (max-width: 900px){
    .c-nav__menu{ order: 3; width: 100%; justify-content: flex-start; }
    .c-nav__cta{ order: 2; width: 100%; justify-content: flex-start; flex-wrap: wrap; }
    .c-nav__cta .wp-block-button{ width: auto; }
  }

  @media (max-width: 520px){
    .c-nav__cta{ flex-direction: column; }
    .c-nav__cta .wp-block-button,
    .c-nav__cta .wp-block-button__link{ width: 100%; }
  }

  /* Hero */
  .c-hero{ padding: var(--m-s7) 0; }
  .c-hero, .c-hero * { text-align: left; } /* hard fix for the “centered lead” issue */

  .c-hero__wrap{
    display: grid;
    gap: var(--m-s6);
    align-items: center;
  }
  @media (min-width: 980px){
    .c-hero__wrap{ grid-template-columns: 1.1fr .9fr; }
  }
  .c-hero__title{
    font-size: clamp(2rem, 1.6rem + 2.2vw, 3.2rem);
    line-height: 1.05;
    letter-spacing: -0.02em;
    font-weight: 800;
    margin: 0;
  }
  .c-hero__lead{
    font-size: 1.125rem;
    color: var(--m-muted);
    max-width: 60ch;
  }
  .c-hero__actions{
    display: flex;
    gap: var(--m-s3);
    flex-wrap: wrap;
    margin-top: var(--m-s4);
    align-items: center;
  }
}

/* ------------------------------ */
/* UTILITIES                      */
/* ------------------------------ */
@layer utilities {
  .u-muted{ color: var(--m-muted); }
  .u-center{ text-align: center; }
  .u-max-narrow{ max-width: 70ch; }
}

/* ------------------------------ */
/* COMPONENTS: Footer             */
/* ------------------------------ */
@layer components {
  .c-footer {
    border-top: 1px solid color-mix(in oklab, var(--m-text), transparent 90%);
    background: var(--m-surface);
  }
}

/* ------------------------------ */
/* UTILITIES (additions)          */
/* ------------------------------ */
@layer utilities {
  /* Centers a narrow-capped element within a wider container */
  .u-max-narrow {
    max-width: 70ch;
    margin-inline: auto;
  }

  /* Screen-reader only text */
  .u-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
  }
}
