:root {
  --bg-main: #0c0e14;
  --bg-card: #151821;
  --bg-card-hover: #1c202c;
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --border-color: rgba(255, 255, 255, 0.08);
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-glow: rgba(99, 102, 241, 0.35);
  --brush-color: rgba(255, 225, 53, 0.55);
  --success: #10b981;
  --warning: #f59e0b;
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
}

body {
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: 100%;
}

/* Header */
.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border-color);
  background: rgba(12, 14, 20, 0.85);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 50;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.sparkle-icon {
  font-size: 1.35rem;
}

.logo-text strong {
  color: #818cf8;
  font-weight: 800;
}

.badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 9999px;
  background: rgba(99, 102, 241, 0.15);
  color: #a5b4fc;
  border: 1px solid rgba(99, 102, 241, 0.3);
  margin-left: 6px;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.status-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  background: var(--bg-card);
  padding: 6px 14px;
  border-radius: 9999px;
  border: 1px solid var(--border-color);
}

.status-chip .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--warning);
  transition: background-color 0.3s;
}

.status-chip.ready .dot {
  background-color: var(--success);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
}

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 100%;
}

/* Dropzone Area */
.dropzone-section {
  width: 100%;
  max-width: 840px;
  padding: 40px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

.dropzone {
  width: 100%;
  background: var(--bg-card);
  border: 2px dashed rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-lg);
  padding: 64px 32px;
  text-align: center;
  cursor: pointer;
  transition: all 0.25s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: var(--bg-card-hover);
  box-shadow: 0 0 24px var(--accent-glow);
  transform: translateY(-2px);
}

.upload-icon-wrapper {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: rgba(99, 102, 241, 0.12);
  color: #818cf8;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}

.dropzone h2 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.dropzone p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  max-width: 460px;
}

.features-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
  margin-top: 10px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.features-row span {
  background: rgba(255, 255, 255, 0.04);
  padding: 6px 12px;
  border-radius: 9999px;
  border: 1px solid var(--border-color);
}

/* Initial Model Download Banner Card */
.model-loading-banner {
  width: 100%;
  max-width: 520px;
  background: rgba(99, 102, 241, 0.07);
  border: 1px solid rgba(99, 102, 241, 0.25);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
  margin-top: 6px;
  transition: all 0.3s ease;
}

.model-loading-banner.ready {
  background: rgba(16, 185, 129, 0.08);
  border-color: rgba(16, 185, 129, 0.35);
}

.model-banner-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.model-banner-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.92rem;
  font-weight: 700;
  color: #c7d2fe;
}

.model-loading-banner.ready .model-banner-title {
  color: #6ee7b7;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--accent);
  box-shadow: 0 0 10px var(--accent);
  animation: pulse-glow 1.5s infinite;
}

.model-loading-banner.ready .pulse-dot {
  background-color: var(--success);
  box-shadow: 0 0 10px var(--success);
  animation: none;
}

@keyframes pulse-glow {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(1.3); }
}

.model-banner-pct {
  font-size: 0.95rem;
  font-weight: 800;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

.model-banner-progress-bar {
  width: 100%;
  height: 7px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 9999px;
  overflow: hidden;
  position: relative;
}

.model-banner-progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #6366f1 0%, #10b981 100%);
  border-radius: 9999px;
  transition: width 0.15s ease-out;
}

.model-banner-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.btn-primary {
  background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  color: #fff;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(99, 102, 241, 0.45);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-card-hover);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-lg {
  padding: 14px 28px;
  font-size: 1rem;
  margin-top: 12px;
}

/* Sample Images Bar */
.sample-images-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.sample-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.samples {
  display: flex;
  gap: 10px;
}

.sample-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 8px 14px;
  border-radius: 9999px;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
}

.sample-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.2);
}

/* Editor Section */
.editor-section {
  width: 100%;
  height: calc(100vh - 73px);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #090a0f;
  overflow: hidden;
}

.canvas-viewport {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  user-select: none;
}

.canvas-wrapper {
  position: relative;
  display: inline-block;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.6);
  border-radius: 8px;
  transform-origin: center center;
  transition: transform 0.05s ease-out;
  will-change: transform;
}

.canvas-viewport.panning {
  cursor: grab;
}
.canvas-viewport.panning:active {
  cursor: grabbing;
}

#image-canvas {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 180px);
  object-fit: contain;
}

#mask-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

/* Brush Cursor Preview */
#brush-cursor {
  position: absolute;
  pointer-events: none;
  border: 2px solid rgba(255, 225, 53, 0.9);
  background: rgba(255, 225, 53, 0.25);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  display: none;
  z-index: 10;
}

/* Floating Bottom Toolbar */
.floating-toolbar {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(21, 24, 33, 0.94);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 9999px;
  padding: 8px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6);
  z-index: 40;
  white-space: nowrap;
  max-width: 95vw;
  box-sizing: border-box;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
}

.tool-group label {
  white-space: nowrap;
}

.tool-group input[type="range"] {
  accent-color: var(--accent);
  cursor: pointer;
  width: 90px;
}

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

.btn-icon {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 8px 12px;
  border-radius: 9999px;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

.btn-erase {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #fff;
  border-radius: 9999px;
  padding: 10px 20px;
  font-size: 0.92rem;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.35);
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-erase:hover {
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.5);
  transform: translateY(-1px);
}

/* Spinner */
.spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Central Loading Progress Overlay */
.progress-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(12, 14, 20, 0.65);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 90;
  animation: fadeIn 0.2s ease-out;
}

.progress-modal {
  background: rgba(21, 24, 33, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-lg);
  padding: 32px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7), 0 0 30px var(--accent-glow);
  text-align: center;
  min-width: 280px;
}

.circular-progress-wrap {
  position: relative;
  width: 110px;
  height: 110px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
}

.progress-ring {
  transform: rotate(-90deg);
}

.progress-ring-bar {
  transition: stroke-dashoffset 0.25s ease;
}

.progress-number {
  position: absolute;
  font-size: 1.4rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.02em;
}

.progress-status-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.progress-status-sub {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

/* Toast */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(17, 24, 39, 0.95);
  border: 1px solid var(--border-color);
  color: #fff;
  padding: 12px 24px;
  border-radius: 9999px;
  font-size: 0.9rem;
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s ease;
  z-index: 100;
}

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

/* Responsive Handling for Narrow Screen / Iframe */
@media (max-width: 768px) {
  .floating-toolbar {
    bottom: 16px;
    padding: 6px 14px;
    gap: 8px;
    transform: translateX(-50%) scale(0.9);
    transform-origin: bottom center;
  }
  .tool-group input[type="range"] {
    width: 70px;
  }
  .btn-icon {
    padding: 6px 8px;
    font-size: 0.8rem;
  }
  .btn-erase {
    padding: 8px 16px;
    font-size: 0.85rem;
  }
}

@media (max-width: 480px) {
  .floating-toolbar {
    transform: translateX(-50%) scale(0.82);
    padding: 4px 10px;
  }
}
