/* =========================================================
   Font Studio — tool styles
   LAB-208. Loads after labs.css.

   SCOPE: everything here is font-tool-specific. The generic
   parts — fields, tabs, buttons, code blocks, section rhythm —
   live in labs.css so this tool inherits them instead of
   re-inventing them (see labs-deploy-checklist.md / LAB-209 §3).

   RULE INHERITED FROM labs.css: a raw hex here is a bug. Tokens
   only — reuse --bg-elev-1, --brand-blue, --r-md, --ease-out etc.,
   new ones namespaced --labs-*.
   ========================================================= */

/* =========================================================
   DEGRADATION GUARD — do not remove. LAB-209 §4.

   labs.css carries `[hidden] { display: none !important }`
   because the UA default sits at specificity 0-1-0 and loses to
   any `display: grid` / `display: flex` this file adds later.
   The rule that defeats [hidden] and the rule that restores it
   must live in the same file — this file is what will create
   the conflict once the grid/flex rules below are filled in, so
   this file carries the fix now, before that happens.
   ========================================================= */

[hidden] { display: none !important; }

/* =======================================================
   NOSCRIPT
   ======================================================= */

.fs-noscript p { margin: 0 0 12px; color: var(--text-secondary); line-height: 1.6; }
.fs-noscript p:last-child { margin-bottom: 0; }
.fs-noscript-alt { font-size: 14px; color: var(--labs-text-muted); }
.fs-noscript-alt a { color: var(--brand-blue-light); text-decoration: underline; }

/* =======================================================
   Section app-mounts still empty (step 4+ fills them in as
   the markup is built). Layout rules for each cluster
   (.fs-compare, .fs-axes, .fs-scale, .fs-readability,
   .fs-background, .fs-tokens, .fs-saved) are added alongside
   the markup that fills them, not before — an empty ruleset
   here would be dead weight with nothing to style.
   ======================================================= */

.fs-toast {
  position: fixed;
  inset: auto 20px 20px auto;
  z-index: 40;
}

/* =======================================================
   1 · STAGE — preview + picker + controls
   ======================================================= */

.fs-preview {
  margin-bottom: var(--labs-grid-gap);
  overflow: hidden;
}

.fs-preview-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 18px;
}

.fs-preview-family {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.fs-preview-badge {
  font-size: 12px;
  color: var(--labs-text-muted);
}

/* Headline and paragraph render in the picked font. app.js sets
   font-family/size/weight/line-height/letter-spacing/text-align
   as inline style, since those are all live, per-render values —
   the one case on this page where inline style is correct rather
   than a token miss. */
.fs-headline {
  outline: none;
  color: var(--text-primary);
  margin: 0 0 20px;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.fs-headline:focus-visible,
.fs-paragraph:focus-visible {
  outline: 2px solid var(--brand-blue-light);
  outline-offset: 4px;
  border-radius: 2px;
}

.fs-measure-wrap {
  position: relative;
  margin-bottom: 24px;
}

.fs-paragraph {
  outline: none;
  color: var(--text-secondary);
  max-width: 100%;
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* Marks positioned in `ch` units, which resolve against THIS
   element's own font-family and font-size — the same font/size
   app.js applies to .fs-paragraph. That is what makes the guide
   track the actual font instead of a generic estimate. */
.fs-measure-marks {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.fs-measure-mark {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 0;
  border-left: 1px dashed var(--border-strong);
}
.fs-measure-mark::after {
  content: attr(data-label);
  position: absolute;
  top: -18px;
  left: 4px;
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--labs-text-muted);
  white-space: nowrap;
}

.fs-specimen {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 20px;
  border-top: 1px solid var(--border-subtle);
  color: var(--text-primary);
}
.fs-specimen-row {
  font-size: 22px;
  line-height: 1.4;
  word-break: break-all;
}

/* ---------- workbench: picker | controls ---------- */

.fs-workbench {
  display: grid;
  grid-template-columns: minmax(0, 320px) minmax(0, 1fr);
  gap: var(--labs-grid-gap);
  align-items: start;
}
@media (max-width: 860px) {
  .fs-workbench { grid-template-columns: 1fr; }
}

.fs-picker {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.fs-font-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 360px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg-elev-1);
}

.fs-font-group-label {
  position: sticky;
  top: 0;
  padding: 8px 12px;
  background: var(--bg-elev-1);
  border-bottom: 1px solid var(--border);
  font-family: var(--font-display);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--labs-text-muted);
}

.fs-font-btn {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  text-align: left;
  color: var(--text-secondary);
  font-size: 15px;
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: color var(--t-fast) var(--ease-out), background-color var(--t-fast) var(--ease-out);
}
.fs-font-list li:last-child .fs-font-btn { border-bottom: none; }
.fs-font-btn:hover { color: var(--text-primary); background: var(--bg-elev-2); }
.fs-font-btn:focus-visible {
  outline: 2px solid var(--brand-blue-light);
  outline-offset: -2px;
}
.fs-font-btn.is-active {
  color: var(--text-primary);
  background: var(--bg-elev-2);
  box-shadow: inset 3px 0 0 var(--brand-blue);
}
.fs-font-btn-meta {
  flex: none;
  font-size: 11px;
  color: var(--labs-text-muted);
}

.fs-font-empty {
  font-size: 13px;
  color: var(--labs-text-muted);
  margin: 0;
  padding: 4px 2px;
}

/* ---------- upload dropzone ---------- */

.fs-dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 20px 16px;
  text-align: center;
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-md);
  background: var(--bg-elev-1);
  transition: border-color var(--t-fast) var(--ease-out), background-color var(--t-fast) var(--ease-out);
}
.fs-dropzone.is-dragover {
  border-color: var(--brand-blue-light);
  background: color-mix(in srgb, var(--brand-blue-light) 8%, var(--bg-elev-1));
}

.fs-dropzone-label {
  margin: 0;
  font-size: 13.5px;
  color: var(--text-secondary);
}

.fs-dropzone .labs-field-help {
  margin: 0;
}

.fs-upload-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.fs-upload-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.fs-upload-select {
  flex: 1;
  min-width: 0;
  text-align: left;
  padding: 8px 12px;
  border-radius: var(--r-md);
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: color var(--t-fast) var(--ease-out), background-color var(--t-fast) var(--ease-out), border-color var(--t-fast) var(--ease-out);
}
.fs-upload-select:hover { color: var(--text-primary); background: var(--bg-elev-2); }
.fs-upload-select:focus-visible { outline: 2px solid var(--brand-blue-light); outline-offset: 2px; }
.fs-upload-select.is-active {
  color: var(--text-primary);
  background: var(--bg-elev-2);
  border-color: var(--brand-blue);
}

.fs-upload-remove {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elev-1);
  color: var(--labs-text-muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  transition: color var(--t-fast) var(--ease-out), background-color var(--t-fast) var(--ease-out), border-color var(--t-fast) var(--ease-out);
}
.fs-upload-remove:hover { color: var(--text-primary); background: var(--bg-elev-2); border-color: var(--border-strong); }
.fs-upload-remove:focus-visible { outline: 2px solid var(--brand-blue-light); outline-offset: 2px; }

.fs-controls {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.labs-field-label-standalone {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.fs-slider-field label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.fs-slider-val {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  font-weight: 400;
  letter-spacing: normal;
  text-transform: none;
  color: var(--labs-text-muted);
}

/* Range input — no generic primitive exists yet (Font Studio is
   the first Labs tool to need one). If a second tool needs the
   same slider, promote this block to labs.css the way the
   [hidden] guard's siblings were promoted — rename, don't
   rewrite.

   Scoped to the whole page, not just .fs-controls: step 6's
   Compare size slider and step 7's axis-playground sliders sit
   outside .fs-controls and were silently falling back to each
   browser's native (inconsistent) thumb until this was widened
   during step 8 — caught while adding the type-scale base-size
   slider, which would have been the third slider to hit the same
   gap. studio.css only loads on this one page, so a page-wide
   selector carries no risk of leaking onto another tool. */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: var(--r-pill);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--brand-blue-light);
  border: 2px solid var(--bg-base);
  box-shadow: 0 0 0 1px var(--brand-blue-light);
  margin-top: -6.5px;
}
input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--brand-blue-light);
  border: 2px solid var(--bg-base);
  box-shadow: 0 0 0 1px var(--brand-blue-light);
}
input[type="range"]:focus-visible {
  outline: 2px solid var(--brand-blue-light);
  outline-offset: 3px;
}

.fs-reset {
  align-self: flex-start;
  margin-top: 4px;
}

/* =======================================================
   2 · COMPARE
   ======================================================= */

.fs-compare-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: var(--labs-grid-gap);
}
.fs-compare-controls .labs-field { min-width: 180px; flex: 1 1 180px; }
.fs-compare-controls .fs-compare-size-field { min-width: 140px; flex: 1 1 140px; }

.fs-compare-swap {
  flex: none;
  /* Sits between two fields whose <label> sets their own height —
     nudge down so the button lines up with the <select> boxes,
     not their labels. */
  margin-bottom: 1px;
}

.fs-compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--labs-grid-gap);
}
@media (max-width: 720px) {
  .fs-compare-grid { grid-template-columns: 1fr; }
}

.fs-compare-pane {
  min-width: 0;
  overflow: hidden;
}

.fs-compare-pane-label {
  margin: 0 0 14px;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 600;
  color: var(--labs-text-muted);
}

.fs-compare-headline {
  color: var(--text-primary);
  margin: 0 0 12px;
  word-break: break-word;
  overflow-wrap: anywhere;
  line-height: 1.15;
}
.fs-compare-paragraph {
  color: var(--text-secondary);
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* =======================================================
   5 · READABILITY
   ======================================================= */

.fs-readability-body {
  display: flex;
  align-items: center;
  gap: 24px;
}
@media (max-width: 560px) {
  .fs-readability-body { flex-direction: column; align-items: flex-start; }
}

.fs-readability-swatch {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 88px;
  height: 88px;
  border-radius: var(--r-lg);
  border: 1px solid var(--labs-card-border);
  /* background-color set inline — the current bg swatch's own
     color, same "this is user-chosen data" exception as .fs-bg-stage. */
  transition: background-color var(--t-base) var(--ease-out);
}

.fs-readability-sample {
  font-size: 34px;
  line-height: 1;
  /* color/font-family/weight/size all set inline — this renders
     the CURRENT stage type at its CURRENT size, not a fixed demo. */
}

.fs-readability-stats { min-width: 0; }

.fs-readability-lc {
  margin: 0 0 4px;
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.fs-readability-verdict {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: 600;
}
/* Same semantic tokens Color Studio's own APCA readout uses
   (.cs-apca-use.is-pass/.is-fail) — one status vocabulary
   across the Labs suite, not a second one invented here. */
.fs-readability-verdict.is-pass { color: var(--labs-status-live); }
.fs-readability-verdict.is-fail { color: var(--labs-status-wip); font-weight: 700; }

.fs-readability-note {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--labs-text-muted);
}

.fs-readability-empty {
  font-size: 14px;
  line-height: 1.6;
  color: var(--labs-text-muted);
  margin: 0;
}

/* =======================================================
   6 · ON BACKGROUND
   ======================================================= */

.fs-bg-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  margin-bottom: var(--labs-grid-gap);
}

.fs-bg-custom-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Native color input — deliberately minimal chrome so the swatch
   itself (the actual color) reads as the control, not a frame
   around it. */
.fs-bg-native {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: none;
  cursor: pointer;
}
.fs-bg-native::-webkit-color-swatch-wrapper { padding: 3px; }
.fs-bg-native::-webkit-color-swatch { border: none; border-radius: var(--r-sm); }
.fs-bg-native::-moz-color-swatch { border: none; border-radius: var(--r-sm); }
.fs-bg-native:focus-visible {
  outline: 2px solid var(--brand-blue-light);
  outline-offset: 2px;
}

.fs-bg-stage {
  padding: clamp(28px, 4vw, 48px);
  border-radius: var(--r-lg);
  border: 1px solid var(--labs-card-border);
  /* background-color set inline by app.js — this is user-chosen
     data, the one case a raw color legitimately isn't a token. */
  transition: background-color var(--t-base) var(--ease-out);
}

.fs-bg-headline {
  margin: 0 0 14px;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.fs-bg-paragraph {
  margin: 0;
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* =======================================================
   3 · VARIABLE AXES
   ======================================================= */

.fs-axes-body {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
}

.fs-axis-field .fs-axis-val {
  /* Carries the raw OpenType tag (e.g. "· wght") alongside the
     value — depth over the incumbents is the whole positioning
     bet, and the tag is the one detail a generic slider UI never
     shows. */
  text-transform: none;
}

.fs-axes-empty {
  font-size: 14px;
  line-height: 1.6;
  color: var(--labs-text-muted);
  margin: 0;
}

/* =======================================================
   4 · TYPE SCALE
   ======================================================= */

.fs-scale-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--labs-grid-gap);
  margin-bottom: var(--labs-grid-gap);
}

.fs-scale-table {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg-elev-1);
  overflow: hidden;
}

.fs-scale-row {
  display: grid;
  grid-template-columns: 76px 132px 1fr;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
}
.fs-scale-table .fs-scale-row:last-child { border-bottom: none; }

/* The step whose sizePx === the base exactly (step 0) — the one
   row every other row is scaled relative to. */
.fs-scale-row-base {
  background: var(--bg-elev-2);
  box-shadow: inset 3px 0 0 var(--brand-blue);
}

.fs-scale-row-label {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--labs-text-muted);
}

.fs-scale-row-meta {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--labs-text-muted);
  white-space: nowrap;
}

/* Renders in the CURRENT stage font/weight/axis values — "set in
   the font you're actually looking at" is the whole reason this
   panel exists instead of a generic ratio calculator. */
.fs-scale-row-sample {
  min-width: 0;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 640px) {
  .fs-scale-row { grid-template-columns: 1fr; gap: 4px; }
  .fs-scale-row-sample { white-space: normal; }
}

/* =======================================================
   7 · TOKEN EXPORT

   .labs-code / .labs-btn-sm / .labs-tabs / .labs-field /
   .labs-input are the generic primitives shared with Color
   Studio (labs.css §1's own comment names Font Studio as an
   intended second consumer) — only the tool-specific layout
   wrapper classes live here, same split as Color Studio's
   .cs-token-bar / .cs-code-wrap / .cs-code-copy.
   ======================================================= */

.fs-mono {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 14px;
  letter-spacing: 0.01em;
}

.fs-token-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.fs-token-name-field { width: min(260px, 100%); }

.fs-code-wrap { position: relative; }

.fs-code-copy {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  background: var(--bg-elev-2);
}

/* =======================================================
   8 · SAVED — layout mirrors Color Studio's .cs-saved-*
   (fs-saved-chip in place of a color swatch: there is no
   visual equivalent for "a font", so the chip is a label
   instead of a circle).
   ======================================================= */

.fs-saved-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

.fs-saved-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.fs-saved-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 8px 14px;
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
}

.fs-saved-chip {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  cursor: pointer;
  text-align: left;
}
.fs-saved-chip:disabled { cursor: not-allowed; opacity: 0.5; }
.fs-saved-chip:focus-visible {
  outline: 2px solid var(--brand-blue-light);
  outline-offset: 2px;
}

.fs-saved-chip-family {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.fs-saved-chip-meta {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--labs-text-muted);
}

.fs-saved-del {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  line-height: 1;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: color var(--t-fast) var(--ease-out), background-color var(--t-fast) var(--ease-out);
}
.fs-saved-del:hover { color: var(--text-primary); background: var(--bg-elev-2); }
.fs-saved-del:focus-visible {
  outline: 2px solid var(--brand-blue-light);
  outline-offset: 2px;
}

.fs-saved-empty {
  font-size: 14px;
  color: var(--labs-text-muted);
  margin: 0;
}
