:root {
  --bg: #07080d;
  --surface: rgba(255, 255, 255, 0.045);
  --surface-2: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.1);
  --text: #eef0f5;
  --text-muted: #9aa2b1;
  --accent: #4f8cff;
  --accent-hover: #6ea0ff;
  --danger: #ff6b6b;
  font-size: 16px;
}

* {
  box-sizing: border-box;
}

body {
  position: relative;
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Murecho", "Hiragino Sans", "Yu Gothic", Meiryo, sans-serif;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

.bg-blobs {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.star {
  position: absolute;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 6px 1px rgba(255, 255, 255, 0.8);
  opacity: 0.15;
  animation: twinkle ease-in-out infinite;
}

@keyframes twinkle {
  0%, 100% {
    opacity: 0.1;
    transform: scale(0.8);
  }
  50% {
    opacity: 0.9;
    transform: scale(1.3);
  }
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
}

.blob-1 {
  width: 55vmax;
  height: 55vmax;
  top: -15%;
  left: -12%;
  background: radial-gradient(circle, rgba(79, 140, 255, 0.38), transparent 70%);
  animation: blobMove1 13s ease-in-out infinite alternate;
}

.blob-2 {
  width: 48vmax;
  height: 48vmax;
  top: -10%;
  right: -14%;
  background: radial-gradient(circle, rgba(139, 92, 246, 0.32), transparent 70%);
  animation: blobMove2 17s ease-in-out infinite alternate;
}

.blob-3 {
  width: 60vmax;
  height: 60vmax;
  bottom: -25%;
  left: 20%;
  background: radial-gradient(circle, rgba(56, 189, 248, 0.26), transparent 70%);
  animation: blobMove3 20s ease-in-out infinite alternate;
}

@keyframes blobMove1 {
  0% {
    transform: translate(0, 0) scale(1);
  }
  100% {
    transform: translate(14%, 16%) scale(1.25);
  }
}

@keyframes blobMove2 {
  0% {
    transform: translate(0, 0) scale(1);
  }
  100% {
    transform: translate(-16%, 14%) scale(1.2);
  }
}

@keyframes blobMove3 {
  0% {
    transform: translate(0, 0) scale(1);
  }
  100% {
    transform: translate(10%, -14%) scale(1.3);
  }
}

.app-header {
  text-align: center;
  padding: clamp(1.2rem, 4vw, 2.2rem) 1rem 0.8rem;
}

.app-header h1 {
  margin: 0;
  font-family: "Unbounded", "Murecho", sans-serif;
  font-size: clamp(1.8rem, 6vw, 2.6rem);
  font-weight: 800;
  letter-spacing: 0.01em;
  background: linear-gradient(90deg, #4f8cff, #38bdf8, #8b5cf6);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 26px rgba(79, 140, 255, 0.45));
}

.tagline {
  display: inline-block;
  margin: 0.7rem auto 0;
  padding: 0.35rem 1rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: clamp(0.78rem, 2.5vw, 0.9rem);
}

.app-main {
  flex: 1;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 1.2rem 1rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 20px;
  padding: clamp(2rem, 8vw, 4rem) 1rem;
  background: var(--surface);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow:
    0 0 0 1px rgba(79, 140, 255, 0.2),
    0 0 44px rgba(79, 140, 255, 0.16),
    0 12px 32px rgba(0, 0, 0, 0.4);
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

.drop-zone.dragover {
  border-color: var(--accent);
  background: rgba(79, 140, 255, 0.08);
  box-shadow: 0 0 0 4px rgba(79, 140, 255, 0.15), 0 12px 32px rgba(0, 0, 0, 0.35);
}

.drop-zone-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  text-align: center;
  color: var(--text-muted);
}

.drop-zone-icon {
  font-size: 3rem;
  margin: 0;
}

.or-text {
  margin: 0.2rem 0;
  font-size: 0.85rem;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 0.75rem 1.6rem;
  font-size: 1rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.15s, background 0.2s, opacity 0.2s, box-shadow 0.2s;
}

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

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

.btn-primary {
  background: linear-gradient(135deg, #4f8cff, #6ea0ff);
  color: white;
  box-shadow: 0 8px 20px rgba(79, 140, 255, 0.35);
  animation: btnPulse 2.4s ease-in-out infinite;
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #6ea0ff, #8bb4ff);
  box-shadow: 0 10px 30px rgba(79, 140, 255, 0.55);
  transform: translateY(-2px);
}

.btn-primary:disabled {
  animation: none;
}

@keyframes btnPulse {
  0%, 100% {
    box-shadow: 0 8px 20px rgba(79, 140, 255, 0.35);
  }
  50% {
    box-shadow: 0 8px 30px rgba(79, 140, 255, 0.6);
  }
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.12);
  transform: translateY(-1px);
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  animation: fadeInUp 0.4s ease;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.hidden {
  display: none !important;
}

.canvas-area {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 640px) {
  .canvas-area {
    grid-template-columns: 1fr;
  }
}

.canvas-pane {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 0;
}

.pane-label {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
}

.canvas-frame {
  position: relative;
  background: var(--surface);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 0 0 1px rgba(79, 140, 255, 0.16),
    0 0 32px rgba(79, 140, 255, 0.12),
    0 8px 24px rgba(0, 0, 0, 0.35);
}

.canvas-frame img,
.canvas-frame canvas {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}

.checkerboard {
  background-color: #1b1f2a;
  background-image:
    linear-gradient(45deg, #2a2f3d 25%, transparent 25%),
    linear-gradient(-45deg, #2a2f3d 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2a2f3d 75%),
    linear-gradient(-45deg, transparent 75%, #2a2f3d 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(18, 20, 28, 0.75);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  color: var(--text);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

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

#result-canvas {
  cursor: crosshair;
  touch-action: none;
}

.retouch-controls {
  background: var(--surface);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.retouch-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

.btn-tool {
  border: 2px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  padding: 0.5rem 0.9rem;
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn-tool.selected {
  border-color: var(--accent);
  background: #2a3550;
}

.brush-size-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.btn-small {
  padding: 0.5rem 0.9rem;
  font-size: 0.85rem;
}

.bg-controls {
  background: var(--surface);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

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

.bg-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}

.bg-swatch {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  padding: 0;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
}

.bg-swatch.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(79, 140, 255, 0.35);
}

.transparent-swatch {
  background-image:
    linear-gradient(45deg, #2a2f3d 25%, transparent 25%),
    linear-gradient(-45deg, #2a2f3d 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2a2f3d 75%),
    linear-gradient(-45deg, transparent 75%, #2a2f3d 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0px;
}

.color-picker {
  padding: 0;
  overflow: hidden;
}

.color-picker::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-picker::-webkit-color-swatch {
  border: none;
  border-radius: 50%;
}

.bg-image-swatch {
  border-style: dashed;
}

.actions {
  display: flex;
  gap: 0.8rem;
  justify-content: center;
  flex-wrap: wrap;
}

.error-message {
  text-align: center;
  color: var(--danger);
  background: rgba(255, 107, 107, 0.1);
  border: 1px solid rgba(255, 107, 107, 0.3);
  border-radius: 10px;
  padding: 0.8rem;
}

.app-footer {
  text-align: center;
  padding: 1rem;
  color: var(--text-muted);
  font-size: 0.8rem;
}
