/* ==========================================================================
   KARKHANA — Design System
   01_foundations.css : tokens, reset, typography, layout primitives
   --------------------------------------------------------------------------
   The system is called "The Technical Atelier": the visual language of a
   spec sheet (dimension lines, tick marks, monospace labels, measured
   swatches) rendered with the material richness of a textile mill.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. TOKENS
   -------------------------------------------------------------------------- */
:root {
  /* --- 1.1 Colour primitives ------------------------------------------- */
  --ink:        #0D1014;   /* primary dark ground                          */
  --ink-2:      #161B22;   /* raised dark surface                          */
  --ink-3:      #1F252D;   /* raised dark surface, lighter                 */
  --ink-line:   #2A323C;   /* hairline on dark                             */
  --paper:      #F2EEE6;   /* light spec-sheet ground                      */
  --paper-2:    #E7E1D5;   /* kraft / secondary light                       */
  --paper-3:    #DAD3C4;   /* deeper kraft                                 */
  --paper-line: #D5CDBC;   /* hairline on light                            */

  --marigold:    #E9A319;  /* primary accent — turmeric / marigold dye      */
  --marigold-hi: #FFC155;  /* accent on dark grounds                       */
  --marigold-dk: #B97B0A;  /* accent text on paper                         */
  --indigo:      #16264A;  /* secondary — dye-vat indigo, structural        */
  --indigo-lt:   #2C4374;
  --madder:      #B8402C;  /* signal / scarcity only                       */
  --madder-lt:   #E06A52;

  --slate:   #7C8590;      /* muted metadata                               */
  --slate-d: #545C66;      /* muted metadata on dark                       */
  --slate-l: #9AA1A9;      /* muted metadata on light                      */

  /* --- 1.2 Semantic tokens --------------------------------------------- */
  --bg:        var(--ink);
  --bg-soft:   var(--ink-2);
  --bg-raise:  var(--ink-3);
  --fg:        #EDE9E1;
  --fg-muted:  var(--slate-l);
  --line:      var(--ink-line);
  --accent:    var(--marigold);
  --accent-fg: var(--ink);
  --focus:     var(--marigold-hi);

  /* --- 1.3 Typography --------------------------------------------------- */
  --f-display: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --f-serif:   "Instrument Serif", Georgia, "Times New Roman", serif;
  --f-mono:    "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --f-body:    "Archivo", "Helvetica Neue", Arial, sans-serif;

  --fs-display-xl: clamp(3.1rem, 8.6vw, 8.25rem);
  --fs-display-l:  clamp(2.5rem, 5.8vw, 5rem);
  --fs-display-m:  clamp(1.95rem, 3.9vw, 3.35rem);
  --fs-h2:         clamp(1.7rem, 3.1vw, 2.85rem);
  --fs-h3:         clamp(1.2rem, 1.9vw, 1.7rem);
  --fs-h4:         clamp(1.02rem, 1.3vw, 1.16rem);
  --fs-lead:       clamp(1.05rem, 1.35vw, 1.3rem);
  --fs-body:       1.03125rem;
  --fs-sm:         0.9375rem;
  --fs-xs:         0.875rem;
  --fs-mono:       0.765rem;
  --fs-mono-lg:   0.875rem;

  --lh-tight: 0.94;
  --lh-snug:  1.16;
  --lh-body:  1.66;
  --tracking-display: -0.035em;
  --tracking-mono: 0.14em;

  /* --- 1.4 Space (8px baseline) ----------------------------------------- */
  --s-1: 4px;   --s-2: 8px;   --s-3: 12px;  --s-4: 16px;
  --s-5: 24px;  --s-6: 32px;  --s-7: 40px;  --s-8: 48px;
  --s-9: 64px;  --s-10: 80px; --s-11: 104px; --s-12: 136px;
  --s-13: 176px;

  --section-y: clamp(64px, 9vw, 136px);
  --gutter:    clamp(20px, 4vw, 48px);
  --shell:     1440px;
  --measure:   68ch;

  /* --- 1.5 Geometry ------------------------------------------------------ */
  --r-sm: 2px;     /* technical default — hard corners                     */
  --r-md: 4px;
  --r-pill: 999px;
  --hair: 1px;

  /* --- 1.6 Motion -------------------------------------------------------- */
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --ease-io:  cubic-bezier(.65, 0, .35, 1);
  --t-fast: 180ms;
  --t-med:  380ms;
  --t-slow: 620ms;
  --t-reveal: 700ms;

  /* --- 1.7 Texture ------------------------------------------------------- */
  --blueprint: rgba(255, 255, 255, .038);
  --stitch-c: rgba(233, 163, 25, .55);
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.82' numOctaves='3'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='.42'/%3E%3C/svg%3E");
}

/* Light-ground overrides.
   --accent is deliberately a deeper marigold here: the bright #E9A319 only
   reaches 1.87:1 on paper, so a separate "text marigold" is required for AA. */
.theme-paper {
  --bg:        var(--paper);
  --bg-soft:   var(--paper-2);
  --bg-raise:  #FBF9F4;
  --fg:        #171B20;
  --fg-muted:  #5C636C;
  --line:      var(--paper-line);
  --accent:    #7E5406;
  --accent-fg: #171B20;
  --focus:     var(--indigo);
  --stitch-c: rgba(22, 38, 74, .3);
  --blueprint: rgba(22, 38, 74, .04);
  color: var(--fg);
  background: var(--bg);
}

/* --------------------------------------------------------------------------
   2. RESET
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

* { margin: 0; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 92px;
}

body {
  font-family: var(--f-body);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  color: var(--fg);
  background: var(--ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  font-feature-settings: "kern" 1, "liga" 1, "calt" 1;
}

img, svg, video, canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
}

button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; padding: 0; }

::selection {
  background: var(--marigold);
  color: var(--ink);
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
  border-radius: 1px;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

/* --------------------------------------------------------------------------
   3. TYPOGRAPHY
   -------------------------------------------------------------------------- */
.display-xl, .display-l, .display-m, h1, h2, h3, h4 {
  font-family: var(--f-display);
  font-weight: 700;
  line-height: var(--lh-snug);
  letter-spacing: var(--tracking-display);
  text-wrap: balance;
}

h1 { font-size: var(--fs-display-xl); line-height: var(--lh-tight); font-weight: 800; }
h2 { font-size: var(--fs-h2); }
h3 { font-size: var(--fs-h3); letter-spacing: -.02em; }
h4 { font-size: var(--fs-h4); letter-spacing: -.012em; font-weight: 600; }

.display-xl { font-size: var(--fs-display-xl); line-height: var(--lh-tight); font-weight: 800; }
.display-l  { font-size: var(--fs-display-l);  line-height: 1.0; }
.display-m  { font-size: var(--fs-display-m); }

.serif {
  font-family: var(--f-serif);
  font-weight: 400;
  letter-spacing: -.01em;
  font-style: italic;
}

.lead {
  font-size: var(--fs-lead);
  line-height: 1.52;
  color: var(--fg-muted);
  max-width: 56ch;
  text-wrap: pretty;
}

.measure { max-width: var(--measure); }
.measure-sm { max-width: 52ch; }

p { text-wrap: pretty; }

/* Monospace label — the system's connective tissue */
.mono {
  font-family: var(--f-mono);
  font-size: var(--fs-mono);
  font-weight: 500;
  letter-spacing: var(--tracking-mono);
  text-transform: uppercase;
  font-feature-settings: "zero" 1;
}

.mono-lg { font-size: var(--fs-mono-lg); letter-spacing: .1em; }
.muted { color: var(--fg-muted); }
.accent { color: var(--accent); }
.nowrap { white-space: nowrap; }

/* Eyebrow — section marker with a leading tick */
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--s-3);
  font-family: var(--f-mono);
  font-size: var(--fs-mono);
  font-weight: 500;
  letter-spacing: var(--tracking-mono);
  text-transform: uppercase;
  color: var(--accent);
}
.eyebrow::before {
  content: "";
  width: 26px;
  height: 1px;
  background: currentColor;
  opacity: .7;
}

/* Section numeral — big Instrument Serif index */
.numeral {
  font-family: var(--f-serif);
  font-size: clamp(3.2rem, 7vw, 6rem);
  line-height: .8;
  color: var(--accent);
  opacity: .5;
  font-weight: 400;
}

/* --------------------------------------------------------------------------
   4. LAYOUT PRIMITIVES
   -------------------------------------------------------------------------- */
.shell {
  width: 100%;
  max-width: var(--shell);
  margin-inline: auto;
  padding-inline: var(--gutter);
}
.shell-narrow { max-width: 980px; }

.section { padding-block: var(--section-y); position: relative; background: var(--bg); color: var(--fg); }
.section-sm { padding-block: clamp(44px, 6vw, 80px); }

.grid { display: grid; gap: var(--s-6); }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.split { display: grid; gap: clamp(32px, 5vw, 88px); align-items: start; }
.split-7-5 { grid-template-columns: 7fr 5fr; }
.split-8-4 { grid-template-columns: 8fr 4fr; }
.split-5-7 { grid-template-columns: 5fr 7fr; }
.split-6-6 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }

@media (max-width: 900px) {
  .g-3, .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split-7-5, .split-8-4, .split-5-7, .split-6-6 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 620px) {
  .g-2, .g-3, .g-4 { grid-template-columns: minmax(0, 1fr); }
}

.stack { display: flex; flex-direction: column; }
.stack-2 { gap: var(--s-2); } .stack-3 { gap: var(--s-3); }
.stack-4 { gap: var(--s-4); } .stack-5 { gap: var(--s-5); }
.stack-6 { gap: var(--s-6); } .stack-7 { gap: var(--s-7); }
.stack-8 { gap: var(--s-8); } .stack-10 { gap: var(--s-10); }

.row { display: flex; align-items: center; gap: var(--s-4); flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); flex-wrap: wrap; }

/* Blueprint grid overlay */
.blueprint { position: relative; }
.blueprint::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(var(--blueprint) 1px, transparent 1px),
    linear-gradient(90deg, var(--blueprint) 1px, transparent 1px);
  background-size: 64px 64px;
  z-index: 0;
}
.blueprint > * { position: relative; z-index: 1; }

/* --------------------------------------------------------------------------
   5. THE SADDLE-STITCH RULE — the system's recurring motif
   -------------------------------------------------------------------------- */
.stitch {
  height: 2px;
  width: 100%;
  background-image: repeating-linear-gradient(
    90deg,
    var(--stitch-c) 0 7px,
    transparent 7px 15px
  );
  border: 0;
}
.stitch-vert {
  width: 2px;
  height: 100%;
  background-image: repeating-linear-gradient(
    180deg,
    var(--stitch-c) 0 7px,
    transparent 7px 15px
  );
}

.hair { height: 1px; background: var(--line); width: 100%; border: 0; }

/* Section header pattern: numeral + title + lede */
.sec-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--s-4);
  margin-bottom: clamp(32px, 4.5vw, 64px);
}
@media (min-width: 900px) {
  .sec-head.has-side {
    grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr);
    gap: var(--s-8);
    align-items: end;
  }
}
