/* HFT-52 explainers: shared tokens and controls.
   Layout: one bordered instrument panel per page (header → controls →
   figure → readout), embedded in week guides or opened on its own.
   Colors mirror tepy.dev (styles/globals.css) and the validated dataviz
   palette: slot 1 blue, slot 2 orange, slot 3 aqua; status good/critical. */

@font-face { font-family: "TT Commons"; src: url("fonts/tt_commons_regular.otf") format("opentype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "TT Commons"; src: url("fonts/tt_commons_bold.otf") format("opentype"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Canela"; src: url("fonts/canela_light.otf") format("opentype"); font-weight: 300; font-display: swap; }

:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --sunken: #f2f2f1;
  --fg: #1a1a1a;
  --muted: #525863;
  --line: #e5e5e5;
  --grid: #ececea;
  --accent: #016d75;
  --accent-soft: rgba(1, 109, 117, 0.12);
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --s1-soft: rgba(42, 120, 214, 0.16);
  --s2-soft: rgba(235, 104, 52, 0.16);
  --s3-soft: rgba(27, 175, 122, 0.16);
  --good: #0ca30c;
  --warn: #b7791f;
  --critical: #d03b3b;
  --code-bg: #24292e;
  --code-fg: #c9d1d9;

  --font-ui: "TT Commons", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Canela", ui-serif, Georgia, "Times New Roman", serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111111; --surface: #171717; --sunken: #1d1d1c; --fg: #ededed; --muted: #9ca3af;
    --line: #2a2a2a; --grid: #242423; --accent: #2dd4bf; --accent-soft: rgba(45, 212, 191, 0.14);
    --s1: #3987e5; --s2: #d95926; --s3: #199e70;
    --s1-soft: rgba(57, 135, 229, 0.22); --s2-soft: rgba(217, 89, 38, 0.22); --s3-soft: rgba(25, 158, 112, 0.22);
    --good: #2fb52f; --warn: #d69e2e; --critical: #e05a5a; --code-bg: #1e1e1e; --code-fg: #c9d1d9;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111111; --surface: #171717; --sunken: #1d1d1c; --fg: #ededed; --muted: #9ca3af;
  --line: #2a2a2a; --grid: #242423; --accent: #2dd4bf; --accent-soft: rgba(45, 212, 191, 0.14);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70;
  --s1-soft: rgba(57, 135, 229, 0.22); --s2-soft: rgba(217, 89, 38, 0.22); --s3-soft: rgba(25, 158, 112, 0.22);
  --good: #2fb52f; --warn: #d69e2e; --critical: #e05a5a; --code-bg: #1e1e1e; --code-fg: #c9d1d9;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 var(--font-ui);
  padding-block: 16px;
  padding-inline: 16px;
}
body.embed { padding: 0; background: var(--bg); }

.hx { max-width: 960px; margin: 0 auto; display: grid; gap: 16px; }
.hx-intro { display: grid; gap: 6px; max-width: 68ch; }
.hx-intro h1 { font: 300 clamp(28px, 4vw, 40px)/1.1 var(--font-display); margin: 0; text-wrap: balance; }
.hx-intro p { margin: 0; color: var(--muted); }
body.embed .standalone-only { display: none !important; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.panel-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--sunken); }
.eyebrow { font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.panel-body { padding: 14px; display: grid; gap: 14px; }
.panel-head .spacer { flex: 1; }

.row { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; }
.grid-2 { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-2 > * { min-width: 0; }

/* Controls */
button, .btn {
  font: 600 12px/1 var(--font-ui); letter-spacing: 0.01em;
  border: 1px solid var(--line); background: var(--surface); color: var(--fg);
  padding: 7px 11px; border-radius: 7px; cursor: pointer;
}
button:hover { border-color: var(--accent); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--surface); }
button:disabled { opacity: 0.45; cursor: default; }
.seg { display: inline-flex; padding: 2px; gap: 2px; background: var(--sunken); border: 1px solid var(--line); border-radius: 8px; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 6px 10px; border-radius: 6px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--accent); box-shadow: 0 0 0 1px var(--line); }
label.ctl { display: grid; gap: 4px; font-size: 12px; color: var(--muted); min-width: 160px; }
label.ctl output { color: var(--fg); font: 600 11px var(--font-mono); }
label.ctl .lab { display: flex; justify-content: space-between; gap: 8px; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

/* Readouts */
.stat { display: grid; gap: 2px; }
.stat .k { font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.stat .v { font: 600 16px/1.2 var(--font-mono); font-variant-numeric: tabular-nums; }
.note { font-size: 13px; color: var(--muted); max-width: 72ch; }
.note strong { color: var(--fg); }
.mono { font-family: var(--font-mono); font-size: 0.88em; font-variant-numeric: tabular-nums; }
code { font: 0.92em var(--font-mono); background: var(--accent-soft); color: var(--accent); padding: 0.05em 0.3em; border-radius: 4px; }
.chip { display: inline-flex; align-items: center; gap: 6px; font: 600 11px/1 var(--font-ui); padding: 5px 8px; border-radius: 999px; background: var(--sunken); color: var(--muted); }
.chip.good { background: color-mix(in srgb, var(--good) 15%, transparent); color: var(--good); }
.chip.bad { background: color-mix(in srgb, var(--critical) 15%, transparent); color: var(--critical); }
.chip.warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

table.hx-table { border-collapse: collapse; width: 100%; font-size: 13px; }
table.hx-table th, table.hx-table td { text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
table.hx-table th:first-child, table.hx-table td:first-child { text-align: left; }
table.hx-table th { font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.scroll-x { overflow-x: auto; }

/* Figures */
.fig { position: relative; width: 100%; }
.fig canvas, .fig svg { display: block; width: 100%; }
.tip {
  position: absolute; pointer-events: none; z-index: 2; min-width: 120px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12); padding: 8px 10px; font-size: 12px;
}
.tip .t { color: var(--muted); margin-bottom: 4px; }
.tip .r { display: flex; justify-content: space-between; gap: 12px; font-family: var(--font-mono); font-size: 11px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
