/* Layer order: lowest → highest priority */
@layer tokens, reset, base, layout, components, utilities;


/* ================================================================
  TOKENS
  All raw values live here. Components reference vars, never raw values.
================================================================ */
@layer tokens {
  :root {
    /* Brand */
    --color-brand: #2c2cff;
    --color-brand-dark: #1a1acc;
    --color-brand-tint: #eeeeff;
    --color-brand-mid: #5c5cff;

    /* Neutrals */
    --color-bg: #f5f4f0;
    --color-surface: #ffffff;
    --color-surface-2: #f0efeb;
    --color-border: #e0e0e0;
    --color-text: #1a1a1a;
    --color-text-muted: #555;
    --color-text-subtle: #888;

    /* Type scale */
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --text-3xl: 1.875rem;
    --text-4xl: 2.25rem;
    --text-5xl: 3rem;
    --text-6xl: 3.75rem;

    /* Spacing */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;
    --space-16: 64px;
    --space-20: 80px;
    --space-24: 96px;

    /* Radii */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
    --shadow-lg: 0 12px 32px rgba(0,0,0,0.1), 0 4px 8px rgba(0,0,0,0.06);

    /* Transitions */
    --duration-fast: 100ms;
    --duration-base: 200ms;
    --ease-default: cubic-bezier(0.4, 0, 0.2, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  /* Dark token values — applied by OS preference OR explicit toggle */
  @media (prefers-color-scheme: dark) {
    /* Only fires when the user hasn't explicitly chosen light */
    :root:not([data-theme="light"]) {
      --color-brand: #7b7bff;
      --color-brand-dark: #9a9aff;
      --color-brand-tint: #1a1a3a;
      --color-brand-mid: #6b6bff;

      --color-bg: #0f0f0f;
      --color-surface: #1a1a1a;
      --color-surface-2: #222;
      --color-border: #2e2e2e;
      --color-text: #f0f0f0;
      --color-text-muted: #aaa;
      --color-text-subtle: #666;
    }
  }

  /* Explicit dark — set by the toggle button, overrides OS light preference */
  :root[data-theme="dark"] {
    --color-brand: #7b7bff;
    --color-brand-dark: #9a9aff;
    --color-brand-tint: #1a1a3a;
    --color-brand-mid: #6b6bff;

    --color-bg: #0f0f0f;
    --color-surface: #1a1a1a;
    --color-surface-2: #222;
    --color-border: #2e2e2e;
    --color-text: #f0f0f0;
    --color-text-muted: #aaa;
    --color-text-subtle: #666;
  }
}


/* ================================================================
  RESET
================================================================ */
@layer reset {
  *, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }

  html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
  }

  :where(img, video) {
    max-width: 100%;
    display: block;
  }

  :where(button, input, select, textarea) {
    font: inherit;
  }
}


/* ================================================================
  BASE
================================================================ */
@layer base {
  body {
    font-family: system-ui, -apple-system, sans-serif;
    background-color: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    font-size: var(--text-base);
    transition: background-color 0.25s var(--ease-default), color 0.2s var(--ease-default);
  }

  :where(h1, h2, h3, h4) {
    line-height: 1.15;
    font-weight: 800;
    color: var(--color-text);
  }

  :where(p) {
    color: var(--color-text-muted);
  }

  :where(a) {
    color: var(--color-brand);
    text-decoration: none;
    transition: color var(--duration-base) var(--ease-default);
  }

  :where(a):hover {
    color: var(--color-brand-dark);
  }

  :where(code) {
    font-family: ui-monospace, 'Cascadia Code', monospace;
    font-size: 0.9em;
    background: var(--color-brand-tint);
    color: var(--color-brand);
    padding: 1px 6px;
    border-radius: var(--radius-sm);
  }
}


/* ================================================================
  LAYOUT
================================================================ */
@layer layout {
  .section-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: var(--space-20) var(--space-6);
  }

  .section-title {
    font-size: var(--text-3xl);
    margin-bottom: var(--space-3);
  }

  .section-sub {
    font-size: var(--text-lg);
    color: var(--color-text-muted);
    max-width: 560px;
    margin-bottom: var(--space-12);
  }
}


/* ================================================================
  COMPONENTS
================================================================ */
@layer components {

  /* --- Buttons --- */

  .button {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    background: var(--color-brand);
    color: white;
    font-size: var(--text-base);
    font-weight: 600;
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    padding: var(--space-3) var(--space-6);
    cursor: pointer;
    text-decoration: none;
    transition:
      background var(--duration-base) var(--ease-default),
      transform var(--duration-base) var(--ease-spring),
      box-shadow var(--duration-base) var(--ease-default);

    &:hover {
      background: var(--color-brand-dark);
      transform: translateY(-2px);
      box-shadow: 0 6px 20px rgba(44, 44, 255, 0.3);
      color: white;
    }

    &:active {
      transform: translateY(0);
      box-shadow: none;
    }

    &.button--ghost {
      background: transparent;
      color: var(--color-brand);
      border-color: var(--color-brand);

      &:hover {
        background: var(--color-brand-tint);
        box-shadow: none;
        color: var(--color-brand-dark);
      }
    }

    &.button--sm {
      font-size: var(--text-sm);
      padding: var(--space-2) var(--space-4);
    }

    &.button--lg {
      font-size: var(--text-lg);
      padding: var(--space-4) var(--space-10);
      border-radius: var(--radius-lg);
    }
  }


  /* --- Nav --- */

  .site-nav {
    position: sticky;
    top: 0;
    z-index: 100;
    background: color-mix(in srgb, var(--color-bg) 90%, transparent);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--color-border);

    .site-nav__inner {
      max-width: 1100px;
      margin: 0 auto;
      padding: var(--space-4) var(--space-6);
      display: flex;
      justify-content: space-between;
      align-items: center;
    }

    .site-nav__logo {
      display: flex;
      align-items: center;
      gap: var(--space-3);
      font-weight: 700;
      font-size: var(--text-base);
      color: var(--color-text);
      text-decoration: none;

      &:hover {
        color: var(--color-text);
      }
    }

    .site-nav__logo-mark {
      background: var(--color-brand);
      color: white;
      font-size: var(--text-xs);
      font-weight: 800;
      letter-spacing: 0.05em;
      padding: 3px 7px;
      border-radius: var(--radius-sm);
    }

    .site-nav__links {
      display: flex;
      align-items: center;
      gap: var(--space-6);
      font-size: var(--text-sm);

      a:not(.button) {
        color: var(--color-text-muted);
        font-weight: 500;

        &:hover {
          color: var(--color-brand);
        }
      }
    }
  }

  /* --- Theme toggle --- */

  .theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    border: 1.5px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-muted);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    transition:
      background var(--duration-base) var(--ease-default),
      border-color var(--duration-base) var(--ease-default),
      color var(--duration-base) var(--ease-default),
      transform var(--duration-base) var(--ease-spring);

    &:hover {
      background: var(--color-brand-tint);
      border-color: var(--color-brand);
      color: var(--color-brand);
      transform: rotate(20deg);
    }

    &:active {
      transform: rotate(0deg) scale(0.92);
    }
  }


  /* --- Hero --- */

  .hero {
    max-width: 1100px;
    margin: 0 auto;
    padding: var(--space-20) var(--space-6);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-16);
    align-items: center;

    .hero__inner {
      display: flex;
      flex-direction: column;
      gap: var(--space-6);
    }

    .hero__eyebrow {
      display: inline-flex;
      align-items: center;
      gap: var(--space-2);
      font-size: var(--text-xs);
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.12em;
      color: var(--color-brand);
    }

    .hero__headline {
      font-size: var(--text-6xl);
      line-height: 1.0;
      letter-spacing: -0.02em;
      color: var(--color-text);
    }

    .hero__sub {
      font-size: var(--text-lg);
      color: var(--color-text-muted);
      line-height: 1.65;
      max-width: 480px;
    }

    .hero__actions {
      display: flex;
      gap: var(--space-3);
      flex-wrap: wrap;
    }

    .hero__badge-row {
      display: flex;
      gap: var(--space-2);
      flex-wrap: wrap;
    }
  }

  /* Badge */
  .badge {
    display: inline-block;
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--color-text-muted);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    padding: var(--space-1) var(--space-3);
  }

  /* Code window */
  .code-window {
    background: #12121f;
    border-radius: var(--radius-xl);
    overflow: hidden;
    box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255,255,255,0.06);

    .code-window__bar {
      background: #1e1e2e;
      padding: var(--space-3) var(--space-4);
      display: flex;
      gap: var(--space-2);

      span {
        width: 12px;
        height: 12px;
        border-radius: var(--radius-full);
        background: #444;

        &:nth-child(1) { background: #ff5f57; }
        &:nth-child(2) { background: #febc2e; }
        &:nth-child(3) { background: #28c840; }
      }
    }

    .code-window__body {
      padding: var(--space-6);
      font-family: ui-monospace, 'Cascadia Code', monospace;
      font-size: var(--text-sm);
      line-height: 1.8;
      color: #cdd6f4;
      overflow-x: auto;

      code {
        background: none;
        color: inherit;
        font-size: inherit;
        padding: 0;
      }
    }
  }

  /* Syntax token colours */
  .tok-comment { color: #6c7086; }
  .tok-selector { color: #cba6f7; }
  .tok-prop { color: #89b4fa; }
  .tok-value { color: #a6e3a1; }


  /* --- Why section --- */

  .why {
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    border-bottom: 1px solid var(--color-border);

    .feature-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
      gap: var(--space-4);
    }
  }

  /* Feature card — uses container query for internal layout */
  .feature-card-wrapper {
    container-type: inline-size;
  }

  .feature-card {
    background: var(--color-bg);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    border: 1px solid var(--color-border);
    transition: box-shadow var(--duration-base) var(--ease-default),
                transform var(--duration-base) var(--ease-spring);

    &:hover {
      box-shadow: var(--shadow-md);
      transform: translateY(-2px);
    }

    .feature-card__icon {
      font-size: var(--text-xl);
      color: var(--color-brand);
      margin-bottom: var(--space-4);
    }

    .feature-card__title {
      font-size: var(--text-lg);
      margin-bottom: var(--space-2);
    }

    p {
      font-size: var(--text-sm);
      line-height: 1.65;
    }
  }


  /* --- Comparison table --- */

  .comparison {
    background: var(--color-surface-2);

    .comparison-table {
      background: var(--color-surface);
      border-radius: var(--radius-xl);
      border: 1px solid var(--color-border);
      overflow: hidden;
      box-shadow: var(--shadow-sm);
    }

    .comparison-table__header {
      display: grid;
      grid-template-columns: 1fr 1fr;
      background: var(--color-brand);
      color: white;
      font-size: var(--text-sm);
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.08em;

      span {
        padding: var(--space-3) var(--space-6);

        &:last-child {
          border-left: 1px solid rgba(255,255,255,0.2);
        }
      }
    }

    .comparison-table__row {
      display: grid;
      grid-template-columns: 1fr 1fr;
      border-top: 1px solid var(--color-border);
      font-size: var(--text-sm);

      span {
        padding: var(--space-4) var(--space-6);
        color: var(--color-text-muted);

        &:first-child {
          color: var(--color-text-subtle);
          text-decoration: line-through;
          text-decoration-color: var(--color-border);
        }

        &:last-child {
          border-left: 1px solid var(--color-border);
          color: var(--color-brand);
          font-weight: 600;

          &::before {
            content: "✓ ";
          }
        }
      }

      &:hover {
        background: var(--color-brand-tint);
      }
    }
  }


  /* --- Curriculum --- */

  .curriculum {
    background: var(--color-bg);

    .lesson-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
      gap: var(--space-3);
    }
  }

  .lesson-card {
    container-type: inline-size;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    padding: var(--space-5);
    display: flex;
    gap: var(--space-4);
    align-items: flex-start;
    transition:
      box-shadow var(--duration-base) var(--ease-default),
      transform var(--duration-base) var(--ease-spring),
      border-color var(--duration-base) var(--ease-default);

    &:hover {
      box-shadow: var(--shadow-md);
      transform: translateY(-2px);
      border-color: var(--color-brand);
    }

    .lesson-card__num {
      font-size: var(--text-xs);
      font-weight: 800;
      color: var(--color-brand);
      background: var(--color-brand-tint);
      border-radius: var(--radius-sm);
      padding: var(--space-1) var(--space-2);
      min-width: 32px;
      text-align: center;
      flex-shrink: 0;
      letter-spacing: 0.02em;
    }

    .lesson-card__body {
      display: flex;
      flex-direction: column;
      gap: var(--space-1);
    }

    .lesson-card__title {
      font-size: var(--text-base);
      font-weight: 700;
      color: var(--color-text);
    }

    .lesson-card__desc {
      font-size: var(--text-sm);
      color: var(--color-text-muted);
      line-height: 1.55;
    }

    /* Variants */
    &.lesson-card--intro {
      .lesson-card__num {
        background: var(--color-surface-2);
        color: var(--color-text-muted);
      }
    }

    &.lesson-card--project {
      border-color: var(--color-brand);
      background: var(--color-brand-tint);

      .lesson-card__num {
        background: var(--color-brand);
        color: white;
      }

      .lesson-card__title {
        color: var(--color-brand);
      }
    }

    &.lesson-card--bonus {
      border-style: dashed;
      border-color: var(--color-brand-mid);

      .lesson-card__num {
        background: var(--color-brand-tint);
        color: var(--color-brand);
        font-size: var(--text-base);
      }
    }
  }


  /* --- CTA --- */

  .cta {
    background: var(--color-brand);

    .cta__inner {
      max-width: 1100px;
      margin: 0 auto;
      padding: var(--space-24) var(--space-6);
      text-align: center;
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: var(--space-6);
    }

    .cta__headline {
      font-size: var(--text-4xl);
      color: white;
      max-width: 600px;
    }

    .cta__sub {
      font-size: var(--text-lg);
      color: rgba(255, 255, 255, 0.75);
      max-width: 480px;
    }

    .cta__actions {
      display: flex;
      gap: var(--space-6);
      flex-wrap: wrap;
      justify-content: center;
      align-items: stretch;
    }

    .button {
      background: white;
      color: var(--color-brand);

      &:hover {
        background: var(--color-brand-tint);
        color: var(--color-brand-dark);
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
      }

      &.button--ghost {
        background: transparent;
        color: white;
        border-color: rgba(255, 255, 255, 0.5);

        &:hover {
          background: rgba(255, 255, 255, 0.12);
          border-color: white;
          color: white;
          box-shadow: none;
        }
      }
    }
  }


  /* --- Footer --- */

  .site-footer {
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);

    .site-footer__inner {
      max-width: 1100px;
      margin: 0 auto;
      padding: var(--space-6);
      display: flex;
      justify-content: space-between;
      align-items: center;
    }

    .site-footer__name {
      font-size: var(--text-sm);
      font-weight: 600;
      color: var(--color-text-muted);
    }

    .site-footer__links {
      display: flex;
      gap: var(--space-6);
      font-size: var(--text-sm);

      a {
        color: var(--color-text-subtle);

        &:hover {
          color: var(--color-brand);
        }
      }
    }
  }

}


/* ================================================================
  UTILITIES
================================================================ */
@layer utilities {
  .visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
}


/* ================================================================
  RESPONSIVE — collapse hero to single column on narrow viewports
================================================================ */
@media (max-width: 768px) {
  .hero {
    grid-template-columns: 1fr;

    .hero__headline {
      font-size: var(--text-4xl);
    }

    .hero__code-preview {
      display: none;
    }
  }

  .site-nav__links a:not(.button) {
    display: none;
  }

  .comparison-table__header span,
  .comparison-table__row span {
    padding: var(--space-3) var(--space-4);
  }
}


/* ================================================================
  REDUCED MOTION
================================================================ */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
