/* =========================================================
   Grok Image Studio — UI/UX Pro Max redesign
   Style: AI-Native + Modern Dark creative workspace
   Tokens: violet primary / pink accent / cinematic dark
   ========================================================= */

:root {
  --bg-deep: #07060c;
  --bg-base: #0c0a14;
  --bg-elevated: #12101c;
  --bg-panel: rgba(18, 16, 28, 0.82);
  --bg-soft: rgba(255, 255, 255, 0.035);
  --bg-soft-2: rgba(255, 255, 255, 0.055);
  --bg-hover: rgba(255, 255, 255, 0.07);
  --bg-active: rgba(124, 58, 237, 0.16);

  --fg: #f4f1fb;
  --fg-secondary: #c9c2db;
  --fg-muted: #8f87a5;
  --fg-faint: #6b647c;

  --primary: #8b5cf6;
  --primary-strong: #7c3aed;
  --primary-soft: rgba(139, 92, 246, 0.16);
  --primary-glow: rgba(124, 58, 237, 0.38);
  --secondary: #6366f1;
  --accent: #ec4899;
  --accent-soft: rgba(236, 72, 153, 0.14);

  --success: #34d399;
  --success-soft: rgba(52, 211, 153, 0.14);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --warning: #fbbf24;

  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --border-focus: rgba(139, 92, 246, 0.7);
  --ring: 0 0 0 3px rgba(139, 92, 246, 0.28);

  --radius-xs: 8px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --radius-full: 999px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 40px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.28);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.28);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 0 1px rgba(139, 92, 246, 0.2), 0 12px 40px rgba(124, 58, 237, 0.22);

  --font: "Inter", "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;

  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --duration: 180ms;
  --duration-slow: 280ms;

  --console-w: 400px;
  --topbar-h: 64px;
  --footer-h: 108px;
  --z-ambient: 0;
  --z-shell: 1;
  --z-sticky: 10;
  --z-toast: 50;
  --z-dialog: 60;
}

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

html {
  color-scheme: dark;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--fg);
  background:
    radial-gradient(1200px 700px at 10% -10%, rgba(124, 58, 237, 0.18), transparent 55%),
    radial-gradient(900px 600px at 95% 0%, rgba(236, 72, 153, 0.1), transparent 50%),
    linear-gradient(180deg, #0e0b17 0%, var(--bg-deep) 40%, #06050a 100%);
  overflow-x: hidden;
  overflow-y: auto;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.015) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.015) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at center, black 20%, transparent 75%);
  opacity: 0.5;
  z-index: var(--z-ambient);
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  border: 0;
  background: none;
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
  display: block;
}

:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hidden {
  display: none !important;
}

/* Ambient blobs */
.ambient {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: var(--z-ambient);
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
  opacity: 0.35;
  animation: float 18s ease-in-out infinite;
}

.blob-a {
  width: 420px;
  height: 420px;
  top: -120px;
  left: -80px;
  background: rgba(124, 58, 237, 0.45);
}

.blob-b {
  width: 360px;
  height: 360px;
  top: 20%;
  right: -100px;
  background: rgba(236, 72, 153, 0.28);
  animation-delay: -6s;
}

.blob-c {
  width: 300px;
  height: 300px;
  bottom: -80px;
  left: 35%;
  background: rgba(99, 102, 241, 0.22);
  animation-delay: -12s;
}

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(30px, -20px) scale(1.08); }
}

/* Shell */
.app-shell {
  position: relative;
  z-index: var(--z-shell);
  height: auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 1680px;
  margin: 0 auto;
  padding: var(--space-4);
  gap: var(--space-4);
  overflow: visible;
}

/* Topbar */
.topbar {
  position: sticky;
  top: var(--space-4);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-height: var(--topbar-h);
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: rgba(12, 10, 20, 0.72);
  backdrop-filter: blur(18px) saturate(140%);
  box-shadow: var(--shadow-sm);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: white;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.18), transparent 45%),
    linear-gradient(135deg, var(--primary-strong), var(--accent));
  box-shadow: 0 8px 24px rgba(124, 58, 237, 0.35);
  flex-shrink: 0;
}

.brand-mark svg {
  width: 22px;
  height: 22px;
}

.brand-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 2px;
}

.brand-copy strong {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.brand-copy span {
  color: var(--fg-muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.save-location {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: var(--fg-muted);
  font-size: 11.5px;
}

.save-location svg {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  color: var(--primary);
}

.save-location > span {
  flex: 0 0 auto;
}

.save-location code {
  min-width: 0;
  max-width: min(40vw, 560px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--fg-secondary);
  font-family: var(--font-mono);
  font-size: 11px;
  user-select: all;
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 12px;
}

.theme-toggle {
  width: 44px;
  height: 44px;
  min-width: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--fg-secondary);
  background: var(--bg-soft);
  cursor: pointer;
  transition: color var(--duration) var(--ease), border-color var(--duration) var(--ease), background var(--duration) var(--ease);
}

.theme-toggle:hover {
  color: var(--fg);
  border-color: var(--border-strong);
  background: var(--bg-hover);
}

.theme-toggle:active {
  background: var(--bg-active);
}

.theme-icon {
  width: 19px;
  height: 19px;
}

.theme-icon-moon { display: none; }

html[data-theme="light"] .theme-icon-sun { display: none; }
html[data-theme="light"] .theme-icon-moon { display: block; }

.connection {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--fg-secondary);
  font-size: 12.5px;
  font-weight: 500;
}

.connection-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--fg-faint);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.04);
}

.connection.ready {
  color: #a7f3d0;
  border-color: rgba(52, 211, 153, 0.28);
  background: var(--success-soft);
}

.connection.ready .connection-dot {
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.15);
  animation: pulse-dot 2s ease infinite;
}

.connection.error {
  color: #fecaca;
  border-color: rgba(248, 113, 113, 0.28);
  background: var(--danger-soft);
}

.connection.error .connection-dot {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(248, 113, 113, 0.14);
}

@keyframes pulse-dot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.15); opacity: 0.75; }
}

.topbar-hint {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--fg-muted);
  font-size: 12px;
}

.topbar-hint kbd {
  display: inline-grid;
  place-items: center;
  min-width: 28px;
  height: 24px;
  padding: 0 7px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--fg-secondary);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.35);
}

.hint-text {
  margin-left: 2px;
}

/* Workspace grid */
.workspace {
  display: grid;
  grid-template-columns: minmax(340px, var(--console-w)) minmax(0, 1fr);
  gap: var(--space-4);
  flex: 0 0 auto;
  min-height: 0;
  align-items: start;
}

/* Console */
.console {
  display: flex;
  flex-direction: column;
  min-height: auto;
  height: auto;
  max-height: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--bg-panel);
  backdrop-filter: blur(20px) saturate(140%);
  box-shadow: var(--shadow-md);
  overflow: visible;
}

.console-scroll {
  flex: none;
  min-height: auto;
  overflow: visible;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  scrollbar-gutter: auto;
}

.console-scroll > .panel {
  flex: 0 0 auto;
}

.console-scroll::-webkit-scrollbar {
  width: 10px;
}

.console-scroll::-webkit-scrollbar-thumb {
  min-height: 56px;
  border: 2px solid transparent;
  background: rgba(120, 205, 189, 0.5);
  background-clip: padding-box;
  border-radius: 999px;
}

.console-scroll::-webkit-scrollbar-track {
  background: rgba(208, 231, 226, 0.045);
}

.console-scroll:hover::-webkit-scrollbar-thumb {
  background: rgba(120, 205, 189, 0.72);
  background-clip: padding-box;
}

/* Panels */
.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 40%),
    rgba(255, 255, 255, 0.02);
  overflow: hidden;
  transition: border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}

.panel:hover {
  border-color: rgba(255, 255, 255, 0.12);
}

.panel-head {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 12px;
  text-align: left;
  color: inherit;
}

.panel-head:not(.static) {
  cursor: pointer;
}

.panel-head:not(.static):hover {
  background: rgba(255, 255, 255, 0.02);
}

.panel-head.static {
  cursor: default;
}

.panel-title {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
}

.panel-title strong {
  display: block;
  font-size: 13.5px;
  font-weight: 620;
  letter-spacing: -0.01em;
}

.panel-title p {
  margin: 2px 0 0;
  color: var(--fg-muted);
  font-size: 12px;
}

.panel-icon {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  color: var(--fg-secondary);
  background: var(--bg-soft-2);
  border: 1px solid var(--border);
}

.panel-icon.accent {
  color: #e9d5ff;
  background: linear-gradient(145deg, rgba(139, 92, 246, 0.28), rgba(236, 72, 153, 0.12));
  border-color: rgba(139, 92, 246, 0.28);
}

.panel-icon svg {
  width: 16px;
  height: 16px;
}

.section-action {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--fg-muted);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  font-size: 16px;
  line-height: 1;
  flex-shrink: 0;
}

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

.stack-sm {
  gap: 10px;
}

/* Fields */
.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
}

.field-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 550;
  color: var(--fg-secondary);
}

.field-label em {
  font-style: normal;
  font-size: 11px;
  font-weight: 500;
  color: var(--fg-faint);
  padding: 2px 7px;
  border-radius: var(--radius-full);
  background: var(--bg-soft);
  border: 1px solid var(--border);
}

.field input,
.field select,
.field textarea,
select,
textarea,
input[type="url"],
input[type="password"],
input[type="text"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.28);
  color: var(--fg);
  padding: 11px 12px;
  transition: border-color var(--duration) var(--ease), background var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}

.field input::placeholder,
.field textarea::placeholder {
  color: var(--fg-faint);
}

.field input:hover,
.field select:hover,
.field textarea:hover {
  border-color: var(--border-strong);
  background: rgba(0, 0, 0, 0.34);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--border-focus);
  background: rgba(0, 0, 0, 0.38);
  box-shadow: var(--ring);
  outline: none;
}

.field select {
  appearance: none;
  min-height: 44px;
  padding-right: 48px;
  background-image: none;
  cursor: pointer;
}

.select-control {
  position: relative;
  width: 100%;
  min-width: 0;
}

.select-control::after {
  content: "";
  position: absolute;
  top: 9px;
  right: 40px;
  bottom: 9px;
  width: 1px;
  background: var(--border);
  pointer-events: none;
}

.select-chevron {
  position: absolute;
  top: 50%;
  right: 12px;
  width: 18px;
  height: 18px;
  color: var(--fg-secondary);
  transform: translateY(-50%);
  pointer-events: none;
  transition: color var(--duration) var(--ease), transform var(--duration) var(--ease);
}

.select-control:hover .select-chevron,
.select-control:focus-within .select-chevron {
  color: var(--primary);
}

.select-control:focus-within .select-chevron {
  transform: translateY(-50%) scale(1.08);
}

.select-control:has(select:disabled) .select-chevron {
  opacity: 0.45;
}

.field textarea {
  resize: vertical;
  min-height: 72px;
  line-height: 1.55;
}

.field-grow textarea {
  min-height: 148px;
}

.input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.field-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: -4px;
  color: var(--fg-faint);
  font-size: 11.5px;
}

.meta-tip {
  color: var(--fg-muted);
}

/* Chips / presets */
.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--fg-secondary);
  font-size: 12px;
  font-weight: 550;
  transition: all var(--duration) var(--ease);
  cursor: pointer;
}

.chip:hover {
  color: var(--fg);
  border-color: rgba(139, 92, 246, 0.4);
  background: var(--primary-soft);
}

.chip:active {
  transform: scale(0.97);
}

/* Segmented control */
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 5px;
  border-radius: var(--radius-md);
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--border);
}

.seg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border-radius: var(--radius-sm);
  color: var(--fg-muted);
  font-size: 13px;
  font-weight: 550;
  transition: all var(--duration) var(--ease);
  cursor: pointer;
}

.seg-btn svg {
  width: 15px;
  height: 15px;
  opacity: 0.8;
}

.seg-btn:hover {
  color: var(--fg-secondary);
  background: rgba(255, 255, 255, 0.04);
}

.seg-btn.active {
  color: white;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.1), transparent),
    linear-gradient(135deg, rgba(124, 58, 237, 0.95), rgba(99, 102, 241, 0.92));
  box-shadow: 0 6px 16px rgba(124, 58, 237, 0.28);
}

.seg-btn.active svg {
  opacity: 1;
}

/* Upload */
.upload-zone {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px dashed rgba(139, 92, 246, 0.35);
  background:
    linear-gradient(180deg, rgba(139, 92, 246, 0.08), rgba(236, 72, 153, 0.03));
  cursor: pointer;
  transition: border-color var(--duration) var(--ease), background var(--duration) var(--ease), transform var(--duration) var(--ease);
  overflow: hidden;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: rgba(139, 92, 246, 0.55);
  background:
    linear-gradient(180deg, rgba(139, 92, 246, 0.12), rgba(236, 72, 153, 0.05));
}

.upload-zone.dragover {
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.18);
  transform: translateY(-1px);
}

.upload-zone input[type="file"] {
  position: absolute;
  inset: 0;
  z-index: 1;
  opacity: 0;
  cursor: pointer;
}

.upload-visual {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: #ddd6fe;
  background: rgba(139, 92, 246, 0.18);
  border: 1px solid rgba(139, 92, 246, 0.25);
}

.upload-visual svg {
  width: 18px;
  height: 18px;
}

.upload-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.upload-copy strong {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.upload-copy span {
  color: var(--fg-muted);
  font-size: 12px;
}

.upload-preview {
  grid-column: 1 / -1;
  width: 100%;
  max-height: 160px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.clear-edit-image {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 3;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(239, 139, 139, 0.36);
  border-radius: var(--radius-sm);
  color: #ffd0d0;
  background: rgba(38, 12, 14, 0.86);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(10px);
  cursor: pointer;
  transition: color var(--duration) var(--ease), border-color var(--duration) var(--ease), background var(--duration) var(--ease);
}

.clear-edit-image:hover {
  color: #ffffff;
  border-color: rgba(239, 139, 139, 0.7);
  background: rgba(124, 35, 40, 0.94);
}

.clear-edit-image svg {
  width: 18px;
  height: 18px;
}

html[data-theme="light"] .clear-edit-image {
  color: #9f2929;
  border-color: rgba(181, 59, 59, 0.3);
  background: rgba(255, 245, 245, 0.94);
}

html[data-theme="light"] .clear-edit-image:hover {
  color: #ffffff;
  background: #b53b3b;
}

/* Params */
.param-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ratio-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.ratio-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 72px;
  padding: 10px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.2);
  color: var(--fg-muted);
  transition: all var(--duration) var(--ease);
  cursor: pointer;
}

.ratio-btn:hover {
  color: var(--fg-secondary);
  border-color: var(--border-strong);
  background: var(--bg-hover);
}

.ratio-btn.active {
  color: #ede9fe;
  border-color: rgba(139, 92, 246, 0.55);
  background: linear-gradient(180deg, rgba(139, 92, 246, 0.22), rgba(139, 92, 246, 0.08));
  box-shadow: inset 0 0 0 1px rgba(139, 92, 246, 0.15);
}

.ratio-btn em {
  font-style: normal;
  font-size: 11px;
  font-weight: 600;
}

.ratio-box {
  display: block;
  border: 1.5px solid currentColor;
  border-radius: 3px;
  opacity: 0.85;
}

.r-11 { width: 18px; height: 18px; }
.r-169 { width: 24px; height: 14px; }
.r-916 { width: 14px; height: 22px; }
.r-43 { width: 22px; height: 16px; }
.r-auto {
  width: 20px;
  height: 18px;
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 700;
  font-style: normal;
}

.param-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.param-meta {
  align-items: center;
}

.stepper {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  min-height: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.28);
  overflow: hidden;
}

.stepper strong {
  text-align: center;
  font-size: 15px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.stepper .icon-btn {
  width: 100%;
  height: 100%;
  min-height: 44px;
  border-radius: 0;
  border: 0;
  background: transparent;
}

.stepper .icon-btn:hover {
  background: var(--bg-hover);
}

.size-pill,
.check-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.22);
  color: var(--fg-muted);
  font-size: 12px;
}

.size-pill {
  justify-content: space-between;
}

.size-pill strong {
  color: var(--fg);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.check-pill {
  cursor: pointer;
  user-select: none;
  transition: border-color var(--duration) var(--ease), background var(--duration) var(--ease);
}

.check-pill:hover {
  border-color: var(--border-strong);
}

.check-pill input {
  width: 15px;
  height: 15px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* Buttons */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
  transition: transform var(--duration) var(--ease), background var(--duration) var(--ease), border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease), opacity var(--duration) var(--ease);
  cursor: pointer;
  white-space: nowrap;
}

.btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled,
.btn.disabled,
a.disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-block {
  width: 100%;
}

.btn-sm {
  min-height: 36px;
  padding: 0 12px;
  font-size: 12.5px;
  border-radius: 9px;
}

.btn-sm svg {
  width: 14px;
  height: 14px;
}

.btn-primary {
  color: white;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.14), transparent 42%),
    linear-gradient(135deg, #8b5cf6 0%, #7c3aed 48%, #db2777 130%);
  box-shadow: var(--shadow-glow);
  overflow: hidden;
}

.btn-primary .btn-glow {
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 20%, rgba(255, 255, 255, 0.22) 45%, transparent 70%);
  transform: translateX(-120%);
  transition: transform 0.6s var(--ease);
}

.btn-primary:hover:not(:disabled) {
  box-shadow: 0 0 0 1px rgba(139, 92, 246, 0.3), 0 16px 40px rgba(124, 58, 237, 0.35);
}

.btn-primary:hover:not(:disabled) .btn-glow {
  transform: translateX(120%);
}

.btn-primary.loading {
  opacity: 0.88;
}

.btn-secondary {
  color: var(--fg);
  background: var(--bg-soft-2);
  border-color: var(--border-strong);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-ghost {
  color: var(--fg-secondary);
  background: transparent;
  border-color: var(--border);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--fg);
  background: var(--bg-soft);
  border-color: var(--border-strong);
}

.icon-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--fg-secondary);
  transition: all var(--duration) var(--ease);
  cursor: pointer;
}

.icon-btn svg {
  width: 16px;
  height: 16px;
}

.icon-btn:hover {
  color: var(--fg);
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.sync-icon {
  width: 16px;
  height: 16px;
}

.sync-icon.spinning {
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Console footer */
.console-footer {
  position: sticky;
  bottom: 12px;
  z-index: var(--z-sticky);
  padding: 14px;
  border-top: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(12, 10, 20, 0.72), rgba(12, 10, 20, 0.96));
  backdrop-filter: blur(16px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.request-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 20px;
  color: var(--fg-muted);
  font-size: 12px;
}

.summary-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  box-shadow: 0 0 10px rgba(139, 92, 246, 0.6);
  flex-shrink: 0;
}

.action-row {
  display: flex;
  gap: 8px;
}

.action-row .btn-primary {
  flex: 1 1 auto;
  width: 100%;
}

.action-row .btn-ghost:not(.hidden) {
  flex: 0 0 auto;
  min-width: 88px;
}

/* Stage column */
.stage-column {
  position: sticky;
  top: calc(var(--topbar-h) + 30px);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
  min-height: 0;
  height: calc(100dvh - var(--topbar-h) - 48px);
  max-height: calc(100dvh - var(--topbar-h) - 48px);
}

.stage-card {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--bg-panel);
  backdrop-filter: blur(20px) saturate(140%);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.stage-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.015);
}

.stage-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.stage-badge {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 9px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #e9d5ff;
  background: var(--primary-soft);
  border: 1px solid rgba(139, 92, 246, 0.28);
}

.stage-title h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.stage-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.stage-viewport {
  position: relative;
  flex: 1;
  min-height: 360px;
  display: grid;
  place-items: center;
  padding: var(--space-6);
  background:
    radial-gradient(ellipse at center, rgba(124, 58, 237, 0.06), transparent 55%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.015), transparent 30%),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 31px,
      rgba(255, 255, 255, 0.015) 32px
    ),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 31px,
      rgba(255, 255, 255, 0.015) 32px
    );
}

/* Stage states */
.stage-state {
  width: min(520px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 12px;
  animation: fade-up 0.35s var(--ease);
}

.stage-state h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.03em;
}

.stage-state p {
  margin: 0;
  color: var(--fg-muted);
  font-size: 14px;
  line-height: 1.65;
  max-width: 44ch;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.empty-visual {
  position: relative;
  width: 96px;
  height: 96px;
  display: grid;
  place-items: center;
  margin-bottom: 4px;
  color: #c4b5fd;
}

.empty-visual > svg {
  width: 36px;
  height: 36px;
  opacity: 0.9;
}

.empty-frame {
  position: absolute;
  inset: 0;
  border-radius: 24px;
  border: 1px solid rgba(139, 92, 246, 0.28);
  background:
    linear-gradient(145deg, rgba(139, 92, 246, 0.14), rgba(236, 72, 153, 0.06));
  box-shadow: 0 16px 40px rgba(124, 58, 237, 0.16);
}

.empty-frame span {
  position: absolute;
  width: 10px;
  height: 10px;
  border: 2px solid rgba(196, 181, 253, 0.7);
}

.empty-frame span:nth-child(1) { top: 10px; left: 10px; border-right: 0; border-bottom: 0; }
.empty-frame span:nth-child(2) { top: 10px; right: 10px; border-left: 0; border-bottom: 0; }
.empty-frame span:nth-child(3) { bottom: 10px; left: 10px; border-right: 0; border-top: 0; }
.empty-frame span:nth-child(4) { bottom: 10px; right: 10px; border-left: 0; border-top: 0; }

.empty-steps {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
  width: min(320px, 100%);
  text-align: left;
}

.empty-steps li {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.18);
  color: var(--fg-secondary);
  font-size: 13px;
}

.empty-steps span {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  color: #ede9fe;
  background: var(--primary-soft);
  border: 1px solid rgba(139, 92, 246, 0.25);
  flex-shrink: 0;
}

/* Loader */
.loader {
  position: relative;
  width: 104px;
  height: 104px;
  margin-bottom: 6px;
}

.orbit-loader {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}

.kinetic-orbits {
  width: 112px;
  height: 112px;
  overflow: visible;
  filter: drop-shadow(0 8px 12px rgba(41, 117, 108, 0.12));
}

.kinetic-guide {
  fill: none;
  stroke: var(--border);
  stroke-width: 1;
  stroke-dasharray: 2 6;
}

.kinetic-group {
  transform-box: view-box;
  transform-origin: 60px 60px;
}

.kinetic-path {
  fill: none;
  stroke-linecap: round;
}

.path-a {
  stroke: var(--primary);
  stroke-width: 3;
  stroke-dasharray: 38 12 15 35;
}

.path-b {
  stroke: var(--accent);
  stroke-width: 2.5;
  stroke-dasharray: 22 12 42 24;
}

.path-c {
  stroke: var(--primary);
  stroke-width: 2;
  stroke-dasharray: 12 8 18 10 30 22;
  opacity: 0.76;
}

.kinetic-node {
  stroke: var(--bg-elevated);
  stroke-width: 2;
}

.node-a, .node-c { fill: var(--primary); }
.node-b { fill: var(--accent); }

.orbit-a { animation: kinetic-clockwise 3.2s linear infinite; }
.orbit-b { animation: kinetic-counter 2.35s linear infinite; }
.orbit-c { animation: kinetic-clockwise 1.55s linear infinite reverse; }

.kinetic-halo {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.5;
  opacity: 0.32;
  transform-box: fill-box;
  transform-origin: center;
  animation: kinetic-halo 1.8s ease-in-out infinite;
}

.kinetic-core {
  fill: var(--bg-elevated);
  stroke: var(--primary);
  stroke-width: 2.5;
  transform-box: fill-box;
  transform-origin: center;
  animation: kinetic-core 1.8s ease-in-out infinite;
}

@keyframes kinetic-clockwise {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes kinetic-counter {
  from { transform: rotate(38deg); }
  to { transform: rotate(-322deg); }
}

@keyframes kinetic-halo {
  0%, 100% { opacity: 0.18; transform: scale(0.82); }
  50% { opacity: 0.58; transform: scale(1.12); }
}

@keyframes kinetic-core {
  0%, 100% { opacity: 0.65; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.08); }
}

.orbit-ring {
  position: absolute;
  left: 50%;
  top: 50%;
  border-style: solid;
  border-radius: 50%;
  transform-origin: center;
}

.orbit-ring i {
  position: absolute;
  display: block;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 10px currentColor;
}

.ring-outer {
  width: 88px;
  height: 88px;
  margin: -44px 0 0 -44px;
  border-width: 2px;
  border-color: var(--primary) transparent rgba(120, 205, 189, 0.28) transparent;
  color: var(--primary);
  animation: orbit-clockwise 2.4s linear infinite;
}

.ring-outer i {
  top: 4px;
  right: 10px;
  width: 7px;
  height: 7px;
}

.ring-middle {
  width: 64px;
  height: 64px;
  margin: -32px 0 0 -32px;
  border-width: 2px;
  border-color: transparent var(--accent) transparent rgba(231, 183, 143, 0.3);
  color: var(--accent);
  animation: orbit-counter 1.8s linear infinite;
}

.ring-middle i {
  left: 3px;
  bottom: 7px;
  width: 6px;
  height: 6px;
}

.ring-inner {
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  border-width: 2px;
  border-color: var(--primary) var(--primary) transparent transparent;
  color: var(--primary);
  opacity: 0.72;
  animation: orbit-clockwise 1.25s linear infinite reverse;
}

.ring-inner i {
  right: -3px;
  bottom: 6px;
  width: 5px;
  height: 5px;
}

.orbit-core {
  width: 12px;
  height: 12px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  background: var(--bg-elevated);
  box-shadow: 0 0 0 5px var(--accent-soft);
  animation: orbit-core-pulse 1.6s ease-in-out infinite;
}

@keyframes orbit-clockwise {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes orbit-counter {
  from { transform: rotate(45deg); }
  to { transform: rotate(-315deg); }
}

@keyframes orbit-core-pulse {
  0%, 100% { opacity: 0.45; transform: scale(0.82); }
  50% { opacity: 1; transform: scale(1); }
}

@keyframes orbit-breathe {
  0%, 100% { opacity: 0.34; }
  50% { opacity: 0.76; }
}

.elapsed-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  min-height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.28);
  color: var(--fg-secondary);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.elapsed-chip svg {
  width: 15px;
  height: 15px;
  color: var(--fg-muted);
}

/* Error */
.error-badge {
  width: 64px;
  height: 64px;
  border-radius: 20px;
  display: grid;
  place-items: center;
  color: #fecaca;
  background: var(--danger-soft);
  border: 1px solid rgba(248, 113, 113, 0.28);
  margin-bottom: 2px;
}

.error-badge svg {
  width: 28px;
  height: 28px;
}

.error-message {
  max-width: 52ch !important;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(248, 113, 113, 0.22);
  background: rgba(248, 113, 113, 0.08);
  color: #fecaca !important;
  font-size: 13px !important;
  text-align: left;
  word-break: break-word;
}

.error-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 4px;
}

/* Image result */
.image-stage {
  width: 100%;
  height: 100%;
  min-height: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  animation: fade-up 0.35s var(--ease);
}

.image-frame {
  position: relative;
  max-width: 100%;
  max-height: min(62vh, 720px);
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border-strong);
  background: #05040a;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.03),
    0 24px 60px rgba(0, 0, 0, 0.45),
    0 0 80px rgba(124, 58, 237, 0.08);
}

.image-frame img {
  display: block;
  max-width: min(100%, 920px);
  max-height: min(62vh, 720px);
  width: auto;
  height: auto;
  object-fit: contain;
  background: #05040a;
}

.image-caption {
  margin: 0;
  max-width: 64ch;
  text-align: center;
  color: var(--fg-muted);
  font-size: 13px;
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* History dock */
.history-dock {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--bg-panel);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow-sm);
  padding: 12px 14px 14px;
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.history-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--fg);
}

.history-title svg {
  width: 16px;
  height: 16px;
  color: var(--fg-muted);
  flex-shrink: 0;
}

.history-title strong {
  font-size: 13px;
  font-weight: 620;
}

.history-cap {
  color: var(--fg-faint);
  font-size: 12px;
}

.history-track {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.12) transparent;
  min-height: 88px;
}

.history-empty {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 88px;
  border-radius: var(--radius-md);
  border: 1px dashed var(--border);
  color: var(--fg-faint);
  font-size: 12.5px;
  background: rgba(0, 0, 0, 0.14);
}

.history-item {
  position: relative;
  flex: 0 0 auto;
  width: 88px;
  height: 88px;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #0a0812;
  padding: 0;
  cursor: pointer;
  transition: transform var(--duration) var(--ease), border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}

.history-item:hover {
  transform: translateY(-2px);
  border-color: rgba(139, 92, 246, 0.4);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
}

.history-item.active {
  border-color: rgba(139, 92, 246, 0.75);
  box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.28), 0 10px 24px rgba(124, 58, 237, 0.2);
}

.history-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.history-item span {
  position: absolute;
  left: 6px;
  bottom: 6px;
  min-width: 22px;
  height: 20px;
  padding: 0 6px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 700;
  color: white;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(6px);
}

/* Dialog */
.raw-dialog {
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  max-width: min(880px, calc(100vw - 32px));
  width: 100%;
}

.raw-dialog::backdrop {
  background: rgba(4, 3, 10, 0.72);
  backdrop-filter: blur(8px);
}

.dialog-card {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  background: linear-gradient(180deg, #151222, #0d0b15);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.dialog-head strong {
  display: block;
  font-size: 15px;
  font-weight: 650;
}

.dialog-head p {
  margin: 4px 0 0;
  color: var(--fg-muted);
  font-size: 12.5px;
}

.raw-dialog pre {
  margin: 0;
  max-height: min(62vh, 560px);
  overflow: auto;
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.55;
  color: #d8d0ee;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: var(--z-toast);
  transform: translateX(-50%) translateY(16px);
  max-width: min(480px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: rgba(18, 16, 28, 0.94);
  color: var(--fg);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-slow) var(--ease), transform var(--duration-slow) var(--ease);
  font-size: 13.5px;
  font-weight: 500;
  text-align: center;
  backdrop-filter: blur(12px);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.error {
  border-color: rgba(248, 113, 113, 0.35);
  background: rgba(48, 18, 24, 0.94);
  color: #fecaca;
}

/* Responsive */
@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: minmax(360px, 38%) minmax(0, 1fr);
  }

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

@media (max-width: 1120px) {
  .app-shell {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
    padding: 12px;
    gap: 12px;
  }

  .workspace {
    grid-template-columns: 1fr;
    flex: none;
    min-height: 0;
  }

  .console,
  .stage-column {
    position: static;
    height: auto;
    max-height: none;
  }

  .console-scroll {
    max-height: none;
    overflow: visible;
    scrollbar-gutter: auto;
  }

  .stage-card {
    min-height: 480px;
  }

  .desktop-only {
    display: none;
  }

  .topbar {
    flex-wrap: wrap;
  }

  .save-location {
    order: 3;
    flex-basis: 100%;
    justify-content: flex-start;
    padding: 6px 2px 0;
    border-top: 1px solid var(--border);
  }

  .save-location code {
    max-width: none;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 12px;
    border-radius: var(--radius-md);
  }

  .brand-copy span {
    display: none;
  }

  .brand-copy strong {
    font-size: 13.5px;
    white-space: nowrap;
  }

  .topbar-meta { gap: 6px; }

  .connection {
    padding: 7px 9px;
    font-size: 11.5px;
  }

  .connection-label { white-space: nowrap; }

  .save-location > span { display: none; }

  .topbar-hint { display: none; }

  .stage-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .stage-actions {
    justify-content: stretch;
  }

  .stage-actions .btn,
  .stage-actions a {
    flex: 1 1 auto;
  }

  .param-row {
    grid-template-columns: 1fr;
  }

  .ratio-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .ratio-btn:nth-child(4),
  .ratio-btn:nth-child(5) {
    grid-column: span 1;
  }

  .stage-viewport {
    padding: 20px 16px;
    min-height: 320px;
  }

  .stage-state h2 {
    font-size: 18px;
  }

  .action-row {
    flex-direction: column;
  }

  .action-row #cancel:not(.hidden) {
    order: 2;
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .blob {
    animation: none;
  }

  .ring-outer { animation: orbit-clockwise 2.4s linear infinite !important; }
  .ring-middle { animation: orbit-counter 1.8s linear infinite !important; }
  .ring-inner { animation: orbit-clockwise 1.25s linear infinite reverse !important; }
  .orbit-core { animation: orbit-core-pulse 1.6s ease-in-out infinite !important; }
  .orbit-a { animation: kinetic-clockwise 3.2s linear infinite !important; }
  .orbit-b { animation: kinetic-counter 2.35s linear infinite !important; }
  .orbit-c { animation: kinetic-clockwise 1.55s linear infinite reverse !important; }
  .kinetic-halo { animation: kinetic-halo 1.8s ease-in-out infinite !important; }
  .kinetic-core { animation: kinetic-core 1.8s ease-in-out infinite !important; }
}

/* Refined mineral dark theme: calmer chrome, clearer canvas focus. */
:root {
  --bg-deep: #070a0a;
  --bg-base: #0b0f0f;
  --bg-elevated: #111817;
  --bg-panel: rgba(15, 21, 20, 0.94);
  --bg-soft: rgba(208, 231, 226, 0.045);
  --bg-soft-2: rgba(208, 231, 226, 0.07);
  --bg-hover: rgba(208, 231, 226, 0.095);
  --bg-active: rgba(116, 205, 190, 0.14);
  --fg: #f3f8f6;
  --fg-secondary: #c5d3cf;
  --fg-muted: #91a29e;
  --fg-faint: #6f817d;
  --primary: #78cdbd;
  --primary-strong: #4eaa9d;
  --primary-soft: rgba(120, 205, 189, 0.14);
  --primary-glow: rgba(83, 181, 165, 0.24);
  --secondary: #96b9b2;
  --accent: #e7b78f;
  --accent-soft: rgba(231, 183, 143, 0.13);
  --success: #70d1aa;
  --success-soft: rgba(112, 209, 170, 0.13);
  --danger: #ef8b8b;
  --danger-soft: rgba(239, 139, 139, 0.12);
  --warning: #e8c27d;
  --border: rgba(199, 224, 218, 0.12);
  --border-strong: rgba(199, 224, 218, 0.2);
  --border-focus: rgba(120, 205, 189, 0.78);
  --ring: 0 0 0 3px rgba(120, 205, 189, 0.2);
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 11px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.28);
  --shadow-md: 0 18px 42px rgba(0, 0, 0, 0.24);
  --shadow-lg: 0 28px 70px rgba(0, 0, 0, 0.44);
  --shadow-glow: 0 0 0 1px rgba(120, 205, 189, 0.18), 0 14px 38px rgba(41, 117, 108, 0.18);
}

html { background: var(--bg-deep); }
body {
  background: var(--bg-deep);
  color: var(--fg);
}
body::before {
  background-image:
    linear-gradient(rgba(183, 219, 211, 0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(183, 219, 211, 0.018) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: linear-gradient(to bottom, black, transparent 86%);
  opacity: 0.55;
}
.ambient, .blob { display: none; }
::selection { color: #07100f; background: var(--primary); }
:focus-visible { box-shadow: var(--ring); }
.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 100;
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #15211f;
  color: var(--fg);
  transform: translateY(-160%);
  transition: transform var(--duration) var(--ease);
}
.skip-link:focus { transform: translateY(0); }

.app-shell { max-width: 1720px; padding: 18px; gap: 14px; }
.topbar {
  min-height: 60px;
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  border-color: var(--border);
  background: rgba(13, 19, 18, 0.96);
  box-shadow: var(--shadow-sm);
}
.brand { gap: 11px; }
.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  color: #b7f2e7;
  background: #17332f;
  border: 1px solid rgba(120, 205, 189, 0.28);
  box-shadow: 0 8px 22px rgba(41, 117, 108, 0.2);
}
.brand-copy strong { font-size: 15px; letter-spacing: -0.01em; }
.brand-copy span { color: var(--fg-muted); }
.connection { background: rgba(208, 231, 226, 0.04); border-color: var(--border); }
.connection-dot { background: #80918d; }
.connection.ready { color: #a9eed0; border-color: rgba(112, 209, 170, 0.3); background: var(--success-soft); }
.connection.error { color: #ffc8c8; border-color: rgba(239, 139, 139, 0.3); background: var(--danger-soft); }
.topbar-hint kbd { background: #111817; border-color: var(--border-strong); }

.workspace { gap: 14px; }
.console, .stage-card, .history-dock {
  border-color: var(--border);
  background: var(--bg-panel);
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(16px) saturate(115%);
}
.console-scroll { padding: 13px; gap: 10px; }
.panel {
  border-radius: var(--radius-lg);
  border-color: rgba(199, 224, 218, 0.1);
  background: linear-gradient(180deg, rgba(208, 231, 226, 0.035), transparent 42%), rgba(208, 231, 226, 0.018);
}
.panel:hover { border-color: rgba(120, 205, 189, 0.25); }
.panel-head { padding: 13px 13px 11px; }
.panel-title { gap: 10px; }
.panel-title strong { font-size: 13px; }
.panel-title p { color: var(--fg-muted); }
.panel-icon {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  color: #b8cfca;
  background: rgba(208, 231, 226, 0.055);
  border-color: var(--border);
}
.panel-icon.accent {
  color: #f4c9a6;
  background: var(--accent-soft);
  border-color: rgba(231, 183, 143, 0.26);
}
.section-action { background: rgba(208, 231, 226, 0.045); border-color: var(--border); }
.panel-body { padding: 0 13px 13px; gap: 11px; }
.field { gap: 6px; }
.field-label { color: var(--fg-secondary); }
.field-label em { color: var(--fg-muted); background: rgba(208, 231, 226, 0.04); border-color: var(--border); }
.field input, .field select, .field textarea, select, textarea, input[type="url"], input[type="password"], input[type="text"] {
  border-radius: var(--radius-sm);
  border-color: rgba(199, 224, 218, 0.14);
  background: rgba(4, 8, 8, 0.5);
}
.field input:hover, .field select:hover, .field textarea:hover { border-color: var(--border-strong); background: rgba(4, 8, 8, 0.68); }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--border-focus); background: rgba(4, 8, 8, 0.76); }
.field input::placeholder, .field textarea::placeholder { color: #71817e; }

.chip { border-color: var(--border); background: rgba(208, 231, 226, 0.04); }
.chip:hover { color: var(--fg); border-color: rgba(120, 205, 189, 0.46); background: var(--primary-soft); }
.segmented { background: rgba(4, 8, 8, 0.5); border-color: var(--border); }
.seg-btn.active { color: #07100f; background: var(--primary); box-shadow: 0 6px 16px rgba(41, 117, 108, 0.22); }
.seg-btn.active svg { color: #07100f; }
.upload-zone { border-color: rgba(199, 224, 218, 0.16); background: rgba(208, 231, 226, 0.025); }
.upload-zone:hover, .upload-zone.dragover { border-color: rgba(120, 205, 189, 0.58); background: var(--primary-soft); }
.upload-visual { color: var(--primary); background: rgba(120, 205, 189, 0.12); border-color: rgba(120, 205, 189, 0.24); }
.ratio-btn { border-color: var(--border); background: rgba(208, 231, 226, 0.025); }
.ratio-btn:hover { border-color: rgba(120, 205, 189, 0.44); background: var(--primary-soft); }
.ratio-btn.active { color: #bff1e6; border-color: rgba(120, 205, 189, 0.7); background: rgba(120, 205, 189, 0.12); box-shadow: inset 0 0 0 1px rgba(120, 205, 189, 0.14); }
.ratio-box { border-color: currentColor; }
.size-pill, .check-pill { border-color: var(--border); background: rgba(208, 231, 226, 0.035); }
.check-pill:hover { border-color: rgba(120, 205, 189, 0.4); background: var(--primary-soft); }

.btn-primary { color: #07100f; background: var(--primary); box-shadow: 0 10px 24px rgba(41, 117, 108, 0.22); }
.btn-primary:hover:not(:disabled) { background: #92ddcf; box-shadow: 0 12px 28px rgba(41, 117, 108, 0.3); }
.btn-primary .btn-glow { display: none; }
.btn-secondary { color: #c4efe7; border-color: rgba(120, 205, 189, 0.32); background: rgba(120, 205, 189, 0.1); }
.btn-secondary:hover:not(:disabled) { border-color: rgba(120, 205, 189, 0.62); background: rgba(120, 205, 189, 0.17); }
.btn-ghost { color: var(--fg-secondary); border-color: var(--border); background: rgba(208, 231, 226, 0.025); }
.btn-ghost:hover:not(:disabled) { color: var(--fg); border-color: var(--border-strong); background: rgba(208, 231, 226, 0.075); }
.icon-btn { border-color: var(--border); background: rgba(208, 231, 226, 0.04); }
.icon-btn:hover { color: var(--fg); border-color: rgba(120, 205, 189, 0.5); background: var(--primary-soft); }
.console-footer { background: rgba(11, 16, 15, 0.96); border-top-color: var(--border); }
.summary-dot { background: var(--primary); box-shadow: 0 0 10px rgba(120, 205, 189, 0.5); }

.stage-toolbar { padding: 13px 15px; border-bottom-color: var(--border); background: rgba(208, 231, 226, 0.018); }
.stage-badge { color: #c4efe7; background: var(--primary-soft); border-color: rgba(120, 205, 189, 0.3); }
.stage-title h1 { font-size: 16px; letter-spacing: -0.015em; }
.stage-viewport {
  padding: 28px;
  background-color: #0a0f0e;
  background-image:
    linear-gradient(rgba(183, 219, 211, 0.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(183, 219, 211, 0.022) 1px, transparent 1px);
  background-size: 40px 40px;
}
.stage-state h2 { font-size: 21px; }
.stage-state p { color: var(--fg-muted); }
.empty-visual { color: #9ee2d4; }
.empty-frame { border-color: rgba(120, 205, 189, 0.32); background: rgba(120, 205, 189, 0.06); box-shadow: 0 16px 40px rgba(41, 117, 108, 0.12); }
.empty-frame span { border-color: rgba(158, 226, 212, 0.75); }
.empty-steps li { border-color: var(--border); background: rgba(4, 8, 8, 0.28); color: var(--fg-secondary); }
.empty-steps span { color: #c4efe7; background: var(--primary-soft); border-color: rgba(120, 205, 189, 0.28); }
.elapsed-chip { border-color: var(--border); background: rgba(4, 8, 8, 0.42); }
.error-message { border-color: rgba(239, 139, 139, 0.25); background: var(--danger-soft); }
.image-frame { border-color: var(--border-strong); box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.025), 0 24px 60px rgba(0, 0, 0, 0.42); }
.history-dock { padding: 11px 13px 13px; }
.history-empty { border-color: rgba(199, 224, 218, 0.18); background: rgba(4, 8, 8, 0.2); }
.history-item { border-color: var(--border); background: #090e0d; }
.history-item:hover { border-color: rgba(120, 205, 189, 0.5); }
.history-item.active { border-color: rgba(120, 205, 189, 0.8); box-shadow: 0 0 0 2px rgba(120, 205, 189, 0.2), 0 10px 24px rgba(41, 117, 108, 0.16); }
.raw-dialog::backdrop { background: rgba(3, 7, 7, 0.78); }
.dialog-card { background: linear-gradient(180deg, #14201e, #0c1211); border-color: var(--border-strong); }
.toast { background: rgba(17, 24, 23, 0.96); border-color: var(--border-strong); }

@media (max-width: 1120px) {
  .app-shell { padding: 12px; }
  .console, .stage-card, .history-dock { box-shadow: var(--shadow-sm); }
}
@media (max-width: 640px) {
  .topbar { border-radius: var(--radius-md); }
  .stage-viewport { padding: 20px 16px; }
  .stage-state h2 { font-size: 19px; }
}
/* Touch and status target normalization. */
.icon-btn { min-width: 44px; min-height: 44px; }
.stepper {
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  height: 45px;
  min-height: 45px;
  border-color: rgba(199, 224, 218, 0.14);
  background: rgba(4, 8, 8, 0.5);
}
.stepper .icon-btn { width: 44px; height: 44px; }
.stepper .icon-btn:first-child { border-right: 1px solid var(--border); }
.stepper .icon-btn:last-child { border-left: 1px solid var(--border); }
.seg-btn { min-height: 44px; }
@media (max-width: 640px) {
  .chip { min-height: 44px; }
}

/* Light theme: cool paper surfaces with the same mineral accent. */
html[data-theme="light"] {
  color-scheme: light;
  --bg-deep: #edf2f0;
  --bg-base: #f4f7f6;
  --bg-elevated: #ffffff;
  --bg-panel: rgba(250, 252, 251, 0.97);
  --bg-soft: rgba(22, 58, 52, 0.055);
  --bg-soft-2: rgba(22, 58, 52, 0.085);
  --bg-hover: rgba(40, 121, 108, 0.1);
  --bg-active: rgba(40, 121, 108, 0.15);
  --fg: #15201e;
  --fg-secondary: #344a46;
  --fg-muted: #5d706c;
  --fg-faint: #71827e;
  --primary: #28796c;
  --primary-strong: #1e695e;
  --primary-soft: rgba(40, 121, 108, 0.11);
  --primary-glow: rgba(40, 121, 108, 0.18);
  --secondary: #527b73;
  --accent: #a66332;
  --accent-soft: rgba(166, 99, 50, 0.1);
  --success: #227a54;
  --success-soft: rgba(34, 122, 84, 0.1);
  --danger: #b53b3b;
  --danger-soft: rgba(181, 59, 59, 0.09);
  --warning: #9b6a1d;
  --border: rgba(31, 65, 59, 0.15);
  --border-strong: rgba(31, 65, 59, 0.25);
  --border-focus: rgba(40, 121, 108, 0.78);
  --ring: 0 0 0 3px rgba(40, 121, 108, 0.18);
  --shadow-sm: 0 1px 2px rgba(23, 45, 41, 0.08);
  --shadow-md: 0 14px 36px rgba(23, 45, 41, 0.1);
  --shadow-lg: 0 28px 70px rgba(23, 45, 41, 0.18);
}

html[data-theme="light"] body {
  background: #edf2f0;
}

html[data-theme="light"] body::before {
  background-image:
    linear-gradient(rgba(31, 65, 59, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(31, 65, 59, 0.035) 1px, transparent 1px);
  opacity: 0.45;
}

html[data-theme="light"] ::selection {
  color: #ffffff;
  background: var(--primary);
}

html[data-theme="light"] .skip-link {
  color: #ffffff;
  background: #205f55;
}

html[data-theme="light"] .topbar {
  background: rgba(248, 251, 250, 0.97);
}

html[data-theme="light"] .brand-mark {
  color: #155b51;
  background: #d9ece7;
  border-color: rgba(40, 121, 108, 0.28);
  box-shadow: 0 7px 18px rgba(40, 121, 108, 0.13);
}

html[data-theme="light"] .connection.ready { color: #196444; }
html[data-theme="light"] .connection.error { color: #a33232; }
html[data-theme="light"] .topbar-hint kbd { background: #ffffff; }

html[data-theme="light"] .console,
html[data-theme="light"] .stage-card,
html[data-theme="light"] .history-dock {
  background: var(--bg-panel);
}

html[data-theme="light"] .panel {
  background: linear-gradient(180deg, rgba(40, 121, 108, 0.035), transparent 42%), rgba(255, 255, 255, 0.72);
}

html[data-theme="light"] .panel-icon { color: #365f58; }
html[data-theme="light"] .panel-icon.accent { color: #8a4c20; }

html[data-theme="light"] .field input,
html[data-theme="light"] .field select,
html[data-theme="light"] .field textarea,
html[data-theme="light"] select,
html[data-theme="light"] textarea,
html[data-theme="light"] input[type="url"],
html[data-theme="light"] input[type="password"],
html[data-theme="light"] input[type="text"] {
  color: var(--fg);
  background-color: #ffffff;
  border-color: rgba(31, 65, 59, 0.2);
}

html[data-theme="light"] .field input:hover,
html[data-theme="light"] .field select:hover,
html[data-theme="light"] .field textarea:hover,
html[data-theme="light"] .field input:focus,
html[data-theme="light"] .field select:focus,
html[data-theme="light"] .field textarea:focus {
  background-color: #ffffff;
}

html[data-theme="light"] .field input::placeholder,
html[data-theme="light"] .field textarea::placeholder { color: #748680; }

html[data-theme="light"] .segmented { background: rgba(31, 65, 59, 0.055); }
html[data-theme="light"] .stepper {
  border-color: rgba(31, 65, 59, 0.2);
  background: #ffffff;
}

html[data-theme="light"] .seg-btn.active,
html[data-theme="light"] .btn-primary {
  color: #ffffff;
  background: var(--primary);
}

html[data-theme="light"] .seg-btn.active svg { color: #ffffff; }
html[data-theme="light"] .btn-primary:hover:not(:disabled) { background: #1f6d61; }
html[data-theme="light"] .btn-secondary { color: #1e665a; }
html[data-theme="light"] .ratio-btn.active { color: #1d6a5e; }

html[data-theme="light"] .console-footer {
  background: rgba(246, 250, 248, 0.98);
}

html[data-theme="light"] .stage-viewport {
  background-color: #e7eeeb;
  background-image:
    linear-gradient(rgba(31, 65, 59, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(31, 65, 59, 0.055) 1px, transparent 1px);
}

html[data-theme="light"] .empty-visual { color: #28796c; }
html[data-theme="light"] .stage-badge,
html[data-theme="light"] .empty-steps span {
  color: #1d675c;
  border-color: rgba(40, 121, 108, 0.25);
}
html[data-theme="light"] .empty-steps li,
html[data-theme="light"] .history-empty,
html[data-theme="light"] .elapsed-chip { background: rgba(255, 255, 255, 0.66); }

html[data-theme="light"] .dialog-card {
  background: linear-gradient(180deg, #ffffff, #f3f7f5);
}

html[data-theme="light"] .raw-dialog::backdrop { background: rgba(28, 40, 37, 0.45); }
html[data-theme="light"] .raw-dialog pre { color: #29413c; }

html[data-theme="light"] .toast {
  color: #f5fbf9;
  background: rgba(25, 50, 45, 0.96);
}

html[data-theme="light"] .toast.error {
  color: #fff4f4;
  background: rgba(120, 34, 34, 0.96);
}
