/* gblocks v2 — "night-shift machine shop".
   Full-colour interlocking blocks (Scratch-style notch & bump, done in CSS),
   dark theme by default with a light mode, SVG icons, no emojis. */

:root {
  --amber: #fa6d3a;
  --amber-soft: rgba(250, 109, 58, .15);
  --danger: #e05252;
  --console: #0d0f11;
  --console-2: #16191c;
  --console-line: #24282d;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --disp: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  /* dark shell (default): neutral graphite, no blue cast */
  --bg: #101214;
  --panel: #15171a;
  --surface: #1c1f23;
  --surface-2: #262a2f;
  --ink: #e8eaed;
  --muted: #969ea7;
  --line: #2a2e34;
  --grid-dot: rgba(255, 255, 255, .05);
  --shadow: 0 2px 6px rgba(0, 0, 0, .35);
  --block-shadow: 0 2px 5px rgba(0, 0, 0, .4), inset 0 1px 0 rgba(255, 255, 255, .12);
}

[data-theme="light"] {
  --bg: #ebedef;
  --panel: #f5f6f7;
  --surface: #ffffff;
  --surface-2: #eef0f2;
  --ink: #17191c;
  --muted: #5d656e;
  --line: #d5d9dd;
  --grid-dot: rgba(23, 25, 28, .09);
  --shadow: 0 1px 3px rgba(23, 25, 28, .12);
  --block-shadow: 0 2px 5px rgba(23, 25, 28, .22), inset 0 1px 0 rgba(255, 255, 255, .18);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* the fix for ghost modals: author styles must never override `hidden` */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: var(--body);
  font-size: 14.5px;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
.ic { vertical-align: -2px; }

:focus-visible { outline: 2px solid var(--amber); outline-offset: 1px; border-radius: 4px; }

.flex-spacer { flex: 1; }

/* ================= TOP BAR — machine console (dark in both themes) ================= */

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 9px 16px;
  background: var(--console);
  color: #e8eaed;
  border-bottom: 1px solid var(--console-line);
  box-shadow: inset 0 -3px 0 var(--amber);
  flex-wrap: wrap;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 9px; }
.brand-mark { color: var(--amber); display: flex; }
.brand-name {
  font-family: var(--disp);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: 0;
}
.brand-sub {
  font-family: var(--mono);
  font-size: 10.5px;
  color: #7a828a;
  letter-spacing: .02em;
  margin-top: 3px;
}

.tabs { display: flex; gap: 4px; background: var(--console-2); padding: 4px; border-radius: 9px; }
.tab {
  font-family: var(--disp);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: .06em;
  padding: 6px 16px;
  border-radius: 6px;
  color: #8a9199;
}
.tab:hover { color: #e8eaed; }
.tab.active { background: var(--amber); color: #0d0f11; }

.top-actions { display: flex; align-items: center; gap: 5px; margin-left: auto; flex-wrap: wrap; }
.v-rule { width: 1px; height: 20px; background: var(--console-line); margin: 0 4px; }

/* top bar buttons (always on dark) */
.topbar .btn {
  font-family: var(--disp);
  font-weight: 600;
  font-size: 12.5px;
  letter-spacing: .03em;
  padding: 7px 12px;
  border-radius: 7px;
  background: #25292e;
  color: #e8eaed;
  border: 1px solid #34393f;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.topbar .btn:hover { background: #2e3339; }
.topbar .btn:disabled { opacity: .35; cursor: default; }
.topbar .btn-ghost { background: transparent; border-color: transparent; color: #b3bac1; }
.topbar .btn-ghost:hover { background: rgba(127, 142, 160, .15); color: #e8eaed; }
.topbar .btn-ghost.active { background: var(--amber-soft); color: var(--amber); }
.topbar .btn-accent { background: var(--amber); border-color: var(--amber); color: #0d0f11; }
.topbar .btn-accent:hover { background: #fb8355; }

/* generic buttons elsewhere (theme-aware) */
.btn {
  font-family: var(--disp);
  font-weight: 600;
  font-size: 12.5px;
  letter-spacing: .03em;
  padding: 7px 12px;
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .4; cursor: default; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: rgba(127, 142, 160, .14); color: var(--ink); }
.btn-ghost.active { background: var(--amber-soft); color: var(--amber); }
.btn-accent { background: var(--amber); border-color: var(--amber); color: #0d0f11; }
.btn-accent:hover { background: #fb8355; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }

.only-mobile { display: none; }

/* ================= LAYOUT ================= */

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

.panel-title {
  font-family: var(--disp);
  font-weight: 700;
  font-size: 11.5px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 14px 14px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.panel-hint { font-family: var(--body); font-weight: 400; font-size: 11px; text-transform: none; letter-spacing: 0; }

/* ================= TOOLBOX ================= */

.toolbox-panel {
  width: 252px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

/* dragging a block over the toolbox = delete (Scratch-style) */
.toolbox-panel.trash-mode {
  outline: 2px dashed var(--danger);
  outline-offset: -4px;
  background: color-mix(in srgb, var(--danger) 10%, var(--panel));
}
.toolbox-panel.trash-mode .tb-cat, .toolbox-panel.trash-mode .panel-title { opacity: .18; }
.trash-overlay {
  display: none;
  position: fixed;
  left: 0; top: 52px; bottom: 0;
  width: 252px;
  z-index: 45;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  font-family: var(--disp);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: .06em;
  color: var(--danger);
}
.toolbox-panel.trash-mode .trash-overlay { display: flex; }

.tb-search { padding: 0 12px 10px; }
.tb-search input {
  width: 100%;
  font-family: var(--mono);
  font-size: 12px;
  padding: 7px 11px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 7px;
}
.tb-search input::placeholder { color: var(--muted); }
.tb-search input:focus { outline: none; border-color: var(--amber); }

.tb-cat { border-bottom: 1px solid var(--line); }
.tb-cat-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 14px;
  font-family: var(--disp);
  font-weight: 600;
  font-size: 13px;
  border-left: 4px solid var(--cat);
  text-align: left;
}
.tb-cat-head:hover, .tb-cat.open .tb-cat-head { background: var(--surface); }
.tb-cat-icon { color: var(--cat); display: flex; filter: saturate(1.4) brightness(1.35); }
[data-theme="light"] .tb-cat-icon { filter: none; }
.tb-cat-arrow { margin-left: auto; color: var(--muted); font-size: 11px; transition: transform .15s; }
.tb-cat.open .tb-cat-arrow { transform: rotate(90deg); }

.tb-cat-body { padding: 6px 10px 12px 12px; }
.tb-empty { font-size: 12px; color: var(--muted); padding: 8px 6px; line-height: 1.5; }

/* toolbox items are miniature blocks: full colour, tiny bump */
.tb-item {
  position: relative;
  display: flex;
  align-items: center;
  padding: 7px 10px;
  margin: 7px 0;
  background: var(--cat);
  border-radius: 7px;
  cursor: grab;
  box-shadow: var(--block-shadow);
  color: #fff;
  transition: transform .1s, filter .1s;
}
.tb-item::after {
  content: "";
  position: absolute;
  bottom: -4px;
  left: 14px;
  width: 22px;
  height: 5px;
  background: var(--cat);
  border-radius: 0 0 4px 4px;
  filter: brightness(.85);
}
.tb-item:hover { transform: translateX(3px); filter: brightness(1.08); }
.tb-item:active { cursor: grabbing; }
.tb-item.tb-group { background: repeating-linear-gradient(-45deg, var(--cat), var(--cat) 12px, color-mix(in srgb, var(--cat) 88%, black) 12px, color-mix(in srgb, var(--cat) 88%, black) 24px); }
.tb-item-label {
  font-size: 12.5px;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  gap: 1px;
  text-shadow: 0 1px 1px rgba(0, 0, 0, .25);
  min-width: 0;
}
.tb-item-code { font-family: var(--mono); font-size: 9.5px; font-weight: 400; color: rgba(255, 255, 255, .75); }
.tb-del {
  margin-left: auto;
  color: rgba(255, 255, 255, .7);
  font-size: 11px;
  padding: 3px 5px;
  border-radius: 4px;
}
.tb-del:hover { color: #fff; background: rgba(0, 0, 0, .25); }

.dialect {
  font-family: var(--mono);
  font-size: 8.5px;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 2px 6px;
  border-radius: 99px;
  background: rgba(0, 0, 0, .28);
  color: rgba(255, 255, 255, .92);
}
.tb-item .dialect { position: absolute; right: 7px; top: 7px; }

/* ================= WORKSPACE — dotted machine grid ================= */

.workspace {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  position: relative;
  background: radial-gradient(var(--grid-dot) 1.2px, transparent 1.2px) 0 0 / 22px 22px, var(--bg);
  padding: 0 22px 90px;
}

.ws-toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 2px;
  background: linear-gradient(color-mix(in srgb, var(--bg) 96%, transparent), color-mix(in srgb, var(--bg) 82%, transparent));
  backdrop-filter: blur(3px);
}
.ws-count { font-family: var(--mono); font-size: 12px; color: var(--muted); }

.select-bar {
  position: sticky;
  top: 48px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin-bottom: 10px;
  background: var(--amber-soft);
  border: 1px solid color-mix(in srgb, var(--amber) 45%, transparent);
  border-radius: 9px;
  font-size: 13px;
  backdrop-filter: blur(4px);
}
#select-count { font-family: var(--disp); font-weight: 600; color: var(--amber); }

.blocklist { max-width: 660px; padding-top: 8px; }

/* ---- empty state ---- */
.ws-empty {
  max-width: 420px;
  margin: 70px auto;
  text-align: center;
  color: var(--muted);
  line-height: 1.65;
}
.ws-empty p { margin: 8px 0; }
.ws-empty-icon { font-size: 40px; color: var(--amber); }
.ws-empty strong { color: var(--ink); font-family: var(--disp); }

/* ================= BLOCKS — interlocking, full colour ================= */

.card {
  position: relative;
  display: flex;
  align-items: stretch;
  background: var(--cat);
  border-radius: 9px;
  box-shadow: var(--block-shadow);
  margin: 0 0 7px;
  color: #fff;
  cursor: grab;
  transition: filter .12s, transform .15s ease;
}
.card:active { cursor: grabbing; }

/* icon plate: category identity strip + natural grab surface */
.plate {
  flex: 0 0 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .24);
  border-radius: 9px 0 0 9px;
  color: rgba(255, 255, 255, .9);
}

/* snap preview: blocks below the insertion point slide down to open a gap */
.card.gap-shift { transform: translateY(18px); }
.card.just-dropped { animation: settle .32s cubic-bezier(.2, 1.4, .5, 1); }
@keyframes settle {
  from { transform: translateY(-7px) scale(1.015); }
  to { transform: none; }
}
/* bump: fills the gap down to the next block */
.card::after {
  content: "";
  position: absolute;
  bottom: -7px;
  left: 22px;
  width: 30px;
  height: 7px;
  background: var(--cat);
  border-radius: 0 0 6px 6px;
  filter: brightness(.82);
  pointer-events: none;
}
/* socket: shaded notch on the top edge where the bump above plugs in */
.card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 22px;
  width: 30px;
  height: 5px;
  background: rgba(0, 0, 0, .28);
  border-radius: 0 0 5px 5px;
  pointer-events: none;
}
.blocklist > .card:first-child::before { display: none; }
.blocklist > .card:last-child::after { display: none; }

.card:hover { filter: brightness(1.06); }
.card.dragging { opacity: .4; }
.card.selected { outline: 2px solid var(--amber); outline-offset: 2px; }

.card-main { flex: 1; min-width: 0; padding: 8px 11px; }
.card.has-truth .card-main { padding-bottom: 0; }

.card-head { display: flex; align-items: center; gap: 7px; min-height: 24px; }
.card-title {
  font-family: var(--disp);
  font-weight: 600;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 1px rgba(0, 0, 0, .25);
}

.block-code {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .04em;
  color: rgba(255, 255, 255, .85);
  background: rgba(0, 0, 0, .26);
  padding: 2px 7px;
  border-radius: 99px;
}

.icon-btn {
  color: rgba(255, 255, 255, .6);
  padding: 3px 5px;
  border-radius: 5px;
  line-height: 1;
  display: inline-flex;
}
.icon-btn:hover { color: #fff; background: rgba(0, 0, 0, .22); }
.menu-btn { font-size: 14px; font-weight: 700; letter-spacing: .05em; }

.card-desc {
  font-size: 12.5px;
  color: rgba(255, 255, 255, .92);
  line-height: 1.55;
  background: rgba(0, 0, 0, .24);
  padding: 8px 11px;
  margin: 7px 0 2px;
  border-radius: 7px;
}

.card-body { margin-top: 4px; }

/* the sentence: words + inline fields */
.sentence {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px 7px;
  font-size: 13px;
  line-height: 2;
}
.sentence .w { color: rgba(255, 255, 255, .95); }

.field { display: inline-flex; align-items: center; gap: 4px; }
.field input[type="text"] {
  font-family: var(--mono);
  font-size: 12px;
  padding: 3px 9px;
  border: none;
  border-radius: 99px;
  background: rgba(255, 255, 255, .93);
  color: #17191c;
  min-width: 30px;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .25);
}
.field input[type="text"]:focus { background: #fff; outline: 2px solid rgba(255, 255, 255, .6); outline-offset: 1px; }
.field input::placeholder { color: #9aa5b1; }
.field .unit { font-size: 10.5px; color: rgba(255, 255, 255, .65); }
.field.flag {
  gap: 6px;
  background: rgba(0, 0, 0, .22);
  border-radius: 99px;
  padding: 3px 10px;
  cursor: pointer;
}
.field.flag input { accent-color: var(--amber); }
.flag-name { font-family: var(--mono); font-size: 12px; font-weight: 500; color: #fff; }

/* slicer placeholder values get a "variable chip" look */
input.is-slicer-var {
  background: #ffe9c2 !important;
  color: #7a4d00 !important;
  font-style: italic;
}

/* extra parameter chips */
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(0, 0, 0, .22);
  border-radius: 99px;
  padding: 2px 4px 2px 9px;
}
.chip-key { font-family: var(--mono); font-size: 11px; font-weight: 500; color: rgba(255, 255, 255, .8); }
.chip input {
  font-family: var(--mono);
  font-size: 12px;
  border: none;
  border-radius: 99px;
  background: rgba(255, 255, 255, .93);
  color: #17191c;
  padding: 2px 7px;
  min-width: 22px;
}
.chip input:focus { outline: none; background: #fff; }
.chip-x { color: rgba(255, 255, 255, .6); font-size: 10px; padding: 2px 5px; }
.chip-x:hover { color: #fff; }
.chip-add {
  font-size: 11.5px;
  color: rgba(255, 255, 255, .75);
  border: 1px dashed rgba(255, 255, 255, .45);
  border-radius: 99px;
  padding: 3px 10px;
}
.chip-add:hover { color: #fff; border-color: #fff; }

.macro-name {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  padding: 3px 9px;
  border: none;
  border-radius: 99px;
  background: rgba(255, 255, 255, .93);
  color: #17191c;
  text-transform: uppercase;
}

/* wide inputs (comment / raw) */
.wide-input {
  width: 100%;
  font-family: var(--mono);
  font-size: 12.5px;
  padding: 6px 10px;
  border: none;
  border-radius: 7px;
  background: rgba(255, 255, 255, .93);
  color: #17191c;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .25);
}
.wide-input:focus { background: #fff; outline: 2px solid rgba(255, 255, 255, .5); }
.comment-input { font-style: italic; }
.raw-hint { font-size: 11px; color: rgba(255, 255, 255, .6); margin: 5px 0 2px; }

/* inline note (; comment) */
.note-field { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.note-semi { font-family: var(--mono); color: rgba(255, 255, 255, .55); }
.note-field input {
  flex: 1;
  font-family: var(--mono);
  font-size: 11.5px;
  font-style: italic;
  color: rgba(255, 255, 255, .85);
  border: none;
  border-bottom: 1px dashed rgba(255, 255, 255, .4);
  background: transparent;
  padding: 2px 4px;
}
.note-field input::placeholder { color: rgba(255, 255, 255, .4); }
.note-field input:focus { outline: none; border-bottom-color: #fff; }

/* truth line — exact G-code this block generates, as a machine readout strip */
.truth {
  font-family: var(--mono);
  font-size: 11px;
  color: rgba(255, 255, 255, .78);
  margin: 8px -11px 0;
  padding: 5px 11px 6px;
  background: rgba(0, 0, 0, .3);
  border-radius: 0 0 9px 0;
  white-space: nowrap;
  overflow-x: auto;
}
.truth::before { content: "→ "; color: var(--amber); }

/* comment / raw / blank use the muted "special" tone but distinct shapes */
.card.blank-card {
  background: transparent;
  box-shadow: none;
  border: 1.5px dashed var(--line);
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 10px;
}
.card.blank-card::before, .card.blank-card::after { display: none; }
.blank-card .icon-btn { color: var(--muted); }
.blank-card .icon-btn:hover { color: var(--ink); background: rgba(127, 142, 160, .18); }
.blank-label { flex: 1; text-align: center; font-size: 10px; letter-spacing: .14em; }

/* comment blocks read as sticky notes — instantly distinct from commands */
.card.comment-card {
  background: #e9d36e;
  color: #453c14;
  border-radius: 2px 9px 9px 2px;
  box-shadow: 1px 2px 6px rgba(0, 0, 0, .35);
}
.comment-card .plate { background: rgba(0, 0, 0, .1); color: #6b5d1e; border-radius: 2px 0 0 2px; }
.comment-card .card-title { color: #453c14; text-shadow: none; }
.comment-card .icon-btn { color: #857430; }
.comment-card .icon-btn:hover { color: #453c14; background: rgba(0, 0, 0, .12); }
.comment-card .card-desc { background: rgba(0, 0, 0, .1); color: #574d1f; }
.comment-card .wide-input {
  background: transparent;
  box-shadow: none;
  border-bottom: 1px dashed rgba(69, 60, 20, .4);
  border-radius: 0;
  color: #453c14;
}
.comment-card .wide-input:focus { outline: none; border-bottom-color: #453c14; background: rgba(255, 255, 255, .25); }
.comment-card::before { background: rgba(0, 0, 0, .14); }
.comment-card::after { background: #d3bd57; filter: none; }

/* raw blocks read as a terminal line — code sent exactly as written */
.card.raw-card {
  background: #0e1013;
  border: 1px solid #2b3036;
  color: #c4cad1;
}
.raw-card .plate { background: rgba(255, 255, 255, .06); color: #6fdd85; }
.raw-card .card-title { color: #9ba4ad; text-shadow: none; }
.raw-card .block-code { background: rgba(111, 221, 133, .14); color: #6fdd85; }
.raw-card .icon-btn { color: #6b737c; }
.raw-card .icon-btn:hover { color: #c4cad1; background: rgba(255, 255, 255, .08); }
.raw-card .card-desc { background: rgba(255, 255, 255, .06); color: #9ba4ad; }
.raw-card .wide-input {
  background: rgba(0, 0, 0, .45);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, .5);
  color: #6fdd85;
}
.raw-card .wide-input:focus { outline: 1px solid #6fdd85; background: #000; }
.raw-card .raw-hint { color: #6b737c; }
.raw-card::before { background: rgba(255, 255, 255, .08); }
.raw-card::after { background: #2b3036; filter: none; }
[data-theme="light"] .card.raw-card { border-color: #0e1013; }

/* group blocks: hatched header + nested children */
.card.group-card {
  background: color-mix(in srgb, var(--cat) 22%, var(--surface));
  border: 1.5px solid var(--cat);
}
.group-card > .plate { background: var(--cat); }
.card.group-card::before, .card.group-card::after { background: var(--cat); }
.group-card > .card-main > .card-head .card-title { color: var(--ink); text-shadow: none; }
.group-card > .card-main > .card-head .card-icon { color: var(--cat); }
.group-card > .card-main > .card-head .grip { color: var(--muted); }
.group-card > .card-main > .card-head .icon-btn { color: var(--muted); }
.group-card > .card-main > .card-head .icon-btn:hover { color: var(--ink); background: rgba(127, 142, 160, .2); }
.group-card > .card-main > .card-desc { background: rgba(127, 142, 160, .14); color: var(--muted); }

.group-kids { margin: 6px 0 4px; padding-left: 10px; border-left: 3px solid var(--cat); }
.card.in-group { margin-bottom: 6px; }
.card.in-group::before, .card.in-group::after { display: none; }
.group-bar { display: flex; gap: 6px; padding-bottom: 8px; }
.group-bar .btn-ghost { color: var(--muted); }
.group-bar .btn-ghost:hover { color: var(--ink); }

.sel-check { width: 17px; height: 17px; accent-color: var(--amber); }

/* drop indicator */
.drop-indicator {
  position: absolute;
  left: 24px;
  width: min(660px, calc(100% - 48px));
  height: 3px;
  background: var(--amber);
  border-radius: 2px;
  z-index: 8;
  pointer-events: none;
  box-shadow: 0 0 8px rgba(250, 109, 58, .6);
}

/* ================= PREVIEW PANEL — console readout ================= */

.preview-panel {
  position: relative;
  width: 320px;
  flex-shrink: 0;
  background: var(--console);
  color: #c9ced3;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--console-line);
}
.preview-panel.closed { display: none; }
.preview-panel .panel-title { color: #7a828a; }

.preview-resizer {
  position: absolute;
  left: -4px;
  top: 0;
  bottom: 0;
  width: 9px;
  cursor: col-resize;
  z-index: 3;
  touch-action: none;
}
.preview-resizer:hover, .preview-resizer:active { background: linear-gradient(90deg, transparent 2px, var(--amber) 2px, var(--amber) 5px, transparent 5px); }

.pv-actions { display: flex; align-items: center; gap: 8px; }
.pv-btn {
  font-family: var(--disp);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: .04em;
  color: #b3bac1;
  background: #25292e;
  border: 1px solid #34393f;
  border-radius: 6px;
  padding: 4px 9px;
}
.pv-btn:hover { color: #fff; background: #2e3339; }
.pv-btn.pv-apply { background: var(--amber); border-color: var(--amber); color: #0d0f11; }
.pv-btn.pv-apply:hover { background: #fb8355; }

.preview-edit {
  flex: 1;
  background: #0a0c0e;
  color: #9fd3a8;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.75;
  padding: 8px 14px 20px;
  border: none;
  resize: none;
  white-space: pre;
}
.preview-edit:focus { outline: 1px solid var(--amber); outline-offset: -1px; }
.annotate-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: var(--body);
  font-size: 11px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  cursor: pointer;
}
.annotate-label input { accent-color: var(--amber); }

.preview-code {
  flex: 1;
  overflow: auto;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.75;
  padding: 4px 14px 20px;
  white-space: pre;
  color: #9fd3a8;
}

/* ================= MENU / MODAL / TOAST ================= */

.popmenu {
  position: fixed;
  z-index: 50;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .4);
  padding: 4px;
  min-width: 160px;
}
.popmenu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  text-align: left;
  padding: 7px 12px;
  font-size: 13px;
  border-radius: 6px;
  color: var(--ink);
}
.popmenu-item .ic { color: var(--muted); }
.popmenu-item:hover { background: var(--surface-2); }
.popmenu-item.danger, .popmenu-item.danger .ic { color: var(--danger); }
.popmenu-item.danger:hover { background: color-mix(in srgb, var(--danger) 14%, transparent); }

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(8, 11, 16, .66);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(2px);
}
.modal-box {
  background: var(--surface);
  border-radius: 13px;
  border: 1px solid var(--line);
  border-top: 4px solid var(--amber);
  padding: 22px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .5);
}
.modal-box h2 { font-family: var(--disp); font-size: 17px; margin-bottom: 6px; }
.modal-sub { font-size: 13px; color: var(--muted); line-height: 1.5; margin-bottom: 14px; }
.modal textarea {
  width: 100%;
  font-family: var(--mono);
  font-size: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg);
  color: var(--ink);
  resize: vertical;
}
.modal-label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 12px; }
.modal-label .opt { color: var(--muted); font-weight: 400; }
.modal-label input {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translate(-50%, 20px);
  background: var(--console-2);
  color: #e8eaed;
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 9px;
  border-left: 4px solid var(--amber);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 70;
  max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ================= RESPONSIVE ================= */

@media (max-width: 1100px) {
  .preview-panel { position: fixed; right: 0; top: 0; bottom: 0; z-index: 30; box-shadow: -10px 0 34px rgba(0, 0, 0, .45); }
}

@media (max-width: 820px) {
  .only-mobile { display: inline-flex; }
  .toolbox-panel {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 40;
    width: min(300px, 85vw);
    transform: translateX(-100%);
    transition: transform .18s ease;
    box-shadow: 10px 0 34px rgba(0, 0, 0, .4);
  }
  body.toolbox-open .toolbox-panel { transform: translateX(0); }
  .brand-sub { display: none; }
  .topbar { gap: 10px; }
  .workspace { padding: 0 12px 90px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
