/* Schematic viewer. Two shapes: an empty state that is mostly a drop target, and a
   stage-plus-sidebar once a build is open.

   Every selector is prefixed with #tool-root, and the mode buttons are called .sc-tab
   rather than .sc-mode. Both are about specificity, not style. css/tool-theme.css loads
   AFTER each widget and re-skins whatever it finds with id-scoped rules, so that the 75
   ported WordPress widgets do not need editing one by one. A plain class rule in here
   loses to it: `#tool-root button:not(.btn):not([class*="tab"])` painted the selected mode
   button the same colour as the unselected ones, in both themes, and `#tool-root *` reset
   its border. The id prefix wins the cascade back, and "tab" in the class name is that
   file's own documented opt-out — accurate here, since the markup already says role="tab". */

#tool-root .sc { display: grid; gap: 12px; }

/* Every panel this widget toggles carries a display rule below, and a display rule beats
   the [hidden] attribute's own display:none. Without this the empty state stayed on screen
   under a loaded build, both mode panels showed at once, and the "Building the mesh…"
   overlay never went away. */
#tool-root .sc [hidden] { display: none !important; }

/* ---------- empty state ---------- */
#tool-root .sc-drop {
  display: grid;
  place-items: center;
  min-height: 340px;
  padding: 32px 20px;
  border: 1px dashed var(--line-strong);
  text-align: center;
}
#tool-root .sc-drop-inner { display: grid; gap: 10px; justify-items: center; max-width: 46ch; }
#tool-root .sc-drop-lead { font-size: 1.25rem; font-weight: 650; color: var(--fg); }
#tool-root .sc-drop-sub { color: var(--fg-muted); font-size: 0.86rem; line-height: 1.65; }
#tool-root .sc-drop-sub code {
  font-family: var(--font-mono);
  font-size: 0.82em;
  padding: 1px 5px;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--grass);
  white-space: nowrap;
}
#tool-root .sc-drop-note { color: var(--fg-dim); font-size: 0.78rem; }

/* The drop target is the whole widget, so the cue has to be too. */
#tool-root .sc.is-dragging .sc-drop,
#tool-root .sc.is-dragging .sc-stage { border-color: var(--grass); box-shadow: var(--glow); }

/* ---------- loaded ---------- */
#tool-root .sc-app { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr) 300px; align-items: start; }
@media (max-width: 900px) { #tool-root .sc-app { grid-template-columns: minmax(0, 1fr); } }

#tool-root .sc-stage {
  position: relative;
  height: min(68vh, 620px);
  min-height: 380px;
  padding: 0;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% 0%, var(--surface-3), transparent 70%),
    var(--surface);
}
@media (max-width: 900px) { #tool-root .sc-stage { height: 56vh; } }
#tool-root .sc-stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }

#tool-root .sc-overlay { position: absolute; z-index: 2; }
#tool-root .sc-overlay-tl { top: 10px; left: 10px; display: flex; gap: 6px; flex-wrap: wrap; max-width: calc(100% - 130px); }
#tool-root .sc-overlay-tr { top: 10px; right: 10px; }

#tool-root .sc-chip {
  padding: 3px 9px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  border: 1px solid var(--line);
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--fg);
  max-width: 34ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#tool-root .sc-chip-dim { color: var(--fg-muted); font-family: var(--font-mono); font-weight: 500; }

#tool-root .sc-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  color: var(--fg-muted);
  font-size: 0.88rem;
  z-index: 3;
}

/* ---------- sidebar ---------- */
#tool-root .sc-side { display: grid; gap: 12px; }
#tool-root .sc-panel { display: grid; gap: 10px; }
#tool-root .sc-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

#tool-root .sc-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
#tool-root .sc-tab {
  padding: 7px 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--fg-muted);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}
#tool-root .sc-tab:hover { color: var(--fg); border-color: var(--line-strong); }
/* No rule for the selected tab on purpose. tool-theme.css already styles
   `[class*="tab"][aria-selected="true"]` and loads later, so anything written here would be
   dead code that reads as if it were in effect. Letting the shared rule own it is also the
   better outcome — the selected mode now looks like a selected tab everywhere else on the
   site. Measured 5.06:1 in the light theme and higher in the dark one, so it clears AA. The
   markup keeps aria-selected in sync with .is-on; that attribute is what the styling hangs
   off, not just the accessibility tree. */

#tool-root .sc-mode-body { display: grid; gap: 10px; }
#tool-root .sc-field { display: grid; gap: 5px; }
#tool-root .sc-field select,
#tool-root .sc-field input[type="range"] { width: 100%; }
#tool-root .sc-field b { color: var(--fg); font-variant-numeric: tabular-nums; }

#tool-root .sc-transport { display: flex; gap: 4px; }
#tool-root .sc-transport .btn { flex: 1; padding-inline: 4px; }
#tool-root .sc-transport .btn-primary { flex: 1.6; }

#tool-root .sc-hint { color: var(--fg-dim); font-size: 0.75rem; line-height: 1.55; }

#tool-root .sc-total { color: var(--fg-muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; }

#tool-root .sc-materials {
  display: grid;
  gap: 1px;
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: 300px;
  overflow-y: auto;
  font-size: 0.82rem;
}
#tool-root .sc-materials li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 6px;
  border-radius: var(--radius);
}
#tool-root .sc-materials li:nth-child(odd) { background: var(--surface-2); }
#tool-root .sc-mat-name { color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#tool-root .sc-mat-count { color: var(--grass); font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
/* --grass is tuned against a near-black page. On the light theme it lands at 3.39:1 over
   --surface-2, under the 4.5 needed for text this size; --grass-deep is the same hue and
   clears it comfortably. Measured, not eyeballed — the counts are the one thing on this
   panel a reader actually reads off. */
:root[data-theme="light"] #tool-root .sc-mat-count { color: var(--grass-deep); }

#tool-root .sc-unresolved {
  color: var(--fg-muted);
  font-size: 0.75rem;
  line-height: 1.6;
  padding: 7px 9px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface-2);
}

#tool-root .sc-error { color: var(--redstone); font-size: 0.88rem; line-height: 1.6; }
