/* Feather design tokens — shared by the web client and the desktop shell.
 *
 * The palette, spacing, radii and type scale live here and nowhere else; both
 * style.css files only reference `var(--token)`. A dark theme is a value
 * override inside `prefers-color-scheme: dark`, never a rule override. The
 * desktop shell pins `<html class="light-only">` because its window is light
 * regardless of the OS theme.
 *
 * The web server serves exactly three files (index.html, app.js, style.css), so
 * scripts/build-web.sh concatenates this file in front of web/src/style.css
 * instead of shipping a fourth request. desktop/src/tokens.css repeats the same
 * token declarations for the Vite build, which does not resolve imports outside
 * its own root; the two files differ only in this header comment. Change the
 * declarations in both together.
 */

:root {
  color-scheme: light dark;

  /* Type ------------------------------------------------------------------ */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;

  --fs-11: 11.5px;
  --fs-12: 12px;
  --fs-13: 13px;
  --fs-15: 15px;
  --fs-20: 20px;

  --fw-regular: 400;
  --fw-medium: 500;
  --fw-strong: 600;

  --lh-tight: 1.35;
  --lh-body: 1.6;

  /* Space (4 / 8 / 12 / 16 / 24 / 32) ------------------------------------- */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;

  /* Radius (6 / 10 / 14 / pill) ------------------------------------------- */
  --r-s: 6px;
  --r-m: 10px;
  --r-l: 14px;
  --r-pill: 999px;

  /* Light palette --------------------------------------------------------- */
  --bg: #f3f5f9;
  --stage: #e6ecf6;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --surface-3: #eef1f7;
  --overlay: rgba(255, 255, 255, 0.88);

  --text: #171b22;
  --text-muted: #59626f;
  --text-faint: #68717e;

  /* Divider hairlines. Never used on an interactive boundary. */
  --line: #e2e6ed;
  --line-soft: #edf0f5;
  /* Interactive boundary: >= 3:1 against --bg, --stage and --surface. */
  --line-strong: #7f8896;

  --accent: #2f5be0;
  --accent-hover: #274cc0;
  --accent-active: #203fa3;
  --accent-fg: #ffffff;
  --accent-soft: #e9effe;
  --accent-line: #bfd0fa;

  --ok: #0f7a4d;
  --ok-soft: #e7f5ee;
  --ok-line: #b2dcc7;

  --warn: #94590a;
  --warn-soft: #fdf2e1;
  --warn-line: #ebd2a6;

  --err: #b42318;
  --err-soft: #fdeeec;
  --err-line: #f0c4be;

  --focus: #2f5be0;

  --shadow-1: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow-2: 0 12px 32px rgba(16, 24, 40, 0.14);

}

@media (prefers-color-scheme: dark) {
  :root:not(.light-only) {
    --bg: #0d1116;
    --stage: #0a0f1d;
    --surface: #151a21;
    --surface-2: #1a202a;
    --surface-3: #212833;
    --overlay: rgba(21, 26, 33, 0.88);

    --text: #e8ebf0;
    --text-muted: #9aa3b0;
    --text-faint: #7b8592;

    --line: #262d38;
    --line-soft: #1e242d;
    --line-strong: #6b7480;

    --accent: #6d8cff;
    --accent-hover: #829bff;
    --accent-active: #96abff;
    --accent-fg: #0b0e13;
    --accent-soft: #1b2440;
    --accent-line: #35456e;

    --ok: #5ad19a;
    --ok-soft: #12251c;
    --ok-line: #2b5745;

    --warn: #e3a458;
    --warn-soft: #2a2114;
    --warn-line: #5c4826;

    --err: #ff9384;
    --err-soft: #2c1715;
    --err-line: #5f332e;

    --focus: #6d8cff;

    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-2: 0 16px 40px rgba(0, 0, 0, 0.55);

  }
}
/* Feather web client.
 *
 * Every colour, radius, gap and font size below comes from tokens.css; a
 * component rule never hard-codes a hex value or a pixel size that belongs to
 * the scale. Dark mode changes token values only. scripts/build-web.sh
 * concatenates tokens.css in front of this file, because the server serves a
 * fixed set of three assets.
 */

* { box-sizing: border-box; }

/* An author-level `display` rule outranks the user agent's [hidden] rule, so
   every panel that toggles the attribute needs this to actually disappear. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-13);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   Buttons
   A secondary button carries a 3:1 boundary; the main action is the only
   filled accent surface on screen at any one time. */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s1);
  height: 30px;
  padding: 0 var(--s3);
  font: inherit;
  font-size: var(--fs-12);
  font-weight: var(--fw-medium);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-s);
  cursor: pointer;
  white-space: nowrap;
  transition: background 120ms ease, border-color 120ms ease;
}
.btn:hover:not(:disabled) { background: var(--surface-3); }
.btn:active:not(:disabled) { background: var(--surface-3); border-color: var(--text-muted); }
.btn:disabled {
  color: var(--text-faint);
  background: var(--surface-2);
  border-color: var(--line);
  cursor: default;
}
.btn.primary {
  color: var(--accent-fg);
  background: var(--accent);
  border-color: var(--accent);
}
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.primary:active:not(:disabled) { background: var(--accent-active); border-color: var(--accent-active); }
.btn.primary:disabled {
  color: var(--accent-fg);
  background: var(--accent);
  border-color: var(--accent);
  opacity: 0.5;
}
.btn.lg { height: 40px; padding: 0 var(--s5); font-size: var(--fs-13); border-radius: var(--r-m); }
.btn.block { width: 100%; }

/* --------------------------------------------------------------------------
   Shell */

.app { display: flex; flex-direction: column; height: 100%; }

.topbar {
  display: flex;
  align-items: center;
  gap: var(--s4);
  height: 52px;
  padding: 0 var(--s4);
  flex: none;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: var(--s2); flex: none; }
.brand strong {
  font-size: var(--fs-13);
  font-weight: var(--fw-strong);
  letter-spacing: 0.01em;
}
.brand .mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: var(--r-s);
  color: #fff;
  background: var(--accent);
}
.brand .mark svg { width: 12px; height: 12px; display: block; }

.doc {
  display: flex;
  align-items: center;
  gap: var(--s3);
  flex: 1 1 auto;
  min-width: 0;
  padding-left: var(--s4);
  border-left: 1px solid var(--line);
  height: 26px;
}
.doc-title {
  font-size: var(--fs-13);
  font-weight: var(--fw-strong);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.doc-sep { width: 1px; height: 14px; background: var(--line); flex: none; }
/* Without a model there is nothing to separate the brand from. */
.doc:not(:has(.doc-title:not([hidden]))) { border-left-color: transparent; }

.topbar-actions { display: flex; align-items: center; gap: var(--s2); flex: none; }

.status {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  height: 24px;
  padding: 0 var(--s2) 0 10px;
  font-size: var(--fs-11);
  color: var(--text-muted);
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  white-space: nowrap;
}
.status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  flex: none;
}
.status.busy { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-line); }
.status.busy::before { background: var(--accent); }
.status.ok { color: var(--ok); background: var(--ok-soft); border-color: var(--ok-line); }
.status.ok::before { background: var(--ok); }
.status.err { color: var(--err); background: var(--err-soft); border-color: var(--err-line); }
.status.err::before { background: var(--err); }

.body { display: flex; flex: 1; min-height: 0; }

/* --------------------------------------------------------------------------
   Sidebar */

.sidebar {
  width: 320px;
  flex: none;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
/* With no session, no model and no tree the column has nothing to say; the
   stage takes the whole width instead of framing an empty strip. */
.sidebar:not(:has(> section:not([hidden]))) { display: none; }

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel:not([hidden]) ~ .panel:not([hidden]) { border-top: 1px solid var(--line); }
.panel.grow { flex: 1; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s2);
  padding: var(--s3) var(--s4) var(--s2);
  flex: none;
}
.panel-title {
  font-size: var(--fs-12);
  font-weight: var(--fw-strong);
  color: var(--text-muted);
  flex: none;
  white-space: nowrap;
}
.panel-head .muted {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.muted { color: var(--text-muted); font-size: var(--fs-11); }

.panel-foot { padding: var(--s2) var(--s4) var(--s4); flex: none; }

/* File list */
.files {
  list-style: none;
  margin: 0;
  padding: 0 var(--s2);
  overflow: auto;
  flex: 1;
  min-height: 0;
}
.files li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px var(--s2);
  padding: 7px var(--s2);
  border-radius: var(--r-s);
  cursor: default;
}
.files li[data-path] { cursor: pointer; }
.files li:hover { background: var(--surface-2); }
.files li.active {
  background: var(--accent-soft);
  box-shadow: inset 2px 0 0 var(--accent);
}
.file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  direction: rtl;
  text-align: left;
  font-size: var(--fs-12);
}
.file-meta {
  display: flex;
  align-items: center;
  gap: var(--s1);
  color: var(--text-muted);
  font-size: var(--fs-11);
  white-space: nowrap;
}
.file-sub { grid-column: 1 / -1; font-size: var(--fs-11); color: var(--text-muted); }
.file-sub.err { color: var(--err); }
.file-sub.ok { color: var(--ok); }
.file-sub.muted { color: var(--text-faint); }

.file-bar {
  grid-column: 1 / -1;
  height: 3px;
  margin-top: 2px;
  border-radius: var(--r-pill);
  background: var(--line);
  overflow: hidden;
}
.file-bar > span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 120ms linear;
}

.files .convert-one { height: 22px; padding: 0 var(--s2); font-size: var(--fs-11); }

/* Model panel */
.meta {
  margin: 0;
  padding: var(--s1) var(--s4) var(--s4);
  display: grid;
  gap: var(--s2);
  font-size: var(--fs-12);
}
.meta > div { display: flex; justify-content: space-between; gap: var(--s3); }
.meta dt { color: var(--text-muted); margin: 0; }
.meta dd { margin: 0; font-variant-numeric: tabular-nums; }

.fidelity {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: 0 var(--s4) var(--s3);
  font-size: var(--fs-11);
  min-width: 0;
}

.badge {
  flex: none;
  padding: 1px 8px;
  border: 1px solid;
  border-radius: var(--r-pill);
  font-size: var(--fs-11);
  font-weight: var(--fw-medium);
  white-space: nowrap;
}
.badge.ok { color: var(--ok); background: var(--ok-soft); border-color: var(--ok-line); }
.badge.warn { color: var(--warn); background: var(--warn-soft); border-color: var(--warn-line); }

.fidelity-note {
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.warnings {
  margin: 0 var(--s4) var(--s4);
  font-size: var(--fs-11);
  color: var(--text-muted);
}
.warnings summary {
  cursor: pointer;
  padding: var(--s1) 0;
  color: var(--warn);
  font-weight: var(--fw-medium);
}
.warnings ul {
  margin: var(--s1) 0 0;
  padding-left: var(--s4);
  display: grid;
  gap: var(--s1);
  line-height: var(--lh-body);
  /* A bounded scroll viewport, not a clipping box: the bottom edge fades while
     more notices remain, so a half-visible line reads as "scroll for more"
     instead of as text cut off mid-line. */
  max-height: 220px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
.warnings ul.more-below {
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 26px), transparent);
  mask-image: linear-gradient(to bottom, #000 calc(100% - 26px), transparent);
}
.warnings ul.more-above {
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 26px);
  mask-image: linear-gradient(to bottom, transparent, #000 26px);
}
.warnings ul.more-above.more-below {
  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent,
    #000 26px,
    #000 calc(100% - 26px),
    transparent
  );
  mask-image: linear-gradient(
    to bottom,
    transparent,
    #000 26px,
    #000 calc(100% - 26px),
    transparent
  );
}
/* Decoder notices carry long SCREAMING_CASE entity names; without an explicit
   break rule a grid item refuses to shrink and the text runs past the panel. */
.warnings li { min-width: 0; overflow-wrap: anywhere; }

/* Assembly tree */
.tree-search {
  display: flex;
  align-items: center;
  gap: var(--s2);
  margin: 0 var(--s4) var(--s2);
  padding: 0 var(--s2);
  height: 28px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-s);
  background: var(--surface);
  color: var(--text-faint);
}
.tree-search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tree-search svg { width: 14px; height: 14px; flex: none; }
.tree-search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font: inherit;
  font-size: var(--fs-12);
  color: var(--text);
}
.tree-search input::placeholder { color: var(--text-faint); }

.tree { overflow: auto; padding: 0 var(--s2) var(--s4); flex: 1; min-height: 0; }

.tree-row {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: 3px var(--s2);
  border-radius: var(--r-s);
  cursor: pointer;
  font-size: var(--fs-12);
}
.tree-row:hover { background: var(--surface-2); }
.tree-row.selected { background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent); }
.tree-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-row .count { color: var(--text-faint); font-size: var(--fs-11); font-variant-numeric: tabular-nums; }
.tree-row input { accent-color: var(--accent); margin: 0; }
.tree-caret {
  width: 16px;
  height: 16px;
  flex: none;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: var(--r-s);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}
.tree-caret:hover { background: var(--surface-3); color: var(--text); }
.tree-caret svg { width: 12px; height: 12px; transition: transform 120ms ease; }
.tree-caret[data-collapsed="true"] svg { transform: rotate(-90deg); }
.tree-caret.leaf { visibility: hidden; }

/* --------------------------------------------------------------------------
   Stage */

.stage { position: relative; flex: 1; min-width: 0; background: var(--stage); }

.viewer { position: absolute; inset: 0; }
.viewer canvas { display: block; }

/* Empty state: the drop target is the page, not a widget in a corner. */
.hero {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--s5);
}
.hero:has(#dropzone[hidden]) { display: none; }

.dropzone {
  width: min(1120px, 94%);
  min-height: min(600px, 86%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s5);
  padding: var(--s6) var(--s5);
  text-align: center;
  border: 2px dashed var(--line-strong);
  border-radius: var(--r-l);
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  box-shadow: var(--shadow-1);
  transition: border-color 120ms ease, background 120ms ease;
}
.dropzone.dragging {
  border-color: var(--accent);
  background: linear-gradient(180deg, var(--accent-soft), var(--surface));
}
.dropzone.dragging .drop-icon svg { border-color: var(--accent); color: var(--accent); }

.drop-icon {
  display: grid;
  place-items: center;
  width: 84px;
  height: 84px;
  border-radius: var(--r-l);
  color: var(--text-muted);
  background: var(--surface-3);
  border: 1px solid var(--line);
}
.drop-icon svg { width: 52px; height: 52px; display: block; }
.drop-icon-arrow { fill: none; stroke: currentColor; }
.drop-icon-tray { fill: none; stroke: var(--accent); }

.drop-title {
  margin: 0;
  font-size: var(--fs-20);
  font-weight: var(--fw-strong);
  line-height: var(--lh-tight);
  letter-spacing: 0.01em;
}
.drop-sub {
  margin: 0;
  max-width: 52ch;
  font-size: var(--fs-13);
  line-height: var(--lh-body);
  color: var(--text-muted);
}

.formats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--s1) var(--s2);
  max-width: 620px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.formats li {
  padding: 2px 10px;
  font-size: var(--fs-11);
  color: var(--text-muted);
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  white-space: nowrap;
}

.drop-actions { display: flex; gap: var(--s2); justify-content: center; flex-wrap: wrap; }
.drop-foot { margin: 0; font-size: var(--fs-11); color: var(--text-faint); }

.empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  padding: var(--s5);
  text-align: center;
  pointer-events: none;
}
.empty-title { margin: 0; font-size: var(--fs-15); font-weight: var(--fw-strong); }
.empty p { margin: 0; }

/* Shown in the stage while a queued or converting job is still running. */
.converting {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  text-align: center;
  pointer-events: none;
}
.converting-ring {
  width: 28px;
  height: 28px;
  margin-bottom: var(--s1);
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 900ms linear infinite;
}
.converting-title { margin: 0; font-size: var(--fs-15); font-weight: var(--fw-strong); }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .converting-ring { animation-duration: 2400ms; }
}

/* --------------------------------------------------------------------------
   Viewport toolbar */

.toolbar {
  position: absolute;
  top: var(--s3);
  left: var(--s3);
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: var(--s2);
  max-width: calc(100% - 2 * var(--s3));
  padding: var(--s1) var(--s2);
  background: var(--overlay);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  box-shadow: var(--shadow-2);
  backdrop-filter: blur(10px);
}

.tb-group { display: flex; align-items: center; gap: var(--s1); height: 26px; }
.tb-label {
  font-size: var(--fs-11);
  color: var(--text-faint);
  margin-right: var(--s1);
  white-space: nowrap;
}
.tb-sep { width: 1px; height: 18px; margin: 0 var(--s1); background: var(--line); align-self: center; }

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 26px;
  padding: 0 10px;
  font: inherit;
  font-size: var(--fs-12);
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-s);
  cursor: pointer;
  white-space: nowrap;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}
.chip:hover:not(:disabled) { background: var(--surface-3); border-color: var(--line-strong); }
.chip.on { color: var(--accent-fg); background: var(--accent); border-color: var(--accent); }
.chip.on:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.chip:disabled {
  color: var(--text-faint);
  background: var(--surface-2);
  border-color: var(--line-soft);
  cursor: default;
}

.seg { display: flex; gap: 2px; }
.seg .chip { width: 26px; padding: 0; }

.tb-sub { position: relative; }
.tb-summary {
  display: flex;
  align-items: center;
  gap: var(--s1);
  height: 26px;
  padding: 0 10px;
  font-size: var(--fs-12);
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-s);
  cursor: pointer;
  white-space: nowrap;
  list-style: none;
  user-select: none;
}
.tb-summary::-webkit-details-marker { display: none; }
.tb-summary:hover { background: var(--surface-3); border-color: var(--line-strong); }
.tb-sub[open] > .tb-summary { background: var(--surface-3); border-color: var(--line-strong); }
.tb-chev { width: 14px; height: 14px; color: var(--text-muted); transition: transform 120ms ease; }
.tb-sub[open] .tb-chev { transform: rotate(180deg); }

.tb-panel {
  position: absolute;
  top: calc(100% + var(--s2));
  left: 0;
  z-index: 4;
  display: grid;
  gap: var(--s2);
  width: 306px;
  padding: var(--s3);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  box-shadow: var(--shadow-2);
}
.tb-row { display: flex; align-items: center; gap: var(--s2); font-size: var(--fs-11); color: var(--text-muted); min-height: 24px; }
.tb-row .tb-label { margin: 0; width: 26px; }
/* Same width as a label, for a row whose slider has no label of its own. */
.tb-gutter { width: 26px; flex: none; }
.tb-hint-row { min-height: 0; }
.tb-hint-row .tb-note { line-height: var(--lh-body); }
.tb-read {
  /* A fixed slot: the percentage never pushes or pulls the neighbours when the
     value goes from 5% to 100%. */
  width: 34px;
  flex: none;
  font-size: var(--fs-11);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.tb-note { font-size: var(--fs-11); color: var(--text-faint); }
/* Whether the section guide or the section controls are on screen is decided in
   applySection(), not here: one `hidden` flag, one place to read it. */
.tb-panel:has(#explode:not(:disabled)) .explode-hint-row { display: none; }
.tb-panel:has(#explode:disabled) #explode,
.tb-panel:has(#explode:disabled) #explode-read { display: none; }
.tb-group:not(:has(#measure.on)) #measure-clear { display: none; }

.tb-panel .chip { height: 24px; padding: 0 var(--s2); font-size: var(--fs-11); }
.tb-panel .seg .chip { width: 24px; padding: 0; }

/* Range inputs: a 2px track and a bordered thumb, instead of the OS widget. */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  min-width: 64px;
  height: 20px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 2px;
  border-radius: var(--r-pill);
  background: var(--line-strong);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -6px;
  border-radius: 50%;
  background: var(--surface);
  border: 1.5px solid var(--line-strong);
  box-shadow: var(--shadow-1);
}
input[type="range"]:hover:not(:disabled)::-webkit-slider-thumb { border-color: var(--accent); }
input[type="range"]:focus-visible::-webkit-slider-thumb { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type="range"]:disabled { cursor: default; }
input[type="range"]:disabled::-webkit-slider-runnable-track { background: var(--line); }
input[type="range"]:disabled::-webkit-slider-thumb { border-color: var(--line); background: var(--surface-2); box-shadow: none; }

.hint {
  position: absolute;
  left: 50%;
  bottom: var(--s4);
  transform: translateX(-50%);
  max-width: 80%;
  padding: var(--s2) var(--s3);
  border-radius: var(--r-m);
  background: var(--surface);
  border: 1px solid var(--err-line);
  box-shadow: var(--shadow-2);
  font-size: var(--fs-12);
  color: var(--err);
}

/* --------------------------------------------------------------------------
   Narrow windows */

@media (max-width: 980px) {
  .sidebar { width: 276px; }
  .doc { padding-left: var(--s3); }
}

@media (max-width: 820px) {
  .sidebar { width: 240px; }
  .topbar { gap: var(--s3); padding: 0 var(--s3); }
  .doc { padding-left: var(--s3); }
  .hero { padding: var(--s4); }
  .dropzone { width: 100%; min-height: 100%; padding: var(--s5) var(--s4); gap: var(--s4); }
  .drop-icon svg { width: 52px; height: 52px; }
  .drop-title { font-size: var(--fs-15); }
  .tb-panel { width: min(306px, calc(100vw - 2 * var(--s3) - var(--s2))); }
  .tb-row { flex-wrap: wrap; }
  input[type="range"] { min-width: 80px; }
}
