:root {
  --color-black: #000000;
  --color-gray-dark: #5c5c5c;
  --color-gray: #e5e5e5;
  --color-gray-light: #f2f2f2;
  --color-white: #ffffff;
  --color-white-alpha: #ffffffcc;
  --color-accent: #ff6b35;
  --color-orange: #FA6500; /* brand orange — mask + eraser controls */
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background-color: #fff;
  color: #0C161D;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url('../../images/background-graphic.png');
  background-repeat: repeat;
  background-size: cover;
  background-position: center;
  transform: scaleX(-1);
  opacity: 0.75;
  z-index: -1;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 40px;
  background-color: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(4px);
  box-shadow: 0px 0px 10px 0px #00000080;
}

.header__back {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--color-black);
  text-decoration: none;
  font-size: 16px;
  font-weight: 500;
}

.header__back:hover {
  opacity: 0.7;
}

.header__cta {
  font-size: 14px;
  color: var(--color-gray-dark);
}

.header__link {
  color: var(--color-accent);
  text-decoration: underline;
}

/* Main Container */
.main-container {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  padding: 0 20px 20px;
  gap: 20px;
}

/* Content Wrapper */
.content-wrapper {
  flex-grow: 1;
  display: flex;
  gap: 24px;
  padding: 20px;
}

/* Upload Panel - left side */
.upload-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(5px);
  box-shadow: 0px 0px 10px 0px #00000080;
  border-radius: 16px;
}

.upload-zone {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 16px;
  border: 2px solid var(--color-accent);
  border-radius: 16px;
  background-color: rgba(255, 255, 255, 0.5);
  backdrop-filter: blur(5px);
  padding: 24px;
}

.upload-zone--drag-over {
  background-color: rgba(255, 107, 53, 0.08);
  border-color: var(--color-accent);
  border-style: dashed;
}

.image-container--drag-over {
  border-style: dashed;
  background-color: rgba(255, 107, 53, 0.08);
}

.upload-zone__hint {
  font-size: 14px;
  color: var(--color-gray-dark);
}

.image-container {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  border: 2px solid var(--color-accent);
  background-color: rgba(255, 255, 255, 0.5);
  backdrop-filter: blur(5px);
  overflow: hidden;
  min-height: 0;
}

.image-container__inner {
  flex: 1;
  position: relative;
  min-height: 0;
  overflow: hidden;
}

/* Image canvas — centered, contained */
.main__canvas {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

/* Mask canvas — overlaid on top of image canvas.
   CSS opacity keeps the color flat and uniform — no matter how many
   overlapping strokes you paint, you always see the same tint. */
.mask__canvas {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  cursor: none; /* replaced by the custom .brush-cursor circle */
  z-index: 2;
  opacity: 0.5;
}

/* Custom brush cursor — a circle matching the current brush size so the user
   can see exactly what they'll paint. Orange ring, 25%-opacity orange fill. */
.brush-cursor {
  position: absolute; /* relative to .image-container__inner (a backdrop-filter
                         ancestor would break position:fixed) */
  box-sizing: content-box; /* width == the painted brush diameter */
  display: none;
  pointer-events: none;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 2px solid var(--color-orange);
  background: rgba(250, 101, 0, 0.25);
  z-index: 50;
}

/* Thumbnail Bar */
.thumbnail-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background-color: rgba(255, 255, 255, 0.85);
  border-top: 1px solid var(--color-gray);
}

.thumbnail-list {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  flex: 1;
}

.thumbnail {
  position: relative;
  flex-shrink: 0;
  width: 60px;
  height: 60px;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.2s;
}

.thumbnail:hover {
  border-color: var(--color-gray-dark);
}

.thumbnail--active {
  border-color: var(--color-accent);
}

.thumbnail__image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumbnail__remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background-color: rgba(0, 0, 0, 0.6);
  color: var(--color-white);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
}

.thumbnail:hover .thumbnail__remove {
  opacity: 1;
}

.thumbnail__remove:hover {
  background-color: rgba(0, 0, 0, 0.8);
}

.thumbnail-add-btn {
  flex-shrink: 0;
  width: 60px;
  height: 60px;
  border-radius: 8px;
  border: 2px solid var(--color-accent);
  background-color: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s;
}

.thumbnail-add-btn:hover {
  opacity: 0.8;
}

/* Settings Column - right side */
.settings-column {
  width: 340px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.settings-column__buttons {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Settings Card */
.settings-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
  border-radius: 16px;
  border: 2px solid var(--color-accent);
  background-color: rgba(255, 255, 255, 0.5);
  backdrop-filter: blur(5px);
  box-shadow: 0px 0px 10px 0px #00000080;
}

.settings-card__header {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--color-black);
}

.settings-card__title {
  font-size: 16px;
  font-weight: 400;
}

.settings-card__description {
  font-size: 13px;
  line-height: 1.5;
  color: var(--color-gray-dark);
}

/* Mask mode toggle — fix 2: smaller, left-aligned */
.mask-mode-toggle {
  display: flex;
  gap: 8px;
  justify-content: flex-start;
}

.mask-mode-btn {
  flex: 0 0 auto;
  padding: 6px 18px;
  border-radius: 30px;
  border: 1.5px solid var(--color-gray);
  background-color: var(--color-white);
  font-size: 13px;
  font-weight: 500;
  color: var(--color-black);
  cursor: pointer;
  transition: background-color 0.2s, border-color 0.2s, color 0.2s;
}

.mask-mode-btn--active {
  background-color: var(--color-accent);
  border-color: var(--color-accent);
  color: var(--color-white);
  font-weight: 600;
}

.mask-mode-btn:not(.mask-mode-btn--active):hover {
  border-color: var(--color-gray-dark);
}

/* Brush size */
.brush-size-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brush-size-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--color-black);
}

.brush-size-value {
  font-size: 14px;
  color: var(--color-gray-dark);
}

.brush-slider {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 9px;
  border-radius: 5px;
  background: linear-gradient(
    to right,
    var(--color-orange) 0%,
    var(--color-orange) calc(var(--value, 49.49) * 1%),
    var(--color-gray) calc(var(--value, 49.49) * 1%),
    var(--color-gray) 100%
  );
  outline: none;
  cursor: pointer;
}

/* Draggable thumb: orange ring with a white center. */
.brush-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--color-white);
  border: 3px solid var(--color-orange);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.brush-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--color-white);
  border: 3px solid var(--color-orange);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

/* Discard mask button — fix 1: add border so it looks like a button */
.discard-mask-row {
  display: flex;
  justify-content: flex-end;
}

.discard-mask-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: 1.5px solid var(--color-gray);
  background: var(--color-white);
  font-size: 13px;
  color: var(--color-gray-dark);
  cursor: pointer;
  border-radius: 20px;
  transition: color 0.2s, border-color 0.2s, background-color 0.2s;
}

.discard-mask-btn:hover:not(:disabled) {
  color: var(--color-black);
  border-color: var(--color-gray-dark);
}

.discard-mask-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* File input */
.file-input {
  display: none;
}

/* Upload button */
.upload-button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 12px 28px;
  border-radius: 30px;
  background-color: var(--color-accent);
  color: var(--color-white);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: opacity 0.2s;
}

.upload-button:hover {
  opacity: 0.9;
}

/* Process / action buttons */
.process-button {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  padding: 14px 32px;
  border-radius: 30px;
  background-color: var(--color-accent);
  color: var(--color-white);
  cursor: pointer;
  border: none;
  font-size: 16px;
  font-weight: 700;
  transition: opacity 0.2s;
  backdrop-filter: blur(8px);
  box-shadow: 0px 0px 10px 0px #00000080;
}

.process-button:disabled {
  background-color: var(--color-gray);
  color: #aaa;
  cursor: default;
  box-shadow: none;
}

.process-button--secondary {
  background-color: var(--color-white);
  color: var(--color-black);
  border: 2px solid var(--color-gray);
  box-shadow: none;
}

.process-button--secondary:hover:not(:disabled) {
  border-color: var(--color-gray-dark);
}

.process-button--download {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.process-button--download:hover:not(:disabled) {
  opacity: 0.85;
}

/* Orange outline + frosted-glass background (Try Again, Erase All). */
.process-button--orange {
  gap: 8px;
  color: var(--color-orange);
  border: 2px solid var(--color-orange);
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: none;
}

.process-button--orange:hover:not(:disabled) {
  background: rgba(250, 101, 0, 0.14);
}

.process-button--orange:disabled {
  color: #aaa;
  border-color: var(--color-gray);
  background: rgba(255, 255, 255, 0.12);
}

/* Loading Spinner */
.loading-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 10;
  transform: translate(-50%, -50%);
  background: rgba(255, 255, 255, 0.9);
  padding: 2rem;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--color-gray);
  border-top: 4px solid var(--color-accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Image Preview Modal */
.image-preview-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.image-preview-modal--open {
  display: flex;
}

.image-preview-modal__backdrop {
  position: absolute;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(6px);
}

.image-preview-modal__inner {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  max-width: calc(100% - 32px);
}

.image-preview-modal__image {
  max-width: 100%;
  max-height: calc(100svh - 80px);
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  display: block;
}

.image-preview-modal__close {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: var(--color-white-alpha);
  color: var(--color-black);
  border: none;
  cursor: pointer;
  backdrop-filter: blur(8px);
  box-shadow: 0px 0px 10px 0px #00000080;
  transition: opacity 0.2s;
}

.image-preview-modal__close:hover {
  opacity: 0.85;
}

/* ============ Before/After Feature ============ */

.ba-container {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.ba-split {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: ew-resize;
  user-select: none;
}

.ba-split__img--before {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  -webkit-user-drag: none;
}

.ba-split__after-wrap {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0; /* clip the After to the RIGHT of the divider (before=left, after=right) */
  width: 50%;
  overflow: hidden;
  will-change: width;
}

.ba-split__img--after {
  position: absolute;
  top: 0;
  right: 0; /* right-align so the visible portion lines up with the base image */
  object-fit: contain;
  pointer-events: none;
  -webkit-user-drag: none;
}

.ba-split__divider {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--color-accent);
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  cursor: ew-resize;
}

.ba-split__handle {
  position: absolute;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--color-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0,0,0,0.35);
  cursor: ew-resize;
  transition: transform 0.15s ease;
}

.ba-split__handle:hover {
  transform: translateX(-50%) scale(1.08);
}

.ba-label {
  position: absolute;
  top: 16px;
  font-size: 18px;
  font-weight: 400;
  padding: 8px 22px;
  border-radius: 30px;
  pointer-events: none;
  z-index: 5;
  letter-spacing: 0.2px;
  text-transform: uppercase;
}

.ba-label--before {
  left: 16px;
  background: rgba(180, 180, 180, 0.85);
  color: #ffffff;
}

.ba-label--after {
  right: 16px;
  background: rgba(255, 255, 255, 0.95);
  color: #000000;
  border: 1.5px solid #1a1a1a;
}

.ba-sidebyside {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  gap: 0;
}

.ba-sidebyside::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  background: rgba(255, 255, 255, 0.8);
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 2;
}

.ba-sidebyside__img {
  width: 50%;
  height: 100%;
  object-fit: contain;
  flex-shrink: 0;
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
}

.ba-sidebyside__img--left  { object-position: right center; }
.ba-sidebyside__img--right { object-position: left center; }

.ba-hover {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ba-hover__img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  cursor: crosshair;
  -webkit-user-drag: none;
  pointer-events: auto;
}

.ba-hover-popup {
  position: fixed;
  z-index: 1000;
  display: flex;
  gap: 0;
  pointer-events: none;
  box-shadow: 0 4px 24px rgba(0,0,0,0.3);
  border-radius: 0;
  overflow: hidden;
}

.ba-hover-popup__panel {
  position: relative;
  width: 280px;
  height: 280px;
  overflow: hidden;
}

.ba-hover-popup__canvas {
  width: 280px;
  height: 280px;
  display: block;
}

@media (max-width: 768px) {
  .ba-hover-popup { flex-direction: row; }
  .ba-hover-popup__panel { width: 150px; height: 150px; }
  .ba-hover-popup__canvas { width: 150px; height: 150px; }
}

.ba-hover-popup__label {
  position: absolute;
  top: 0;
  left: 0;
  font-size: 17px;
  font-weight: 300;
  padding: 5px 12px;
  background: #ffffff;
  color: var(--color-accent);
  letter-spacing: 0.2px;
  line-height: 1.4;
}

.ba-hover-popup__label--after {
  background: var(--color-accent);
  color: #ffffff;
}

.ba-switcher {
  position: absolute;
  bottom: 16px;
  left: 16px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.ba-switcher__options {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-radius: 24px;
  padding: 6px;
  box-shadow: 0 2px 16px rgba(0,0,0,0.18);
  border: 2px solid var(--color-accent);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(6px) scale(0.96);
  transform-origin: bottom center;
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
}

.ba-switcher__options--open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.ba-switcher__btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.18s;
  flex-shrink: 0;
}

.ba-switcher__btn img {
  pointer-events: none;
  flex-shrink: 0;
  transition: filter 0.18s;
}

.ba-switcher__btn:hover { background: rgba(0,0,0,0.06); }
.ba-switcher__btn--active { background: var(--color-accent) !important; }
.ba-switcher__btn--active img { filter: brightness(0) invert(1); }

.ba-switcher__toggle {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 2px solid var(--color-accent);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  box-shadow: 0 2px 16px rgba(0,0,0,0.18);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.18s;
  flex-shrink: 0;
}

.ba-switcher__toggle img {
  pointer-events: none;
  flex-shrink: 0;
  transition: filter 0.18s;
}

.ba-switcher__toggle:hover { background: #fff; }
.ba-switcher__toggle--open { background: var(--color-accent); }
.ba-switcher__toggle--open:hover { background: var(--color-accent); opacity: 0.88; }
.ba-switcher__toggle--open img { filter: brightness(0) invert(1); }

/* ============ End Before/After Feature ============ */

/* Mobile responsive */
@media (max-width: 768px) {
  .header { padding: 12px 16px; }
  .main-container { padding: 0 16px 16px; }
  .content-wrapper { flex-direction: column; padding: 16px; }
  .settings-column { width: 100%; }
  .upload-zone { min-height: 200px; }
  .image-container__inner { min-height: 300px; }
}

.image-actions {
  position: absolute;
  bottom: 12px;
  right: 12px;
  display: flex;
  gap: 6px;
  z-index: 10;
}

.image-action-btn {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  transition: background 0.15s;
}

.image-action-btn--feedback { background: #284B60; }
.image-action-btn--feedback:hover { background: #1f3c4d; }
.image-action-btn--bad { background: rgba(200,81,0,0.5); }
.image-action-btn--bad:hover, .image-action-btn--bad--active { background: #c85100; }
.image-action-btn--good { background: rgba(2,159,134,0.5); }
.image-action-btn--good:hover, .image-action-btn--good--active { background: #029f86; }

/* Locked while an erase job runs — no interaction, dimmed. */
.thumbnail-bar--disabled {
  pointer-events: none;
  opacity: 0.4;
}
.settings-card--disabled {
  pointer-events: none;
  opacity: 0.5;
}

/* ── Error banner (image limit / upload errors) ── */
.error-banner {
  position: fixed;
  top: 63px;
  left: 0;
  right: 0;
  z-index: 9999;
  display: none;
  align-items: center;
  gap: 10px;
  padding: 10px 40px;
  background-color: #A62727E5;
  border-bottom: none;
  backdrop-filter: blur(10px);
  color: #ffffff;
  font-size: 13px;
  font-weight: 500;
}

.error-banner__close {
  flex-shrink: 0;
  margin-left: auto;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  color: #ffffff;
  cursor: pointer;
  border-radius: 50%;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.error-banner__close:hover {
  opacity: 1;
}
