/* ============================================================
   Bowdler.app — Global Stylesheet
   Architecture: CUBE CSS + @layer
   Layers: reset → tokens → base → layout → components → header → footer → utilities
   ============================================================ */

@layer reset, tokens, base, layout, components, header, footer, page, utilities;

/* || @layer reset */
@layer reset {
  * { margin: 0; padding: 0; box-sizing: border-box; }
}

/* || @layer tokens */
@layer tokens {
  :root {
    --bg: #0b0c10;
    --elevated: #13151a;
    --card: #1a1d24;
    --text: #dadbdf;
    --muted: #8a8f98;
    --faint: #6b7179;
    --dim: #555a64;
    --border: rgba(255,255,255,0.06);
    --accent: #D4843A;
    --accent-soft: rgba(212,132,58,0.12);
    --accent-hover: #E09B5A;
    --accent-glow: rgba(212,132,58,0.15);
    --success: #34d399;
    --danger: #f87171;

    --font-sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

    --max: 760px;
    --header-h: 48px;

    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --space-7: 2.5rem;
    --space-8: 3rem;
    --space-9: 4rem;

    --fs-xs: 0.7rem;
    --fs-sm: 0.78rem;
    --fs-base: 0.82rem;
    --fs-md: 0.85rem;
    --fs-lg: 0.88rem;
    --fs-xl: 0.9rem;
    --fs-2xl: 0.95rem;
    --fs-3xl: 1rem;
    --fs-hero: clamp(4rem, 10vw, 6.5rem);

    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
  }

  @media (max-width: 640px) {
    :root { --header-h: 52px; }
  }
}

/* || @layer base */
@layer base {
  html {
    font-size: 17px;
    scroll-behavior: smooth;
    scroll-padding-top: calc(var(--header-h) + var(--safe-top, 0px));
    overflow-x: hidden;
    min-height: 100svh;
    min-height: -webkit-fill-available;
    background: var(--bg);
  }

  body {
    font-family: var(--font-sans);
    font-weight: 400;
    line-height: 1.7;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    position: relative;
    min-height: 100svh;
    padding-top: calc(var(--header-h) + var(--safe-top, 0px));
  }

  @media (pointer: fine) {
    body::after {
      content: '';
      position: fixed; inset: 0;
      pointer-events: none; z-index: 9999;
      opacity: 0.025;
      mix-blend-mode: overlay;
      background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
      background-size: 180px;
    }
  }

  a { color: inherit; }

  :focus-visible {
    outline: 2px solid var(--text);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px var(--accent-glow);
  }

  :focus:not(:focus-visible) {
    outline: none;
  }

  @supports (interpolate-size: allow-keywords) {
    :root { interpolate-size: allow-keywords; }
    details::details-content {
      block-size: 0;
      overflow: hidden;
      transition: block-size 0.35s cubic-bezier(0.25, 0.1, 0.25, 1), content-visibility 0.35s cubic-bezier(0.25, 0.1, 0.25, 1);
      transition-behavior: allow-discrete;
    }
    details[open]::details-content {
      block-size: auto;
    }
  }
}

/* || @layer layout */
@layer layout {
  .section {
    padding: var(--space-8) var(--space-6);
  }

  .inner {
    max-width: var(--max);
    margin: 0 auto;
  }

  .page-header {
    padding: 3rem 2rem 2rem;
  }

  .page-header h1 {
    font-size: clamp(2.5rem, 6vw, 3.5rem);
    font-weight: 700;
    letter-spacing: -0.04em;
    line-height: 1;
    margin-bottom: 0.75rem;
  }

  .page-header p {
    font-size: 1.1rem;
    color: var(--muted);
    max-width: 560px;
  }

  .page-header-cta {
    margin-top: 1.5rem;
  }

  @media (max-width: 640px) {
    .page-header {
      padding-top: 2rem;
      padding-left: 1.5rem;
      padding-right: 1.5rem;
    }
    .section {
      padding: var(--space-8) var(--space-5);
    }
  }
}

/* || @layer components */
@layer components {
  .rule {
    border: none;
    height: 1px;
    max-width: var(--max);
    margin: 0 auto;
    background: linear-gradient(90deg, transparent 0%, var(--border) 20%, var(--border) 80%, transparent 100%);
  }

  .section-kicker {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 1.25rem;
    display: block;
    letter-spacing: -0.01em;
  }

  .section-kicker--display {
    font-size: clamp(1.6rem, 3vw, 2.4rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    margin-bottom: 1.5rem;
  }

  .section-kicker--how {
    font-size: clamp(2.4rem, 5vw, 3.8rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--text);
    margin-bottom: 1.5rem;
  }

  .section-kicker--friendly {
    font-size: 1.35rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-bottom: 1.25rem;
  }

  .section-kicker--terms {
    font-size: 1.15rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text);
    margin-bottom: 1.5rem;
  }

  .section-kicker--apply {
    font-size: clamp(2rem, 4vw, 3.5rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--text);
    margin-bottom: 1rem;
  }

  .section-kicker--faq {
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text);
    margin-bottom: 1.25rem;
  }

  .section-kicker--changelog {
    font-size: clamp(1.6rem, 3vw, 2.4rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--text);
    margin-bottom: 1.5rem;
  }

  .section-kicker--compare {
    font-size: clamp(1.6rem, 3vw, 2.4rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    margin-bottom: 1.5rem;
    color: var(--text);
  }

  .pill {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: 0.75rem 1.6rem;
    border-radius: 50px;
    font-size: var(--fs-lg);
    font-weight: 500;
    text-decoration: none;
    transition: transform 0.15s ease, background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
    min-height: 44px;
    min-width: 44px;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
  }
  .pill:active { transform: scale(0.97); }

  .pill-primary {
    background: var(--accent);
    color: var(--bg);
    font-weight: 600;
  }
  .pill-primary:hover { background: var(--accent-hover); }
  .pill-primary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

  .pill-secondary {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
  }
  .pill-secondary:hover {
    background: rgba(255,255,255,0.04);
    border-color: var(--accent);
    color: var(--accent);
  }
  .pill-secondary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

  .features-cta-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: var(--fs-md);
    font-weight: 500;
    color: var(--text);
    text-decoration: none;
    transition: color 0.25s ease;
    min-height: 44px;
    padding: 0.3rem 0.25rem 0.3rem 0;
    overflow: visible;
  }
  .features-cta-link:hover { color: var(--accent); }
  .features-cta-arrow {
    display: inline-block;
    text-decoration: none;
    transition: transform 0.2s ease;
  }
  .features-cta-link:hover .features-cta-arrow { transform: translateX(3px); }

  .faq-item {
    border-bottom: 1px solid var(--border);
    padding: var(--space-4) 0;
  }
  .faq-item:last-child { border-bottom: none; }
  .faq-q {
    font-size: var(--fs-xl);
    font-weight: 500;
    color: var(--text);
    margin: 0 0 0.4rem;
  }
  .faq-a {
    font-size: var(--fs-md);
    color: var(--muted);
    line-height: 1.7;
  }

  .accordion {
    border-bottom: 1px solid var(--border);
  }
  .accordion summary {
    cursor: pointer;
    padding: var(--space-4) 0;
    font-weight: 600;
    color: var(--muted);
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: var(--fs-2xl);
  }
  .accordion summary::-webkit-details-marker { display: none; }
  .accordion summary::after {
    content: '+';
    font-family: var(--font-sans);
    color: var(--faint);
    font-size: 1rem;
    transition: transform 0.3s cubic-bezier(0.25, 0.1, 0.25, 1);
    flex-shrink: 0;
    margin-left: var(--space-4);
    display: inline-block;
  }
  .accordion[open] summary::after {
    transform: rotate(45deg);
  }
  .accordion > :not(summary) {
    padding-bottom: var(--space-4);
    margin: 0;
    color: var(--muted);
  }

  .receipt {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 var(--space-7);
    max-width: 720px;
    margin: 2rem auto 0;
  }
  .receipt-col {
    display: grid;
    grid-template-rows: subgrid;
  }
  .receipt-head {
    font-size: var(--fs-3xl);
    font-weight: 600;
    color: var(--text);
    margin-bottom: var(--space-4);
    letter-spacing: -0.01em;
    padding-top: var(--space-4);
  }
  .receipt-row {
    font-size: var(--fs-xl);
    color: var(--muted);
    line-height: 1.7;
    padding: 0.9rem 0;
    border-top: 1px solid var(--border);
  }
  .receipt-row:first-of-type {
    border-top: 2px solid var(--text);
  }
  .receipt-row strong {
    color: var(--text);
    font-weight: 500;
  }
  .receipt-val {
    font-family: var(--font-sans);
    font-weight: 500;
    color: var(--accent);
    font-size: 0.92em;
  }

  @supports not (grid-template-rows: subgrid) {
    .receipt-col { display: block; }
  }

  @media (max-width: 640px) {
    .receipt {
      grid-template-columns: 1fr;
      gap: 0 var(--space-4);
    }
    .receipt-col {
      display: block;
    }
    .receipt-row {
      border-top: 1px solid var(--border);
    }
    .receipt-col:first-child .receipt-row:first-of-type,
    .receipt-col:last-child .receipt-row:first-of-type {
      border-top: 2px solid var(--text);
    }
  }
}

/* || @layer header */
@layer header {
  .sticky-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: calc(var(--header-h) + var(--safe-top, 0px));
    z-index: 100;
    contain: layout style paint;
    background: var(--bg);
    padding-top: var(--safe-top, 0px);
    box-sizing: border-box;
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    will-change: transform;
  }

  [data-scroll-dir="down"] .sticky-header {
    transform: translateY(calc(-100% - var(--safe-top, 0px)));
  }

  [data-scroll-dir="up"] .sticky-header,
  :root:not([data-scroll-dir]) .sticky-header {
    transform: translateY(0);
  }

  @media (prefers-reduced-motion: reduce) {
    .sticky-header {
      transition: none;
    }
  }

  .header-compact {
    padding: 0 1.5rem;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    height: var(--header-h);
    max-width: 1200px;
    margin: 0 auto;
  }

  .compact-brand {
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: -0.03em;
    line-height: 1;
    text-decoration: none;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0;
    flex-shrink: 0;
    color: var(--text);
    transition: transform 200ms cubic-bezier(0.25, 0.46, 0.45, 0.94),
                color 200ms ease;
  }

  .compact-brand:hover {
    transform: translateY(-1px);
    color: var(--accent-hover);
  }

  .compact-brand:active {
    transform: translateY(0);
    transition-duration: 100ms;
  }

  .compact-brand:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    border-radius: 6px;
    color: var(--accent-hover);
    transform: translateY(-1px);
  }

  .brand-logo {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    flex-shrink: 0;
    display: block;
  }

  .masthead-nav {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    font-size: var(--fs-base);
    gap: 1.25rem;
  }

  .masthead-nav a {
    color: var(--faint);
    text-decoration: none;
    transition: color 0.25s ease;
    white-space: nowrap;
    padding: 0.55rem 0.4rem;
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .masthead-nav a:hover,
  .masthead-nav a:focus-visible {
    color: var(--text);
  }

  .masthead-nav a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
  }

  .masthead-nav a[aria-current="page"],
  .masthead-nav a.active {
    color: var(--accent);
    font-weight: 600;
  }

  .header-compact .masthead-nav {
    justify-content: flex-end;
    font-size: 0.88rem;
    gap: 1.25rem;
    line-height: 1;
    flex-shrink: 0;
  }
  .header-compact .masthead-nav a {
    padding: 0.55rem 0.4rem;
  }

  @media (max-width: 640px) {
    .header-compact {
      padding: 0 1rem;
      gap: 0.75rem;
      overflow-x: auto;
      scrollbar-width: none;
    }
    .header-compact::-webkit-scrollbar { display: none; }
    .compact-brand { font-size: 1rem; padding: 0.3rem 0; }
    .masthead-nav { flex-wrap: nowrap; gap: 0.5rem; font-size: 0.78rem; }
    .header-compact .masthead-nav { gap: 0.5rem; }
    .masthead-nav a { padding: 0.4rem 0.3rem; min-height: 44px; min-width: 44px; }
  }
}

/* || @layer footer */
@layer footer {
  footer {
    border-top: 1px solid var(--border);
    padding: var(--space-8) var(--space-6) var(--space-8);
    margin-top: var(--space-5);
  }

  .footer-inner {
    max-width: 1100px;
    margin: 0 auto;
  }

  .footer-top {
    display: grid;
    grid-template-columns: 1.5fr 2fr;
    gap: var(--space-8);
    margin-bottom: var(--space-8);
    align-items: start;
  }

  .footer-brand {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .footer-wordmark {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    text-decoration: none;
    color: var(--text);
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    padding: 0.4rem 0;
  }

  .footer-tagline {
    font-size: 0.88rem;
    color: var(--muted);
    line-height: 1.6;
    max-width: 280px;
  }

  .footer-links {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-6);
  }

  .footer-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.6rem;
  }

  .footer-label {
    font-size: var(--fs-base);
    font-weight: 600;
    color: var(--dim);
    margin-bottom: 0.35rem;
  }

  .footer-group a {
    font-size: var(--fs-xl);
    line-height: 1.7;
    color: var(--faint);
    text-decoration: none;
    transition: color 0.25s ease;
    padding: 0.75rem 0;
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
  }
  .footer-group a:hover { color: var(--accent); }

  .footer-bottom {
    border-top: 1px solid var(--border);
    padding-top: var(--space-5);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  .footer-copy {
    font-size: var(--fs-md);
    color: var(--dim);
  }
  .footer-copy a {
    color: var(--faint);
    text-decoration: none;
    transition: color 0.25s ease;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0;
  }
  .footer-copy a:hover {
    color: var(--accent);
    text-decoration: underline;
  }

  .sig-heart {
    color: var(--accent);
    opacity: 0;
    transition: opacity 0.25s ease;
  }
  .sig-wrap:hover .sig-heart {
    opacity: 1;
  }

  .footer-meta {
    font-size: var(--fs-sm);
    color: var(--dim);
  }

  @media (max-width: 768px) {
    .footer-top {
      grid-template-columns: 1fr;
      gap: var(--space-6);
      margin-bottom: var(--space-6);
    }
    .footer-links {
      grid-template-columns: repeat(3, 1fr);
      gap: 1.5rem;
    }
    footer { padding: 2.5rem 1.5rem; }
  }

  @media (max-width: 640px) {
    footer {
      padding: var(--space-6) var(--space-5);
      margin-top: var(--space-4);
    }
    .footer-links {
      grid-template-columns: repeat(2, 1fr);
      gap: 1.5rem 1rem;
    }
    .footer-top {
      gap: 1.25rem;
      margin-bottom: 1.25rem;
    }
    .footer-group { gap: 0.4rem; }
    .footer-label {
      font-size: 0.9rem;
      margin-bottom: 0.6rem;
      color: var(--muted);
    }
    .footer-group a {
      font-size: var(--fs-base);
      line-height: 1.5;
      padding: 0.15rem 0;
    }
    .footer-tagline {
      font-size: var(--fs-base);
      line-height: 1.5;
      max-width: none;
    }
    .footer-bottom {
      flex-direction: column;
      align-items: flex-start;
      gap: 0.35rem;
      padding-top: 0.875rem;
    }
    .footer-copy { font-size: var(--fs-sm); }
    .footer-meta { font-size: var(--fs-xs); }
    .footer-wordmark { font-size: 1.1rem; }
  }

  @media (max-width: 360px) {
    .footer-links {
      grid-template-columns: 1fr;
      gap: 0.875rem;
    }
    footer { padding: 1.5rem 0.75rem; }
  }
}

/* || @layer utilities */
@layer utilities {

  .is-hidden {
    display: none;
  }

  @media (prefers-reduced-motion: reduce) {
    .compact-brand,
    .brand-logo,
    .pill,
    .features-cta-link,
    .features-cta-arrow,
    .reviews-nav-btn {
      transition: none !important;
      transform: none !important;
    }
  }

}
