:root {
  color-scheme: dark;
  --bg-0: #0b0d12;
  --bg-1: #10131a;
  --bg-2: #151925;
  --bg-3: #1c2130;
  --bg-4: #252c3e;
  --surface: #141822;
  --surface-hover: #1a1f2d;
  --border-1: #1e2435;
  --border-2: #2a3246;
  --text-1: #e6e9f2;
  --text-2: #b0b7c7;
  --text-3: #6f778a;
  --text-4: #4b5265;
  --accent: #5eead4;
  --accent-dim: rgba(94, 234, 212, 0.12);
  --accent-mid: rgba(94, 234, 212, 0.4);
  --accent-strong: #2dd4bf;
  --danger: #f87171;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.5);
  --radius-xs: 3px;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --font-sans: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --panel-width: 260px;
  --tick-pct: 0%;
  --val-pct: 0%;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg-0);
  color: var(--text-1);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100vh;
  overflow: hidden;
}

button, input { font: inherit; }
button { cursor: pointer; border: 0; background: none; color: inherit; }
button:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.app-root {
  display: flex;
  flex-direction: column;
  height: calc(100vh / 1.1);
  min-height: 0;
  zoom: 1.1;
}

/* ==================== Topbar ==================== */
.app-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  height: 44px;
  padding: 0 14px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border-1);
  z-index: 20;
}

.topbar-left,
.topbar-center,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-right {
  gap: 6px;
}

.topbar-divider {
  width: 1px;
  height: 20px;
  background: var(--border-2);
  flex-shrink: 0;
}

.btn.btn-upload--mobile { display: none; }
.btn.btn-upload--desktop { display: inline-flex; }

.btn-upload input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

.btn-video-upload {
  position: relative;
  width: 100%;
  justify-content: center;
  margin-bottom: 4px;
}

.btn-video-upload input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-mark {
  width: 32px;
  height: 32px;
  color: var(--accent);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  transform: translateY(1px);
}

.brand-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-1);
}

.brand-en {
  font-family: var(--font-sans);
  font-size: 9px;
  color: var(--text-4);
}

.menu-wrap {
  position: relative;
}

.btn-menu {
  gap: 4px;
}

.menu-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 16px;
  padding: 0 5px;
  border-radius: 8px;
  background: var(--bg-4);
  color: var(--text-2);
  font-size: 10px;
  font-weight: 700;
  font-family: var(--font-mono);
  line-height: 1;
}

.menu-popover {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 260px;
  max-width: 320px;
  background: var(--bg-2);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45), 0 2px 8px rgba(0, 0, 0, 0.3);
  z-index: 50;
  overflow: hidden;
  opacity: 0;
  transform: translateY(-6px) scale(0.97);
  transform-origin: top left;
  transition: opacity 160ms var(--ease), transform 180ms var(--ease);
}

.menu-popover.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.popover-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border-1);
  background: var(--bg-3);
}

.popover-close {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  color: var(--text-3);
  font-size: 11px;
  display: grid;
  place-items: center;
  transition: background 120ms var(--ease), color 120ms var(--ease);
}
.popover-close:hover { background: var(--bg-4); color: var(--text-1); }

.popover-list {
  list-style: none;
  padding: 4px;
  margin: 0;
  max-height: 320px;
  overflow-y: auto;
}

.popover-list:empty::before {
  content: attr(data-empty);
  display: block;
  padding: 20px 12px;
  text-align: center;
  font-size: 11px;
  color: var(--text-4);
}

.popover-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 100ms var(--ease);
}
.popover-item:hover { background: var(--bg-3); }
.popover-item.is-active { background: var(--accent-dim); }

.popover-thumb {
  width: 32px;
  height: 32px;
  border-radius: 5px;
  background: var(--bg-4) center/cover no-repeat;
  flex-shrink: 0;
  border: 1px solid var(--border-1);
}

.popover-meta {
  flex: 1;
  min-width: 0;
}

.popover-name {
  display: block;
  font-size: 12px;
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.popover-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
}

.popover-kind {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
  padding: 3px 6px;
  border-radius: 4px;
}
.popover-kind--image { background: rgba(52, 211, 153, 0.15); color: #34d399; }
.popover-kind--gif   { background: rgba(167, 139, 250, 0.15); color: #a78bfa; }
.popover-kind--video { background: rgba(96, 165, 250, 0.15); color: #60a5fa; }

.popover-dims {
  font-size: 11px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.popover-delete-btn {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  color: var(--text-3);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  cursor: pointer;
  border: none;
  background: transparent;
  padding: 0;
  transition: color 120ms var(--ease), background 120ms var(--ease);
}
.popover-delete-btn:hover { color: #fff; background: rgba(239, 68, 68, 0.35); }
.popover-delete-btn svg { pointer-events: none; }

.popover-item.is-dragging { opacity: 0.45; }
.popover-item.is-drop-target { outline: 2px solid var(--accent); outline-offset: -2px; }

.popover-foot {
  padding: 8px 12px;
  border-top: 1px solid var(--border-1);
  background: var(--bg-3);
  text-align: right;
}

.export-menu-wrap .export-popover {
  right: 0;
  left: auto;
  min-width: 130px;
  top: calc(100% + 6px);
  transform-origin: top right;
}

.menu-wrap.is-right .menu-popover {
  right: 0;
  left: auto;
  min-width: 96px;
  top: calc(100% + 6px);
  transform-origin: top right;
}

.export-menu-wrap .chev-icon {
  transition: transform 160ms var(--ease);
  opacity: 0.85;
}
.export-menu-wrap [aria-expanded="true"] .chev-icon {
  transform: rotate(180deg);
}

.menu-item {
  width: 100%;
  padding: 8px 12px;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: var(--radius-md);
  transition: background 120ms var(--ease), color 120ms var(--ease);
}
.menu-item:hover {
  background: var(--accent-dim);
  color: var(--accent);
}

.menu-item-accent {
  color: var(--accent);
}
.menu-item-accent:hover {
  background: var(--accent);
  color: #042f2e;
}

.menu-divider {
  height: 1px;
  background: var(--border-1);
  margin: 4px 8px;
  list-style: none;
}

.btn-sm {
  height: 24px;
  padding: 0 8px;
  font-size: 11px;
}

.btn-ghost:hover {
  background: var(--bg-3);
  color: var(--text-1);
}

.btn-danger {
  color: #f87171;
}
.btn-danger:hover { background: rgba(239, 68, 68, 0.35) !important; color: #fff !important; }

.control-panel.is-disabled {
  opacity: 0.5;
  pointer-events: none;
  filter: grayscale(0.4);
  transition: opacity 160ms var(--ease), filter 160ms var(--ease);
}

.confirm-overlay {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--accent) 22%, rgba(0, 0, 0, 0.72));
  display: grid;
  place-items: center;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.3s var(--ease);
}
.confirm-overlay.is-danger .btn-primary,
.confirm-overlay.is-critical .btn-primary {
  background: var(--danger);
  border-color: var(--danger);
  color: #230202;
}
.confirm-overlay.is-danger .btn-primary:hover,
.confirm-overlay.is-critical .btn-primary:hover {
  background: #ef4444;
  border-color: #ef4444;
}
.confirm-overlay.is-critical {
  background: color-mix(in srgb, #5d1212 28%, rgba(0, 0, 0, 0.72));
}
.confirm-overlay.is-visible { opacity: 1; }

.confirm-dialog {
  width: min(360px, calc(100vw - 32px));
  background: var(--bg-2);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.5);
  padding: 22px 24px 18px;
  animation: dialogIn 140ms var(--ease);
}

@keyframes dialogIn {
  from { opacity: 0; transform: translateY(-6px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.confirm-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-1);
  margin-bottom: 14px;
}

.confirm-body {
  font-size: 14px;
  color: var(--text-2);
  line-height: 1.5;
  margin-bottom: 30px;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.confirm-dialog .btn {
  height: 30px;
  padding: 0 12px;
  font-size: 14px;
}

.about-dialog {
  position: relative;
}
.about-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 0;
  background: transparent;
  color: var(--text-4);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: color 120ms var(--ease), background 120ms var(--ease);
}
.about-close:hover { color: var(--text-1); background: var(--bg-3); }
.about-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}
.about-logo {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  color: var(--accent);
}
.about-text {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.about-name {
  font-size: 18px;
  font-weight: 800;
  color: var(--text-1);
}
.about-en {
  font-size: 10px;
  color: var(--text-4);
  text-transform: uppercase;
}
.about-version {
  font-size: 11px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}
.about-credits {
  margin-left: 4px;
  margin-top: 18px;
  font-size: 11px;
  color: var(--text-3);
  line-height: 1.6;
}
.about-credits a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s;
}
.about-credits a:hover {
  border-bottom-color: var(--accent);
}
.about-credits > div:last-child {
  padding-left: 1px;
}
.about-dialog .confirm-actions {
  margin-top: 30px;
}
.setting-desc {
  margin-top: 4px;
  margin-bottom: 16px;
  font-size: 11px;
  line-height: 1.6;
  color: var(--text-3);
}
.setting-force-hint {
  font-size: 10px;
  color: var(--text-4);
  font-weight: 500;
}
.settings-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-1);
  margin-top: 0;
  margin-bottom: 18px;
}
.settings-dialog .confirm-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.settings-dialog .toggle-sm .toggle-label,
.settings-dialog .settings-action-btn .toggle-label {
  font-size: 13px;
  cursor: default;
  pointer-events: none;
}
.settings-dialog .toggle-sm {
  pointer-events: none;
}
.settings-dialog .setting-desc {
  margin-top: -12px;
  margin-bottom: 0;
  padding-left: 33px;
}
.settings-divider {
  height: 1px;
  margin: 12px 0 12px;
  background: var(--border-1, rgba(255, 255, 255, 0.08));
}
.settings-dialog .toggle-sm input,
.settings-dialog .toggle-sm .toggle-track {
  pointer-events: auto;
}
.settings-action-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0;
  margin: 0;
  background: transparent;
  border: none;
  pointer-events: none;
  width: 100%;
}
.settings-action-icon {
  width: 28px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-4);
  color: var(--text-2);
  flex-shrink: 0;
  pointer-events: auto;
  cursor: pointer;
  transition: background-color 120ms var(--ease), color 120ms var(--ease);
}
.settings-action-btn:hover .settings-action-icon {
  background: color-mix(in srgb, var(--bg-4) 85%, #fff);
  color: var(--text-1);
}
.btn-link {
  background: transparent;
  border: none;
  color: var(--accent);
  padding: 4px 10px;
  font-size: inherit;
  cursor: pointer;
  text-decoration: none;
  border-radius: var(--radius-sm);
}
.btn-link:hover {
  background: rgba(255, 255, 255, 0.08);
}

/* Buttons */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 10px;
  border-radius: var(--radius-md);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background 120ms var(--ease), border-color 120ms var(--ease), color 120ms var(--ease);
}

.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border: 1px solid transparent;
}
.btn-ghost:hover {
  background: var(--bg-3);
  color: var(--text-1);
}

.btn-full {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  margin-bottom: 6px;
}

.btn-full:last-child {
  margin-bottom: 0;
}

.btn-export {
  padding: 8px 12px;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 0;
  text-align: left;
  position: relative;
}

.btn-export svg {
  flex-shrink: 0;
  margin-right: 8px;
}

.btn-main {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-1);
  line-height: 1.3;
}

.btn-sub {
  margin-left: auto;
  font-size: 10px;
  color: var(--text-4);
  line-height: 1;
}

.btn-export.is-busy .btn-main {
  color: var(--accent);
}

.btn-export.is-busy .btn-sub {
  opacity: 0.7;
}

.btn-export:not(.is-busy) .btn-sub {
  display: none;
}

.btn-primary {
  background: var(--accent);
  color: #042f2e;
  border: 1px solid var(--accent);
}
.btn-primary:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-md);
  display: grid;
  place-items: center;
  color: var(--text-2);
  transition: background 120ms var(--ease), color 120ms var(--ease);
}
.icon-btn:hover { background: var(--bg-3); color: var(--text-1); }

.mobile-tip {
  display: none;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  padding: 6px 14px;
  background: rgba(245, 158, 11, 0.12);
  color: #fbbf24;
  font-size: 11px;
  line-height: 1.3;
  border-bottom: 1px solid rgba(245, 158, 11, 0.2);
}
.mobile-tip span { flex: 1; }
.mobile-tip.hidden { display: none !important; }
.mobile-tip-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  border-radius: 4px;
  opacity: 0.7;
  transition: opacity 120ms var(--ease), background 120ms var(--ease);
}
.mobile-tip-close:hover { opacity: 1; background: rgba(245, 158, 11, 0.2); }

/* ==================== Body Layout ==================== */
.app-body {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ==================== Control Panel ==================== */
.control-panel {
  width: var(--panel-width);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-1);
  border-right: 1px solid var(--border-1);
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-gutter: stable;
  transition: transform 220ms var(--ease), opacity 180ms var(--ease), margin-left 220ms var(--ease), margin-top 220ms var(--ease);
  scrollbar-width: thin;
  scrollbar-color: var(--bg-4) transparent;
}

.control-panel::-webkit-scrollbar { width: 5px; }
.control-panel::-webkit-scrollbar-track { background: transparent; }
.control-panel::-webkit-scrollbar-thumb {
  background: var(--bg-4);
  border-radius: 3px;
}

html.panel-collapsed .control-panel {
  transform: translateX(-100%);
  margin-left: calc(-1 * var(--panel-width, 260px));
  opacity: 0;
  pointer-events: none;
  border-right: 0;
}

/* ==================== Panel Toggle Button ==================== */
.btn-panel-toggle {
  flex-shrink: 0;
  padding: 0;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-panel-toggle .icon-collapsed { display: none; }
html.panel-collapsed .btn-panel-toggle .icon-open { display: none; }
html.panel-collapsed .btn-panel-toggle .icon-collapsed { display: block; }

/* ==================== Panel Tabs ==================== */
.panel-tabs {
  display: flex;
  gap: 4px;
  margin: 4px 10px 2px;
  padding: 3px;
  background: var(--bg-3);
  border: 1px solid var(--border-1);
  border-radius: 8px;
}

.panel-tab {
  flex: 1;
  padding: 3px 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.panel-tab:hover { color: var(--text-1); }

.panel-tab.is-active {
  color: var(--text-1);
  background: var(--bg-1);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* ==================== Panel Sections ==================== */
.control-panel {
  gap: 10px;
  padding: 12px 0;
}

.panel-section {
  display: flex;
  flex-direction: column;
  margin: 0 10px;
  background: var(--bg-2);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-sm, 8px);
}

.panel-section-footer {
}

.panel-section:has([data-control="morph"]:not(:checked)) .panel-body {
  opacity: 0.4;
  pointer-events: none;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 12px 12px;
}

.section-header-left {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.toggle-compact {
  padding: 0;
  border: none !important;
  background: transparent !important;
  outline: none;
  box-shadow: none !important;
}

.toggle-compact:hover {
  background: transparent;
  border-color: transparent;
  outline: none;
  box-shadow: none;
}

.toggle-compact .toggle-track {
  width: 26px;
  height: 14px;
}

.toggle-compact .toggle-thumb {
  width: 10px;
  height: 10px;
  top: 2px;
  left: 2px;
}

.toggle-compact input:checked + .toggle-track .toggle-thumb {
  transform: translateX(12px);
}

.section-label {
  font-size: 13px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.section-hint {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-4);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.notice-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 4px 10px 8px;
  padding: 7px 10px;
  font-size: 11px;
  line-height: 1.4;
  color: var(--text-2);
  background: rgba(251, 191, 36, 0.08);
  border: 1px solid rgba(251, 191, 36, 0.22);
  border-radius: var(--radius-md);
}

.notice-bar svg {
  flex-shrink: 0;
  color: #fbbf24;
}

.panel-body {
  padding: 0 12px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toggle-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ==================== Rows & Segmented ==================== */
.panel-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.panel-row-inline {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

.row-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
}

.segmented {
  display: grid;
  gap: 0;
  background: var(--bg-2);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  overflow: hidden;
  grid-template-columns: repeat(auto-fit, minmax(32px, 1fr));
}

.segmented-two { grid-template-columns: repeat(2, 1fr); }
.segmented-five { grid-template-columns: repeat(5, 1fr); }

.segmented button {
  min-width: 0;
  padding: 6px 4px;
  background: transparent;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  transition: background 100ms var(--ease), color 100ms var(--ease);
}

.segmented button:hover {
  color: var(--text-1);
  background: var(--bg-3);
}

.segmented button.is-active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 700;
}

/* ==================== Sliders ==================== */
.slider-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.slider-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
}

.slider-head output {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  color: var(--text-4);
  padding: 2px 6px;
  background: var(--bg-2);
  border-radius: var(--radius-xs);
  min-width: 40px;
  text-align: right;
}

.slider-row input[type="range"] {
  width: 100%;
  height: 20px;
  padding: 0;
  -webkit-appearance: none;
  appearance: none;
  background-color: transparent;
  background-image: linear-gradient(
    to bottom,
    transparent 25%,
    var(--bg-4) 25%,
    var(--bg-4) 75%,
    transparent 75%
  );
  background-size: 2px 100%;
  background-position: var(--tick-pct) 0;
  background-repeat: no-repeat;
  cursor: pointer;
}

.slider-row input[type="range"]::-webkit-slider-runnable-track {
  height: 2px;
  border-radius: 2px;
  background: var(--bg-4);
}

.slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  background: var(--bg-1);
  margin-top: -5px;
  transition: transform 100ms var(--ease), box-shadow 100ms var(--ease);
}

.slider-row input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
  box-shadow: 0 0 0 4px var(--accent-dim);
}

.slider-row input[type="range"]::-moz-range-track {
  height: 2px;
  border-radius: 2px;
  background: var(--bg-4);
}

.slider-row input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  background: var(--bg-1);
}

/* ==================== Swatches ==================== */
.swatches {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.swatch-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: opacity 120ms var(--ease);
}
.swatch-item.is-disabled {
  opacity: 0.125;
  pointer-events: none;
}
.swatch-item.is-disabled .swatch-box {
  cursor: default;
  filter: grayscale(1);
}
.swatch-item.is-disabled .swatch-box:hover { border-color: var(--border-1); transform: none; }

.swatch-label {
  font-size: 9px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  text-align: center;
}

.swatch-box {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-1);
  background: var(--bg-2);
  cursor: pointer;
  transition: border-color 120ms var(--ease), transform 120ms var(--ease);
}
.swatch-box:hover { border-color: var(--accent-mid); transform: scale(1.05); }

.swatch-box input[type="color"] {
  position: absolute;
  inset: -4px;
  width: calc(100% + 8px);
  height: calc(100% + 8px);
  border: 0;
  padding: 0;
  cursor: pointer;
  background: transparent;
}

.swatch-box input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.swatch-box input[type="color"]::-webkit-color-swatch {
  border: 0;
  border-radius: var(--radius-sm);
}

/* ==================== Toggles ==================== */
.toggles {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.toggle {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  background: var(--bg-2);
  border: 1px solid var(--border-1);
  cursor: pointer;
  transition: border-color 120ms var(--ease), background 120ms var(--ease);
}
.toggle:hover { border-color: var(--border-2); background: var(--surface-hover); }

.toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  outline: none;
}

.toggle-track {
  position: relative;
  width: 28px;
  height: 16px;
  border-radius: 8px;
  background: var(--bg-4);
  flex-shrink: 0;
  transition: background-color 120ms var(--ease);
}
.toggle-sm:hover .toggle-track {
  background: var(--bg-3);
}
.toggle-sm:hover .toggle-thumb {
  background: color-mix(in srgb, var(--text-2) 80%, #000);
}
.toggle-sm input:checked:hover + .toggle-track {
  background: color-mix(in srgb, var(--accent-dim) 80%, #000);
}
.toggle-sm input:checked:hover + .toggle-track .toggle-thumb {
  background: color-mix(in srgb, var(--accent) 80%, #000);
}

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text-2);
  transition: transform 150ms var(--ease), background 150ms var(--ease);
}

.toggle input:checked + .toggle-track {
  background: var(--accent-dim);
}
.toggle input:checked + .toggle-track .toggle-thumb {
  transform: translateX(12px);
  background: var(--accent);
}
.toggle input:disabled + .toggle-track {
  opacity: 0.5;
}
.toggle input:disabled + .toggle-track .toggle-thumb {
  opacity: 0.7;
}

.toggle-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

/* ==================== Play Button ==================== */
.toolbar-controls {
  display: flex;
  align-items: center;
  gap: 0;
  min-width: 0;
}
.toolbar-controls .play-btn {
  flex-shrink: 0;
  margin-right: 8px;
}
.toolbar-controls .hint {
  flex-shrink: 0;
}
.toolbar-controls .toggle-track,
.toolbar-controls .toggle input {
  flex-shrink: 0;
}
.toolbar-controls .toggle-sm {
  margin-right: 8px;
}

.toggle-sm {
  --toggle-height: 20px;
  --toggle-thumb: 14px;
  gap: 0;
  font-size: 11px;
  padding: 0;
  background: transparent;
  border: none;
  min-width: 0;
  flex-shrink: 1;
}
.toggle-sm:hover { background: transparent; }
.toggle-sm .toggle-label {
  font-size: 11px;
  flex-shrink: 1;
  margin-left: 5px;
  min-width: 0;
}

.hint {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  color: var(--text-4);
  cursor: help;
  border-radius: 50%;
  transition: color 120ms var(--ease), background 120ms var(--ease);
}
.hint:hover,
.hint:focus-visible {
  color: var(--text-2);
  background: var(--bg-3);
  outline: none;
}
.hint-bubble {
  position: absolute;
  left: 50%;
  top: calc(100% + 8px);
  transform: translateX(-50%) translateY(-4px);
  min-width: 200px;
  max-width: 260px;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--bg-4);
  color: var(--text-1);
  font-size: 11px;
  line-height: 1.5;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-2);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 140ms var(--ease), transform 140ms var(--ease), visibility 140ms;
  white-space: normal;
  z-index: 100;
}
.hint-bubble::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 100%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-bottom-color: var(--bg-4);
}
.hint:hover .hint-bubble,
.hint:focus-visible .hint-bubble {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.play-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: var(--bg-2);
  border: 1px solid var(--border-1);
  color: var(--text-2);
  display: grid;
  place-items: center;
  transition: background 120ms var(--ease), color 120ms var(--ease), border-color 120ms var(--ease);
}

.play-btn:hover {
  background: var(--accent-dim);
  border-color: var(--accent-mid);
  color: var(--accent);
}

.play-btn[hidden] {
  display: none !important;
}

.play-btn .play-icon { display: none; }
.play-btn.playing .play-pause { display: block; }
.play-btn:not(.playing) .play-play { display: block; }

.toolbar-controls .play-btn {
  width: 26px;
  height: 26px;
}

.btn-reset-params {
  margin-top: auto;
  align-self: center;
  justify-content: center;
}

/* ==================== Canvas Area ==================== */
.canvas-area {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-0);
}

.canvas-toolbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  height: 36px;
  padding: 0 14px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border-1);
}

.toolbar-left,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.toolbar-left {
  flex-shrink: 1;
  min-width: 68px;
}

.toolbar-right {
  gap: 6px;
  flex-shrink: 1;
  min-width: 0;
  overflow: hidden;
  justify-content: flex-end;
}

.mode-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  font-family: var(--font-mono);
  padding-right: 10px;
  border-right: 1px solid var(--border-1);
}

.tag-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 var(--accent-dim); }
  50% { opacity: 0.7; box-shadow: 0 0 0 4px transparent; }
}

.info-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 12px;
  background: var(--bg-2);
  border: 1px solid var(--border-1);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  color: var(--text-3);
  white-space: nowrap;
  flex-shrink: 0;
}
.toolbar-right .info-pill:has([data-caption]) {
  min-width: 0;
  flex-shrink: 1;
  overflow: hidden;
}
.info-pill > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.info-pill.is-hidden {
  display: none;
}

.info-pill:has([data-caption].is-exporting) {
  background: rgba(249, 115, 22, 0.12);
  border-color: rgba(249, 115, 22, 0.45);
  color: #fb923c;
}

.canvas-wrap {
  flex: 1;
  min-height: 0;
  margin: 0;
  position: relative;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  background-image:
    linear-gradient(45deg, #131722 25%, transparent 25%),
    linear-gradient(-45deg, #131722 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #131722 75%),
    linear-gradient(-45deg, transparent 75%, #131722 75%);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
  background-color: #1a1f2d;
}

.canvas-wrap:active { cursor: grabbing; }

.canvas-wrap canvas {
  display: block;
  position: absolute;
  left: 0;
  top: 0;
  border: none;
  border-radius: var(--radius-sm);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.04), 0 8px 40px rgba(0,0,0,0.6);
  user-select: none;
  touch-action: none;
}
.canvas-wrap canvas.is-hidden {
  opacity: 0;
}

.canvas-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  height: 24px;
  padding: 0 14px;
  background: var(--bg-1);
  border-top: 1px solid var(--border-1);
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-4);
}

.footer-sep { opacity: 0.5; }

/* ==================== Responsive ==================== */
@media (max-width: 1100px) {
  :root { --panel-width: 232px; }
  .swatches { grid-template-columns: repeat(5, 1fr); gap: 4px; }
}

@media (max-width: 640px) {
  html, body {
    min-height: 100dvh;
    height: 100dvh;
    overflow: hidden;
  }

  .app-root {
    height: 100dvh;
    zoom: 1;
  }

  .mobile-tip { display: flex; }

  .app-topbar {
    flex-wrap: wrap;
    height: auto;
    padding: 8px 10px;
    gap: 6px;
  }

  .topbar-left { gap: 6px; }
  .topbar-center { display: none; }
  .topbar-right { width: 100%; flex-wrap: wrap; gap: 4px; }
  .topbar-right .btn-panel-toggle { margin-right: auto; }

  .btn { height: 26px; padding: 0 8px; font-size: 11px; }

  .panel-section-footer { margin-bottom: 12px; }

  html.panel-collapsed .control-panel {
    margin-top: 0;
  }

  .topbar-divider { display: none; }

  .btn.btn-upload--desktop { display: none; }
  .btn.btn-upload--mobile { display: inline-flex; }

  .canvas-toolbar { display: none; }
  .canvas-footer { display: none; }

  .swatches { grid-template-columns: repeat(5, 1fr); }

  .toggle-group .panel-row-inline {
    justify-content: space-between;
  }
  .toggle-group .toggle {
    margin-left: auto;
  }

  .btn-panel-toggle { width: 36px; height: 36px; }
  .btn-panel-toggle svg { width: 20px; height: 20px; }

  .slider-row input[type="range"] { display: none; }
  .slider-row { gap: 0; }
  .slider-head {
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    background-color: var(--bg-2);
    background-image:
      linear-gradient(to right, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.03));
    background-size: var(--val-pct, 0%) 100%;
    background-position: left center;
    background-repeat: no-repeat;
    cursor: pointer;
    transition: background-color 120ms var(--ease);
  }
  .slider-head:active { background-color: var(--bg-3); }
  .slider-head output {
    background: transparent;
    padding: 0;
  }

  .menu-popover,
  .export-menu-wrap .export-popover,
  .menu-wrap.is-right .menu-popover {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) scale(0.92) !important;
    transform-origin: center !important;
    min-width: 280px !important;
    max-width: calc(100vw - 64px) !important;
    width: min(320px, calc(100vw - 64px));
    max-height: 80vh !important;
    z-index: 1000 !important;
  }
  .menu-popover.is-open,
  .export-menu-wrap .export-popover.is-open,
  .menu-wrap.is-right .menu-popover.is-open {
    transform: translate(-50%, -50%) scale(1) !important;
  }
  .menu-popover::before,
  .export-menu-wrap .export-popover::before,
  .menu-wrap.is-right .menu-popover::before {
    display: none;
  }
  .popover-list { max-height: min(320px, calc(80vh - 120px)); }
}

body.slider-anti-mistouch .slider-row input[type="range"] { display: none; }
body.slider-anti-mistouch .slider-row { gap: 0; }
body.slider-anti-mistouch .slider-head {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background-color: var(--bg-2);
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.03));
  background-size: var(--val-pct, 0%) 100%;
  background-position: left center;
  background-repeat: no-repeat;
  cursor: pointer;
  transition: background-color 120ms var(--ease);
}
body.slider-anti-mistouch .slider-head:active { background-color: var(--bg-3); }
body.slider-anti-mistouch .slider-head output {
  background: transparent;
  padding: 0;
}

/* Slider popover (mobile) */
.slider-popover {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.slider-popover__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 200ms var(--ease);
}

.popover-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  z-index: 10;
  display: none;
}

@media (max-width: 640px) {
  .popover-backdrop {
    display: block;
    opacity: 1;
    pointer-events: auto;
  }
}
.slider-popover__panel {
  position: relative;
  width: 100%;
  max-width: 480px;
  background: var(--bg-1);
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform 220ms var(--ease);
}
.slider-popover.is-open .slider-popover__backdrop { opacity: 1; }
.slider-popover.is-open .slider-popover__panel { transform: translateY(0); }
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.slider-popover__label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.slider-popover__label span {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-1);
}
.slider-popover__label output {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-4);
  padding: 4px 10px;
  background: var(--bg-2);
  border-radius: var(--radius-xs);
  min-width: 48px;
  text-align: right;
}
.slider-popover input[type="range"] {
  width: 100%;
  height: 44px;
  padding: 0;
  margin: 0;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  position: relative;
}
.slider-popover input[type="range"]::before {
  content: '';
  position: absolute;
  top: 50%;
  left: var(--tick-pct, 50%);
  width: 3px;
  height: 40px;
  transform: translate(-50%, -50%);
  background: var(--text-3);
  opacity: 0.35;
  pointer-events: none;
}
.slider-popover input[type="range"]::-webkit-slider-runnable-track {
  height: 28px;
  border-radius: 6px;
  background-color: var(--bg-4);
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0.5));
  background-size: var(--val-pct, 0%) 100%;
  background-position: left center;
  background-repeat: no-repeat;
}
.slider-popover input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  margin-top: 0;
}
.slider-popover input[type="range"]::-moz-range-track {
  height: 28px;
  border-radius: 6px;
  background-color: var(--bg-4);
}
.slider-popover input[type="range"]::-moz-range-thumb {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
}
/* ==================== Update Banner ==================== */
.update-banner {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translate(-50%, -130%);
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px 9px 12px;
  background: var(--bg-2);
  color: var(--text-1);
  font-size: 12px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--accent-mid);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(94, 234, 212, 0.08), 0 0 24px rgba(94, 234, 212, 0.06);
  backdrop-filter: blur(12px) saturate(140%);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  transition: transform 320ms cubic-bezier(0.16, 1, 0.3, 1), opacity 240ms ease;
  pointer-events: none;
  opacity: 0;
  min-width: 240px;
  max-width: 92vw;
}
.update-banner.is-visible {
  transform: translate(-50%, 0);
  pointer-events: auto;
  opacity: 1;
}
.update-banner__spinner {
  color: var(--accent);
  flex-shrink: 0;
  filter: drop-shadow(0 0 6px rgba(94, 234, 212, 0.4));
  animation: update-spin 1.6s linear infinite;
}
@keyframes update-spin {
  to { transform: rotate(360deg); }
}
.update-banner span {
  flex: 1;
  text-align: center;
  font-weight: 500;
  font-size: 13px;
  letter-spacing: 0.01em;
}
.btn-update-refresh {
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  color: var(--bg-1);
  background: var(--accent);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 160ms var(--ease), transform 120ms var(--ease), box-shadow 160ms var(--ease);
  box-shadow: 0 2px 8px rgba(94, 234, 212, 0.25);
  flex-shrink: 0;
}
.btn-update-refresh:hover {
  background: var(--accent-strong);
  box-shadow: 0 4px 14px rgba(94, 234, 212, 0.4);
}
.btn-update-refresh:active { transform: scale(0.96); }
.btn-update-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-4);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: color 140ms var(--ease), background 140ms var(--ease);
  flex-shrink: 0;
}
.btn-update-close:hover { color: var(--text-1); background: var(--bg-3); }