/*
  MMH Web Solutions - main stylesheet
  Conventions: kebab-case class names (max 4 dashes), max 3 levels of
  native CSS nesting, no external resources.
*/

@layer reset, base, layout, components;

/* ---------- Design tokens ---------- */

:root {
  color-scheme: light dark;

  /* Palettes (contrast checked: text 15:1+, links and buttons 5:1+, fields 4.6:1+) */
  --light-bg: #fff;
  --light-surface: #f3f7f7;
  --brand-pale: #eef6f7; /* disc behind the service icons */
  --light-text: #0d1f21;
  --light-muted: #3d5557;
  --light-accent: #00717a;
  --light-on-accent: #fff;
  --light-border: #cfdcdc;
  --light-field-border: #5f7a7c;
  --light-error: #b3261e;

  --dark-bg: #040c0d;
  --dark-surface: #0a1b1d;
  --dark-text: #e8f4f4;
  --dark-muted: #a6abab;
  --dark-accent: #58c2c5;
  --dark-on-accent: #040c0d;
  --dark-border: #1f3e40;
  --dark-field-border: #5f9395;
  --dark-error: #ff9a93;

  /* Fixed dark bands, the same in both modes: the header and footer frame the page in the
     deepest ink (the art's own near-black), and the hero and steps sit one step lighter. */
  --band-ink: #01090a;
  --band-mid: #0f2a2d;

  /* Semantic tokens follow the visitor's color scheme */
  --color-bg: var(--light-bg);
  --color-surface: var(--light-surface);
  --color-text: var(--light-text);
  --color-muted: var(--light-muted);
  --color-accent: var(--light-accent);
  --color-on-accent: var(--light-on-accent);
  --color-border: var(--light-border);
  --color-field-border: var(--light-field-border);
  --color-error: var(--light-error);

  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-heading: var(--font-body);

  --space-s: 0.75rem;
  --space-m: 1.5rem;
  --space-l: 3rem;
  --space-xl: 5rem;
  --radius: 0.25rem;
  --content-width: 68rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: var(--dark-bg);
    --color-surface: var(--dark-surface);
    --color-text: var(--dark-text);
    --color-muted: var(--dark-muted);
    --color-accent: var(--dark-accent);
    --color-on-accent: var(--dark-on-accent);
    --color-border: var(--dark-border);
    --color-field-border: var(--dark-field-border);
    --color-error: var(--dark-error);
  }
}

/* ---------- Reset ---------- */

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

  * {
    margin: 0;
  }

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

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

  [hidden] {
    display: none !important;
  }
}

/* ---------- Base ---------- */

@layer base {
  html {
    font-family: var(--font-body);
    line-height: 1.6;
    -webkit-text-size-adjust: 100%;

    /* Keep anchor targets and focused elements clear of the sticky header. */
    scroll-padding-top: 6rem;
  }

  @media (prefers-reduced-motion: no-preference) {
    html {
      scroll-behavior: smooth;
    }
  }

  body {
    background: var(--color-bg);
    color: var(--color-text);
  }

  h1,
  h2,
  h3 {
    font-family: var(--font-heading);
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: -0.015em;
  }

  h1 {
    font-size: clamp(2rem, 5vw, 3rem);
  }

  h2 {
    font-size: clamp(1.5rem, 3vw, 2rem);
  }

  h3 {
    font-size: 1.15rem;
    letter-spacing: -0.005em;
  }

  p,
  ul,
  ol {
    max-width: 65ch;
  }

  a {
    color: var(--color-accent);
    text-underline-offset: 0.2em;
  }

  /* A two-tone ring: the accent outline sits on a gap filled with the local background,
     so it stays visible on any band or card. */
  :focus-visible {
    outline: 3px solid var(--color-accent);
    outline-offset: 3px;
    box-shadow: 0 0 0 3px var(--color-bg);
  }
}

/* ---------- Layout ---------- */

@layer layout {
  .layout-wrap {
    width: min(100% - 2rem, var(--content-width));
    margin-inline: auto;
  }

  .page-section {
    padding-block: var(--space-m);
    border-top: 3px solid var(--color-accent);

    & > .layout-wrap > * + * {
      margin-top: var(--space-m);
    }
  }

  .page-section-alt {
    background: var(--color-surface);
  }

  .card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
    gap: var(--space-m);
    max-width: none;
    padding: 0;
    list-style: none;
  }
}

/* ---------- Components ---------- */

@layer components {
  .skip-link {
    position: absolute;
    top: 0;
    left: 0;
    padding: var(--space-s) var(--space-m);
    background: var(--color-accent);
    color: var(--color-on-accent);
    z-index: 20;
    transform: translateY(-110%);

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

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

  /* Header and navigation */

  .site-header {
    position: sticky;
    top: 0;
    z-index: 10;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg);

    & .layout-wrap {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      justify-content: space-between;
      gap: var(--space-s);
      padding-block: var(--space-s);
    }
  }

  .site-brand {
    display: flex;
    align-items: center;
    gap: var(--space-s);
    color: var(--color-text);
    font-size: 1.05rem;
    font-weight: 600;
    text-decoration: none;

    & img {
      width: 2.75rem;
      height: 2.75rem;
      border-radius: 50%;
      background: var(--dark-bg);
      object-fit: cover;
    }
  }

  .nav-toggle {
    display: inline-flex;
    padding: 0.6rem;
    border: 0;
    border-radius: var(--radius);
    background: transparent;
    color: var(--color-text);
    cursor: pointer;

    &[aria-expanded="false"] .nav-toggle-close,
    &[aria-expanded="true"] .nav-toggle-open {
      display: none;
    }
  }

  .nav-toggle-icon {
    width: 1.75rem;
    height: 1.75rem;
    fill: none;
    stroke: currentcolor;
    stroke-width: 2;
    stroke-linecap: round;
  }

  .site-nav {
    flex-basis: 100%;

    @media (min-width: 48em) {
      flex-basis: auto;
    }
  }

  .site-nav-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-s) var(--space-m);
    max-width: none;
    padding: 0;
    list-style: none;

    & a {
      display: inline-flex;
      align-items: center;
      min-height: 2.75rem;
      color: var(--color-text);
      font-size: 1rem;
      text-decoration: none;

      &:hover {
        text-decoration: underline;
      }
    }
  }

  /* Buttons */

  .button-link {
    display: inline-block;
    padding: 0.7rem 1.25rem;
    border: 2px solid var(--color-accent);
    border-radius: var(--radius);
    background: var(--color-accent);
    color: var(--color-on-accent);
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
  }

  .button-link-outline {
    background: transparent;
    color: var(--color-accent);
  }

  /* Hover swaps filled and outlined; the footer icons share this. */
  .button-link:hover,
  .footer-social-link:hover {
    background: transparent;
    color: var(--color-accent);
  }

  .button-link-outline:hover {
    background: var(--color-accent);
    color: var(--color-on-accent);
  }

  .button-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-s);
  }

  /*
    Dark bands (header, hero, steps, footer, error pages) look the same in light and
    dark mode: they take the dark palette inside them only, by swapping the semantic
    tokens. The header and footer use the deepest ink, the rest the mid tone.
  */
  .band-ink,
  .band-mid {
    --color-text: var(--dark-text);
    --color-muted: var(--dark-muted);
    --color-accent: var(--dark-accent);
    --color-on-accent: var(--dark-on-accent);
    --color-border: var(--dark-border);
    --color-field-border: var(--dark-field-border);
    --color-error: var(--dark-error);

    color: var(--color-text);
  }

  .band-ink {
    --color-bg: var(--band-ink);

    background: var(--color-bg);
  }

  .band-mid {
    --color-bg: var(--band-mid);

    background: var(--color-bg);
  }

  .hero-section {
    padding-block: var(--space-m);
  }

  .badge-image {
    width: min(100%, 18rem);
    margin-inline: auto;
    border-radius: 50%;
    background: var(--dark-bg);
  }

  .error-section {
    padding-block: var(--space-m);
  }

  .error-grid {
    display: grid;
    gap: var(--space-l);
    align-items: center;

    @media (min-width: 48em) {
      grid-template-columns: 1.2fr 1fr;
    }
  }

  .error-copy > * + * {
    margin-top: var(--space-m);
  }

  /*
    Mobile: title with a small logo on its right, then the rest full width.
    Desktop: copy column on the left, large logo on the right.
  */
  .hero-grid {
    display: grid;
    grid-template-columns: 1fr 5.5rem;
    grid-template-areas:
      "title logo"
      "subline subline"
      "actions actions";
    gap: var(--space-m);
    align-items: center;

    @media (min-width: 48em) {
      grid-template-columns: 1.4fr 1fr;
      grid-template-areas: none;
      gap: var(--space-l);
    }
  }

  .hero-copy {
    display: contents;

    @media (min-width: 48em) {
      display: block;

      & > * + * {
        margin-top: var(--space-m);
      }
    }
  }

  .hero-title {
    grid-area: title;
  }

  .hero-subline {
    grid-area: subline;
    color: var(--color-muted);
    font-size: 1.15rem;
  }

  .hero-actions {
    grid-area: actions;
  }

  .hero-logo {
    grid-area: logo;

    @media (min-width: 48em) {
      grid-area: auto;
    }
  }

  /* Service cards */

  .service-card {
    padding: var(--space-m);
    border: 1px solid var(--color-border);
    border-top: 3px solid var(--color-accent);
    border-radius: var(--radius);
    background: var(--color-bg);

    & > * + * {
      margin-top: var(--space-s);
    }
  }

  /* Grid cards are equal height; pin the icon to the bottom so they line up. */
  .card-grid > .service-card {
    display: flex;
    flex-direction: column;

    & > p {
      margin-bottom: var(--space-s);
    }

    & > .service-icon {
      margin-top: auto;
    }
  }

  /* Where subgrid is supported, each card shares five row tracks with its row
     neighbors (title, lead-in, toggle, details, icon) so "Learn more" and the
     icon line up across the row however the titles and lead-ins wrap. */
  @supports (grid-template-rows: subgrid) {
    .card-grid > .service-card {
      display: grid;
      grid-row: span 5;
      grid-template-rows: subgrid;
      row-gap: 0;

      & > p {
        margin-bottom: 0;
      }

      & > .service-icon {
        align-self: end;
      }
    }
  }

  /* Placeholder art: a pale disc, the header mark's color, keeps the dark cauldron visible in dark mode. */
  .service-icon {
    display: block;
    width: 5rem;
    height: 5rem;
    margin-inline: auto;
    padding: 0.5rem;
    border-radius: 50%;
    background: var(--brand-pale);
    isolation: isolate;

    & img {
      width: 100%;
      height: 100%;
      object-fit: contain;

      /* Multiplying onto the disc turns any white in the art into the disc color. */
      mix-blend-mode: multiply;
    }
  }

  /* Magic (public/js/magic.js adds .is-magic, or .is-magic-reverse for the opposite turn):
     service icons make one turn and two sparkles pop beside them; a primary
     button gets two stars at its top-right and bottom-left corners that turn. Skipped entirely for visitors who prefer reduced motion. */
  @media (prefers-reduced-motion: no-preference) {
    .service-icon,
    .button-link {
      position: relative;

      &::before,
      &::after {
        content: "";
        position: absolute;
        width: 0.9rem;
        height: 0.9rem;
        background: var(--color-accent);

        /* A four-point star. */
        clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
        opacity: 0;
        pointer-events: none;
      }

      &::after {
        width: 0.65rem;
        height: 0.65rem;
      }

      &.is-magic::before,
      &.is-magic-reverse::before {
        animation: icon-spark 0.9s ease-out;
      }

      &.is-magic::after,
      &.is-magic-reverse::after {
        animation: icon-spark 0.9s ease-out 0.15s;
      }
    }

    /* Button stars stay lit while they turn, then fade as the page scrolls away. */
    .button-link.is-magic {
      &::before,
      &::after {
        width: 1.1rem;
        height: 1.1rem;
        animation: button-spark 1.2s ease-in-out;
      }
    }

    .service-icon {
      &::before {
        top: 0;
        right: 0;
      }

      &::after {
        bottom: 0.4rem;
        left: -0.1rem;
      }

      &.is-magic img,
      &.is-magic-reverse img {
        animation: icon-spin 0.8s ease-in-out;
      }
    }

    /* Each star sits 1rem outside its corner. */
    .button-link {
      &::before {
        top: -1rem;
        right: -1rem;
      }

      &::after {
        bottom: -1rem;
        left: -1rem;
      }
    }

    /* Opening turns clockwise; closing (.is-magic-reverse) turns the other way. */
    .service-icon.is-magic-reverse {
      --turn: -1;
    }

    @keyframes icon-spin {
      to {
        transform: rotate(calc(360deg * var(--turn, 1)));
      }
    }

    @keyframes button-spark {
      0% {
        opacity: 0;
        transform: scale(0) rotate(0deg);
      }

      25% {
        opacity: 1;
        transform: scale(1) rotate(90deg);
      }

      75% {
        opacity: 1;
        transform: scale(1) rotate(270deg);
      }

      100% {
        opacity: 0;
        transform: scale(0.4) rotate(360deg);
      }
    }

    @keyframes icon-spark {
      0% {
        opacity: 0;
        transform: scale(0) rotate(0deg);
      }

      40% {
        opacity: 1;
        transform: scale(1.3) rotate(calc(45deg * var(--turn, 1)));
      }

      100% {
        opacity: 0;
        transform: scale(0.4) rotate(calc(90deg * var(--turn, 1)));
      }
    }
  }

  /* Full-width blocks: icon beside the text on desktop, above it on mobile. */
  .service-card-featured,
  .contract-band {
    display: grid;
    gap: var(--space-m);
    justify-items: center;

    @media (min-width: 48em) {
      grid-template-columns: auto 1fr;
      justify-items: start;
      align-items: center;
    }

    /* Mobile: icon after the text. Desktop: icon on the left. */
    & .service-icon {
      order: 1;
      width: 7rem;
      height: 7rem;

      @media (min-width: 48em) {
        order: 0;
      }
    }
  }

  /* Learn more: the lead-in always shows; the rest opens with a smooth height transition. */
  .service-more {
    display: grid;
    grid-template-rows: 0fr;
    visibility: hidden;

    /* Hold visibility until the close animation ends so the hidden text leaves the tab order. */
    @media (prefers-reduced-motion: no-preference) {
      transition:
        grid-template-rows 0.3s ease,
        visibility 0s linear 0.3s;
    }

    & > div {
      overflow: hidden;
    }

    /* Breathing room under the details; inside the clip so a closed panel stays flush. */
    & > div > p {
      padding-bottom: 0.75rem;
    }

    &.is-open {
      grid-template-rows: 1fr;
      visibility: visible;

      @media (prefers-reduced-motion: no-preference) {
        transition:
          grid-template-rows 0.3s ease,
          visibility 0s;
      }
    }
  }

  .service-toggle {
    min-height: 2.75rem;
    display: inline-flex;
    justify-self: start;
    align-items: center;
    gap: 0.25rem;
    padding: 0.5rem 0;
    border: 0;
    background: none;
    color: var(--color-accent);
    font: inherit;
    font-weight: 600;
    cursor: pointer;

    & svg {
      width: 1.1rem;
      height: 1.1rem;
      fill: none;
      stroke: currentcolor;
      stroke-width: 2;
      stroke-linecap: round;
      stroke-linejoin: round;

      @media (prefers-reduced-motion: no-preference) {
        transition: transform 0.3s ease;
      }
    }

    &[aria-expanded="true"] svg {
      transform: rotate(180deg);
    }
  }

  .service-card-body > * + * {
    margin-top: var(--space-s);
  }

  /* Card titles take the teal accent; the lead-in is larger and italic so it
     reads apart from the plain-weight details under "Learn more". */
  .service-card h3,
  .contract-band h3 {
    color: var(--color-accent);
    font-size: 1.3rem;
    font-weight: 700;
  }

  .service-lead {
    font-size: 1.15rem;
    font-style: italic;
    font-weight: 500;
  }

  .service-card-featured {
    padding: var(--space-l) var(--space-m);

    & h3 {
      font-size: 1.75rem;
    }

    & p {
      max-width: 48rem;
    }

    & .service-lead {
      font-size: 1.3rem;
    }
  }

  .contract-band {
    padding: var(--space-m);
    border-left: 3px solid var(--color-accent);
    background: var(--color-bg);

    & > * + * {
      margin-top: var(--space-s);
    }
  }

  /* Process steps */

  .process-list {
    display: grid;
    gap: var(--space-m);
    max-width: none;
    padding: 0;
    list-style: none;
    counter-reset: step;

    @media (min-width: 48em) {
      grid-template-columns: repeat(3, 1fr);
    }

    & li {
      display: grid;
      grid-template-columns: auto 1fr;
      column-gap: var(--space-s);
      align-items: center;
      align-content: start;
      counter-increment: step;

      /* The details paragraph spans under the badge and title. */
      & > p {
        grid-column: 1 / -1;
        margin-top: var(--space-s);
      }

      /* A numbered badge: an outlined circle in the accent color. */
      &::before {
        content: counter(step);
        display: flex;
        align-items: center;
        justify-content: center;
        width: 2.75rem;
        height: 2.75rem;
        border: 2px solid var(--color-accent);
        border-radius: 50%;
        color: var(--color-accent);
        font-size: 1.15rem;
        font-weight: 700;
      }

      & h3 {
        color: var(--color-accent);
        font-weight: 700;
      }
    }
  }

  /* Contact form */

  /* About: text with the workspace art beside it on desktop; the art is hidden on mobile. */
  .about-art {
    display: none;
  }

  .about-main > * + * {
    margin-top: var(--space-m);
  }

  @media (min-width: 48em) {
    .about-grid {
      display: grid;
      grid-template-columns: 1.6fr 1fr;
      gap: var(--space-l);
      align-items: center;
    }

    .about-art {
      display: block;
      width: 100%;
      height: auto;
    }
  }

  .contact-art {
    display: none;
  }

  .page-section > .contact-grid > .contact-main {
    margin-top: 0;
  }

  .contact-main > * + * {
    margin-top: var(--space-m);
  }

  @media (min-width: 48em) {
    .contact-grid {
      display: grid;
      grid-template-columns: 1fr 1.6fr;
      gap: var(--space-l);
      align-items: start;
    }

    /* Stays in view beside the long form, clear of the sticky header. */
    .contact-art {
      display: block;
      position: sticky;
      top: 6rem;

      & img {
        width: 100%;
        height: auto;
        border-radius: 50%;
      }
    }
  }

  .contact-form {
    display: grid;
    gap: var(--space-m);
    max-width: 40rem;
  }

  .form-honeypot {
    display: none;
  }

  .form-field {
    display: grid;
    gap: 0.35rem;

    & ::placeholder {
      color: var(--color-muted);
      opacity: 1;
    }

    & input,
    & select,
    & textarea {
      width: 100%;
      padding: 0.65rem 0.75rem;
      border: 1px solid var(--color-field-border);
      border-radius: var(--radius);
      background: var(--color-bg);
      color: var(--color-text);
    }

    & textarea {
      min-height: 7rem;
      resize: vertical;
    }

    /* Style the closed select; the open list is drawn by the browser or OS. */
    & select {
      padding-right: 2.5rem;
      appearance: none;
      background-image:
        linear-gradient(45deg, transparent 50%, var(--color-text) 50%),
        linear-gradient(135deg, var(--color-text) 50%, transparent 50%);
      background-position:
        calc(100% - 1.2rem) 50%,
        calc(100% - 0.85rem) 50%;
      background-size: 0.35rem 0.35rem;
      background-repeat: no-repeat;
    }

    & option {
      background: var(--color-bg);
      color: var(--color-text);
    }
  }

  .form-field-label {
    font-weight: 600;
  }

  .form-privacy-note {
    color: var(--color-muted);
    font-size: 0.9rem;
  }

  .form-status {
    max-width: 40rem;
    padding: var(--space-m);
    border: 1px solid var(--color-border);
    border-left: 3px solid var(--color-accent);
    border-radius: var(--radius);
    background: var(--color-surface);

    & > * + * {
      margin-top: var(--space-s);
    }
  }

  .form-status-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-s);
  }

  /* Footer */

  .site-footer {
    padding-block: var(--space-l);
    border-top: 3px solid var(--color-accent);
    color: var(--color-muted);
    font-size: 0.95rem;

    & p + p {
      margin-top: var(--space-s);
    }
  }

  .footer-grid {
    display: grid;
    gap: var(--space-l);

    @media (min-width: 48em) {
      grid-template-columns: repeat(3, 1fr);
    }
  }

  .footer-column > * + * {
    margin-top: var(--space-s);
  }

  .footer-brand {
    color: var(--color-text);
    font-weight: 600;
  }

  .footer-heading {
    color: var(--color-text);
    font-size: 1rem;
  }

  /* Its own row: a light divider above, centered. */
  .footer-copyright {
    max-width: none;
    margin-top: var(--space-l);
    padding-top: var(--space-m);
    border-top: 1px solid var(--color-border);
    font-size: 0.9rem;
    text-align: center;
  }

  .footer-link-list {
    display: grid;
    gap: 0;
    padding: 0;
    list-style: none;

    & a {
      display: inline-flex;
      align-items: center;
      min-height: 2.75rem;
    }
  }

  .footer-social-list {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: var(--space-s) var(--space-m);
    margin-top: var(--space-m);
    padding: 0;
    list-style: none;

    @media (min-width: 48em) {
      justify-content: space-evenly;
      padding-inline: var(--space-m);
    }
  }

  .footer-social-link {
    --social-scale: 1.15;
    --social-turn: 25deg;

    display: inline-flex;
    padding: 0.75rem;
    border: 2px solid var(--color-accent);
    border-radius: 50%;
    background: var(--color-accent);
    color: var(--color-on-accent);

    & svg {
      width: 1.5rem;
      height: 1.5rem;
      fill: none;
      stroke: currentcolor;
      stroke-width: 2;
      stroke-linecap: round;
      stroke-linejoin: round;
    }

    @media (prefers-reduced-motion: no-preference) {
      transition: transform 0.2s ease, background-color 0.2s ease, color 0.2s ease;

      &:hover,
      &:active,
      &:focus-visible {
        transform: scale(var(--social-scale)) rotate(var(--social-turn));
      }
    }
  }
}
