@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;700;800&family=Noto+Sans+SC:wght@400;500;700&display=swap');

:root {
  --bg: #232323;
  --bg-soft: #2A2A2A;
  --bg-card: #2E2E2E;
  --ink: #FFFFFF;
  --ink-dim: #A0A0A0;
  --accent: #896CFE;
  /* Purple */
  --accent-light: #B3A0FF;
  /* Light Purple */
  --accent-bright: #E2F163;
  /* Lime Green */
  --success: #0f766e;
  --brand-pink: #E2F163;
  /* Reused Lime Green for hints */
  --brand-purple: #896CFE;
  --text-muted: #888888;

  --font-body: 'Outfit', 'Noto Sans SC', sans-serif;
  --font-display: 'GEOMETOS', 'OPPOSans', 'Outfit', 'Noto Sans SC', sans-serif;

  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;

  --shadow-soft: 0 8px 24px rgba(0, 0, 0, 0.2);
  --shadow-strong: 0 12px 32px rgba(0, 0, 0, 0.3);

  /* Pixel Editor Adaptive Scaling Defaults */
  --pe-ui-scale: 1;
  --pe-font-size: calc(0.85rem * var(--pe-ui-scale));
  --pe-chip-size: calc(44px * var(--pe-ui-scale));
  --pe-toolbar-strip-width: calc(var(--pe-chip-size) + 16px);
  --pe-toolbar-float-gap: calc(12px * var(--pe-ui-scale));
  --pe-toolbar-reserve: calc(var(--pe-toolbar-strip-width) + var(--pe-toolbar-float-gap) + 8px);
  --pe-sidebar-width: calc(280px * var(--pe-ui-scale));
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --app-vh: 100vh;
}

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

body {
  font-family: var(--font-body);
  color: var(--ink);
  line-height: 1.6;
  min-height: var(--app-vh);
  margin: 0;
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--bg);
  touch-action: manipulation;
}

body.pe-open {
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

.single-page {
  width: 100%;
  padding-top: calc(96px + var(--safe-top));
  padding-bottom: calc(56px + var(--safe-bottom));
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.8s cubic-bezier(0.16, 1, 0.3, 1) 0.3s, transform 0.8s cubic-bezier(0.16, 1, 0.3, 1) 0.3s;
}

body.page-loaded .single-page {
  opacity: 1;
  transform: translateY(0);
}

/* Hero container removed */

.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  /* Ensure navbar is always on top (over wrapper content) */
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: calc(14px + var(--safe-top)) calc(24px + var(--safe-right)) 14px calc(24px + var(--safe-left));
  background: rgba(35, 35, 35, 0.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.6s cubic-bezier(0.16, 1, 0.3, 1) 0.5s, transform 0.6s cubic-bezier(0.16, 1, 0.3, 1) 0.5s;
}

body.page-loaded .navbar {
  opacity: 1;
  transform: translateY(0);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
  font-family: var(--font-display);
  letter-spacing: 1px;
  font-size: 1.6rem;
}

.navbar-desktop {
  width: 100%;
  display: flex;
  align-items: center;
}

.mobile-nav-tabs {
  display: none;
}

.mobile-nav-tab {
  min-width: 44px;
  min-height: 44px;
  border-radius: 14px;
  color: rgba(255, 255, 255, 0.68);
  text-decoration: none;
  border: 1px solid transparent;
}

.logo-icon {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-display);
  font-size: 1.15rem;
  box-shadow: 0 4px 12px rgba(137, 108, 254, 0.4);
}

.nav-logo-icon {
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.nav-config {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.nav-config input,
.nav-config select,
input[type="number"],
input[type="text"] {
  background: var(--bg-soft);
  color: var(--ink);
  border: none;
  border-radius: 4px;
  /* Slightly squarer, more tech feel */
  padding: 9px 14px;
  font-family: inherit;
  font-size: 0.86rem;
  outline: none;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
  transition: box-shadow 0.2s ease;
}

.nav-config input:focus,
.nav-config select:focus,
input:focus {
  box-shadow: inset 0 0 0 1px var(--accent-light), 0 0 0 2px rgba(137, 108, 254, 0.2);
}

.btn,
.icon-btn,
.mobile-nav-tab,
.color-chip,
.pe-tool-btn,
.pe-action-toolbar .icon-btn,
.pe-palette-item,
.upload-mobile-cta {
  min-height: 44px;
}

a,
button,
input,
select,
textarea,
[role="button"] {
  touch-action: manipulation;
}

/* Intro Loader Styles */
.intro-loader {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.6s cubic-bezier(0.16, 1, 0.3, 1), transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
  opacity: 1;
  pointer-events: all;
}

.intro-loader.pwa-launch {
  background:
    radial-gradient(circle at 50% 35%, rgba(137, 108, 254, 0.28), transparent 54%),
    var(--bg);
}

.intro-loader.hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(1.02);
}

.intro-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.pwa-standalone .intro-content {
  transform: translateY(-8px);
}

.intro-logo {
  width: 80px;
  height: 80px;
  object-fit: contain;
  filter: drop-shadow(0 0 32px rgba(137, 108, 254, 0.6));
  animation: pulseLogo 2s infinite alternate ease-in-out;
}

@keyframes pulseLogo {
  0% {
    transform: scale(0.98);
    filter: drop-shadow(0 0 24px rgba(137, 108, 254, 0.4));
  }

  100% {
    transform: scale(1.02);
    filter: drop-shadow(0 0 40px rgba(137, 108, 254, 0.8));
  }
}

.intro-wordmark {
  font-family: var(--font-display);
  letter-spacing: 0.04em;
  font-size: 3.5rem;
  font-weight: 800;
  line-height: 1;
  color: var(--ink);
}

.intro-progress-container {
  width: 180px;
  height: 3px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 16px;
}

.intro-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--brand-pink);
  box-shadow: 0 0 10px rgba(226, 241, 99, 0.6);
  border-radius: 4px;
  /* JS animated width */
}

.main-container {
  width: min(1380px, 100% - 36px);
  margin: 0 auto;
  padding: 22px 0 60px;
}

.section-title {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-family: var(--font-display);
  letter-spacing: 1px;
  font-size: 2rem;
  margin-bottom: 20px;
}

.section-title svg {
  width: 24px;
  height: 24px;
  color: var(--accent);
}

.tools-grid {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.workspace-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 28px;
  align-items: start;
}

.mobile-flow-shell,
.mobile-flow-track,
.mobile-flow-page {
  display: contents;
}

.config-sidebar {
  grid-column: 2;
  grid-row: 1 / span 2;
  position: sticky;
  top: 94px;
}

.config-sidebar-inner {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(6px);
}

.config-sidebar-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  letter-spacing: 0.6px;
  margin-bottom: 4px;
  color: #fff;
}

.config-sidebar-desc {
  font-size: 0.82rem;
  color: #cfcfcf;
  margin-bottom: 12px;
}

#uploadCard {
  grid-column: 1;
  grid-row: 1;
  order: 1;
}

#renderCard {
  grid-column: 1;
  grid-row: 2;
  order: 2;
}

.card {
  background: var(--bg-card);
  color: var(--ink);
  border: none;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
  position: relative;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  display: flex;
  flex-direction: column;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-strong);
}

.card-header {
  background: var(--accent);
  color: #fff;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-header-title {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
}

.header-arrow {
  font-size: 0.8rem;
  color: var(--accent-bright);
}

.card-tag {
  font-family: var(--font-display);
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.7);
  background: rgba(0, 0, 0, 0.15);
  padding: 2px 8px;
  border-radius: 4px;
}

.card-content {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--bg-card);
}

/* Specific fix for text inside card-content since the background is white */
.card-content p,
.card-content .param-label,
.card-content .checkbox-wrapper .param-label {
  color: var(--ink);
}

.card-description {
  color: var(--ink-dim);
  font-size: 0.92rem;
}

.control-group,
.control-grid-combined {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 0;
}

.config-sidebar .control-group {
  gap: 12px;
}

.config-cluster {
  position: relative;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.02) 0%, rgba(255, 255, 255, 0.05) 100%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 8px 22px rgba(137, 108, 254, 0.08);
}

.cluster-title {
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--accent-light);
  margin-bottom: 10px;
  text-transform: uppercase;
}

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

.param-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  background: var(--bg-soft);
  border: none;
  border-radius: var(--radius-md);
  padding: 11px 12px;
}

.param-row-featured {
  background: rgba(137, 108, 254, 0.1);
  border: 1px solid rgba(137, 108, 254, 0.16);
}

.param-row-full {
  grid-column: 1 / -1;
}

.param-label-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.param-label {
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 700;
}

.param-row-critical {
  position: relative;
  border-color: rgba(226, 241, 99, 0.35);
  background: linear-gradient(135deg, rgba(226, 241, 99, 0.12) 0%, rgba(137, 108, 254, 0.14) 100%);
}

.param-critical-badge {
  flex: 0 0 auto;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(226, 241, 99, 0.45);
  background: rgba(226, 241, 99, 0.18);
  color: #24270f;
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.05em;
}

.param-hint {
  color: var(--ink-dim);
  font-size: 0.72rem;
  font-weight: 600;
}

.param-val {
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 700;
}

input[type="number"] {
  width: 100%;
  border-radius: var(--radius-sm);
  text-align: left;
}

#maxColors {
  max-width: 180px;
}

#maxColorsRow {
  scroll-margin-top: 100px;
}

#maxColorsRow.is-guided {
  animation: maxColorsGuidePulse 1.25s cubic-bezier(0.16, 1, 0.3, 1) 1;
}

@keyframes maxColorsGuidePulse {
  0% {
    transform: translateY(0);
    box-shadow: 0 0 0 0 rgba(226, 241, 99, 0.45);
  }

  35% {
    transform: translateY(-2px);
    box-shadow: 0 0 0 7px rgba(226, 241, 99, 0.24), 0 16px 24px rgba(111, 90, 245, 0.22);
  }

  100% {
    transform: translateY(0);
    box-shadow: 0 0 0 0 rgba(226, 241, 99, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  #maxColorsRow.is-guided {
    animation: none;
    box-shadow: 0 0 0 2px rgba(226, 241, 99, 0.45);
  }
}

input[type="text"] {
  width: 100%;
  border-radius: var(--radius-sm);
}

select {
  width: 100%;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-family: inherit;
  font-size: 0.86rem;
  outline: none;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

select:focus {
  border-color: #7d69ff;
  box-shadow: 0 0 0 3px rgba(125, 105, 255, 0.18);
}

.algorithm-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.algorithm-toggle input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.algorithm-toggle label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: var(--bg);
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.2s ease;
}

.algorithm-toggle label:hover {
  transform: translateY(-1px);
  border-color: #b8adff;
}

.algorithm-toggle input[type="radio"]:checked+label {
  color: #fff;
  border-color: #7d69ff;
  background: linear-gradient(120deg, #6f5af5, #9178ff);
  box-shadow: 0 8px 18px rgba(111, 90, 245, 0.26);
}

input[type="range"] {
  width: 100%;
  appearance: none;
  height: 10px;
  border-radius: 999px;
  background: #E0E0E0;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 2px 6px rgba(137, 108, 254, 0.4);
  cursor: pointer;
}

.checkbox-wrapper {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  background: var(--bg-soft);
  border: none;
  border-radius: var(--radius-md);
  padding: 6px 10px;
}

.checkbox-wrapper input {
  width: 13px;
  height: 13px;
  accent-color: var(--accent);
}

.btn {
  width: 100%;
  border: none;
  border-radius: 24px;
  padding: 12px 20px;
  font-size: 1rem;
  font-weight: 700;
  font-family: var(--font-body);
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn:hover:not(:disabled) {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  filter: grayscale(0.5);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 12px rgba(137, 108, 254, 0.3);
}

.btn-secondary {
  background: var(--accent-bright);
  color: #111;
  box-shadow: 0 4px 12px rgba(226, 241, 99, 0.3);
}

.btn-export {
  background: linear-gradient(160deg, #1a1a23 0%, #232330 100%);
  color: #f5f6ff;
  border: 1px solid rgba(137, 108, 254, 0.36);
  box-shadow: 0 10px 20px rgba(10, 10, 16, 0.38), inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}

.btn-export:hover:not(:disabled) {
  border-color: rgba(137, 108, 254, 0.58);
}

.btn-toggle {
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 0.88rem;
}

.btn-toggle.is-on {
  background: linear-gradient(120deg, #6f5af5, #9178ff);
  color: #fff;
  box-shadow: 0 8px 18px rgba(111, 90, 245, 0.26);
}

.btn-toggle.is-off {
  background: #3a3a3a;
  color: #d0d0d0;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.btn-compact {
  padding: 6px 16px;
  font-size: 0.85rem;
  white-space: nowrap;
}

.remove-bg-params {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.remove-bg-params.is-disabled {
  opacity: 0.48;
}

.advanced-settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-top: 4px;
  transition: background 0.2s ease;
  user-select: none;
}

.advanced-settings-header:hover {
  background: rgba(255, 255, 255, 0.08);
}

.advanced-settings-header span {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink-dim);
}

.advanced-settings-header .toggle-icon {
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  color: var(--ink-dim);
}

.advanced-settings-header.is-expanded .toggle-icon {
  transform: rotate(180deg);
}

.advanced-params-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
  transition: max-height 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
  max-height: 1000px;
  opacity: 1;
}

.advanced-params-content.is-collapsed {
  max-height: 0;
  opacity: 0;
  pointer-events: none;
}

.clickable-trigger {
  cursor: pointer;
}

.file-input-hidden {
  display: none;
}

.is-hidden {
  display: none !important;
}

.upload-zone {
  border: 2px dashed rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-md);
  width: min(100%, 560px);
  aspect-ratio: 1 / 1;
  margin-inline: auto;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  background: var(--bg-soft);
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--accent);
  background: rgba(137, 108, 254, 0.05);
}

.upload-icon-wrapper {
  margin-bottom: 12px;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.upload-custom-icon {
  width: 56px;
  height: 56px;
  object-fit: contain;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.3));
  transition: all 0.3s ease;
}

.upload-zone:hover .upload-icon-wrapper,
.upload-zone.drag-over .upload-icon-wrapper {
  transform: scale(1.15) translateY(-4px);
}

.upload-zone:hover .upload-custom-icon,
.upload-zone.drag-over .upload-custom-icon {
  filter: drop-shadow(0 8px 16px rgba(137, 108, 254, 0.5));
}

.upload-zone p {
  color: var(--ink-dim);
  font-size: 0.9rem;
  margin: 0;
}

.upload-zone p span {
  color: var(--accent);
  font-weight: 700;
}

.upload-mobile-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border-radius: 999px;
  border: 1px solid rgba(137, 108, 254, 0.5);
  background: rgba(137, 108, 254, 0.2);
  color: #fff;
  font-family: var(--font-display);
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.upload-mobile-cta:hover {
  transform: translateY(-1px);
  background: rgba(137, 108, 254, 0.36);
  box-shadow: 0 8px 24px rgba(137, 108, 254, 0.32);
}

.upload-mobile-cta:focus-visible {
  outline: 2px solid var(--accent-bright);
  outline-offset: 2px;
}

.upload-hint {
  margin-top: 2px;
  opacity: 0.8;
}

.upload-preview {
  margin-top: 12px;
  background: var(--bg-soft);
  border: none;
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Fullscreen Crop Styles */
.file-info {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
  text-align: center;
}

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

.upload-preview img,
.result-img {
  max-width: 100%;
  max-height: min(70vh, 460px);
  border-radius: 8px;
  image-rendering: pixelated;
}

.fs-crop-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(20, 20, 20, 0.95);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.fs-crop-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.fs-crop-workspace {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 90vw;
  max-height: 90vh;
}

.fs-crop-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 0.92rem;
  letter-spacing: 0.04em;
  color: rgba(255, 255, 255, 0.9);
  text-align: center;
}

.fs-crop-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  width: 100%;
  min-width: 0;
}

.fs-crop-container {
  position: relative;
  overflow: hidden;
  user-select: none;
  cursor: crosshair;
  background: repeating-conic-gradient(rgba(255, 255, 255, 0.05) 0% 25%, transparent 0% 50%) 50% / 20px 20px;
  border-radius: var(--radius-md);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  display: flex;
}

.fs-crop-img {
  max-width: calc(90vw - 80px);
  /* Leave room for toolbar */
  max-height: calc(90vh - 68px);
  display: block;
  -webkit-user-drag: none;
}

.fs-crop-box {
  position: absolute;
  border: 2px solid var(--accent-bright);
  background: rgba(137, 108, 254, 0.2);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.65);
  pointer-events: none;
  display: none;
}

.fs-crop-toolbar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: rgba(255, 255, 255, 0.05);
  padding: 12px;
  border-radius: 100px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.fs-crop-toolbar .icon-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.fs-crop-toolbar .icon-btn:hover {
  background: var(--accent);
  transform: scale(1.1);
  box-shadow: 0 4px 16px rgba(137, 108, 254, 0.4);
}

.fs-crop-toolbar .icon-btn-danger:hover {
  background: #f43f5e;
  box-shadow: 0 4px 16px rgba(244, 63, 94, 0.4);
}

.fs-crop-toolbar .icon-btn svg {
  width: 22px;
  height: 22px;
}

.result-area {
  margin-top: 6px;
  display: none;
  animation: fadeIn 0.22s ease-out;
  gap: 12px;
}

.result-area.visible {
  display: grid;
}

/* Image Preview Overlay */
.fs-preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 2001;
  background: rgba(10, 10, 10, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.3s ease;
  cursor: zoom-out;
  overflow: hidden;
}

.fs-preview-close-btn {
  position: fixed;
  top: calc(12px + var(--safe-top));
  right: calc(12px + var(--safe-right));
  width: 44px;
  height: 44px;
  z-index: 2;
}

.fs-preview-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.fs-preview-img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  image-rendering: pixelated;
  transition: transform 0.15s linear;
  transform: scale(1);
  transform-origin: center center;
}

.fs-preview-hint {
  position: absolute;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.85rem;
  background: rgba(0, 0, 0, 0.5);
  padding: 8px 16px;
  border-radius: 20px;
  pointer-events: none;
  backdrop-filter: blur(4px);
  transition: opacity 0.3s ease;
}

.fs-preview-overlay.hidden .fs-preview-hint {
  opacity: 0;
}

.cut-preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 2002;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.25s ease;
}

.cut-preview-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.cut-preview-panel {
  width: min(1200px, calc(100vw - 32px));
  height: min(800px, calc(100vh - 48px));
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  box-shadow: var(--shadow-strong);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.cut-preview-header {
  position: relative;
  background: var(--accent);
  color: #fff;
  padding: 14px 72px 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.cut-preview-title-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cut-preview-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
}

.cut-preview-meta {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.8);
  font-weight: 500;
}

.cut-preview-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.cut-preview-close-btn {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
}

.scale-control {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0, 0, 0, 0.2);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
}

.scale-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.9);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.scale-slider {
  width: 100px;
  height: 8px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  outline: none;
}

.scale-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  background: var(--accent-bright);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.3);
}

.scale-value {
  font-size: 0.8rem;
  color: var(--accent-bright);
  font-weight: 700;
  min-width: 28px;
}

.cut-preview-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 20px;
  gap: 16px;
  background: var(--bg);
}

.cut-preview-warning {
  background: rgba(226, 241, 99, 0.1);
  border: 1px solid rgba(226, 241, 99, 0.2);
  color: var(--accent-bright);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.cut-preview-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--tile-display-size, 100px), 1fr));
  grid-auto-rows: min-content;
  gap: 12px;
  padding: 4px;
}

.tile-card {
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-md);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.tile-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.tile-img-container {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.15);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.cut-preview-tile {
  image-rendering: pixelated;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: fill;
}

.tile-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px;
}

.tile-index {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--accent-bright);
  background: rgba(0, 0, 0, 0.2);
  padding: 2px 6px;
  border-radius: 4px;
}

.tile-coord {
  font-size: 0.65rem;
  color: var(--ink-dim);
  font-weight: 500;
}

.result-img.zoomable {
  cursor: zoom-in;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s ease;
}

.result-img.zoomable:hover {
  transform: scale(1.03);
  box-shadow: 0 8px 24px rgba(137, 108, 254, 0.2);
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(5px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.result-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.result-box {
  width: 100%;
  text-align: center;
  background: var(--bg-soft);
  border: none;
  border-radius: var(--radius-md);
  padding: 16px;
}

.result-box h4 {
  margin-bottom: 12px;
  font-size: 0.85rem;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--ink);
  font-family: var(--font-display);
}

.result-box-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-bottom: 4px;
}

.result-box-header h4 {
  margin-bottom: 0;
}

.btn-grid-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border: 1px solid rgba(137, 108, 254, 0.3);
  border-radius: 8px;
  background: rgba(137, 108, 254, 0.12);
  color: var(--accent-light);
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  white-space: nowrap;
  user-select: none;
  line-height: 1;
}

.btn-grid-toggle svg {
  flex-shrink: 0;
  transition: opacity 0.2s ease;
}

.btn-grid-toggle.is-on {
  background: linear-gradient(120deg, rgba(111, 90, 245, 0.35), rgba(145, 120, 255, 0.25));
  border-color: rgba(137, 108, 254, 0.5);
  color: #fff;
  box-shadow: 0 2px 8px rgba(111, 90, 245, 0.2);
}

.btn-grid-toggle.is-off {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.1);
  color: var(--ink-dim);
  box-shadow: none;
}

.btn-grid-toggle.is-off svg {
  opacity: 0.5;
}

.btn-grid-toggle:hover {
  transform: translateY(-1px);
  filter: brightness(1.15);
}

.btn-grid-toggle:active {
  transform: translateY(0);
}

.zoom-container {
  overflow: auto;
  min-height: 240px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Output workspace: image + vertical toolbar */
.output-workspace {
  display: flex;
  align-items: center;
  gap: 16px;
  justify-content: center;
  width: 100%;
}

.render-img-wrapper {
  position: relative;
  display: inline-block;
  font-size: 0;
  line-height: 0;
  border-radius: 8px;
  overflow: hidden;
}

.checkerboard-bg {
  background-color: #16161a;
  background-image:
    linear-gradient(45deg, rgba(255, 255, 255, 0.06) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.06) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.06) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, 0.06) 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0;
}

.output-toolbar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: rgba(255, 255, 255, 0.05);
  padding: 10px;
  border-radius: 100px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
}

.output-tool-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.output-tool-btn:hover {
  background: var(--accent);
  transform: scale(1.1);
  box-shadow: 0 4px 16px rgba(137, 108, 254, 0.4);
}

.output-tool-btn.is-on {
  background: linear-gradient(120deg, rgba(111, 90, 245, 0.6), rgba(145, 120, 255, 0.45));
  box-shadow: 0 4px 14px rgba(111, 90, 245, 0.35);
}

.output-tool-btn.is-off {
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink-dim);
}

.output-tool-btn.is-off svg {
  opacity: 0.5;
}

.output-tool-btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.output-tool-btn:disabled:hover {
  background: rgba(255, 255, 255, 0.08);
  transform: none;
  box-shadow: none;
}

.palette-box {
  text-align: left;
}

.result-actions-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
}

.zoom-container .result-img {
  transition: transform 0.2s ease;
  max-width: none;
}

pre.json-output {
  margin-top: 8px;
  padding: 12px;
  background: var(--bg-soft);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  color: var(--ink);
  text-align: left;
  overflow-x: auto;
}

.loading-overlay {
  display: none;
  position: absolute;
  inset: 0;
  border: none;
  border-radius: var(--radius-lg);
  background: rgba(137, 108, 254, 0.1);
  backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  z-index: 10;
}

.loading-overlay.active {
  display: flex;
}

.global-loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 2600;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(8, 9, 16, 0.58);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  pointer-events: all;
}

.global-loading-overlay.active {
  display: flex;
}

.global-loading-panel {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-width: 168px;
  padding: 18px 22px;
  border-radius: 16px;
  background: rgba(20, 21, 30, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.42);
}

body.pipeline-processing {
  overflow: hidden;
}

.loader {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid rgba(137, 108, 254, 0.2);
  border-top-color: var(--accent);
  animation: spin 0.8s ease-in-out infinite;
}

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

.loading-text {
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 700;
}

.error-msg {
  display: none;
  margin-top: 8px;
  padding: 10px 12px;
  background: rgba(225, 29, 72, 0.11);
  border: none;
  border-radius: var(--radius-sm);
  color: #9f1239;
  font-size: 0.84rem;
  word-break: break-all;
}

.error-msg.visible {
  display: block;
}

.color-actions {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  background: var(--bg-soft);
  padding: 10px 14px;
  border-radius: var(--radius-md);
}

.color-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.color-count {
  font-size: 0.85rem;
  color: var(--ink-dim);
  font-weight: 600;
}

.color-action-btns {
  display: flex;
  margin-left: auto;
  gap: 12px;
}

.color-action-btns .btn-compact {
  min-width: 78px;
  padding-inline: 18px;
}

.color-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.color-list.is-disabled {
  pointer-events: none;
  opacity: 0.6;
}

.color-chip {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--ink);
  transition: all 0.2s ease;
  user-select: none;
}

.color-chip:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-1px);
}

.color-chip:active:not(:disabled) {
  transform: translateY(1px);
}

.color-chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.color-chip.selected {
  background: rgba(137, 108, 254, 0.15);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
  font-weight: 500;
}

.c-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  box-shadow: inset 0 0 0 1px rgba(29, 26, 23, 0.12);
}

@media (max-width: 860px) {
  .workspace-layout {
    display: block;
    width: 100%;
  }

  .mobile-flow-shell {
    display: block;
    position: relative;
    width: 100%;
    overflow: hidden;
    touch-action: pan-y;
  }

  .mobile-flow-track {
    display: flex;
    width: 100%;
    min-width: 0;
    transition: transform 0.34s cubic-bezier(0.16, 1, 0.3, 1);
    will-change: transform;
  }

  .mobile-flow-track.is-dragging {
    transition: none;
  }

  .mobile-flow-page {
    display: block;
    flex: 0 0 100%;
    min-width: 100%;
    max-width: 100%;
    max-height: calc(var(--app-vh) - (112px + var(--safe-bottom)));
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 10px;
  }

  .mobile-flow-page > * {
    min-width: 0;
  }

  .config-sidebar {
    position: static;
    grid-column: auto;
    grid-row: auto;
  }

  #renderCard {
    margin-top: 0;
  }

  .cluster-grid {
    grid-template-columns: 1fr;
  }

  .navbar {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px calc(10px + var(--safe-right)) calc(8px + var(--safe-bottom)) calc(10px + var(--safe-left));
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom: 0;
    background: rgba(23, 23, 23, 0.92);
    backdrop-filter: blur(10px);
  }

  .navbar-desktop {
    display: none;
  }

  .mobile-nav-tabs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    gap: 8px;
  }

  .mobile-nav-tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 10px;
    font-size: 0.78rem;
    font-weight: 600;
    border-color: rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.04);
  }

  .card-header {
    padding: 13px 16px;
  }

  .card-header-title {
    font-size: 1.2rem;
    gap: 6px;
    line-height: 1.2;
  }

  .mobile-nav-tab svg {
    width: 18px;
    height: 18px;
  }

  .mobile-nav-tab.is-active {
    color: #fff;
    background: rgba(137, 108, 254, 0.3);
    border-color: rgba(137, 108, 254, 0.65);
    box-shadow: 0 8px 16px rgba(137, 108, 254, 0.22);
  }

  .single-page {
    padding-top: 12px;
    padding-bottom: calc(92px + var(--safe-bottom));
  }

  .main-container {
    width: calc(100% - 20px);
    padding-bottom: 0;
  }

  .card-content {
    padding: 12px;
  }

  .config-sidebar-title {
    font-size: 0.96rem;
  }

  .config-cluster {
    padding: 12px;
  }

  .cluster-title {
    font-size: 0.74rem;
  }

  .param-row {
    padding: 10px 10px;
  }

  .param-label {
    font-size: 0.78rem;
  }

  .param-hint {
    font-size: 0.68rem;
  }

  .btn {
    padding: 10px 16px;
    font-size: 0.94rem;
  }

  .btn-compact {
    padding: 6px 14px;
    font-size: 0.8rem;
  }

  .btn-toggle {
    padding: 8px 12px;
    font-size: 0.82rem;
  }

  select,
  input[type="text"],
  input[type="number"] {
    padding: 7px 10px;
    font-size: 0.82rem;
  }

  input[type="range"] {
    height: 8px;
  }

  input[type="range"]::-webkit-slider-thumb {
    width: 24px;
    height: 24px;
  }

  .result-box {
    padding: 12px;
  }

  .result-box h4 {
    font-size: 0.78rem;
  }

  .output-workspace {
    flex-direction: column;
    align-items: center;
    gap: 12px;
  }

  .output-toolbar {
    flex-direction: row;
    align-self: center;
    border-radius: 16px;
    padding: 8px;
    gap: 8px;
  }

  .output-tool-btn {
    width: 42px;
    height: 42px;
  }

  .color-actions {
    gap: 8px;
    padding: 8px 10px;
  }

  .color-count {
    font-size: 0.8rem;
  }

  .color-chip {
    padding: 6px 10px;
    font-size: 0.8rem;
  }
}

@media (max-width: 480px) {
  .single-page {
    padding-top: 12px;
    padding-bottom: calc(96px + var(--safe-bottom));
  }

  .main-container {
    width: calc(100% - 14px);
  }

  .card-header {
    padding: 11px 14px;
  }

  .card-header-title {
    font-size: 1.08rem;
  }

  .workspace-layout {
    gap: 12px;
  }

  .upload-zone {
    width: 100%;
    aspect-ratio: 4 / 5;
    padding: 18px 12px;
  }

  .upload-icon-wrapper {
    margin-bottom: 8px;
  }

  .upload-custom-icon {
    width: 64px;
    height: 64px;
  }

  .upload-hint {
    display: none;
  }

  .upload-mobile-cta {
    width: min(240px, 100%);
    font-size: 0.95rem;
  }

  .action-row {
    width: 100%;
    flex-direction: column;
  }

  .action-row .btn {
    width: 100%;
  }

  .btn {
    padding: 9px 14px;
    font-size: 0.9rem;
  }

  .btn-compact {
    padding: 5px 12px;
    font-size: 0.78rem;
  }

  .output-tool-btn {
    width: 40px;
    height: 40px;
  }

  .color-actions {
    padding: 7px 8px;
  }

  .mobile-nav-tab {
    font-size: 0.74rem;
  }

  .mobile-nav-tab svg {
    width: 16px;
    height: 16px;
  }

  .color-chip {
    min-height: 42px;
    padding: 8px 10px;
  }

  .c-swatch {
    width: 16px;
    height: 16px;
  }

  .pe-palette-swatch {
    width: 32px;
    height: 32px;
  }
}

@media (orientation: landscape) and (max-height: 500px) and (max-width: 980px) {
  body {
    padding-left: calc(48px + var(--safe-left));
  }

  .navbar {
    top: 0;
    bottom: 0;
    left: 0;
    right: auto;
    width: 48px;
    padding: calc(8px + var(--safe-top)) 6px calc(8px + var(--safe-bottom));
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    border-top: 0;
  }

  .navbar-desktop {
    display: none;
  }

  .mobile-nav-tabs {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    gap: 8px;
    align-items: center;
    justify-content: center;
  }

  .mobile-nav-tab {
    width: 44px;
    min-width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 12px;
  }

  .mobile-nav-tab span {
    display: none;
  }

  .single-page {
    padding-top: 8px;
    padding-bottom: 12px;
  }

  .mobile-flow-page {
    max-height: calc(var(--app-vh) - 24px);
  }

  .workspace-layout {
    grid-template-columns: minmax(0, 1fr) 300px;
  }
}

/* 网格覆盖层及缩放同步 */
.grid-overlay {
  background-size: calc(100% / var(--img-w, 1)) calc(100% / var(--img-h, 1));
  background-image:
    linear-gradient(to right, rgba(137, 108, 254, 0.5) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(137, 108, 254, 0.5) 1px, transparent 1px);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 2;
}

.result-img.zoomable {
  position: relative;
  z-index: 1;
}

.result-img.zoomable:hover~.grid-overlay {
  transform: scale(1.03);
}

/* ============================================================
   PIXEL EDITOR OVERLAY  (mirrors .fs-crop-overlay pattern)
   ============================================================ */

.pe-overlay {
  position: fixed;
  inset: 0;
  z-index: 2002;
  background: rgba(20, 20, 20, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.pe-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.pe-rotate-hint {
  position: absolute;
  top: calc(10px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 2310;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(18, 18, 18, 0.85);
  border: 1px solid rgba(226, 241, 99, 0.45);
  color: var(--accent-bright);
  font-size: 0.82rem;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.pe-rotate-hint.is-hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(-6px);
}

/* Layout: canvas + toolbar + right sidebar */
.pe-workspace {
  display: flex;
  align-items: stretch;
  gap: 20px;
  max-width: 98vw;
  max-height: 94vh;
  width: 100%;
  height: 100%;
  padding: 16px;
}

.pe-main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

/* Canvas container */
.pe-canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  cursor: crosshair;
  touch-action: none;
  border-radius: var(--radius-md);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  background-color: #16161a;
  background-image:
    linear-gradient(45deg, rgba(255, 255, 255, 0.05) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.05) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.05) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, 0.05) 75%);
  background-size: 14px 14px;
  background-position: 0 0, 0 7px, 7px -7px, -7px 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pe-canvas-wrap canvas {
  position: absolute;
  top: 0;
  left: 0;
  image-rendering: pixelated;
  touch-action: none;
}

/* Narrow Vertical Toolbar Strip */
.pe-toolbar-h {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  gap: 16px;
  background: rgba(255, 255, 255, 0.05);
  padding: 10px 24px;
  border-radius: 100px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  z-index: 8;
  width: fit-content;
  margin: 0;
}

/* Footer layout for tools */
.pe-footer-bar {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  gap: 24px;
  /* Gap between 3 and 5 */
  z-index: 10;
  width: 100%;
}

/* Action toolbar (the group of 5) */
.pe-action-toolbar {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  gap: 16px;
  background: rgba(255, 255, 255, 0.05);
  padding: 10px 24px;
  border-radius: 100px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.pe-action-toolbar .icon-btn {
  width: var(--pe-chip-size);
  height: var(--pe-chip-size);
  border-radius: 50%;
  flex-shrink: 0;
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.pe-action-toolbar .icon-btn:hover {
  background: var(--accent);
  transform: scale(1.1);
  box-shadow: 0 4px 16px rgba(137, 108, 254, 0.4);
}

.pe-action-toolbar .icon-btn-danger:hover {
  background: #f43f5e;
  box-shadow: 0 4px 16px rgba(244, 63, 94, 0.4);
}

.pe-action-toolbar .pe-btn-save:hover {
  background: #10b981;
  box-shadow: 0 4px 16px rgba(16, 185, 129, 0.4);
}

.pe-action-toolbar .icon-btn svg {
  width: calc(20px * var(--pe-ui-scale));
  height: calc(20px * var(--pe-ui-scale));
}

/* Right sidebar (pill-shaped like crop toolbar, but taller) */
.pe-sidebar {
  width: var(--pe-sidebar-width);
  min-width: 180px;
  max-height: 100%;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

.pe-sidebar-handle {
  display: none;
  width: 100%;
  min-height: 48px;
  border: 0;
  background: rgba(137, 108, 254, 0.24);
  color: #fff;
  padding: 0 12px;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.pe-sidebar-handle-main {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.pe-sidebar-handle-color {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: #888;
  flex: 0 0 auto;
}

.pe-sidebar-handle-id {
  font-size: 0.86rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pe-sidebar-handle-label {
  font-size: 0.76rem;
  color: rgba(255, 255, 255, 0.72);
  flex: 0 0 auto;
}

.pe-sidebar-handle-icon {
  flex: 0 0 auto;
  color: rgba(255, 255, 255, 0.88);
  transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

.pe-sidebar-handle-icon.is-open {
  transform: rotate(180deg);
}

.pe-sidebar-section {
  padding: 14px 14px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.pe-sidebar-section-grow {
  flex: 1;
  overflow-y: auto;
  /* Enable scroll here */
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.pe-sidebar-heading {
  font-size: calc(0.68rem * var(--pe-ui-scale));
  font-weight: 700;
  color: rgba(255, 255, 255, 0.35);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 10px;
}

/* Tool row - Vertical layout */
.pe-tool-row {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  justify-content: center;
}

.pe-tool-btn {
  width: var(--pe-chip-size);
  height: var(--pe-chip-size);
  border-radius: 50%;
  flex-shrink: 0;
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.pe-tool-btn:hover {
  background: rgba(137, 108, 254, 0.25);
  transform: scale(1.08);
}

.pe-tool-btn.is-active {
  background: var(--accent);
  box-shadow: 0 4px 16px rgba(137, 108, 254, 0.4);
  transform: scale(1.05);
}

/* Current color indicator */
.pe-current-color-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
}

.pe-current-label {
  font-size: calc(0.7rem * var(--pe-ui-scale));
  color: rgba(255, 255, 255, 0.35);
  flex-shrink: 0;
}

.pe-active-color {
  width: calc(24px * var(--pe-ui-scale));
  height: calc(24px * var(--pe-ui-scale));
  border-radius: 6px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  background: #888;
  flex-shrink: 0;
  transition: background 0.15s ease;
}

.pe-current-id {
  font-size: var(--pe-font-size);
  color: rgba(255, 255, 255, 0.6);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Palette list */
.pe-palette-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 6px;
}

.pe-palette-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: all 0.15s ease;
  background: rgba(255, 255, 255, 0.03);
  color: rgba(255, 255, 255, 0.55);
  font-size: calc(var(--pe-font-size) * 0.9);
  text-align: left;
}

.pe-palette-item:hover {
  background: rgba(137, 108, 254, 0.1);
  color: #fff;
}

.pe-palette-item.is-active {
  background: rgba(137, 108, 254, 0.18);
  border-color: var(--accent);
  color: #fff;
}

.pe-palette-swatch {
  width: calc(18px * var(--pe-ui-scale));
  height: calc(18px * var(--pe-ui-scale));
  border-radius: 4px;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.pe-palette-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Info section */
.pe-info-section {
  padding: 10px 14px;
}

.pe-info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 2px 0;
  font-size: calc(0.72rem * var(--pe-ui-scale));
  font-family: 'SF Mono', 'Consolas', 'Courier New', monospace;
  color: rgba(255, 255, 255, 0.5);
}

.pe-info-label {
  color: rgba(255, 255, 255, 0.3);
}

.pe-radial-menu {
  position: fixed;
  z-index: 2400;
  width: 92px;
  height: 92px;
  pointer-events: none;
}

.pe-radial-menu.hidden {
  display: none;
}

.pe-radial-item {
  position: absolute;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(46, 46, 46, 0.95);
  color: #fff;
  font-family: var(--font-display);
  font-size: 0.8rem;
  pointer-events: auto;
}

.pe-radial-item-paint {
  top: 0;
  left: 24px;
}

.pe-radial-item-eye {
  right: 0;
  bottom: 8px;
}

.pe-radial-item-erase {
  left: 0;
  bottom: 8px;
}


/* Scrollbar */
.pe-palette-list::-webkit-scrollbar {
  width: 4px;
}

.pe-palette-list::-webkit-scrollbar-track {
  background: transparent;
}

.pe-palette-list::-webkit-scrollbar-thumb {
  background: rgba(137, 108, 254, 0.25);
  border-radius: 2px;
}

@media (max-width: 700px) {
  :root {
    --pe-toolbar-float-gap: calc(8px * var(--pe-ui-scale));
  }

  .pe-tool-btn {
    width: 44px;
    height: 44px;
  }

  .pe-action-toolbar .icon-btn {
    width: 44px;
    height: 44px;
  }
}

@media (max-width: 980px) {
  .pe-workspace {
    gap: 8px;
    max-width: 100vw;
    max-height: 100dvh;
    padding: 8px;
  }

  .pe-footer-bar {
    gap: 10px;
  }

  .pe-toolbar-h,
  .pe-action-toolbar {
    justify-content: center;
    gap: 10px;
    padding: 8px 12px;
  }

  .pe-sidebar-section {
    padding: 10px 12px 8px;
  }

  .pe-palette-swatch {
    width: 26px;
    height: 26px;
  }

  .pe-palette-list {
    grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  }
}

@media (max-width: 980px) and (orientation: portrait) {
  .pe-workspace {
    flex-direction: column;
    justify-content: flex-start;
    gap: 8px;
    padding-bottom: 8px;
  }

  .pe-main-area {
    flex: 1;
    min-height: 56dvh;
    position: relative;
    padding-right: calc(var(--pe-toolbar-strip-width) + 12px);
  }

  .pe-canvas-wrap {
    min-height: 56dvh;
    max-height: min(60dvh, 560px);
  }

  .pe-footer-bar {
    position: absolute;
    top: 8px;
    right: 6px;
    bottom: 8px;
    z-index: 12;
    width: var(--pe-toolbar-strip-width);
    flex-direction: column;
    flex-wrap: nowrap;
    justify-content: flex-start;
    align-items: center;
    gap: 8px;
    padding: 6px;
    border-radius: 14px;
    background: rgba(12, 12, 12, 0.66);
    border: 1px solid rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(8px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .pe-toolbar-h,
  .pe-action-toolbar {
    width: 100%;
    flex-direction: column;
    flex-wrap: nowrap;
    justify-content: flex-start;
    align-items: center;
    gap: 8px;
    border-radius: 12px;
    padding: 6px;
  }

  .pe-tool-btn,
  .pe-action-toolbar .icon-btn {
    width: 40px;
    height: 40px;
  }

  .pe-sidebar {
    position: static;
    width: 100%;
    min-width: 0;
    max-height: min(48dvh, 360px);
    border-radius: 16px;
    transform: none;
    transition: max-height 0.24s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease;
    z-index: auto;
  }

  .pe-overlay:not(.pe-sidebar-open) .pe-sidebar {
    max-height: 56px;
  }

  .pe-overlay.pe-sidebar-open .pe-sidebar {
    max-height: min(48dvh, 360px);
  }

  .pe-sidebar-handle {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    min-height: 52px;
    max-height: 52px;
  }

  .pe-overlay:not(.pe-sidebar-open) .pe-sidebar .pe-sidebar-section {
    display: none;
  }

  .pe-overlay:not(.pe-sidebar-open) .pe-sidebar .pe-sidebar-handle {
    border-bottom: 0;
  }

  .pe-current-color-section {
    display: none;
  }

  .pe-sidebar-section-grow {
    overflow-y: auto;
    overflow-x: hidden;
  }

  .pe-palette-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(98px, 1fr));
    gap: 8px;
    overflow-y: auto;
    overflow-x: hidden;
    align-content: start;
    padding-bottom: 12px;
  }

  .pe-palette-item {
    min-width: 0;
    width: 100%;
  }
}

@media (max-width: 980px) and (orientation: landscape) {
  .pe-workspace {
    flex-direction: row;
    align-items: stretch;
    gap: 10px;
  }

  .pe-main-area {
    flex: 0 0 70%;
    min-width: 0;
    position: relative;
    min-height: 0;
  }

  .pe-canvas-wrap {
    min-height: calc(100dvh - 30px);
  }

  .pe-footer-bar {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 8px;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 14px;
    background: rgba(12, 12, 12, 0.66);
  }

  .pe-toolbar-h,
  .pe-action-toolbar {
    width: auto;
    margin: 0;
  }

  .pe-sidebar {
    position: static;
    flex: 1;
    width: auto;
    min-width: 0;
    max-height: none;
    transform: none;
  }

  .pe-sidebar-handle {
    display: none;
  }

  .pe-palette-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    overflow-y: auto;
    overflow-x: hidden;
  }
}

/* remove background manual + preview overlays */
.rb-manual-overlay,
.rb-preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 2200;
  background: rgba(5, 6, 12, 0.78);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.rb-manual-overlay.hidden,
.rb-preview-overlay.hidden {
  display: none;
}

.rb-manual-panel,
.rb-preview-panel {
  position: relative;
  width: min(1100px, 96vw);
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-strong);
  padding: 14px;
}

.rb-panel-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  z-index: 3;
}

.rb-manual-header h3,
.rb-preview-panel h3 {
  font-family: var(--font-display);
  font-size: 1.08rem;
  margin-bottom: 4px;
  padding-right: 56px;
}

.rb-manual-header p,
.rb-preview-panel p {
  color: var(--ink-dim);
  font-size: 0.85rem;
  margin-bottom: 10px;
  padding-right: 56px;
}

.rb-manual-canvas-wrap {
  width: 100%;
  height: min(72vh, 760px);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  overflow: hidden;
  background: linear-gradient(145deg, #252636, #1d1f2e);
  cursor: crosshair;
}

#rbManualCanvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}

.rb-manual-actions,
.rb-preview-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

#rbPreviewImage {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: min(62vh, 640px);
  margin: 0 auto;
  image-rendering: pixelated;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

@media (max-width: 980px) {
  .fs-crop-workspace {
    width: 100%;
    height: 100%;
    max-width: 100vw;
    max-height: 100dvh;
    align-items: stretch;
    justify-content: flex-start;
    gap: 10px;
    padding: calc(10px + var(--safe-top)) 10px calc(10px + var(--safe-bottom));
  }

  .fs-crop-title {
    font-size: 0.85rem;
    letter-spacing: 0.03em;
    text-align: center;
  }

  .fs-crop-stage {
    flex: 1;
    min-height: 0;
    flex-direction: column;
    justify-content: space-between;
    gap: 12px;
  }

  .fs-crop-container {
    width: 100%;
    flex: 1;
    min-height: 0;
  }

  .fs-crop-img {
    max-width: 100%;
    max-height: 100%;
    margin: auto;
  }

  .fs-crop-toolbar {
    position: static;
    align-self: center;
    flex-direction: row;
    border-radius: 16px;
    padding: 8px;
    gap: 8px;
  }

  .cut-preview-panel {
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
    padding-top: calc(12px + var(--safe-top));
  }

  .rb-manual-overlay,
  .rb-preview-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .rb-manual-panel,
  .rb-preview-panel {
    width: 100%;
    max-height: 88dvh;
    border-radius: 20px 20px 0 0;
    border-bottom: 0;
    padding-bottom: calc(14px + var(--safe-bottom));
  }

  .rb-panel-close {
    top: 8px;
    right: calc(8px + var(--safe-right));
  }

  .rb-manual-canvas-wrap {
    height: min(56dvh, 520px);
  }
}

/* Desktop pointer devices: keep crop action buttons on the image right side */
@media (hover: hover) and (pointer: fine) {
  .fs-crop-stage {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 24px;
  }

  .fs-crop-container {
    min-width: 0;
  }

  .fs-crop-img {
    max-width: calc(90vw - 120px);
  }

  .fs-crop-toolbar {
    position: static;
    align-self: center;
    flex-direction: column;
    border-radius: 100px;
    padding: 12px;
    gap: 16px;
    flex-shrink: 0;
  }
}
