/* ==========================================================================
   Avatar Cropper — Style Sheet
   Material Design 3 inspired dark theme with purple accents
   ========================================================================== */

/* ---- Google Fonts (loaded in HTML) ---- */

/* ---- Design Tokens ---------------------------------------------------- */
:root {
  /* Surfaces */
  --surface-0: #121220;
  --surface-1: #1a1a2e;
  --surface-2: #252541;
  --surface-3: #2e2e52;
  --surface-hover: #33335a;

  /* Primary accent */
  --primary: #7c4dff;
  --primary-light: #b388ff;
  --primary-dark: #5e35b1;
  --primary-surface: rgba(124, 77, 255, 0.12);

  /* On-surface text */
  --on-surface: #e8e6f0;
  --on-surface-medium: #b0adc0;
  --on-surface-dim: #7a7890;

  /* Functional */
  --success: #66bb6a;
  --error: #ef5350;

  /* Elevation */
  --shadow-1: 0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
  --shadow-2: 0 3px 6px rgba(0,0,0,.35), 0 3px 6px rgba(0,0,0,.25);
  --shadow-3: 0 10px 20px rgba(0,0,0,.3), 0 6px 6px rgba(0,0,0,.2);

  /* Shape */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  /* Spacing */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;
  --sp-8: 64px;

  /* Transitions */
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --ease-bounce: cubic-bezier(.34, 1.56, .64, 1);
  --dur-fast: 150ms;
  --dur-normal: 250ms;
  --dur-slow: 400ms;
}

/* ---- Reset & Base ----------------------------------------------------- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--surface-0);
  color: var(--on-surface);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

img { display: block; max-width: 100%; }
button { cursor: pointer; font: inherit; border: none; background: none; color: inherit; }
a { color: var(--primary-light); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Typography ------------------------------------------------------- */
h1 { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.25rem; font-weight: 600; }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.text-dim { color: var(--on-surface-dim); }
.text-medium { color: var(--on-surface-medium); }

/* ---- Layout ----------------------------------------------------------- */
.app-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: var(--sp-5);
}

/* ---- Header ----------------------------------------------------------- */
.app-header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding-bottom: var(--sp-5);
  border-bottom: 1px solid var(--surface-3);
  margin-bottom: var(--sp-6);
}

.app-header .logo-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-1);
}

.app-header .logo-icon .material-icons {
  font-size: 24px;
  color: #fff;
}

.app-header h1 {
  background: linear-gradient(135deg, var(--on-surface), var(--primary-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-subtitle {
  color: var(--on-surface-dim);
  font-size: 0.85rem;
  margin-left: auto;
}

/* ---- Panels (state-driven visibility) --------------------------------- */
.panel {
  display: none;
  animation: fadeSlideIn var(--dur-slow) var(--ease-out) both;
}

.panel.active {
  display: block;
}

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

/* ---- Upload Zone ------------------------------------------------------ */
.upload-zone {
  border: 2px dashed var(--surface-3);
  border-radius: var(--radius-lg);
  padding: var(--sp-8) var(--sp-5);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-4);
  text-align: center;
  transition: border-color var(--dur-normal) var(--ease-out),
              background var(--dur-normal) var(--ease-out),
              transform var(--dur-normal) var(--ease-out);
  cursor: pointer;
  position: relative;
  min-height: 340px;
}

.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-surface);
  transform: scale(1.01);
}

.upload-zone .upload-icon {
  font-size: 64px;
  color: var(--primary-light);
  transition: transform var(--dur-normal) var(--ease-bounce);
}

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

.upload-zone p {
  color: var(--on-surface-medium);
  max-width: 360px;
}

.upload-zone .file-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-formats {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
  justify-content: center;
  margin-top: var(--sp-2);
}

.upload-formats span {
  background: var(--surface-2);
  color: var(--on-surface-dim);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  letter-spacing: 0.04em;
}

/* ---- Editor Panel ----------------------------------------------------- */
.editor-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: var(--sp-5);
  align-items: start;
}

@media (max-width: 860px) {
  .editor-layout {
    grid-template-columns: 1fr;
  }
}

/* Cropper container */
.cropper-wrapper {
  background: var(--surface-1);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-2);
  position: relative;
}

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

/* Sidebar */
.editor-sidebar {
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}

.sidebar-card {
  background: var(--surface-1);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-1);
}

.sidebar-card h2 {
  margin-bottom: var(--sp-4);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--on-surface);
}

.sidebar-card h2 .material-icons {
  font-size: 20px;
  color: var(--primary-light);
}

/* Shape selector grid */
.shape-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-2);
}

.shape-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-3) var(--sp-2);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  transition: background var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
  position: relative;
  overflow: hidden;
}

.shape-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  transition: border-color var(--dur-fast) var(--ease-out);
  pointer-events: none;
}

.shape-btn:hover {
  background: var(--surface-hover);
  transform: translateY(-1px);
}

.shape-btn.active {
  background: var(--primary-surface);
}

.shape-btn.active::after {
  border-color: var(--primary);
}

.shape-btn svg {
  width: 32px;
  height: 32px;
  color: var(--on-surface-medium);
  transition: color var(--dur-fast);
}

.shape-btn.active svg {
  color: var(--primary-light);
}

.shape-btn .shape-label {
  font-size: 0.65rem;
  color: var(--on-surface-dim);
  text-align: center;
  line-height: 1.2;
  white-space: nowrap;
}

.shape-btn.active .shape-label {
  color: var(--primary-light);
}

/* Zoom controls */
.zoom-controls {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.zoom-controls input[type="range"] {
  flex: 1;
  accent-color: var(--primary);
  height: 4px;
}

.zoom-controls .material-icons {
  font-size: 20px;
  color: var(--on-surface-dim);
}

/* Editor toolbar (bottom of cropper) */
.editor-toolbar {
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-3);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  flex-wrap: wrap;
}

.toolbar-group {
  display: flex;
  gap: var(--sp-1);
}

.toolbar-group + .toolbar-group {
  margin-left: var(--sp-2);
  padding-left: var(--sp-3);
  border-left: 1px solid var(--surface-3);
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  transition: background var(--dur-fast), color var(--dur-fast);
  color: var(--on-surface-medium);
}

.icon-btn:hover {
  background: var(--surface-hover);
  color: var(--on-surface);
}

.icon-btn .material-icons {
  font-size: 20px;
}

/* ---- Result Panel ----------------------------------------------------- */
.result-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-6);
}

.result-preview {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-3);
}

/* Checkerboard transparency background */
.result-preview::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(45deg, #2a2a3e 25%, transparent 25%),
    linear-gradient(-45deg, #2a2a3e 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2a2a3e 75%),
    linear-gradient(-45deg, transparent 75%, #2a2a3e 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  z-index: 0;
}

.result-preview canvas {
  display: block;
  position: relative;
  z-index: 1;
  max-width: 100%;
  max-height: 480px;
  object-fit: contain;
}

.result-actions {
  display: flex;
  gap: var(--sp-3);
  flex-wrap: wrap;
  justify-content: center;
}

/* ---- Buttons ---------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--radius-full);
  font-weight: 600;
  font-size: 0.9rem;
  letter-spacing: 0.02em;
  transition: background var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
  position: relative;
  overflow: hidden;
}

.btn .material-icons {
  font-size: 18px;
}

/* Ripple */
.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at var(--ripple-x, 50%) var(--ripple-y, 50%),
              rgba(255,255,255,.25) 0%, transparent 60%);
  opacity: 0;
  transition: opacity var(--dur-normal);
}
.btn:active::after {
  opacity: 1;
  transition: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  box-shadow: var(--shadow-1);
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-2);
  filter: brightness(1.1);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--on-surface);
  border: 1px solid var(--surface-3);
}
.btn-secondary:hover {
  background: var(--surface-hover);
  transform: translateY(-1px);
}

.btn-accent {
  background: linear-gradient(135deg, var(--success), #43a047);
  color: #fff;
  box-shadow: var(--shadow-1);
}
.btn-accent:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-2);
  filter: brightness(1.1);
}

/* ---- Toast / Snackbar ------------------------------------------------- */
.toast-container {
  position: fixed;
  bottom: var(--sp-6);
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  pointer-events: none;
}

.toast {
  background: var(--surface-3);
  color: var(--on-surface);
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-3);
  font-size: 0.875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  animation: toastIn var(--dur-slow) var(--ease-bounce) both;
  pointer-events: auto;
}

.toast.toast-success { border-left: 3px solid var(--success); }
.toast.toast-error   { border-left: 3px solid var(--error); }

.toast .material-icons { font-size: 18px; }
.toast.toast-success .material-icons { color: var(--success); }
.toast.toast-error .material-icons   { color: var(--error); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(16px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to   { opacity: 0; transform: translateY(-8px) scale(0.95); }
}

/* ---- Footer ----------------------------------------------------------- */
.app-footer {
  margin-top: auto;
  padding: var(--sp-5) 0;
  border-top: 1px solid var(--surface-2);
  text-align: center;
  color: var(--on-surface-dim);
  font-size: 0.8rem;
}

.app-footer .material-icons {
  font-size: 14px;
  vertical-align: middle;
}

/* ---- Cropper.js overrides --------------------------------------------- */
.cropper-container {
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.cropper-view-box {
  outline: none;
  transition: clip-path var(--dur-normal) var(--ease-out),
              -webkit-clip-path var(--dur-normal) var(--ease-out);
}

.cropper-view-box img {
  /* Ensure the image inside the view box also gets clipped */
}


.cropper-line {
  background-color: var(--primary) !important;
  opacity: 0.5;
}

.cropper-point {
  background-color: var(--primary-light) !important;
  width: 10px !important;
  height: 10px !important;
  border-radius: 50%;
}

.cropper-modal {
  background-color: var(--surface-0) !important;
  opacity: 0.7 !important;
}

.cropper-dashed {
  border-color: rgba(179, 136, 255, 0.35) !important;
}

/* ---- Loading overlay -------------------------------------------------- */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(18, 18, 32, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  border-radius: var(--radius-lg);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--surface-3);
  border-top-color: var(--primary-light);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ---- Responsive ------------------------------------------------------- */
@media (max-width: 600px) {
  .app-wrapper { padding: var(--sp-4); }
  h1 { font-size: 1.35rem; }
  .upload-zone { padding: var(--sp-6) var(--sp-4); min-height: 260px; }
  .upload-zone .upload-icon { font-size: 48px; }
  .shape-grid { grid-template-columns: repeat(4, 1fr); }
  .result-actions { flex-direction: column; width: 100%; }
  .result-actions .btn { justify-content: center; }
  .header-subtitle { display: none; }
}

@media (max-width: 400px) {
  .shape-grid { grid-template-columns: repeat(3, 1fr); }
}
