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

:root {
  --bg: #f0efed;
  --surface: #ffffff;
  --border: #d9d7d4;
  --text: #1a1917;
  --text-muted: #74726e;
  --accent: #1a1917;
  --accent-hover: #3d3b38;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
}

/* ── Header ─────────────────────────────────────────── */

header {
  padding: 2.5rem 2rem 1.5rem;
  text-align: center;
}

header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.tagline {
  margin-top: 0.35rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ── Main ────────────────────────────────────────────── */

main {
  flex: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.5rem 3rem;
}

/* ── Drop zone ───────────────────────────────────────── */

#drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  min-height: 340px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

#drop-zone.drag-over {
  border-color: var(--accent);
  background: #f9f8f7;
}

#drop-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  padding: 3rem 2rem;
  pointer-events: none;
}

.drop-icon {
  width: 52px;
  height: 52px;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.drop-text {
  font-size: 1.05rem;
  font-weight: 500;
}

.drop-subtext {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.drop-subtext button {
  pointer-events: all;
  background: none;
  border: none;
  color: var(--accent);
  font-size: inherit;
  font-family: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  padding: 0;
}

.drop-subtext button:hover {
  color: var(--accent-hover);
}

.error {
  color: #c0392b;
  font-size: 0.875rem;
  margin-top: 0.25rem;
}

/* ── Workspace (grid + controls) ────────────────────── */

#workspace {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
}

#grid-wrap {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  /* allow dropping more files onto the grid */
  min-height: 200px;
}

#photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
}

/* ── Photo card ──────────────────────────────────────── */

.photo-card {
  position: relative;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 0.75rem 0.6rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.thumb-wrap {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.thumb-wrap canvas {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: 2px;
  box-shadow: var(--shadow);
}

.card-name {
  width: 100%;
  font-size: 0.75rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

.card-dl-btn {
  width: 100%;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.775rem;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s;
}

.card-dl-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.card-remove-btn {
  position: absolute;
  top: 5px;
  right: 6px;
  width: 20px;
  height: 20px;
  border: none;
  background: rgba(0,0,0,0.08);
  border-radius: 50%;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, color 0.12s;
}

.card-remove-btn:hover {
  background: #e0392b;
  color: #fff;
}

/* ── Controls panel ──────────────────────────────────── */

#controls {
  width: 240px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.control-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.value-badge {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 7px;
}

/* Segmented control */

.segmented {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 7px;
  overflow: hidden;
  background: var(--bg);
}

.seg-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 0.5rem 0;
  font-size: 0.875rem;
  font-family: inherit;
  cursor: pointer;
  color: var(--text-muted);
  transition: background 0.12s, color 0.12s;
}

.seg-btn:hover {
  background: #e8e7e4;
}

.seg-btn.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* Range sliders */

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}

/* Color picker */

input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 44px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 2px;
  cursor: pointer;
  background: none;
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 5px;
}

/* Select */

select {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  padding: 0.5rem 2rem 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2374726e' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 0.65rem center;
  color: var(--text);
  font-size: 0.875rem;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  transition: border-color 0.12s;
}

select:focus {
  border-color: var(--accent);
}

.ratio-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Action buttons */

.control-actions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 0.5rem;
}

.btn-instagram {
  width: 100%;
  padding: 0.7rem 1rem;
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, #f58529, #dd2a7b, #8134af, #515bd4);
  color: #fff;
  font-size: 0.9rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  transition: opacity 0.15s, box-shadow 0.15s;
  box-shadow: 0 2px 8px rgba(221, 42, 123, 0.25);
}

.btn-instagram:hover {
  opacity: 0.9;
  box-shadow: 0 4px 14px rgba(221, 42, 123, 0.35);
}

.btn-instagram.active {
  box-shadow: 0 0 0 3px rgba(221, 42, 123, 0.3), 0 2px 8px rgba(221, 42, 123, 0.25);
}

.btn-primary {
  width: 100%;
  padding: 0.7rem 1rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 0.9rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-ghost {
  width: 100%;
  padding: 0.6rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s;
}

.btn-ghost:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-ghost.btn-danger {
  color: #c0392b;
  border-color: #e8c4c1;
}

.btn-ghost.btn-danger:hover {
  border-color: #c0392b;
  color: #c0392b;
}

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

/* ── Footer ──────────────────────────────────────────── */

footer {
  text-align: center;
  padding: 1.25rem 1rem;
  font-size: 0.775rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

/* ── Responsive ──────────────────────────────────────── */

@media (max-width: 680px) {
  header {
    padding: 1.75rem 1rem 1rem;
  }

  main {
    padding: 0 1rem 2.5rem;
  }

  #workspace {
    flex-direction: column;
  }

  #controls {
    width: 100%;
  }

  #photo-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }
}
