/* ─────────────────────────────────────────────────────────────────
   Arrange — v7 · Rille
   Codename: the groove. Synthesis of v4 (mechanism) and v6 (enamel).
   Whiter, cooler surface. Recessed ROUTS as UI channels.
   Enamel-color inlays mark state. Chamfered toggles introduce angle.
   No skeuomorphism. No faux-aluminum. The screen is honestly the screen.
   ───────────────────────────────────────────────────────────────── */

@layer tokens, base, primitives, components, utilities;

/* ─────────────────────────────────────────────────────────────────
   A. TOKENS
   ───────────────────────────────────────────────────────────────── */
@layer tokens {
  :root {
    /* Surface — clean off-white, dramatically whiter than v3/v4's warm cream */
    --surface:        #fbfaf6;
    --surface-2:      #eeede8;
    --surface-3:      #dedbd4;
    --surface-edge:   rgba(20, 18, 14, 0.14);

    /* Compatibility aliases — keep v3/v4 token names alive */
    --plane:          var(--surface);
    --plane-2:        var(--surface-2);
    --plane-3:        var(--surface-3);
    --plane-edge:     var(--surface-edge);
    --paper:          var(--surface);
    --paper-2:        var(--surface-2);
    --paper-3:        var(--surface-3);

    /* Ink — neutral graphite (less warm than v3) */
    --ink:            #1c1b18;
    --ink-2:          #44423d;
    --ink-3:          #7a7770;

    --rule:           rgba(20, 18, 14, 0.16);
    --rule-soft:      rgba(20, 18, 14, 0.07);
    --hair:           1px;

    /* Enamel palette — saturated jewel-tones, set into routs */
    --enamel-vermilion: #c2271c;
    --enamel-cobalt:    #1e3a8a;
    --enamel-emerald:   #1a5e3a;
    --enamel-gold:      #b8851c;
    --enamel-amethyst:  #5a2080;
    --enamel-burnt:     #b8651c;

    /* Wash variants — for backgrounds derived from enamel colors */
    --enamel-vermilion-wash: rgba(194, 39, 28, 0.10);
    --enamel-cobalt-wash:    rgba(30, 58, 138, 0.10);
    --enamel-emerald-wash:   rgba(26, 94, 58, 0.10);
    --enamel-gold-wash:      rgba(184, 133, 28, 0.13);
    --enamel-amethyst-wash:  rgba(90, 32, 128, 0.10);
    --enamel-burnt-wash:     rgba(184, 101, 28, 0.10);

    /* Accent — cobalt (replaces v3/v4 burnt sienna as primary action) */
    --accent:         var(--enamel-cobalt);
    --accent-ink:     #f8f7f3;
    --accent-wash:    var(--enamel-cobalt-wash);
    --accent-line:    rgba(30, 58, 138, 0.45);

    /* Status — bound to enamel colors */
    --status-positive:      var(--enamel-emerald);
    --status-positive-wash: var(--enamel-emerald-wash);
    --status-warning:       var(--enamel-gold);
    --status-warning-wash:  var(--enamel-gold-wash);
    --status-negative:      var(--enamel-vermilion);
    --status-negative-wash: var(--enamel-vermilion-wash);
    --status-info:          var(--accent);
    --status-info-wash:     var(--accent-wash);

    /* Type */
    --font-sans:    "Inter", "Helvetica Neue", Helvetica, system-ui, sans-serif;
    --font-mono:    "JetBrains Mono", "IBM Plex Mono", ui-monospace, Menlo, monospace;

    --w-regular: 400;
    --w-medium:  500;
    --w-bold:    600;

    --t-xs:  11px;
    --t-sm:  13px;
    --t-md:  15px;
    --t-lg:  18px;
    --t-xl:  26px;
    --t-2xl: 40px;
    --t-3xl: 56px;

    --lh-tight: 1.12;
    --lh-base:  1.5;

    --tracking-eyebrow:    0.10em;
    --tracking-display:    -0.018em;
    --tracking-display-xl: -0.024em;
    --tracking-label:      0.02em;

    /* Space (4px scale) */
    --s-1:  4px;  --s-2:  8px;  --s-3: 12px; --s-4: 16px;
    --s-5: 24px;  --s-6: 32px;  --s-7: 48px; --s-8: 64px; --s-9: 96px;

    /* Radius */
    --r-sm:   3px;
    --r-md:   6px;
    --r-lg:   10px;
    --r-xl:   16px;
    --r-2xl:  24px;
    --r-pill: 999px;

    /* Motion — between v4's spring and v6's instant click */
    --m-instant: 90ms;
    --m-quick:   140ms;
    --m-base:    200ms;
    --m-slow:    300ms;
    --ease:      cubic-bezier(0.2, 0, 0, 1);
    --ease-soft: cubic-bezier(0.32, 1.18, 0.42, 1);   /* subtle spring */
    --ease-press: cubic-bezier(0.4, 0, 0.2, 1);       /* press-down */

    /* ════════════════════════════════════════════════════════════
       ROUTS — recessed UI channels.
       Honest digital depressions, not faux-metal edges.
       The shadow says "this area is recessed below the surface" —
       it does not pretend to be light catching a machined wall.
       ════════════════════════════════════════════════════════════ */
    --rout-shallow:
      inset 0 1px 2px rgba(0, 0, 0, 0.10),
      inset 0 1px 0 rgba(0, 0, 0, 0.06);
    --rout-mid:
      inset 0 2px 4px rgba(0, 0, 0, 0.14),
      inset 0 1px 0 rgba(0, 0, 0, 0.08);
    --rout-deep:
      inset 0 3px 7px rgba(0, 0, 0, 0.18),
      inset 0 1px 0 rgba(0, 0, 0, 0.10);
    --rout-deepest:
      inset 0 5px 12px rgba(0, 0, 0, 0.22),
      inset 0 1px 0 rgba(0, 0, 0, 0.12);

    /* Legacy v3/v4 inset names — alias to rout system */
    --inset-cut:    var(--rout-mid);
    --inset-deep:   var(--rout-deep);

    /* Elevation — for things ABOVE the surface (caps, keys, knobs) */
    --e0: 0 0 0 0 transparent;
    --e1:
      0 1px 0 rgba(20, 18, 14, 0.07),
      0 2px 4px rgba(20, 18, 14, 0.06);
    --e2:
      0 1px 0 rgba(20, 18, 14, 0.06),
      0 6px 12px rgba(20, 18, 14, 0.10);
    --e3:
      0 1px 0 rgba(20, 18, 14, 0.05),
      0 4px 10px rgba(20, 18, 14, 0.08),
      0 18px 40px rgba(20, 18, 14, 0.13);

    /* Control metrics */
    --control-h-sm: 28px;
    --control-h-md: 36px;
    --control-h-lg: 46px;
  }

  [data-theme="ink"] {
    /* Dark mode — deep neutral graphite under task light */
    --surface:    #1c1c19;
    --surface-2:  #252523;
    --surface-3:  #2e2e2b;
    --surface-edge: rgba(255, 248, 235, 0.10);

    --ink:        #ebe8e0;
    --ink-2:      #b0aca3;
    --ink-3:      #7a766e;

    --rule:       rgba(255, 248, 235, 0.16);
    --rule-soft:  rgba(255, 248, 235, 0.06);

    /* Enamel — slightly lifted on dark for clean reading on the deep surface */
    --enamel-vermilion: #e54a3f;
    --enamel-cobalt:    #5b85d6;
    --enamel-emerald:   #4ea076;
    --enamel-gold:      #d4a850;
    --enamel-amethyst:  #9c6bcb;
    --enamel-burnt:     #e08555;

    --enamel-vermilion-wash: rgba(229, 74, 63, 0.14);
    --enamel-cobalt-wash:    rgba(91, 133, 214, 0.16);
    --enamel-emerald-wash:   rgba(78, 160, 118, 0.14);
    --enamel-gold-wash:      rgba(212, 168, 80, 0.16);
    --enamel-amethyst-wash:  rgba(156, 107, 203, 0.14);
    --enamel-burnt-wash:     rgba(224, 133, 85, 0.14);

    --accent:       var(--enamel-cobalt);
    --accent-ink:   #1c1c19;
    --accent-wash:  var(--enamel-cobalt-wash);
    --accent-line:  rgba(91, 133, 214, 0.45);

    /* Routs on dark — honest depressions into the deep surface */
    --rout-shallow:
      inset 0 1px 2px rgba(0, 0, 0, 0.50),
      inset 0 1px 0 rgba(0, 0, 0, 0.40);
    --rout-mid:
      inset 0 2px 4px rgba(0, 0, 0, 0.55),
      inset 0 1px 0 rgba(0, 0, 0, 0.45);
    --rout-deep:
      inset 0 3px 7px rgba(0, 0, 0, 0.60),
      inset 0 1px 0 rgba(0, 0, 0, 0.50);
    --rout-deepest:
      inset 0 5px 12px rgba(0, 0, 0, 0.65),
      inset 0 1px 0 rgba(0, 0, 0, 0.55);

    --e1: 0 1px 0 rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.40);
    --e2: 0 1px 0 rgba(0, 0, 0, 0.45), 0 8px 18px rgba(0, 0, 0, 0.50);
    --e3: 0 1px 0 rgba(0, 0, 0, 0.40), 0 6px 12px rgba(0, 0, 0, 0.45),
          0 24px 48px rgba(0, 0, 0, 0.60);
  }
}

/* ─────────────────────────────────────────────────────────────────
   B. BASE
   ───────────────────────────────────────────────────────────────── */
@layer base {
  *, *::before, *::after { box-sizing: border-box; }

  html {
    font-family: var(--font-sans);
    font-size: var(--t-md);
    line-height: var(--lh-base);
    color: var(--ink);
    background: var(--surface);
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: "cv11", "ss01";
  }

  body {
    margin: 0;
    background: var(--surface);
    color: var(--ink);
    min-height: 100vh;
  }

  h1, h2, h3, h4, h5, h6 {
    margin: 0;
    font-family: var(--font-sans);
    font-weight: var(--w-bold);
    line-height: var(--lh-tight);
    color: var(--ink);
    letter-spacing: var(--tracking-display);
  }
  h1 { font-size: var(--t-3xl); letter-spacing: var(--tracking-display-xl); }
  h2 { font-size: var(--t-2xl); letter-spacing: var(--tracking-display); }
  h3 { font-size: var(--t-xl); }
  h4 { font-size: var(--t-lg); font-weight: var(--w-medium); }

  p { margin: 0; }

  a {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px solid var(--accent-line);
    transition: color var(--m-quick) var(--ease), border-color var(--m-quick) var(--ease);
  }
  a:hover { color: var(--ink); border-bottom-color: var(--ink); }

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

  hr { border: 0; height: 1px; background: var(--rule); margin: var(--s-5) 0; }

  code, kbd, samp { font-family: var(--font-mono); font-size: 0.92em; }

  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
      animation-duration: 0.001ms !important;
      transition-duration: 0.001ms !important;
    }
  }
}

/* ─────────────────────────────────────────────────────────────────
   C. PRIMITIVES
   ───────────────────────────────────────────────────────────────── */
@layer primitives {

  .eyebrow {
    font-size: var(--t-xs);
    font-weight: var(--w-medium);
    text-transform: uppercase;
    letter-spacing: var(--tracking-eyebrow);
    color: var(--ink-3);
  }

  /* ════════ Button ════════
     Caps sitting on the surface. Press depresses into a shallow rout. */
  .btn {
    --_bg: var(--surface);
    --_fg: var(--ink);
    --_border: var(--rule);
    --_shadow: var(--e1);
    --_shadow-hover: var(--e2);

    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--s-2);
    height: var(--control-h-md);
    padding: 0 var(--s-4);
    font-family: var(--font-sans);
    font-size: var(--t-sm);
    font-weight: var(--w-medium);
    letter-spacing: var(--tracking-label);
    line-height: 1;
    color: var(--_fg);
    background: var(--_bg);
    border: 1px solid var(--_border);
    border-radius: var(--r-sm);
    box-shadow: var(--_shadow);
    cursor: pointer;
    user-select: none;
    transform: translateY(0);
    transition:
      box-shadow var(--m-quick) var(--ease-soft),
      transform  var(--m-quick) var(--ease-soft),
      background-color var(--m-quick) var(--ease),
      border-color var(--m-quick) var(--ease),
      color var(--m-quick) var(--ease);
  }
  .btn:hover {
    box-shadow: var(--_shadow-hover);
    transform: translateY(-1px);
  }
  .btn:active {
    box-shadow: var(--rout-shallow);
    transform: translateY(1px);
    transition: box-shadow var(--m-instant) var(--ease-press),
                transform var(--m-instant) var(--ease-press);
  }
  .btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }
  .btn[disabled], .btn[aria-disabled="true"] {
    opacity: 0.45;
    box-shadow: var(--e0);
    cursor: not-allowed;
    pointer-events: none;
    transform: none;
  }

  .btn--primary {
    --_bg: var(--accent);
    --_fg: var(--accent-ink);
    --_border: var(--accent);
  }
  .btn--ghost {
    --_bg: transparent;
    --_border: transparent;
    --_shadow: var(--e0);
    --_shadow-hover: var(--e0);
  }
  .btn--ghost:hover { background: var(--surface-2); transform: none; }

  .btn--danger {
    --_fg: var(--enamel-vermilion);
    --_border: var(--rule);
  }
  .btn--danger:hover {
    background: var(--enamel-vermilion);
    color: var(--surface);
    --_border: var(--enamel-vermilion);
  }

  .btn--accent {
    --_bg: var(--enamel-burnt);
    --_fg: var(--surface);
    --_border: var(--enamel-burnt);
  }

  .btn--sm { height: var(--control-h-sm); padding: 0 var(--s-3); font-size: var(--t-xs); }
  .btn--lg { height: var(--control-h-lg); padding: 0 var(--s-5); font-size: var(--t-md); }
  .btn--icon { width: var(--control-h-md); padding: 0; }
  .btn--icon.btn--sm { width: var(--control-h-sm); }
  .btn--icon.btn--lg { width: var(--control-h-lg); }

  /* ════════ Deep button — calculator-key press ════════ */
  .btn-deep {
    --_bg: var(--surface);
    --_fg: var(--ink);
    --_border: var(--rule);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--s-2);
    height: var(--control-h-md);
    padding: 0 var(--s-4);
    font-family: var(--font-sans);
    font-size: var(--t-sm);
    font-weight: var(--w-medium);
    letter-spacing: var(--tracking-label);
    line-height: 1;
    color: var(--_fg);
    background: var(--_bg);
    border: 1px solid var(--_border);
    border-radius: var(--r-sm);
    box-shadow: var(--e1);
    cursor: pointer;
    transform: translateY(0) scale(1);
    transition:
      box-shadow var(--m-quick) var(--ease-soft),
      transform  var(--m-quick) var(--ease-soft),
      background-color var(--m-quick) var(--ease);
  }
  .btn-deep:hover  { box-shadow: var(--e2); transform: translateY(-1px) scale(1); }
  .btn-deep:active {
    box-shadow: var(--rout-deep);
    transform: translateY(2px) scale(0.98);
    transition: all var(--m-instant) var(--ease-press);
  }
  .btn-deep--primary { --_bg: var(--accent); --_fg: var(--accent-ink); --_border: var(--accent); }
  .btn-deep--accent  { --_bg: var(--enamel-burnt); --_fg: var(--surface); --_border: var(--enamel-burnt); }

  /* ════════ Inputs — recessed routs ════════ */
  .input, .select, .textarea {
    display: block;
    width: 100%;
    height: var(--control-h-md);
    padding: 0 var(--s-3);
    font-family: var(--font-sans);
    font-size: var(--t-sm);
    color: var(--ink);
    background: var(--surface);
    border: 0;
    border-radius: var(--r-sm);
    box-shadow: var(--rout-mid);
    transition: box-shadow var(--m-quick) var(--ease);
  }
  .input::placeholder, .textarea::placeholder { color: var(--ink-3); }
  .input:hover, .select:hover, .textarea:hover { box-shadow: var(--rout-mid), 0 0 0 1px var(--rule); }
  .input:focus, .select:focus, .textarea:focus {
    outline: none;
    box-shadow:
      var(--rout-mid),
      0 0 0 2px var(--accent-wash),
      0 0 0 1px var(--accent);
  }
  .textarea { height: auto; padding: var(--s-2) var(--s-3); line-height: var(--lh-base); resize: vertical; }
  .select {
    appearance: none;
    background-image:
      linear-gradient(45deg, transparent 50%, var(--ink-2) 50%),
      linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
    background-position: calc(100% - 16px) center, calc(100% - 11px) center;
    background-size: 5px 5px;
    background-repeat: no-repeat;
    padding-right: var(--s-6);
  }

  .checkbox, .radio {
    appearance: none;
    width: 18px;
    height: 18px;
    margin: 0;
    background: var(--surface);
    border-radius: var(--r-sm);
    box-shadow: var(--rout-mid);
    cursor: pointer;
    display: inline-grid;
    place-content: center;
    vertical-align: middle;
    transition: background-color var(--m-quick) var(--ease), box-shadow var(--m-quick) var(--ease);
  }
  .radio { border-radius: var(--r-pill); }
  .checkbox:checked, .radio:checked {
    background: var(--accent);
    box-shadow: var(--e1);
  }
  .checkbox:checked::after {
    content: "";
    width: 9px; height: 5px;
    border-left: 1.5px solid var(--accent-ink);
    border-bottom: 1.5px solid var(--accent-ink);
    transform: rotate(-45deg) translate(1px, -1px);
  }
  .radio:checked::after {
    content: "";
    width: 7px; height: 7px;
    border-radius: var(--r-pill);
    background: var(--accent-ink);
  }

  .field { display: flex; flex-direction: column; gap: var(--s-2); }
  .field__label {
    font-size: var(--t-xs);
    font-weight: var(--w-medium);
    color: var(--ink-2);
    text-transform: uppercase;
    letter-spacing: var(--tracking-eyebrow);
  }
  .field__hint { font-size: var(--t-xs); color: var(--ink-3); }

  /* ════════ Card ════════ */
  .card {
    background: var(--surface);
    border-radius: var(--r-md);
    box-shadow: var(--e1);
    padding: var(--s-5);
  }
  .card--panel    { background: var(--surface-2); box-shadow: var(--e0); border: 1px solid var(--surface-edge); }
  .card--lifted   { box-shadow: var(--e2); }
  .card--floating { box-shadow: var(--e3); }
  .card--flush    { padding: 0; }
  .card__head {
    display: flex; align-items: baseline; justify-content: space-between;
    padding-bottom: var(--s-3);
    margin-bottom: var(--s-3);
    border-bottom: 1px solid var(--rule-soft);
  }
  .card__title { font-size: var(--t-md); font-weight: var(--w-bold); }
  .card__meta  { font-size: var(--t-sm); color: var(--ink-3); }

  /* ════════ Table ════════ */
  .table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--t-sm);
    color: var(--ink);
  }
  .table th {
    text-align: left;
    font-weight: var(--w-medium);
    font-size: var(--t-xs);
    text-transform: uppercase;
    letter-spacing: var(--tracking-eyebrow);
    color: var(--ink-3);
    padding: var(--s-3);
    border-bottom: 1px solid var(--ink);
    white-space: nowrap;
  }
  .table td {
    padding: var(--s-3);
    border-bottom: 1px solid var(--rule-soft);
    vertical-align: top;
  }
  .table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
  .table td.mono { font-family: var(--font-mono); font-size: 0.92em; color: var(--ink-2); }
  .table tbody tr:hover td { background: var(--surface-2); }
  .table tbody tr[aria-selected="true"] td { background: var(--accent-wash); }

  /* ════════ Tag — small enamel-inlay chip ════════ */
  .tag {
    display: inline-flex;
    align-items: center;
    gap: var(--s-1);
    height: 22px;
    padding: 0 var(--s-3);
    font-size: var(--t-xs);
    font-weight: var(--w-medium);
    line-height: 1;
    letter-spacing: var(--tracking-label);
    color: var(--ink-2);
    background: var(--surface);
    border-radius: var(--r-pill);
    box-shadow: var(--e1);
    white-space: nowrap;
  }
  .tag--accent   { color: var(--accent);          background: var(--accent-wash); }
  .tag--positive { color: var(--status-positive); background: var(--status-positive-wash); }
  .tag--warning  { color: var(--status-warning);  background: var(--status-warning-wash); }
  .tag--negative { color: var(--status-negative); background: var(--status-negative-wash); }

  /* ════════ Status mark / LED ════════ */
  .dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: var(--r-pill);
    background: var(--ink-3);
    flex-shrink: 0;
  }
  .dot--positive { background: var(--status-positive); }
  .dot--warning  { background: var(--status-warning); }
  .dot--negative { background: var(--status-negative); }
  .dot--info     { background: var(--accent); }

  .led {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: var(--r-pill);
    background: var(--ink-3);
    box-shadow: var(--rout-shallow);
    flex-shrink: 0;
    transition: background-color var(--m-quick) var(--ease), box-shadow var(--m-quick) var(--ease);
  }
  .led.is-on { box-shadow: var(--rout-shallow), 0 0 0 2px color-mix(in srgb, currentColor 22%, transparent); }
  .led.is-on.led--vermilion { background: var(--enamel-vermilion); color: var(--enamel-vermilion); }
  .led.is-on.led--cobalt    { background: var(--enamel-cobalt);    color: var(--enamel-cobalt); }
  .led.is-on.led--emerald   { background: var(--enamel-emerald);   color: var(--enamel-emerald); }
  .led.is-on.led--gold      { background: var(--enamel-gold);      color: var(--enamel-gold); }
  .led.is-on.led--amethyst  { background: var(--enamel-amethyst);  color: var(--enamel-amethyst); }
  .led.is-on.led--accent    { background: var(--accent);           color: var(--accent); }

  /* ════════ Tabs / segmented (light) ════════ */
  .tabs {
    display: inline-flex;
    padding: 3px;
    background: var(--surface);
    border-radius: var(--r-md);
    box-shadow: var(--rout-mid);
    gap: 2px;
  }
  .tabs__tab {
    appearance: none;
    border: 0;
    background: transparent;
    font: inherit;
    font-size: var(--t-sm);
    font-weight: var(--w-medium);
    color: var(--ink-2);
    padding: 0 var(--s-3);
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color var(--m-quick) var(--ease), color var(--m-quick) var(--ease), box-shadow var(--m-quick) var(--ease);
  }
  .tabs__tab:hover { color: var(--ink); }
  .tabs__tab[aria-selected="true"] {
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--e1);
  }

  /* ════════ Kbd ════════ */
  .kbd {
    font-family: var(--font-mono);
    font-size: var(--t-xs);
    padding: 1px 6px;
    color: var(--ink-2);
    background: var(--surface);
    border-radius: var(--r-sm);
    box-shadow: var(--e1), inset 0 -1.5px 0 rgba(0,0,0,0.10);
  }

  .divider { height: 1px; background: var(--rule-soft); margin: var(--s-4) 0; }
  .divider--strong { background: var(--ink); }
}

/* ─────────────────────────────────────────────────────────────────
   D. MECHANISMS — the v4 vocabulary, refined with routs
   ───────────────────────────────────────────────────────────────── */
@layer primitives {

  /* ════════ Toggle — knob slides in a rout ════════
     The track itself is a rout cut into the surface.
     The knob is a cap that rides above the rout's lip.
     Enamel inlay shows at the active end of the rout. */
  .toggle {
    --_track-w: 44px;
    --_track-h: 22px;
    --_knob-d:  16px;
    --_inlay:   var(--accent);

    position: relative;
    display: inline-block;
    width: var(--_track-w);
    height: var(--_track-h);
    border-radius: var(--r-pill);
    background: var(--surface);
    box-shadow: var(--rout-mid);
    cursor: pointer;
    transition: background-color var(--m-base) var(--ease);
    vertical-align: middle;
  }
  .toggle__knob {
    position: absolute;
    top: 3px; left: 3px;
    width: var(--_knob-d);
    height: var(--_knob-d);
    border-radius: var(--r-pill);
    background: var(--surface-2);
    box-shadow: var(--e1);
    transition: transform var(--m-base) var(--ease-soft);
  }
  .toggle__inlay {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    width: 6px;
    height: 6px;
    border-radius: var(--r-pill);
    background: var(--_inlay);
    opacity: 0;
    transition: opacity var(--m-quick) var(--ease) var(--m-quick);
  }
  .toggle.is-on .toggle__knob   { transform: translateX(calc(var(--_track-w) - var(--_knob-d) - 6px)); }
  .toggle.is-on .toggle__inlay  { opacity: 1; }
  .toggle.is-on { background: color-mix(in srgb, var(--_inlay) 8%, var(--surface)); }

  .toggle--cobalt    { --_inlay: var(--enamel-cobalt); }
  .toggle--vermilion { --_inlay: var(--enamel-vermilion); }
  .toggle--emerald   { --_inlay: var(--enamel-emerald); }
  .toggle--gold      { --_inlay: var(--enamel-gold); }
  .toggle--amethyst  { --_inlay: var(--enamel-amethyst); }
  .toggle--lg { --_track-w: 56px; --_track-h: 28px; --_knob-d: 22px; }

  /* Chamfered toggle — Bauhaus angle. 45° cuts at each corner.
     The rectangle replaces the pill. Minimalist, geometric, precise. */
  .toggle--chamfered {
    --_track-w: 48px;
    --_track-h: 22px;
    --_knob-d: 16px;
    border-radius: 0;
    clip-path: polygon(
      5px 0, calc(100% - 5px) 0,
      100% 5px, 100% calc(100% - 5px),
      calc(100% - 5px) 100%, 5px 100%,
      0 calc(100% - 5px), 0 5px
    );
  }
  .toggle--chamfered .toggle__knob {
    border-radius: 0;
    clip-path: polygon(
      3px 0, calc(100% - 3px) 0,
      100% 3px, 100% calc(100% - 3px),
      calc(100% - 3px) 100%, 3px 100%,
      0 calc(100% - 3px), 0 3px
    );
  }
  .toggle--chamfered .toggle__inlay {
    border-radius: 0;
    width: 4px;
    height: 4px;
    transform: translateY(-50%) rotate(45deg);
    right: 7px;
  }
  .toggle--chamfered.is-on .toggle__knob {
    transform: translateX(calc(var(--_track-w) - var(--_knob-d) - 6px));
  }

  /* ════════ Knob — milled cap with notch ════════
     A circular cap sitting in a routed pocket.
     A few precision tickmarks define detents (no full watch dial). */
  .knob-group {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: var(--s-2);
  }
  /* The knob sits in a routed pocket. Outer ring = pocket; inner cap = milled metal. */
  .knob {
    --_d: 64px;
    --_pocket-pad: 8px;     /* the pocket is bigger than the cap */
    --_notch: var(--enamel-cobalt);

    position: relative;
    width: var(--_d);
    height: var(--_d);
    padding: var(--_pocket-pad);
    border-radius: var(--r-pill);
    background: var(--surface);
    box-shadow: var(--rout-deep);
    cursor: pointer;
    border: 0;
    color: inherit;
  }
  /* The milled cap inside the pocket */
  .knob::after {
    content: "";
    position: absolute;
    inset: var(--_pocket-pad);
    border-radius: var(--r-pill);
    background:
      radial-gradient(circle at 32% 28%,
        color-mix(in srgb, var(--surface) 30%, #ffffff) 0%,
        var(--surface) 55%,
        color-mix(in srgb, var(--surface) 70%, #000) 100%);
    box-shadow: var(--e2), inset 0 0 0 1px var(--rule-soft);
    transition: transform var(--m-base) var(--ease-soft);
    transform-origin: 50% 50%;
    transform: rotate(var(--_rot, 0deg));
  }
  [data-theme="ink"] .knob::after {
    background:
      radial-gradient(circle at 32% 28%,
        color-mix(in srgb, var(--surface) 30%, #5a5852) 0%,
        var(--surface) 55%,
        color-mix(in srgb, var(--surface) 60%, #000) 100%);
  }
  /* The enamel notch — rendered as a tiny inlay rectangle near the top of the cap */
  .knob::before {
    content: "";
    position: absolute;
    z-index: 2;
    left: 50%;
    top: calc(var(--_pocket-pad) + 4px);
    transform-origin: 50% calc(var(--_d) / 2 - 4px);
    transform: translateX(-50%) rotate(var(--_rot, 0deg));
    width: 4px;
    height: 9px;
    border-radius: 1px;
    background: var(--_notch);
    box-shadow: 0 0 0 1px rgba(0,0,0,0.10);
    transition: transform var(--m-base) var(--ease-soft);
  }
  /* Tickmark ring — rendered via inline SVG in the markup (.knob__ticks) */
  .knob__ticks {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
    color: var(--ink-2);
  }
  .knob__ticks line {
    stroke: currentColor;
    stroke-width: 1;
    stroke-linecap: round;
  }
  .knob__ticks line.tick--major { stroke-width: 1.5; opacity: 0.85; }
  .knob__ticks line.tick--minor { opacity: 0.40; }
  .knob-group__labels {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1px;
    font-family: var(--font-mono);
    font-size: var(--t-xs);
    text-align: center;
    color: var(--ink-3);
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }
  .knob-group__value { color: var(--ink); font-weight: var(--w-bold); }

  .knob--vermilion { --_notch: var(--enamel-vermilion); }
  .knob--cobalt    { --_notch: var(--enamel-cobalt); }
  .knob--emerald   { --_notch: var(--enamel-emerald); }
  .knob--gold      { --_notch: var(--enamel-gold); }
  .knob--amethyst  { --_notch: var(--enamel-amethyst); }

  /* ════════ Segmented (deep) — a long rout with cells ════════
     The whole strip is a rout. Inactive segments are flush with the rout floor.
     The active segment is a CAP that rises out of the rout, with an enamel inlay. */
  .segmented-deep {
    --_inlay: var(--accent);
    display: inline-flex;
    padding: 4px;
    background: var(--surface);
    border-radius: var(--r-md);
    box-shadow: var(--rout-mid);
    gap: 2px;
  }
  .segmented-deep__seg {
    appearance: none;
    border: 0;
    background: transparent;
    font: inherit;
    font-size: var(--t-sm);
    font-weight: var(--w-medium);
    color: var(--ink-3);
    padding: 0 var(--s-3);
    height: 28px;
    min-width: 60px;
    border-radius: var(--r-sm);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--s-2);
    transition:
      background-color var(--m-quick) var(--ease),
      color var(--m-quick) var(--ease),
      box-shadow var(--m-quick) var(--ease),
      transform var(--m-quick) var(--ease-soft);
  }
  .segmented-deep__seg:hover { color: var(--ink); }
  .segmented-deep__seg.is-active {
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--e1);
    transform: translateY(-1px);
  }
  /* The enamel inlay marker on the active segment */
  .segmented-deep__seg.is-active::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: var(--r-pill);
    background: var(--_inlay);
  }
  .segmented-deep--cobalt    { --_inlay: var(--enamel-cobalt); }
  .segmented-deep--vermilion { --_inlay: var(--enamel-vermilion); }
  .segmented-deep--emerald   { --_inlay: var(--enamel-emerald); }
  .segmented-deep--gold      { --_inlay: var(--enamel-gold); }

  /* ════════ Slot button — two-state mode key ════════
     Off: flush with the routed pocket (inset shadow).
     On:  extruded above the surface (elevation + enamel inlay glows). */
  .slot-btn {
    --_inlay: var(--accent);
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--s-2);
    height: var(--control-h-md);
    padding: 0 var(--s-4);
    font-family: var(--font-sans);
    font-size: var(--t-sm);
    font-weight: var(--w-medium);
    letter-spacing: var(--tracking-label);
    line-height: 1;
    color: var(--ink-2);
    background: var(--surface);
    border: 0;
    border-radius: var(--r-sm);
    box-shadow: var(--rout-shallow);
    cursor: pointer;
    transition: all var(--m-quick) var(--ease-soft);
  }
  .slot-btn::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: var(--r-pill);
    background: var(--ink-3);
    box-shadow: var(--rout-shallow);
    transition: background-color var(--m-quick) var(--ease), box-shadow var(--m-quick) var(--ease);
  }
  .slot-btn.is-on {
    color: var(--ink);
    box-shadow: var(--e1);
    transform: translateY(-1px);
  }
  .slot-btn.is-on::before {
    background: var(--_inlay);
    box-shadow: var(--rout-shallow), 0 0 0 2px color-mix(in srgb, var(--_inlay) 22%, transparent);
  }
  .slot-btn--cobalt    { --_inlay: var(--enamel-cobalt); }
  .slot-btn--vermilion { --_inlay: var(--enamel-vermilion); }
  .slot-btn--emerald   { --_inlay: var(--enamel-emerald); }
  .slot-btn--gold      { --_inlay: var(--enamel-gold); }
  .slot-btn--amethyst  { --_inlay: var(--enamel-amethyst); }

  /* ════════ Fader — slider in a long rout ════════ */
  .fader {
    --_inlay: var(--accent);
    --_h: 24px;
    --_track-h: 6px;
    --_thumb-d: 18px;

    position: relative;
    display: block;
    width: 100%;
    height: var(--_h);
    user-select: none;
    cursor: pointer;
  }
  .fader__track {
    position: absolute;
    left: 0; right: 0; top: 50%;
    transform: translateY(-50%);
    height: var(--_track-h);
    border-radius: var(--r-pill);
    background: var(--surface);
    box-shadow: var(--rout-mid);
  }
  .fader__fill {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    height: var(--_track-h);
    border-radius: var(--r-pill);
    background: var(--_inlay);
    width: 50%;
    transition: width var(--m-quick) var(--ease);
  }
  .fader__thumb {
    position: absolute;
    top: 50%;
    left: 50%;
    width: var(--_thumb-d);
    height: var(--_thumb-d);
    border-radius: var(--r-pill);
    background:
      radial-gradient(circle at 30% 28%,
        color-mix(in srgb, var(--surface) 50%, #ffffff) 0%,
        var(--surface) 100%);
    box-shadow: var(--e2), inset 0 0 0 1px var(--rule-soft);
    transform: translate(-50%, -50%);
    transition: box-shadow var(--m-quick) var(--ease);
  }
  [data-theme="ink"] .fader__thumb {
    background:
      radial-gradient(circle at 30% 28%,
        color-mix(in srgb, var(--surface) 50%, #4a4843) 0%,
        var(--surface) 100%);
  }
  .fader:hover .fader__thumb { box-shadow: var(--e2), 0 0 0 4px var(--accent-wash); }
  .fader__value {
    position: absolute;
    bottom: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%);
    padding: 2px 8px;
    background: var(--ink);
    color: var(--surface);
    font-family: var(--font-mono);
    font-size: var(--t-xs);
    border-radius: var(--r-sm);
    box-shadow: var(--e2);
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--m-quick) var(--ease);
  }
  .fader:hover .fader__value, .fader.is-active .fader__value { opacity: 1; }

  .fader--cobalt    { --_inlay: var(--enamel-cobalt); }
  .fader--vermilion { --_inlay: var(--enamel-vermilion); }
  .fader--emerald   { --_inlay: var(--enamel-emerald); }
  .fader--gold      { --_inlay: var(--enamel-gold); }

  /* ════════ Tickmark row — small graphical scale ════════ */
  .tickmark-row {
    display: flex;
    align-items: end;
    gap: 0;
    height: 8px;
    width: 100%;
  }
  .tickmark-row__tick {
    flex: 1;
    background: var(--ink-3);
    width: 1px;
  }
  .tickmark-row__tick--tall   { height: 8px; }
  .tickmark-row__tick--mid    { height: 5px; }
  .tickmark-row__tick--short  { height: 3px; }
}

/* ─────────────────────────────────────────────────────────────────
   E. ROUT UTILITIES — direct use as visual primitives
   ───────────────────────────────────────────────────────────────── */
@layer primitives {
  .rout         { box-shadow: var(--rout-mid); background: var(--surface); border-radius: var(--r-sm); }
  .rout--shallow{ box-shadow: var(--rout-shallow); }
  .rout--mid    { box-shadow: var(--rout-mid); }
  .rout--deep   { box-shadow: var(--rout-deep); }
  .rout--deepest{ box-shadow: var(--rout-deepest); }

  /* Inlay — color set into a rout */
  .inlay {
    display: inline-block;
    border-radius: var(--r-sm);
    background: var(--accent);
  }
  .inlay--vermilion { background: var(--enamel-vermilion); }
  .inlay--cobalt    { background: var(--enamel-cobalt); }
  .inlay--emerald   { background: var(--enamel-emerald); }
  .inlay--gold      { background: var(--enamel-gold); }
  .inlay--amethyst  { background: var(--enamel-amethyst); }
}

/* ─────────────────────────────────────────────────────────────────
   F. COMPONENTS
   ───────────────────────────────────────────────────────────────── */
@layer components {
  .page-head {
    display: flex; align-items: baseline; justify-content: space-between;
    padding: var(--s-5) 0 var(--s-4);
    border-bottom: 1px solid var(--ink);
    margin-bottom: var(--s-5);
  }
  .page-head__title { font-size: var(--t-3xl); letter-spacing: var(--tracking-display); }
  .page-head__meta {
    font-family: var(--font-mono);
    font-size: var(--t-sm);
    color: var(--ink-3);
    font-variant-numeric: tabular-nums;
  }

  .shell {
    display: grid;
    grid-template-columns: 340px 1fr;
    min-height: 480px;
    background: var(--surface);
    border-radius: var(--r-lg);
    box-shadow: var(--e2);
    overflow: hidden;
  }
  .shell__rail {
    border-right: 1px solid var(--rule-soft);
    background: var(--surface-2);
    overflow-y: auto;
  }
  .shell__main {
    background: var(--surface);
    overflow-y: auto;
    padding: var(--s-5);
  }

  .empty {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    text-align: center; gap: var(--s-2);
    padding: var(--s-7) var(--s-5);
    color: var(--ink-3);
  }
  .empty__title { font-size: var(--t-md); font-weight: var(--w-bold); color: var(--ink-2); }

  /* ════════ Data row — the fully-resolved programming row.
     A single room at full information density, done calmly.
     Code stamp in margin. Body carries name + dept + provenance.
     Meta column: NSF, qty, status — each in its own register. ════════ */
  .data-row {
    display: grid;
    grid-template-columns: 56px 1fr auto;
    gap: var(--s-4);
    align-items: center;
    padding: var(--s-3) var(--s-4);
    background: var(--surface);
    border-bottom: 1px solid var(--rule-soft);
    transition: background-color var(--m-quick) var(--ease);
    cursor: default;
  }
  .data-row:first-child { border-top: 1px solid var(--rule-soft); }
  .data-row:hover { background: var(--surface-2); }
  .data-row[aria-selected="true"] { background: var(--accent-wash); }

  .data-row__stamp {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: var(--s-2) var(--s-1);
    background: var(--surface);
    border-radius: var(--r-sm);
    box-shadow: var(--rout-mid);
    min-height: 40px;
  }
  .data-row__code {
    font-family: var(--font-mono);
    font-size: var(--t-sm);
    font-weight: var(--w-bold);
    color: var(--ink);
    letter-spacing: 0.03em;
    line-height: 1;
  }
  .data-row__type {
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--ink-3);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    line-height: 1;
  }

  .data-row__body {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    min-width: 0;
  }
  .data-row__name {
    font-size: var(--t-sm);
    font-weight: var(--w-bold);
    color: var(--ink);
    letter-spacing: var(--tracking-display);
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .data-row__dept {
    font-size: var(--t-xs);
    color: var(--ink-2);
    line-height: 1.3;
  }
  .data-row__provenance {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--ink-3);
    display: flex;
    gap: var(--s-3);
    align-items: center;
    margin-top: 1px;
  }
  .data-row__prov-item {
    display: flex;
    align-items: center;
    gap: 3px;
  }

  .data-row__meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: center;
    gap: var(--s-1);
    flex-shrink: 0;
  }
  .data-row__nsf {
    font-family: var(--font-mono);
    font-size: var(--t-md);
    font-weight: var(--w-bold);
    color: var(--ink);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.01em;
    line-height: 1;
  }
  .data-row__qty {
    font-family: var(--font-mono);
    font-size: var(--t-xs);
    color: var(--ink-3);
    font-variant-numeric: tabular-nums;
    line-height: 1;
  }

  /* ════════ Stat strip — horizontal project totals, Bauhaus spec-sheet style.
     4-up grid. Number in large mono; label in eyebrow caps below.
     Hairline separators between cells. Clean, no shadow, honest. ════════ */
  .stat-strip {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    background: var(--surface);
    border: 1px solid var(--rule-soft);
    border-radius: var(--r-md);
    overflow: hidden;
  }
  .stat-strip__cell {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
    padding: var(--s-4) var(--s-5);
    border-right: 1px solid var(--rule-soft);
  }
  .stat-strip__cell:last-child { border-right: 0; }
  .stat-strip__value {
    font-family: var(--font-mono);
    font-size: var(--t-xl);
    font-weight: var(--w-bold);
    color: var(--ink);
    font-variant-numeric: tabular-nums;
    letter-spacing: var(--tracking-display);
    line-height: 1;
  }
  .stat-strip__value--accent   { color: var(--enamel-cobalt); }
  .stat-strip__value--positive { color: var(--enamel-emerald); }
  .stat-strip__value--warning  { color: var(--enamel-gold); }
  .stat-strip__value--negative { color: var(--enamel-vermilion); }
  .stat-strip__label {
    font-size: var(--t-xs);
    font-weight: var(--w-medium);
    text-transform: uppercase;
    letter-spacing: var(--tracking-eyebrow);
    color: var(--ink-3);
    line-height: 1;
  }
  .stat-strip__sub {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--ink-3);
    margin-top: 1px;
  }
}

/* ─────────────────────────────────────────────────────────────────
   G. UTILITIES
   ───────────────────────────────────────────────────────────────── */
@layer utilities {
  .stack       { display: flex; flex-direction: column; gap: var(--s-3); }
  .stack--lg   { gap: var(--s-5); }
  .row         { display: flex; align-items: center; gap: var(--s-3); }
  .row--baseline { align-items: baseline; }
  .row--between  { justify-content: space-between; }

  .muted   { color: var(--ink-3); }
  .mono    { font-family: var(--font-mono); }
  .tabular { font-variant-numeric: tabular-nums; }
  .nowrap  { white-space: nowrap; }
  .grow    { flex: 1 1 0; min-width: 0; }

  .obj-resting  { box-shadow: var(--e1); }
  .obj-lifted   { box-shadow: var(--e2); }
  .obj-floating { box-shadow: var(--e3); }
  .obj-cut      { box-shadow: var(--rout-mid); background: var(--surface); }
  .obj-cut-deep { box-shadow: var(--rout-deep); background: var(--surface); }
}
