/* Smoked Glass 2: Elijah's system for internal apps (picked 2026-11-08, round 3 system 02; version 2 on 2026-11-11).
   Source of truth: C:/BB Projects/design-language/smoked-glass/. Rules: DESIGN.md next to this file.
   Copies live in the apps that use it (consumers.json lists them). Change here first, run `node check.mjs`, then copy.

   This file can be copied as it is: it has no @import (load Geist with a <link>, see DESIGN.md "Using it") and
   every blur goes through var(--sg-backdrop), which survives bb's plugin CSS build.

   Token rule: a token's value is a literal, never another var(--sg-*). An alias is resolved on the element that
   declares it, so it would keep the dark value under .sg-light. Compose tokens in rules, not in other tokens. */

:root, .sg-scope {
  --sg-version: 2;

  /* canvas: the only colourful surface */
  --sg-canvas-top: #13162d;
  --sg-canvas-mid: #1b1a42;
  --sg-canvas-end: #291f56;
  --sg-canvas: linear-gradient(170deg, #13162d 0%, #1b1a42 40%, #291f56 100%);
  /* the three glows, as one background layer stack (no extra DOM, safe on a scroll container) */
  --sg-canvas-glow:
    radial-gradient(560px 560px at 86% 0%, rgba(91, 75, 214, 0.42), transparent 70%),
    radial-gradient(460px 460px at 62% 104%, rgba(45, 111, 214, 0.26), transparent 70%),
    radial-gradient(340px 340px at 100% 76%, rgba(194, 86, 154, 0.2), transparent 70%),
    linear-gradient(170deg, #13162d 0%, #1b1a42 40%, #291f56 100%);

  /* surfaces, from the back forward: panel, raised control, bar, overlay */
  --sg-panel: rgba(14, 16, 27, 0.7);
  --sg-panel-2: rgba(26, 29, 44, 0.72);
  --sg-panel-solid: #121522;                        /* where see-through is not wanted or not available */
  --sg-panel-2-solid: #1a1d2c;
  --sg-panel-edge: rgba(190, 196, 255, 0.1);
  --sg-panel-shadow: inset 0 1px 0 rgba(200, 206, 255, 0.05);   /* the lit top edge of a sheet of glass */
  --sg-bar: rgba(18, 21, 34, 0.92);                 /* sticky and fixed bars: near-solid, cards must not show through */
  --sg-overlay: rgba(18, 21, 34, 0.96);             /* dialogs, drawers, popovers, toasts */
  --sg-overlay-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
  --sg-scrim: rgba(5, 6, 14, 0.6);                  /* behind a dialog */
  --sg-blur: 16px;
  --sg-backdrop: blur(16px);                        /* only on bars and overlays: content passes behind them */

  /* ink and lines. Contrast is checked by check.mjs: ink and muted pass 4.5:1 everywhere, faint on panels only */
  --sg-ink: #e8e9f2;
  --sg-muted: #a0a4bc;                              /* secondary text, on panels and on the bare canvas */
  --sg-faint: #7f84a3;                              /* placeholders, axis labels, disabled. Never on the bare canvas */
  --sg-line: rgba(170, 178, 230, 0.09);
  --sg-line-strong: rgba(170, 178, 230, 0.18);
  --sg-hover: rgba(255, 255, 255, 0.05);
  --sg-press: rgba(255, 255, 255, 0.09);
  --sg-selected: rgba(26, 29, 44, 0.72);            /* the chosen tab or segment */
  --sg-selection: rgba(169, 155, 255, 0.34);

  /* the one action colour */
  --sg-action: #a99bff;
  --sg-action-hover: #b8acff;
  --sg-action-ink: #17142e;
  --sg-action-soft: rgba(169, 155, 255, 0.16);     /* "you changed this" */

  /* state colours: never used for areas. Fill for dots, bars and edges; -ink for words; -soft behind a word */
  --sg-yes: #34d3a6;
  --sg-warn: #f7b955;
  --sg-no: #f2555a;
  --sg-yes-ink: #34d3a6;
  --sg-warn-ink: #f7b955;
  --sg-no-ink: #ff8589;
  --sg-yes-soft: rgba(52, 211, 166, 0.14);
  --sg-warn-soft: rgba(247, 185, 85, 0.13);
  --sg-no-soft: rgba(242, 85, 90, 0.14);

  /* area colours: fixed in every app, one owner each. Fill for dots and bars; -ink when the area is a word */
  --sg-area-tuthill: #5cc98a;
  --sg-area-bb: #9a7bff;
  --sg-area-studioc: #ff8a4c;
  --sg-area-s2p: #4ea8ff;
  --sg-area-messages: #ff6b8b;
  --sg-area-games: #ffd166;
  --sg-area-tuthill-ink: #5cc98a;
  --sg-area-bb-ink: #ab92ff;
  --sg-area-studioc-ink: #ff8a4c;
  --sg-area-s2p-ink: #4ea8ff;
  --sg-area-messages-ink: #ff7c98;
  --sg-area-games-ink: #ffd166;

  /* type */
  --sg-font: "Geist", system-ui, -apple-system, "Segoe UI", sans-serif;
  --sg-mono: "Geist Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --sg-text-xs: 12px;                               /* n, ids, kickers (mono) */
  --sg-text-sm: 13px;                               /* secondary lines, tags */
  --sg-text: 15px;                                  /* body and controls */
  --sg-text-lg: 18px;                               /* panel headings, insights */
  --sg-text-title: 24px;                            /* the page title in a header band */
  --sg-text-display: 40px;                          /* a title that stands alone */

  /* shape */
  --sg-r-panel: 14px;
  --sg-r-control: 10px;
  --sg-r-tag: 8px;
  --sg-tap: 44px;                                   /* the smallest thing a finger can hit */
  --sg-control-h: 44px;                             /* control height: 44 for touch, 38 with a mouse (set below) */

  /* layout (DESIGN.md "Layout"): one centred column, an edge line and a text line 50 px in, a shared header band */
  --sg-col: 800px;
  --sg-gutter: 16px;
  --sg-gutter-wide: 32px;
  --sg-band: 56px;
  --sg-band-wide: 76px;
  --sg-indent: 50px;

  /* motion and stacking */
  --sg-fast: 120ms;
  --sg-ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --sg-z-bar: 20;
  --sg-z-dock: 30;
  --sg-z-overlay: 40;
  --sg-z-toast: 50;
}

@media (hover: hover) and (pointer: fine) {
  :root, .sg-scope { --sg-control-h: 38px; }
}

/* ---------- canvas ---------- */
.sg-canvas { background: var(--sg-canvas-glow); background-color: var(--sg-canvas-mid); color: var(--sg-ink); color-scheme: dark; font-family: var(--sg-font); font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased; scrollbar-color: var(--sg-line-strong) transparent; }
/* On <body> the canvas is a fixed layer behind the page, so the glows stay put while the page scrolls.
   (background-attachment: fixed is ignored by iOS.) On any other element .sg-canvas paints its own background. */
html:has(> body.sg-canvas) { background-color: var(--sg-canvas-mid); color-scheme: dark; scrollbar-color: var(--sg-line-strong) transparent; }
body.sg-canvas { min-height: 100vh; min-height: 100dvh; margin: 0; background: transparent; }
body.sg-canvas::before { content: ""; position: fixed; inset: 0; z-index: -1; background: var(--sg-canvas-glow); background-color: var(--sg-canvas-mid); pointer-events: none; }
:where(.sg-canvas, .sg-scope) ::selection { background: var(--sg-selection); }

/* keyboard focus: one violet ring, on everything. shadcn pages (.sg-scope) keep their own ring, mapped in shadcn-scope.css */
:where(.sg-canvas:not(.sg-scope)) :focus-visible { outline: 2px solid var(--sg-action); outline-offset: 2px; }

/* ---------- plain-HTML component layer (apps without shadcn) ---------- */

/* layout */
.sg-col { box-sizing: border-box; width: 100%; max-width: calc(var(--sg-col) + 2 * var(--sg-gutter)); margin-inline: auto; padding-inline: var(--sg-gutter); }
.sg-band { display: flex; align-items: center; gap: 12px; min-height: var(--sg-band); }

/* panels. No blur: over the smooth canvas a blur changes nothing you can see, and it is the expensive part */
.sg-panel, .sg-card, .sg-stat { box-sizing: border-box; background: var(--sg-panel); border: 1px solid var(--sg-panel-edge); border-radius: var(--sg-r-panel); box-shadow: inset 3px 0 0 var(--sg-edge, transparent), var(--sg-panel-shadow); }
.sg-panel { padding: 18px; }
.sg-card { padding: 13px; }
.sg-panel-h { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 14px; }
.sg-panel-h b { font-weight: 400; font-size: var(--sg-text-lg); letter-spacing: -0.02em; }
/* a status edge is an inset shadow, so it never moves the content */
.sg-edge-yes { --sg-edge: var(--sg-yes); }
.sg-edge-warn { --sg-edge: var(--sg-warn); }
.sg-edge-no { --sg-edge: var(--sg-no); }
.sg-edge-action { --sg-edge: var(--sg-action); }
.sg-edge-muted { --sg-edge: var(--sg-muted); }
/* blank = unknown: a dashed outline, never zero. Drawn as an outline so the box keeps its size */
.sg-unknown { background: transparent; border-color: transparent; box-shadow: none; outline: 1.5px dashed var(--sg-line-strong); outline-offset: -1.5px; }

/* glass: the blur, for layers that content passes behind */
.sg-glass { backdrop-filter: var(--sg-backdrop); -webkit-backdrop-filter: var(--sg-backdrop); }
.sg-bar { background: var(--sg-bar); backdrop-filter: var(--sg-backdrop); -webkit-backdrop-filter: var(--sg-backdrop); }
.sg-bar.top { position: sticky; top: 0; z-index: var(--sg-z-bar); border-bottom: 1px solid var(--sg-line); }
.sg-bar.dock { position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--sg-z-dock); border-top: 1px solid var(--sg-line); padding-bottom: env(safe-area-inset-bottom); }

/* text */
.sg-title { margin: 0; font-weight: 300; font-size: var(--sg-text-display); line-height: 1.05; letter-spacing: -0.035em; }
.sg-band .sg-title { font-size: 20px; letter-spacing: -0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sg-kicker, .sg-n, .sg-id { font: 400 var(--sg-text-xs)/1.4 var(--sg-mono); color: var(--sg-muted); }
.sg-h { display: flex; align-items: center; gap: 10px; margin: 28px 0 10px; font: 400 var(--sg-text-xs)/1.4 var(--sg-mono); letter-spacing: 0.06em; text-transform: uppercase; color: var(--sg-muted); }
.sg-h small { font: inherit; letter-spacing: 0; text-transform: none; }
.sg-h::after { content: ""; flex: 1; height: 1px; background: var(--sg-line); }
.sg-insight { margin: 0; font-weight: 300; font-size: var(--sg-text-lg); line-height: 1.4; letter-spacing: -0.01em; text-wrap: pretty; }
.sg-link { color: var(--sg-action); text-decoration: underline; text-decoration-color: var(--sg-line-strong); text-underline-offset: 3px; }
.sg-link:hover { text-decoration-color: currentColor; }

/* numbers lead */
.sg-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.sg-stat { display: grid; gap: 2px; align-content: start; padding: 14px; container-type: inline-size; }
.sg-stat-k { font-size: var(--sg-text-sm); color: var(--sg-muted); }
.sg-stat-v { font-weight: 200; font-size: clamp(28px, 26cqi, 52px); line-height: 1.05; letter-spacing: -0.04em; font-variant-numeric: tabular-nums; }   /* shrinks in a narrow tile instead of truncating */
.sg-stat-v small { font-size: max(13px, 0.35em); color: var(--sg-muted); letter-spacing: 0; }
.sg-stat-v.unknown, .sg-unknown .sg-stat-v { color: var(--sg-muted); }
.sg-meter { height: 6px; border-radius: 3px; background: var(--sg-line); overflow: hidden; }
.sg-meter::before { content: ""; display: block; height: 100%; width: calc(var(--v, 0) * 100%); border-radius: 3px; background: var(--c, var(--sg-muted)); }
.sg-meter.unknown { background: transparent; outline: 1px dashed var(--sg-line-strong); outline-offset: -1px; }

/* controls */
.sg-btn { box-sizing: border-box; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--sg-control-h); margin: 0; padding: 0 18px; border-radius: var(--sg-r-control); border: 1px solid transparent; background: transparent; color: var(--sg-ink); font: 500 var(--sg-text)/1 var(--sg-font); white-space: nowrap; cursor: pointer; text-decoration: none; transition: background-color var(--sg-fast) var(--sg-ease), border-color var(--sg-fast) var(--sg-ease), color var(--sg-fast) var(--sg-ease); }
.sg-btn.primary { background: var(--sg-action); color: var(--sg-action-ink); }
.sg-btn.primary:hover { background: var(--sg-action-hover); }
.sg-btn.secondary { border-color: var(--sg-line-strong); }
.sg-btn.ghost { color: var(--sg-muted); }
.sg-btn.secondary:hover, .sg-btn.ghost:hover { background: var(--sg-hover); color: var(--sg-ink); }
.sg-btn.secondary:active, .sg-btn.ghost:active { background: var(--sg-press); }
.sg-btn:disabled, .sg-btn[aria-disabled="true"] { opacity: 0.45; cursor: default; pointer-events: none; }

.sg-label { display: block; margin-bottom: 6px; font-size: var(--sg-text-sm); color: var(--sg-muted); }
.sg-hint { margin-top: 6px; font-size: var(--sg-text-sm); color: var(--sg-muted); }
.sg-error { margin-top: 6px; font-size: var(--sg-text-sm); color: var(--sg-no-ink); }
.sg-input, .sg-select, .sg-textarea { box-sizing: border-box; min-height: var(--sg-control-h); margin: 0; padding: 0 12px; background: var(--sg-panel-2); border: 1px solid var(--sg-line-strong); border-radius: var(--sg-r-control); color: var(--sg-ink); font: 400 var(--sg-text)/1.4 var(--sg-font); transition: border-color var(--sg-fast) var(--sg-ease); }
.sg-textarea { display: block; width: 100%; padding: 10px 12px; resize: vertical; }
.sg-input::placeholder, .sg-textarea::placeholder { color: var(--sg-faint); opacity: 1; }
.sg-input:hover, .sg-select:hover, .sg-textarea:hover { border-color: var(--sg-muted); }
.sg-input:focus-visible, .sg-select:focus-visible, .sg-textarea:focus-visible { outline: 2px solid var(--sg-action); outline-offset: -1px; border-color: transparent; }
.sg-input[aria-invalid="true"], .sg-select[aria-invalid="true"], .sg-textarea[aria-invalid="true"] { border-color: var(--sg-no); }
.sg-input:disabled, .sg-select:disabled, .sg-textarea:disabled { opacity: 0.45; }
@media (pointer: coarse) { .sg-input, .sg-select, .sg-textarea { font-size: 16px; } }   /* iOS zooms the page on focus under 16 px */

.sg-check { width: 18px; height: 18px; margin: 0; accent-color: var(--sg-action); }
.sg-switch { appearance: none; -webkit-appearance: none; box-sizing: border-box; position: relative; flex: none; width: 36px; height: 22px; margin: 0; border-radius: 11px; border: 1px solid var(--sg-line-strong); background: var(--sg-panel-2); cursor: pointer; transition: background-color var(--sg-fast) var(--sg-ease), border-color var(--sg-fast) var(--sg-ease); }
.sg-switch::before { content: ""; box-sizing: border-box; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--sg-muted); transition: transform var(--sg-fast) var(--sg-ease), background-color var(--sg-fast) var(--sg-ease); }
.sg-switch:checked { background: var(--sg-action); border-color: transparent; }
.sg-switch:checked::before { transform: translateX(14px); background: var(--sg-action-ink); }

.sg-seg { display: inline-flex; padding: 3px; gap: 2px; border: 1px solid var(--sg-line); border-radius: var(--sg-r-control); }
.sg-seg button { min-height: calc(var(--sg-control-h) - 8px); margin: 0; padding: 0 14px; border: 0; border-radius: 8px; background: transparent; color: var(--sg-muted); font: inherit; cursor: pointer; }
.sg-seg button:hover { color: var(--sg-ink); }
.sg-seg button.on, .sg-seg button[aria-selected="true"], .sg-seg button[aria-pressed="true"] { background: var(--sg-selected); color: var(--sg-ink); }

/* a row of sections that scrolls sideways on a phone */
.sg-tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.sg-tabs::-webkit-scrollbar { display: none; }
.sg-tab { flex: 0 0 auto; min-height: var(--sg-control-h); margin: 0; padding: 0 12px; border: 0; border-radius: 8px; background: transparent; color: var(--sg-muted); font: 400 14px/1 var(--sg-font); white-space: nowrap; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.sg-tab:hover { color: var(--sg-ink); }
.sg-tab.on, .sg-tab[aria-selected="true"], .sg-tab[aria-current="page"] { background: var(--sg-selected); color: var(--sg-ink); }
.sg-tab small { font: 400 11.5px/1 var(--sg-mono); color: var(--sg-muted); }

/* tags name an area (set --c to its colour); chips state a fact. Colour only on what someone changed or on a state */
.sg-tag { display: inline-flex; align-items: center; gap: 7px; height: 26px; padding: 0 10px; border-radius: var(--sg-r-tag); background: var(--sg-panel-2); font-size: 12.5px; white-space: nowrap; }
.sg-tag::before { content: ""; box-sizing: border-box; width: 8px; height: 8px; border-radius: 2px; background: var(--c, var(--sg-muted)); }
.sg-chip { display: inline-flex; align-items: center; height: 26px; padding: 0 10px; border-radius: var(--sg-r-tag); background: var(--sg-panel-2); color: var(--sg-muted); font-size: 12.5px; white-space: nowrap; }
.sg-chip.changed { background: var(--sg-action-soft); color: var(--sg-action); }
.sg-chip.yes { background: var(--sg-yes-soft); color: var(--sg-yes-ink); }
.sg-chip.warn { background: var(--sg-warn-soft); color: var(--sg-warn-ink); }
.sg-chip.no { background: var(--sg-no-soft); color: var(--sg-no-ink); }

.sg-rows { list-style: none; margin: 0; padding: 0; }
.sg-rows > li { display: grid; grid-template-columns: 38px 1fr auto auto; gap: 12px; align-items: center; min-height: 52px; border-bottom: 1px solid var(--sg-line); }
.sg-rows > li:last-child { border-bottom: 0; }
.sg-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.sg-table th { padding: 8px 12px 8px 0; text-align: left; font: 400 var(--sg-text-xs)/1.4 var(--sg-mono); color: var(--sg-muted); border-bottom: 1px solid var(--sg-line-strong); }
.sg-table td { padding: 10px 12px 10px 0; border-bottom: 1px solid var(--sg-line); vertical-align: baseline; }
.sg-table tr:last-child td { border-bottom: 0; }
.sg-table .sg-num { text-align: right; padding-right: 0; font-variant-numeric: tabular-nums; }

/* overlays */
.sg-dialog { box-sizing: border-box; width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 20px; border: 1px solid var(--sg-panel-edge); border-radius: var(--sg-r-panel); background: var(--sg-overlay); color: var(--sg-ink); box-shadow: var(--sg-overlay-shadow); backdrop-filter: var(--sg-backdrop); -webkit-backdrop-filter: var(--sg-backdrop); }
.sg-dialog::backdrop { background: var(--sg-scrim); }
.sg-toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: var(--sg-z-toast); transform: translateX(-50%); max-width: calc(100vw - 32px); padding: 10px 16px; border: 1px solid var(--sg-panel-edge); border-radius: var(--sg-r-control); background: var(--sg-overlay); color: var(--sg-ink); box-shadow: var(--sg-overlay-shadow); font-size: 14px; }

/* ---------- phone first: desktop rules sit in a min-width block so the phone layout cannot change ---------- */
@media (max-width: 760px) {
  .sg-title { font-size: 32px; }
  .sg-rows > li { grid-template-columns: 30px 1fr auto; }
}
@media (min-width: 761px) {
  .sg-col { max-width: calc(var(--sg-col) + 2 * var(--sg-gutter-wide)); padding-inline: var(--sg-gutter-wide); }
  .sg-band { min-height: var(--sg-band-wide); }
  .sg-band .sg-title { font-size: var(--sg-text-title); }
  .sg-indent { margin-left: var(--sg-indent); }
}

/* ---------- what happens when the nice parts are missing ---------- */

/* the person asked the system for less transparency: solid panels, no blur */
@media (prefers-reduced-transparency: reduce) {
  :root, .sg-scope { --sg-panel: #121522; --sg-panel-2: #1a1d2c; --sg-bar: #121522; --sg-overlay: #121522; --sg-backdrop: none; }
}
/* more contrast: brighter secondary text, firmer lines */
@media (prefers-contrast: more) {
  :root, .sg-scope { --sg-muted: #c3c6d9; --sg-faint: #a0a4bc; --sg-line: rgba(170, 178, 230, 0.22); --sg-line-strong: rgba(170, 178, 230, 0.42); --sg-panel-edge: rgba(190, 196, 255, 0.3); }
}
@media (prefers-reduced-motion: reduce) {
  .sg-btn, .sg-input, .sg-select, .sg-textarea, .sg-switch, .sg-switch::before { transition: none; }
}
/* Windows high contrast: colours are replaced, so edges that were shadows or tints become real borders */
@media (forced-colors: active) {
  .sg-panel, .sg-card, .sg-stat, .sg-dialog, .sg-toast, .sg-tag, .sg-chip, .sg-btn { border: 1px solid CanvasText; }
  .sg-edge-yes, .sg-edge-warn, .sg-edge-no, .sg-edge-action, .sg-edge-muted { border-left-width: 4px; }
  .sg-unknown { border: 1px dashed CanvasText; outline: none; }   /* unknown stays dashed */
  .sg-btn.primary { background: Highlight; color: HighlightText; forced-color-adjust: none; }
  .sg-tag::before, .sg-meter::before { forced-color-adjust: none; }
  .sg-switch:checked { background: Highlight; }
}
/* paper: no canvas, black on white */
@media print {
  :root, .sg-scope { --sg-canvas-glow: none; --sg-canvas-mid: #ffffff; --sg-panel: #ffffff; --sg-panel-2: #f3f3f6; --sg-bar: #ffffff; --sg-ink: #111111; --sg-muted: #444444; --sg-faint: #666666; --sg-line: #dddddd; --sg-line-strong: #bbbbbb; --sg-panel-edge: #bbbbbb; --sg-panel-shadow: none; }
  .sg-canvas, html:has(> body.sg-canvas) { color-scheme: light; }
  .sg-bar.top, .sg-bar.dock { position: static; }
}
