/* State classes are .is-* / .has-*, set from JS. Breakpoints: 1180 / 940 / 700 / 420. */

/* ---------- suite header ---------- */
.suitebar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: var(--suitebar-h);
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 8px clamp(14px, 2.5vw, 34px);
  border-bottom: 1px solid var(--line);
  background: var(--bg-veil);
}
.suite-wordmark {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  color: var(--ink);
  text-decoration: none;
  flex: none;
}
.suite-wordmark span {
  font-family: var(--font-mono);
  font-size: var(--fs-2xl);
  line-height: 1;
  font-weight: 600;
  letter-spacing: -.05em;
}
.suite-wordmark small {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  letter-spacing: .16em;
}
.suite-nav { display: flex; align-items: center; gap: 2px; min-width: 0; }
.suite-nav a {
  display: grid;
  place-items: center;
  min-height: var(--control-h-sm);
  padding: 0 12px;
  border-radius: var(--radius-md);
  color: var(--muted);
  font-size: var(--fs-md);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.suite-nav a:hover { color: var(--ink); }
/* Quiet on purpose: the accent fill is reserved for selections inside a tool. */
.suite-nav a[aria-current="page"] {
  color: var(--ink);
  background: var(--panel-2);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}

/* ---------- page layout ---------- */
.shell {
  width: min(1700px, 100%);
  margin: 0 auto;
  padding: 12px clamp(10px, 1.5vw, 24px) calc(30px + env(safe-area-inset-bottom));
}
/* Rail + panes. A page sets --wb-cols (and the narrower variants) to taste. */
.workbench {
  display: grid;
  grid-template-columns: var(--wb-cols, 244px minmax(400px, 1.62fr) minmax(292px, .78fr));
  gap: var(--gap-workbench);
  align-items: start;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.toolrail {
  position: sticky;
  top: calc(var(--suitebar-h) + 12px);
  max-height: calc(100vh - var(--suitebar-h) - 24px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
.rail-section { padding: var(--pad-y) var(--pad-x); border-bottom: 1px solid var(--line); }
.rail-section:last-child { border-bottom: 0; }
.section-heading { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: 8px; }
.section-heading > span, .pane-index { color: var(--accent); font-family: var(--font-mono); font-size: var(--fs-2xs); }
.section-heading h2 { font-size: var(--fs-md); font-weight: 600; letter-spacing: .01em; }

/* ---------- panes ---------- */
.pane { min-width: 0; overflow: hidden; }
.pane-head {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 10px 6px 13px;
  border-bottom: 1px solid var(--line);
}
.pane-title { display: flex; align-items: center; gap: 9px; min-width: 0; }
.pane-title strong { font-size: var(--fs-lg); }
.pane-head > .tabs { flex: 1; }
.pane-head > .tabs + .mono-label { margin-left: 8px; }
/* A raised strip of controls inside a pane. */
.pane-body { padding: 12px; border-top: 1px solid var(--line); background: var(--panel-2); }
.pane-foot {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: var(--fs-sm);
}

/* ---------- control groups ---------- */
.control-group { padding: var(--sp-3) 0 1px; border-top: 1px solid var(--line); }
.control-group h3 {
  margin-bottom: 6px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  font-weight: 600;
  letter-spacing: var(--ls-caps);
  text-transform: uppercase;
}
.control-group > .note { margin: 3px 0 8px; }
.control-group h3 + .note { margin: -2px 0 6px; line-height: 1.35; }  /* one-line help under a group title */
.rail-section > .note { margin-top: var(--sp-2); }
.control-grid { display: grid; grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)); gap: 10px 12px; }
.control-grid > .control { margin-bottom: 0; }
.control-grid > .toggle-row { padding-bottom: 0; padding-top: 8px; }
.span-all { grid-column: 1 / -1; }

/* ---------- slider row ---------- */
.control { min-width: 0; margin-bottom: var(--control-gap); }
.control-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 1px; }
.control-head label, .control-label { font-size: var(--fs-sm); font-weight: 600; }
.value { color: var(--accent); font-family: var(--font-mono); font-size: var(--fs-2xs); }

input[type="range"] {
  appearance: none;
  width: 100%;
  height: var(--range-h);
  margin: 0;
  background: transparent;
  cursor: pointer;
}
/* WebKit has no "filled" track part; --range-fill is kept current by shared/ui.js. */
input[type="range"]::-webkit-slider-runnable-track {
  height: var(--range-track);
  border-radius: 2px;
  background: linear-gradient(to right, var(--accent) 0 var(--range-fill, 0%), var(--track) var(--range-fill, 0%) 100%);
}
input[type="range"]::-moz-range-track { height: var(--range-track); border-radius: 2px; background: var(--track); }
input[type="range"]::-moz-range-progress { height: var(--range-track); border-radius: 2px; background: var(--accent); }
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: var(--range-thumb);
  height: var(--range-thumb);
  margin-top: calc((var(--range-track) - var(--range-thumb)) / 2);
  border: 2px solid var(--panel);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
input[type="range"]::-moz-range-thumb {
  width: calc(var(--range-thumb) - 2px);
  height: calc(var(--range-thumb) - 2px);
  border: 2px solid var(--panel);
  border-radius: 50%;
  background: var(--accent);
}
input[type="range"]:focus-visible { outline: none; }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 1px var(--accent), 0 0 0 4px var(--accent-ring); }
input[type="range"]:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 4px var(--accent-ring); }
input[type="range"]:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- switch row ---------- */
.toggle-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: var(--sp-3) 0;
  border-top: 1px solid var(--line);
  cursor: pointer;
}
.toggle-row.is-stacked { display: block; cursor: auto; }
.toggle-copy strong { display: block; font-size: var(--fs-sm); }
.toggle-copy small { display: block; margin-top: 1px; color: var(--dim); font-size: var(--fs-2xs); line-height: 1.35; }
.toggle-row:has(:disabled) { opacity: .45; cursor: not-allowed; }
.switch { position: relative; width: var(--switch-w); height: var(--switch-h); }
.switch input {
  appearance: none;
  position: absolute;
  inset: 0;
  width: var(--switch-w);
  height: var(--switch-h);
  margin: 0;
  border: 0;
  border-radius: calc(var(--switch-h) / 2);
  background: var(--track);
  cursor: inherit;
}
.switch span { position: absolute; inset: 0; border-radius: calc(var(--switch-h) / 2); pointer-events: none; }
.switch span::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 4px;
  width: var(--switch-knob);
  height: var(--switch-knob);
  border-radius: 50%;
  background: var(--ink);
  transition: .18s ease;
}
.switch input:checked { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(calc(var(--switch-w) - var(--switch-knob) - 8px)); background: var(--accent-ink); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Plain checkbox with a label, for dense rows. */
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: var(--fs-sm); white-space: nowrap; cursor: pointer; }
.check input { accent-color: var(--accent); margin: 0; }

/* ---------- segmented control and tabs (radio inputs) ----------
   <div class="seg" role="radiogroup"><label><input type="radio"><span>…</span></label>…</div>
   .seg is boxed (a setting); .tabs is bare (chooses what a pane shows). */
.seg, .tabs { display: flex; gap: 4px; min-width: 0; }
.seg {
  margin-top: var(--sp-2);
  padding: 3px;
  background: var(--well);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
:is(.seg, .tabs) > label { position: relative; flex: 1 1 0; min-width: 0; }
:is(.seg, .tabs) input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
:is(.seg, .tabs) span {
  display: grid;
  place-items: center;
  min-height: var(--control-h-sm);
  padding: 0 7px;
  border-radius: var(--radius-md);
  color: var(--muted);
  font-size: var(--fs-2xs);
  font-weight: 600;
  white-space: nowrap;
}
.tabs span { min-height: var(--tab-h); font-size: var(--fs-md); }
:is(.seg, .tabs) input:checked + span { color: var(--accent-ink); background: var(--accent); }
:is(.seg, .tabs) input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
:is(.seg, .tabs) input:disabled { cursor: not-allowed; }
:is(.seg, .tabs) input:disabled + span { opacity: .4; }

/* ---------- selects and fields ---------- */
select, input[type="number"] {
  min-height: var(--control-h-sm);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--ink);
  background: var(--panel-2);
  font-size: var(--fs-xs);
  font-weight: 600;
}
select { padding: 0 26px 0 9px; cursor: pointer; }
input[type="number"] { min-width: 0; width: 100%; padding: 0 9px; }
select:disabled { cursor: not-allowed; }
/* label left, select right */
.select-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: var(--sp-3) 0;
  border-top: 1px solid var(--line);
}
.select-row label { font-size: var(--fs-sm); font-weight: 600; }
/* label above, control below */
.field { display: grid; gap: 4px; min-width: 0; font-size: var(--fs-sm); font-weight: 600; }
.field > span { color: var(--muted); }
.field select { width: 100%; }
.field:has(:disabled) { opacity: .45; }
.field-grid { display: grid; grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)); gap: 8px; }

/* ---------- buttons ---------- */
.btn {
  min-width: 0;
  min-height: var(--control-h);
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: var(--fs-sm);
  font-weight: 600;
  cursor: pointer;
}
.btn:disabled { cursor: not-allowed; }
.btn:not(:disabled):active { transform: translateY(1px); }
.btn-primary { color: var(--accent-ink); background: var(--accent); }
.btn-primary:disabled { color: var(--dim); background: var(--panel-3); }
.btn-secondary { color: var(--ink); border-color: var(--line-bright); background: var(--control); }
.btn-secondary:disabled { color: var(--dim); border-color: var(--line); background: var(--panel-2); }
.btn-ghost { color: var(--accent); border-color: var(--accent); background: transparent; }
.btn-ghost:disabled { color: var(--dim); border-color: var(--track); }
.btn-ghost:not(:disabled):active { background: var(--accent-soft); transform: none; }
.btn-sm { min-height: var(--control-h-sm); padding: 0 9px; font-size: var(--fs-xs); }
.btn-xs { min-height: var(--control-h-xs); padding: 0 8px; border-radius: var(--radius-sm); font-size: var(--fs-2xs); }
.btn-block { width: 100%; }
.btn-block + .btn-block, .control + .btn-block { margin-top: var(--sp-2); }
.btn-grid { display: grid; grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)); gap: var(--sp-2); }

/* ---------- dropzone ---------- */
.drop-stack { display: grid; gap: 6px; }
.drop {
  position: relative;
  min-height: var(--drop-h);
  display: grid;
  grid-template-columns: var(--drop-art) minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: var(--sp-3);
  border: 1px dashed var(--line-bright);
  border-radius: 8px;
  background: var(--well);
  cursor: pointer;
  transition: border-color .16s ease, background .16s ease;
  overflow: hidden;
}
.drop:hover, .drop:focus-within, .drop.is-drag { border-color: var(--accent); background: var(--panel-2); }
.drop.has-file { border-style: solid; }
.drop input[type="file"] {
  position: absolute;
  right: 6px;
  bottom: 5px;
  width: 76px;
  height: var(--control-h-xs);
  color: transparent;
  cursor: pointer;
  z-index: 2;
}
.drop input[type="file"]::file-selector-button {
  width: 76px;
  height: var(--control-h-xs);
  border: 1px solid var(--line-bright);
  border-radius: var(--radius-sm);
  color: var(--ink);
  background: var(--control);
  font-size: var(--fs-2xs);
  font-weight: 600;
  cursor: pointer;
}
.drop-art {
  width: var(--drop-art);
  height: var(--drop-art);
  display: grid;
  place-items: center;
  flex: none;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--accent);
  background:
    linear-gradient(45deg, var(--panel-3) 25%, transparent 25%, transparent 75%, var(--panel-3) 75%),
    linear-gradient(45deg, var(--panel-3) 25%, var(--panel-2) 25%, var(--panel-2) 75%, var(--panel-3) 75%);
  background-position: 0 0, 6px 6px;
  background-size: 12px 12px;
}
.drop-art img { display: none; width: 100%; height: 100%; object-fit: cover; }
.has-file .drop-art img { display: block; }
.has-file .drop-art :is(svg, b) { display: none; }
.drop-copy { min-width: 0; }
.drop-copy strong { display: block; font-size: var(--fs-sm); }
.drop-copy small { display: block; margin-top: 1px; padding-bottom: 22px; color: var(--muted); font-size: var(--fs-2xs); line-height: 1.35; }
.drop.has-file .drop-copy small { color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- stage: a viewport on a transparency checkerboard ---------- */
.stage {
  position: relative;
  width: 100%;
  aspect-ratio: var(--stage-ratio, 1 / 1);
  overflow: hidden;
  background-color: var(--well);
  background-image:
    linear-gradient(45deg, var(--checker) 25%, transparent 25%, transparent 75%, var(--checker) 75%),
    linear-gradient(45deg, var(--checker) 25%, transparent 25%, transparent 75%, var(--checker) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 10px 10px;
}
.stage > canvas { display: block; width: 100%; height: 100%; }
.empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 28px;
  text-align: center;
  pointer-events: none;
  background: var(--stage-veil);
}
.empty > div { max-width: 260px; }
.empty svg { margin-bottom: 12px; color: var(--dim); }
.empty strong { display: block; font-size: var(--fs-xl); }
.empty span { display: block; margin-top: 6px; color: var(--muted); font-size: var(--fs-md); line-height: 1.45; }
.stage.is-ready .empty { display: none; }

/* ---------- status ---------- */
.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  text-transform: uppercase;
}
.statusbar > :last-child:not(:first-child) { text-align: right; }
.status-line { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--muted); font-size: var(--fs-sm); }
.status-line > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-dot { flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--dim); }
.status-dot.is-ready { background: var(--ok); }
progress.progress {
  appearance: none;
  display: block;
  width: 100%;
  height: 3px;
  border: 0;
  border-radius: 2px;
  overflow: hidden;
  background: var(--panel-3);
}
progress.progress::-webkit-progress-bar { background: var(--panel-3); }
progress.progress::-webkit-progress-value { background: var(--accent); transition: width .2s ease; }
progress.progress::-moz-progress-bar { background: var(--accent); }

/* The ad's own stylesheet (/ad/ad.css) turns this back on, so a blocked
   stylesheet hides the slot instead of leaving an unstyled image. */
.ad-wrap { display: none; }

/* ---------- breakpoints ---------- */
@media (max-width: 1180px) {
  .workbench { grid-template-columns: var(--wb-cols-lg, 232px minmax(350px, 1.35fr) minmax(270px, .76fr)); }
}
@media (max-width: 940px) {
  .workbench { grid-template-columns: var(--wb-cols-md, minmax(0, 1fr) minmax(270px, .72fr)); }
  .toolrail {
    position: static;
    max-height: none;
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .rail-section { border-bottom: 0; border-right: 1px solid var(--line); }
  .rail-section:last-child { border-right: 0; }
}
@media (max-width: 700px) {
  .suitebar { position: relative; gap: 12px; padding: 8px 10px; }
  .suite-wordmark small { display: none; }
  .suite-nav { flex: 1; justify-content: flex-end; }
  .shell { padding-top: 8px; }
  .workbench { grid-template-columns: 1fr; gap: 8px; }
  .toolrail { grid-column: auto; grid-template-columns: 1fr; }
  .rail-section { border-right: 0; border-bottom: 1px solid var(--line); }
  .rail-section:last-child { border-bottom: 0; }
}
@media (max-width: 420px) {
  .suite-wordmark span { font-size: 17px; }
  .suite-nav a { padding: 0 8px; font-size: var(--fs-sm); }
  .pane-head { min-height: 46px; }
}
