@import url("tokens.css");

/*
  Site styles. Every value comes from tokens.css (see tokens/README.md).

  Cascade layers, lowest to highest priority. A later layer wins over an
  earlier one regardless of selector specificity, so the order is the rule:
    base        element defaults and reset
    type        type styles shared across the site
    components  reusable parts: header, menu, hero, catalog, diagrams, footer
    pages       layouts specific to one page
    motion      animation helpers and reduced-motion handling
    responsive  small-screen adjustments
    utilities   single-purpose overrides
*/
@layer base, type, components, pages, motion, responsive, utilities;

@layer base {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  html {
    scroll-behavior: smooth;
  }

  html,
  body {
    margin: 0;
    padding: 0;
  }

  body {
    min-height: 100vh;
    background: var(--kpd-color-surface-default);
    color: var(--kpd-color-text-primary);
    font-family: var(--kpd-type-family-ui);
    font-size: var(--kpd-type-size-body);
    font-weight: var(--kpd-type-weight-regular);
    line-height: 1.5;
    letter-spacing: -0.01em;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    transition: background-color var(--kpd-motion-duration-base) var(--kpd-motion-easing), color var(--kpd-motion-duration-base) var(--kpd-motion-easing);
  }

  img,
  svg {
    display: block;
    max-width: 100%;
  }

  a {
    color: inherit;
    text-decoration: none;
  }

  button {
    font: inherit;
    color: inherit;
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
  }

  h1,
  h2,
  h3,
  h4,
  p,
  ul,
  ol,
  dl,
  figure,
  blockquote {
    margin: 0;
  }

  ul,
  ol {
    padding: 0;
    list-style: none;
  }

  ::selection {
    background: var(--kpd-color-surface-inverse);
    color: var(--kpd-color-text-inverse);
  }

  :focus-visible {
    outline: 1px solid var(--kpd-color-focus-ring);
    outline-offset: 3px;
  }

  .skip {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 100;
    padding: 0.6rem 0.9rem;
    background: var(--kpd-color-surface-inverse);
    color: var(--kpd-color-text-inverse);
  }

  .skip:focus {
    left: var(--kpd-layout-gutter);
    top: 0.4rem;
  }
}

@layer type {
  /* ---------- type ---------- */

  .meta {
    font-size: var(--kpd-type-size-meta);
    letter-spacing: var(--kpd-type-tracking-meta);
    text-transform: uppercase;
    color: var(--kpd-color-text-secondary);
  }

  .display {
    font-size: var(--kpd-type-size-display);
    font-weight: var(--kpd-type-weight-regular);
    line-height: 0.9;
    letter-spacing: var(--kpd-type-tracking-display);
  }

  .lede {
    max-width: 34rem;
    font-family: var(--kpd-type-family-editorial);
    font-size: var(--kpd-type-size-lede);
    font-weight: var(--kpd-type-weight-regular);
    line-height: 1.3;
    letter-spacing: 0;
  }

  .link-line {
    display: inline-block;
    background-image: linear-gradient(currentColor, currentColor);
    background-position: 0 100%;
    background-repeat: no-repeat;
    background-size: 0 1px;
    transition: background-size var(--kpd-motion-duration-base) var(--kpd-motion-easing);
  }

  .link-line:hover {
    background-size: 100% 1px;
  }

  /* Links inside running text stay underlined so they read as links. */
  .link-inline {
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 0.2em;
    text-decoration-color: var(--kpd-color-text-secondary);
    transition: text-decoration-color var(--kpd-motion-duration-base) var(--kpd-motion-easing);
  }

  .link-inline:hover {
    text-decoration-color: currentColor;
  }
}

@layer components {
  /* ---------- chrome ---------- */

  .site-header {
    position: sticky;
    top: 0;
    z-index: 40;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    height: var(--kpd-comp-header-height);
    padding: 0 var(--kpd-layout-gutter);
    background: var(--kpd-color-surface-default);
    border-bottom: 1px solid var(--kpd-color-border-subtle);
  }

  .wordmark {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    justify-self: start;
    font-size: var(--kpd-type-size-caption);
    letter-spacing: 0.04em;
  }

  .nav {
    display: flex;
    gap: var(--kpd-space-lg);
  }

  .nav a,
  .menu-btn,
  .theme-toggle button {
    font-size: var(--kpd-type-size-meta);
    letter-spacing: var(--kpd-type-tracking-meta);
    text-transform: uppercase;
  }

  .nav a[aria-current="page"] {
    text-decoration: underline;
    text-underline-offset: 0.28em;
  }

  .header-end {
    display: flex;
    align-items: center;
    gap: var(--kpd-space-lg);
    justify-self: end;
  }

  /* Same idiom as the filter bar: the current option is underlined. */
  .theme-toggle {
    display: flex;
    align-items: center;
    gap: var(--kpd-space-xs);
  }

  .theme-toggle button {
    color: var(--kpd-color-text-secondary);
    transition: color var(--kpd-motion-duration-base) var(--kpd-motion-easing);
  }

  .theme-toggle button:hover {
    color: var(--kpd-color-text-primary);
  }

  .theme-toggle button[aria-pressed="true"] {
    color: var(--kpd-color-text-primary);
    text-decoration: underline;
    text-underline-offset: 0.28em;
  }

  .theme-toggle__rule {
    width: 1px;
    height: 0.75rem;
    background: var(--kpd-color-border-subtle);
  }

  .menu-btn {
    display: none;
    justify-self: end;
  }

  .menu {
    position: fixed;
    inset: var(--kpd-comp-header-height) 0 0 0;
    z-index: 30;
    display: none;
    flex-direction: column;
    gap: 0.4rem;
    padding: var(--kpd-space-lg) var(--kpd-layout-gutter);
    background: var(--kpd-color-surface-default);
  }

  .menu.is-open {
    display: flex;
  }

  body.is-menu-open {
    overflow: hidden;
  }

  .menu a {
    font-size: clamp(2rem, 8vw, 3.5rem);
    letter-spacing: var(--kpd-type-tracking-display);
    line-height: 1.1;
  }

  .menu .theme-toggle {
    margin-top: var(--kpd-space-lg);
    padding-top: var(--kpd-space-md);
    border-top: 1px solid var(--kpd-color-border-subtle);
  }

  .wrap {
    width: min(100%, var(--kpd-layout-max));
    margin: 0 auto;
    padding: 0 var(--kpd-layout-gutter);
  }

  .rule {
    height: 1px;
    background: var(--kpd-color-border-subtle);
    border: 0;
  }

  /* ---------- hero ---------- */

  .hero {
    display: grid;
    gap: var(--kpd-space-xl);
    padding: clamp(2.5rem, 7vw, 5.5rem) 0 clamp(2rem, 5vw, 3.5rem);
  }

  .hero__top {
    display: flex;
    justify-content: space-between;
    gap: var(--kpd-space-sm);
  }

  .hero__display {
    overflow: visible;
  }

  .hero__line {
    display: block;
  }

  .hero__note {
    max-width: 34rem;
    font-family: var(--kpd-type-family-editorial);
    font-size: var(--kpd-type-size-prose);
    line-height: 1.45;
    color: var(--kpd-color-text-secondary);
  }

  .hero__stage {
    height: 4.5rem;
    margin-top: var(--kpd-space-lg);
  }

  .hero__stage svg {
    width: 100%;
    height: 100%;
  }

  .figure__rule,
  .figure__draw {
    stroke: currentColor;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .figure__rule {
    stroke-width: 0.8;
    opacity: 0.35;
  }

  .figure__draw {
    stroke-width: 1.75;
  }

  /* ---------- catalog ---------- */

  .section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--kpd-space-sm);
    padding: var(--kpd-space-sm) 0;
    border-top: 1px solid var(--kpd-color-border-subtle);
  }

  .catalog {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--kpd-layout-gutter);
    padding: var(--kpd-space-3xs) 0 var(--kpd-space-4xl);
  }

  .product {
    min-width: 0;
  }

  .product a {
    display: grid;
    gap: 0.7rem;
  }

  .product__media {
    aspect-ratio: 4 / 5;
    background: var(--kpd-color-surface-raised);
    overflow: hidden;
  }

  .product__media .figure {
    width: 100%;
    height: 100%;
  }

  .modular__ink {
    fill: var(--kpd-color-graphic-primary);
  }

  .modular__soft {
    fill: var(--kpd-color-graphic-secondary);
  }

  .modular__ground {
    fill: var(--kpd-color-surface-raised);
  }

  .modular__accent {
    fill: var(--kpd-color-graphic-accent);
  }

  .modular__grid {
    fill: none;
    stroke: var(--kpd-color-border-subtle);
    stroke-width: 0.8;
  }

  .modular__wire {
    fill: none;
    stroke: var(--kpd-color-graphic-primary);
    stroke-width: 1.15;
    stroke-linejoin: miter;
  }

  .modular__wire--accent {
    stroke: var(--kpd-color-graphic-accent);
  }

  .modular__line {
    fill: none;
    stroke: var(--kpd-color-graphic-primary);
    stroke-width: 1.6;
  }

  .modular__line--accent {
    stroke: var(--kpd-color-graphic-accent);
  }

  .modular__ring-soft {
    fill: none;
    stroke: var(--kpd-color-graphic-secondary);
    stroke-width: 26;
    opacity: 0.26;
  }

  .modular__ring-bold {
    fill: none;
    stroke: var(--kpd-color-graphic-primary);
    stroke-width: 10;
  }

  .modular__cut {
    fill: none;
    stroke: var(--kpd-color-surface-raised);
    stroke-width: 18;
  }

  .modular__cut-bold {
    fill: none;
    stroke: var(--kpd-color-surface-raised);
    stroke-width: 18;
  }

  .modular__spoke {
    fill: none;
    stroke: var(--kpd-color-graphic-primary);
    stroke-width: 7.5;
  }

  .modular__spoke--accent {
    stroke: var(--kpd-color-graphic-accent);
  }

  .modular__chord {
    fill: none;
    stroke: var(--kpd-color-graphic-primary);
    stroke-width: 8.5;
  }

  .modular__chord--accent {
    stroke: var(--kpd-color-graphic-accent);
  }

  /* Optional subtle hover motion for modular figures (disabled when data-figure-motion="static") */
  .figure[data-figure-motion="subtle"] .modular__drift,
  .figure[data-figure-motion="subtle"] .modular__pulse,
  .figure[data-figure-motion="subtle"] .modular__turn,
  .figure[data-figure-motion="subtle"] .modular__turn-step,
  .figure[data-figure-motion="subtle"] .modular__dial,
  .figure[data-figure-motion="subtle"] .modular__slide {
    transform-origin: 0 0;
    transition: transform 0.78s var(--kpd-motion-easing);
    transition-delay: var(--delay, 0ms);
  }

  .product:hover .figure[data-figure-motion="subtle"] .modular__drift,
  .product:focus-within .figure[data-figure-motion="subtle"] .modular__drift,
  .pdp-hero__media:hover .figure[data-figure-motion="subtle"] .modular__drift {
    transform: rotate(1.8deg);
  }

  .product:hover .figure[data-figure-motion="subtle"] .modular__pulse,
  .product:focus-within .figure[data-figure-motion="subtle"] .modular__pulse,
  .pdp-hero__media:hover .figure[data-figure-motion="subtle"] .modular__pulse {
    transform: scale(1.45);
  }

  .product:hover .figure[data-figure-motion="subtle"] .modular__turn,
  .product:focus-within .figure[data-figure-motion="subtle"] .modular__turn,
  .pdp-hero__media:hover .figure[data-figure-motion="subtle"] .modular__turn {
    transform: rotate(90deg);
  }

  .product:hover .figure[data-figure-motion="subtle"] .modular__turn-step,
  .product:focus-within .figure[data-figure-motion="subtle"] .modular__turn-step,
  .pdp-hero__media:hover .figure[data-figure-motion="subtle"] .modular__turn-step {
    transform: rotate(45deg);
  }

  .product:hover .figure[data-figure-motion="subtle"] .modular__dial,
  .product:focus-within .figure[data-figure-motion="subtle"] .modular__dial,
  .pdp-hero__media:hover .figure[data-figure-motion="subtle"] .modular__dial {
    transform: rotate(9deg);
  }

  .product:hover .figure[data-figure-motion="subtle"] .modular__slide,
  .product:focus-within .figure[data-figure-motion="subtle"] .modular__slide,
  .pdp-hero__media:hover .figure[data-figure-motion="subtle"] .modular__slide {
    transform: translate(var(--mx, 0px), var(--my, 0px));
  }

  .product:hover .figure__draw {
    transform-origin: center;
  }

  .product__meta-row {
    display: flex;
    justify-content: space-between;
    font-size: var(--kpd-type-size-meta);
    letter-spacing: var(--kpd-type-tracking-meta);
    text-transform: uppercase;
    color: var(--kpd-color-text-secondary);
  }

  .product__title {
    font-size: var(--kpd-type-size-base);
    font-weight: var(--kpd-type-weight-regular);
    letter-spacing: -0.015em;
    width: fit-content;
    background-image: linear-gradient(currentColor, currentColor);
    background-position: 0 100%;
    background-repeat: no-repeat;
    background-size: 0 1px;
    transition: background-size var(--kpd-motion-duration-base) var(--kpd-motion-easing);
  }

  .product:hover .product__title {
    background-size: 100% 1px;
  }

  .product__sub {
    font-size: var(--kpd-type-size-meta);
    letter-spacing: 0.02em;
    color: var(--kpd-color-text-secondary);
  }

  /* Diagrams: drawn with site tokens so they follow light/dark. */
  .diagram {
    padding: var(--kpd-space-md);
    background: var(--kpd-comp-diagram-surface);
  }

  .dg {
    display: block;
    width: 100%;
    height: auto;
  }

  /* A figure that spans the full row; its diagram keeps the size of its neighbours. */
  .evidence--wide {
    grid-column: 1 / -1;
  }

  .evidence--wide .dg {
    max-width: calc((100% - var(--kpd-layout-gutter)) / 2 - var(--kpd-space-md));
    margin-inline: auto;
  }

  .dg-hair { stroke: var(--kpd-comp-diagram-line); stroke-width: 0.75; opacity: 0.3; }
  .dg-draw { fill: none; stroke: var(--kpd-comp-diagram-line); stroke-width: 1; stroke-linecap: round; stroke-linejoin: round; }
  .dg-dot { fill: var(--kpd-comp-diagram-line); }
  .dg-dot--hollow { fill: var(--kpd-comp-diagram-surface); stroke: var(--kpd-comp-diagram-line); stroke-width: 1; }
  .dg-dot--accent { fill: var(--kpd-comp-diagram-accent); }

  .dg-meta {
    fill: var(--kpd-comp-diagram-label);
    font-family: var(--kpd-type-family-ui);
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .dg-title {
    fill: var(--kpd-comp-diagram-title);
    font-family: var(--kpd-type-family-editorial);
    font-size: 19px;
  }

  .dg-title--sm { font-size: 15px; }
  .dg-accent { fill: var(--kpd-comp-diagram-accent-text); }

  .footer-contact {
    display: grid;
    justify-items: start;
    gap: var(--kpd-space-sm);
  }

  .footer-contact .footer-legal {
    width: 100%;
  }


  .dg-draw--accent { stroke: var(--kpd-comp-diagram-accent); }
  .dg-card { fill: var(--kpd-comp-diagram-card); stroke: var(--kpd-comp-diagram-line); stroke-width: 0.75; }
  .dg-tone { fill: var(--kpd-comp-diagram-line); }
  .dg-ink-line { fill: none; stroke: var(--kpd-comp-diagram-line); stroke-width: 2; opacity: 0.45; stroke-linecap: round; }

  /* ---------- footer ---------- */

  .site-footer {
    border-top: 1px solid var(--kpd-color-border-subtle);
    padding: 1.75rem 0 var(--kpd-space-2xl);
  }





  .footer-legal {
    display: flex;
    justify-content: space-between;
    gap: var(--kpd-space-sm);
    margin-top: var(--kpd-space-2xl);
    padding-top: var(--kpd-space-sm);
    font-size: var(--kpd-type-size-meta);
    letter-spacing: var(--kpd-type-tracking-meta);
    text-transform: uppercase;
    color: var(--kpd-color-text-secondary);
  }
}

@layer pages {
  /* ---------- about layout ---------- */

  .about-layout {
    display: grid;
    grid-template-columns: 1fr 1.2fr;
    gap: var(--kpd-layout-gutter);
    padding: var(--kpd-space-3xl) 0 var(--kpd-space-5xl);
    border-top: 1px solid var(--kpd-color-border-subtle);
  }

  .about__portrait {
    aspect-ratio: 3 / 4;
    object-fit: cover;
    width: 100%;
    height: auto;
    filter: grayscale(1) contrast(1.05);
  }

  .about__copy {
    display: grid;
    align-content: start;
    gap: var(--kpd-space-lg);
  }

  .about__note {
    display: grid;
    gap: 0.6rem;
    max-width: 34rem;
  }

  .about__note p:last-child,
  .about__note li {
    font-family: var(--kpd-type-family-editorial);
    font-size: var(--kpd-type-size-prose);
    line-height: 1.45;
  }

  .about__note ul {
    display: grid;
    gap: var(--kpd-space-xs);
  }

  .about__note strong,
  .project-content strong {
    font-weight: var(--kpd-type-weight-strong);
  }



  /* ---------- project / pdp ---------- */

  .crumb {
    display: flex;
    gap: 0.7rem;
    padding: 1.1rem 0;
    font-size: var(--kpd-type-size-meta);
    letter-spacing: var(--kpd-type-tracking-meta);
    text-transform: uppercase;
    color: var(--kpd-color-text-secondary);
  }

  .crumb a:hover {
    color: var(--kpd-color-text-primary);
  }

  .pdp-hero {
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: var(--kpd-layout-gutter);
    padding: var(--kpd-space-2xs) 0 3.5rem;
  }

  .pdp-hero__media {
    aspect-ratio: 4 / 5;
    background: var(--kpd-color-surface-raised);
  }

  .pdp-hero__media .figure {
    width: 100%;
    height: 100%;
  }

  .pager {
    display: grid;
    grid-template-columns: 1fr 1fr;
    border-top: 1px solid var(--kpd-color-border-subtle);
  }

  .pager a {
    display: grid;
    gap: 0.35rem;
    padding: 1.4rem 0 var(--kpd-space-2xl);
  }

  .pager > :last-child {
    text-align: right;
    border-left: 1px solid var(--kpd-color-border-subtle);
    padding-left: var(--kpd-layout-gutter);
  }

  .pager > :first-child {
    padding-right: var(--kpd-layout-gutter);
  }

  /* ---------- concise project pages ---------- */

  .project-intro {
    display: grid;
    justify-items: start;
    gap: var(--kpd-space-md);
    padding: clamp(2.5rem, 7vw, 5.5rem) 0;
    border-bottom: 1px solid var(--kpd-color-border-subtle);
  }

  .project-intro h1 {
    max-width: 12ch;
  }

  .project-content {
    display: grid;
    max-width: 58rem;
    padding: var(--kpd-space-sm) 0 3.5rem;
  }

  .project-content section {
    display: grid;
    grid-template-columns: minmax(8rem, 0.4fr) minmax(0, 1fr);
    column-gap: var(--kpd-layout-gutter);
    row-gap: var(--kpd-space-sm);
    padding: var(--kpd-space-lg) 0;
  }

  /* Label in the left column; everything else stacks in the right. */
  .project-content section > h2 {
    grid-column: 1;
    grid-row: 1;
  }

  .project-content section > :not(h2) {
    grid-column: 2;
  }

  .project-content h2 {
    font-size: var(--kpd-type-size-meta);
    font-weight: var(--kpd-type-weight-regular);
    letter-spacing: var(--kpd-type-tracking-meta);
    text-transform: uppercase;
  }

  .project-content p,
  .project-content li {
    font-family: var(--kpd-type-family-editorial);
    font-size: var(--kpd-type-size-prose);
    line-height: 1.45;
  }

  .project-content ul {
    display: grid;
    gap: 0.55rem;
  }

  .project-content li {
    position: relative;
    padding-left: 1.1rem;
  }

  .project-content li::before {
    position: absolute;
    top: 0.65em;
    left: 0;
    width: 0.4rem;
    border-top: 1px solid var(--kpd-color-border-strong);
    content: "";
  }

  .project-visuals {
    padding: var(--kpd-space-lg) 0 3.5rem;
    border-top: 1px solid var(--kpd-color-border-subtle);
  }

  .visual-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--kpd-layout-gutter);
    margin-top: var(--kpd-space-sm);
  }

  .evidence {
    min-width: 0;
  }

  .visual-placeholder {
    display: grid;
    min-height: 20rem;
    place-items: center;
    padding: var(--kpd-space-lg);
    background: var(--kpd-color-surface-raised);
    color: var(--kpd-color-text-secondary);
    font-size: var(--kpd-type-size-meta);
    letter-spacing: var(--kpd-type-tracking-meta);
    text-align: center;
    text-transform: uppercase;
  }

  .evidence figcaption {
    padding-top: 0.65rem;
  }

  .evidence img {
    display: block;
    width: 100%;
    height: auto;
  }
}

@layer motion {
  /* ---------- motion helpers ---------- */

  code {
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 0.85em;
    background: var(--kpd-color-surface-raised);
    padding: 0.05em 0.3em;
  }

  @media (prefers-reduced-motion: reduce) {
    html {
      scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
      animation: none !important;
      transition: none !important;
    }

    .figure[data-figure-motion="subtle"] .modular__drift,
    .figure[data-figure-motion="subtle"] .modular__pulse,
    .figure[data-figure-motion="subtle"] .modular__turn,
    .figure[data-figure-motion="subtle"] .modular__turn-step,
    .figure[data-figure-motion="subtle"] .modular__dial,
    .figure[data-figure-motion="subtle"] .modular__slide {
      transform: none !important;
    }
  }
}

@layer responsive {
  /* ---------- responsive ---------- */

  @media (max-width: 860px) {
    .site-header {
      grid-template-columns: 1fr auto;
    }

    .nav,
    .header-end {
      display: none;
    }

    .menu-btn {
      display: block;
    }

    .about-layout,
    .pdp-hero,
    .pager {
      grid-template-columns: 1fr;
    }

    .pager > :last-child {
      text-align: left;
      border-left: 0;
      border-top: 1px solid var(--kpd-color-border-subtle);
      padding-left: 0;
    }

    .hero__stage {
      height: 3rem;
    }

    .project-content section {
      grid-template-columns: 1fr;
      gap: var(--kpd-space-xs);
    }

    .project-content section > :not(h2) {
      grid-column: 1;
    }
  }

  @media (max-width: 560px) {
    .catalog,
    .visual-grid {
      grid-template-columns: 1fr;
    }

    .evidence--wide .dg {
      max-width: none;
    }

    .product__media {
      aspect-ratio: 4 / 3;
    }

    .hero__top {
      flex-direction: column;
    }
  }

  @media (max-width: 640px) {
    .diagram { padding: var(--kpd-space-2xs); }
  }
}

@layer utilities {
  [hidden] { display: none !important; }
}
