@layer reset, tokens, base, components, responsive;

@layer tokens {
  :root {
    --ink-0: oklch(0.145 0.006 80);
    --ink-1: oklch(0.19 0.006 80);
    --ink-2: oklch(0.245 0.008 80);
    --paper-0: oklch(0.94 0.008 90);
    --paper-1: oklch(0.79 0.01 90);
    --paper-2: oklch(0.65 0.012 90);
    --orange-0: oklch(0.69 0.22 43);
    --line: oklch(0.34 0.01 80);
    --bg: var(--ink-0);
    --surface: var(--ink-1);
    --surface-raised: var(--ink-2);
    --text: var(--paper-0);
    --muted: var(--paper-1);
    --subtle: var(--paper-2);
    --accent: var(--orange-0);
    --font-display: "Space Grotesk", sans-serif;
    --font-mono: "DM Mono", monospace;
    --gutter: clamp(16px, 2vw, 32px);
  }
}

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html { scroll-behavior: smooth; }
  body, h1, h2, h3, p, ol, dl, dd { margin: 0; }
  img, svg, canvas { display: block; max-width: 100%; }
  button, a { font: inherit; }
  button { color: inherit; }
}

@layer base {
  body {
    min-height: 100dvh;
    overflow-x: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-display);
    font-size: 16px;
    line-height: 1.6;
  }
  a { color: inherit; text-decoration: none; }
  button { cursor: pointer; }
  a, button { -webkit-tap-highlight-color: transparent; }
  :focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
  ::selection { background: var(--accent); color: var(--ink-0); }
  .micro {
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.5;
    letter-spacing: .08em;
    text-transform: uppercase;
  }
  .orange { color: var(--accent); }
  .skip-link {
    position: fixed;
    top: 8px;
    left: 8px;
    z-index: 50;
    padding: 10px 14px;
    background: var(--accent);
    color: var(--ink-0);
    transform: translateY(-150%);
    transition: transform 160ms ease-out;
  }
  .skip-link:focus { transform: translateY(0); }
}

@layer components {
  .site-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    min-height: 72px;
    padding: 0 var(--gutter);
    border-bottom: 1px solid var(--line);
    background: color-mix(in oklch, var(--bg) 92%, transparent);
    backdrop-filter: blur(16px);
  }
  .brand { display: inline-flex; align-items: center; gap: 10px; width: max-content; font-weight: 700; letter-spacing: -.02em; }
  .brand svg { width: 28px; height: 28px; }
  .brand path { fill: none; stroke: var(--accent); stroke-width: 2.4; }
  .site-header nav { display: flex; gap: 32px; }
  .site-header nav a, .domain {
    position: relative;
    padding: 22px 0;
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 12px;
    text-transform: uppercase;
  }
  .site-header nav a::after {
    content: "";
    position: absolute;
    right: 0;
    bottom: 15px;
    left: 0;
    height: 1px;
    background: var(--accent);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 180ms ease-out;
  }
  .site-header nav a:hover::after, .site-header nav a:focus-visible::after { transform: scaleX(1); }
  .domain { justify-self: end; }

  .hero {
    position: relative;
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    align-items: end;
    gap: 20px;
    min-height: calc(100svh - 72px);
    padding: clamp(48px, 8vh, 96px) var(--gutter) 40px;
    border-bottom: 1px solid var(--line);
    overflow: hidden;
  }
  .hero-title-wrap { grid-column: 1 / 10; position: relative; z-index: 2; }
  .hero h1 {
    margin-top: 20px;
    font-size: clamp(72px, 13.7vw, 208px);
    font-weight: 700;
    line-height: .77;
    letter-spacing: -.075em;
  }
  .hero-copy { grid-column: 10 / 13; position: relative; z-index: 2; padding-bottom: 8px; }
  .hero-copy p { max-width: 34ch; color: var(--muted); font-size: 17px; line-height: 1.65; }
  .primary-link {
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 48px;
    margin-top: 32px;
    padding: 12px 0;
    border-bottom: 1px solid var(--accent);
    color: var(--text);
    font-weight: 600;
  }
  .primary-link span:last-child { color: var(--accent); transition: transform 180ms ease-out; }
  .primary-link:hover span:last-child { transform: translate(4px, 4px); }
  .hero-mark { position: absolute; right: 10vw; bottom: 4vh; width: min(28vw, 420px); opacity: .12; }
  .hero-mark path { fill: none; stroke: var(--accent); stroke-width: 1; }

  .library { padding: 32px var(--gutter) clamp(72px, 10vw, 144px); scroll-margin-top: 88px; }
  .section-heading {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 20px;
    margin-bottom: 32px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--line);
  }
  .section-heading h2 { font-size: clamp(26px, 3vw, 42px); line-height: 1.1; letter-spacing: -.04em; }
  .category-filters { display: flex; flex-wrap: wrap; gap: 8px; margin: -8px 0 28px; }
  .category-filter {
    min-height: 44px;
    padding: 10px 16px;
    border: 1px solid var(--line);
    border-radius: 0;
    background: transparent;
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 11px;
    text-transform: uppercase;
  }
  .category-filter:hover { border-color: var(--muted); color: var(--text); }
  .category-filter[aria-pressed="true"] { border-color: var(--accent); background: var(--accent); color: var(--ink-0); }
  .catalogue-layout { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 20px; align-items: start; }
  .model-index { grid-column: span 3; }
  .model-list { display: grid; gap: 12px; }
  .model-group-title { margin: 18px 0 2px; color: var(--subtle); font-family: var(--font-mono); font-size: 10px; font-weight: 400; letter-spacing: .06em; line-height: 1.5; text-transform: uppercase; }
  .model-group-title:first-child { margin-top: 0; }
  .model-card {
    display: grid;
    grid-template-columns: 74px 1fr;
    gap: 14px;
    width: 100%;
    min-height: 92px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 0;
    background: transparent;
    text-align: left;
    transition: background 180ms ease-out, border-color 180ms ease-out, transform 180ms ease-out;
  }
  .model-card:hover { transform: translateY(-2px); border-color: var(--muted); background: var(--surface); }
  .model-card[aria-pressed="true"] { border-color: var(--accent); background: var(--surface); }
  .model-card img { width: 74px; height: 74px; object-fit: cover; background: var(--surface); }
  .model-card-copy { display: flex; flex-direction: column; justify-content: space-between; min-width: 0; padding: 3px 4px 3px 0; }
  .model-card strong { font-size: 14px; line-height: 1.3; }
  .model-card small { color: var(--muted); font-family: var(--font-mono); font-size: 10px; letter-spacing: .06em; text-transform: uppercase; }
  .index-note { max-width: 32ch; margin-top: 20px; color: var(--subtle); font-family: var(--font-mono); font-size: 11px; line-height: 1.6; }

  .model-stage { grid-column: span 6; min-width: 0; }
  .viewer {
    position: relative;
    height: clamp(420px, 50vw, 590px);
    max-height: 65vh;
    min-height: 420px;
    overflow: hidden;
    border: 1px solid var(--line);
    background: var(--surface);
  }
  .canvas-host { position: absolute; inset: 0; }
  .canvas-host canvas { width: 100%; height: 100%; touch-action: none; }
  .viewer-poster { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: .78; }
  .viewer-poster.hidden { display: none; }
  .viewer-topline, .viewer-bottomline {
    position: absolute;
    right: 16px;
    left: 16px;
    z-index: 3;
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: none;
  }
  .viewer-topline { top: 16px; }
  .viewer-bottomline { bottom: 16px; color: var(--muted); font-family: var(--font-mono); font-size: 10px; letter-spacing: .05em; }
  .viewer-badge { padding: 6px 8px; background: var(--bg); color: var(--muted); font-family: var(--font-mono); font-size: 10px; letter-spacing: .08em; }
  .icon-button {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border: 1px solid var(--line);
    border-radius: 0;
    background: var(--bg);
    pointer-events: auto;
    transition: border-color 160ms ease-out, color 160ms ease-out;
  }
  .icon-button:hover { border-color: var(--accent); color: var(--accent); }
  .icon-button svg { width: 20px; height: 20px; }
  .icon-button path { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .text-button {
    min-height: 44px;
    padding: 8px 0 8px 16px;
    border: 0;
    background: transparent;
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 11px;
    pointer-events: auto;
  }
  .text-button[aria-pressed="true"] { color: var(--accent); }
  .loading {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: grid;
    place-items: center;
    background: color-mix(in oklch, var(--surface) 76%, transparent);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 12px;
  }
  .loading.hidden { display: none; }
  .loading.error { padding: 32px; text-align: center; color: var(--muted); }
  .stage-caption { display: flex; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); font-family: var(--font-mono); font-size: 11px; }
  .stage-caption span:last-child { color: var(--muted); text-align: right; }

  .model-details { grid-column: span 3; min-width: 0; }
  .model-details h3 { margin: 12px 0 16px; font-size: clamp(28px, 3vw, 44px); line-height: .98; letter-spacing: -.055em; }
  .model-details > p:not(.micro):not(.fit-note) { color: var(--muted); font-size: 15px; line-height: 1.65; }
  .spec-list { margin-top: 24px; border-top: 1px solid var(--line); }
  .spec-list > div { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .spec-list dt { color: var(--muted); font-family: var(--font-mono); font-size: 10px; text-transform: uppercase; }
  .spec-list dd { text-align: right; font-family: var(--font-mono); font-size: 11px; }
  .downloads { display: grid; gap: 8px; margin-top: 24px; }
  .download-link {
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 46px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    font-family: var(--font-mono);
    font-size: 11px;
    transition: background 160ms ease-out, border-color 160ms ease-out;
  }
  .download-link:first-child { border-color: var(--accent); background: var(--accent); color: var(--ink-0); font-weight: 500; }
  .download-link:hover { border-color: var(--accent); }
  .download-link:not(:first-child):hover { background: var(--surface); }
  .fit-note { margin-top: 20px; color: var(--subtle); font-size: 12px; line-height: 1.6; }

  .print-guide {
    scroll-margin-top: 72px;
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 20px;
    padding: clamp(64px, 9vw, 128px) var(--gutter);
    border-top: 1px solid var(--line);
    background: var(--surface);
  }
  .print-guide > div:first-child { grid-column: 1 / 7; }
  .print-guide h2 { margin-top: 20px; font-size: clamp(42px, 6.5vw, 96px); line-height: .92; letter-spacing: -.065em; }
  .guide-copy { grid-column: 8 / 13; }
  .guide-copy > p { max-width: 55ch; color: var(--muted); font-size: 17px; line-height: 1.7; }
  .guide-copy ol { margin-top: 36px; padding: 0; list-style: none; border-top: 1px solid var(--line); }
  .guide-copy li { display: grid; grid-template-columns: 42px 1fr; gap: 12px; padding: 16px 0; border-bottom: 1px solid var(--line); }
  .guide-copy li span { color: var(--accent); font-family: var(--font-mono); font-size: 12px; }

  footer {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 20px;
    align-items: center;
    min-height: 96px;
    padding: 24px var(--gutter);
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: .04em;
  }
  footer a { justify-self: end; min-height: 44px; padding: 10px 0; color: var(--text); }
}

@layer responsive {
  @media (max-width: 1100px) {
    .hero-title-wrap { grid-column: 1 / 9; }
    .hero-copy { grid-column: 9 / 13; }
    .model-index { grid-column: span 4; }
    .model-stage { grid-column: span 8; }
    .model-details { grid-column: 5 / 13; margin-top: 24px; }
    .model-details > p:not(.micro):not(.fit-note) { max-width: 65ch; }
    .downloads { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  }
  @media (max-width: 760px) {
    .site-header { grid-template-columns: 1fr auto; min-height: 64px; }
    .site-header nav { gap: 18px; }
    .site-header nav a { padding: 20px 0; }
    .domain { display: none; }
    .hero { min-height: 76svh; padding-top: 48px; }
    .hero-title-wrap { grid-column: 1 / 13; }
    .hero h1 { font-size: clamp(66px, 20vw, 120px); line-height: .8; }
    .hero-copy { grid-column: 2 / 13; margin-top: 24px; }
    .hero-copy p { font-size: 16px; }
    .hero-mark { right: -8vw; bottom: 20vh; width: 58vw; }
    .section-heading { align-items: flex-start; flex-direction: column; gap: 8px; }
    .model-index, .model-stage, .model-details { grid-column: 1 / 13; }
    .model-index { margin-bottom: 12px; }
    .model-card { grid-template-columns: 84px 1fr; }
    .model-card img { width: 84px; height: 84px; }
    .index-note { display: none; }
    .viewer { height: 390px; min-height: 390px; max-height: none; }
    .model-details { margin-top: 24px; }
    .model-details h3 { font-size: 40px; }
    .stage-caption { flex-direction: column; gap: 4px; }
    .stage-caption span:last-child { text-align: left; }
    .print-guide > div:first-child, .guide-copy { grid-column: 1 / 13; }
    .guide-copy { margin-top: 32px; }
    .print-guide h2 { font-size: clamp(44px, 13vw, 72px); }
    footer { grid-template-columns: 1fr auto; }
    footer span:nth-child(2) { display: none; }
  }
  @media (max-width: 420px) {
    .site-header nav a { font-size: 10px; }
    .brand { font-size: 14px; }
    .downloads { grid-template-columns: 1fr; }
    .viewer { height: 350px; min-height: 350px; }
    .viewer-bottomline > span { max-width: 160px; }
  }
  @media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after { transition-duration: .01ms !important; }
  }
}
