:root {
  --app-header-height: 64px;
  --nav-width: 76px;
  --library-width: 314px;
  --inspector-width: 328px;
  --workspace: #eef0f3;
  --panel-muted: #f7f7f8;
  --neutral-border: #e4e5e7;
  --focus-ring: 0 0 0 3px rgba(162, 29, 40, .18);
}

body {
  display: block;
  min-width: 0;
  overflow: hidden;
  background: var(--workspace);
}

#app-shell {
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#editor-workspace {
  min-width: 0;
  min-height: 0;
  flex: 1;
  display: flex;
  position: relative;
  overflow: hidden;
}

#header {
  min-height: var(--app-header-height);
  height: var(--app-header-height);
  width: 100%;
  padding: 8px 16px;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto minmax(360px, 1fr);
  gap: 16px;
  align-items: center;
  position: relative;
  z-index: 1200;
  background: rgba(255, 255, 255, .98);
  border-bottom: 1px solid var(--neutral-border);
  box-shadow: 0 1px 8px rgba(26, 26, 26, .05);
}

#brand-area,
#document-meta,
#header-actions,
#history-controls {
  display: flex;
  align-items: center;
}

#brand-area { min-width: 0; gap: 12px; }

#brand-home {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  text-decoration: none;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: -.02em;
}

#brand-home img {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  object-fit: cover;
  border-radius: 12px;
  box-shadow: 0 3px 10px rgba(162, 29, 40, .15);
}

#document-meta {
  min-width: 0;
  gap: 10px;
  padding-left: 12px;
  border-left: 1px solid var(--neutral-border);
}

#template-name {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 700;
}

#status {
  flex: 0 0 auto;
  min-height: 24px;
  padding: 4px 9px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 999px;
  background: #f0f7f2;
  color: #307547;
  font-size: 11px;
  font-weight: 700;
}

#status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

#status[data-state="saving"] { background: #fff5e6; color: #9b5b00; }
#status[data-state="dirty"] { background: #fff0f1; color: var(--accent); }
#status[data-state="error"] { background: #fff0f1; color: var(--danger); }

#history-controls {
  position: static;
  transform: none;
  gap: 4px;
  justify-self: center;
}

#header-actions {
  min-width: 0;
  justify-content: flex-end;
  gap: 8px;
}

#account-menu-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

#header-actions > #account-menu-wrap {
  flex: 0 0 auto;
}

.account-status {
  min-width: 162px;
  min-height: 42px;
  padding: 8px 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px solid rgba(162, 29, 40, .20);
  border-radius: 999px;
  background:
    linear-gradient(#fff, #fff) padding-box,
    linear-gradient(135deg, #f7b731, #bd1f2d, #6d4aff) border-box;
  color: var(--accent);
  font-size: 12px;
  font-weight: 850;
  line-height: 1;
  box-shadow: 0 8px 22px rgba(162, 29, 40, .12);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}

.account-status:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 28px rgba(162, 29, 40, .18);
}

.account-status:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring), 0 12px 28px rgba(162, 29, 40, .18);
}

.account-status .material-icons {
  width: 19px;
  height: 19px;
  flex: 0 0 19px;
  font-size: 19px;
}

.account-status-avatar {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #07810f;
  color: #fff;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: .02em;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.45);
}

.account-status.signed-in {
  min-width: 0;
  width: auto;
  padding: 2px;
  border: 0;
  background: transparent;
  color: var(--text);
  box-shadow: none;
}

.account-status.signed-in:hover {
  box-shadow: 0 0 0 6px rgba(7, 129, 15, .08);
}

.account-status-name {
  max-width: 118px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.account-status.signed-in .account-status-name,
.account-status.signed-in .account-status-plan {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

#account-menu {
  width: min(320px, calc(100vw - 24px));
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  padding: 12px;
  background: #fff;
  border: 1px solid rgba(0,0,0,.06);
  border-radius: 22px;
  box-shadow: 0 24px 58px rgba(29, 33, 44, .20);
  z-index: 1700;
}

#account-menu[hidden] {
  display: none;
}

#account-menu::before {
  content: '';
  position: absolute;
  top: -6px;
  right: 24px;
  width: 14px;
  height: 14px;
  transform: rotate(45deg);
  background: #fff;
  border-left: 1px solid rgba(0,0,0,.06);
  border-top: 1px solid rgba(0,0,0,.06);
}

.account-menu-card {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 4px 2px 12px;
}

.account-menu-avatar {
  width: 74px;
  height: 74px;
  flex: 0 0 74px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #07810f;
  color: #fff;
  font-size: 36px;
  font-weight: 900;
}

.account-menu-copy {
  min-width: 0;
}

.account-menu-name {
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-size: 15px;
  font-weight: 850;
}

.account-menu-email {
  max-width: 190px;
  margin-top: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #35323a;
  font-size: 14px;
  line-height: 1.25;
}

.account-menu-plan {
  width: max-content;
  max-width: 190px;
  margin-top: 9px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #fff4e0;
  color: #925500;
  font-size: 11px;
  font-weight: 800;
}

.account-menu-plan.pro {
  background: #fff0f1;
  color: var(--accent);
}

.account-menu-action {
  width: 100%;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--neutral-border);
  border-radius: 12px;
  background: #fafafa;
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
}

.account-menu-action:hover {
  background: #fff0f1;
  border-color: rgba(162, 29, 40, .24);
  color: var(--accent);
}

.toolbar-btn,
#header-actions > button,
#history-controls button {
  min-width: 40px;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 10px;
  border-color: var(--neutral-border);
  background: #fff;
  font-weight: 700;
}

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  line-height: 1;
  vertical-align: middle;
}

.toolbar-btn .button-label {
  display: inline-flex;
  align-items: center;
  line-height: 20px;
}

.toolbar-btn.icon-only,
#history-controls button {
  width: 40px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.toolbar-btn .material-icons,
#history-controls .material-icons {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  font-size: 20px;
}

#save {
  background: #fff;
  color: var(--accent);
  border-color: rgba(162, 29, 40, .34);
}

#header-actions > #download-trigger-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 6px 16px rgba(162, 29, 40, .2);
}

#header-actions > #download-trigger-btn:hover:not(:disabled) {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  color: #fff;
}

#more-actions-wrap { position: relative; }

#admin-menu {
  display: none;
  width: 286px;
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  padding: 8px;
  background: #fff;
  border: 1px solid var(--neutral-border);
  border-radius: 14px;
  box-shadow: 0 18px 44px rgba(28, 24, 24, .18);
  z-index: 1500;
}

#admin-menu.open { display: block; }

.admin-menu-title {
  padding: 7px 9px 9px;
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.admin-menu-item,
#admin-menu > button {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-weight: 600;
}

#admin-menu .material-icons { width: 20px; font-size: 19px; color: var(--text-dim); }
#admin-menu > button:hover { background: var(--accent-soft); }
#admin-menu #delete-btn { color: var(--danger); }
#admin-menu #delete-btn .material-icons { color: var(--danger); }

#live-controls {
  display: none;
  padding: 8px;
  margin-top: 6px;
  gap: 7px;
  border-top: 1px solid var(--neutral-border);
}

#admin-menu.open #live-controls { display: grid; grid-template-columns: 1fr auto; }
#liveId { width: 100%; min-width: 0; grid-column: 1 / -1; }
#fetchLive, #pushLive { width: 100%; min-height: 38px; }
#upload { display: none; }
#admin-menu.open #upload { display: flex; }

#library {
  width: var(--library-width);
  background: #fff;
  border-color: var(--neutral-border);
  box-shadow: none;
}

#library-nav {
  width: var(--nav-width);
  padding: 12px 8px;
  gap: 4px;
  border-color: var(--neutral-border);
}

.nav-tab {
  width: 60px;
  min-height: 58px;
  height: auto;
  padding: 8px 4px;
  border-radius: 12px;
  gap: 5px;
}

.nav-tab .material-icons { font-size: 22px; }
.nav-label { font-size: 10px; font-weight: 700; }
.nav-tab.active { box-shadow: none; }

.secondary-nav { margin-top: auto; }

.tab-pane h2 {
  padding: 18px 16px 12px;
  background: #fff;
  border: 0;
  color: var(--text);
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -.02em;
  text-transform: none;
}

#lib-search-input {
  min-height: 40px;
  margin: 0 12px 10px;
  padding: 9px 13px 9px 36px;
  border-color: var(--neutral-border);
  border-radius: 10px;
  background: #f7f7f8;
}

.panel-subhead {
  padding: 10px 16px 6px;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.preset-text-btn,
.sticker-item-btn,
.shape-item-btn,
.textart-category-btn {
  border-color: var(--neutral-border);
  border-radius: 10px;
  box-shadow: none;
}

#center {
  min-width: 0;
  min-height: 0;
  flex: 1;
  position: relative;
  background: var(--workspace);
}

#download-dropdown {
  position: fixed;
  top: calc(var(--app-header-height) + 8px);
  right: 12px;
  width: 296px;
  border-color: var(--neutral-border);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 18px 44px rgba(28, 24, 24, .18);
  z-index: 1600;
}

#stage {
  min-width: 0;
  padding: 40px 48px 84px;
  justify-content: flex-start;
  align-items: flex-start;
  background: var(--workspace);
}

#stage-inner { margin: auto; }

.tm-canvas {
  background: #fff;
  box-shadow: 0 12px 34px rgba(21, 24, 28, .16), 0 1px 3px rgba(21, 24, 28, .12);
}

#zoom-bar {
  width: max-content;
  max-width: calc(100% - 32px);
  min-height: 48px;
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 20;
  padding: 6px 8px;
  gap: 5px;
  border: 1px solid var(--neutral-border);
  border-radius: 14px;
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 8px 24px rgba(21, 24, 28, .12);
}

.zoom-preset {
  min-width: 40px;
  min-height: 34px;
  padding: 5px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 11px;
  font-weight: 700;
}

.zoom-preset.active { background: var(--accent-soft); color: var(--accent); }
#zoomSlider { width: 132px; }
#zoomPercent { min-width: 42px; text-align: center; font-weight: 700; color: var(--text); }
#zoomReset { width: 34px; height: 34px; padding: 0; border: 0; border-radius: 8px; }

#inspector {
  width: var(--inspector-width);
  background: #fff;
  border-color: var(--neutral-border);
  box-shadow: none;
}

#inspector-header {
  min-height: 52px;
  padding: 10px 12px 0;
  display: flex;
  align-items: flex-end;
  border-bottom: 1px solid var(--neutral-border);
}

#inspector-tabs {
  min-width: 0;
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

.inspector-tab {
  min-height: 40px;
  padding: 8px 5px;
  position: relative;
  border: 0;
  border-radius: 8px 8px 0 0;
  background: transparent;
  color: var(--text-dim);
  font-weight: 700;
}

.inspector-tab[aria-selected="true"] { color: var(--accent); }
.inspector-tab[aria-selected="true"]::after {
  content: '';
  height: 3px;
  position: absolute;
  left: 9px;
  right: 9px;
  bottom: -1px;
  border-radius: 3px 3px 0 0;
  background: var(--accent);
}

#close-inspector-btn {
  display: none;
  width: 40px;
  height: 40px;
  margin-bottom: 3px;
  padding: 0;
  border: 0;
}

.inspector-panel {
  min-height: 0;
  flex: 1;
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.inspector-panel.active { display: flex; }

#editor-settings {
  min-height: 44px;
  padding: 8px 14px !important;
  border-color: var(--neutral-border) !important;
}

#layer-list {
  height: auto;
  min-height: 0;
  flex: 1;
  padding: 10px 10px 100px 10px;
  border: 0;
  overflow-y: auto;
  position: relative;
}

#layer-list-toolbar {
  min-height: 48px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--neutral-border);
}

#layer-list-title { font-size: 13px; font-weight: 800; }

.layer-item-row {
  min-height: 54px;
  margin-bottom: 8px;
  background: #e9ecef;
  border: 2px solid transparent;
  border-radius: 12px;
  box-shadow: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  transition: all 0.15s ease;
  padding: 4px 6px;
  cursor: grab;
}

.layer-item-row:hover {
  background: #e2e8f0;
  border-color: #cbd5e1;
}

.layer-item-row.selected {
  border-color: #8b3dff;
  background: #ffffff;
  box-shadow: 0 2px 10px rgba(139, 61, 255, 0.14);
}

.layer-drag-handle {
  width: 32px;
  min-width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  color: #0f172a !important;
  cursor: grab;
  border-radius: 6px;
}

.layer-drag-handle .material-icons,
.layer-drag-handle svg {
  color: #0f172a !important;
  fill: #0f172a !important;
}

.layer-drag-handle:hover {
  color: #000000 !important;
  background: rgba(0, 0, 0, 0.08);
}

.layer-item-select {
  min-height: 44px;
  padding: 4px 8px;
  gap: 10px;
  font-weight: 600;
  font-size: 13px;
  color: #1e293b;
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  overflow: hidden;
  text-align: left;
}

.layer-thumb {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.layer-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.layer-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  color: #1e293b;
  font-size: 13px;
}

.layer-status-indicators {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-right: 4px;
}

.layer-status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #64748b;
}

.layer-status-badge .material-icons {
  font-size: 16px;
}

.layer-more-btn {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #334155;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;
  margin-right: 2px;
}

.layer-item-row:hover .layer-more-btn,
.layer-item-row.selected .layer-more-btn,
.layer-item-row.menu-open .layer-more-btn {
  opacity: 1;
}

.layer-more-btn:hover {
  background: rgba(0, 0, 0, 0.1);
  color: #0f172a;
}

.layer-item-row.selected .layer-more-btn {
  background: #1e293b;
  color: #ffffff;
}

.layer-item-row.selected .layer-more-btn:hover {
  background: #0f172a;
}

#global-layer-options-menu,
.layer-options-menu.global-popup {
  display: none;
  flex-direction: column;
  position: fixed;
  z-index: 999999;
  min-width: 195px;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.25), 0 4px 12px rgba(0, 0, 0, 0.12);
  border: 1px solid #cbd5e1;
  padding: 6px;
  gap: 2px;
}

#global-layer-options-menu.visible,
.layer-options-menu.global-popup.visible {
  display: flex !important;
}

#global-color-picker-popup {
  display: none;
  flex-direction: column;
  position: fixed;
  z-index: 999999;
  width: 250px;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.22), 0 4px 16px rgba(0, 0, 0, 0.08);
  border: 1px solid #e2e8f0;
  padding: 14px;
  gap: 12px;
  font-family: inherit;
}
#global-color-picker-popup.visible {
  display: flex !important;
}
.color-popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 13px;
  color: #0f172a;
  padding-bottom: 6px;
  border-bottom: 1px solid #f1f5f9;
}
.color-popup-preview-badge {
  display: flex;
  align-items: center;
  gap: 8px;
}
.color-popup-preview-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.15);
}
.color-popup-close-btn {
  background: #f1f5f9;
  border: none;
  font-size: 14px;
  color: #64748b;
  cursor: pointer;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s ease, color 0.1s ease;
}
.color-popup-close-btn:hover {
  background: #e2e8f0;
  color: #0f172a;
}
.color-popup-section-title {
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.color-popup-swatches {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}
.color-popup-swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid #e2e8f0;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
  box-shadow: 0 2px 4px rgba(0,0,0,0.06);
}
.color-popup-swatch:hover {
  transform: scale(1.15);
  border-color: #8b3dff;
  box-shadow: 0 4px 10px rgba(139, 61, 255, 0.3);
}
.color-popup-swatch.active {
  border-color: #8b3dff;
  box-shadow: 0 0 0 2px #ffffff, 0 0 0 4px #8b3dff;
}
.color-popup-swatch.transparent-swatch,
.text-solid-swatch[data-color="transparent"] {
  background: repeating-conic-gradient(#cbd5e1 0% 25%, #ffffff 0% 50%) 50% / 10px 10px !important;
  position: relative !important;
  overflow: hidden !important;
}
.color-popup-swatch.transparent-swatch::after,
.text-solid-swatch[data-color="transparent"]::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 2px;
  background: #ef4444;
  transform: rotate(-45deg);
}
.color-popup-custom-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f8fafc;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
}
.color-popup-hex {
  flex-grow: 1;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 600;
  font-family: monospace;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  outline: none;
  text-transform: uppercase;
  color: #0f172a;
}
.color-popup-hex:focus {
  border-color: #8b3dff;
}
.color-popup-ok-btn {
  width: 100% !important;
  background: #8b3dff !important;
  color: #ffffff !important;
  border: none !important;
  font-weight: 700 !important;
  padding: 8px 16px !important;
  border-radius: 999px !important;
  cursor: pointer !important;
  font-size: 13px !important;
  box-shadow: 0 4px 12px rgba(139, 61, 255, 0.3) !important;
  transition: transform 0.1s ease, background 0.1s ease !important;
}
.color-popup-ok-btn:hover {
  background: #7a2eff !important;
  transform: translateY(-1px) !important;
}

/* Background Removal Action Button Styling (App Theme Crimson/Purple Gradient) */
.btn-remove-bg {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  background: linear-gradient(135deg, #A21D28 0%, #8b3dff 100%);
  color: #ffffff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(162, 29, 40, 0.3);
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}
.btn-remove-bg:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 5px 15px rgba(162, 29, 40, 0.4);
}
.btn-remove-bg:disabled {
  opacity: 0.85;
  cursor: not-allowed;
}
.btn-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
  display: inline-block;
  flex-shrink: 0;
}
@keyframes btn-spin {
  to { transform: rotate(360deg); }
}

.btn-restore-bg {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 8px 12px;
  background: #fff5f5;
  color: #A21D28;
  border: 1px solid #fca5a5;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn-restore-bg:hover {
  background: #fee2e2;
  border-color: #f87171;
  color: #881337;
}

/* Canvas Layer Processing Loader Overlay & Laser Scanner Line */
.bg-removal-canvas-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.55);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  z-index: 1000;
  color: #ffffff;
  pointer-events: none;
  overflow: hidden;
  animation: overlay-fade-in 0.2s ease-out;
}
@keyframes overlay-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.bg-removal-scanner-line {
  position: absolute;
  top: 0;
  left: -10%;
  width: 120%;
  height: 4px;
  background: linear-gradient(90deg, transparent 0%, #ff2a4b 15%, #ffffff 50%, #8b3dff 85%, transparent 100%);
  box-shadow: 0 0 14px #ff2a4b, 0 0 28px #8b3dff, 0 0 36px #ffffff;
  z-index: 1001;
  pointer-events: none;
  will-change: transform;
  animation: scan-line-sweep 1.3s ease-in-out infinite alternate !important;
}
@keyframes scan-line-sweep {
  0% {
    transform: translateY(0px);
    opacity: 0.6;
  }
  50% {
    opacity: 1;
  }
  100% {
    transform: translateY(var(--scanner-travel-height, 180px));
    opacity: 0.6;
  }
}

.bg-removal-spinner-ring {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: #A21D28;
  border-right-color: #8b3dff;
  border-radius: 50%;
  animation: btn-spin 0.75s linear infinite;
  box-shadow: 0 0 16px rgba(139, 61, 255, 0.5);
}

.bg-removal-badge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
  background: rgba(255, 255, 255, 0.15);
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #ffffff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.layer-action-item {
  display: flex !important;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: #334155;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s ease, color 0.12s ease;
}

.layer-action-item .material-icons,
.layer-action-item svg {
  font-size: 18px;
  width: 18px;
  height: 18px;
  color: #64748b;
  fill: #64748b;
}

.layer-action-item:hover {
  background: #f1f5f9;
  color: #0f172a;
}

.layer-action-item:hover .material-icons,
.layer-action-item:hover svg {
  color: #0f172a;
  fill: #0f172a;
}

.layer-action-item.delete-layer:hover {
  background: #fef2f2;
  color: #dc2626;
}

.layer-action-item.delete-layer:hover .material-icons,
.layer-action-item.delete-layer:hover svg {
  color: #dc2626;
  fill: #dc2626;
}

.layer-action-item[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}

.layer-action-item[disabled]:hover {
  background: transparent;
  color: #334155;
}

#properties { min-height: 0; flex: 1; background: #fff; }
.prop-group { padding: 14px 16px; border-color: var(--neutral-border); }
.prop-label { color: var(--text); font-size: 12px; font-weight: 800; }
.prop-row { gap: 9px; }
.prop-row input[type="range"] { min-width: 0; flex: 1; accent-color: var(--accent); }
.prop-row input[type="number"] { width: 68px; }

#prop-empty,
.inspector-empty-state {
  margin: auto;
  padding: 32px 22px;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.5;
}

.inspector-empty-state .material-icons {
  display: block;
  margin-bottom: 10px;
  color: #b7b8bc;
  font-size: 34px;
}

.tm-selection-toolbar { top: -58px; gap: 2px; padding: 5px; border-radius: 13px; }
.tm-selection.toolbar-below .tm-selection-toolbar { top: calc(100% + 12px); }
.tm-selection.toolbar-below .tm-selection-bottom-controls { top: calc(100% + 64px); }
.tm-selection-action { width: 40px; height: 40px; border-radius: 9px; }
.tm-selection-action svg { width: 20px; height: 20px; }
.tm-selection.is-locked { outline-color: var(--accent) !important; }

button:focus-visible,
input:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.material-icons {
  max-width: 1em;
  overflow: hidden;
  white-space: nowrap;
  pointer-events: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  font-weight: normal;
  font-style: normal;
  line-height: 1;
}
.material-icons svg {
  width: 1em;
  height: 1em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

body.preview-mode #library-nav,
body.preview-mode #library,
body.preview-mode #inspector,
body.preview-mode #zoom-bar,
body.preview-mode #history-controls,
body.preview-mode #document-meta,
body.preview-mode #brand-area,
body.preview-mode #header-actions > :not(#preview-btn) { display: none !important; }
body.preview-mode #header {
  width: auto;
  height: auto;
  min-height: 0;
  padding: 0;
  display: block;
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1600;
  border: 0;
  background: transparent;
  box-shadow: none;
}
body.preview-mode #header-actions { display: block; }
body.preview-mode #preview-btn {
  min-width: 124px;
  border-color: rgba(0, 0, 0, .12);
  background: rgba(255, 255, 255, .94);
  box-shadow: 0 8px 28px rgba(28, 24, 24, .16);
  backdrop-filter: blur(8px);
}
body.preview-mode #editor-workspace {
  width: 100vw;
  height: 100vh;
  position: fixed;
  inset: 0;
  z-index: 1300;
}
body.preview-mode #stage {
  width: 100%;
  height: 100%;
  padding: 28px;
  pointer-events: none;
}
body.preview-mode .tm-selection { display: none !important; }

@media (max-width: 1440px) {
  :root { --library-width: 288px; --inspector-width: 300px; }
  #header { grid-template-columns: minmax(180px, 1fr) auto minmax(330px, 1fr); gap: 10px; padding-inline: 10px; }
  #brand-home span { display: none; }
  #document-meta { padding-left: 6px; border-left: 0; }
  #stage { padding-inline: 28px; }
}

@media (max-width: 1160px) {
  #header { grid-template-columns: auto auto minmax(300px, 1fr); }
  #history-controls { position: static; }
  #document-meta { display: none; }
  #library,
  #inspector {
    height: 100%;
    position: absolute;
    top: 0;
    z-index: 1000;
    transform: translateX(-105%);
    transition: transform .22s ease;
    box-shadow: 0 18px 44px rgba(28, 24, 24, .2);
  }
  #library { left: 0; }
  #inspector { right: 0; transform: translateX(105%); }
  #library.visible,
  #inspector.visible { transform: translateX(0); }
  #toggle-library-btn,
  #toggle-inspector-btn,
  #close-library-btn,
  #close-inspector-btn { display: inline-flex !important; }
  #stage { padding: 28px 20px 82px; }
}

@media (max-width: 760px) {
  :root { --app-header-height: 58px; --mobile-nav-bar-height: 60px; }
  /* The 1160px breakpoint's grid-template-columns keeps a 300px floor on
     the 3rd column sized for full-width labeled buttons — but by 760px
     those buttons have already gone icon-only (40px each, below), so that
     floor is stale and starves columns 1+2 to ~0 width, spilling their
     buttons out on top of each other (confirmed: toggle-library-btn and
     undo-btn landed almost exactly overlapping at 390px). Drop the floor
     now that col3's real content is ~170px, not 300px. */
  #header { grid-template-columns: auto auto minmax(0, 1fr); }
  #header { padding: 7px 8px; gap: 5px; }
  #brand-area { gap: 4px; }
  #brand-home { display: none; }
  #history-controls { position: static; }
  #header-actions { gap: 4px; }
  #header-actions .button-label { display: none; }
  .toolbar-btn, #header-actions > button { width: 40px; padding: 0; }
  .account-status {
    min-width: 40px;
    width: 40px;
    min-height: 40px;
    padding: 0;
  }
  .account-status:not(.signed-in) .account-status-label { display: none; }
  .account-status.signed-in { width: 40px; }
  .account-status-avatar {
    width: 36px;
    height: 36px;
    flex-basis: 36px;
  }
  #account-menu {
    position: fixed;
    top: 66px;
    right: 8px;
  }
  #inspector { width: min(92vw, 360px); }
  #zoom-bar .zoom-preset[data-zoom="0.5"],
  #zoom-bar .zoom-preset[data-zoom="0.75"] { display: none; }
  #zoomSlider { width: 92px; }

  /* Library becomes a persistent bottom icon bar + a bottom sheet for its
     content, instead of the 1160px breakpoint's hidden side drawer — matches
     the pattern users already know from Canva/CapCut, and doesn't require
     remembering a header toggle exists. #inspector (layers panel) keeps its
     side-drawer behavior unchanged; only #library changes here.
     display:contents drops #library's own box (and with it the 1160px
     absolute/translateX rules — there's no box left for them to apply to),
     so #library-nav and #library-content lay out as independent fixed
     children instead of fighting their parent's positioning. */
  #library { display: contents; }

  #library-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: var(--mobile-nav-bar-height, 60px);
    flex-direction: row;
    align-items: stretch;
    overflow-x: auto;
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom, 0px));
    gap: 2px;
    border-right: none;
    border-top: 1px solid var(--neutral-border);
    z-index: 1001;
    /* #library-nav/#library-content never had their own background — they
       always just sat visually in front of #library's own white box. Now
       that #library is display:contents (no box, see above), there's
       nothing behind them, so they need their own fill. */
    background: #fff;
  }
  #library-nav .nav-tab {
    flex: 0 0 auto;
    width: 58px;
  }
  /* Templates (choosing a starting template) and Tools (admin-only legacy
     repair) don't belong in the primary mobile bottom bar — everything
     else (Text/Stickers/Shapes/Text Art/Uploads/Projects) stays. */
  #library-nav [data-tab="templates"],
  #library-nav [data-tab="legacy"] { display: none; }

  /* Reuses the SAME #library.visible class every existing open/close call
     site already toggles (toggle-library-btn, close-library-btn, selecting
     a template, Escape, etc.) — none of those call sites need to change;
     the descendant selector just gives that class a second, mobile-only
     meaning here. */
  #library-content {
    position: fixed;
    left: 0;
    right: 0;
    bottom: var(--mobile-nav-bar-height, 60px);
    width: 100%;
    max-height: 55vh;
    overflow-y: auto;
    /* translateY(100%) only shifts by the box's OWN height — since this box
       is already offset `bottom: 60px` above the true viewport edge (to
       clear the nav bar when open), a plain 100% lands its "closed" top
       edge exactly back at the bar's own top edge, not below it. With a
       transparent background that overlap was invisible; now that it has
       a real background (fixed above) it opaquely painted over the whole
       bar — confirmed bug. Shifting by the bar's height too clears it. */
    transform: translateY(calc(100% + var(--mobile-nav-bar-height, 60px)));
    transition: transform .22s ease;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 30px rgba(28, 24, 24, .18);
    z-index: 1001;
    background: #fff;
  }
  #library.visible #library-content { transform: translateY(0); }

  /* The bottom bar is always on-screen, so the header's separate "open
     design panel" toggle is redundant here — one less icon crammed into an
     already-tight mobile header. */
  #toggle-library-btn { display: none !important; }

  /* Keep the canvas and its floating zoom control clear of the new
     persistent bottom bar. */
  #stage { padding-bottom: calc(var(--mobile-nav-bar-height, 60px) + env(safe-area-inset-bottom, 0px) + 20px); }
  #zoom-bar { bottom: calc(var(--mobile-nav-bar-height, 60px) + env(safe-area-inset-bottom, 0px) + 12px); }
}
