:root {
  --color-bg: #f7f5f2;
  --color-bg-elevated: #ffffff;
  --color-ink: #1a1a1a;
  --color-ink-muted: #5c5a56;
  --color-stone: #8a867f;
  --color-line: #e4e0d8;
  --color-accent: #0a8f9e;
  --color-accent-hover: #087a87;
  --color-accent-wash: rgba(10, 143, 158, 0.08);
  --color-warn: #b3552f;
  --color-warn-wash: rgba(179, 85, 47, 0.08);
  --font-display: "Fraunces", "Times New Roman", serif;
  --font-body: "DM Sans", "Helvetica Neue", sans-serif;
  --radius: 0.25rem;
}

* { box-sizing: border-box; }

.hidden { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--color-bg);
  color: var(--color-ink);
  font-family: var(--font-body);
}

/* Full-height flex column: the topbar takes whatever height it wraps to and
   the layout adapts to the browser window instead of assuming a fixed height. */
body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.topbar { flex: 0 0 auto; }

a { color: var(--color-accent); }
a:hover { color: var(--color-accent-hover); }

.topbar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.75rem;
  background: var(--color-bg-elevated);
  border-bottom: 1px solid var(--color-line);
  flex-wrap: wrap;
}

.topbar .brand-mark {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  margin-right: 0.5rem;
}

.brand-dot {
  color: var(--color-accent);
}

.topbar input[type="text"], .topbar select {
  padding: 0.35rem 0.5rem;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  color: var(--color-ink);
  font-family: var(--font-body);
}

.topbar .spacer { flex: 1; }

button, select {
  padding: 0.4rem 0.75rem;
  background: var(--color-accent);
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: #fff;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.85rem;
}

button.secondary { background: transparent; color: var(--color-ink); border-color: var(--color-line); }
button.secondary:hover { background: var(--color-accent-wash); border-color: var(--color-ink); }
button.danger { background: transparent; color: var(--color-warn); border-color: var(--color-line); }
button.danger:hover { background: var(--color-warn-wash); border-color: var(--color-warn); }
button:hover { background: var(--color-accent-hover); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

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

/* Topbar dropdown menus (Canvas / Reference / Fonts / Data) */
.menu { position: relative; }
.menu-btn { white-space: nowrap; }
.menu-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 300px;
  max-height: 72vh;
  overflow-y: auto;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  padding: 0.75rem;
  z-index: 200;
  box-shadow: 0 12px 36px rgba(26, 22, 18, 0.16);
  display: none;
}
.menu.open .menu-panel { display: block; }
.menu-panel h4 {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-stone);
  font-weight: 500;
}
.menu-panel .field-row label { flex-basis: 76px; }
.menu-panel .layers-list li { padding-left: 0.25rem; }

/* Layers sidebar (right side) */
.layers-sidebar {
  width: 300px;
  background: var(--color-bg);
  border-left: 1px solid var(--color-line);
  padding: 0.75rem;
  overflow-y: auto;
}
.layers-title {
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-stone);
  margin-bottom: 0.25rem;
}
#layers-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

/* Layer rows + dropdown accordion (stacked: layer item ABOVE its panel) */
#layers-list .layer-item {
  display: block;  /* override .layers-list li { display:flex } so the dropdown stacks below the row */
  padding: 0;
  margin-bottom: 2px;
}
.layer-row {
  display: flex;
  width: 100%;
  box-sizing: border-box;
  align-items: center;
  gap: 0.4rem;
  padding: 0.32rem 0.5rem;
  cursor: pointer;
  border-radius: var(--radius);
  font-size: 0.82rem;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-line);
}
.layer-row:hover { background: var(--color-accent-wash); }
.layer-item.open > .layer-row,
.layer-row.active { background: var(--color-accent); border-color: var(--color-accent); color: #fff; }
.layer-row .gicon { flex: 0 0 auto; }
.layer-row .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.layer-row .chev { font-size: 0.6rem; color: var(--color-stone); }
.layer-item.open > .layer-row .chev { color: #fff; }

/* Per-row stacking arrows (↑/↓) — revealed on hover, subdued otherwise */
.layer-row .layer-nav {
  display: inline-flex;
  gap: 1px;
  flex: 0 0 auto;
  opacity: 0;
  transition: opacity 0.12s ease;
}
.layer-row:hover .layer-nav,
.layer-row.active .layer-nav { opacity: 1; }
.layer-row .layer-nav button {
  padding: 0 0.25rem;
  line-height: 1;
  font-size: 0.66rem;
  color: var(--color-stone);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 3px;
  cursor: pointer;
}
.layer-row .layer-nav button:hover {
  color: var(--color-ink);
  border-color: var(--color-line);
  background: var(--color-bg-elevated);
}
.layer-item.open > .layer-row .layer-nav button,
.layer-row.active .layer-nav button { color: #fff; }
.layer-item.open > .layer-row .layer-nav button:hover,
.layer-row.active .layer-nav button:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.35);
}

/* Right-click context menu (canvas objects + layer rows) */
.ctx-menu {
  position: fixed;
  z-index: 20000;
  min-width: 168px;
  padding: 0.3rem;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.18);
  font-size: 0.8rem;
}
.ctx-menu .ctx-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.35rem 0.55rem;
  background: transparent;
  border: none;
  border-radius: 3px;
  color: var(--color-ink);
  cursor: pointer;
  white-space: nowrap;
}
.ctx-menu .ctx-item:hover { background: var(--color-accent-wash); }
.ctx-menu .ctx-item.disabled {
  color: var(--color-stone);
  cursor: default;
  opacity: 0.55;
}
.ctx-menu .ctx-item.disabled:hover { background: transparent; }
.ctx-menu .ctx-sep {
  height: 1px;
  margin: 0.25rem 0.35rem;
  background: var(--color-line);
}
.layer-dropdown {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-line);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 0.5rem;
}
.tabs { display: flex; gap: 0.25rem; margin-bottom: 0.5rem; }
.tabs button {
  flex: 1;
  padding: 0.25rem 0.4rem;
  font-size: 0.72rem;
  background: transparent;
  color: var(--color-ink);
  border: 1px solid var(--color-line);
}
.tabs button.active { background: var(--color-accent); color: #fff; border-color: var(--color-accent); }
.tab-body { max-height: 340px; overflow-y: auto; }
.tab-body .anim-actions { margin-bottom: 0.4rem; }

.tools {
  width: 64px;
  background: var(--color-bg-elevated);
  border-right: 1px solid var(--color-line);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.5rem;
  gap: 0.4rem;
  overflow-y: auto;
}

.tools button {
  width: 48px;
  height: 48px;
  padding: 0;
  font-size: 1.2rem;
  background: var(--color-bg);
  color: var(--color-ink);
  border: 1px solid var(--color-line);
}

.tools button:hover { background: var(--color-accent-wash); }
.tools button.active { background: var(--color-accent); color: #fff; border-color: var(--color-accent); }

.canvas-area {
  flex: 1;
  overflow: hidden;
  /* Plain pasteboard, deliberately NOT checkered — the checker pattern lives
     on #canvas itself (see below) so it's bounded to the true 1920x1080
     frame. When both used the same checker, the workspace and the actual
     canvas were visually indistinguishable: nothing marked where the real
     frame ended and empty scratch space began. */
  background-color: var(--color-bg);
}

.sidebar {
  width: 300px;
  background: var(--color-bg);
  border-left: 1px solid var(--color-line);
  padding: 0.75rem;
  overflow-y: auto;
}

.sidebar h3 {
  margin: 0.75rem 0 0.4rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-stone);
  font-weight: 500;
}

.sidebar h3:first-child { margin-top: 0; }

.field-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.45rem;
}

.field-row label {
  flex: 0 0 84px;
  font-size: 0.82rem;
  color: var(--color-ink-muted);
}

.field-row input[type="text"],
.field-row input[type="number"],
.field-row select {
  flex: 1;
  min-width: 0;
  padding: 0.3rem 0.4rem;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  color: var(--color-ink);
  font-size: 0.82rem;
}

.field-row input[type="color"] {
  width: 36px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
}

.field-row input[type="checkbox"] { flex: 0 0 auto; width: auto; }

.layers-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.82rem;
}

.layers-list li {
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.3rem;
}

.layers-list li:hover { background: var(--color-accent-wash); }
.layers-list li.active { background: var(--color-accent); color: #fff; }
.layers-list li .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layers-list li .badge { font-size: 0.7rem; color: var(--color-accent); }

.empty-hint {
  color: var(--color-stone);
  font-size: 0.82rem;
  padding: 0.5rem 0;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(26, 22, 18, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  padding: 1.25rem;
  max-width: 720px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}

.modal h2 { font-family: var(--font-display); font-weight: 500; margin-top: 0; }

.template-grid {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
}
.design-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.template-card, .design-card {
  background: var(--color-bg);
  border-radius: var(--radius);
  padding: 0.75rem;
  cursor: pointer;
  border: 1px solid var(--color-line);
}

/* Template folders (grouped by sport) */
.tpl-folder { margin-bottom: 0.9rem; }
.tpl-folder-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  padding: 0.45rem 0.6rem;
  color: var(--color-ink);
  font-weight: 500;
  text-transform: capitalize;
}
.tpl-folder-head:hover { background: var(--color-accent-wash); }
/* "User Templates" folder (the org's own saved templates, vs. the sport/Generic
   starter-template folders) — same layout, just visually set apart. */
.tpl-folder.user-folder .tpl-folder-head { border-color: var(--color-accent); text-transform: none; }
.tpl-folder-head .arrow { transition: transform 0.15s; font-size: 0.7rem; }
.tpl-folder.collapsed .tpl-folder-head .arrow { transform: rotate(-90deg); }
.tpl-folder-head .count {
  margin-left: auto;
  font-weight: 400;
  font-size: 0.75rem;
  color: var(--color-stone);
}
.tpl-folder-body {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
  margin-top: 0.6rem;
}
.tpl-folder.collapsed .tpl-folder-body { display: none; }

.template-card:hover, .design-card:hover { border-color: var(--color-accent); }
.template-card .cat { font-size: 0.72rem; color: var(--color-accent); text-transform: uppercase; letter-spacing: 0.04em; }
.template-card .sport, .design-card .sport { font-size: 0.75rem; color: var(--color-stone); }

.hint { color: var(--color-stone); font-size: 0.8rem; margin: 0.25rem 0 0.5rem; }

.divider { height: 1px; background: var(--color-line); margin: 0.75rem 0; }

.output-list { list-style: none; margin: 0; padding: 0; }
.output-card {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.output-card .head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}
.output-card .head input[type="text"] {
  font-size: 1rem;
  font-weight: 500;
  font-family: var(--font-display);
  background: transparent;
  border: none;
  color: var(--color-ink);
  padding: 0.2rem;
}
.output-card .url {
  font-size: 0.78rem;
  color: var(--color-accent);
  word-break: break-all;
  margin-bottom: 0.6rem;
}
.graphic-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.5rem;
  background: var(--color-bg);
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  margin-bottom: 0.4rem;
  flex-wrap: wrap;
}
.graphic-row .name { flex: 1; }
.toggle-btn { background: var(--color-line); color: var(--color-ink); }
.toggle-btn.on { background: var(--color-accent); color: #fff; }
.toggle-btn.on:hover { background: var(--color-accent-hover); }

/* --- Designer additions: backdrop, zoom, history, animations --- */

.canvas-area {
  position: relative;
  overflow: hidden;
  padding: 0;
}
.canvas-holder {
  position: absolute;
  z-index: 1;
  display: flex;
}
/* No position/z-index on #canvas itself — fabric stacks its transparent upper
   canvas above this one for pointer events (selection, marquee, dragging). */
#canvas {
  border: 1px solid var(--color-line);
  box-shadow: 0 0 0 1px rgba(26, 22, 18, 0.15), 0 12px 40px rgba(26, 22, 18, 0.18);
}
/* Transparency checker, scoped to the canvas element itself (not the
   surrounding .canvas-area pasteboard, which is a plain solid color) so a
   transparent-background design's checker can never be mistaken for empty
   workspace outside the true 1920x1080 frame. Applied only when no preview
   backdrop scene is selected (backdropEl has no bg-* class, see
   designer.js's backdropSelect handler) — with a scene selected, #canvas
   must stay transparent so .backdrop's broadcast/stadium/etc. color shows
   through instead. */
#canvas.checker-bg {
  background-image:
    linear-gradient(45deg, var(--color-line) 25%, transparent 25%),
    linear-gradient(-45deg, var(--color-line) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--color-line) 75%),
    linear-gradient(-45deg, transparent 75%, var(--color-line) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
  background-color: var(--color-bg);
}
/* Reference graphics (underlay/overlay view aids) */
.refs-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
#refs-over { z-index: 2; }
.ref-item { position: absolute; top: 0; left: 0; opacity: 0.9; }
.ref-item.dimmed { opacity: 0.35; }
/* Screen / safe-area guides — visual only, never saved with the design. These
   overlay the broadcast canvas itself (not the app chrome), so they keep
   scorerelay-rx's neutral white-on-dark convention regardless of app theme. */
.canvas-guides {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: none;
  z-index: 3;
}
.canvas-guides.on { display: block; }
.canvas-guides .guide-guide {
  position: absolute;
  border: 1px dashed rgba(255,255,255,0.28);
}
.canvas-guides .guide-guide.action-safe { inset: 4%; }
.canvas-guides .guide-guide.title-safe { inset: 9%; border-color: rgba(255,255,255,0.14); }
.canvas-guides .guide-cross::before,
.canvas-guides .guide-cross::after {
  content: '';
  position: absolute;
  background: rgba(255,255,255,0.12);
}
.canvas-guides .guide-cross::before { left: 50%; top: 0; bottom: 0; width: 1px; }
.canvas-guides .guide-cross::after { top: 50%; left: 0; right: 0; height: 1px; }
/* Preview backdrops simulate broadcast environments (dark studio, field,
   court, ice, stadium, TV) behind a transparent graphic — these are
   functional environment previews, not app branding, so they keep their
   original colors regardless of theme. */
.backdrop {
  position: absolute;
  inset: 0;
  z-index: 0;
}
.backdrop.bg-broadcast {
  background: radial-gradient(ellipse at 50% 40%, #2b3640 0%, #10151a 60%, #06080b 100%);
}
.backdrop.bg-stadium {
  background:
    radial-gradient(ellipse 30% 18% at 50% 0%, rgba(255,255,255,0.35) 0%, transparent 70%),
    radial-gradient(ellipse at 50% 50%, #1c2632 0%, #07090d 100%);
}
.backdrop.bg-field {
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,0.07) 0 2px, transparent 2px 160px),
    linear-gradient(180deg, #1e5a2e 0%, #174a24 100%);
}
.backdrop.bg-court {
  background:
    radial-gradient(ellipse at 50% 45%, #c98a4b 0%, #9c5f2c 100%);
}
.backdrop.bg-ice {
  background: linear-gradient(180deg, #eef6f8 0%, #cfe4ea 60%, #b8d4dd 100%);
}
.backdrop.bg-tv {
  background:
    radial-gradient(ellipse at 50% -10%, rgba(120,180,255,0.25) 0%, transparent 60%),
    linear-gradient(180deg, #22303d 0%, #101820 100%);
}

.tool-sep {
  width: 48px;
  height: 1px;
  background: var(--color-line);
  margin: 0.3rem 0;
}

button.mini {
  width: 24px;
  height: 24px;
  padding: 0;
  font-size: 0.75rem;
  line-height: 1;
  background: var(--color-bg);
  color: var(--color-ink);
  border: 1px solid var(--color-line);
}
button.mini:hover { background: var(--color-accent-wash); }

/* --- Properties panel sections --- */

.panel-section {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-stone);
  margin: 0.6rem 0 0.3rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--color-line);
}
.advanced-toggle {
  width: 100%;
  margin-top: 0.6rem;
  background: var(--color-bg);
  color: var(--color-ink);
  border: 1px solid var(--color-line);
}
.advanced-toggle:hover { background: var(--color-accent-wash); }
.advanced-body {
  margin-top: 0.5rem;
  border-left: 2px solid var(--color-line);
  padding-left: 0.5rem;
}
.chk-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
  font-size: 0.82rem;
}
.chk-row label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--color-ink-muted);
  cursor: pointer;
}
.chk-row input[type="checkbox"] { width: auto; }

/* --- Control room field editor --- */

.field-editor {
  background: var(--color-bg);
  border: 1px solid var(--color-line);
  border-left: 3px solid var(--color-accent);
  border-radius: var(--radius);
  padding: 0.6rem;
  margin: 0.4rem 0 0.4rem 1.2rem;
}
.fe-head { font-size: 0.82rem; margin-bottom: 0.5rem; color: var(--color-ink-muted); }
.fe-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}
.fe-label {
  flex: 0 0 180px;
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fe-field {
  flex: 0 0 150px;
  font-size: 0.7rem;
  color: var(--color-accent);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}
.fe-input {
  flex: 1;
  min-width: 0;
  padding: 0.3rem 0.45rem;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  color: var(--color-ink);
  font-size: 0.82rem;
}
.fe-actions {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.55rem;
}
.badge {
  font-size: 0.7rem;
  color: var(--color-warn);
  padding: 0.1rem 0.35rem;
  border: 1px solid rgba(179, 85, 47, 0.3);
  border-radius: var(--radius);
  background: var(--color-warn-wash);
}

.anim-actions {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.35rem;
  flex-wrap: wrap;
}
.anim-actions button { flex: 1; padding: 0.3rem 0.4rem; font-size: 0.75rem; }

.anim-card {
  background: var(--color-bg);
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  padding: 0.5rem;
  margin-bottom: 0.5rem;
}
.anim-card .field-row label { flex: 0 0 74px; }
.anim-card input[type="number"] { width: 56px !important; flex: none !important; }

/* Keyframe timeline editor inside an animation card */
.kf-edit {
  margin-top: 0.45rem;
  padding-top: 0.45rem;
  border-top: 1px dashed var(--color-line);
}
.kf-bar {
  position: relative;
  height: 22px;
  margin: 0.4rem 0 0.45rem;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 4px;
  cursor: pointer;
}
.kf-tick {
  position: absolute;
  top: 3px;
  bottom: 3px;
  width: 2px;
  border-radius: 1px;
  background: var(--color-accent, #8ab4f8);
  opacity: 0.7;
}
.kf-tick.active { background: #ffffff; opacity: 1; width: 3px; }
.kf-row {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  margin-bottom: 0.3rem;
  flex-wrap: wrap;
  padding: 0.2rem;
  border-radius: 4px;
}
.kf-row.active { background: rgba(255, 255, 255, 0.06); }
.kf-row .kf-label {
  flex: 0 0 auto;
  font-size: 0.62rem;
  color: var(--color-dim, rgba(255, 255, 255, 0.62));
  min-width: 26px;
  text-align: right;
}
.kf-row input[type="number"] { width: 52px !important; font-size: 0.72rem; }
.kf-row select { flex: 1 1 90px; font-size: 0.7rem; min-width: 0; }
.kf-row button { flex: none; padding: 0.15rem 0.3rem; font-size: 0.7rem; }
.kf-addrow { margin: 0.1rem 0 0.35rem; }
.kf-addrow button { width: auto; padding: 0.2rem 0.6rem; font-size: 0.72rem; }

.modal-small { max-width: 340px; }
.modal-small button {
  display: block;
  width: 100%;
  margin-bottom: 0.5rem;
}

/* ================= Designer layout (body.dz) =================
   Three panels: what the graphic is made of (left), the canvas with a
   preview bar under it (centre), and an inspector for whatever is selected
   (right). Scoped to body.dz so the control room, which shares this file,
   is untouched. */

.dz-topbar { flex-wrap: nowrap; gap: 0.5rem; }
.dz-topbar #design-name { flex: 0 1 240px; min-width: 120px; font-weight: 500; }
.dz-topbar button { white-space: nowrap; }
.dz-btngroup { display: flex; }
.dz-btngroup button:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.dz-btngroup button:last-child { border-radius: 0 var(--radius) var(--radius) 0; margin-left: -1px; }
.dz-file-menu { width: 200px; display: none; flex-direction: column; gap: 0.3rem; }
.menu.open .dz-file-menu { display: flex; }
.dz-file-menu button { text-align: left; }

.dz-layout { min-width: 0; }
.dz-panel {
  background: var(--color-bg-elevated);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.dz-left { flex: 0 0 248px; border-right: 1px solid var(--color-line); padding: 0.75rem 0.6rem 0; }
.dz-right { flex: 0 0 336px; border-left: 1px solid var(--color-line); }
.dz-center { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.dz-center .canvas-area { flex: 1; min-height: 0; }

.dz-section-title {
  font-weight: 500;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-stone);
}
.dz-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0.9rem 0 0.4rem;
}
.dz-layer-tools { display: flex; gap: 2px; }
.dz-layer-tools button.mini { border-color: transparent; background: transparent; }
.dz-layer-tools button.mini:hover { border-color: var(--color-line); }

.dz-add-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.3rem;
  margin-top: 0.4rem;
}
.dz-add-grid button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.45rem 0.2rem 0.4rem;
  font-size: 0.7rem;
  background: var(--color-bg);
  color: var(--color-ink);
  border: 1px solid var(--color-line);
}
.dz-add-grid button:hover { background: var(--color-accent-wash); border-color: var(--color-accent); }
.dz-glyph { font-size: 1.05rem; line-height: 1.2; height: 1.3rem; letter-spacing: -0.08em; }

.dz-layers { flex: 1; overflow-y: auto; margin: 0 -0.6rem; padding: 0 0.6rem 0.75rem; }
.dz-layers .layer-item { margin-bottom: 1px; }
.dz-layers .layer-row { border-color: transparent; background: transparent; padding: 0.3rem 0.4rem; }
.dz-layers .layer-row:hover { background: var(--color-accent-wash); }
.dz-layers .layer-row.active { background: var(--color-accent); border-color: var(--color-accent); color: #fff; }
.dz-layers .layer-row.is-hidden .name { opacity: 0.5; }
.dz-layers .gicon { width: 1rem; text-align: center; color: var(--color-stone); font-size: 0.7rem; }
.dz-layers .layer-row.active .gicon { color: #fff; }
.layer-kind {
  flex: 0 0 auto;
  width: 1.1rem;
  text-align: center;
  font-size: 0.72rem;
  color: var(--color-stone);
}
.layer-row.active .layer-kind { color: rgba(255, 255, 255, 0.85); }
.layer-flags { display: inline-flex; gap: 3px; flex: 0 0 auto; }
.layer-flag {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-stone);
}
.layer-flag.data { background: var(--color-accent); }
.layer-flag.motion { background: #7a5bd6; }
.layer-flag.event { background: #e0a100; }
.layer-row.active .layer-flag { box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.7); }

/* Preview bar under the canvas */
.dz-stagebar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.4rem 0.75rem;
  background: var(--color-bg-elevated);
  border-top: 1px solid var(--color-line);
  flex-wrap: wrap;
}
.dz-stagebar .spacer { flex: 1; }
.dz-stage-group { display: flex; align-items: center; gap: 0.3rem; }
.dz-stage-label {
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-stone);
  margin-right: 0.1rem;
}
.dz-stagebar button, .dz-stagebar select { padding: 0.28rem 0.55rem; font-size: 0.78rem; }
.dz-stagebar select {
  background: var(--color-bg-elevated);
  color: var(--color-ink);
  border: 1px solid var(--color-line);
  max-width: 150px;
}
.dz-check { display: inline-flex; align-items: center; gap: 0.25rem; font-size: 0.78rem; color: var(--color-ink-muted); cursor: pointer; }

/* Inspector */
.dz-insp-head { padding: 0.75rem 0.85rem 0.5rem; }
.dz-insp-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dz-insp-sub { font-size: 0.76rem; color: var(--color-stone); margin-top: 0.1rem; }
.dz-tabs { margin: 0; padding: 0 0.85rem; gap: 0; border-bottom: 1px solid var(--color-line); }
.dz-tabs button {
  flex: 0 0 auto;
  padding: 0.4rem 0.7rem;
  font-size: 0.8rem;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--color-ink-muted);
  background: transparent;
}
.dz-tabs button:hover { background: transparent; color: var(--color-ink); }
.dz-tabs button.active { background: transparent; color: var(--color-accent); border-bottom-color: var(--color-accent); font-weight: 500; }
.dz-insp-body { flex: 1; min-height: 0; overflow-y: auto; padding: 0.75rem 0.85rem 1.5rem; }
.dz-insp-body select {
  background: var(--color-bg-elevated);
  color: var(--color-ink);
  border: 1px solid var(--color-line);
}
.dz-insp-body .panel-section.dz-first,
.dz-insp-body > .panel-section:first-child { margin-top: 0; padding-top: 0; border-top: none; }
.dz-insp-body .anim-card { background: var(--color-bg); }
.dz-insp-body .anim-card select { min-width: 0; flex: 1; padding: 0.3rem 0.35rem; font-size: 0.8rem; }
.dz-insp-body .kf-bar { background: rgba(26, 22, 18, 0.08); }
.dz-insp-body .kf-tick.active { background: var(--color-ink); }
.dz-insp-body .kf-row.active { background: var(--color-accent-wash); }
.dz-insp-body .kf-row .kf-label { color: var(--color-stone); }

.dz-group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin: 1rem 0 0.15rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--color-line);
}
.dz-group-head:first-child { margin-top: 0; padding-top: 0; border-top: none; }
.dz-group-head h4 { margin: 0; font-size: 0.86rem; font-weight: 600; }
.dz-group-head button { padding: 0.2rem 0.5rem; font-size: 0.74rem; }
.dz-group-note { font-size: 0.76rem; color: var(--color-stone); margin: 0 0 0.5rem; }

.dz-chips { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-bottom: 0.6rem; }
.dz-chips button {
  padding: 0.25rem 0.55rem;
  font-size: 0.74rem;
  border-radius: 999px;
  background: var(--color-bg);
  color: var(--color-ink);
  border: 1px solid var(--color-line);
}
.dz-chips button:hover { background: var(--color-accent-wash); border-color: var(--color-accent); }

.dz-presets { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem; margin-bottom: 0.4rem; }
.dz-presets button {
  text-align: left;
  padding: 0.5rem 0.6rem;
  background: var(--color-bg);
  color: var(--color-ink);
  border: 1px solid var(--color-line);
  line-height: 1.25;
}
.dz-presets button:hover { background: var(--color-accent-wash); border-color: var(--color-accent); }
.dz-presets button b { display: block; font-size: 0.8rem; font-weight: 600; }
.dz-presets button span { font-size: 0.7rem; color: var(--color-stone); }

.anim-card-head {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
  font-size: 0.74rem;
  color: var(--color-stone);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.anim-card-head .spacer { flex: 1; }
.anim-card-head button { padding: 0.15rem 0.45rem; font-size: 0.72rem; text-transform: none; letter-spacing: 0; }
.anim-card.event { border-left: 3px solid #e0a100; }
.anim-card .field-row input[type="text"] { min-width: 0; }
