#content:has(> #ladder-ide) {
  max-width: none;
  padding: 0;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.ide {
  --ide-canvas-bg: #fbfbfc;
  --ide-grid: #c7cbd1;
  --ide-wire: #4b5563;
  --ide-power: #16a34a;
  --ide-power-fill: rgba(22, 163, 74, .18);
  --ide-text: var(--text);
  --ide-muted: var(--muted);
  --ide-accent: #0d9488;
  --ide-error: #dc2626;
  --ide-hover: rgba(13, 148, 136, .08);
  --ide-rung-bg: rgba(13, 148, 136, .06);
  --scene-floor: #eef0f3;
  --scene-grid: #dde1e7;
  --scene-frame: #64748b;
  --scene-belt: #334155;
  --scene-roller: #64748b;
  --scene-transfer: #475569;
  --scene-beam: #ef4444;
  --scene-led: #f59e0b;
  --scene-box: #c8955a;
  --scene-box-edge: #8a5a2b;
  --scene-tape: #e3c08f;
  --scene-grass: #dfe8d6;
  --scene-road: #4b5563;
  --scene-curb: #9ca3af;
  --scene-lane: #f3f4f6;
  --scene-centre: #facc15;
  --scene-signal: #1f2937;
  --scene-loop: #94a3b8;
  --scene-locked: rgba(100, 116, 139, .22);

  display: grid;
  grid-template-columns: 200px minmax(0, 1fr) 250px;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "toolbar toolbar toolbar"
    "tags    canvas  props"
    "status  status  status";
  height: calc(100dvh - var(--bar-h));
  background: var(--bg);
}
@media (prefers-color-scheme: dark) {
  .ide {
    --ide-canvas-bg: #0d1014;
    --ide-grid: #2b323c;
    --ide-wire: #9ca3af;
    --ide-power: #22c55e;
    --ide-power-fill: rgba(34, 197, 94, .2);
    --ide-error: #f87171;
    --ide-accent: #2dd4bf;
    --ide-hover: rgba(45, 212, 191, .1);
    --ide-rung-bg: rgba(45, 212, 191, .06);
    --scene-floor: #151a21;
    --scene-grid: #222a34;
    --scene-frame: #64748b;
    --scene-belt: #0b0f14;
    --scene-roller: #3b4655;
    --scene-transfer: #1e293b;
    --scene-beam: #f87171;
    --scene-grass: #17201a;
    --scene-road: #2b3038;
    --scene-curb: #4b5563;
    --scene-lane: #d1d5db;
    --scene-centre: #ca8a04;
    --scene-signal: #0b0f14;
    --scene-loop: #64748b;
    --scene-locked: rgba(0, 0, 0, .45);
  }
}

.ide.show-scene {
  grid-template-rows: auto minmax(120px, 1fr) var(--scene-size, 45%) auto;
  grid-template-areas:
    "toolbar toolbar toolbar"
    "tags    canvas  props"
    "scene   scene   scene"
    "status  status  status";
}

.ide-toolbar {
  grid-area: toolbar;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem 1rem;
  padding: .5rem .75rem;
  background: linear-gradient(180deg, color-mix(in srgb, var(--surface) 92%, var(--accent)), var(--surface));
  border-bottom: 1px solid var(--border);
}
.tool-group { display: flex; flex-wrap: wrap; gap: .25rem; }
.tool-group + .tool-group { padding-left: 1rem; border-left: 1px solid var(--border); }
.tool-group-end { margin-left: auto; border-left: 0 !important; }

.tool {
  display: grid;
  justify-items: center;
  gap: 2px;
  min-width: 52px;
  padding: .3rem .4rem;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.tool:hover:not(:disabled) { background: var(--bg); border-color: var(--border); }
.tool[aria-pressed="true"] {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  border-color: var(--accent);
}
.tool[hidden] { display: none; }
.tool .glyph { font-family: ui-monospace, "Cascadia Mono", Menlo, monospace; font-size: 1rem; line-height: 1.1; white-space: pre; }
.tool .mn { font-size: .815rem; color: var(--muted); }
.tool-icon .glyph svg {
  display: block; width: 24px; height: 18px;
  fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

.btn {
  padding: .4rem .7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.825rem;
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn-danger { color: var(--ide-error); }
.btn-danger:hover:not(:disabled) { border-color: var(--ide-error); }
.tool:disabled, .btn:disabled, .ide input:disabled, .ide select:disabled { opacity: .45; cursor: not-allowed; }

.run-btn { min-width: 6rem; font-weight: 600; }
.run-btn[aria-pressed="true"] {
  background: var(--ide-power);
  border-color: var(--ide-power);
  color: #fff;
}

.tool-palette { flex-direction: column; gap: .2rem; width: min(640px, 100%); }
.tool-tabs { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--border); }
.tool-tab {
  margin-bottom: -1px;
  padding: .2rem .6rem;
  border: 1px solid transparent;
  border-radius: 6px 6px 0 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: .85rem;
  cursor: pointer;
}
.tool-tab:hover { color: var(--text); }
.tool-tab[aria-selected="true"] {
  border-color: var(--border);
  border-bottom-color: var(--surface);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
}
.tool-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tool-row { display: flex; flex-wrap: wrap; gap: .25rem; min-height: 46px; }
.tool[draggable="true"]:not(:disabled) { cursor: grab; }

.ide-menu {
  position: fixed;
  z-index: 50;
  display: grid;
  min-width: 190px;
  padding: .25rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
  font-size: .875rem;
}
.ide-menu[hidden] { display: none; }
.ide-menu button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: .4rem .6rem;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.ide-menu button:hover:not(:disabled), .ide-menu button:focus-visible { background: var(--ide-hover); outline: none; }
.ide-menu button:disabled { opacity: .45; cursor: default; }
.ide-menu button.danger:not(:disabled) { color: var(--ide-error); }
.ide-menu kbd { color: var(--muted); font-family: ui-monospace, "Cascadia Mono", Menlo, monospace; font-size: .75rem; }
.ide-menu hr { margin: .25rem 0; border: 0; border-top: 1px solid var(--border); }

.ide-drag-ghost {
  position: fixed;
  top: -100px;
  left: 0;
  padding: .25rem .5rem;
  border: 1px solid var(--ide-accent);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: 600 12px ui-monospace, Menlo, monospace;
  white-space: pre;
  pointer-events: none;
}

.ide-panel {
  overflow-y: auto;
  padding: .75rem;
  background: linear-gradient(180deg, var(--surface), color-mix(in srgb, var(--surface) 94%, var(--accent)));
  font-size: .875rem;
}
.ide-tags { grid-area: tags; border-right: 1px solid var(--border); }
.ide-props { grid-area: props; border-left: 1px solid var(--border); }
.ide-panel h3 {
  margin: 0 0 .5rem;
  font-size: .75rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}
.ide-panel h4 { margin: 1.25rem 0 .5rem; font-size: .875rem; }
.panel-note, .ide-panel .muted { margin: 0 0 .5rem; color: var(--muted); font-size: .8rem; }

.tag-list { list-style: none; margin: 0 0 .75rem; padding: 0; }
.tag-list li { display: flex; align-items: center; gap: .25rem; }
.tag-toggle {
  flex: 1;
  display: flex;
  align-items: center;
  gap: .5rem;
  min-width: 0;
  padding: .35rem .5rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-family: ui-monospace, "Cascadia Mono", Menlo, monospace;
  text-align: left;
  cursor: pointer;
}
.tag-toggle:hover { background: var(--bg); }
.tag-toggle .tag-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.led {
  flex: none;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--border);
}
.tag-list li.on .led { background: var(--ide-power); box-shadow: 0 0 6px var(--ide-power); }
.tag-del {
  padding: .2rem .45rem;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.tag-del:hover:not(:disabled) { color: var(--ide-error); background: var(--bg); }

.tag-struct { flex-wrap: wrap; row-gap: 0; cursor: default; }
.tag-struct:hover { background: transparent; }
.tag-struct .tag-name { flex: 1; }
.tag-type { flex: none; font-size: .6rem; font-weight: 700; color: var(--muted); }
.tag-num-input {
  flex: 1 0 100%;
  width: 0;
  padding: .15rem .35rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: .8rem;
  text-align: right;
}
.field input.bad { border-color: var(--ide-error); }
.tag-val { flex: 1 0 100%; padding-left: calc(10px + .5rem); font-size: .75rem; color: var(--muted); }

.tag-form { display: flex; flex-wrap: wrap; gap: .25rem; }
.tag-form input { flex: 1 1 100%; }
.tag-form select { flex: 1; }
.tag-form input, .tag-form select, .field input, .field select {
  width: 100%;
  min-width: 0;
  padding: .4rem .5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.tag-form input, .field input { font-family: ui-monospace, "Cascadia Mono", Menlo, monospace; }

.field { display: grid; gap: .25rem; margin-bottom: .75rem; }
.field > span { font-size: .75rem; color: var(--muted); }
.props-loc { margin: 0 0 .75rem; font-family: ui-monospace, "Cascadia Mono", Menlo, monospace; font-size: .8rem; color: var(--muted); }
.btn-row { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .5rem; }

.shortcuts { display: grid; grid-template-columns: auto 1fr; gap: .3rem .75rem; margin: 0; }
.shortcuts dt { font-family: ui-monospace, "Cascadia Mono", Menlo, monospace; }
.shortcuts dt kbd {
  padding: 0 .35rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  font-size: .75rem;
}
.shortcuts dd { margin: 0; color: var(--muted); }

.ide-main {
  grid-area: canvas;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.ide-views {
  flex: none;
  display: flex;
  gap: 2px;
  padding: .3rem .75rem 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.ide-view-tab {
  margin-bottom: -1px;
  padding: .3rem .9rem;
  border: 1px solid transparent;
  border-radius: 6px 6px 0 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: .85rem;
  cursor: pointer;
}
.ide-view-tab:hover { color: var(--text); }
.ide-view-tab[aria-selected="true"] {
  border-color: var(--border);
  border-bottom-color: var(--ide-canvas-bg);
  background: var(--ide-canvas-bg);
  color: var(--text);
  font-weight: 600;
}
.ide-view-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.view-count {
  margin-left: .2rem;
  padding: 0 .35rem;
  border-radius: 999px;
  background: var(--border);
  color: var(--text);
  font-size: .7rem;
  font-weight: 600;
}
.view-count:empty { display: none; }

.ide-canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: auto;
  scrollbar-gutter: stable;
  background: var(--ide-canvas-bg);
}
.ide-canvas-wrap[hidden] { display: none; }

.ide-inline {
  position: absolute;
  z-index: 5;
  height: 22px;
  padding: 0 .3rem;
  border: 2px solid var(--ide-accent);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  font: 12px ui-monospace, "Cascadia Mono", Menlo, monospace;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .18);
}
.ide-inline:focus { outline: none; }
.ide-inline[hidden] { display: none; }

.ide-tag-editor {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: .75rem 1rem 1.5rem;
  background: var(--ide-canvas-bg);
  font-size: .875rem;
}
.ide-tag-editor[hidden] { display: none; }
.te-form { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; margin-bottom: .75rem; }
.te-form input, .te-form select, .te-table input, .te-table select {
  min-width: 0;
  padding: .3rem .45rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.te-form input { width: 14rem; font-family: ui-monospace, "Cascadia Mono", Menlo, monospace; }
.te-note { flex-basis: 100%; margin: .2rem 0 0; color: var(--muted); font-size: .78rem; }
.te-table { width: 100%; max-width: 900px; border-collapse: collapse; }
.te-table th {
  padding: .35rem .5rem;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .05em;
  text-align: left;
  text-transform: uppercase;
}
.te-table td { padding: .25rem .5rem; border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent); }
.te-table tbody tr:hover { background: var(--ide-hover); }
.te-table input { width: 100%; font-family: ui-monospace, "Cascadia Mono", Menlo, monospace; }
.te-table .te-name { min-width: 9rem; }
.te-table .te-name:not(:focus):not(:disabled) { border-color: transparent; background: transparent; }
.te-table .te-name:hover:not(:disabled) { border-color: var(--border); }
.te-table .te-uses { color: var(--muted); font-variant-numeric: tabular-nums; text-align: center; }
.te-table .te-value { min-width: 8rem; }
.te-acc { color: var(--muted); font-family: ui-monospace, "Cascadia Mono", Menlo, monospace; font-size: .8rem; }
.te-bool {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .2rem .55rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-family: ui-monospace, "Cascadia Mono", Menlo, monospace;
  cursor: pointer;
}
.te-table tr.on .led { background: var(--ide-power); box-shadow: 0 0 6px var(--ide-power); }
#ide-canvas { display: block; }
#ide-canvas:focus { outline: none; }
#ide-canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.ide-scene {
  grid-area: scene;
  display: none;
  flex-direction: column;
  min-height: 0;
}
.ide.show-scene .ide-scene { display: flex; }
.scene-resizer {
  flex: none;
  height: 7px;
  margin-top: -2px;
  background: var(--border);
  cursor: row-resize;
  touch-action: none;
}
.scene-resizer:hover, .scene-resizer:focus-visible { background: var(--accent); outline: none; }
.scene-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .35rem 1rem;
  padding: .3rem .75rem;
  background: linear-gradient(180deg, color-mix(in srgb, var(--surface) 92%, var(--accent)), var(--surface));
  border-bottom: 1px solid var(--border);
}
.scene-toolbar .tool { min-width: 46px; padding: .2rem .35rem; }
.scene-title { font-size: .9rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.scene-kind {
  padding: .25rem .4rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: .9rem;
}
.scene-toolbar .tool[hidden] { display: none; }
.field-note.warn { color: var(--ide-error); }
.scene-status { margin-left: auto; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.scene-canvas-wrap { flex: 1; min-height: 0; overflow: auto; background: var(--scene-floor); }
#scene-canvas { display: block; touch-action: none; }
#scene-canvas:focus { outline: none; }
#scene-canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
#ide-sim-toggle[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.field-note { color: var(--muted); font-size: .75rem; }

.ide-status {
  grid-area: status;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .3rem .75rem;
  border-top: 1px solid var(--border);
  background: linear-gradient(0deg, color-mix(in srgb, var(--surface) 92%, var(--accent)), var(--surface));
  font-size: .8rem;
  color: var(--muted);
}
.ide-status .mode {
  padding: .05rem .5rem;
  border-radius: 4px;
  background: var(--border);
  color: var(--text);
  font-weight: 600;
  letter-spacing: .05em;
}
.ide.is-running .ide-status .mode { background: var(--ide-power); color: #fff; }
.ide-status .hint { margin-left: auto; color: var(--text); }

.ide:not(.is-pro) [data-pro] { position: relative; }
.ide:not(.is-pro) [data-pro]::after {
  content: "PRO";
  position: absolute;
  top: -6px; right: -6px;
  padding: 0 4px;
  border-radius: 4px;
  background: var(--grad-accent);
  color: var(--on-accent);
  font-size: 9px;
  font-weight: 700;
  line-height: 14px;
  letter-spacing: .04em;
}
.upgrade-btn { padding: .15rem .6rem; border-color: var(--accent); color: var(--accent); font-weight: 600; }
.upgrade-btn[hidden] { display: none; }
.cloud-ref { color: var(--text); }

.ide-dialog {
  width: min(520px, calc(100vw - 2rem));
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: linear-gradient(180deg, var(--bg), color-mix(in srgb, var(--bg) 95%, var(--accent)));
  color: var(--text);
}
.ide-dialog::backdrop { background: rgba(0, 0, 0, .4); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .75rem; }
.dialog-head h3 { margin: 0; font-size: 1rem; }
.cloud-list { list-style: none; margin: 0 0 1rem; padding: 0; max-height: 50vh; overflow-y: auto; }
.cloud-list li {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .45rem 0;
  border-bottom: 1px solid var(--border);
  font-size: .875rem;
}
.cloud-list li.muted { color: var(--muted); border: 0; }
.cloud-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.switch-text { margin: 0 0 .5rem; font-size: .9rem; }
.switch-note { margin: 0 0 1rem; color: var(--muted); font-size: .85rem; }
.btn-primary { border-color: transparent; background: var(--grad-accent); color: var(--on-accent); font-weight: 600; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.cloud-date { color: var(--muted); font-size: .75rem; }
.cloud-badge {
  padding: .05rem .4rem; border-radius: 999px; font-size: .7rem; font-weight: 600;
  background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent);
}
.save-form { display: flex; flex-direction: column; gap: .75rem; }
.save-field { display: flex; flex-direction: column; gap: .25rem; font-size: .875rem; font-weight: 500; }
.save-field input, .save-field textarea {
  font: inherit; font-weight: 400; padding: .4rem .5rem; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--text);
}
.save-field small { color: var(--muted); font-weight: 400; }
.save-field[hidden] { display: none; }
.save-vis { margin: 0; padding: .5rem .75rem; border: 1px solid var(--border); border-radius: 8px; font-size: .85rem; }
.save-vis legend { padding: 0 .25rem; font-weight: 500; }
.save-vis label { display: flex; gap: .5rem; align-items: flex-start; padding: .25rem 0; }
.save-vis input { margin-top: .2rem; }
.save-note { margin: 0; color: var(--muted); font-size: .8rem; }
.save-error { margin: 0; color: var(--error, #c0392b); font-size: .85rem; }
.save-error:empty, .save-note:empty { display: none; }

@media (max-width: 900px) {
  .ide, .ide.show-scene {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 60vh auto auto auto;
    grid-template-areas: "toolbar" "canvas" "props" "tags" "status";
    height: auto;
  }
  .scene-resizer { display: none; }
  .ide.show-scene {
    grid-template-rows: auto 50vh 50vh auto auto auto;
    grid-template-areas: "toolbar" "canvas" "scene" "props" "tags" "status";
  }
  .ide-tags, .ide-props { border: 0; border-top: 1px solid var(--border); }
  .tool-group + .tool-group { padding-left: 0; border-left: 0; }
}
