html { overflow-x: hidden; }
  body { margin: 0; font-family: 'Inter', system-ui, -apple-system, sans-serif; -webkit-font-smoothing: antialiased; overflow-x: hidden; }
  a { text-decoration: none; }
  input, textarea, button { font-family: inherit; }
  input::placeholder, textarea::placeholder { color: var(--text-muted); }
  input:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
  input:invalid, textarea:invalid { box-shadow: none; }
  .switch-btn { border: none; background: transparent; cursor: pointer; }
  .icon-badge { width: 44px; height: 44px; border-radius: 12px; background: var(--accent-soft); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
  .dot-grid { position: absolute; inset: 0; background-image: radial-gradient(var(--border-strong) 1px, transparent 1.5px); background-size: 22px 22px; opacity: 0.55; pointer-events: none; }
  .nav-link:hover { text-decoration: underline; text-decoration-color: var(--accent); text-decoration-thickness: 2px; text-underline-offset: 8px; }
  .foot-link:hover { color: var(--accent) !important; }
  .ph-chip { display: inline-block; padding: 3px 10px; border: 1px dashed var(--border-strong); border-radius: 999px; font-size: 12.5px; font-weight: 600; color: var(--text-muted); background: var(--bg-alt); white-space: nowrap; }

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

  /* Nav: full row when it fits, hamburger + dropdown when it doesn't.
     There is no fixed pixel breakpoint: app-shell.js (fitNav) measures the
     full row after every render, on resize and once the web fonts have
     loaded, and adds html.nav-compact only when the row would not fit.
     (A fixed breakpoint broke whenever the font, language or zoom changed
     the row's width.) */
  .nav-toggle { display: none; }
  .nav-links { display: flex; align-items: center; gap: 22px; }
  .nav-links > * { flex-shrink: 0; }
  .nav-links > a { white-space: nowrap; }
  html.nav-measuring .nav-links { flex: none; width: max-content; }

  html.nav-compact .nav-toggle { display: inline-flex !important; }
  html.nav-compact .nav-links {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 10px clamp(16px, 5vw, 48px) 20px;
    box-shadow: 0 16px 28px rgba(15, 23, 42, 0.14);
    max-height: calc(100vh - 70px);
    overflow-y: auto;
  }
  html.nav-compact .nav-links.is-open { display: flex; }
  html.nav-compact .nav-links .nav-divider { display: none; }
  html.nav-compact .nav-links > a, html.nav-compact .nav-links > button { width: 100%; box-sizing: border-box; }
  html.nav-compact .nav-links > a.nav-link { padding: 10px 0; }
  html.nav-compact .nav-links > div { align-self: flex-start; margin: 4px 0; }

  /* Grids: collapse to a single column on narrow screens */
  @media (max-width: 720px) {
    .grid-cols-2, .grid-cols-3 { grid-template-columns: 1fr !important; }
  }

  /* Footer: 4 columns -> 2 -> 1 as the screen narrows */
  @media (max-width: 900px) {
    .footer-grid { grid-template-columns: 1fr 1fr !important; gap: 32px !important; }
  }
  @media (max-width: 560px) {
    .footer-grid { grid-template-columns: 1fr !important; }
  }

  /* Rows that pair a text block with a button: stack on narrow screens */
  @media (max-width: 640px) {
    .stack-row { flex-direction: column !important; align-items: flex-start !important; }
    .stack-row > a, .stack-row > button { width: 100%; box-sizing: border-box; justify-content: center; }
  }

  /* Referral page: form + sticky summary, collapsing to one column on narrow screens */
  .grid-referral { display: grid; grid-template-columns: 1.15fr 0.85fr; gap: 24px; align-items: start; }
  .referral-aside { position: sticky; top: 96px; display: flex; flex-direction: column; gap: 20px; }
  @media (max-width: 860px) {
    .grid-referral { grid-template-columns: 1fr !important; }
    .referral-aside { position: static !important; }
  }

  /* Referral page: wrapping rows of selectable chip buttons */
  .chip-row { display: flex; flex-wrap: wrap; gap: 8px; }

  /* Referral page: decorative drone blueprint behind the hero copy, hidden on narrow screens.
     Width-only sizing keeps the image's own aspect ratio intact (no distortion). */
  .referral-hero-art {
    position: absolute; right: clamp(-10px, 1.5vw, 20px); top: 50%; transform: translateY(-50%);
    width: min(26vw, 300px); max-width: 300px; opacity: 0.85; pointer-events: none;
    z-index: 0; border-radius: 18px;
  }
  @media (max-width: 900px) {
    .referral-hero-art { display: none; }
  }

  /* Referral page: Terms & Conditions modal — theme tokens keep it in sync with light/dark */
  .terms-modal-backdrop {
    position: fixed; inset: 0; background: rgba(8, 12, 20, 0.6);
    display: flex; align-items: center; justify-content: center;
    padding: 24px; z-index: 300;
  }
  .terms-modal {
    background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.35);
    width: min(680px, 100%); max-height: min(84vh, 760px);
    display: flex; flex-direction: column; overflow: hidden;
  }
  .terms-modal-header { padding: 24px 28px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
  .terms-modal-body { padding: 18px 28px; overflow-y: auto; flex: 1 1 auto; }
  .terms-section-h {
    margin: 18px 0 6px; font-family: 'Space Grotesk', sans-serif; font-weight: 700;
    font-size: 14.5px; color: var(--header-text);
  }
  .terms-modal-body .terms-section-h:first-child { margin-top: 0; }
  .terms-section-b { margin: 0; font-size: 13.5px; line-height: 1.65; color: var(--text-secondary); }
  .terms-foot-note {
    margin: 22px 0 0; padding-top: 14px; border-top: 1px solid var(--border);
    font-size: 12px; color: var(--text-muted);
  }
  .terms-modal-footer {
    padding: 18px 28px 24px; border-top: 1px solid var(--border);
    flex-shrink: 0; display: flex; flex-direction: column; gap: 10px;
  }
  .terms-close-btn {
    align-self: flex-start; font-size: 14px; font-weight: 600; color: #ffffff;
    background: var(--accent); border: none; padding: 11px 26px; border-radius: 12px; cursor: pointer;
  }
  .terms-gate-hint { margin: 0; font-size: 12.5px; color: var(--text-muted); font-style: italic; }
  @media (max-width: 640px) {
    .terms-modal { max-height: 92vh; border-radius: 14px; }
    .terms-modal-header, .terms-modal-body, .terms-modal-footer { padding-left: 18px; padding-right: 18px; }
  }

  /* ---- STEM fields carousel (home page; markup built by stem-carousel.js) ----
     Colors come from the site's theme tokens (--accent, --surface, --border...),
     so light/dark follow the theme toggle automatically. */
  .stem-section {
    width: 100%; box-sizing: border-box; padding: 80px 0 64px;
    background: var(--bg-alt); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
    overflow-x: clip; scroll-margin-top: 76px; position: relative; z-index: 2;
  }
  .stem-carousel { width: 100%; }
  .stem-head {
    max-width: 1120px; margin: 0 auto; box-sizing: border-box; padding: 0 clamp(20px, 6vw, 64px);
    display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 24px; align-items: end;
  }
  .stem-eyebrow { display: block; font-size: 13px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--accent); margin-bottom: 12px; }
  .stem-title {
    margin: 0 0 12px; font-family: 'Space Grotesk', sans-serif; font-weight: 700;
    font-size: clamp(26px, 6vw, 34px); line-height: 1.2; letter-spacing: -0.02em; color: var(--header-text); text-wrap: balance;
  }
  .stem-intro { margin: 0; max-width: 640px; font-size: 17px; line-height: 1.7; color: var(--text-secondary); }
  .stem-hint { margin-top: 14px; display: flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 500; color: var(--text-muted); }
  .stem-hint svg { flex: none; color: var(--accent); }
  .stem-controls { display: flex; gap: 8px; }
  .stem-btn {
    width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--border-strong);
    background: var(--surface); color: var(--header-text); cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08); transition: border-color .2s ease, color .2s ease, transform .1s ease;
  }
  .stem-btn:hover { border-color: var(--accent); color: var(--accent); }
  .stem-btn:active { transform: scale(.95); }
  .stem-btn .stem-ico-play { display: none; }
  .stem-btn[aria-pressed="true"] .stem-ico-play { display: block; }
  .stem-btn[aria-pressed="true"] .stem-ico-pause { display: none; }

  .stem-stage { position: relative; margin-top: 36px; }
  .stem-viewport {
    overflow: hidden; padding: 14px 0 22px; cursor: grab; touch-action: pan-y;
    -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 7%, #000 93%, transparent 100%);
            mask-image: linear-gradient(90deg, transparent 0, #000 7%, #000 93%, transparent 100%);
  }
  .stem-viewport.is-dragging { cursor: grabbing; }
  .stem-track { display: flex; gap: 20px; width: max-content; padding: 0 10px; will-change: transform; }
  .stem-card {
    position: relative; flex: none; width: 280px; padding: 0; overflow: hidden; cursor: pointer;
    text-align: left; color: inherit; font: inherit;
    background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
    transition: transform .25s ease, border-color .25s ease, box-shadow .25s ease;
    user-select: none; -webkit-user-select: none;
  }
  .stem-card:hover, .stem-card.is-active {
    transform: translateY(-6px); border-color: var(--accent); box-shadow: 0 14px 32px rgba(65, 182, 230, .22);
  }
  .stem-card img {
    display: block; width: 100%; height: auto; max-width: 100%; aspect-ratio: 4 / 3; object-fit: cover;
    background: var(--placeholder-bg); pointer-events: none; -webkit-user-drag: none;
  }
  .stem-card-body { display: flex; align-items: center; gap: 12px; padding: 14px 16px 16px; border-top: 1px solid var(--border); }
  .stem-num {
    flex: none; width: 34px; height: 34px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center;
    background: var(--accent-soft); color: var(--accent); font: 700 13.5px 'Space Grotesk', sans-serif;
  }
  .stem-card.is-active .stem-num, .stem-pop-head .stem-num { background: var(--accent); color: #ffffff; }
  .stem-label { font-family: 'Space Grotesk', sans-serif; font-weight: 600; font-size: 16px; line-height: 1.25; color: var(--header-text); }
  .stem-card:focus-visible, .stem-btn:focus-visible, .stem-pop-close:focus-visible, .stem-pop-cta:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

  .stem-pop {
    position: absolute; z-index: 30; width: min(420px, calc(100vw - 32px)); box-sizing: border-box;
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border); border-top: 3px solid var(--accent); border-radius: 14px;
    box-shadow: 0 18px 48px rgba(15, 23, 42, 0.22); padding: 20px 20px 18px;
    opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity .2s ease, transform .2s ease;
  }
  .stem-pop.is-open { opacity: 1; transform: translateY(0); pointer-events: auto; }
  .stem-pop::before {
    content: ""; position: absolute; top: -10px; left: var(--stem-arrow-x, 50%); width: 16px; height: 16px;
    margin-left: -8px; transform: rotate(45deg); background: var(--accent); border-radius: 3px 0 0 0;
  }
  .stem-pop-head { display: flex; align-items: flex-start; gap: 12px; padding-right: 32px; }
  .stem-pop-title { margin: 2px 0 0; font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 19px; line-height: 1.25; color: var(--header-text); }
  .stem-pop-close {
    position: absolute; top: 12px; right: 12px; width: 32px; height: 32px; border-radius: 50%;
    border: 0; background: transparent; color: var(--text-secondary); cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
  }
  .stem-pop-close:hover { background: var(--accent-soft); color: var(--header-text); }
  .stem-pop-desc { margin: 12px 0 0; font-size: 15px; line-height: 1.6; color: var(--text); }
  .stem-pop-sub { margin: 14px 0 6px; font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); }
  .stem-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
  .stem-chips li { font-size: 12.5px; font-weight: 500; padding: 4px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--header-text); }
  .stem-build {
    margin-top: 14px; padding: 10px 12px; border-radius: 10px; background: var(--bg-alt);
    border: 1px dashed var(--border-strong); font-size: 14px; line-height: 1.55; color: var(--text-secondary);
  }
  .stem-build strong { color: var(--header-text); font-weight: 600; }
  .stem-pop-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; }
  .stem-pop-foot small { font-size: 12.5px; color: var(--text-muted); }
  .stem-pop-cta {
    display: inline-flex; align-items: center; white-space: nowrap; background: var(--accent); color: #ffffff;
    font-weight: 600; font-size: 14px; padding: 9px 16px; border-radius: 12px; box-shadow: 0 4px 6px -1px rgba(65, 182, 230, .25);
  }
  .stem-pop-cta:hover { background: var(--accent-hover); }

  .stem-status {
    max-width: 1120px; margin: 2px auto 0; box-sizing: border-box; padding: 0 clamp(20px, 6vw, 64px);
    display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-muted);
  }
  .stem-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); }
  .stem-status.is-paused .stem-dot { background: #f59e0b; }

  @media (max-width: 720px) {
    .stem-section { padding: 56px 0 48px; }
    .stem-head { grid-template-columns: 1fr; }
    .stem-card { width: 220px; }
    .stem-label { font-size: 14.5px; }
    .stem-pop {
      position: fixed; left: 12px !important; right: 12px; top: auto !important; bottom: 12px;
      width: auto; max-height: 72vh; overflow: auto; z-index: 250;
    }
    .stem-pop::before { display: none; }
  }
  @media (prefers-reduced-motion: reduce) {
    .stem-card, .stem-pop { transition: none; }
  }

  /* Tools page: clickable card grid + detail popup */
  .tool-card {
    font-family: inherit; text-align: left; cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  }
  .tool-card:hover, .tool-card:focus-visible {
    transform: translateY(-2px);
    border-color: var(--accent) !important;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12) !important;
  }
  .tool-modal-backdrop {
    position: fixed; inset: 0; background: rgba(8, 12, 20, 0.6);
    display: flex; align-items: center; justify-content: center;
    padding: 24px; z-index: 300;
  }
  .tool-modal {
    background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.35);
    width: min(520px, 100%); max-height: min(84vh, 640px);
    display: flex; flex-direction: column; overflow: hidden;
  }
  .tool-modal-header {
    padding: 24px 28px 0; flex-shrink: 0;
    display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  }
  .tool-modal-close-x {
    flex-shrink: 0; width: 32px; height: 32px; border-radius: 999px; border: 1px solid var(--border-strong);
    background: var(--bg-alt); color: var(--text-secondary); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
  }
  .tool-modal-body { padding: 14px 28px 4px; overflow-y: auto; flex: 1 1 auto; }
  .tool-modal-footer {
    padding: 20px 28px 28px; border-top: 1px solid var(--border); margin-top: 18px;
    flex-shrink: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  }
  .tool-visit-btn {
    font-size: 14px; font-weight: 600; color: #ffffff; background: var(--accent); border: none;
    padding: 11px 22px; border-radius: 12px; display: inline-flex; align-items: center; gap: 8px;
  }
  .tool-close-btn {
    font-size: 14px; font-weight: 600; color: var(--header-text); background: var(--surface);
    border: 1px solid var(--border-strong); padding: 11px 20px; border-radius: 12px; cursor: pointer;
  }
  @media (max-width: 640px) {
    .tool-modal { max-height: 92vh; border-radius: 14px; }
    .tool-modal-header, .tool-modal-body, .tool-modal-footer { padding-left: 18px; padding-right: 18px; }
  }
