/* KnitLab Pro design tokens, 2026-11 ("Machine sheet")
 * Light is the default; dark applies with prefers-color-scheme unless the page
 * forces [data-theme="light"], or always with [data-theme="dark"].
 * RTL tokens apply under [dir="rtl"] (or :lang(fa)).
 * Contrast ratios are listed in design-system.md §3.2 (WCAG 2.2, computed).
 *
 * Font: Vazirmatn (OFL-1.1), self-hosted (CSP font-src 'self'). The file is the
 * one the editor already ships (kli/web/public/editor/fonts/Vazirmatn-wght.woff2).
 * No raw colour values outside this file.
 */

@font-face {
  font-family: "Vazirmatn";
  src: url("/fonts/Vazirmatn-wght.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;

  /* ---------- Colour: materials ---------- */
  --kl-enamel:        #E3E9E5; /* app chrome: the machine's grey-green enamel */
  --kl-paper:         #FAFBF9; /* working surfaces: the set-up sheet */
  --kl-sunk:          #EEF2EF; /* inset wells, table stripes, read-only fields */
  --kl-table:         #E9EDEA; /* the fabric inspection table (viewport) */
  --kl-graph:         #CBD8E4; /* graph-paper rule (decorative only, never alone) */
  --kl-graph-strong:  #93A9BF; /* repeat boundary on charts */

  /* ---------- Colour: ink ---------- */
  --kl-ink:           #15201B; /* primary text 16.1:1 on paper */
  --kl-ink-2:         #45524C; /* secondary text 7.9:1 */
  --kl-ink-3:         #5F6B65; /* tertiary text, placeholders 5.4:1 */
  --kl-line:          #C3CDC7; /* hairlines between regions (decorative) */
  --kl-line-strong:   #7D8A84; /* control borders 3.5:1 (WCAG 1.4.11) */

  /* ---------- Colour: action (indigo dye) ---------- */
  --kl-action:        #2B3EA0; /* primary buttons, links, selection 8.8:1 */
  --kl-action-hover:  #22328A;
  --kl-on-action:     #FFFFFF; /* 9.1:1 on action */
  --kl-action-soft:   #E2E6FA; /* selected rows, pressed segments */
  --kl-focus:         #2B3EA0; /* focus ring colour */
  --kl-focus-halo:    #FAFBF9; /* inner halo so the ring shows on any fill */

  /* ---------- Colour: signal lamps (machine signal tower) ---------- */
  --kl-ok:            #14683A; --kl-ok-soft:     #DCEFE3; --kl-ok-lamp:     #1E7A45;
  --kl-caution:       #7F4E00; --kl-caution-soft:#FBEACB; --kl-caution-lamp:#B07000;
  --kl-danger:        #AE2A20; --kl-danger-soft: #F9DFDC; --kl-danger-lamp: #C2372C;
  --kl-info:          #2B3EA0; --kl-info-soft:   #E2E6FA;
  --kl-idle-lamp:     #7D8A84;
  /* the signal tower's lit lamps (on its own dark housing in both themes) */
  --kl-tower-housing: #15201B;
  --kl-tower-off:     #3A4540;
  --kl-tower-red:     #FF5A4E;
  --kl-tower-amber:   #FFB020;
  --kl-tower-green:   #3DDC84;

  /* ---------- Colour: brand (the KnitLab wordmark and PRO plate) ---------- */
  --kl-brand:         #4A2B8C; /* 10.0:1 on paper */
  --kl-on-brand:      #FFFFFF; /* 10.4:1 */
  --kl-shadow:        rgba(21, 32, 27, .18); /* scroll-edge shades */
  --kl-veil:          rgba(250, 251, 249, .78); /* stale hatch, label backings over fabric */
  --kl-on-ink:        #FAFBF9; /* toast text */

  /* ---------- Colour: stitches (always paired with a symbol) ---------- */
  --kl-knit:          #15201B; /* filled loop */
  --kl-tuck:          #15201B; /* open V */
  --kl-miss:          #5F6B65; /* dash */
  --kl-cell-bg:       #FAFBF9;
  --kl-cell-alt:      #F3F6F4; /* alternate track column */
  --kl-cell-selected: #E2E6FA;
  --kl-tint-knit:     #E4DEF7; /* cell background by ACTION (owner's v3): knit lavender */
  --kl-tint-tuck:     #FBE7C2; /* tuck amber; miss stays plain */

  /* ---------- Colour: the 10 yarn slots (stored in links; names are fixed) ---------- */
  --kl-yarn-navy:     #1F2E5C;
  --kl-yarn-heather:  #9AA0A6;
  --kl-yarn-white:    #F7F7F2;
  --kl-yarn-brick:    #A3452F;
  --kl-yarn-mustard:  #D1A21E;
  --kl-yarn-bottle:   #1E5A3C;
  --kl-yarn-black:    #1A1A1A;
  --kl-yarn-ecru:     #E9DFC6;
  --kl-yarn-sand:     #CDB58F;
  --kl-yarn-sky:      #7FB3DD;
  --kl-yarn-edge:     rgba(21, 32, 27, .45); /* swatch outline, so white/ecru read */

  /* ---------- Typography ---------- */
  --kl-font:          "Vazirmatn", "Vazirmatn UI", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  --kl-font-num:      var(--kl-font); /* + font-variant-numeric: tabular-nums */
  /* Three steps + two utility sizes. 1rem = 16px; touch devices bump body to 17px. */
  --kl-fs-caption:    0.8125rem;  /* 13px  chart axis labels, legends */
  --kl-fs-small:      0.875rem;   /* 14px  secondary lines, table cells */
  --kl-fs-body:       1rem;       /* 16px  body, controls (17px on coarse pointers) */
  --kl-fs-title:      1.25rem;    /* 20px  panel titles */
  --kl-fs-heading:    1.75rem;    /* 28px  page titles */
  --kl-fs-display:    clamp(2rem, 1.2rem + 3vw, 3.25rem); /* landing only */
  --kl-lh-tight:      1.25;
  --kl-lh-body:       1.5;        /* Latin */
  --kl-lh-body-fa:    1.8;        /* Persian body */
  --kl-fw-regular:    400;
  --kl-fw-medium:     500;
  --kl-fw-bold:       700;
  --kl-measure:       68ch;

  /* ---------- Spacing (4-pt base) ---------- */
  --kl-s-1: 4px;  --kl-s-2: 8px;  --kl-s-3: 12px; --kl-s-4: 16px;
  --kl-s-5: 24px; --kl-s-6: 32px; --kl-s-7: 48px; --kl-s-8: 64px;
  --kl-gutter:        clamp(16px, 2.5vw, 32px);

  /* ---------- Size: touch ---------- */
  --kl-hit:           44px;  /* minimum target (the editor on a phone at standard density: 40 px, design-system §8); never subtract from it */
  --kl-hit-floor:     56px;  /* floor actions: tools, Simulate, Undo, face/back, state */
  --kl-cell:          44px;  /* cam / needle / grid cell */
  --kl-cell-gap:      2px;

  /* ---------- Radii (hierarchy, not one radius for all) ---------- */
  --kl-r-cell:        4px;   /* graph-paper cells */
  --kl-r-control:     10px;  /* buttons, fields, segments */
  --kl-r-panel:       14px;  /* panels, cards */
  --kl-r-sheet:       20px;  /* sheets, dialogs */
  --kl-r-pill:        999px; /* lamps, chips */

  /* ---------- Elevation (border first, shadow only for things that float) ---------- */
  --kl-e0: none;
  --kl-e1: 0 0 0 1px var(--kl-line);
  --kl-e2: 0 1px 2px rgba(21,32,27,.10), 0 8px 24px rgba(21,32,27,.12);
  --kl-e3: 0 2px 4px rgba(21,32,27,.12), 0 24px 64px rgba(21,32,27,.22);
  --kl-scrim: rgba(14,19,17,.48);

  /* ---------- Motion ---------- */
  --kl-dur-1: 120ms;  /* press, toggle */
  --kl-dur-2: 200ms;  /* expand, popover */
  --kl-dur-3: 320ms;  /* sheet, dialog */
  --kl-ease:  cubic-bezier(.2, 0, 0, 1);
  --kl-ease-exit: cubic-bezier(.3, 0, 1, 1);

  /* ---------- Z-index ---------- */
  --kl-z-base: 0;
  --kl-z-sticky: 10;   /* sticky chart headers, column labels */
  --kl-z-dock: 20;     /* bottom dock / top bar */
  --kl-z-popover: 30;  /* yarn picker, menus */
  --kl-z-sheet: 40;
  --kl-z-dialog: 50;
  --kl-z-toast: 60;

  /* ---------- Direction (logical helpers) ---------- */
  --kl-dir-sign: 1;            /* multiply translateX by this for mirrored chrome motion */
  --kl-chart-direction: ltr;   /* charts, fabric, set-out never mirror */
}

/* Touch devices: larger body and controls. */
@media (pointer: coarse) {
  :root { --kl-fs-body: 1.0625rem; }
}

/* Shop-floor density (user setting): gloves, oily fingers, arm's length. */
:root[data-density="floor"] {
  --kl-hit: 56px;
  --kl-hit-floor: 64px;
  --kl-cell: 56px;
  --kl-cell-gap: 3px;
  --kl-fs-body: 1.125rem;
  --kl-fs-small: 1rem;
  --kl-fs-caption: 0.875rem;
}

/* ---------- Dark ("night shift") ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --kl-enamel: #0E1311; --kl-paper: #161C19; --kl-sunk: #1D2420; --kl-table: #1B211E;
    --kl-graph: #2A3833; --kl-graph-strong: #4F6A7F;
    --kl-ink: #E5ECE8; --kl-ink-2: #B2BDB7; --kl-ink-3: #909C96;
    --kl-line: #323D38; --kl-line-strong: #7D8A84;
    --kl-action: #AEBBFF; --kl-action-hover: #C6CFFF; --kl-on-action: #0E1311;
    --kl-action-soft: #252C52; --kl-focus: #AEBBFF; --kl-focus-halo: #0E1311;
    --kl-ok: #6FD39A; --kl-ok-soft: #173323; --kl-ok-lamp: #4FBF7F;
    --kl-caution: #F2BA55; --kl-caution-soft: #3A2B10; --kl-caution-lamp: #F2BA55;
    --kl-danger: #FF9086; --kl-danger-soft: #3D1A17; --kl-danger-lamp: #FF7468;
    --kl-info: #AEBBFF; --kl-info-soft: #252C52; --kl-idle-lamp: #7D8A84;
    --kl-brand: #C9B6FF; --kl-on-brand: #0E1311; --kl-shadow: rgba(0,0,0,.45); --kl-veil: rgba(22,28,25,.72); --kl-on-ink: #0E1311;
    --kl-tower-housing: #050807; --kl-tint-knit: #2C2650; --kl-tint-tuck: #3A2B10;
    --kl-knit: #E5ECE8; --kl-tuck: #E5ECE8; --kl-miss: #909C96;
    --kl-cell-bg: #161C19; --kl-cell-alt: #1A211D; --kl-cell-selected: #252C52;
    --kl-yarn-edge: rgba(229,236,232,.55);
    --kl-e2: 0 1px 2px rgba(0,0,0,.5), 0 8px 24px rgba(0,0,0,.5);
    --kl-e3: 0 2px 4px rgba(0,0,0,.5), 0 24px 64px rgba(0,0,0,.6);
    --kl-scrim: rgba(0,0,0,.6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --kl-enamel: #0E1311; --kl-paper: #161C19; --kl-sunk: #1D2420; --kl-table: #1B211E;
  --kl-graph: #2A3833; --kl-graph-strong: #4F6A7F;
  --kl-ink: #E5ECE8; --kl-ink-2: #B2BDB7; --kl-ink-3: #909C96;
  --kl-line: #323D38; --kl-line-strong: #7D8A84;
  --kl-action: #AEBBFF; --kl-action-hover: #C6CFFF; --kl-on-action: #0E1311;
  --kl-action-soft: #252C52; --kl-focus: #AEBBFF; --kl-focus-halo: #0E1311;
  --kl-ok: #6FD39A; --kl-ok-soft: #173323; --kl-ok-lamp: #4FBF7F;
  --kl-caution: #F2BA55; --kl-caution-soft: #3A2B10; --kl-caution-lamp: #F2BA55;
  --kl-danger: #FF9086; --kl-danger-soft: #3D1A17; --kl-danger-lamp: #FF7468;
  --kl-info: #AEBBFF; --kl-info-soft: #252C52; --kl-idle-lamp: #7D8A84;
    --kl-brand: #C9B6FF; --kl-on-brand: #0E1311; --kl-shadow: rgba(0,0,0,.45); --kl-veil: rgba(22,28,25,.72); --kl-on-ink: #0E1311;
    --kl-tower-housing: #050807; --kl-tint-knit: #2C2650; --kl-tint-tuck: #3A2B10;
  --kl-knit: #E5ECE8; --kl-tuck: #E5ECE8; --kl-miss: #909C96;
  --kl-cell-bg: #161C19; --kl-cell-alt: #1A211D; --kl-cell-selected: #252C52;
  --kl-yarn-edge: rgba(229,236,232,.55);
  --kl-e2: 0 1px 2px rgba(0,0,0,.5), 0 8px 24px rgba(0,0,0,.5);
  --kl-e3: 0 2px 4px rgba(0,0,0,.5), 0 24px 64px rgba(0,0,0,.6);
  --kl-scrim: rgba(0,0,0,.6);
}

/* ---------- RTL / Persian ---------- */
[dir="rtl"], :lang(fa) {
  --kl-dir-sign: -1;
  --kl-lh-body: var(--kl-lh-body-fa);
}
/* Persian is never letter-spaced; Persian digits via the font's feature where present. */
:lang(fa) { letter-spacing: 0 !important; font-feature-settings: "ss01" 0; }

/* ---------- Korean and Chinese ---------- */
/* Vazirmatn draws no Hangul or Han: after it, the system's Hangul and Han fonts by their local names, never a file
   fetched, before the generic system font. */
:root:lang(ko) { --kl-font: "Vazirmatn", "Vazirmatn UI", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", "Noto Sans CJK KR", system-ui, -apple-system, "Segoe UI", sans-serif; }
:root:lang(zh) { --kl-font: "Vazirmatn", "Vazirmatn UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "Noto Sans CJK SC", system-ui, -apple-system, "Segoe UI", sans-serif; }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  :root { --kl-dur-1: 0ms; --kl-dur-2: 0ms; --kl-dur-3: 0ms; }
}
