*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Dev mode — hide dev-only in public, hide pub-label in dev */
body:not(.dev-mode) .dev-only { display: none !important; }
body.dev-mode .pub-label { display: none !important; }

/* Public mode: make the 生成 button stand out */
body:not(.dev-mode) #btn-generate {
  background: linear-gradient(135deg, #22d3ee, #a855f7, #f97316);
  background-size: 200% 200%;
  animation: gen-glow 3s ease-in-out infinite;
  color: #fff !important;
  font-weight: 700;
  border: none !important;
  box-shadow: 0 0 16px rgba(34, 211, 238, 0.4), 0 0 32px rgba(168, 85, 247, 0.2);
  padding: 0 14px;
}
body:not(.dev-mode) #btn-generate:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 0 24px rgba(34, 211, 238, 0.6), 0 0 48px rgba(168, 85, 247, 0.35);
}
@keyframes gen-glow {
  0%, 100% { background-position: 0% 50%; }
  50%      { background-position: 100% 50%; }
}

:root {
  --bg-0: #080c14;
  --bg-1: #0f141f;
  --bg-2: #141b27;
  --bg-3: #1a2332;
  --bg-4: #1e2940;
  --border: #243042;
  --border-light: #2d3d55;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --accent: #22d3ee;
  --accent-dim: #0891b2;
  --accent-bg: rgba(34, 211, 238, 0.1);
  --accent-glow: rgba(34, 211, 238, 0.25);
  --danger: #f87171;
  --success: #34d399;
  --warning: #fbbf24;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 12px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 12px rgba(34, 211, 238, 0.15);
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
  --transition-slow: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

html, body {
  height: 100%;
  background: var(--bg-0);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 13px;
  line-height: 1.4;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

/* ============== Toolbar ============== */

#toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 48px;
  padding: 0 12px;
  background: linear-gradient(180deg, #141c2b 0%, var(--bg-1) 100%);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 6px rgba(0,0,0,0.3);
  flex-shrink: 0;
  user-select: none;
  position: relative;
}

/* ============== Logo ============== */

#logo {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 12px;
  padding-right: 14px;
  border-right: 1px solid var(--border);
}

.logo-icon {
  width: 32px;
  height: 32px;
  filter: drop-shadow(0 0 6px var(--accent-glow));
  animation: logo-pulse 3s ease-in-out infinite;
}

.logo-top    { fill: #22d3ee; }
.logo-right  { fill: #0891b2; }
.logo-left   { fill: #0e7490; }

.logo-cut-hole {
  fill: #060d17;
}

.logo-cut-inner {
  fill: #0c1a28;
}

.logo-text {
  font-size: 14px;
  color: var(--text-dim);
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.logo-text strong {
  color: var(--accent);
  font-weight: 700;
  text-shadow: 0 0 8px var(--accent-glow);
}

@keyframes logo-pulse {
  0%, 100% { filter: drop-shadow(0 0 6px var(--accent-glow)); }
  50%      { filter: drop-shadow(0 0 14px rgba(34, 211, 238, 0.5)); }
}

#toolbar::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent-dim), transparent);
  opacity: 0.3;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

.tool-divider {
  width: 1px;
  height: 22px;
  background: linear-gradient(180deg, transparent, var(--border-light), transparent);
  margin: 0 6px;
}

/* Pivot visibility dropdown */
.dropdown-menu {
  position: relative;
  display: inline-flex;
}

.dropdown-panel {
  position: absolute;
  top: 36px;
  left: 0;
  z-index: 200;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  padding: 4px 6px;
  min-width: 130px;
  max-height: 360px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.dropdown-panel.hidden {
  display: none;
}

/* Screenshot background picker */
#screenshot-bg-panel {
  min-width: 220px;
  max-width: 240px;
}

.swatch-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 2px;
}

.bg-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}

.bg-swatch:hover {
  transform: scale(1.15);
}

.bg-swatch.active {
  border-color: var(--text-primary);
}

.bg-ai-row {
  display: flex;
  gap: 4px;
  padding: 4px 2px;
  margin-top: 2px;
}

.bg-ai-row input {
  flex: 1;
  padding: 3px 6px;
  font-size: 11px;
  background: var(--bg-inset);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
}

.bg-ai-row input::placeholder {
  color: var(--text-dim);
}

.bg-ai-row button {
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
}

.bg-ai-row button:hover {
  opacity: 0.85;
}

.bg-ai-row button.loading {
  opacity: 0.6;
  pointer-events: none;
}

.bg-username-input {
  width: 100%;
  margin-top: 4px;
  padding: 3px 6px;
  font-size: 11px;
  background: var(--bg-inset);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  box-sizing: border-box;
}

.bg-username-input::placeholder {
  color: var(--text-dim);
}

.bg-caption-row {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}

.bg-caption-input {
  flex: 1;
  padding: 3px 6px;
  font-size: 11px;
  background: var(--bg-inset);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
}

.bg-caption-input::placeholder {
  color: var(--text-dim);
}

.gen-caption-btn {
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
}

.gen-caption-btn:hover { background: var(--accent); color: #fff; }
.gen-caption-btn.loading { opacity: 0.5; pointer-events: none; }

.bg-blurb-input {
  width: 100%;
  margin-top: 4px;
  padding: 4px 6px;
  font-size: 11px;
  font-family: inherit;
  background: var(--bg-inset);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  resize: vertical;
  box-sizing: border-box;
  min-height: 52px;
}

.bg-blurb-input::placeholder { color: var(--text-dim); }

.text-color-row {
  display: flex;
  gap: 5px;
  margin-top: 4px;
  padding: 2px 0;
}

.text-color-swatch {
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}
.text-color-swatch:hover { transform: scale(1.2); }
.text-color-swatch.active { border-color: var(--text); }

.scroll-dir-row {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-top: 4px;
}
.scroll-label {
  font-size: 10px;
  color: var(--text-dim);
  margin-right: 2px;
}
.scroll-dir-btn {
  width: 22px; height: 20px;
  font-size: 10px; line-height: 1;
  padding: 0;
  background: var(--bg-inset);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}
.scroll-dir-btn:hover { color: var(--text); border-color: var(--text-dim); }
.scroll-dir-btn.active { background: var(--accent-bg); color: var(--accent); border-color: var(--accent); }

.capture-btn {
  width: 100%;
  margin-top: 6px;
  padding: 5px 0;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.capture-btn:hover {
  opacity: 0.85;
}

.pivot-group-item {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}

.pivot-group-item:hover {
  background: var(--accent-dim);
  color: var(--text-primary);
}

.pivot-group-item input[type="checkbox"] {
  accent-color: var(--accent);
  transform: scale(0.85);
}

#btn-pivot-toggle svg {
  width: 18px;
  height: 18px;
}

#toolbar button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 8px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  color: var(--text-dim);
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
}

#toolbar button:hover {
  background: rgba(255,255,255,0.05);
  color: var(--text);
  transform: translateY(-1px);
}

#toolbar button:active {
  transform: translateY(0) scale(0.96);
}

#toolbar button.active {
  background: var(--accent-bg);
  border-color: var(--accent-dim);
  color: var(--accent);
  box-shadow: var(--shadow-glow);
}

#toolbar button.active:hover {
  background: rgba(34, 211, 238, 0.18);
}

#toolbar button svg {
  width: 16px;
  height: 16px;
}

#toolbar .spacer {
  flex: 1;
}

.orientation-badge {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--accent);
  padding: 3px 10px;
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius-md);
  background: var(--accent-bg);
  box-shadow: inset 0 0 8px rgba(34, 211, 238, 0.06);
}

#time-display {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--text);
  min-width: 48px;
  text-align: center;
}

.model-info {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: 8px;
}

#model-name {
  font-weight: 600;
  font-size: 12px;
  color: var(--text);
}

#model-stats {
  font-size: 11px;
  color: var(--text-dim);
}

/* ============== Workspace ============== */

#workspace {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ============== Sidebar ============== */

#sidebar-left {
  display: flex;
  flex-direction: column;
  width: 260px;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 2px 0 8px rgba(0,0,0,0.15);
}

#sidebar-right {
  display: flex;
  flex-direction: column;
  width: 260px;
  background: var(--bg-1);
  border-left: 1px solid var(--border);
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: -2px 0 8px rgba(0,0,0,0.15);
}

#code-panel {
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--border);
  transition: max-height var(--transition-slow);
  max-height: 260px;
  overflow: hidden;
}

#code-panel.collapsed {
  max-height: 34px;
}

#code-panel .panel-header {
  cursor: pointer;
}

#code-panel.collapsed .panel-body {
  display: none;
}

#code-editor {
  width: 100%;
  min-height: 140px;
  padding: 10px;
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-family: 'Consolas', 'Monaco', 'JetBrains Mono', monospace;
  font-size: 12px;
  line-height: 1.5;
  resize: vertical;
  tab-size: 2;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

#code-editor:focus {
  outline: none;
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.1);
}

.code-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}

#btn-run-code {
  height: 28px;
  padding: 0 14px;
  background: linear-gradient(135deg, var(--accent-dim), #0e7490);
  border: 1px solid var(--accent);
  border-radius: var(--radius-md);
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: 0 2px 8px rgba(34, 211, 238, 0.2);
}

#btn-run-code:hover {
  background: linear-gradient(135deg, var(--accent), #06b6d4);
  box-shadow: 0 2px 12px rgba(34, 211, 238, 0.35);
  transform: translateY(-1px);
}

#btn-run-code:active {
  transform: translateY(0) scale(0.97);
}

#code-status {
  font-size: 11px;
  color: var(--text-dim);
  flex: 1;
}

.panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  border-bottom: 1px solid var(--border);
}

.panel:last-child {
  border-bottom: none;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  background: linear-gradient(135deg, var(--bg-2), var(--bg-3));
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
  padding-left: 16px;
}

.panel-header::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent-dim);
  border-radius: 0 2px 2px 0;
  opacity: 0.6;
}

.panel-header button {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.panel-header button:hover {
  background: rgba(255,255,255,0.08);
  color: var(--text);
  transform: scale(1.05);
}

.panel-header button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.panel-header button:disabled:hover {
  background: transparent;
  color: var(--text-dim);
  transform: none;
}

.panel-header button svg {
  width: 14px;
  height: 14px;
}

.panel-header-actions {
  display: inline-flex;
  gap: 2px;
  align-items: center;
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

/* ============== Outliner ============== */

.outliner-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--text-dim);
  font-size: 12px;
  transition: all var(--transition-fast);
}

.outliner-item:hover {
  background: rgba(255,255,255,0.04);
  color: var(--text);
}

.outliner-item.selected {
  background: var(--accent-bg);
  color: var(--accent);
  border: 1px solid var(--accent-dim);
  box-shadow: var(--shadow-glow);
}

.outliner-item .indent {
  display: inline-block;
  width: 14px;
  flex-shrink: 0;
}

.outliner-item .eye-btn {
  margin-left: auto;
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity var(--transition-fast);
}

.outliner-item .eye-btn:hover {
  opacity: 1;
}

.outliner-item.locked {
  opacity: 0.5;
}

.outliner-item.is-group {
  font-weight: 600;
  color: var(--text);
}

/* ============== Properties ============== */

.prop-empty {
  padding: 24px;
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
}

.prop-group-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}

.prop-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px;
}

.prop-row label {
  width: 60px;
  font-size: 11px;
  color: var(--text-dim);
  flex-shrink: 0;
}

.prop-row input[type="number"] {
  flex: 1;
  min-width: 0;
  height: 24px;
  padding: 0 6px;
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.prop-row input[type="number"]:focus {
  outline: none;
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 2px rgba(34, 211, 238, 0.1);
}

.prop-row .axis-x { color: #f87171; }
.prop-row .axis-y { color: #34d399; }
.prop-row .axis-z { color: #60a5fa; }

.prop-row input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
}

/* ============== Viewport ============== */

#viewport {
  position: relative;
  flex: 1;
  background: linear-gradient(180deg, #c8ced6 0%, #b8bec8 100%);
  overflow: hidden;
}

#viewport-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#selection-box {
  position: absolute;
  border: 1px dashed rgba(34, 211, 238, 0.8);
  background: rgba(34, 211, 238, 0.08);
  pointer-events: none;
  z-index: 10;
  display: none;
}

#viewport-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

.timing-overlay {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 10px;
  color: var(--accent);
  padding: 5px 10px;
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius-sm);
  background: rgba(8, 12, 20, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  white-space: nowrap;
  pointer-events: auto;
  box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}
.timing-overlay.hidden { display: none; }

#zoom-slider-wrap {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 120px;
  pointer-events: auto;
}
#zoom-slider {
  width: 100%;
  accent-color: var(--accent);
  opacity: 0.4;
  transition: opacity var(--transition-fast);
  cursor: pointer;
}
#zoom-slider:hover { opacity: 0.9; }

#direction-indicator {
  position: absolute;
  bottom: 16px;
  left: 16px;
  width: 80px;
  height: 80px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 50%;
  background: rgba(8, 12, 20, 0.65);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.3), inset 0 0 20px rgba(34, 211, 238, 0.03);
}

.dir-label {
  position: absolute;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-dim);
}

.dir-f { top: 2px; left: 50%; transform: translateX(-50%); color: var(--accent); }
.dir-b { bottom: 2px; left: 50%; transform: translateX(-50%); }
.dir-l { left: 4px; top: 50%; transform: translateY(-50%); }
.dir-r { right: 4px; top: 50%; transform: translateY(-50%); }

#selection-info {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  white-space: nowrap;
  z-index: 50;
  display: none;
}

#selection-info.selection-hint {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: rgba(230, 168, 23, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 10px 22px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.3);
  box-shadow: 0 2px 16px rgba(230, 168, 23, 0.5);
  animation: hint-pulse 2s ease-in-out infinite;
}

@keyframes hint-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.85; }
}

@keyframes ctrl-loading {
  0% { opacity: 0.4; }
  50% { opacity: 1; }
  100% { opacity: 0.4; }
}

#selection-info.autosave-banner {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  background: rgba(76, 175, 80, 0.85);
  padding: 8px 18px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.25);
  box-shadow: 0 2px 12px rgba(76, 175, 80, 0.4);
  animation: autosave-fade 3s ease-out forwards;
}

@keyframes autosave-fade {
  0% { opacity: 1; }
  70% { opacity: 1; }
  100% { opacity: 0; }
}

/* ============== Timeline ============== */

#timeline {
  display: flex;
  flex-direction: column;
  height: 160px;
  background: var(--bg-1);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  user-select: none;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.15);
  position: relative;
}

#timeline::before {
  content: '';
  position: absolute;
  top: -1px;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-light), transparent);
}

#timeline-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  background: linear-gradient(180deg, var(--bg-2), var(--bg-1));
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#timeline-toolbar button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
  transition: all var(--transition-fast);
}

#timeline-toolbar button:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text);
  transform: scale(1.05);
}

#timeline-toolbar button:active {
  transform: scale(0.95);
}

#timeline-toolbar button svg {
  width: 14px;
  height: 14px;
}

#timeline-toolbar .input-group {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
}

#timeline-toolbar .input-group label {
  font-size: 11px;
  color: var(--text-dim);
}

#timeline-toolbar .input-group input {
  width: 48px;
  height: 22px;
  padding: 0 4px;
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  transition: border-color var(--transition-fast);
}

#timeline-toolbar .input-group input:focus {
  border-color: var(--accent-dim);
  outline: none;
}

#tl-anim-name {
  width: 70px !important;
}

#timeline-ruler {
  position: relative;
  flex: 1;
  overflow: auto;
}

#timeline-tracks {
  position: relative;
  height: 100%;
  min-width: 100%;
}

.timeline-track {
  position: relative;
  height: 28px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  transition: background var(--transition-fast);
}

.timeline-track:nth-child(even) {
  background: rgba(255,255,255,0.01);
}

.timeline-track:hover {
  background: rgba(255,255,255,0.03);
}

.timeline-track-label {
  position: sticky;
  left: 0;
  width: 100px;
  padding: 0 10px;
  font-size: 11px;
  color: var(--text-dim);
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  z-index: 2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timeline-track-keys {
  position: relative;
  flex: 1;
  height: 100%;
}

.timeline-key {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%) rotate(45deg);
  width: 10px;
  height: 10px;
  background: var(--accent);
  border: 1px solid var(--accent-dim);
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: 0 0 6px rgba(34, 211, 238, 0.2);
}

.timeline-key:hover {
  background: var(--text);
  z-index: 5;
  box-shadow: 0 0 12px rgba(34, 211, 238, 0.4);
  transform: translate(-50%, -50%) rotate(45deg) scale(1.2);
}

.timeline-key.selected {
  background: var(--warning);
  border-color: var(--warning);
  box-shadow: 0 0 10px rgba(251, 191, 36, 0.4);
}

.timeline-key-delete {
  display: none;
  position: absolute;
  top: -8px;
  right: -8px;
  width: 14px;
  height: 14px;
  line-height: 13px;
  text-align: center;
  font-size: 11px;
  font-weight: bold;
  color: #fff;
  background: rgba(200, 40, 40, 0.85);
  border-radius: 50%;
  cursor: pointer;
  z-index: 10;
  transform: rotate(-45deg);
  transition: background var(--transition-fast);
}

.timeline-key:hover .timeline-key-delete,
.timeline-key.selected .timeline-key-delete {
  display: block;
}

.timeline-key-delete:hover {
  background: rgba(255, 60, 60, 0.95);
  transform: rotate(-45deg) scale(1.15);
}

.timeline-tick {
  position: absolute;
  top: 0;
  width: 1px;
  height: 6px;
  background: var(--border);
}

.timeline-tick.major {
  height: 10px;
  background: var(--text-dim);
}

.timeline-tick-label {
  position: absolute;
  top: 10px;
  font-size: 9px;
  color: var(--text-dim);
  transform: translateX(-50%);
}

#timeline-cursor {
  position: absolute;
  top: 0;
  left: 100px;
  width: 2px;
  height: 100%;
  background: var(--danger);
  pointer-events: auto;
  cursor: col-resize;
  z-index: 3;
  box-shadow: 0 0 8px rgba(248, 113, 113, 0.4);
}

#timeline-cursor::after {
  content: '';
  position: absolute;
  top: -3px;
  left: -4px;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--danger);
  filter: drop-shadow(0 0 3px rgba(248, 113, 113, 0.5));
}

/* Animation List Panel */
.anim-list-panel {
  display: flex;
  flex-direction: column;
  max-height: 120px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-0);
  flex-shrink: 0;
}

.anim-list-header {
  display: flex;
  align-items: center;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
}

.anim-list {
  overflow-y: auto;
  flex: 1;
}

.anim-list-empty {
  padding: 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 11px;
}

.anim-list-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-bottom: 1px solid rgba(36, 48, 66, 0.5);
  cursor: pointer;
  transition: background 0.1s;
}

.anim-list-item:hover {
  background: var(--bg-2);
}

.anim-list-item.active {
  background: var(--accent-bg);
  border-left: 2px solid var(--accent);
}

.anim-list-name {
  flex: 1;
  font-size: 11px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.anim-list-meta {
  font-size: 10px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.anim-list-badge {
  font-size: 9px;
  padding: 1px 4px;
  background: var(--bg-3);
  color: var(--text-dim);
  border-radius: 3px;
}

.anim-list-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.15s;
}

.anim-list-item:hover .anim-list-actions,
.anim-list-item.active .anim-list-actions {
  opacity: 1;
}

.anim-list-btn {
  width: 18px;
  height: 18px;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 3px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 10px;
  line-height: 1;
  transition: all 0.15s;
}

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

.anim-list-btn.anim-list-delete:hover {
  background: var(--danger);
  color: #fff;
}

.anim-list-btn.anim-list-load:hover {
  background: var(--success);
  color: #fff;
}

/* ============== Resize Handles ============== */

.resize-handle {
  flex-shrink: 0;
  z-index: 10;
  transition: background var(--transition-normal);
  background: var(--border);
}

.resize-handle:hover,
.resize-handle.dragging {
  background: var(--accent-dim);
  box-shadow: 0 0 6px rgba(34, 211, 238, 0.2);
}

.resize-handle-h {
  width: 5px;
  cursor: col-resize;
}

.resize-handle-v {
  height: 5px;
  cursor: row-resize;
}

.resize-handle-panel {
  margin: 0;
}

/* ============== Scrollable Areas ============== */

.panel-body {
  overflow-y: auto;
  overflow-x: hidden;
}

#code-panel .panel-body {
  overflow-y: auto;
}

#code-panel[style*="height"] {
  max-height: none !important;
}

.opt-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}

.modal-body {
  overflow-y: auto;
  max-height: 60vh;
}

.opt-gallery {
  overflow-y: auto;
}

.opt-issues {
  overflow-y: auto;
}

/* ============== Modal ============== */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: modalFadeIn 0.2s ease;
}

@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  width: 480px;
  max-width: 90vw;
  background: linear-gradient(180deg, #151d2e, var(--bg-1));
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: var(--shadow-lg), 0 0 40px rgba(0,0,0,0.3);
  animation: modalSlideIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalSlideIn {
  from { transform: translateY(12px) scale(0.97); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: linear-gradient(135deg, var(--bg-2), var(--bg-3));
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 14px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.modal-close:hover {
  color: var(--text);
  background: rgba(255,255,255,0.08);
}

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

.modal-body .input-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.modal-body .input-group label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
}

.modal-body .input-group label.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  text-transform: none;
  cursor: pointer;
  user-select: none;
}

.modal-body .input-group label.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  cursor: pointer;
}

.modal-body input,
.modal-body textarea,
.modal-body select {
  padding: 8px 10px;
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.modal-body input:focus,
.modal-body textarea:focus,
.modal-body select:focus {
  outline: none;
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.1);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: var(--bg-2);
}

.gen-settings {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  background: var(--bg-0);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Stream Preview (batch generation) */
.stream-preview {
  margin: 0 16px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-0);
}

.stream-preview.hidden {
  display: none;
}

.stream-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
}

.stream-preview pre {
  margin: 0;
  padding: 10px 12px;
  max-height: 300px;
  overflow-y: auto;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.stream-preview code {
  font-family: inherit;
}

.btn-secondary {
  padding: 7px 16px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-secondary:hover {
  background: var(--bg-4);
  border-color: var(--border-light);
}

.btn-secondary:active {
  transform: scale(0.97);
}

.btn-primary {
  padding: 7px 16px;
  background: linear-gradient(135deg, var(--accent-dim), #0e7490);
  border: 1px solid var(--accent);
  border-radius: var(--radius-md);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: 0 2px 8px rgba(34, 211, 238, 0.15);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--accent), #06b6d4);
  box-shadow: 0 2px 12px rgba(34, 211, 238, 0.3);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0) scale(0.97);
}

/* ============== Utility ============== */

.hidden {
  display: none !important;
}

button.disabled {
  opacity: 0.35;
  pointer-events: none;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--bg-3);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-light);
}

/* ============== Single Model Optimizer ============== */

.sopt-content {
  width: 90vw;
  max-width: 960px;
  height: 88vh;
  display: flex;
  flex-direction: column;
}

.sopt-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sopt-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.sopt-col {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-0);
  padding: 12px;
}

.sopt-col-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
  text-align: center;
}

.sopt-score {
  text-align: center;
  margin-bottom: 8px;
}

.sopt-big-score {
  font-size: 32px;
  font-weight: 700;
}

.sopt-score-max {
  font-size: 14px;
  color: var(--text-dim);
  font-weight: 400;
}

.sopt-delta {
  font-size: 18px;
  font-weight: 700;
  margin-left: 6px;
}

.sopt-dims {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
  margin-bottom: 8px;
}

.sopt-dim {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg-2);
  border-radius: var(--radius-sm);
  padding: 3px 8px;
  min-width: 48px;
}

.sopt-dim span {
  font-size: 9px;
  color: var(--text-dim);
}

.sopt-dim strong {
  font-size: 16px;
}

.sopt-dim-delta {
  font-size: 10px;
  font-weight: 600;
}

.sopt-issues-list {
  max-height: 180px;
  overflow-y: auto;
  margin-bottom: 8px;
}

.sopt-issue {
  display: flex;
  gap: 6px;
  align-items: flex-start;
  padding: 3px 0;
  font-size: 11px;
}

.sopt-issue-sev {
  font-size: 9px;
  padding: 0 4px;
  border-radius: 2px;
  font-weight: 600;
  white-space: nowrap;
  color: #fff;
}

.sopt-issue-critical .sopt-issue-sev { background: #ef4444; }
.sopt-issue-major .sopt-issue-sev { background: #f59e0b; }
.sopt-issue-minor .sopt-issue-sev { background: #3b82f6; }

.sopt-issue-desc { color: var(--text-dim); }

.sopt-na { font-size: 12px; color: var(--text-dim); text-align: center; padding: 8px; }
.sopt-loading { font-size: 14px; color: var(--accent); }

.sopt-view-btn {
  display: block;
  width: 100%;
  padding: 6px 0;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: 11px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.sopt-view-btn:hover { background: var(--border); }

.sopt-input-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sopt-input-section label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
}

.sopt-input-section textarea {
  width: 100%;
  padding: 8px;
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  resize: vertical;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.sopt-input-section textarea:focus {
  outline: none;
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.1);
}

.sopt-status {
  font-size: 12px;
  color: var(--accent);
  text-align: center;
  padding: 4px;
  min-height: 20px;
}

/* ============== Prompt Repository ============== */

.repo-toolbar {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  margin-bottom: 8px;
}

.repo-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.repo-empty {
  padding: 24px;
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
}

.repo-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-1);
  padding: 10px;
  transition: border-color var(--transition-fast);
}

.repo-card:hover {
  border-color: var(--border-light);
}

.repo-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.repo-card-version {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.repo-card-iter {
  font-size: 10px;
  color: var(--text-dim);
  background: var(--bg-2);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
}

.repo-card-score {
  font-size: 13px;
  font-weight: 600;
}

.repo-card-models {
  font-size: 10px;
  color: var(--text-dim);
}

.repo-card-time {
  font-size: 10px;
  color: var(--text-dim);
  margin-left: auto;
}

.repo-card-actions {
  display: flex;
  gap: 6px;
}

.repo-btn {
  padding: 3px 10px;
  font-size: 10px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
  transition: all var(--transition-fast);
}

.repo-btn-view { background: var(--bg-3); color: var(--text); }
.repo-btn-view:hover { background: var(--border); }
.repo-btn-models { background: var(--bg-3); color: var(--accent); }
.repo-btn-models:hover { background: var(--border); }
.repo-btn-load { background: var(--accent-dim); color: #fff; }
.repo-btn-load:hover { background: var(--accent); }
.repo-btn-sm { padding: 2px 8px; font-size: 10px; background: var(--bg-3); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; }
.repo-btn-sm:hover { background: var(--border); }

.repo-card-detail {
  margin-top: 8px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.repo-prompt-text {
  font-size: 11px;
  font-family: 'Consolas', 'Monaco', monospace;
  color: var(--text-dim);
  white-space: pre-wrap;
  max-height: 500px;
  overflow-y: auto;
  padding: 8px;
  background: var(--bg-0);
  border-radius: var(--radius-md);
  word-break: break-word;
}

.repo-card-models-list {
  margin-top: 8px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.repo-model-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  padding: 4px 8px;
  background: var(--bg-0);
  border-radius: var(--radius-sm);
}

.repo-model-item span { flex: 1; color: var(--text); }

.repo-model-score {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
}

.repo-detail {
  margin-top: 8px;
}

/* ============== Model Gallery ============== */

.gallery-content {
  width: 90vw;
  max-width: 1100px;
  height: 85vh;
  display: flex;
  flex-direction: column;
}

.gallery-header-info {
  font-size: 11px;
  color: var(--text-dim);
  margin-left: 12px;
}

.gallery-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.gallery-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.gallery-info {
  font-size: 11px;
  color: var(--text-dim);
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 10px;
}

.gallery-empty {
  grid-column: 1 / -1;
  padding: 40px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

.gallery-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-1);
  padding: 12px;
  cursor: pointer;
  transition: all var(--transition-normal);
}

.gallery-card:hover {
  border-color: var(--accent);
  background: var(--bg-2);
  box-shadow: 0 4px 16px rgba(34, 211, 238, 0.08);
  transform: translateY(-2px);
}

.gallery-card:active {
  transform: translateY(0);
}

.gallery-card-thumb {
  width: 100%;
  height: 100px;
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: 8px;
  background: var(--bg-0);
  border: 1px solid var(--border);
}

.gallery-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gallery-card-thumb--empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 11px;
}

.gallery-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.gallery-card-cat {
  font-size: 10px;
  color: var(--text-dim);
  background: var(--bg-2);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
}

.gallery-card-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}

.gallery-card-score {
  font-size: 18px;
  font-weight: 700;
}

.gallery-card-score--pending {
  font-size: 11px;
  font-weight: 400;
}

.gallery-card-dims {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.gallery-card-dim {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg-2);
  border-radius: var(--radius-sm);
  padding: 3px 8px;
  min-width: 44px;
}

.gallery-card-dim span {
  font-size: 9px;
  color: var(--text-dim);
}

.gallery-card-dim strong {
  font-size: 14px;
  color: var(--text);
}

.gallery-card-issues {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.gallery-badge {
  font-size: 9px;
  padding: 0 5px;
  border-radius: 2px;
  font-weight: 500;
}

.gallery-badge-critical { background: #3a1a1a; color: #ef4444; }
.gallery-badge-major { background: #3a2a1a; color: #f59e0b; }

.gallery-card-desc {
  font-size: 10px;
  color: var(--text-dim);
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.gallery-card-actions {
  display: flex;
  gap: 6px;
}

.gallery-btn {
  flex: 1;
  padding: 6px 0;
  font-size: 11px;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-weight: 500;
  transition: all var(--transition-fast);
}

.gallery-btn-view {
  background: var(--bg-3);
  color: var(--text);
}

.gallery-btn-view:hover { background: var(--border); }

.gallery-btn-optimize {
  background: var(--accent-dim);
  color: #fff;
}

.gallery-btn-optimize:hover { background: var(--accent); }

/* ============== Optimizer Dashboard ============== */

#optimizer-dashboard {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

#optimizer-dashboard.hidden {
  display: none;
}

.opt-dashboard {
  width: 95vw;
  max-width: 1000px;
  height: 92vh;
  max-height: 850px;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #151d2e, var(--bg-1));
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: var(--shadow-lg), 0 0 60px rgba(0, 0, 0, 0.4);
  animation: modalSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.opt-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, var(--bg-2), var(--bg-3));
  flex-shrink: 0;
}

.opt-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.opt-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.opt-header-right {
  display: flex;
  gap: 4px;
}

.opt-btn-icon {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  transition: all var(--transition-fast);
}

.opt-btn-icon:hover {
  background: var(--bg-3);
  color: var(--text);
  border-color: var(--border-light);
}

.opt-state {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 10px;
  background: var(--bg-3);
  color: var(--text-dim);
}

.opt-state-running {
  background: rgba(34, 211, 238, 0.15);
  color: var(--accent);
  animation: opt-pulse 1.5s infinite;
}

.opt-state-completed {
  background: rgba(52, 211, 153, 0.15);
  color: var(--success);
}

.opt-state-stopped {
  background: rgba(251, 191, 36, 0.15);
  color: var(--warning);
}

@keyframes opt-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.opt-elapsed {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
}

.opt-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.opt-section {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-0);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 40px;
}

.opt-section h4 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  padding: 8px 12px;
  background: linear-gradient(135deg, var(--bg-2), var(--bg-3));
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.opt-section-toggle {
  cursor: pointer;
  user-select: none;
}

.opt-section-toggle:hover {
  color: var(--text);
}

.opt-section.collapsed .opt-section-body,
.opt-section.collapsed .opt-section-resize {
  display: none;
}

.opt-section-body {
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  min-height: 0;
}

.opt-section-resize {
  height: 5px;
  cursor: row-resize;
  flex-shrink: 0;
  background: transparent;
  transition: background var(--transition-fast);
}

.opt-section-resize:hover {
  background: var(--accent-dim);
}

.opt-config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  padding: 10px 12px;
}

.opt-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.opt-field label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
}

.opt-field input {
  height: 28px;
  padding: 0 8px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  transition: border-color var(--transition-fast);
}

.opt-field input:focus {
  outline: none;
  border-color: var(--accent-dim);
}

/* Progress */
.opt-progress-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
}

.opt-progress-bar {
  flex: 1;
  height: 8px;
  background: var(--bg-2);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.opt-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  border-radius: var(--radius-md);
  transition: width 0.3s ease;
  box-shadow: 0 0 8px rgba(34, 211, 238, 0.2);
}

.opt-progress-pct {
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  min-width: 36px;
  text-align: right;
}

.opt-progress-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 12px 8px;
  font-size: 11px;
  color: var(--text-dim);
}

/* Model Gallery */
.opt-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
  padding: 4px 8px;
  max-height: 400px;
  overflow-y: auto;
}

.opt-feed-empty, .opt-issues-empty {
  padding: 16px;
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
}

/* Model Card */
.opt-model-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-1);
  padding: 10px;
  cursor: pointer;
  transition: all var(--transition-normal);
}

.opt-model-card:hover {
  border-color: var(--accent);
  background: var(--bg-2);
  box-shadow: 0 2px 12px rgba(34, 211, 238, 0.08);
}

.opt-model-active {
  border-color: var(--accent) !important;
  background: var(--bg-3) !important;
  box-shadow: 0 0 0 1px var(--accent), var(--shadow-glow);
}

.opt-model-card-error {
  opacity: 0.6;
  cursor: default;
}

.opt-mc-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.opt-mc-cat {
  font-size: 10px;
  color: var(--text-dim);
  background: var(--bg-2);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
}

.opt-mc-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}

.opt-mc-status {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  font-weight: 500;
}

.opt-mc-status.status-pending { background: var(--bg-3); color: var(--text-dim); }
.opt-mc-status.status-scored { background: #1a3a2a; color: #22c55e; }
.opt-mc-status.status-err { background: #3a1a1a; color: #ef4444; }

.opt-mc-score {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.opt-mc-score-value {
  font-size: 18px;
  font-weight: 700;
  min-width: 50px;
}

.opt-mc-score-bar {
  flex: 1;
  height: 4px;
  background: var(--bg-3);
  border-radius: 2px;
  overflow: hidden;
}

.opt-mc-score-fill {
  display: block;
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s;
}

.opt-mc-issues {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}

.opt-mc-issue-count {
  font-size: 10px;
  color: var(--text-dim);
}

.opt-mc-issue-tag {
  font-size: 9px;
  padding: 0 4px;
  border-radius: 2px;
  font-weight: 500;
}

.opt-mc-issue-tag.tag-critical { background: #3a1a1a; color: #ef4444; }
.opt-mc-issue-tag.tag-major { background: #3a2a1a; color: #f59e0b; }
.opt-mc-issue-tag.tag-minor { background: #1a2a3a; color: #3b82f6; }

.opt-mc-error {
  font-size: 11px;
  color: var(--danger);
  margin-bottom: 6px;
}

.opt-mc-actions {
  display: flex;
  gap: 6px;
}

.opt-mc-view-btn {
  flex: 1;
  padding: 5px 0;
  font-size: 11px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-weight: 500;
  transition: all var(--transition-fast);
}

.opt-mc-view-btn:hover { background: var(--accent-hover); }

/* Model Detail */
.opt-detail {
  padding: 4px 8px;
}

.opt-detail-score {
  margin-bottom: 12px;
}

.opt-detail-score-big {
  font-size: 28px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 10px;
}

.opt-detail-score-big span {
  font-size: 14px;
  color: var(--text-dim);
  font-weight: 400;
}

.opt-detail-dims {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.opt-detail-dim {
  display: flex;
  align-items: center;
  gap: 8px;
}

.opt-detail-dim-label {
  font-size: 11px;
  color: var(--text-dim);
  width: 40px;
  text-align: right;
}

.opt-detail-dim-bar {
  flex: 1;
  height: 6px;
  background: var(--bg-3);
  border-radius: 3px;
  overflow: hidden;
}

.opt-detail-dim-fill {
  display: block;
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s;
}

.opt-detail-dim-val {
  font-size: 12px;
  font-weight: 700;
  width: 30px;
}

.opt-detail-issues-header {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin: 12px 0 4px;
  padding: 4px 0;
  border-top: 1px solid var(--border);
}

.opt-detail-no-issues {
  padding: 12px;
  text-align: center;
  color: #22c55e;
  font-size: 12px;
}

.opt-detail-pending {
  padding: 12px;
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
}

/* Feed */
.opt-feed {
  max-height: 160px;
  overflow-y: auto;
  padding: 4px 8px;
}

.opt-feed-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  font-size: 12px;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}

.opt-feed-item:hover {
  background: var(--bg-2);
}

.opt-feed-status {
  width: 16px;
  text-align: center;
  font-size: 11px;
}

.opt-feed-status.status-ok { color: var(--success); }
.opt-feed-status.status-err { color: var(--danger); }

.opt-feed-cat {
  color: var(--text-dim);
  font-size: 10px;
  background: var(--bg-2);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  min-width: 70px;
  text-align: center;
}

.opt-feed-name {
  color: var(--text);
}

.opt-feed-error {
  color: var(--danger);
  font-size: 10px;
  margin-left: auto;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.opt-feed-view-btn {
  margin-left: auto;
  padding: 2px 8px;
  font-size: 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.opt-feed-view-btn:hover {
  background: var(--accent-hover);
}

.opt-feed-active {
  background: var(--bg-3) !important;
  border-left: 2px solid var(--accent);
}

/* Score cards */
.opt-score-card {
  margin: 4px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-1);
  overflow: hidden;
}

.opt-score-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: var(--bg-2);
}

.opt-score-model {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.opt-score-value {
  font-size: 22px;
  font-weight: 700;
}

.opt-score-max {
  font-size: 12px;
  color: var(--text-dim);
}

.opt-score-dims {
  display: flex;
  gap: 4px;
  padding: 6px 10px;
  flex-wrap: wrap;
}

.opt-score-dim {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg-3);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  min-width: 50px;
}

.opt-score-dim-label {
  font-size: 9px;
  color: var(--text-dim);
  text-transform: uppercase;
}

.opt-score-dim-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

/* Issues */
.opt-issues {
  max-height: 240px;
  overflow-y: auto;
  padding: 4px 8px;
}

.opt-issue-card {
  margin: 4px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-1);
  overflow: hidden;
}

.opt-issue-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: var(--bg-2);
}

.opt-issue-severity {
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
}

.opt-issue-category {
  font-size: 10px;
  color: var(--text-dim);
  background: var(--bg-3);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
}

.opt-issue-model {
  margin-left: auto;
  font-size: 10px;
  color: var(--text-dim);
}

.opt-issue-body {
  padding: 6px 8px;
  font-size: 11px;
  color: var(--text-dim);
}

.opt-issue-body p {
  margin-bottom: 4px;
}

.opt-issue-suggestion {
  color: var(--accent) !important;
  font-size: 11px;
}

/* Version Management */
.opt-version-summary {
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
}

.opt-version-items {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 12px;
}

.opt-version-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-1);
  padding: 8px 10px;
  transition: all var(--transition-fast);
}

.opt-version-active {
  border-color: var(--accent);
  background: var(--accent-bg);
  box-shadow: var(--shadow-glow);
}

.opt-version-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.opt-version-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.opt-version-iter {
  font-size: 10px;
  color: var(--text-dim);
  background: var(--bg-2);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
}

.opt-version-score {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
}

.opt-version-issues {
  font-size: 10px;
  color: var(--text-dim);
}

.opt-version-time {
  font-size: 10px;
  color: var(--text-dim);
  margin-left: auto;
}

.opt-version-stats {
  font-size: 10px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.opt-version-actions {
  display: flex;
  gap: 6px;
}

.opt-version-btn {
  padding: 3px 12px;
  font-size: 10px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
  transition: all var(--transition-fast);
}

.opt-version-btn-view {
  background: var(--bg-3);
  color: var(--text);
}

.opt-version-btn-view:hover { background: var(--border); }

.opt-version-btn-rollback {
  background: #3a1a1a;
  color: #ef4444;
}

.opt-version-btn-rollback:hover { background: #5a2a2a; }

.opt-version-current {
  font-size: 10px;
  color: var(--accent);
  padding: 3px 8px;
}

.opt-version-compare {
  border-top: 1px solid var(--border);
  padding: 8px 12px;
}

.opt-version-detail-header {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.opt-version-detail-body {
  font-size: 11px;
  font-family: 'Consolas', 'Monaco', monospace;
  color: var(--text-dim);
  white-space: pre-wrap;
  max-height: 300px;
  overflow-y: auto;
  padding: 8px;
  background: var(--bg-0);
  border-radius: var(--radius-md);
}

/* Review Section */
.opt-review-list {
  padding: 8px 12px;
}

.opt-review-summary {
  padding: 6px 12px;
  font-size: 11px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
}

.opt-review-prev-note {
  margin-top: 4px;
  font-style: italic;
  color: var(--accent);
}

.opt-review-items {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px 12px;
  max-height: 350px;
  overflow-y: auto;
}

.opt-review-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-1);
  padding: 8px;
}

.opt-review-check {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 12px;
}

.opt-review-check input[type="checkbox"] {
  accent-color: var(--accent);
}

.opt-review-sev {
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 2px;
  color: #fff;
  font-weight: 600;
}

.opt-review-sev-critical { background: #ef4444; }
.opt-review-sev-major { background: #f59e0b; }
.opt-review-sev-minor { background: #3b82f6; }

.opt-review-cat {
  font-size: 10px;
  color: var(--text-dim);
  background: var(--bg-2);
  padding: 1px 5px;
  border-radius: 2px;
}

.opt-review-model {
  font-size: 10px;
  color: var(--text-dim);
  margin-left: auto;
}

.opt-review-desc {
  font-size: 11px;
  color: var(--text);
  margin-top: 4px;
  padding-left: 22px;
}

.opt-review-sugg {
  font-size: 10px;
  color: var(--accent);
  padding-left: 22px;
  margin-top: 2px;
}

.opt-review-note {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 12px;
}

.opt-review-note label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
}

.opt-review-note textarea {
  width: 100%;
  padding: 6px 8px;
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: 11px;
  font-family: inherit;
  resize: vertical;
  transition: border-color var(--transition-fast);
}

.opt-review-note textarea:focus {
  outline: none;
  border-color: var(--accent-dim);
}

.opt-review-actions {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  justify-content: flex-end;
}

/* Prompt diff */
.opt-diff-container {
  max-height: 200px;
  overflow-y: auto;
  padding: 10px 12px;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 11px;
  white-space: pre-wrap;
  color: var(--text);
  background: var(--bg-0);
  line-height: 1.5;
}

/* Footer */
.opt-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-2);
  flex-shrink: 0;
}

.btn-danger {
  padding: 7px 16px;
  background: rgba(248, 113, 113, 0.15);
  border: 1px solid var(--danger);
  border-radius: var(--radius-md);
  color: var(--danger);
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-danger:hover {
  background: rgba(248, 113, 113, 0.25);
}

.btn-danger:active {
  transform: scale(0.97);
}

/* ---- Library commit groups ---- */
.lib-arrow.rotated {
  transform: rotate(90deg);
  display: inline-block;
}

.lib-commit-header:hover {
  background: var(--bg-2) !important;
}

/* ---- Diff View ---- */
.diff-panel {
  flex: 1;
  overflow: auto;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 11px;
  line-height: 1.6;
  background: var(--bg-0);
}

.diff-panel:first-child {
  border-right: 1px solid var(--border);
}

.diff-panel-header {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 6px 12px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.diff-line {
  display: flex;
  min-height: 18px;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}

.diff-line-num {
  width: 40px;
  min-width: 40px;
  padding: 0 6px;
  text-align: right;
  color: var(--text-dim);
  user-select: none;
  opacity: 0.5;
  border-right: 1px solid var(--border);
  background: var(--bg-1);
}

.diff-line-code {
  flex: 1;
  padding: 0 8px;
  white-space: pre;
  overflow-x: auto;
}

.diff-line.equal { background: transparent; }
.diff-line.added { background: rgba(52, 211, 153, 0.12); }
.diff-line.removed { background: rgba(248, 113, 113, 0.12); }

.diff-line.equal .diff-line-num { background: var(--bg-1); }
.diff-line.added .diff-line-num { background: rgba(52, 211, 153, 0.15); }
.diff-line.removed .diff-line-num { background: rgba(248, 113, 113, 0.15); }
