@import "./tokens.css";

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
  color: var(--color-text);
  font: 15px/1.5 var(--font-sans);
}
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
h1, h2, h3, p { margin-top: 0; }
h2 { font-size: 16px; font-weight: 600; letter-spacing: -.01em; margin-bottom: 4px; }
button, input { font: inherit; }
button {
  min-height: 40px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  background: var(--color-surface-raised);
  color: var(--color-text);
  cursor: pointer;
  transition: background 140ms var(--ease-standard), border-color 140ms var(--ease-standard);
}
button:hover:not(:disabled) { background: var(--color-surface-hover); border-color: var(--color-text-muted); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; }
button[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
button[aria-disabled="true"]:hover { background: var(--color-surface-raised); border-color: var(--color-border-strong); }
button[aria-disabled="true"]:active { transform: none; }
button.primary { background: var(--color-primary); border-color: var(--color-primary); font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--color-accent); border-color: var(--color-accent); color: var(--color-bg); }
button.danger { color: var(--color-danger); }
button[aria-pressed="true"] { border-color: var(--color-primary); background: var(--color-surface-hover); box-shadow: inset 0 0 0 1px var(--color-primary); }
button[aria-pressed="true"][aria-disabled="true"] { opacity: .8; }
input[type="text"], input[type="number"], input[type="email"], input[type="search"] {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  background: var(--color-surface-raised);
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
}
textarea, select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  background: var(--color-surface-raised);
  color: var(--color-text);
}
textarea { min-height: 72px; resize: vertical; }
select { appearance: auto; }
input[type="number"] { appearance: textfield; }
input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--color-primary); }
label { color: var(--color-text-secondary); font-size: 13px; font-weight: 500; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  flex: none;
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: 10px clamp(14px, 2.4vw, 32px);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 170px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: var(--radius-md);
  background: var(--color-primary);
  font-weight: 800;
  letter-spacing: -.05em;
}
.brand strong { display: block; font-size: 14px; line-height: 1.15; }
.brand small { display: block; margin-top: 2px; color: var(--color-text-muted); font-size: 12px; }
.header-actions { display: flex; align-items: flex-end; justify-content: flex-end; gap: var(--space-2); flex-wrap: wrap; }
.project-name { width: 190px; }
.project-name label { display: block; margin-bottom: 3px; font-size: 12px; color: var(--color-text-muted); }
.project-name input { min-height: 36px; padding-block: 4px; }
.project-name-error { display: block; margin-top: 3px; color: var(--color-danger); font-size: 12px; }
.project-name-error:empty { display: none; }
.button-group { display: flex; gap: var(--space-1); flex-wrap: wrap; }
.save-status {
  max-width: 240px;
  margin: 0;
  padding-bottom: 10px;
  overflow: hidden;
  color: var(--color-text-muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.save-status[data-state="saving"] { color: var(--color-warning); }
.save-status[data-state="dirty"],
.save-status[data-state="error"] { color: var(--color-danger); }
.save-status[data-state="conflict"] { color: var(--color-warning); }
.save-banner {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding: 10px clamp(14px, 2.4vw, 32px);
  border-bottom: 1px solid var(--color-danger);
  background: var(--color-surface);
  color: var(--color-danger);
}
.save-banner-message { flex: 1 1 260px; margin: 0; font-size: 13px; }
.snapshot-banner { border-bottom-color: var(--color-danger); }
/* A revision conflict is a decision, not a hard failure: warning tone. */
.conflict-banner {
  border-bottom-color: var(--color-warning);
  color: var(--color-warning);
}
.conflict-banner button { color: var(--color-text); }
.conflict-banner button.danger { color: var(--color-danger); }
.conflict-banner button:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* Snapshot list: a compact popover under the split diskette. */
.snapshot-menu {
  position: fixed;
  z-index: 46;
  width: min(430px, calc(100vw - 16px));
  max-height: min(70vh, 560px);
  overflow-y: auto;
  padding: var(--space-3);
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-overlay);
}
.snapshot-menu-head h2 { margin-bottom: var(--space-1); }
.snapshot-menu-head .hint { margin-bottom: var(--space-2); font-size: 12px; }
.snapshot-menu-status:empty { display: none; }
.snapshot-list { list-style: none; margin: 0; padding: 0; }
.snapshot-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 56px;
  padding: var(--space-2) 0;
  border-top: 1px solid var(--color-border);
}
.snapshot-row:first-child { border-top: 0; }
.snapshot-info { flex: 1; min-width: 0; display: grid; gap: var(--space-1); }
.snapshot-name {
  overflow: hidden;
  color: var(--color-text);
  font-size: 13px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.snapshot-meta { color: var(--color-text-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.snapshot-actions { display: flex; gap: var(--space-1); flex: none; }
.snapshot-action {
  width: 40px;
  height: 40px;
  min-height: 40px !important;
  border-color: transparent;
  background: transparent;
  color: var(--color-text-muted);
}
.snapshot-action:hover:not(:disabled),
.snapshot-action:focus-visible { background: var(--color-surface-hover); color: var(--color-text); }
.snapshot-action.danger { color: var(--color-danger); }
.snapshot-empty { padding: var(--space-3) 0; color: var(--color-text-muted); font-size: 13px; }
.snapshot-rename { display: flex; align-items: center; gap: var(--space-1); width: 100%; flex-wrap: wrap; }
.snapshot-rename input { flex: 1 1 140px; min-height: 40px; padding: 4px 8px; }
.snapshot-rename button { min-height: 40px; padding: 4px 8px; font-size: 12px; }

/* Project list: the entry point at `/`. The editor is hidden until a named
   project is open, so no anonymous in-memory project is ever shown. */
.project-list-view {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
body[data-view="editor"] .project-list-view { display: none; }
body[data-view="list"] .app-header,
body[data-view="list"] #save-banner,
body[data-view="list"] #conflict-banner,
body[data-view="list"] #context-bar,
body[data-view="list"] .workspace { display: none; }
.project-library-header {
  flex: none;
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  padding: 10px clamp(14px, 2.4vw, 32px);
  border-bottom: 1px solid var(--color-border);
}
.project-library-actions { align-items: center; }
.project-library {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: clamp(24px, 5vw, 56px) clamp(14px, 4vw, 40px) 64px;
  display: grid;
  align-content: start;
  gap: var(--space-6);
}
.project-library-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
}
.project-library-heading h1 {
  margin-bottom: var(--space-1);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -.02em;
}
.project-library-heading .hint { margin: 0; }
.project-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); }
.project-row { display: flex; align-items: stretch; gap: var(--space-2); }
.project-row .project-card { flex: 1 1 auto; min-width: 0; }
.project-row-actions { display: flex; align-items: stretch; }
.project-row .project-duplicate,
.project-row .project-delete,
.project-row .project-restore {
  width: 44px;
  height: auto;
  min-height: 44px !important;
  align-self: stretch;
  flex: none;
}
.project-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) repeat(3, minmax(92px, auto));
  align-items: center;
  gap: var(--space-4);
  min-height: 64px;
  padding: 12px var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  color: var(--color-text);
  text-decoration: none;
  transition: background 140ms var(--ease-standard), border-color 140ms var(--ease-standard);
}
.project-card:hover { background: var(--color-surface-hover); border-color: var(--color-border-strong); }
.project-card:active { background: var(--color-surface-hover); transform: translateY(1px); }
.project-card:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
.project-name-cell { min-width: 0; }
.project-name-cell strong {
  display: block;
  overflow: hidden;
  color: var(--color-text);
  font-size: 15px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.project-metric { min-width: 0; }
.project-metric-label {
  display: block;
  margin-bottom: 2px;
  color: var(--color-text-muted);
  font-size: 12px;
  font-weight: 500;
}
.project-metric-value {
  display: block;
  overflow: hidden;
  color: var(--color-text-secondary);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.project-empty {
  display: grid;
  justify-items: center;
  gap: var(--space-3);
  padding: clamp(40px, 8vw, 72px) var(--space-4);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  text-align: center;
}
.project-empty p { max-width: 52ch; margin: 0; color: var(--color-text-secondary); font-size: 14px; }
.project-empty .button-group { justify-content: center; margin-top: var(--space-1); }
.project-list-notice { margin: 0; }
.trash-library {
  display: grid;
  gap: var(--space-3);
  margin-top: var(--space-4);
  padding-top: var(--space-6);
  border-top: 1px solid var(--color-border);
}
.trash-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
}
.trash-heading h2 { margin-bottom: var(--space-1); }
.trash-heading .hint { margin: 0; max-width: 68ch; }
.trash-card {
  grid-template-columns: minmax(0, 1fr) minmax(92px, auto);
  background: var(--color-surface-raised);
}
.project-create-field { display: block; margin: var(--space-4) 0 var(--space-1); }
.field-error { margin: var(--space-1) 0 0; color: var(--color-danger); font-size: 13px; }
@media (max-width: 720px) {
  .project-card { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
  .project-name-cell { grid-column: 1 / -1; }
}
@media (max-width: 480px) {
  .project-library-header { align-items: stretch; }
  .project-library-actions { width: 100%; }
  .project-library-actions button { flex: 1 1 auto; }
}

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  --properties-width: 340px;
  grid-template-columns: 48px 252px minmax(360px, 1fr) 12px var(--properties-width);
  grid-template-areas: "tools panel stage resizer properties";
  gap: var(--space-2);
  padding: var(--space-2);
}
.panel-resizer {
  grid-area: resizer;
  align-self: stretch;
  width: 12px;
  min-width: 12px;
  border-radius: 999px;
  cursor: col-resize;
  background: transparent;
  position: relative;
  touch-action: none;
}
.panel-resizer::before {
  content: "";
  position: absolute;
  inset: 0 -14px;
}
.panel-resizer::after {
  content: "";
  position: absolute;
  inset: 12px 5px;
  border-radius: 999px;
  background: var(--color-border-strong);
}
.panel-resizer:hover::after,
.panel-resizer:focus-visible::after,
.panel-resizer.is-resizing::after { background: var(--color-accent); }
.panel-resizer:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 1px; }
.tool-panel, .properties-panel, .stage-panel {
  min-width: 0;
  min-height: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}
.tool-rail {
  grid-area: tools;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-2) 4px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}
.tool-panel { grid-area: panel; display: flex; flex-direction: column; overflow-y: auto; }
.tool-panel-section { display: flex; flex-direction: column; }
.tool-shortcut {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1);
  margin: 0 0 var(--space-2);
  padding: 0 var(--space-4);
  color: var(--color-text-secondary);
  font-size: 12px;
}
.tool-shortcut kbd,
.tool-docs kbd {
  padding: 1px var(--space-1);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-surface-raised);
  font-family: var(--font-mono);
  font-size: 11px;
}
.tool-docs { padding: 0 var(--space-4) var(--space-3); color: var(--color-text-secondary); font-size: 13px; line-height: 1.55; }
.tool-docs .tool-shortcut { padding: 0; margin: 0 0 var(--space-1); }
.tool-doc-heading { margin: var(--space-3) 0 var(--space-2); color: var(--color-text); font-size: 13px; font-weight: 600; }
.tool-docs ul { margin: 0; padding-left: 18px; display: grid; gap: 6px; }
.tool-docs li { margin: 0; }
.tool-docs strong { color: var(--color-text); }

.tool-panel-section[hidden] { display: none; }
.import-block { display: grid; gap: var(--space-1); padding: 0 var(--space-4) var(--space-3); }
.properties-panel {
  grid-area: properties;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  grid-template-areas: "body rail";
}
.panel-body { grid-area: body; overflow-y: auto; min-width: 0; }
.panel-rail[hidden] { display: none; }
body[data-preview="true"] .properties-panel { grid-template-columns: minmax(0, 1fr); grid-template-areas: "body"; }
.panel-rail {
  grid-area: rail;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-2) 4px;
  border-left: 1px solid var(--color-border);
}
.rail-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text-muted);
}
.rail-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.rail-button:hover:not(:disabled) { background: var(--color-surface-hover); color: var(--color-text); }
.rail-button[aria-pressed="true"], .rail-button[aria-selected="true"] {
  background: var(--color-surface-hover);
  border-color: var(--color-border-strong);
  color: var(--color-text);
  box-shadow: none;
}
/* The active tool stands out more than the panel that happens to be open. */
.rail-button[data-tool][aria-pressed="true"] {
  color: var(--color-primary);
  border-color: var(--color-primary);
  box-shadow: inset 0 0 0 1px var(--color-primary);
}
.rail-button:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
.stage-panel { grid-area: stage; display: flex; flex-direction: column; }
.panel-heading { padding: var(--space-4) var(--space-4) var(--space-2); }
.panel-heading.compact { padding: var(--space-3) var(--space-4) var(--space-2); }
.hint { margin: 0; color: var(--color-text-muted); font-size: 12px; line-height: 1.5; }

.panel-tab { flex: none; }
.panel-tab-panel { min-height: 100%; }
#properties-content { padding: 0 var(--space-4) var(--space-4); }
.canvas-settings { display: grid; gap: var(--space-3); padding: 0 var(--space-4) var(--space-4); }
.canvas-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  font-size: 13px;
}
.canvas-row strong { color: var(--color-text); font-weight: 600; font-variant-numeric: tabular-nums; }
.canvas-row button { flex: none; }

.context-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  padding: 8px clamp(14px, 2.4vw, 32px);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}
.context-bar[hidden] { display: none; }
.context-bar [hidden] { display: none !important; }
.context-group { display: flex; align-items: center; gap: var(--space-1); flex-wrap: wrap; }
.context-label { color: var(--color-text-muted); font-size: 12px; margin-right: var(--space-1); }
.context-note { color: var(--color-text-muted); font-size: 12px; font-style: italic; margin-right: var(--space-1); }
.context-sep { width: 1px; height: 24px; background: var(--color-border-strong); }
#context-staging button { min-height: 36px; padding: 4px 10px; font-size: 13px; }
.icon-button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  min-height: 36px !important;
  padding: 0 !important;
}
.icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.header-actions .icon-button { width: 38px; height: 38px; }
.split-button { display: flex; align-items: stretch; }
.split-button #save-project {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}
.header-actions .split-button .split-toggle {
  width: 30px;
  min-width: 30px;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  border-left: 0;
}
.context-bar button[aria-pressed="true"] {
  border-color: var(--color-primary);
  background: var(--color-surface-hover);
  box-shadow: inset 0 0 0 1px var(--color-primary);
}
.operation-group .icon-button { flex: none; }

/* Action ribbon: a few category buttons instead of one icon per command. */
.context-ribbon {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-wrap: wrap;
  min-width: 0;
}
.ribbon-group { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.ribbon-group[hidden] { display: none !important; }
.ribbon-divider { width: 1px; height: 30px; margin: 0 var(--space-1); background: var(--color-border-strong); }
.ribbon-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;
  padding: 5px 9px 5px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text-secondary);
  font-size: 13px;
  line-height: 1.2;
}
.ribbon-button:hover,
.ribbon-button[aria-expanded="true"] {
  background: var(--color-surface-hover);
  border-color: var(--color-border);
  color: var(--color-text);
}
.ribbon-button:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 1px; }
.ribbon-button:active { background: var(--color-surface-hover); }
.ribbon-button svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.ribbon-button .ribbon-chevron,
.command-menu-item .menu-chevron {
  width: 12px;
  height: 12px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  color: var(--color-text-muted);
}
.ribbon-button .ribbon-chevron { stroke-width: 1.6; }
.command-menu-item .menu-chevron { stroke-width: 1.8; }
.ribbon-button:hover .ribbon-chevron,
.ribbon-button:focus-visible .ribbon-chevron,
.ribbon-button[aria-expanded="true"] .ribbon-chevron,
.command-menu-item:hover .menu-chevron,
.command-menu-item:focus-visible .menu-chevron,
.command-menu-item[aria-expanded="true"] .menu-chevron {
  color: var(--color-text);
}
.ribbon-label { white-space: nowrap; }
.ribbon-state { color: var(--color-text-muted); font-size: 12px; }
.ribbon-state:empty { display: none; }
.ribbon-segmented {
  display: flex;
  align-items: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.ribbon-segmented button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 36px;
  padding: 4px 9px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--color-text-secondary);
  font-size: 12px;
}
.ribbon-segmented button + button { border-left: 1px solid var(--color-border); }
.ribbon-segmented button[aria-pressed="true"] { background: var(--color-primary); color: var(--color-text); }
.ribbon-segmented button:focus-visible { outline: 2px solid var(--color-accent); outline-offset: -2px; }
.ribbon-segmented button[aria-disabled="true"] { cursor: not-allowed; }
.preview-toggle button { font-size: 14px; }
.preview-toggle button[aria-pressed="true"] { color: var(--color-text); }
.ribbon-segmented button svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.ribbon-segmented button span { white-space: nowrap; }
.selection-mode-group { flex: none; }
.keyboard-selection {
  margin: var(--space-2) 0;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}
.keyboard-selection legend { padding: 0 var(--space-1); color: var(--color-text-secondary); font-size: 13px; }
.keyboard-selection .hint { margin: var(--space-1) 0 0; }
.ribbon-pinned {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 4px 9px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text-secondary);
  font-size: 12px;
}
.ribbon-pinned:hover,
.ribbon-pinned:active { background: var(--color-surface-hover); border-color: var(--color-border); color: var(--color-text); }
.ribbon-pinned svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.ribbon-pinned.danger { color: var(--color-danger); }
.ribbon-pinned[aria-disabled="true"],
.ribbon-pinned:disabled { opacity: .42; cursor: not-allowed; }

.command-menu {
  position: fixed;
  z-index: 45;
  min-width: 240px;
  max-width: min(360px, calc(100vw - 16px));
  max-height: calc(100vh - 16px);
  overflow-y: auto;
  padding: 4px;
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-overlay);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.command-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 7px 9px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text);
  font-size: 13px;
  text-align: left;
}
.command-menu-item:hover:not([aria-disabled="true"]),
.command-menu-item:focus-visible,
.command-menu-item:not([aria-disabled="true"]):active { background: var(--color-surface-hover); }
.command-menu-item[aria-disabled="true"] { opacity: .58; cursor: not-allowed; }
.command-menu-item .menu-icon { display: grid; place-items: center; width: 18px; height: 18px; flex: none; color: var(--color-text-secondary); }
.command-menu-item .menu-icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.command-menu-item[aria-pressed="true"] .menu-icon { color: var(--color-accent); }
.command-menu-item .menu-label { flex: 1; min-width: 0; }
.command-menu-item .menu-shortcut { margin-left: auto; color: var(--color-text-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.command-menu-row { display: flex; align-items: center; gap: 2px; }
.command-menu-row .command-menu-item { flex: 1; min-width: 0; }
.command-menu-pin {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: none;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-muted);
  opacity: .38;
}
.command-menu-row:hover .command-menu-pin,
.command-menu-row:focus-within .command-menu-pin,
.command-menu-pin[aria-checked="true"] { opacity: 1; }
.command-menu-pin:hover,
.command-menu-pin:focus-visible { background: var(--color-surface-hover); color: var(--color-text); }
.command-menu-pin[aria-checked="true"] { color: var(--color-accent); }
.command-menu-pin .pin-icon { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.command-menu-pin[aria-checked="true"] .pin-icon { fill: currentColor; }
.ribbon-pinned-commands {
  display: flex;
  align-items: center;
  gap: 2px;
  padding-left: var(--space-1);
  margin-left: var(--space-1);
  border-left: 1px solid var(--color-border);
}
.ribbon-pinned-commands[hidden] { display: none !important; }
.ribbon-pinned-command { width: 40px; min-width: 40px; padding: 0; justify-content: center; }
.ribbon-pinned-command[aria-disabled="true"] { opacity: .42; cursor: not-allowed; }
.ribbon-pinned-command[aria-pressed="true"] { border-color: var(--color-primary); background: var(--color-surface-hover); color: var(--color-text); }
.command-menu-heading { padding: 8px 9px 3px; color: var(--color-text-muted); font-size: 11px; }
.command-menu-sep { height: 1px; margin: 4px 6px; background: var(--color-border); }

.context-menu {
  position: fixed;
  z-index: 40;
  min-width: 220px;
  max-width: min(320px, calc(100vw - 16px));
  max-height: calc(100vh - 16px);
  overflow-x: hidden;
  overflow-y: auto;
  padding: var(--space-1);
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-overlay);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.context-menu[hidden] { display: none; }
.context-menu button {
  min-height: 40px;
  padding: 6px 10px;
  border: 0;
  background: transparent;
  border-radius: var(--radius-sm);
  text-align: left;
  font-size: 13px;
}
.context-menu button:hover:not(:disabled):not([aria-disabled="true"]),
.context-menu button:focus-visible:not([aria-disabled="true"]) { background: var(--color-surface-hover); }

.node-tools { display: grid; gap: var(--space-2); margin-top: var(--space-2); }
.node-edit-actions { flex-wrap: wrap; }

.shape-library { overflow-y: auto; padding: 0 var(--space-4) var(--space-4); }
.image-import { padding: 0 var(--space-4) var(--space-3); }
.image-import button { width: 100%; }
.image-import .hint { margin-top: var(--space-2); }
.shape-category { padding-top: var(--space-3); border-top: 1px solid var(--color-border); margin-top: var(--space-3); }
.shape-category:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.category-heading { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-2); margin-bottom: var(--space-2); }
.category-heading h3 { margin: 0; font-size: 13px; font-weight: 600; }
.category-count { color: var(--color-text-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.shape-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2); }
.shape-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 100px;
  padding: 8px 6px;
  color: var(--color-text-secondary);
  font-size: 14px;
  line-height: 1.25;
  text-align: center;
}
.shape-item svg { width: 38px; height: 38px; color: var(--color-text); }
.shape-item:hover:not(:disabled) svg { color: var(--color-accent); }

.stage-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
}
.stage-bar h2 { margin: 0; }
.stage-meta { display: flex; align-items: center; gap: var(--space-2); color: var(--color-text-muted); font-size: 12px; }
.stage-node-status { padding-left: var(--space-2); border-left: 1px solid var(--color-border-strong); color: var(--color-text-secondary); font-variant-numeric: tabular-nums; }
.stage-sep { width: 1px; height: 14px; background: var(--color-border-strong); }
.tool-hint { margin: 0; padding: 0 var(--space-4) var(--space-2); color: var(--color-text-muted); font-size: 12px; line-height: 1.45; }
.stage-view { display: inline-flex; align-items: center; gap: var(--space-1); flex-wrap: nowrap; min-width: 0; }
.stage-view button { min-width: 40px; min-height: 40px; padding: 4px 8px; font-size: 14px; }
.zoom-label { color: var(--color-text-muted); font-size: 12px; margin-right: 2px; }
.zoom-level {
  flex: 0 0 66px;
  width: 66px;
  min-height: 40px !important;
  padding: 4px 6px !important;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.zoom-suffix { color: var(--color-text-muted); font-size: 12px; }
@media (max-width: 1360px) { .zoom-label { display: none; } }
.stage-area {
  flex: 1;
  min-height: 0;
  padding: var(--space-4);
  overflow: hidden;
}
.stage-grid {
  height: 100%;
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  grid-template-rows: 26px minmax(0, 1fr);
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.ruler-corner {
  display: grid;
  place-items: center;
  border-right: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}
.ruler { background: var(--color-surface-raised); overflow: hidden; }
.ruler-x { border-bottom: 1px solid var(--color-border); cursor: ns-resize; }
.ruler-y { border-right: 1px solid var(--color-border); cursor: ew-resize; }
.ruler svg { display: block; width: 100%; height: 100%; }
.ruler-tick { stroke: var(--color-text-muted); stroke-width: 1; vector-effect: non-scaling-stroke; }
.ruler-tick.major { stroke: var(--color-text-secondary); }
.ruler-label { fill: var(--color-text-muted); font: 9px var(--font-sans); }
.stage-wrap {
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: stretch;
  overflow: hidden;
}
#stage { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; }
#stage[data-space-pan="true"] { cursor: grab; }
#stage[data-space-pan="true"]:active { cursor: grabbing; }
#stage .guide { stroke: var(--color-accent); stroke-width: 1; vector-effect: non-scaling-stroke; pointer-events: none; }
#stage .guide.is-selected { stroke: var(--color-primary); stroke-width: 2; }
#stage .guide-hit { stroke: transparent; stroke-width: 12; vector-effect: non-scaling-stroke; pointer-events: stroke; cursor: ew-resize; }
#stage .guide-hit[data-guide-axis="y"] { cursor: ns-resize; }
#stage .artboard { fill: var(--color-preview-bg); stroke: var(--color-preview-grid); stroke-width: .6; }
#stage .grid-line { stroke: var(--color-preview-grid); stroke-width: .18; opacity: .75; }
#stage .node-cut:not(.node-styled) { fill: none; stroke: var(--color-preview-cut); stroke-width: 1.5; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
#stage .node-draw:not(.node-styled) { fill: none; stroke: var(--color-accent); stroke-width: 1.5; stroke-dasharray: 5 3; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
#stage .node-draw.node-styled { fill: none; stroke: var(--color-accent); stroke-width: 1.5; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
#stage .preview-cut { fill: none; stroke: var(--color-preview-cut); stroke-width: 1.5; stroke-linejoin: round; vector-effect: non-scaling-stroke; pointer-events: none; }
#stage .preview-draw { fill: none; stroke: var(--color-accent); stroke-width: 1.5; stroke-linejoin: round; vector-effect: non-scaling-stroke; pointer-events: none; }
#stage .preview-highlight { fill: none; stroke: var(--color-warning); stroke-width: 5; stroke-linejoin: round; opacity: .5; vector-effect: non-scaling-stroke; pointer-events: none; }
#stage .preview-missing-frame { fill: none; stroke: var(--color-warning); stroke-width: 1.2; stroke-dasharray: 4 2; vector-effect: non-scaling-stroke; }
#stage .preview-missing-text .node-text { fill: var(--color-warning); }
#stage .preview-missing-text .node-cut.node-text,
#stage .preview-missing-text .node-draw.node-text { fill: var(--color-warning); }
#stage .preview-error { fill: var(--color-danger); font-size: 5px; }
#stage[data-preview="true"] { cursor: default; }
#stage .node-text { font-family: var(--font-sans); }
#stage .node-cut.node-text { fill: var(--color-preview-cut); stroke: none; }
#stage .node-draw.node-text { fill: var(--color-accent); stroke: none; }
#stage .node-image { pointer-events: all; }
#stage .node-image-placeholder { fill: none; stroke: var(--color-text-muted); stroke-width: 1.2; stroke-dasharray: 5 4; vector-effect: non-scaling-stroke; }
#stage .node-label { fill: var(--color-text-muted); font-size: 4px; }
#stage .node-group[data-locked="true"] { pointer-events: none; opacity: .65; }
#stage .node-group { cursor: grab; }
#stage .node-group:active { cursor: grabbing; }
#stage .node-group:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
#stage .node-cut, #stage .node-draw, #stage .node-image-placeholder, #stage .node-text { pointer-events: all; }
#stage .selection-box { fill: none; stroke: var(--color-primary); stroke-width: 1.4; stroke-dasharray: 6 4; vector-effect: non-scaling-stroke; pointer-events: none; }
#stage .draft-rubber { stroke: var(--color-accent); stroke-width: .8; stroke-dasharray: 2 2; vector-effect: non-scaling-stroke; }
#stage .draft-handle { stroke: var(--color-accent); stroke-width: .8; vector-effect: non-scaling-stroke; }
#stage .draft-control { fill: var(--color-accent); stroke: none; }
#stage .selection-handle { fill: var(--color-primary); stroke: var(--color-bg); stroke-width: .5; pointer-events: none; }
#stage .selection-frame { fill: none; stroke: var(--color-primary); stroke-width: 1.2; stroke-dasharray: 6 4; vector-effect: non-scaling-stroke; pointer-events: none; }
#stage .frame-handle { fill: var(--color-primary); stroke: var(--color-bg); stroke-width: 1; vector-effect: non-scaling-stroke; pointer-events: all; }
#stage .frame-handle:hover, #stage .frame-handle:focus-visible { fill: var(--color-accent); }
#stage .frame-rotate { fill: var(--color-accent); }
#stage .frame-rotate-line { stroke: var(--color-primary); stroke-width: 1; vector-effect: non-scaling-stroke; pointer-events: none; }
#stage .frame-handle[data-cursor="nwse-resize"] { cursor: nwse-resize; }
#stage .frame-handle[data-cursor="nesw-resize"] { cursor: nesw-resize; }
#stage .frame-handle[data-cursor="ew-resize"] { cursor: ew-resize; }
#stage .frame-handle[data-cursor="ns-resize"] { cursor: ns-resize; }
#stage .frame-handle[data-cursor="grab"] { cursor: grab; }
#stage .snap-guide { stroke: var(--color-accent); stroke-width: 1; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; pointer-events: none; }
#stage .drag-readout rect { fill: var(--color-surface); stroke: var(--color-border-strong); stroke-width: 1; vector-effect: non-scaling-stroke; }
#stage .drag-readout text { fill: var(--color-text); font-family: var(--font-sans); font-variant-numeric: tabular-nums; pointer-events: none; }
#stage .control-line { stroke: var(--color-text-muted); stroke-width: 1; vector-effect: non-scaling-stroke; pointer-events: none; }
#stage .control-point { fill: var(--color-surface); stroke: var(--color-accent); stroke-width: 1; vector-effect: non-scaling-stroke; pointer-events: none; }
#stage .control-point.is-selected { fill: var(--color-accent); stroke: var(--color-text); }
#stage .control-target { fill: transparent; stroke: none; cursor: grab; pointer-events: all; }
#stage .control-target:active { cursor: grabbing; }
#stage[data-tool="path"], #stage[data-tool="freehand"], #stage[data-tool="text"] { cursor: crosshair; }
#stage .draft-line { fill: none; stroke: var(--color-primary); stroke-width: 1.4; stroke-dasharray: 5 3; stroke-linejoin: round; vector-effect: non-scaling-stroke; pointer-events: none; }
#stage .draft-node { fill: var(--color-surface); stroke: var(--color-primary); stroke-width: .5; pointer-events: none; }
#stage .draft-node.is-last { fill: var(--color-accent); stroke: var(--color-accent); }
#stage .draft-start-ring { fill: none; stroke: var(--color-accent); stroke-width: 1.6; stroke-dasharray: 3 2; vector-effect: non-scaling-stroke; pointer-events: none; }
#stage .path-node-target { fill: transparent; stroke: none; cursor: grab; pointer-events: all; }
#stage .path-node-target:active { cursor: grabbing; }
#stage .path-node-target:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
#stage .path-node { fill: var(--color-preview-bg); stroke: var(--color-primary); stroke-width: 1; pointer-events: none; }
#stage .path-node.is-start,
#stage .path-node.is-end { stroke: var(--color-accent); }
#stage .path-node.is-selected { fill: var(--color-primary); stroke: var(--color-text); stroke-width: 1.6; }
#stage .node-group.is-locked { cursor: not-allowed; }
#stage[data-node-edit="false"] .node-group.is-selected[data-node-type="path"],
#stage[data-node-edit="false"] .node-group.is-selected[data-node-type="folder"] {
  filter: drop-shadow(0 0 1px var(--color-accent)) drop-shadow(0 0 3px var(--color-glow));
}
#stage .selected-segment {
  fill: none;
  stroke: var(--color-accent);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: .55;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}
#stage .node-marquee,
#stage .selection-marquee,
#stage .selection-lasso,
#stage .selection-polygon {
  fill: var(--color-glow);
  stroke: var(--color-accent);
  stroke-width: 1;
  stroke-dasharray: 4 3;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}
#stage .selection-marquee,
#stage .selection-lasso,
#stage .selection-polygon {
  stroke-width: 1.2;
  stroke-dasharray: 5 3;
  filter: drop-shadow(0 0 3px var(--color-glow));
}
#stage .selection-polygon-point { fill: var(--color-accent); stroke: var(--color-surface); stroke-width: 1; vector-effect: non-scaling-stroke; pointer-events: none; }
#stage .selection-rubber { stroke: var(--color-accent); stroke-width: 1; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; pointer-events: none; }
#stage .selection-start-ring { fill: none; stroke: var(--color-accent); stroke-width: 1.6; stroke-dasharray: 3 2; vector-effect: non-scaling-stroke; pointer-events: none; }
#stage[data-tool="select"][data-selection-mode="lasso"],
#stage[data-tool="select"][data-selection-mode="polygon"] { cursor: crosshair; }
#stage[data-tool="node"][data-segment-hover="select"] { cursor: pointer; }
#stage[data-tool="node"][data-segment-hover="insert"] { cursor: copy; }
#stage .segment-insert-hint circle { fill: var(--color-surface); stroke: var(--color-accent); stroke-width: 1.4; vector-effect: non-scaling-stroke; pointer-events: none; }
#stage .segment-insert-hint path { stroke: var(--color-accent); stroke-width: 1.4; stroke-linecap: round; vector-effect: non-scaling-stroke; pointer-events: none; }
#stage .segment-insert-hint .segment-select-dot { fill: var(--color-accent); stroke: none; pointer-events: none; }
#stage .path-preview { fill: none; stroke: var(--color-accent); stroke-width: 1.6; stroke-dasharray: 5 4; stroke-linejoin: round; vector-effect: non-scaling-stroke; pointer-events: none; }
#stage[data-tool="node"] { cursor: crosshair; }

.notice {
  margin: 0 var(--space-4) var(--space-4);
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-raised);
  color: var(--color-text-secondary);
  font-size: 13px;
}
.notice[data-tone="success"] { color: var(--color-success); border-color: var(--color-success); }
.notice[data-tone="warning"] { color: var(--color-warning); border-color: var(--color-warning); }
.notice[data-tone="danger"] { color: var(--color-danger); border-color: var(--color-danger); }

.empty-state { margin: 0; padding: var(--space-4); color: var(--color-text-muted); font-size: 13px; }
.transform-panel { padding: 0 var(--space-4) var(--space-4); }
.selection-summary { margin: 0 0 var(--space-3); color: var(--color-text-secondary); font-size: 13px; }
fieldset { margin: 0 0 var(--space-4); padding: var(--space-3); border: 1px solid var(--color-border); border-radius: var(--radius-md); }
legend { padding: 0 4px; color: var(--color-text-secondary); font-size: 12px; font-weight: 600; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
.field { display: grid; gap: 4px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field-label { color: var(--color-text-secondary); font-size: 13px; }
.dash-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-2); }
.dash-fields .field { gap: 2px; font-size: 12px; color: var(--color-text-muted); }
.dash-fields input { width: 100%; }
.color-row { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.color-row input[type="color"], .field input[type="color"] {
  width: 100%;
  min-width: 64px;
  height: 34px;
  padding: 2px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-surface-raised);
}
.color-row input[type="color"] { width: 72px; flex: none; }
.check-row.compact { margin-top: 0; font-size: 12px; }
.field .unit-label, .unit-fixed { color: var(--color-text-muted); font-weight: 400; }
.field:only-child { grid-column: 1 / -1; }
.check-row { display: flex; align-items: center; gap: var(--space-2); margin-top: var(--space-3); cursor: pointer; }
.mirror-group { margin-top: var(--space-3); }
.mirror-group button { flex: 1 1 130px; font-size: 13px; }
.freeze-block { padding: var(--space-3); margin-bottom: var(--space-4); border: 1px dashed var(--color-border-strong); border-radius: var(--radius-md); }
.freeze-block button { margin-top: var(--space-2); width: 100%; }
.node-edit-actions { margin-top: var(--space-2); }
.node-edit-actions button { flex: 1 1 130px; width: auto; }
.text-actions { margin-top: var(--space-3); }
.text-actions button { flex: 1 1 150px; }
.overlap-group button { flex: 1 1 135px; }
.dialog-actions { justify-content: flex-end; margin-top: var(--space-4); }
.layers-block { margin: 0 var(--space-4) var(--space-4); padding-top: var(--space-3); border-top: 1px solid var(--color-border); }
.layers-block .panel-heading.compact { padding: 0 0 var(--space-2); }
.layer-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-1); }
.layer-list .layer-row { display: flex; align-items: center; gap: var(--space-2); min-width: 0; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.layer-item { min-width: 0; }
.layer-row.is-selected { background: var(--color-glow); box-shadow: inset 3px 0 0 var(--color-accent); }
.layer-disclosure {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  min-height: 24px;
  padding: 0;
  flex: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-muted);
}
.layer-disclosure:hover { background: var(--color-surface-hover); color: var(--color-text); }
.layer-disclosure svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; transition: transform 140ms var(--ease-standard); }
.layer-disclosure[aria-expanded="true"] svg { transform: rotate(90deg); }
.layer-item.is-collapsed > .layer-row { margin-bottom: 0; }
.layer-row.is-dragging { opacity: .45; }
.layer-row.drop-before { box-shadow: inset 0 3px 0 var(--color-accent); }
.layer-row.drop-after { box-shadow: inset 0 -3px 0 var(--color-accent); }
.layer-row.drop-inside { background: var(--color-glow); outline: 1px solid var(--color-accent); outline-offset: -1px; }
.layer-row.drop-group { background: var(--color-glow); outline: 1px solid var(--color-primary); outline-offset: -1px; }
.layer-drop-root {
  margin-top: var(--space-2);
  padding: var(--space-2);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font-size: 12px;
  text-align: center;
}
.layer-drop-root[hidden] { display: none; }
.layer-drop-root.drop-root { border-color: var(--color-accent); color: var(--color-accent); background: var(--color-glow); }
.layer-list > li > .layer-row > button[data-layer-id],
.layer-children > li > .layer-row > button[data-layer-id] {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: 1 1 auto;
  min-width: 0;
  width: auto;
  min-height: 40px;
  padding: 4px 8px;
  border-color: transparent;
  background: transparent;
  text-align: left;
  font-size: 14px;
  color: var(--color-text-secondary);
}
.layer-list button:hover:not(:disabled) { background: var(--color-surface-hover); border-color: var(--color-border); }
.layer-list button[aria-current="true"] { color: var(--color-text); background: transparent; border-color: transparent; font-weight: 600; }
.layer-selected-mark { color: var(--color-accent); font-size: 12px; font-weight: 700; margin-right: var(--space-1); }
.layer-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}
.layer-rename {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  padding: 4px 8px;
  border: 1px solid var(--color-accent);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  font-size: 14px;
}
.layer-list .layer-kind { flex: none; color: var(--color-text-muted); font-size: 12px; }
.layer-actions { display: flex; gap: 2px; margin-left: auto; flex: none; }
.layer-list button[data-layer-id] {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-align: left;
}
.layer-list .layer-action {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  min-height: 26px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-muted);
}
.layer-list .layer-action svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.layer-list .layer-action:hover:not(:disabled) { color: var(--color-text); background: var(--color-surface-hover); }
.layer-list .layer-action[aria-pressed="true"] { color: var(--color-primary); }
.layer-list .layer-action[aria-pressed="false"] { opacity: .55; }
.layer-children { min-width: 0; margin: 0 0 0 var(--space-4); padding-left: var(--space-2); border-left: 1px solid var(--color-border); }
.layer-children > li { min-width: 0; }

dialog {
  width: min(520px, calc(100vw - 32px));
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-dialog);
}
dialog::backdrop { background: var(--color-overlay); }
dialog h2 { margin-bottom: var(--space-2); }
.offset-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); margin-top: var(--space-3); }
dialog .notice { margin: 0 0 var(--space-3); }

/* Schnittvorschau */
.preview-badge {
  padding: 2px var(--space-2);
  border: 1px solid var(--color-primary);
  border-radius: 999px;
  color: var(--color-primary);
  font-size: 12px;
  font-weight: 600;
}
.preview-panel { display: flex; flex-direction: column; min-height: 100%; }
.preview-panel-body { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.preview-status { margin: 0 var(--space-4) var(--space-3); }
.preview-summary { margin: 0 var(--space-4) var(--space-3); color: var(--color-text-secondary); font-size: 13px; }
.preview-summary p { margin: 0 0 var(--space-1); }
.preview-details { display: grid; gap: var(--space-2); padding: 0 var(--space-4) var(--space-4); }
.preview-detail { border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--color-surface-raised); }
.preview-detail > summary {
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  min-height: 40px;
  display: flex;
  align-items: center;
}
.preview-detail > summary:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
.preview-detail.is-danger { border-color: var(--color-danger); }
.preview-detail.is-warning { border-color: var(--color-warning); }
.preview-detail-list { list-style: none; margin: 0; padding: 0 var(--space-3) var(--space-2); display: grid; gap: var(--space-1); font-size: 13px; }
.preview-detail-list li { min-width: 0; color: var(--color-text-secondary); }
.preview-order-heading { margin-top: var(--space-2); color: var(--color-text-muted); font-size: 12px; font-weight: 600; }
.preview-order-heading:first-child { margin-top: 0; }
.preview-detail .hint { padding: 0 var(--space-3) var(--space-2); }
.preview-object {
  display: block;
  width: 100%;
  min-height: 40px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 13px;
  text-align: left;
  overflow-wrap: anywhere;
}
.preview-object:hover { background: var(--color-surface-hover); }
.preview-object[aria-pressed="true"] { border-color: var(--color-warning); box-shadow: inset 3px 0 0 var(--color-warning); }
.preview-highlight-note { padding: 0 var(--space-4) var(--space-2); }
.preview-footer {
  position: sticky;
  bottom: 0;
  z-index: 1;
  display: grid;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
}
.preview-footer .hint { margin: 0; }
.preview-footer .button-group { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.preview-footer button { min-height: 40px; }
body[data-preview="true"] .tool-rail,
body[data-preview="true"] .tool-panel { opacity: .55; }
body[data-preview="true"] #context-bar button:not([data-preview-toggle]) { opacity: .55; cursor: not-allowed; }
.preview-action-reason { align-self: center; margin-left: var(--space-2); color: var(--color-warning); font-size: 12px; white-space: nowrap; }
@media (max-width: 720px) {
  .preview-footer .button-group { flex-direction: column; }
  .preview-footer button { width: 100%; }
}

/* Tastatur-Dialog */
#keyboard-dialog { width: min(560px, calc(100vw - 32px)); }
.keyboard-roles {
  display: grid;
  grid-template-columns: minmax(150px, auto) minmax(0, 1fr);
  gap: var(--space-2) var(--space-4);
  align-items: start;
  margin: var(--space-4) 0;
}
.keyboard-roles .field { min-width: 150px; }
.keyboard-roles .hint { margin: 0; padding-top: 8px; }
.keyboard-preview {
  margin: 0 0 var(--space-3);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-raised);
  color: var(--color-text-secondary);
  font-size: 13px;
}

.command-tooltip {
  position: fixed;
  z-index: 100;
  max-width: 320px;
  padding: 7px 10px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-surface-raised);
  color: var(--color-text);
  font-size: 12px;
  line-height: 1.4;
  box-shadow: var(--shadow-dialog);
  pointer-events: none;
}
.command-tooltip[hidden] { display: none; }
.command-tooltip-title { font-size: 13px; }
.command-tooltip-title strong { font-weight: 600; }
.command-tooltip-description { margin-top: 4px; color: var(--color-text-secondary); font-size: 12px; line-height: 1.45; }

/* Nachzeichnen-Dialog */
#trace-dialog { width: min(760px, calc(100vw - 32px)); }
.trace-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-6) var(--space-4);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-lg);
  background: var(--color-surface-raised);
  text-align: center;
}
.trace-drop.is-over { border-color: var(--color-primary); background: var(--color-surface-hover); }
.trace-drop:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
.trace-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 240px;
  gap: var(--space-4);
  margin-top: var(--space-3);
  align-items: start;
}
.trace-preview {
  width: 100%;
  max-height: 46vh;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-preview-bg);
}
.trace-controls { display: flex; flex-direction: column; gap: var(--space-2); }
@media (max-width: 720px) {
  .trace-body { grid-template-columns: 1fr; }
}
#stage .offset-preview { fill: none; stroke: var(--color-accent); stroke-width: 1.4; stroke-dasharray: 6 4; stroke-linejoin: round; vector-effect: non-scaling-stroke; pointer-events: none; }

@media (max-width: 1180px) {
  body { display: block; }
  .panel-resizer { display: none; }
  .workspace {
    grid-template-columns: 48px 210px minmax(320px, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas: "tools panel stage" "properties properties properties";
    min-height: calc(100dvh - 66px);
  }
  .stage-panel { min-height: 460px; }
  .properties-panel { max-height: none; }
  .transform-panel { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); align-items: start; }
  .transform-panel .selection-summary, .transform-panel .freeze-block { grid-column: 1 / -1; }
}

@media (max-width: 820px) {
  .app-header { align-items: stretch; flex-direction: column; }
  .brand { min-width: 0; }
  .header-actions { justify-content: flex-start; }
  .project-name { width: min(100%, 260px); }
  .workspace {
    grid-template-columns: 48px minmax(0, 1fr);
    grid-template-rows: auto minmax(420px, 1fr) auto;
    grid-template-areas: "tools panel" "stage stage" "properties properties";
  }
  .tool-panel { max-height: 340px; }
  .properties-panel { grid-template-columns: minmax(0, 1fr) 44px; }
  .shape-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stage-area { padding: var(--space-2); }
  .transform-panel { display: block; }
}

@media (max-width: 480px) {
  .shape-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-grid { grid-template-columns: 1fr; }
  .dash-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .offset-fields { grid-template-columns: 1fr; }
  .header-actions > * { flex: 1 1 auto; }
  .project-name { flex-basis: 100%; }
}

/* Schriftbibliothek */
#font-library-dialog { width: min(880px, calc(100vw - 32px)); max-height: min(88vh, 900px); }
#font-library-dialog .font-library { display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; }
.font-library-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); }
.font-library-head h2 { margin: 0; }
.font-library-filters { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-2); }
.font-library-filters .full { grid-column: 1 / -1; }
.font-library-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); overflow-y: auto; max-height: min(52vh, 520px); }
.font-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--space-3); padding: var(--space-3); border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--color-surface-raised); }
.font-card-body { min-width: 0; display: grid; gap: 2px; }
.font-card-name { margin: 0; font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.font-card-meta { margin: 0; color: var(--color-text-muted); font-size: 12px; overflow-wrap: anywhere; }
.font-card-tags { display: flex; flex-wrap: wrap; gap: 4px; margin: 2px 0 0; }
.font-tag { border: 1px solid var(--color-border); border-radius: 999px; padding: 1px 7px; font-size: 11px; color: var(--color-text-secondary); }
.font-card-actions { display: flex; flex-direction: column; align-items: flex-end; justify-content: center; gap: var(--space-2); }
.font-status { font-size: 12px; color: var(--color-text-muted); white-space: nowrap; }
.font-status.is-bundled { color: var(--color-text-secondary); }
.font-status.is-project { color: var(--color-accent); }
.font-library-upload { border-top: 1px solid var(--color-border); padding-top: var(--space-3); }
.font-library-upload h3 { margin: 0 0 var(--space-1); font-size: 14px; }
@media (max-width: 720px) {
  .font-library-filters { grid-template-columns: 1fr 1fr; }
  .font-card { grid-template-columns: 1fr; }
  .font-card-actions { flex-direction: row; justify-content: flex-start; align-items: center; }
}
@media (max-width: 440px) {
  .font-library-filters { grid-template-columns: 1fr; }
}

/* Bibliotheksbereiche */
.library-areas { display: flex; gap: 4px; padding: 3px; border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--color-surface-raised); }
.library-area-tab { flex: 1 1 0; min-width: 0; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--color-text-secondary); padding: 6px 8px; font: inherit; font-size: 13px; cursor: pointer; }
.library-area-tab:hover { background: var(--color-surface-hover); color: var(--color-text); }
.library-area-tab[aria-selected="true"] { background: var(--color-primary); color: var(--color-text); }
.library-area-hint { margin: 0; }

/* Bibliothekssuche */
.library-filters { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 150px); gap: var(--space-2); }
.library-filters input, .library-filters select { min-width: 0; }
.library-results { display: grid; gap: var(--space-3); }
.shape-category-label { display: block; font-size: 10px; color: var(--color-text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 480px) {
  .library-filters { grid-template-columns: 1fr; }
}

/* Rahmeneditor */
#frame-editor-dialog { width: min(980px, calc(100vw - 32px)); max-height: min(92vh, 940px); }
.frame-editor { display: grid; gap: var(--space-3); min-width: 0; }
.frame-editor-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); }
.frame-editor-head h2 { margin: 0; }
.frame-editor-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(240px, 0.7fr); gap: var(--space-4); min-width: 0; }
.frame-editor-cell { display: grid; gap: var(--space-2); min-width: 0; }
.frame-editor-tools { display: flex; flex-wrap: wrap; gap: 4px; }
.frame-editor-tools button[aria-pressed="true"] { border-color: var(--color-primary); color: var(--color-text); background: var(--color-surface-hover); }
.frame-cell-editor { width: 100%; aspect-ratio: 2 / 1; min-height: 220px; border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--color-preview-bg); touch-action: none; }
.frame-preview { width: 100%; aspect-ratio: 2 / 1; min-height: 100px; border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--color-preview-bg); }
.frame-editor-preview { display: grid; gap: var(--space-2); align-content: start; min-width: 0; }
.frame-editor-preview h3 { margin: 0; font-size: 14px; }
@media (max-width: 760px) {
  .frame-editor-grid { grid-template-columns: 1fr; }
  .frame-editor-preview { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .frame-editor-preview { grid-template-columns: 1fr; }
}

/* Projekteigenschaften */
.project-font-list { list-style: none; margin: 0 0 var(--space-3); padding: 0; display: grid; gap: var(--space-1); }
.project-font-list li { display: flex; justify-content: space-between; gap: var(--space-3); border-bottom: 1px solid var(--color-border); padding: 4px 0; font-size: 13px; }
.project-font-list small { color: var(--color-text-muted); }
.shape-template-label { display: inline-block; margin-top: 2px; font-size: 10px; color: var(--color-accent); }
.font-library-more { display: flex; justify-content: center; }
.font-library-more button[hidden] { display: none; }
.font-card-preview { margin: 2px 0 4px; font-size: 22px; line-height: 1.25; color: var(--color-text); overflow-wrap: anywhere; }
.font-card-preview.is-fallback { font-size: 12px; color: var(--color-text-muted); font-style: italic; }
.font-card-link { display: inline-block; margin-top: 4px; font-size: 12px; color: var(--color-accent); text-decoration: none; }
.font-card-link:hover, .font-card-link:focus-visible { text-decoration: underline; }
.shape-item.is-frame-preview { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: var(--space-2); text-align: left; }
.shape-item.is-frame-preview svg { width: 100%; height: auto; aspect-ratio: 5 / 1; min-width: 0; }
.shape-item.is-frame-preview > span { font-size: 12px; }
.shape-item.is-frame-preview .shape-category-label { display: none; }
