/* =========================================================================
   Link-in-Bio Kit — Theme Editor chrome

   Application chrome, not page chrome. It consumes the kit's tokens so the
   tool and the thing it edits cannot drift apart, and defines no `lb-`
   class of its own so it can never reach into the preview.

   The preview lives in an iframe, which is not a purity exercise: the kit's
   own layout rules are `@media (min-width: …)`, and a media query inside a
   scaled `<div>` still measures the outer viewport. Without a real nested
   browsing context a "mobile" preview would confidently render the desktop
   layout, which is the one bug a WYSIWYG editor may not have.
   ========================================================================= */

.ed-app {
  --ed-bar-h: 56px;
  --ed-rail-w: 264px;
  --ed-panel-w: 328px;
  --ed-row-h: 30px;
  --ed-gap: 10px;
  --ed-island-r: var(--lb-r-md);

  position: fixed;
  inset: 0;
  display: grid;
  gap: var(--ed-gap);
  padding: var(--ed-gap);
  grid-template-columns: var(--ed-rail-w) minmax(0, 1fr) var(--ed-panel-w);
  grid-template-rows: var(--ed-bar-h) minmax(0, 1fr) auto;
  grid-template-areas:
    "bar    bar     bar"
    "rail   stage   panel"
    "status status  status";
  background: var(--lb-background);
  color: var(--lb-on-surface);
  font: var(--lb-type-body-xs);
  font-family: var(--lb-font-sans);
  font-feature-settings: "ss01", "cv11";
  -webkit-font-smoothing: antialiased;
}
.ed-app * { box-sizing: border-box; }

/* `[hidden]` is a UA rule at specificity 0-0-1. Every panel class here sets
   `display`, which outranks it — so `hidden = true` did nothing and the code
   panel painted in all five modes, on top of the canvas. This one line is
   the fix, and it has to be important because the losing rule is the UA's. */
.ed-app [hidden] { display: none !important; }

/* Chrome floats: each region is its own surface with a gap around it, so the
   tool reads as panels over a ground rather than as sealed edge-to-edge
   frames. Nothing touches the window edge. */
.ed-rail,
.ed-panel,
.ed-stage,
.ed-status {
  border: 1px solid var(--lb-outline);
  border-radius: var(--ed-island-r);
  background: var(--lb-surface);
}

/* Collapsing a rail removes its column outright rather than zeroing the
   width: a 0px column still gets a gap on both sides, which reads as a
   misaligned margin nobody can explain. */
.ed-app[data-rail="closed"] {
  grid-template-columns: minmax(0, 1fr) var(--ed-panel-w);
  grid-template-areas: "bar bar" "stage panel" "status status";
}
.ed-app[data-panel="closed"] {
  grid-template-columns: var(--ed-rail-w) minmax(0, 1fr);
  grid-template-areas: "bar bar" "rail stage" "status status";
}
.ed-app[data-rail="closed"][data-panel="closed"] {
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "bar" "stage" "status";
}
.ed-app[data-rail="closed"] .ed-rail,
.ed-app[data-panel="closed"] .ed-panel { display: none; }

/* Preview mode gives the whole window to the page. */
.ed-app[data-mode="preview"] {
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "bar" "stage" "status";
}
.ed-app[data-mode="preview"] .ed-rail,
.ed-app[data-mode="preview"] .ed-panel { display: none; }

@media (max-width: 1240px) {
  .ed-app { --ed-rail-w: 224px; --ed-panel-w: 300px; }
}



/* ---------- Shared atoms ------------------------------------------------- */

.ed-app :where(button, input, select, textarea) {
  font: inherit;
  color: inherit;
  font-family: inherit;
}
.ed-app :where(button, [tabindex], input, select, textarea, a):focus { outline: none; }
.ed-app :where(button, [tabindex], input, select, textarea, a):focus-visible {
  outline: 2px solid var(--lb-focus);
  outline-offset: 1px;
  border-radius: 4px;
}

.ed-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--ed-row-h);
  padding-inline: 10px;
  border: 1px solid var(--lb-outline);
  border-radius: var(--lb-r-xs);
  background: var(--lb-surface);
  font: var(--lb-type-label-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color var(--lb-dur-instant) var(--lb-ease), border-color var(--lb-dur-instant) var(--lb-ease);
}
.ed-btn:hover:not([disabled]) { background: var(--lb-surface-3); }
.ed-btn[disabled] { opacity: 0.4; cursor: default; }
.ed-btn--primary { background: var(--lb-primary); color: var(--lb-on-primary); border-color: transparent; }
.ed-btn--primary:hover:not([disabled]) { background: var(--lb-primary-hover); }
.ed-btn--quiet { border-color: transparent; background: transparent; }
.ed-btn--quiet:hover:not([disabled]) { background: var(--lb-scrim); }
.ed-btn--icon { width: var(--ed-row-h); padding: 0; }
.ed-btn--danger:hover:not([disabled]) { background: var(--lb-error-surface); color: var(--lb-error); }
.ed-btn .lb-icon, .ed-btn svg { width: 16px; height: 16px; flex: 0 0 auto; }

.ed-icon { width: 16px; height: 16px; flex: 0 0 auto; display: block; }
.ed-icon path, .ed-icon circle, .ed-icon rect, .ed-icon line, .ed-icon polyline {
  fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
}
.ed-icon--fill path { fill: currentColor; stroke: none; }

.ed-seg {
  display: inline-flex;
  max-width: 100%;
  min-width: 0;
  padding: 2px;
  gap: 2px;
  border: 1px solid var(--lb-outline);
  border-radius: var(--lb-r-xs);
  background: var(--lb-surface-2);
}
.ed-seg button {
  flex: 1 1 0;
  min-width: 0;
  height: calc(var(--ed-row-h) - 6px);
  padding-inline: 8px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  font: var(--lb-type-label-sm);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ed-seg button:hover { background: var(--lb-scrim); }
.ed-seg button[aria-pressed="true"] { background: var(--lb-surface); color: var(--lb-on-surface); box-shadow: var(--lb-elev-raised); }
.ed-seg--sm button { height: 22px; padding-inline: 6px; font: var(--lb-type-mono-xs); }

.ed-input,
.ed-app select.ed-input {
  width: 100%;
  height: var(--ed-row-h);
  padding-inline: 8px;
  border: 1px solid var(--lb-outline);
  border-radius: var(--lb-r-xs);
  background: var(--lb-surface);
  font: var(--lb-type-body-xs);
}
.ed-input:focus { border-color: var(--lb-outline-strong); }
textarea.ed-input { height: auto; min-height: 72px; padding-block: 6px; resize: vertical; line-height: 1.5; }
/* A number input has to fit its value *and* the spinner the browser draws
   inside it. 62px fit neither, so "0.012" rendered as "0.01" with the
   spinner sitting on the last digit. */
.ed-input--num {
  width: 78px;
  text-align: end;
  padding-inline: 6px 2px;
  font: var(--lb-type-mono-sm);
}

.ed-input::placeholder { color: var(--lb-on-surface-3); opacity: 1; font-style: normal; }
/* A slider sitting at its minimum because nothing is set looks identical to
   one deliberately dragged there. Dimming it says which. */
.ed-range[data-unset="true"] { opacity: 0.55; }

.ed-codestub {
  flex: 1 1 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-width: 0;
}
.ed-codestub .ed-mono { color: var(--lb-on-surface-3); }

.ed-muted { color: var(--lb-on-surface-3); }
.ed-mono { font: var(--lb-type-mono-xs); }

/* ---------- Top bar ------------------------------------------------------ */

.ed-bar {
  grid-area: bar;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: var(--ed-gap);
  min-width: 0;
}

/* Each island is a surface in its own right. The centre one is sized to its
   content and the outer two share what is left, so the mode switcher stays
   centred in the window rather than centred in whatever the other two did
   not use. */
.ed-island {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 100%;
  min-width: 0;
  padding-inline: 8px;
  border: 1px solid var(--lb-outline);
  border-radius: var(--ed-island-r);
  background: var(--lb-surface);
}
.ed-bar-side {
  display: flex;
  align-items: center;
  gap: var(--ed-gap);
  min-width: 0;
  height: 100%;
}
.ed-bar-side--start { justify-self: start; }
.ed-bar-side--end { justify-self: end; }

.ed-island--identity { min-width: 0; overflow: hidden; }
.ed-island--modes { justify-self: center; flex: 0 0 auto; padding-inline: 6px; }

/* The mode switcher stacks an icon over a label, so it cannot borrow the
   segmented control's 24px row. It gets its own height and its own baseline.

   It may never wrap: it is the only way back out of a mode, and a Preview
   button on a second line is both broken layout and a trap. It shrinks
   instead — labels go, then the buttons narrow to their icons. */
.ed-modes {
  display: inline-flex;
  flex-wrap: nowrap;
  gap: 2px;
  padding: 3px;
  border-radius: var(--lb-r-sm);
  background: var(--lb-surface-2);
}
.ed-modes button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 62px;
  height: 38px;
  padding: 4px 10px;
  border: 0;
  border-radius: var(--lb-r-xs);
  background: transparent;
  color: var(--lb-on-surface-2);
  cursor: pointer;
  line-height: 1;
  white-space: nowrap;
}
.ed-modes button span { font: var(--lb-type-label-sm); line-height: 1; }
.ed-modes button .ed-icon { width: 15px; height: 15px; }
.ed-modes button:hover { background: var(--lb-scrim); color: var(--lb-on-surface); }
.ed-modes button[aria-pressed="true"] {
  background: var(--lb-surface);
  color: var(--lb-on-surface);
  box-shadow: var(--lb-elev-raised);
}

/* Progressive disclosure, outside-in. Each step removes a whole island, so
   nothing is ever half a control. */
@media (max-width: 1440px) { .ed-brand-name { display: none; } }
@media (max-width: 1320px) { .ed-btn-label { display: none; } }
@media (max-width: 1240px) { .ed-island--view { display: none; } }
@media (max-width: 1100px) { .ed-island--device { display: none; } }
@media (max-width: 1000px) { .ed-island--history { display: none; } }

.ed-bar-group { display: flex; align-items: center; gap: 6px; min-width: 0; }
.ed-bar-group--grow { flex: 1 1 auto; justify-content: center; }
.ed-bar-sep { width: 1px; height: 18px; background: var(--lb-outline); flex: 0 0 auto; }

.ed-brand {
  display: flex; align-items: center; gap: 8px;
  text-decoration: none; color: inherit;
  padding-right: 4px;
}
.ed-brand-mark {
  display: grid; place-items: center;
  width: 26px; height: 26px;
  border-radius: var(--lb-r-full);
  background: var(--lb-primary); color: var(--lb-on-primary);
  font: var(--lb-type-mono-xs);
}
.ed-brand-name { font: var(--lb-type-label); white-space: nowrap; }

.ed-title {
  min-width: 0; max-width: 220px;
  height: 26px; padding-inline: 6px;
  border: 1px solid transparent; border-radius: var(--lb-r-xs);
  background: transparent;
  font: var(--lb-type-label);
  text-overflow: ellipsis;
}
.ed-title:hover { border-color: var(--lb-outline); }
.ed-title:focus { border-color: var(--lb-outline-strong); background: var(--lb-surface-2); }

.ed-dirty {
  width: 6px; height: 6px; border-radius: var(--lb-r-full);
  background: var(--lb-warning); flex: 0 0 auto;
}
.ed-dirty[hidden] { display: none; }

/* ---------- Rails -------------------------------------------------------- */

.ed-rail {
  grid-area: rail;
  display: flex; flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.ed-panel {
  grid-area: panel;
  display: flex; flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.ed-tabs {
  display: flex;
  gap: 2px;
  padding: 6px;
  border-bottom: 1px solid var(--lb-outline);
  flex: 0 0 auto;
}
.ed-tabs button {
  flex: 1 1 0; min-width: 0;
  height: 26px;
  border: 0; border-radius: var(--lb-r-xs);
  background: transparent;
  font: var(--lb-type-label-sm);
  cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ed-tabs button:hover { background: var(--lb-scrim); }
.ed-tabs button[aria-selected="true"] { background: var(--lb-surface-3); }
.ed-tabpanel { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; }
.ed-tabpanel[hidden] { display: none; }

/* ---------- Layer tree --------------------------------------------------- */

.ed-layers { padding: 6px; display: flex; flex-direction: column; gap: 1px; }
.ed-layer {
  display: grid;
  grid-template-columns: 18px 18px minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding-inline: 6px;
  border-radius: var(--lb-r-xs);
  background: transparent;
  border: 1px solid transparent;
  cursor: grab;
  text-align: start;
  width: 100%;
  font: var(--lb-type-body-xs);
}
.ed-layer:hover { background: var(--lb-scrim); }
.ed-layer[aria-current="true"] { background: var(--lb-surface-3); border-color: var(--lb-outline-strong); }
.ed-layer[data-hidden="true"] .ed-layer-name { opacity: 0.45; text-decoration: line-through; }
.ed-layer[data-dragging="true"] { opacity: 0.4; }
.ed-layer-grip { color: var(--lb-on-surface-3); display: grid; place-items: center; }
.ed-layer-kind { color: var(--lb-on-surface-3); display: grid; place-items: center; }
.ed-layer-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-layer-meta { display: flex; align-items: center; gap: 3px; color: var(--lb-on-surface-3); }
.ed-layer-dot { width: 5px; height: 5px; border-radius: var(--lb-r-full); background: var(--lb-info); }
.ed-layer-dot--rule { background: var(--lb-warning); }
.ed-layer-act {
  width: 20px; height: 20px; display: grid; place-items: center;
  border: 0; border-radius: 4px; background: transparent; cursor: pointer; color: inherit;
  opacity: 0;
}
.ed-layer:hover .ed-layer-act, .ed-layer-act:focus-visible, .ed-layer-act[data-on="true"] { opacity: 1; }
.ed-layer-act:hover { background: var(--lb-scrim-strong); }

.ed-droplane {
  height: 2px; margin: 0 6px;
  border-radius: 2px;
  background: var(--lb-primary);
  opacity: 0;
}
.ed-droplane[data-on="true"] { opacity: 1; }

/* ---------- Library ------------------------------------------------------ */

.ed-search { padding: 8px; border-bottom: 1px solid var(--lb-outline); position: sticky; top: 0; background: var(--lb-surface); z-index: 2; }
.ed-lib-cat { padding: 10px 10px 4px; font: var(--lb-type-mono-xs); text-transform: uppercase; letter-spacing: var(--lb-track-caps); color: var(--lb-on-surface-3); }
.ed-lib-items { display: flex; flex-direction: column; gap: 1px; padding-inline: 6px; }
.ed-lib-item {
  display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; gap: 8px; align-items: center;
  min-height: 30px; padding-inline: 6px;
  border: 1px solid transparent; border-radius: var(--lb-r-xs);
  background: transparent; cursor: pointer; text-align: start; width: 100%;
  font: var(--lb-type-body-xs);
}
.ed-lib-item:hover { background: var(--lb-scrim); }
.ed-lib-item .ed-lib-add { opacity: 0; color: var(--lb-on-surface-3); }
.ed-lib-item:hover .ed-lib-add, .ed-lib-item:focus-visible .ed-lib-add { opacity: 1; }
.ed-lib-empty { padding: 24px 12px; text-align: center; color: var(--lb-on-surface-3); }

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

.ed-stage {
  grid-area: stage;
  position: relative;
  min-width: 0; min-height: 0;
  overflow: auto;
  display: grid;
  /* Centre the frame in both axes, but safely: once it is taller than the
     stage, centring would push its top edge above the scroll origin and
     make the first block unreachable. `safe` falls back to start. */
  place-items: safe center;
  align-content: safe center;
  padding: var(--lb-s-5) var(--lb-s-4);
  overscroll-behavior: contain;
  /* A ground the kit itself never draws, so the boundary between the tool
     and the page being edited is never in question. */
  background:
    radial-gradient(circle at 1px 1px, var(--lb-outline) 1px, transparent 0) 0 0 / 16px 16px,
    var(--lb-background);
}
.ed-app[data-mode="preview"] .ed-stage { background: var(--lb-surface); padding: 0; }

.ed-viewport {
  /* Zoom scales the frame; this wrapper carries the *scaled* footprint so
     the stage scrolls to the real painted size rather than the layout size. */
  transform-origin: top center;
  transition: width var(--lb-dur-fast) var(--lb-ease);
  will-change: transform;
}
.ed-frame {
  position: relative;
  display: block;
  width: 100%;
  border: 1px solid var(--lb-outline);
  border-radius: var(--lb-r-md);
  background: var(--lb-surface);
  box-shadow: var(--lb-elev-float);
  overflow: hidden;
}
.ed-app[data-mode="preview"] .ed-frame { border: 0; border-radius: 0; box-shadow: none; }
.ed-frame iframe { display: block; width: 100%; height: 100%; border: 0; background: transparent; }
.ed-frame[data-loading="true"] iframe { opacity: 0; }

.ed-framebar,
.ed-framehint {
  display: block;
  width: 100%;
  font: var(--lb-type-mono-xs);
  color: var(--lb-on-surface-3);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ed-framebar { margin-bottom: 8px; }
.ed-framehint { margin-top: 8px; }
.ed-app[data-mode="preview"] .ed-framebar,
.ed-app[data-mode="preview"] .ed-framehint { display: none; }

/* ---------- Inspector ---------------------------------------------------- */

.ed-panel-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--lb-outline);
  min-height: 44px;
}
.ed-panel-title { font: var(--lb-type-label); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-panel-kind { font: var(--lb-type-mono-xs); color: var(--lb-on-surface-3); }

.ed-group { border-bottom: 1px solid var(--lb-outline-soft); }
.ed-group-head {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 38px;
  padding-inline: 10px;
  border: 0; background: transparent;
  cursor: pointer; text-align: start;
  font: var(--lb-type-label-sm);
}
.ed-group-head:hover { background: var(--lb-scrim); }
.ed-group-caret { transition: transform var(--lb-dur-instant) var(--lb-ease); color: var(--lb-on-surface-3); }
.ed-group[data-open="true"] .ed-group-caret { transform: rotate(90deg); }
.ed-group-count {
  min-width: 16px; height: 16px; padding-inline: 4px;
  display: grid; place-items: center;
  border-radius: var(--lb-r-pill);
  background: var(--lb-info); color: var(--lb-on-primary);
  font: var(--lb-type-mono-xs);
}
.ed-group-body { padding: 2px 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.ed-group[data-open="false"] .ed-group-body { display: none; }
.ed-group-note {
  margin: 0 0 4px;
  color: var(--lb-on-surface-3);
  font: var(--lb-type-body-xs);
  line-height: 1.45;
}

.ed-field { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 8px; align-items: center; }
.ed-field--stack { grid-template-columns: minmax(0, 1fr); }
.ed-field--stack > .ed-label { margin-bottom: -2px; }
.ed-label {
  display: flex; align-items: center; gap: 4px;
  font: var(--lb-type-body-xs);
  color: var(--lb-on-surface-2);
  min-width: 0;
}
.ed-label[data-set="true"] { color: var(--lb-on-surface); }
.ed-label[data-set="true"]::after {
  content: ""; width: 5px; height: 5px; border-radius: var(--lb-r-full);
  background: var(--lb-info); flex: 0 0 auto;
}
.ed-control { min-width: 0; display: flex; align-items: center; gap: 6px; }
.ed-control > .ed-seg { flex: 1 1 auto; }
.ed-help {
  grid-column: 1 / -1;
  margin: -2px 0 2px;
  color: var(--lb-on-surface-3);
  font: var(--lb-type-body-xs);
  line-height: 1.45;
}
.ed-advanced-toggle {
  align-self: start;
  margin-top: 2px;
  color: var(--lb-on-surface-3);
  background: transparent; border: 0; padding: 4px 0;
  font: var(--lb-type-label-sm);
  cursor: pointer;
  display: flex; align-items: center; gap: 4px;
}
.ed-advanced-toggle:hover { color: var(--lb-on-surface); }

.ed-range { flex: 1 1 auto; min-width: 0; accent-color: var(--lb-primary); height: 20px; }
.ed-reset {
  width: 20px; height: 20px; flex: 0 0 auto;
  display: grid; place-items: center;
  border: 0; border-radius: 4px; background: transparent;
  color: var(--lb-on-surface-3); cursor: pointer;
}
.ed-reset:hover { background: var(--lb-scrim-strong); color: var(--lb-on-surface); }
.ed-reset[hidden] { display: none; }

.ed-swatch {
  width: 28px; height: var(--ed-row-h); flex: 0 0 auto;
  border: 1px solid var(--lb-outline); border-radius: var(--lb-r-xs);
  cursor: pointer; padding: 0;
  background-image: linear-gradient(45deg, var(--lb-surface-3) 25%, transparent 25%, transparent 75%, var(--lb-surface-3) 75%),
                    linear-gradient(45deg, var(--lb-surface-3) 25%, transparent 25%, transparent 75%, var(--lb-surface-3) 75%);
  background-size: 8px 8px;
  background-position: 0 0, 4px 4px;
}
.ed-swatch span { display: block; width: 100%; height: 100%; border-radius: inherit; }

.ed-colorpop {
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px;
  margin-top: 4px;
  border: 1px solid var(--lb-outline);
  border-radius: var(--lb-r-sm);
  background: var(--lb-surface-2);
}
.ed-colorpop[hidden] { display: none; }
.ed-lch { display: grid; grid-template-columns: 14px minmax(0, 1fr) 46px; gap: 6px; align-items: center; }
.ed-lch label { font: var(--lb-type-mono-xs); color: var(--lb-on-surface-3); }
.ed-hue-track { accent-color: currentColor; }
.ed-contrast {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  padding: 6px 8px; border-radius: var(--lb-r-xs);
  font: var(--lb-type-mono-xs);
  background: var(--lb-surface-3);
}
.ed-contrast[data-pass="false"] { background: var(--lb-error-surface); color: var(--lb-error); }
.ed-contrast[data-pass="true"] { background: var(--lb-success-surface); color: var(--lb-success); }

.ed-box-wrap { flex: 1 1 auto; display: flex; gap: 6px; align-items: start; min-width: 0; }
.ed-box {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  min-width: 0;
}
.ed-box-cell { display: grid; gap: 2px; justify-items: center; min-width: 0; }
.ed-box-cell > span {
  font: var(--lb-type-mono-xs);
  color: var(--lb-on-surface-3);
  line-height: 1;
}
.ed-box input {
  width: 100%;
  min-width: 0;
  height: var(--ed-row-h);
  padding-inline: 4px;
  text-align: center;
  border: 1px solid var(--lb-outline);
  border-radius: var(--lb-r-xs);
  background: var(--lb-surface);
  font: var(--lb-type-mono-sm);
}
.ed-box-wrap .ed-reset { margin-top: 0; height: var(--ed-row-h); width: var(--ed-row-h); }

.ed-switch {
  position: relative; width: 34px; height: 20px; flex: 0 0 auto;
  border: 0; border-radius: var(--lb-r-pill);
  background: var(--lb-outline-strong); cursor: pointer;
  transition: background-color var(--lb-dur-fast) var(--lb-ease);
}
.ed-switch::after {
  content: ""; position: absolute; top: 2px; inset-inline-start: 2px;
  width: 16px; height: 16px; border-radius: var(--lb-r-full);
  background: var(--lb-surface);
  transition: translate var(--lb-dur-fast) var(--lb-ease);
}
.ed-switch[aria-checked="true"] { background: var(--lb-primary); }
.ed-switch[aria-checked="true"]::after { translate: 14px 0; }

.ed-presets { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.ed-preset {
  display: flex; flex-direction: column; gap: 6px;
  padding: 8px;
  border: 1px solid var(--lb-outline); border-radius: var(--lb-r-sm);
  background: var(--lb-surface); cursor: pointer; text-align: start;
  font: var(--lb-type-label-sm);
}
.ed-preset:hover { border-color: var(--lb-outline-strong); }
.ed-preset[aria-pressed="true"] { border-color: var(--lb-primary); box-shadow: inset 0 0 0 1px var(--lb-primary); }
.ed-preset-chips { display: flex; gap: 3px; }
.ed-preset-chip { width: 14px; height: 14px; border-radius: 4px; border: 1px solid var(--lb-outline); }

/* ---------- Rules -------------------------------------------------------- */

.ed-rules { padding: 10px; display: flex; flex-direction: column; gap: 10px; }
.ed-rule {
  display: flex; flex-direction: column; gap: 6px;
  padding: 8px;
  border: 1px solid var(--lb-outline); border-radius: var(--lb-r-sm);
  background: var(--lb-surface-2);
}
.ed-rule-head { display: flex; align-items: center; gap: 6px; }
.ed-rule-head select { flex: 1 1 auto; min-width: 0; }
.ed-rule-row { display: flex; gap: 6px; align-items: center; }
.ed-rule-row > * { min-width: 0; }
.ed-rule-note {
  margin: 0; padding-top: 2px;
  color: var(--lb-on-surface-3);
  font: var(--lb-type-body-xs); line-height: 1.45;
}
.ed-rule-summary {
  padding: 8px 10px;
  border-radius: var(--lb-r-xs);
  background: var(--lb-surface-3);
  font: var(--lb-type-mono-xs);
  line-height: 1.5;
}
.ed-days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
.ed-days button {
  height: 26px; border: 1px solid var(--lb-outline); border-radius: 4px;
  background: var(--lb-surface); font: var(--lb-type-mono-xs); cursor: pointer;
}
.ed-days button[aria-pressed="true"] { background: var(--lb-primary); color: var(--lb-on-primary); border-color: transparent; }

/* ---------- Simulator ---------------------------------------------------- */

.ed-sim { padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.ed-sim-banner {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px; border-radius: var(--lb-r-xs);
  background: var(--lb-warning-surface); color: var(--lb-warning);
  font: var(--lb-type-label-sm);
}
.ed-sim-banner[hidden] { display: none; }

/* ---------- Code workspace ----------------------------------------------- */

/* Code mode reshapes the stage into a workspace: a file list, an editor, and
   the canvas still running beside it. The preview is the point — a stylesheet
   you cannot see take effect is a text file. */
.ed-app[data-mode="code"] .ed-stage {
  display: grid;
  grid-template-columns: minmax(0, var(--ed-split, 58%)) auto minmax(0, 1fr);
  gap: 0;
  padding: var(--ed-gap);
  align-items: stretch;
  align-content: stretch;
  justify-items: stretch;
  overflow: hidden;
}
.ed-app[data-mode="code"] .ed-viewport {
  align-self: start;
  justify-self: center;
  overflow: auto;
  max-height: 100%;
}

/* The divider is a real control: draggable, focusable, and driven by the
   arrow keys, because a mouse-only divider is a mouse-only layout. */
.ed-split {
  width: 11px;
  align-self: stretch;
  border: 0;
  background: transparent;
  cursor: col-resize;
  position: relative;
  touch-action: none;
}
.ed-split::before {
  content: "";
  position: absolute;
  inset-block: 0;
  inset-inline-start: 5px;
  width: 1px;
  background: var(--lb-outline);
}
.ed-split:hover::before,
.ed-split:focus-visible::before,
.ed-split[data-dragging]::before { background: var(--lb-primary); width: 2px; }
.ed-split:focus-visible { outline: none; }

@media (max-width: 1100px) {
  /* Below this the two panes are each too narrow to read. Code takes the
     stage and the preview steps aside rather than both being unusable. */
  .ed-app[data-mode="code"] .ed-stage { grid-template-columns: minmax(0, 1fr); }
  .ed-app[data-mode="code"] .ed-viewport,
  .ed-split { display: none; }
}

.ed-code {
  display: grid;
  grid-template-columns: 172px minmax(0, 1fr);
  min-width: 0;
  gap: var(--ed-gap);
  min-height: 0;
  height: 100%;
}
@media (max-width: 760px) {
  .ed-code { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .ed-files { flex-direction: row; overflow-x: auto; }
}

.ed-files {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--lb-outline);
  border-radius: var(--lb-r-sm);
  background: var(--lb-surface-2);
}
.ed-files button {
  display: flex; align-items: center; gap: 6px;
  height: 28px; padding-inline: 8px;
  border: 0; border-radius: var(--lb-r-xs);
  background: transparent;
  font: var(--lb-type-mono-xs);
  color: var(--lb-on-surface-2);
  cursor: pointer;
  text-align: start;
  white-space: nowrap;
}
.ed-files button:hover { background: var(--lb-scrim); }
.ed-files button[aria-selected="true"] { background: var(--lb-surface); color: var(--lb-on-surface); box-shadow: var(--lb-elev-raised); }
.ed-files .ed-icon { width: 14px; height: 14px; }
.ed-file-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.ed-file-tag { margin-inline-start: auto; color: var(--lb-on-surface-3); font-size: 9px; letter-spacing: 0.04em; }
.ed-file-tag:empty { display: none; }

.ed-code-main { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 8px; min-height: 0; }
.ed-code-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }

/* The highlighted layer and the textarea are stacked and must agree on every
   metric, or the caret drifts from the glyphs under it. Both inherit the same
   font, padding and line height from the container for exactly that reason. */
.ed-code-editor {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  min-height: 0;
  border: 1px solid var(--lb-outline);
  border-radius: var(--lb-r-sm);
  background: var(--lb-surface-2);
  overflow: hidden;
  font: var(--lb-type-mono-xs);
  line-height: 1.6;
  tab-size: 2;
}
.ed-code-editor[data-readonly="true"] { background: var(--lb-surface-3); }
.ed-code-gutter {
  padding: 10px 8px;
  overflow: hidden;
  text-align: end;
  white-space: pre;
  color: var(--lb-on-surface-3);
  border-inline-end: 1px solid var(--lb-outline);
  user-select: none;
}
.ed-code-stack { position: relative; min-width: 0; min-height: 0; }
.ed-code-paint,
.ed-code-input {
  margin: 0;
  padding: 10px 12px;
  border: 0;
  font: inherit;
  line-height: inherit;
  tab-size: inherit;
  white-space: pre;
  overflow: auto;
  overflow-wrap: normal;
}
.ed-code-paint {
  position: absolute;
  inset: 0;
  color: var(--lb-on-surface);
  pointer-events: none;
}
.ed-code-input {
  position: relative;
  width: 100%;
  height: 100%;
  resize: none;
  background: transparent;
  /* Transparent text over the painted layer, with the caret still visible.
     `color: transparent` alone would take the caret with it. */
  color: transparent;
  caret-color: var(--lb-on-surface);
}
.ed-code-input::selection { background: var(--lb-primary); color: transparent; }
.ed-code-input:focus { outline: none; }
.ed-code-editor:focus-within { border-color: var(--lb-outline-strong); }

.ed-tok--key, .ed-tok--prop { color: var(--lb-primary); }
.ed-tok--str { color: var(--lb-success); }
.ed-tok--num { color: var(--lb-info); }
.ed-tok--kw, .ed-tok--at, .ed-tok--tag { color: var(--lb-warning); }
.ed-tok--attr { color: var(--lb-on-surface-2); }
.ed-tok--com { color: var(--lb-on-surface-3); font-style: italic; }
.ed-tok--pun { color: var(--lb-on-surface-3); }

.ed-code-status { font: var(--lb-type-mono-xs); color: var(--lb-on-surface-3); margin: 0; }
.ed-code-status[data-state="error"] { color: var(--lb-error); }
.ed-code-status[data-state="ok"] { color: var(--lb-success); }

/* ---------- Status bar --------------------------------------------------- */

.ed-status {
  grid-area: status;
  display: flex; align-items: center; gap: var(--lb-s-3);
  min-height: 30px;
  padding-inline: 12px;
  font: var(--lb-type-mono-xs);
  color: var(--lb-on-surface-3);
  overflow: hidden;
}
.ed-status-island {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 100%;
  min-width: 0;
  padding-inline: 10px;
  border-radius: var(--lb-r-xs);
}
.ed-status-island--doc,
.ed-status-island--help { background: var(--lb-surface-2); }
.ed-status-help {
  border: 0; background: transparent; cursor: pointer;
  font: inherit; color: inherit; padding: 0;
}
.ed-status-help:hover { color: var(--lb-on-surface); }
.ed-width { width: 148px; }

.ed-status-item { display: flex; align-items: center; gap: 5px; white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.ed-status-spacer { flex: 1 1 auto; }
.ed-status kbd {
  font: var(--lb-type-mono-xs);
  padding: 1px 4px;
  border: 1px solid var(--lb-outline);
  border-radius: 4px;
  background: var(--lb-surface-2);
}

/* ---------- Empty state -------------------------------------------------- */

.ed-empty {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 40px 16px; text-align: center;
  color: var(--lb-on-surface-3);
}
.ed-empty p { margin: 0; line-height: 1.5; }
.ed-empty strong { color: var(--lb-on-surface); font-weight: 500; }

/* ---------- Toast -------------------------------------------------------- */

.ed-toast {
  position: fixed;
  inset-block-end: 44px;
  inset-inline: 0;
  margin-inline: auto;
  width: max-content; max-width: 80vw;
  padding: 8px 14px;
  border-radius: var(--lb-r-pill);
  background: var(--lb-primary); color: var(--lb-on-primary);
  font: var(--lb-type-label-sm);
  box-shadow: var(--lb-elev-popover);
  z-index: var(--lb-z-toast);
  opacity: 0;
  translate: 0 8px;
  pointer-events: none;
  transition: opacity var(--lb-dur-fast) var(--lb-ease), translate var(--lb-dur-fast) var(--lb-ease);
}
.ed-toast[data-on="true"] { opacity: 1; translate: 0 0; }

/* ---------- Dialog ------------------------------------------------------- */

.ed-dialog {
  border: 1px solid var(--lb-outline);
  border-radius: var(--lb-r-md);
  background: var(--lb-surface);
  color: var(--lb-on-surface);
  padding: 0;
  max-width: min(560px, calc(100vw - 32px));
  box-shadow: var(--lb-elev-modal);
  font: var(--lb-type-body-xs);
  font-family: var(--lb-font-sans);
}
.ed-dialog::backdrop { background: var(--lb-overlay); }
.ed-dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--lb-outline); }
.ed-dialog-head h2 { margin: 0; font: var(--lb-type-h4); }
.ed-dialog-body { padding: 16px; display: flex; flex-direction: column; gap: 12px; max-height: 60vh; overflow: auto; }
.ed-dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--lb-outline); }
.ed-shortcuts { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 16px; align-items: center; }
.ed-shortcuts dt { min-width: 0; }
.ed-shortcuts dd { margin: 0; text-align: end; }

.ed-visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip-path: inset(50%);
  overflow: hidden; white-space: nowrap;
}

/* ---------- Small screens ------------------------------------------------ */

/* An editor is a desktop tool. Rather than pretend otherwise on a phone,
   the rails stack under the canvas and the tool says what it is. */
@media (max-width: 900px) {
  /* Stacking the rails under the canvas made a phone scroll through 400px of
     inspector to reach the page it was inspecting. They become drawers over
     the canvas instead: closed by default, one at a time, dismissable — the
     same open/closed state the desktop toggles drive, so there is one
     mechanism rather than two layouts to keep in agreement. */
  .ed-app,
  .ed-app[data-rail="closed"],
  .ed-app[data-panel="closed"],
  .ed-app[data-mode="preview"] {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "bar" "stage" "status";
  }

  .ed-app { --ed-gap: 8px; --ed-bar-h: 52px; }

  .ed-rail,
  .ed-panel {
    position: fixed;
    z-index: 40;
    top: calc(var(--ed-gap) + var(--ed-bar-h) + var(--ed-gap));
    bottom: var(--ed-gap);
    width: min(340px, calc(100vw - 2 * var(--ed-gap)));
    box-shadow: var(--lb-elev-overlay);
    display: flex;
  }
  .ed-rail { left: var(--ed-gap); }
  .ed-panel { right: var(--ed-gap); }
  .ed-app[data-rail="closed"] .ed-rail,
  .ed-app[data-panel="closed"] .ed-panel { display: none; }

  .ed-scrim {
    position: fixed;
    inset: 0;
    z-index: 30;
    background: var(--lb-scrim-strong, rgb(0 0 0 / 0.32));
    border: 0;
    padding: 0;
  }

  /* At phone width the device simulator is the wrong tool: the window *is*
     the device. Those controls are hidden rather than shrunk, because a
     three-way device switch at 40px per option is not a control. */
  /* At phone width the identity island keeps only what identifies the
     document, and the canvas island keeps only the two controls that reach
     the rest of the tool. */
  .ed-bar { grid-template-columns: auto minmax(0, 1fr) auto; }
  .ed-island { padding-inline: 5px; gap: 4px; }
  .ed-island--modes { padding-inline: 4px; }
  .ed-brand, .ed-bar-sep,
  .ed-island--device,
  .ed-island--view,
  .ed-island--history { display: none; }
  /* Labels go before icons do: five icons still read as five modes, whereas
     three labels and two icons reads as a broken row. */
  .ed-modes button { min-width: 0; padding-inline: 9px; }
  .ed-modes button span { display: none; }
  .ed-modes button .ed-icon { width: 18px; height: 18px; }
  .ed-title { max-width: 40vw; }
  .ed-status-item[data-role="rules"] { display: none; }
}

@media (max-width: 620px) {
  .ed-brand-mark { display: none; }
  .ed-status-item[data-role="count"] { display: none; }
}

/* The scrim only exists on small screens; on desktop the rails are columns
   and dimming the canvas to reach them would be absurd. */
@media (min-width: 901px) {
  .ed-scrim { display: none; }
}
}
