/*
 * VeriGraph product & pedagogical site stylesheet (world: "verigraph")
 * Built on the Hazen Studio kit (/hazen/hazen.css): zero external fonts,
 * measured WCAG 2.2 AA contrast in both light and dark themes, compositor-only
 * motion, native CSS scroll-driven animations with IntersectionObserver fallback,
 * and timing curves injected from verified `@motion` (motion.wasm).
 */

@layer base {
  [data-world="verigraph"] {
    --w-bg-l: #e7eceb;
    --w-bg-d: #080d11;
    --w-raise-l: #dce3e2;
    --w-raise-d: #0d151b;
    --w-surface-l: #f5f8f7;
    --w-surface-d: #121d25;
    --w-surface2-l: #cdd6d5;
    --w-surface2-d: #1b2a35;
    --w-text-l: #0d1518;
    --w-text-d: #ecf3f2;
    --w-text2-l: #2e3c41;
    --w-text2-d: #b7c6c8;
    --w-text3-l: #495a60;
    --w-text3-d: #8fa3a7;
    --w-line: 20%;
    --w-line-strong: 48%;

    /* Verdigris-emerald proof accent + warm gold secondary */
    --hz-accent-l: #076c52;
    --hz-accent-l-strong: #055641;
    --hz-on-accent-l: #f5fbf9;
    --hz-accent-text-light: #06634b;
    --hz-accent-d: #3bd496;
    --hz-accent-d-strong: #6be2b0;
    --hz-accent-text-dark: #3bd496;

    --hz-radius-xs: 2px;
    --hz-radius-sm: 2px;
    --hz-radius-md: 2px;
    --hz-radius-lg: 2px;
    --hz-radius-xl: 2px;
    --hz-radius-2xl: 2px;
    --hz-radius-full: 2px;

    /* Replaced at runtime by linear() curves sampled from verified @motion (motion.wasm) */
    --vg-out: var(--hz-ease-out);
    --vg-back: cubic-bezier(0.34, 1.45, 0.64, 1);
    --vg-inout: var(--hz-ease-in-out);
  }
}

/* Scroll-driven entry reveal (Baseline 2026-10, progressive enhancement + IO fallback) */
@property --vg-fade-start {
  syntax: "<length>";
  inherits: false;
  initial-value: 0px;
}
@property --vg-fade-end {
  syntax: "<length>";
  inherits: false;
  initial-value: 0px;
}

@layer components {
  .vg-header {
    position: sticky;
    top: 0;
    z-index: var(--hz-z-header);
    background: var(--hz-bg);
    border-bottom: 1px solid var(--hz-line-strong);
  }
  .vg-header__inner {
    display: flex;
    min-height: var(--hz-header-h);
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    padding-block: 0.5rem;
  }
  .vg-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.625rem;
    font-family: var(--hz-font-display);
    font-variation-settings: var(--hz-heading-settings);
    font-weight: 800;
    font-size: 1.25rem;
    color: var(--hz-text);
    text-decoration: none;
    letter-spacing: -0.02em;
  }
  .vg-brand__mark {
    display: inline-grid;
    grid-template-columns: repeat(2, 8px);
    gap: 2px;
    padding: 4px;
    border: 1px solid var(--hz-line-strong);
    background: var(--hz-surface);
  }
  .vg-brand__mark i {
    display: block;
    width: 8px;
    height: 8px;
    background: var(--hz-text-3);
  }
  .vg-brand__mark i:first-child,
  .vg-brand__mark i:last-child {
    background: var(--hz-accent);
  }
  .vg-nav {
    display: none;
    align-items: center;
    gap: 0.25rem;
    margin-inline-start: 0.5rem;
  }
  @media (min-width: 1120px) {
    .vg-nav {
      display: flex;
    }
  }
  .vg-header__actions {
    margin-inline-start: auto;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
  }
  .vg-lang-nav {
    display: inline-flex;
    border: 1px solid var(--hz-line-strong);
    background: var(--hz-surface);
  }
  .vg-lang-link {
    display: inline-flex;
    min-height: 2.75rem;
    min-width: 2.75rem;
    padding-inline: 0.65rem;
    align-items: center;
    justify-content: center;
    font-size: var(--hz-text-xs);
    font-weight: 650;
    color: var(--hz-text-2);
    text-decoration: none;
    position: relative;
  }
  .vg-lang-link + .vg-lang-link {
    border-inline-start: 1px solid var(--hz-line);
  }
  .vg-lang-link:hover {
    background: var(--hz-surface-2);
    color: var(--hz-text);
  }
  .vg-lang-link[aria-current="page"] {
    color: var(--hz-accent-text);
    background: var(--hz-accent-soft);
  }
  .vg-lang-link[aria-current="page"]::after {
    content: "";
    position: absolute;
    inset: auto 0 0;
    border-block-end: 3px solid var(--hz-accent);
  }

  /* Hero with live @aurora WebAssembly canvas */
  .vg-hero {
    position: relative;
    overflow: clip;
    padding-block: clamp(3rem, 2rem + 5vw, 6.5rem);
    border-bottom: 1px solid var(--hz-line-strong);
  }
  .vg-hero__canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0.34;
    pointer-events: none;
    image-rendering: auto;
  }
  [data-theme="light"] .vg-hero__canvas {
    opacity: 0.14;
  }
  .vg-hero__grid {
    position: relative;
    z-index: 1;
    display: grid;
    gap: clamp(2rem, 4vw, 3.5rem);
    align-items: start;
  }
  @media (min-width: 1024px) {
    .vg-hero__grid {
      grid-template-columns: minmax(0, 6.5fr) minmax(0, 5.5fr);
    }
  }
  .vg-hero__hud {
    margin-top: 1.75rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.625rem 1rem;
    padding: 0.75rem 1rem;
    border: 1px solid var(--hz-line-strong);
    background: var(--hz-surface);
    font-size: var(--hz-text-xs);
  }
  .vg-proof-line {
    font-family: var(--hz-font-mono);
    font-size: 0.78rem;
    line-height: 1.55;
    color: var(--hz-text-2);
    margin: 0.65rem 0 0;
  }
  .vg-proof-line b {
    color: var(--hz-accent-text);
    font-weight: 600;
  }

  /* Ruled sections */
  .vg-sec {
    padding-block: clamp(3.75rem, 2.5rem + 5vw, 6.75rem);
    border-bottom: 1px solid var(--hz-line-strong);
  }
  .vg-sec--alt {
    background: var(--hz-bg-raise);
  }
  .vg-sec__head {
    max-width: 48rem;
    margin-bottom: clamp(2rem, 4vw, 3rem);
  }
  .vg-sec__head h2 {
    margin: 0;
  }
  .vg-sec__head p {
    margin: 1rem 0 0;
  }

  /* Ruled metric strip */
  .vg-readings {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
    border: 1px solid var(--hz-line-strong);
    background: var(--hz-surface);
    margin: 2rem 0 0;
  }
  .vg-readings > div {
    padding: 1.125rem 1.25rem;
  }
  .vg-readings > div + div {
    border-inline-start: 1px solid var(--hz-line);
  }
  @media (max-width: 639px) {
    .vg-readings > div + div {
      border-inline-start: 0;
      border-block-start: 1px solid var(--hz-line);
    }
  }
  .vg-readings dt {
    font-size: var(--hz-text-xs);
    color: var(--hz-text-2);
  }
  .vg-readings dd {
    margin: 0.375rem 0 0;
    font-family: var(--hz-font-mono);
    font-variant-numeric: tabular-nums;
    font-size: clamp(1.5rem, 1.2rem + 1.2vw, 2.25rem);
    font-weight: 600;
    line-height: 1.05;
    color: var(--hz-accent-text);
  }

  /* Pedagogical comparison split */
  .vg-compare-grid {
    display: grid;
    gap: 1.5rem;
  }
  @media (min-width: 900px) {
    .vg-compare-grid {
      grid-template-columns: 1fr 1fr;
    }
  }
  .vg-panel {
    border: 1px solid var(--hz-line-strong);
    background: var(--hz-surface);
    padding: clamp(1.125rem, 2.2vw, 1.75rem);
  }
  .vg-panel--danger {
    border-color: var(--hz-danger);
  }
  .vg-panel--ok {
    border-color: var(--hz-accent);
  }
  .vg-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.2rem 0.55rem;
    border: 1px solid var(--hz-line-strong);
    font-family: var(--hz-font-mono);
    font-size: 0.75rem;
    color: var(--hz-text-2);
    background: var(--hz-bg-raise);
  }
  .vg-badge--ok {
    border-color: var(--hz-accent-line);
    color: var(--hz-accent-text);
    background: var(--hz-accent-soft);
  }
  .vg-badge--bad {
    border-color: var(--hz-danger);
    color: var(--hz-danger);
    background: var(--hz-danger-soft);
  }

  /* Interactive Annotated Code Explorer */
  .vg-annot-grid {
    display: grid;
    gap: 1.5rem;
    align-items: start;
  }
  @media (min-width: 980px) {
    .vg-annot-grid {
      grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
    }
  }
  .vg-code-frame {
    border: 1px solid var(--hz-line-strong);
    background: #0b1218;
    color: #e7eff2;
    overflow-x: auto;
  }
  .vg-code-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.55rem 0.9rem;
    border-bottom: 1px solid rgb(231 239 242 / 0.16);
    background: #101b24;
    font-family: var(--hz-font-mono);
    font-size: 0.75rem;
    color: #9cb0b8;
  }
  pre.vg-code {
    margin: 0;
    padding: 1rem 1.125rem;
    font-family: var(--hz-font-mono);
    font-size: 0.84rem;
    line-height: 1.65;
    overflow-x: auto;
    color: #e7eff2;
  }
  .vg-tok-kw { color: #7cc4ff; font-weight: 600; }
  .vg-tok-lab { color: #4ee0a6; }
  .vg-tok-port { color: #f6c96b; }
  .vg-tok-ty { color: #c4a7ff; }
  .vg-tok-op { color: #6fe3db; }
  .vg-tok-lit { color: #ff9f88; }
  .vg-tok-com { color: #859aa4; }

  .vg-hotspot {
    cursor: pointer;
    border-bottom: 1.5px dashed #4ee0a6;
    padding-inline: 2px;
    transition: background-color 150ms var(--vg-out), color 150ms var(--vg-out);
  }
  .vg-hotspot:hover,
  .vg-hotspot:focus-visible,
  .vg-hotspot.is-active {
    background: rgb(59 212 150 / 0.22);
    border-bottom-style: solid;
    outline: none;
  }
  .vg-hotspot--bad {
    border-bottom-color: #ff8e77;
  }
  .vg-hotspot--bad:hover,
  .vg-hotspot--bad:focus-visible,
  .vg-hotspot--bad.is-active {
    background: rgb(255 142 119 / 0.24);
  }
  .vg-hotspot:focus-visible {
    outline: 2px solid #4ee0a6;
    outline-offset: 2px;
  }

  .vg-annot-inspector {
    position: sticky;
    top: calc(var(--hz-header-h) + 1.25rem);
    border: 1px solid var(--hz-line-strong);
    background: var(--hz-surface);
    padding: 1.25rem 1.375rem;
  }
  .vg-pin-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    margin: 0 0 1rem;
    padding: 0;
    list-style: none;
  }
  .vg-pin-btn {
    display: inline-flex;
    min-height: 2.35rem;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.65rem;
    border: 1px solid var(--hz-line-strong);
    background: var(--hz-bg-raise);
    color: var(--hz-text-2);
    font-family: var(--hz-font-mono);
    font-size: 0.75rem;
    cursor: pointer;
  }
  .vg-pin-btn[aria-pressed="true"] {
    border-color: var(--hz-accent);
    background: var(--hz-accent-soft);
    color: var(--hz-accent-text);
    font-weight: 600;
  }

  /* Verified @layout SVG diagrams */
  .vg-stage {
    border: 1px solid var(--hz-line-strong);
    background: var(--hz-surface);
    padding: clamp(0.875rem, 2vw, 1.5rem);
    overflow-x: auto;
  }
  svg.vg-dg {
    display: block;
    width: 100%;
    height: auto;
    overflow: visible;
  }
  .vg-arr-fill { fill: var(--hz-text-3); }
  .vg-arr-ok-fill { fill: var(--hz-accent); }
  .vg-arr-bad-fill { fill: var(--hz-danger); }
  .vg-dg-edge {
    fill: none;
    stroke: var(--hz-line-strong);
    stroke-width: 1.65;
    stroke-dasharray: 1;
    stroke-dashoffset: calc(1 - var(--e, 1));
    transition: stroke 200ms var(--vg-out), stroke-width 200ms var(--vg-out);
  }
  .vg-dg-edge.vg-dg-back {
    stroke: var(--hz-danger);
    stroke-dasharray: 6 5;
    stroke-dashoffset: 0;
    opacity: var(--e, 1);
  }
  .vg-dg-edge.is-on {
    stroke: var(--hz-accent);
    stroke-width: 2.6;
  }
  .vg-dg-edge.vg-dg-back.is-on {
    stroke: var(--hz-danger);
    stroke-width: 2.8;
  }
  .vg-dg-node {
    opacity: var(--e, 1);
    cursor: pointer;
  }
  .vg-dg-node > rect:first-of-type {
    fill: var(--hz-bg-raise);
    stroke: var(--hz-line-strong);
    stroke-width: 1.25;
    transition: fill 200ms var(--vg-out), stroke 200ms var(--vg-out);
  }
  .vg-dg-node .vg-dg-corner {
    fill: var(--hz-line-strong);
    transition: fill 200ms var(--vg-out);
  }
  .vg-dg-node.vg-dg-ok > rect:first-of-type {
    stroke: var(--hz-accent);
  }
  .vg-dg-node.vg-dg-ok .vg-dg-corner {
    fill: var(--hz-accent);
  }
  .vg-dg-node.vg-dg-ai > rect:first-of-type {
    stroke: var(--hz-info);
  }
  .vg-dg-node.vg-dg-ai .vg-dg-corner {
    fill: var(--hz-info);
  }
  .vg-dg-node:hover > rect:first-of-type,
  .vg-dg-node.is-on > rect:first-of-type {
    fill: var(--hz-accent-soft);
    stroke: var(--hz-accent);
    stroke-width: 2;
  }
  .vg-dg-node.is-on .vg-dg-corner {
    fill: var(--hz-accent);
  }
  .vg-dg-node.is-bad > rect:first-of-type {
    fill: var(--hz-danger-soft);
    stroke: var(--hz-danger);
    stroke-width: 2;
  }
  .vg-dg-label {
    font-family: var(--hz-font-mono);
    font-size: 12.5px;
    font-weight: 600;
    fill: var(--hz-text);
  }
  .vg-dg-sub {
    font-family: var(--hz-font-sans);
    font-size: 10.5px;
    fill: var(--hz-text-2);
  }
  .vg-dg-packet {
    fill: var(--hz-accent);
    pointer-events: none;
  }
  .vg-dg-packet.is-bad {
    fill: var(--hz-danger);
  }
  .vg-dg-packet.is-ai {
    fill: var(--hz-info);
  }

  /* Pipeline interactive step list */
  .vg-tour-grid {
    display: grid;
    gap: 1.5rem;
    align-items: start;
  }
  @media (min-width: 1024px) {
    .vg-tour-grid {
      grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
    }
  }
  .vg-step-list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 0.5rem;
  }
  .vg-step-btn {
    width: 100%;
    text-align: start;
    display: grid;
    grid-template-columns: 2rem minmax(0, 1fr);
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    border: 1px solid var(--hz-line-strong);
    background: var(--hz-surface);
    color: var(--hz-text);
    cursor: pointer;
    position: relative;
  }
  .vg-step-btn:hover {
    background: var(--hz-surface-2);
  }
  .vg-step-btn[aria-current="step"] {
    border-color: var(--hz-accent);
    background: var(--hz-accent-soft);
  }
  .vg-step-btn[aria-current="step"][data-kind="bad"] {
    border-color: var(--hz-danger);
    background: var(--hz-danger-soft);
  }
  .vg-step-num {
    font-family: var(--hz-font-mono);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--hz-accent-text);
  }
  .vg-step-btn[data-kind="bad"] .vg-step-num {
    color: var(--hz-danger);
  }

  /* Accessible Tablist (modern-web-guidance `tabs` compliant) */
  .vg-tablist-scroller {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: inline proximity;
    border-bottom: 1px solid var(--hz-line-strong);
    gap: 0;
    --fade-size: 2.5rem;
    scroll-padding-inline: var(--fade-size);
  }
  .vg-tab {
    flex: none;
    scroll-snap-align: start;
    position: relative;
    min-height: 3rem;
    padding: 0.65rem 1.15rem;
    border: 0;
    border-inline-end: 1px solid var(--hz-line);
    background: var(--hz-surface);
    color: var(--hz-text-2);
    font-family: var(--hz-font-sans);
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
  }
  .vg-tab:hover {
    background: var(--hz-surface-2);
    color: var(--hz-text);
  }
  .vg-tab[aria-selected="true"] {
    color: var(--hz-accent-text);
    background: var(--hz-bg);
  }
  .vg-tab[aria-selected="true"]::after {
    content: "";
    position: absolute;
    inset: auto 0 0;
    border-block-end: 3px solid var(--hz-accent);
  }
  .vg-tabpanel-inner {
    border: 1px solid var(--hz-line-strong);
    border-top: 0;
    background: var(--hz-surface);
    padding: clamp(1.25rem, 2.5vw, 2rem);
  }

  /* Terminal replay */
  .vg-term {
    border: 1px solid var(--hz-line-strong);
    background: #080f14;
    color: #e4eef2;
  }
  .vg-term__bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.5rem 0.9rem;
    border-bottom: 1px solid rgb(228 238 242 / 0.16);
    background: #0f1a22;
    font-family: var(--hz-font-mono);
    font-size: 0.75rem;
    color: #9cb0b8;
  }
  .vg-term__body {
    padding: 1rem 1.125rem;
    font-family: var(--hz-font-mono);
    font-size: 0.8125rem;
    line-height: 1.6;
    max-height: 24rem;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
  }
  .vg-term__cmd {
    display: block;
    color: #4ee0a6;
    font-weight: 600;
    margin-top: 0.65rem;
  }
  .vg-term__cmd:first-child {
    margin-top: 0;
  }
  .vg-term__cmd::before {
    content: "$ ";
    color: #859aa4;
  }
  .vg-term__out {
    display: block;
    color: #c9d8de;
    margin-top: 0.25rem;
  }

  /* Interactive WASM lab layouts */
  .vg-lab-split {
    display: grid;
    gap: 1.5rem;
    align-items: start;
  }
  @media (min-width: 960px) {
    .vg-lab-split {
      grid-template-columns: minmax(0, 6.5fr) minmax(0, 5.5fr);
    }
  }
  .vg-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    margin-top: 0.625rem;
  }
  .vg-eval-grid {
    display: grid;
    gap: 0.625rem;
    margin-top: 1rem;
  }
  .vg-eval-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.65rem 0.85rem;
    border: 1px solid var(--hz-line-strong);
    background: var(--hz-bg-raise);
    font-size: var(--hz-text-sm);
  }
  .vg-eval-row output {
    font-family: var(--hz-font-mono);
    font-weight: 600;
  }

  /* Antigravity IDE annotated mockup */
  .vg-ide-window {
    border: 1px solid var(--hz-line-strong);
    background: #0b1218;
    color: #e6eff2;
  }
  .vg-ide-titlebar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.55rem 0.9rem;
    border-bottom: 1px solid rgb(230 239 242 / 0.16);
    background: #121e28;
    font-family: var(--hz-font-mono);
    font-size: 0.78rem;
  }
  .vg-ide-actions {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.375rem;
  }
  .vg-ide-btn {
    display: inline-flex;
    min-height: 2rem;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.6rem;
    border: 1px solid rgb(78 224 166 / 0.45);
    background: rgb(78 224 166 / 0.12);
    color: #4ee0a6;
    font-family: var(--hz-font-mono);
    font-size: 0.73rem;
    cursor: pointer;
  }
  .vg-ide-btn:hover,
  .vg-ide-btn[aria-pressed="true"] {
    background: #4ee0a6;
    color: #091216;
  }
  .vg-ide-panes {
    display: grid;
  }
  @media (min-width: 860px) {
    .vg-ide-panes {
      grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    }
  }
  .vg-ide-agent {
    border-top: 1px solid rgb(230 239 242 / 0.16);
    padding: 1rem 1.125rem;
    background: #0e1820;
    font-size: 0.85rem;
  }
  @media (min-width: 860px) {
    .vg-ide-agent {
      border-top: 0;
      border-inline-start: 1px solid rgb(230 239 242 / 0.16);
    }
  }

  /* Donut & bar chart colophon */
  .vg-colophon-charts {
    display: grid;
    gap: 1.5rem;
    align-items: start;
  }
  @media (min-width: 900px) {
    .vg-colophon-charts {
      grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
    }
  }
  .vg-donut-wrap {
    position: relative;
    max-width: 17rem;
    margin-inline: auto;
  }
  .vg-donut-center {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    text-align: center;
  }
  .vg-donut-center b {
    font-family: var(--hz-font-mono);
    font-size: 2rem;
    line-height: 1;
    color: var(--hz-accent-text);
  }
  .vg-curves-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr));
    gap: 0.75rem;
  }
  .vg-curve-card {
    border: 1px solid var(--hz-line-strong);
    background: var(--hz-surface);
    padding: 0.75rem;
  }

  /* Scroll-driven entry reveal (decorative progressive enhancement) */
  @media (prefers-reduced-motion: no-preference) {
    @supports ((animation-timeline: view()) and (animation-range: entry)) {
      @keyframes vg-tile-enter {
        from {
          opacity: 0.18;
          transform: translateY(18px);
        }
        to {
          opacity: 1;
          transform: none;
        }
      }
      .vg-scroll-reveal {
        animation: vg-tile-enter auto linear backwards;
        animation-timeline: view();
        animation-range: entry 0% entry 85%;
      }
    }
  }
}
