@layer reset, tokens, base, layout, components, pages;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html { min-width: 320px; scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
  body { margin: 0; overflow-x: hidden; }
  img, svg { display: block; max-width: 100%; }
  button, input, textarea, select { font: inherit; color: inherit; }
  button { cursor: pointer; }
}

@layer tokens {
  :root {
    color-scheme: dark;
    --bg: #070a0d;
    --bg-2: #10151a;
    --surface: rgba(18, 25, 31, .86);
    --surface-2: rgba(29, 39, 47, .76);
    --ink: #f6f1e8;
    --muted: #bac6cd;
    --soft: #82919b;
    --line: rgba(176, 205, 216, .18);
    --line-strong: rgba(237, 241, 232, .36);
    --ember: #e87436;
    --gold: #e1b15a;
    --teal: #5ec7b7;
    --steel: #89b7cf;
    --violet: #9c89d9;
    --danger: #e06767;
    --ok: #74c894;
    --radius: 8px;
    --shadow: 0 24px 80px rgba(0, 0, 0, .36);
    --ease: cubic-bezier(.2, .8, .2, 1);
    --font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Arial, sans-serif;
    --mono: "Cascadia Code", "Segoe UI Mono", Consolas, monospace;
  }
  html[data-theme="light"] {
    color-scheme: light;
    --bg: #f4f1ea;
    --bg-2: #e8edf0;
    --surface: rgba(255,255,255,.82);
    --surface-2: rgba(245,247,248,.88);
    --ink: #162028;
    --muted: #4c5b65;
    --soft: #6d7a83;
    --line: rgba(22,32,40,.16);
    --line-strong: rgba(22,32,40,.34);
    --shadow: 0 24px 70px rgba(42, 54, 64, .16);
  }
}

@layer base {
  body {
    min-height: 100vh;
    background:
      radial-gradient(1200px 700px at 20% -10%, rgba(94,199,183,.24), transparent 60%),
      radial-gradient(900px 620px at 88% 12%, rgba(232,116,54,.22), transparent 62%),
      linear-gradient(135deg, var(--bg), var(--bg-2));
    color: var(--ink);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.6;
  }
  body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image: linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
    background-size: 38px 38px;
    mask-image: linear-gradient(to bottom, rgba(0,0,0,.78), transparent 78%);
  }
  a { color: inherit; }
  h1, h2, h3 { margin: 0; line-height: 1.05; letter-spacing: 0; }
  h1 { font-size: clamp(2.4rem, 7vw, 5.8rem); }
  h2 { font-size: clamp(1.35rem, 3vw, 2.4rem); }
  p { margin: 0; color: var(--muted); }
  :focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; border-radius: 6px; }
  .skip-link { position: fixed; z-index: 999; top: 10px; left: 10px; transform: translateY(-140%); background: var(--ink); color: var(--bg); padding: .7rem 1rem; border-radius: 7px; }
  .skip-link:focus { transform: translateY(0); }
  .eyebrow { margin: 0 0 .8rem; color: var(--teal); font: 700 .78rem/1 var(--mono); letter-spacing: 0; text-transform: uppercase; }
  .lead { font-size: clamp(1.05rem, 1.4vw, 1.32rem); max-width: 68ch; }
  .hp { position: absolute; left: -100vw; width: 1px; height: 1px; opacity: 0; }
}

@layer layout {
  .site-header {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 72px;
    padding: 0 clamp(1rem, 4vw, 3rem);
    border-bottom: 1px solid transparent;
    backdrop-filter: blur(0);
    transition: background .28s var(--ease), border-color .28s var(--ease), backdrop-filter .28s var(--ease);
  }
  .site-header.is-stuck { background: rgba(7,10,13,.72); border-color: var(--line); backdrop-filter: blur(18px) saturate(1.2); }
  html[data-theme="light"] .site-header.is-stuck { background: rgba(244,241,234,.78); }
  .brand, .app-brand { display: inline-flex; align-items: center; gap: .75rem; text-decoration: none; font-weight: 800; }
  .brand img, .app-brand img { border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.28); }
  .site-nav { display: flex; align-items: center; gap: .35rem; }
  .site-nav a { min-height: 42px; display: inline-flex; align-items: center; padding: .5rem .8rem; color: var(--muted); text-decoration: none; border-radius: 8px; }
  .site-nav a:hover { color: var(--ink); background: rgba(255,255,255,.06); }
  .site-nav .nav-cta { background: var(--ink); color: var(--bg); font-weight: 800; }
  .site-main { position: relative; z-index: 1; }
  .site-footer { display: flex; justify-content: space-between; gap: 1rem; padding: 3rem clamp(1rem,4vw,3rem); border-top: 1px solid var(--line); color: var(--muted); }
  .site-footer div { display: grid; gap: .15rem; }
  .site-footer nav { display: flex; gap: 1rem; flex-wrap: wrap; }
  .hero-section {
    min-height: calc(100vh - 72px);
    display: grid;
    grid-template-columns: minmax(0, .95fr) minmax(320px, 1.05fr);
    align-items: center;
    gap: clamp(2rem, 6vw, 5rem);
    padding: clamp(2.5rem, 6vw, 6rem) clamp(1rem, 5vw, 5rem) 6rem;
  }
  .hero-copy { max-width: 760px; }
  .hero-actions { display: flex; flex-wrap: wrap; gap: .9rem; margin-top: 2rem; }
  .hero-visual { min-height: 420px; display: grid; place-items: center; transform-style: preserve-3d; }
  .hero-visual img { width: min(100%, 860px); filter: drop-shadow(0 36px 90px rgba(0,0,0,.36)); }
  .section-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; padding: 2rem clamp(1rem,5vw,5rem) 6rem; }
  .architecture-band { display: grid; grid-template-columns: minmax(0,.8fr) minmax(0,1.2fr); gap: 2rem; align-items: center; padding: 6rem clamp(1rem,5vw,5rem); border-block: 1px solid var(--line); background: linear-gradient(90deg, rgba(14,21,27,.7), rgba(28,34,40,.36)); }
  .links-band { display: flex; flex-wrap: wrap; gap: .8rem; padding: 2rem clamp(1rem,5vw,5rem) 6rem; }
  .legal-page { width: min(920px, calc(100% - 2rem)); margin: 4rem auto 7rem; padding: clamp(1.4rem, 4vw, 3rem); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
  .legal-page p + p { margin-top: 1rem; }
}

@layer components {
  .btn, button.btn, .logout-form button {
    min-height: 46px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .55rem;
    padding: .78rem 1.1rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255,255,255,.05);
    color: var(--ink);
    text-decoration: none;
    font-weight: 800;
    transition: transform .22s var(--ease), border-color .22s var(--ease), background .22s var(--ease);
  }
  .btn:hover, .logout-form button:hover { transform: translateY(-2px); border-color: var(--line-strong); background: rgba(255,255,255,.09); }
  .btn-primary { border-color: transparent; background: linear-gradient(135deg, var(--ember), var(--gold)); color: #160a03; box-shadow: 0 16px 42px rgba(232,116,54,.24); }
  .theme-toggle, .icon-button { width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 8px; background: rgba(255,255,255,.05); display: grid; place-items: center; }
  .theme-toggle span { width: 18px; height: 18px; border-radius: 50%; background: linear-gradient(135deg, var(--gold) 50%, transparent 50%); border: 2px solid var(--ink); }
  .feature-card, .panel, .metric-grid article {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: linear-gradient(180deg, var(--surface), rgba(13,18,23,.72));
    box-shadow: var(--shadow);
  }
  .feature-card { padding: 1rem; min-height: 330px; display: grid; align-content: start; gap: 1rem; transform-style: preserve-3d; }
  .feature-card img { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; border-radius: 7px; border: 1px solid var(--line); }
  .pipeline { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(6, minmax(80px, 1fr)); gap: .7rem; }
  .pipeline li { min-height: 74px; display: grid; place-items: center; text-align: center; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(255,255,255,.06); color: var(--muted); font-weight: 800; position: relative; }
  .pipeline li:not(:last-child)::after { content: ""; position: absolute; right: -.75rem; width: .8rem; height: 2px; background: linear-gradient(90deg, var(--teal), var(--ember)); }
  .links-band a { padding: .85rem 1rem; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(255,255,255,.05); text-decoration: none; }
  .stack-form { display: grid; gap: 1rem; }
  label { display: grid; gap: .45rem; color: var(--muted); font-weight: 700; }
  input, textarea, select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255,255,255,.06);
    color: var(--ink);
    padding: .85rem .95rem;
    outline: none;
  }
  textarea { resize: vertical; min-height: 120px; }
  input:focus, textarea:focus, select:focus { border-color: var(--teal); box-shadow: 0 0 0 4px rgba(94,199,183,.13); }
  .check { display: flex; align-items: flex-start; gap: .65rem; }
  .check input { width: auto; margin-top: .32rem; }
  .toast-stack { position: fixed; z-index: 100; right: 1rem; bottom: 1rem; display: grid; gap: .7rem; width: min(360px, calc(100vw - 2rem)); }
  .toast { padding: .9rem 1rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
  .scroll-progress { position: fixed; z-index: 120; left: 0; top: 0; width: 100%; height: 3px; background: linear-gradient(90deg, var(--teal), var(--ember), var(--gold)); transform-origin: left; transform: scaleX(0); }
  .markdown-output { color: var(--muted); }
  .markdown-output h1, .markdown-output h2, .markdown-output h3 { color: var(--ink); font-size: 1.2rem; margin: 1rem 0 .5rem; }
  .markdown-output pre { overflow: auto; padding: 1rem; border-radius: var(--radius); background: rgba(0,0,0,.22); border: 1px solid var(--line); }
}

@media (max-width: 980px) {
  .site-nav { display: none; }
  .hero-section, .architecture-band { grid-template-columns: 1fr; }
  .hero-section { min-height: auto; padding-top: 3rem; }
  .hero-visual { min-height: 260px; }
  .section-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pipeline { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .pipeline li::after { display: none; }
}

@media (max-width: 640px) {
  h1 { font-size: clamp(2.1rem, 13vw, 3.5rem); }
  .section-grid { grid-template-columns: 1fr; }
  .hero-actions, .site-footer { flex-direction: column; }
  .feature-card { min-height: auto; }
}
