::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }

/* Light is the primary theme (matches posterkaaran.com's brand palette —
   maroon/orange on warm white). Dark stays available as an opt-in via
   [data-theme="dark"] on <html>, preserving every value from the original
   dark redesign unchanged so switching back looks exactly as before. */
:root {
  --app-header-height: 64px;
  --nav-width: 76px;
  --library-width: 314px;
  --inspector-width: 328px;

  --workspace: #f1ece3;
  --canvas-bg: #ffffff;
  --canvas-shadow: 0 20px 60px rgba(162, 29, 40, 0.12), 0 0 0 1px rgba(162, 29, 40, 0.08);
  --panel-glass: rgba(255, 255, 255, 0.92);
  --panel-glass-strong: rgba(255, 255, 255, 0.98);
  --panel-muted: rgba(162, 29, 40, 0.045);
  --neutral-border: rgba(162, 29, 40, 0.14);
  --surface-hover: rgba(162, 29, 40, 0.09);
  --surface-strong: rgba(162, 29, 40, 0.14);

  --text-primary: #1a1a1a;
  --text-dim: #6f625f;
  --text-inverse: #ffffff;

  --accent: #A21D28;
  --accent-2: #ff9800;
  --accent-soft: rgba(162, 29, 40, 0.10);
  --accent-border: rgba(162, 29, 40, 0.30);
  --accent-gradient: linear-gradient(135deg, #A21D28 0%, #ff9800 100%);
  --accent-gradient-hover: linear-gradient(135deg, #8a1721 0%, #e68600 100%);
  --guest-badge-gradient: linear-gradient(135deg, #ff9800, #A21D28, #7d1520);

  --focus-ring: 0 0 0 3px rgba(162, 29, 40, .22);
  --shadow-soft: 0 1px 12px rgba(0, 0, 0, .06);
  --shadow-med: 0 12px 36px rgba(0, 0, 0, .10);
  --shadow-strong: 0 18px 44px rgba(0, 0, 0, .16);

  --checker-a: rgba(0, 0, 0, 0.06);
  --checker-b: #ffffff;

  --status-success-bg: rgba(22, 163, 74, 0.10); --status-success-text: #15803d;
  --status-warning-bg: rgba(217, 119, 6, 0.10); --status-warning-text: #b45309;
  --status-danger-bg: rgba(220, 38, 38, 0.10);  --status-danger-text: #dc2626;
  --status-dirty-bg: var(--accent-soft);        --status-dirty-text: var(--accent);
  --avatar-bg: #0f7a1a;

  --scrollbar-thumb: rgba(0, 0, 0, 0.18);
  --scrollbar-thumb-hover: rgba(0, 0, 0, 0.3);
}

:root[data-theme="dark"] {
  --workspace: #0d0d12;
  --canvas-bg: #12121a;
  --canvas-shadow: 0 20px 60px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.05);
  --panel-glass: rgba(18, 18, 26, 0.85);
  --panel-glass-strong: rgba(18, 18, 26, 0.95);
  --panel-muted: rgba(255, 255, 255, 0.04);
  --neutral-border: rgba(255, 255, 255, 0.08);
  --surface-hover: rgba(255, 255, 255, 0.08);
  --surface-strong: rgba(255, 255, 255, 0.12);

  --text-primary: #f4f4f5;
  --text-dim: #a1a1aa;
  --text-inverse: #ffffff;

  --accent: #ec4899;
  --accent-2: #8b3dff;
  --accent-soft: rgba(236, 72, 153, 0.12);
  --accent-border: rgba(236, 72, 153, 0.3);
  --accent-gradient: linear-gradient(135deg, #ec4899 0%, #8b3dff 100%);
  --accent-gradient-hover: linear-gradient(135deg, #d946ef 0%, #7c3aed 100%);
  --guest-badge-gradient: linear-gradient(135deg, #f7b731, #bd1f2d, #6d4aff);

  --focus-ring: 0 0 0 3px rgba(236, 72, 153, .18);
  --shadow-soft: 0 1px 12px rgba(0, 0, 0, .2);
  --shadow-med: 0 12px 36px rgba(0, 0, 0, .4);
  --shadow-strong: 0 18px 44px rgba(0, 0, 0, .4);

  --checker-a: rgba(255, 255, 255, 0.08);
  --checker-b: #12121a;

  --status-success-bg: rgba(34, 197, 94, 0.12); --status-success-text: #4ade80;
  --status-warning-bg: rgba(245, 158, 11, 0.12); --status-warning-text: #fbbf24;
  --status-danger-bg: rgba(239, 68, 68, 0.12);  --status-danger-text: #f87171;
  --status-dirty-bg: rgba(236, 72, 153, 0.12);  --status-dirty-text: #f472b6;
  --avatar-bg: #07810f;

  --scrollbar-thumb: rgba(255, 255, 255, 0.15);
  --scrollbar-thumb-hover: rgba(255, 255, 255, 0.28);
}

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: var(--panel-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--neutral-border);
  box-shadow: var(--shadow-soft);
}

#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-primary);
  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(0, 0, 0, .3);
}

#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;
  color: var(--text-primary);
}

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

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

#status[data-state="saving"] { background: var(--status-warning-bg); color: var(--status-warning-text); }
#status[data-state="dirty"] { background: var(--status-dirty-bg); color: var(--status-dirty-text); }
#status[data-state="error"] { background: var(--status-danger-bg); color: var(--status-danger-text); }

#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 var(--accent-border);
  border-radius: 999px;
  background:
    linear-gradient(var(--panel-glass-strong), var(--panel-glass-strong)) padding-box,
    var(--guest-badge-gradient) border-box;
  color: var(--accent);
  font-size: 12px;
  font-weight: 850;
  line-height: 1;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .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(0, 0, 0, .18);
}

.account-status:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring), 0 12px 28px rgba(0, 0, 0, .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: var(--avatar-bg);
  color: var(--text-inverse);
  font-size: 18px;
  font-weight: 900;
  letter-spacing: .02em;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.2);
}

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

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

.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: var(--panel-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--neutral-border);
  border-radius: 22px;
  box-shadow: var(--shadow-strong);
  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: var(--panel-glass-strong);
  border-left: 1px solid var(--neutral-border);
  border-top: 1px solid var(--neutral-border);
}

.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: var(--avatar-bg);
  color: var(--text-inverse);
  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-primary);
  font-size: 15px;
  font-weight: 850;
}

.account-menu-email {
  max-width: 190px;
  margin-top: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-dim);
  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: var(--status-warning-bg);
  color: var(--status-warning-text);
  font-size: 11px;
  font-weight: 800;
}

.account-menu-plan.pro {
  background: var(--accent-soft);
  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: var(--panel-muted);
  color: var(--text-primary);
  font-weight: 800;
  cursor: pointer;
}

.account-menu-action:hover {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent);
}

.toolbar-btn,
#header-actions > button,
#history-controls button {
  min-width: 40px;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--neutral-border);
  background: var(--panel-muted);
  color: var(--text-primary);
  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: var(--panel-muted);
  color: var(--accent);
  border-color: var(--accent-border);
}

#header-actions > #download-trigger-btn {
  background: var(--accent-gradient);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.2);
  box-shadow: 0 4px 16px rgba(162, 29, 40, 0.25);
}

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

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

#admin-menu {
  display: none;
  width: 286px;
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  padding: 8px;
  background: var(--panel-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--neutral-border);
  border-radius: 14px;
  box-shadow: var(--shadow-strong);
  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-primary);
  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(--status-danger-text); }
#admin-menu #delete-btn .material-icons { color: var(--status-danger-text); }

#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: var(--panel-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-right: 1px solid var(--neutral-border);
  box-shadow: none;
}

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

.nav-tab {
  width: 60px;
  min-height: 58px;
  height: auto;
  padding: 8px 4px;
  border-radius: 12px;
  gap: 5px;
  color: var(--text-dim);
}

.nav-tab .material-icons { font-size: 22px; }
.nav-label { font-size: 10px; font-weight: 700; }
.nav-tab.active { box-shadow: none; color: var(--accent); background: var(--accent-soft); border: 1px solid var(--accent-border); }

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

.tab-pane h2 {
  padding: 18px 16px 12px;
  background: transparent;
  border: 0;
  color: var(--text-primary);
  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: 1px solid var(--neutral-border);
  border-radius: 10px;
  background: var(--panel-muted);
  color: var(--text-primary);
}

.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: 1px solid var(--neutral-border);
  border-radius: 10px;
  box-shadow: none;
  background: var(--panel-muted);
  color: var(--text-primary);
}

#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: 1px solid var(--neutral-border);
  border-radius: 14px;
  background: var(--panel-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow-strong);
  z-index: 1600;
}

#stage {
  min-width: 0;
  padding: 40px 48px 84px;
  justify-content: flex-start;
  align-items: flex-start;
  background: var(--workspace);
  background-image: radial-gradient(circle at 50% 30%, var(--accent-soft), transparent 50%), radial-gradient(circle at 80% 80%, rgba(255, 152, 0, 0.06), transparent 45%);
}

#stage-inner { margin: auto; }

.tm-canvas {
  background: var(--canvas-bg);
  box-shadow: var(--canvas-shadow);
  user-select: none !important;
  -webkit-user-select: none !important;
  -webkit-user-drag: none !important;
}
.tm-canvas img,
.tm-bg {
  user-select: none !important;
  -webkit-user-select: none !important;
  -webkit-user-drag: none !important;
  -khtml-user-drag: none !important;
  -moz-user-drag: none !important;
  -o-user-drag: none !important;
}
.tm-canvas [data-layer-index] {
  pointer-events: auto;
}
.tm-canvas.is-transparent-bg {
  background-image: repeating-conic-gradient(var(--checker-a) 0% 25%, var(--checker-b) 0% 50%) !important;
  background-size: 16px 16px !important;
  background-position: 0 0, 8px 8px !important;
}

#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: var(--panel-glass-strong);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow-med);
}

.zoom-preset {
  min-width: 40px;
  min-height: 34px;
  padding: 5px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-primary);
  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-primary); }
#zoomReset { width: 34px; height: 34px; padding: 0; border: 0; border-radius: 8px; color: var(--text-primary); }

#inspector {
  width: var(--inspector-width);
  background: var(--panel-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-left: 1px solid 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;
  color: var(--text-primary);
}

.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; color: var(--text-primary); }

.layer-item-row {
  min-height: 54px;
  margin-bottom: 8px;
  background: var(--panel-muted);
  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: var(--surface-hover);
  border-color: var(--neutral-border);
}

.layer-item-row.selected {
  border-color: var(--accent-2);
  background: var(--panel-glass);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
}

.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: var(--text-primary) !important;
  cursor: grab;
  border-radius: 6px;
}

.layer-drag-handle .material-icons,
.layer-drag-handle svg {
  color: var(--text-primary) !important;
  fill: var(--text-primary) !important;
}

.layer-drag-handle:hover {
  color: var(--text-primary) !important;
  background: var(--surface-hover);
}

.layer-item-select {
  min-height: 44px;
  padding: 4px 8px;
  gap: 10px;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-primary);
  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 var(--neutral-border);
  background: var(--canvas-bg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

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

.layer-shape-thumb {
  padding: 5px;
  box-sizing: border-box;
}

.layer-shape-thumb svg {
  display: block;
  width: 100%;
  height: 100%;
}

.layer-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  color: var(--text-primary);
  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: var(--text-dim);
}

.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: var(--text-primary);
  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: var(--surface-strong);
  color: var(--text-primary);
}

.layer-item-row.selected .layer-more-btn {
  background: var(--surface-strong);
  color: var(--text-primary);
}

.layer-item-row.selected .layer-more-btn:hover {
  background: var(--surface-strong);
}

#global-layer-options-menu,
.layer-options-menu.global-popup {
  display: none;
  flex-direction: column;
  position: fixed;
  z-index: 999999;
  min-width: 195px;
  background: var(--panel-glass-strong);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 12px;
  box-shadow: var(--shadow-strong);
  border: 1px solid var(--neutral-border);
  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: var(--panel-glass-strong);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 16px;
  box-shadow: var(--shadow-strong);
  border: 1px solid var(--neutral-border);
  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: var(--text-primary);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--neutral-border);
}
.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 var(--neutral-border);
}
.color-popup-close-btn {
  background: var(--panel-muted);
  border: none;
  font-size: 14px;
  color: var(--text-dim);
  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: var(--surface-hover);
  color: var(--text-primary);
}
.color-popup-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  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 var(--neutral-border);
  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.15);
}
.color-popup-swatch:hover {
  transform: scale(1.15);
  border-color: var(--accent-2);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.18);
}
.color-popup-swatch.active {
  border-color: var(--text-inverse);
  box-shadow: 0 0 0 2px var(--accent-2), 0 0 0 4px var(--accent-2);
}
.color-popup-swatch.transparent-swatch,
.text-solid-swatch[data-color="transparent"] {
  background: repeating-conic-gradient(var(--checker-a) 0% 25%, var(--checker-b) 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: var(--status-danger-text);
  transform: rotate(-45deg);
}
.color-popup-custom-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-muted);
  padding: 8px;
  border-radius: 10px;
  border: 1px solid var(--neutral-border);
}
.color-popup-hex {
  flex-grow: 1;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 600;
  font-family: monospace;
  background: var(--canvas-bg);
  border: 1px solid var(--neutral-border);
  border-radius: 8px;
  outline: none;
  text-transform: uppercase;
  color: var(--text-primary);
}
.color-popup-hex:focus {
  border-color: var(--accent-2);
}
.color-popup-ok-btn {
  width: 100% !important;
  background: var(--accent-2) !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(0, 0, 0, 0.2) !important;
  transition: transform 0.1s ease, background 0.1s ease !important;
}
.color-popup-ok-btn:hover {
  filter: brightness(0.92) !important;
  transform: translateY(-1px) !important;
}

.btn-remove-bg {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  background: var(--accent-gradient);
  color: #ffffff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
  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(0, 0, 0, 0.24);
}
.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: var(--status-danger-bg);
  color: var(--status-danger-text);
  border: 1px solid rgba(220, 38, 38, 0.3);
  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: rgba(220, 38, 38, 0.18);
  border-color: rgba(220, 38, 38, 0.5);
  color: var(--status-danger-text);
}

.bg-removal-canvas-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 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%, var(--accent) 15%, #ffffff 50%, var(--accent-2) 85%, transparent 100%);
  box-shadow: 0 0 14px var(--accent), 0 0 28px var(--accent-2), 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: var(--accent);
  border-right-color: var(--accent-2);
  border-radius: 50%;
  animation: btn-spin 0.75s linear infinite;
  box-shadow: 0 0 16px rgba(0, 0, 0, 0.3);
}

.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: var(--text-primary);
  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: var(--text-dim);
  fill: var(--text-dim);
}

.layer-action-item:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.layer-action-item:hover .material-icons,
.layer-action-item:hover svg {
  color: var(--text-primary);
  fill: var(--text-primary);
}

.layer-action-item.delete-layer:hover {
  background: var(--status-danger-bg);
  color: var(--status-danger-text);
}

.layer-action-item.delete-layer:hover .material-icons,
.layer-action-item.delete-layer:hover svg {
  color: var(--status-danger-text);
  fill: var(--status-danger-text);
}

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

.layer-action-item[disabled]:hover {
  background: transparent;
  color: var(--text-dim);
}

#properties { min-height: 0; flex: 1; background: transparent; }
.prop-group { padding: 14px 16px; border-bottom: 1px solid var(--neutral-border); }
.prop-label { color: var(--text-primary); 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; background: var(--panel-muted); color: var(--text-primary); border: 1px solid var(--neutral-border); border-radius: 6px; padding: 4px; }

#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: var(--text-dim);
  font-size: 34px;
}

.tm-selection-toolbar { top: -58px; gap: 2px; padding: 5px; border-radius: 13px; background: var(--panel-glass-strong); backdrop-filter: blur(12px); border: 1px solid var(--neutral-border); }
/* Flipped below the box (layer near the artboard's top edge) — the nearest
   edge is now the TOP one, so anchor the counter-scale there instead so the
   toolbar still grows away from the selection rather than back across it. */
.tm-selection.toolbar-below .tm-selection-toolbar { top: calc(100% + 12px); transform-origin: top center; }
.tm-selection.toolbar-below .tm-selection-bottom-controls { top: calc(100% + 64px); }
/* The frame's own hairline is inside the same double-scaled overlay — without
   this it thins to sub-pixel (1.5px x 0.55 x 0.5 = 0.4px) and visibly fades. */
.tm-selection { outline-width: calc(1.5px * var(--sel-inv-zoom, 1)); }
.tm-selection-action {
  width: 40px;
  height: 40px;
  border-radius: 9px;
  color: var(--text-primary);
  background: var(--panel-muted);
  border: 1px solid transparent;
}
.tm-selection-action:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}
.tm-selection-action svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
}
.tm-selection-action svg * {
  fill: none;
  stroke: currentColor;
}
.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 {
  font-family: 'Material Icons';
  font-weight: normal;
  font-style: normal;
  display: inline-block;
  line-height: 1;
  text-transform: none;
  letter-spacing: normal;
  word-wrap: normal;
  white-space: nowrap;
  direction: ltr;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'liga';
  pointer-events: none;
}
.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: 1px solid var(--neutral-border);
  background: var(--panel-glass);
  box-shadow: var(--shadow-med);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: var(--text-primary);
}
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; }

/* ── Redesigned Inspector Controls ────────────────────────── */

/* Section header title (like "Text Properties") */
.prop-section-title {
  padding: 14px 14px 6px;
  margin: 0;
  font-size: 14px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

/* Refined property group */
#inspector .prop-group {
  padding: 8px 14px;
  border-bottom: 1px solid var(--neutral-border);
}

#inspector .prop-group:last-child {
  border-bottom: none;
}

/* Refined prop-label — left aligned, uppercase */
#inspector .prop-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Refined prop-row */
#inspector .prop-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

#inspector .prop-row:last-child {
  margin-bottom: 0;
}

/* Value badge — right-aligned box showing slider value */
.prop-value-badge {
  min-width: 48px;
  height: 30px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 8px;
  border: 1px solid var(--neutral-border);
  background: var(--panel-muted);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Slider track (range input) refinement inside inspector */
#inspector input[type="range"] {
  flex: 1;
  min-width: 0;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--surface-strong);
  border-radius: 999px;
  outline: none;
  border: none;
}

#inspector input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

#inspector input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

/* Number input inside inspector — styled as badge */
#inspector input[type="number"] {
  min-width: 48px;
  width: 56px;
  height: 30px;
  padding: 0 6px;
  flex-shrink: 0;
  border-radius: 8px;
  border: 1px solid var(--neutral-border);
  background: var(--panel-muted);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: center;
  outline: none;
}

#inspector input[type="number"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

/* Font picker button refinement */
#inspector .textart-font-button {
  width: 100%;
  min-height: 36px;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 10px;
  border: 1px solid var(--neutral-border);
  background: var(--panel-muted);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

#inspector .textart-font-button::after {
  content: '▾';
  font-size: 14px;
  color: var(--text-dim);
  margin-left: 8px;
}

#inspector .textart-font-button:hover {
  border-color: var(--surface-strong);
}

/* Segmented control for font weight */
.segmented-control {
  display: flex;
  gap: 0;
  border-radius: 10px;
  border: 1px solid var(--neutral-border);
  background: var(--panel-muted);
  overflow: hidden;
}

.segment-btn {
  flex: 1;
  min-height: 34px;
  padding: 6px 10px;
  border: none;
  border-right: 1px solid var(--neutral-border);
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.segment-btn:last-child {
  border-right: none;
}

.segment-btn:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.segment-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

/* Alignment icon row refinement */
#text-align-controls .prop-row {
  display: flex;
  gap: 4px;
}

#text-align-controls .aspect-btn.icon-btn {
  flex: 1;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--neutral-border);
  background: var(--panel-muted);
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.15s ease;
}

#text-align-controls .aspect-btn.icon-btn:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

#text-align-controls .aspect-btn.icon-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent);
}

/* Color swatch palette header */
.swatch-palette-header {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Color swatches grid — neat 7-column layout */
#text-solid-swatches.text-preset-grid,
#text-gradient-presets.text-preset-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-top: 8px;
}

.text-solid-swatch,
.text-gradient-preset {
  width: 100%;
  aspect-ratio: 1;
  height: auto;
  border-radius: 6px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.text-solid-swatch:hover,
.text-gradient-preset:hover {
  transform: scale(1.15);
  border-color: var(--surface-strong);
}

.text-solid-swatch.active,
.text-gradient-preset.active {
  border-color: #fff;
  box-shadow: 0 0 0 2px var(--accent-soft);
}

/* "Custom color" button */
#text-solid-more,
#text-gradient-more {
  width: 100%;
  min-height: 32px;
  margin-top: 8px;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--neutral-border);
  background: var(--panel-muted);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

#text-solid-more:hover,
#text-gradient-more:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

/* Header center capsule for undo/redo + status */
#history-controls {
  gap: 2px;
  padding: 4px 6px;
  border-radius: 999px;
  background: var(--panel-muted);
  border: 1px solid var(--neutral-border);
}

#history-controls button {
  width: 34px;
  min-width: 34px;
  min-height: 34px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
}

#history-controls button:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--text-primary);
}

#history-controls button:disabled {
  opacity: 0.3;
}

/* Status badge inside the header capsule look */
#document-meta #status {
  font-size: 11px;
}

/* prop-row-label inside inspector refined */
#inspector .prop-row-label {
  min-width: 48px;
  padding: 0 6px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 8px;
  border: 1px solid var(--neutral-border);
  background: var(--panel-muted);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: center;
  width: auto;
}

/* Theme toggle (header) */
#theme-toggle-btn {
  min-width: 40px;
  min-height: 40px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 1px solid var(--neutral-border);
  background: var(--panel-muted);
  color: var(--text-primary);
  cursor: pointer;
}
#theme-toggle-btn:hover { background: var(--surface-hover); }
#theme-toggle-btn .material-icons { font-size: 20px; }
#theme-toggle-btn .theme-toggle-icon-dark { display: none; }
:root[data-theme="dark"] #theme-toggle-btn .theme-toggle-icon-light { display: none; }
:root[data-theme="dark"] #theme-toggle-btn .theme-toggle-icon-dark { display: inline-block; }

@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: var(--shadow-strong);
  }
  #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; }
  #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 {
    position: fixed;
    left: 0;
    right: 0;
    bottom: var(--mobile-nav-bar-height, 60px);
    top: auto;
    width: 100%;
    max-height: 55vh;
    overflow-y: auto;
    transform: translateY(calc(100% + var(--mobile-nav-bar-height, 60px)));
    transition: transform .22s ease;
    border-radius: 16px 16px 0 0;
    box-shadow: var(--shadow-strong);
    z-index: 1002;
    background: var(--panel-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-left: none;
    border-top: 1px solid var(--neutral-border);
  }
  #inspector.visible { transform: translateY(0); }

  #mobile-zoom-btn {
    display: flex !important;
  }

  #mobile-zoom-popover {
    position: fixed;
    top: var(--app-header-height, 60px);
    right: 12px;
    background: var(--panel-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: 12px;
    box-shadow: var(--shadow-med);
    border: 1px solid var(--neutral-border);
    padding: 12px;
    z-index: 1005;
    min-width: 230px;
  }

  #mobile-nudge-pad {
    display: grid;
    grid-template-columns: repeat(3, 38px);
    grid-template-rows: repeat(3, 38px);
    gap: 4px;
    justify-content: center;
    margin-top: 6px;
  }

  #mobile-nudge-pad button {
    background: var(--panel-muted);
    border: 1px solid var(--neutral-border);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    outline: none;
    color: var(--text-primary);
  }

  #mobile-nudge-pad button:active {
    background: var(--surface-hover);
  }

  #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;
    background: var(--panel-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
  }
  #library-nav .nav-tab {
    flex: 0 0 auto;
    min-width: 52px;
  }
  #library-nav [data-tab="legacy"] { display: none; }

  #library-content {
    position: fixed;
    left: 0;
    right: 0;
    bottom: var(--mobile-nav-bar-height, 60px);
    width: 100%;
    max-height: 55vh;
    overflow-y: auto;
    transform: translateY(calc(100% + var(--mobile-nav-bar-height, 60px)));
    transition: transform .22s ease;
    border-radius: 16px 16px 0 0;
    box-shadow: var(--shadow-strong);
    z-index: 1001;
    background: var(--panel-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--neutral-border);
  }
  #library.visible #library-content { transform: translateY(0); }

  #toggle-library-btn { display: none !important; }

  #stage { padding-bottom: calc(var(--mobile-nav-bar-height, 60px) + 12px) !important; }
  #zoom-bar { bottom: calc(var(--mobile-nav-bar-height, 60px) + env(safe-area-inset-bottom, 0px) + 12px); }
}

.header-upgrade-pill {
  display: inline-flex;
  align-items: center;
  gap: 0;
  padding: 6px 9px;
  background: var(--panel-glass);
  color: var(--accent-2);
  border: 1px solid rgba(255, 152, 0, 0.3);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(255, 152, 0, 0.15);
  transition: all 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
  line-height: 1;
  overflow: hidden;
  max-width: 34px;
}

.header-upgrade-pill .button-label {
  opacity: 0;
  max-width: 0;
  transition: opacity 0.2s ease, max-width 0.28s cubic-bezier(0.4, 0, 0.2, 1), margin-left 0.2s ease;
  overflow: hidden;
  white-space: nowrap;
  margin-left: 0;
}

.header-upgrade-pill:hover {
  max-width: 170px;
  padding: 6px 14px 6px 10px;
  background: linear-gradient(135deg, var(--panel-glass) 0%, rgba(255, 152, 0, 0.12) 100%);
  border-color: var(--accent-2);
  box-shadow: 0 4px 14px rgba(255, 152, 0, 0.3);
  transform: translateY(-1px);
}

.header-upgrade-pill:hover .button-label {
  opacity: 1;
  max-width: 120px;
  margin-left: 6px;
}

.header-upgrade-pill .material-icons {
  font-size: 18px;
  color: var(--status-warning-text);
  flex-shrink: 0;
}

@media (max-width: 900px) {
  .toolbar-btn .button-label {
    display: none !important;
  }
  .toolbar-btn {
    padding: 6px 10px !important;
    min-width: 36px;
    justify-content: center;
  }
  .account-status-name,
  .account-status-plan {
    display: none !important;
  }
  .account-status {
    padding: 4px 8px !important;
  }
}
