:root {
  --bg-dark: #0a0a0b;
  --bg-panel: rgba(18, 18, 22, 0.65);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.16);
  --accent: #5e6ad2;
  --accent-glow: rgba(94, 106, 210, 0.5);
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --radius-xl: 24px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --shadow-lg: 0 24px 48px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text-main);
  background-color: var(--bg-dark);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

img { display: block; max-width: 100%; }
button { font-family: inherit; }

/* Hidden state utility */
.hidden { display: none !important; }

/* Ambient Background */
.ambient-orbs {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
  background: var(--bg-dark);
}
.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.4;
  animation: float 20s infinite alternate ease-in-out;
}
.orb-1 {
  width: 50vw; height: 50vw;
  background: radial-gradient(circle, rgba(74,68,226,0.3) 0%, transparent 70%);
  top: -10%; left: -10%;
}
.orb-2 {
  width: 40vw; height: 40vw;
  background: radial-gradient(circle, rgba(236,72,153,0.15) 0%, transparent 70%);
  bottom: 0%; right: -5%;
  animation-delay: -5s;
}
.orb-3 {
  width: 30vw; height: 30vw;
  background: radial-gradient(circle, rgba(45,212,191,0.15) 0%, transparent 70%);
  top: 40%; left: 40%;
  animation-delay: -10s;
}
.noise-overlay {
  position: absolute; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
}
@keyframes float {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(5%, 5%) scale(1.1); }
}

/* App Container */
.app-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Typography & Badges */
.hero-badge {
  display: inline-block;
  padding: 6px 12px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 99px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.5px;
  color: #a5b4fc;
  margin-bottom: 24px;
}
h1 {
  font-size: clamp(32px, 5vw, 56px);
  font-weight: 700;
  letter-spacing: -1px;
  margin: 0 0 16px;
  background: linear-gradient(to right, #fff, #94a3b8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.hero-desc {
  font-size: 16px; color: var(--text-muted);
  line-height: 1.6; max-width: 540px; margin: 0 auto 40px;
}

/* Hero View (Upload) */
.hero-view {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}
body.workflow-ready .hero-view { display: none; }
.hero-content {
  text-align: center;
  width: 100%;
  max-width: 600px;
}

/* Dropzone */
.dropzone {
  background: var(--bg-panel);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-xl);
  padding: 64px 32px;
  cursor: pointer;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  transition: all 0.3s ease;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.dropzone:hover, .dropzone.is-dragging {
  border-color: var(--accent);
  background: rgba(94, 106, 210, 0.05);
  transform: translateY(-2px);
  box-shadow: 0 12px 32px rgba(0,0,0,0.2), 0 0 0 1px rgba(94,106,210,0.2) inset;
}
.dropzone-icon {
  color: var(--text-muted);
  margin-bottom: 8px;
  transition: color 0.3s;
}
.dropzone:hover .dropzone-icon { color: var(--accent); }
.dropzone-title { font-size: 20px; font-weight: 600; color: #fff; }
.dropzone-hint { font-size: 14px; color: var(--text-muted); }

/* Buttons */
.hero-actions { margin-top: 24px; }
.btn-full { width: 100%; justify-content: center; }

.glass-btn, .primary-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 14px; font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
}
.glass-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  backdrop-filter: blur(10px);
}
.glass-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--border-hover);
}
.primary-btn {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 12px rgba(94, 106, 210, 0.3);
}
.primary-btn:hover {
  background: #6f7bf0;
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(94, 106, 210, 0.4);
}
.primary-btn.glow {
  position: relative;
}
.icon-btn {
  background: transparent; border: none; color: var(--text-muted);
  width: 32px; height: 32px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all 0.2s;
}
.icon-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }

.glass-btn:disabled, .primary-btn:disabled, .icon-btn:disabled {
  opacity: 0.5; cursor: not-allowed; transform: none !important;
}

.status-text {
  margin-top: 20px; font-size: 14px; color: var(--accent);
  min-height: 20px;
}

/* =========================================================
   WORKSPACE LAYOUT
   ========================================================= */
.workspace {
  display: flex;
  height: 100vh;
  padding: 20px;
  gap: 20px;
}
@media (max-width: 1024px) {
  .workspace { flex-direction: column; height: auto; }
}

/* Sidebar */
.sidebar {
  width: 340px;
  flex-shrink: 0;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
@media (max-width: 1024px) {
  .sidebar { width: 100%; height: 50vh; }
}

.sidebar-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex; align-items: center; justify-content: space-between;
}
.logo {
  display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 16px; letter-spacing: 0.5px;
}
.logo svg { color: var(--accent); }
.sidebar-status { margin: 0; font-size: 12px; }

.sidebar-scrollable {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex; flex-direction: column; gap: 28px;
}

/* Tool Cards */
.tool-card { display: flex; flex-direction: column; gap: 12px; }
.card-header label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); }
.flex-header { display: flex; justify-content: space-between; align-items: center; }

/* Upload Preview */
.upload-preview {
  width: 120px; aspect-ratio: 9/16;
  border-radius: var(--radius-md); overflow: hidden;
  background: rgba(0,0,0,0.3); border: 1px solid var(--border-color);
}
.upload-preview img { width: 100%; height: 100%; object-fit: cover; }

/* Styles */
.style-grid { display: flex; flex-direction: column; gap: 8px; }
.style-card {
  text-align: left; background: rgba(255,255,255,0.03); border: 1px solid var(--border-color);
  border-radius: var(--radius-md); padding: 14px; cursor: pointer; transition: all 0.2s; color: var(--text-main);
}
.style-card:hover { background: rgba(255,255,255,0.06); border-color: var(--border-hover); }
.style-card.is-active { border-color: var(--accent); background: rgba(94,106,210,0.1); box-shadow: inset 0 0 0 1px var(--accent); }
.style-card strong { display: block; font-size: 14px; margin-bottom: 4px; font-weight: 500; }
.style-card span { display: block; font-size: 12px; color: var(--text-muted); line-height: 1.4; }

/* Crop */
.crop-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.crop-chip {
  background: rgba(255,255,255,0.03); border: 1px solid var(--border-color);
  padding: 10px; border-radius: var(--radius-md); color: var(--text-main); font-size: 13px; cursor: pointer; transition: all 0.2s;
}
.crop-chip:hover { background: rgba(255,255,255,0.08); }
.crop-chip.is-active { background: var(--text-main); color: var(--bg-dark); border-color: var(--text-main); font-weight: 500; }

/* Backgrounds */
.background-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.background-card {
  background: transparent; border: 2px solid transparent; padding: 0; border-radius: var(--radius-md); cursor: pointer; transition: all 0.2s; overflow: hidden; position: relative;
}
.background-card img { width: 100%; aspect-ratio: 9/16; object-fit: cover; border-radius: calc(var(--radius-md) - 2px); transition: transform 0.3s; }
.background-card:hover img { transform: scale(1.05); }
.background-card.is-active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(94,106,210,0.3); }
.background-card span {
  position: absolute; bottom: 4px; left: 4px; right: 4px;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); color: #fff; font-size: 10px; padding: 2px 0; border-radius: 4px; text-align: center;
}

/* Main Canvas */
.canvas-area {
  flex: 1; display: flex; flex-direction: column;
  background: var(--bg-panel); border: 1px solid var(--border-color);
  border-radius: var(--radius-xl); backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px); box-shadow: var(--shadow-lg);
}
.canvas-header {
  padding: 20px 24px; border-bottom: 1px solid var(--border-color);
  display: flex; justify-content: space-between; align-items: center;
}
.header-info h2 { margin: 0; font-size: 16px; font-weight: 600; }
.saved-path { display: block; margin-top: 4px; font-size: 12px; color: var(--text-muted); }
.header-actions { display: flex; gap: 12px; }

.canvas-wrapper {
  flex: 1; padding: 24px; display: flex; justify-content: center; align-items: center;
  background: radial-gradient(circle, rgba(255,255,255,0.02) 0%, transparent 70%);
  overflow: hidden;
}
.preview-frame { position: relative; max-height: 100%; max-width: 100%; }
.preview-stage { position: relative; display: inline-flex; justify-content: center; max-width: 100%; max-height: 100%; }
.preview-stage img {
  max-width: 100%; max-height: calc(100vh - 160px); width: auto; height: auto;
  border-radius: var(--radius-lg); box-shadow: 0 24px 64px rgba(0,0,0,0.5); object-fit: contain;
}

/* Crop Overlay logic heavily relies on original classnames from app.js */
.crop-overlay { position: absolute; inset: 0; pointer-events: none; }
.crop-guide { position: absolute; z-index: 2; opacity: 0; background: var(--accent); transition: opacity 120ms ease; }
.crop-guide-x { left: 50%; top: 0; width: 1px; height: 100%; transform: translateX(-0.5px); }
.crop-guide-y { left: 0; top: 50%; width: 100%; height: 1px; transform: translateY(-0.5px); }
.crop-overlay.snap-x .crop-guide-x, .crop-overlay.snap-y .crop-guide-y { opacity: 1; }

.crop-shade { position: absolute; z-index: 1; background: rgba(0, 0, 0, 0.5); backdrop-filter: blur(2px); }
.crop-shade-top { left: 0; top: 0; width: 100%; height: var(--crop-top); }
.crop-shade-right { top: var(--crop-top); right: 0; width: calc(100% - var(--crop-left) - var(--crop-width)); height: var(--crop-height); }
.crop-shade-bottom { left: 0; bottom: 0; width: 100%; height: calc(100% - var(--crop-top) - var(--crop-height)); }
.crop-shade-left { top: var(--crop-top); left: 0; width: var(--crop-left); height: var(--crop-height); }

.crop-box {
  position: absolute; z-index: 3;
  left: var(--crop-left); top: var(--crop-top); width: var(--crop-width); height: var(--crop-height);
  border: 1.5px solid #fff; border-radius: 12px; cursor: grab; pointer-events: auto; touch-action: none;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.2), inset 0 0 0 1px rgba(0,0,0,0.2);
}
.crop-box:active { cursor: grabbing; }

.crop-label {
  position: absolute; top: 12px; left: 12px;
  padding: 4px 8px; border-radius: 6px; background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(4px);
  color: #fff; font-size: 11px; font-weight: 500;
}

.crop-handle {
  position: absolute; width: 16px; height: 16px;
  background: #fff; border-radius: 50%; box-shadow: 0 2px 8px rgba(0,0,0,0.3); border: 1px solid rgba(0,0,0,0.1);
}
.crop-handle-nw { left: 0; top: 0; transform: translate(-50%, -50%); cursor: nwse-resize; }
.crop-handle-n { left: 50%; top: 0; transform: translate(-50%, -50%); cursor: ns-resize; }
.crop-handle-ne { right: 0; top: 0; transform: translate(50%, -50%); cursor: nesw-resize; }
.crop-handle-e { right: 0; top: 50%; transform: translate(50%, -50%); cursor: ew-resize; }
.crop-handle-se { right: 0; bottom: 0; transform: translate(50%, 50%); cursor: nwse-resize; }
.crop-handle-s { left: 50%; bottom: 0; transform: translate(-50%, 50%); cursor: ns-resize; }
.crop-handle-sw { left: 0; bottom: 0; transform: translate(-50%, 50%); cursor: nesw-resize; }
.crop-handle-w { left: 0; top: 50%; transform: translate(-50%, -50%); cursor: ew-resize; }

/* Modal */
body.modal-open { overflow: hidden; }
.image-modal { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; }
.image-modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.85); backdrop-filter: blur(12px); }
.image-modal-dialog {
  position: relative; z-index: 1; width: min(95vw, 1200px); max-height: 95vh;
  display: flex; flex-direction: column; align-items: center;
}
.image-modal-close {
  align-self: flex-end; margin-bottom: 16px;
  background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2); color: #fff;
  width: 44px; height: 44px; border-radius: 50%; cursor: pointer; transition: all 0.2s;
  display: flex; align-items: center; justify-content: center;
}
.image-modal-close:hover { background: rgba(255,255,255,0.2); transform: scale(1.05); }
.image-modal-image { max-height: calc(95vh - 60px); border-radius: var(--radius-lg); object-fit: contain; box-shadow: 0 32px 80px rgba(0,0,0,0.6); }

/* Custom Scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }
