:root {
  --bg: #f4f4f2;
  --panel: #ffffff;
  --text: #1d1d1f;
  --muted: #6b6b70;
  --border: #dcdcd8;
  --accent: #2463eb;
  --accent-text: #ffffff;
  --stage: #e7e7e3;
  --warn-bg: #fff4d6;
  --warn-text: #6b4e00;
  --danger: #b42318;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161618;
    --panel: #1f1f22;
    --text: #ececef;
    --muted: #9a9aa2;
    --border: #34343a;
    --accent: #5b8cff;
    --accent-text: #0b0b0d;
    --stage: #111113;
    --warn-bg: #3a2f10;
    --warn-text: #f3d68a;
    --danger: #ff7b6e;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #161618;
  --panel: #1f1f22;
  --text: #ececef;
  --muted: #9a9aa2;
  --border: #34343a;
  --accent: #5b8cff;
  --accent-text: #0b0b0d;
  --stage: #111113;
  --warn-bg: #3a2f10;
  --warn-text: #f3d68a;
  --danger: #ff7b6e;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 { font-size: 16px; margin: 0; font-weight: 600; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 8px; }
h2:first-child, .panel-toggle + h2 { margin-top: 0; }

button, a.button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button, a.button {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary, a.button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.danger-link { border: none; background: none; color: var(--danger); padding: 4px 0; margin-top: 8px; }

input[type="number"], input[type="text"], select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
}
textarea { resize: vertical; min-height: 60px; }

label { display: block; margin-bottom: 10px; color: var(--muted); font-size: 13px; }
label > input:not([type="checkbox"]):not([type="radio"]), label > select, label > textarea { margin-top: 3px; color: var(--text); }
label.inline { display: flex; align-items: center; gap: 6px; color: var(--text); margin-bottom: 6px; }

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.topbar .conn { flex: 1; }
.actions { display: flex; gap: 8px; align-items: center; }
/* Narrow screens: the header buttons wrap under the title. */
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; row-gap: 8px; }
  .actions { flex-wrap: wrap; }
}
.copies { display: flex; align-items: center; gap: 6px; margin: 0; }
.copies input { width: 56px; }

.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}
.pill.ok { color: var(--accent); border-color: var(--accent); }

.banner {
  background: var(--warn-bg);
  color: var(--warn-text);
  padding: 8px 16px;
  font-size: 13px;
}
.banner a { color: inherit; font-weight: 600; }
.banner button { margin-left: 8px; padding: 3px 10px; font-size: 13px; }
button.link { border: none; background: none; color: var(--accent); padding: 4px 0; display: block; margin-bottom: 10px; }

dialog.help {
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
}
dialog.help::backdrop { background: rgba(0, 0, 0, .45); }
dialog.help header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
dialog.help h2 { font-size: 17px; text-transform: none; letter-spacing: 0; color: var(--text); margin: 0; }
dialog.help .close { border: none; background: none; font-size: 22px; line-height: 1; padding: 2px 6px; }
dialog.help .error-detail { color: var(--muted); font-size: 12px; margin: 0 0 10px; }
dialog.help .why { color: var(--muted); font-size: 13px; padding: 0 12px 6px; }
dialog.help .why p { margin: 0 0 6px; }
dialog.help .tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; border-bottom: 1px solid var(--border); }
dialog.help .tab { border: none; border-bottom: 2px solid transparent; border-radius: 0; padding: 6px 10px; background: none; color: var(--muted); }
dialog.help .tab.active { color: var(--text); border-bottom-color: var(--accent); }
dialog.help .steps { list-style: none; padding: 0; margin: 0 0 16px; }
dialog.help .step { padding: 10px 12px; border-radius: 8px; margin-bottom: 6px; border: 1px solid transparent; }
dialog.help .step.current { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
dialog.help .step p { margin: 6px 0; }
dialog.help .step ol { margin: 6px 0; padding-left: 20px; }
dialog.help .step a { color: var(--accent); }
dialog.help .commands { display: flex; gap: 8px; align-items: flex-start; margin: 6px 0; }
dialog.help pre {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 8px 10px;
  overflow-x: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
dialog.help .row { justify-content: flex-end; margin: 0; }

.layout {
  display: grid;
  grid-template-columns: var(--left, 260px) minmax(0, 1fr) var(--right, 280px);
  gap: 0;
  min-height: calc(100vh - 54px);
}

.panel {
  background: var(--panel);
  padding: 16px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
}
#props { border-right: none; border-left: 1px solid var(--border); }
/* Side panels fold away to a narrow strip for more room (small screens). */
.panel { position: relative; }
.panel-toggle {
  position: absolute; top: 10px; right: 8px;
  padding: 2px 4px; border: none; background: none; color: var(--muted); line-height: 0;
}
.panel-toggle:hover { color: var(--text); background: var(--border); }
.panel-toggle .rail-label { display: none; }
.layout.hide-setup { --left: 36px; }
.layout.hide-props { --right: 36px; }
.panel.collapsed { padding: 8px 0; overflow: hidden; }
.panel.collapsed > :not(.panel-toggle) { display: none !important; }
.panel.collapsed .panel-toggle {
  position: static; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 6px 0; line-height: normal; font-size: 12px; font-weight: 600;
}
.panel.collapsed .panel-toggle .rail-label { display: block; writing-mode: vertical-rl; letter-spacing: .04em; }

.row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.note { color: var(--muted); font-size: 12px; margin: 6px 0; }
.note.error { color: var(--danger); }

.stage { padding: 16px; min-width: 0; }
.toolbar { display: flex; gap: 4px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar > button { padding: 6px 10px; }
/* Icons in buttons (Lucide, see lucide.js), before the name if there is one. */
svg.ico { width: 16px; height: 16px; vertical-align: -3px; flex: none; }
button:not(.icon) > svg.ico, summary > svg.ico, .menu-list a > svg.ico { margin-right: 6px; }
.icon > svg.ico { display: block; margin: 0 auto; }
dialog.symbols .grid button > svg.ico { width: 22px; height: 22px; margin: 0 auto; display: block; }
dialog.symbols input[type="search"] { width: 100%; box-sizing: border-box; margin: 4px 0 6px; }
dialog.symbols .symbol-scroll { max-height: 60vh; overflow: auto; }
.toolbar .spacer { flex: 1; }
/* The view controls wrap as one group, never one button at a time. */
.toolbar .tools { display: inline-flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.toolbar .grp { display: inline-flex; gap: 4px; align-items: center; white-space: nowrap; }
.toolbar .icon { padding: 6px 8px; min-width: 30px; }
.toolbar .seg + .icon { margin-left: 4px; }
/* The text format bar, as in DYMO Label: the everyday text settings above
   the label; the panel on the right has the rest. */
.format-bar { margin-top: -6px; }
.format-bar select { width: auto; max-width: 150px; }
.format-bar .unit { color: var(--muted); font-size: 12px; margin: 0 4px 0 -2px; }
.format-bar input { width: 5em; }
.format-bar button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.format-bar .b { font-weight: 700; }
.format-bar .i { font-style: italic; font-family: serif; }
.format-bar .sep { width: 1px; align-self: stretch; background: var(--border); margin: 2px 4px; }
.format-bar.idle { opacity: .55; }
#zoom-label { min-width: 42px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }

.canvas-wrap {
  position: relative;
  background: var(--stage);
  border-radius: 8px;
  padding: 24px;
  overflow: auto;
}
/* Segmented toggle (orientation). */
.seg { display: inline-flex; }
.seg button { border-radius: 0; }
.seg button:first-child { border-radius: 6px 0 0 6px; }
.seg button:last-child { border-radius: 0 6px 6px 0; margin-left: -1px; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

/* Screen calibration for the actual-size preview. */
dialog.screen .cal-stage { padding: 12px 0; overflow: auto; }
dialog.screen .cal-outline { border: 2px solid var(--accent); background: rgba(36, 99, 235, .08); box-sizing: border-box; }
dialog.screen .cal-outline.card { border-radius: 3mm; }
dialog.screen .row input[type="range"] { flex: 1; }
#zoom-actual.unset { opacity: .55; }
/* The label at its real size, under the editor. */
.actual-wrap { margin: 10px 0 0; padding: 12px 16px 16px; background: var(--stage); border-radius: 8px; overflow: auto; }
.actual-wrap figcaption { font-size: 12px; color: var(--muted); margin-bottom: 8px; display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; }
.actual-wrap figcaption .estimate { color: var(--warn-text); font-weight: 600; }
#actual-canvas { display: block; }
#zoom-actual[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

/* Rulers above and left of the label. */
.ruled {
  display: grid;
  grid-template-columns: 18px auto;
  grid-template-rows: 18px auto;
  gap: 2px;
  justify-content: start;
}
.ruler { display: block; }
.ruler-corner { font-size: 9px; color: var(--muted); align-self: end; }
#item-list li.hidden-item { opacity: .5; }
/* Left-anchored so a growing label extends to the right and items stay put. */
#canvas {
  display: block;
  margin: 0;
  touch-action: none;
  outline: none;
}
#canvas:focus-visible { box-shadow: 0 0 0 2px var(--accent); }

/* Buttons on the labels of a 2-up row (top-right corner of each). */
.lane-button {
  position: absolute;
  z-index: 1;
  transform: translateX(-100%);
  padding: 2px 8px;
  font-size: 12px;
  border-radius: 999px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
}
/* Small toggles beside the label's end grip and the selected text's handle. */
.canvas-chip {
  position: absolute;
  z-index: 1;
  padding: 1px 7px;
  font-size: 11px;
  border-radius: 999px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
}
.canvas-chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
/* In-place text editor, laid over the item on the label. */
textarea.inplace {
  position: absolute;
  z-index: 2;
  box-sizing: content-box;
  width: auto;
  min-height: 0;
  margin: 0;
  padding: 0 2px;
  border: none;
  border-radius: 0;
  outline: 2px solid var(--accent);
  background: rgba(255, 255, 255, .94);
  color: #111;
  resize: none;
  overflow: hidden;
  white-space: pre;
  field-sizing: content;
}

.dims { color: var(--text); font-variant-numeric: tabular-nums; margin: 10px 0 2px; }
/* Red: will be cut off. Amber: past the safe area, may not print. */
.dims.warn { color: var(--danger); }
/* The File menu in the header. */
details.menu { position: relative; }
details.menu > summary { list-style: none; cursor: pointer; background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px; }
details.menu > summary::-webkit-details-marker { display: none; }
details.menu[open] > summary, details.menu > summary:hover { border-color: var(--accent); }
details.menu .menu-list { position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; display: grid; min-width: 190px; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, .18); padding: 4px; }
details.menu .menu-list.left { left: 0; right: auto; }
.toolbar details.menu > summary { padding: 6px 10px; }
dialog.symbols .grid { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 12px; }
dialog.symbols .grid button { min-width: 38px; height: 38px; font-size: 18px; padding: 0 6px; }
dialog.symbols h3 { margin: 8px 0 2px; font-size: 13px; }
details.menu .menu-list button { border: none; background: none; text-align: left; padding: 7px 10px; border-radius: 5px; }
details.menu .menu-list button:hover, details.menu .menu-list a:hover { background: var(--stage); }
details.menu .menu-list a { color: inherit; text-decoration: none; padding: 7px 10px; border-radius: 5px; font-size: inherit; }
.browser-note { color: var(--warn-text); font-weight: 600; }
.pill.muted { color: var(--muted); }
.topbar h1 { display: flex; align-items: center; gap: 8px; }
.topbar h1 .logo { display: block; }
.dims.caution { color: var(--warn-text); }
.hint { color: var(--muted); font-size: 12px; margin: 0; }
.site-footer { color: var(--muted); font-size: 12px; margin-top: auto; padding-top: 24px; }
.site-footer a { color: inherit; }

.item-list { list-style: none; padding: 0; margin: 0 0 12px; }
.item-list li {
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item-list li:hover { border-color: var(--border); }
.item-list li.selected { border-color: var(--accent); }
.item-list .kind { color: var(--muted); font-size: 11px; text-transform: uppercase; margin-right: 6px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .panel.collapsed .panel-toggle { flex-direction: row; justify-content: center; }
  .panel.collapsed .panel-toggle .rail-label { writing-mode: horizontal-tb; }
  /* Stacked panels fold up and down: the arrows turn to match. */
  #setup .panel-toggle svg { transform: rotate(90deg); }
  #props .panel-toggle svg { transform: rotate(-90deg); }
  .panel { border: none; border-bottom: 1px solid var(--border); }
  #props { border-left: none; }
  .stage { order: -1; }
  .topbar { padding: 10px 16px; }
}

.tests { margin: 4px 0 10px; }
.tests h3 { font-size: 13px; margin: 12px 0 6px; }
.roll-code { font-size: 13px; margin: 4px 0 8px; }
.roll-code strong { font-size: 16px; letter-spacing: .08em; }
.roll-code code { font: 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; user-select: all; }

dialog.about { width: min(820px, calc(100vw - 32px)); }
dialog.about .about-body { max-height: calc(100vh - 220px); overflow-y: auto; margin-bottom: 14px; }
dialog.about h3 { font-size: 14px; margin: 16px 0 6px; }
dialog.about ul, dialog.about ol { margin: 6px 0; padding-left: 20px; }
dialog.about ol.start li { margin-bottom: 6px; }
dialog.about li { margin-bottom: 4px; }
dialog.about a, button.linklike { color: var(--accent); }
button.linklike { border: none; background: none; padding: 0; font: inherit; cursor: pointer; text-decoration: underline; }
.table-scroll { overflow-x: auto; }
table.compat { border-collapse: collapse; width: 100%; font-size: 13px; }
table.compat th, table.compat td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.compat th { color: var(--muted); font-weight: 600; }
table.compat tr.tested td:first-child { font-weight: 600; }
table.compat tr.unimplemented td { color: var(--muted); }
table.compat td:nth-child(2), table.compat td:nth-child(3) { white-space: nowrap; }

details.section { margin: 18px 0 8px; }
details.section > summary { cursor: pointer; list-style: none; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 6px; }
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary::before { content: '▸'; color: var(--muted); font-size: 11px; }
details.section[open] > summary::before { content: '▾'; }
details.section > summary h2 { display: inline; margin: 0; white-space: nowrap; }
details.section > summary .state { color: var(--accent); font-size: 12px; }
details.section > div { margin-top: 10px; }
details.section > summary .state { flex-basis: 100%; padding-left: 14px; }
/* hidden always wins over a display set above (flex, grid, block links). */
[hidden] { display: none !important; }

dialog.library .cards { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
dialog.library .card { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; padding: 10px; border: 1px solid var(--border); border-radius: 8px; align-items: center; }
dialog.library .card.current { border-color: var(--accent); }
dialog.library .thumb { grid-row: span 2; background: #fff; border-radius: 4px; display: flex; align-items: center; justify-content: center; min-height: 40px; padding: 4px; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); }
dialog.library .thumb img { max-width: 100%; max-height: 72px; image-rendering: pixelated; }
dialog.library .meta { display: flex; flex-direction: column; gap: 2px; font-size: 13px; color: var(--muted); min-width: 0; }
dialog.library .meta strong { color: var(--text); font-size: 14px; }
dialog.library .actions { display: flex; gap: 6px; flex-wrap: wrap; }
dialog.library .actions button { padding: 4px 10px; font-size: 13px; }
dialog.library .empty { color: var(--muted); }
@media (max-width: 520px) { dialog.library .card { grid-template-columns: 1fr; } dialog.library .thumb { grid-row: auto; } }
a.small-link { display: block; font-size: 12px; color: var(--accent); margin: -4px 0 10px; }
#report-printer { color: var(--accent); }

/* Data rows, counter and date: under the editor while the design has fields. */
.data-bar[hidden] { display: none; }
dialog.data-paste textarea { width: 100%; box-sizing: border-box; min-height: 220px; font: 12px/1.45 ui-monospace, monospace; tab-size: 16; }
dialog.data-paste .examples p { margin: 6px 0; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
dialog.data-paste .chip { border-radius: 999px; padding: 3px 12px; font-size: 13px; }
dialog.data-paste .chip[aria-pressed="true"] { border-color: var(--accent); font-weight: 600; }
.generic-box { border-left: 3px solid var(--accent); padding: 4px 0 4px 10px; margin: 6px 0; }
.generic-box h3 { margin: 0 0 4px; font-size: 13px; }
.generic-report { margin: 8px 0; }
.generic-report summary { cursor: pointer; font-weight: 600; font-size: 13px; }
.generic-report textarea { width: 100%; box-sizing: border-box; font: 11px/1.4 ui-monospace, monospace; margin: 6px 0; }
a.button { display: inline-block; text-decoration: none; }
.generic-report .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.data-bar { margin: 8px 0 0; padding: 10px 12px; background: var(--stage); border-radius: 8px; font-size: 13px; display: grid; gap: 10px; }
.data-bar header { display: flex; align-items: center; justify-content: space-between; }
.data-bar h2 { margin: 0; font-size: 13px; }
.data-bar h3 { margin: 0 0 6px; font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.data-bar h3 .num { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; background: var(--accent); color: var(--accent-text); font-size: 11px; }
.data-bar .batch-step { display: grid; gap: 6px; }
.data-bar .chip { border-radius: 999px; padding: 3px 12px; font-size: 13px; }
.data-bar .close { padding: 0 8px; }
.data-bar .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.data-bar .muted { color: var(--muted); overflow-wrap: anywhere; }
.data-bar .note { margin: 0; }
.data-bar .counter input { width: 5em; }
.data-bar .table-scroll { max-height: 240px; overflow: auto; margin-top: 6px; }
.data-bar table { border-collapse: collapse; font-size: 12px; }
.data-bar th, .data-bar td { border-bottom: 1px solid var(--line, rgba(0, 0, 0, .1)); padding: 3px 8px; text-align: left; white-space: pre-line; }
.data-bar tr:hover td { background: rgba(36, 99, 235, .06); cursor: pointer; }
.with-picker .field-picker { margin-top: 4px; font-size: 12px; }
#color-note { font-size: 12px; color: var(--muted); margin: 0 0 8px; }
.len-quick { white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); margin: 0 6px; }
.len-quick input { width: 66px; }
.len-auto { padding: 3px 8px; font-size: 12px; }
.len-auto[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
aside h3.sub { font-size: 12px; font-weight: 600; color: var(--muted); margin: 8px 0 4px; }
