:root {
  --bg-page: #ececec;
  --bg-card: #ffffff;
  --bg-head: #dbe7f3;
  --bg-toolbar: #303237;
  --text-main: #273443;
  --text-muted: #5f6f82;
  --line: #d5dde6;
  --accent: #0f7d67;
  --accent-dark: #0c6856;
  --input-bg: #ffffff;
  --shadow: 0 3px 12px rgba(18, 38, 63, 0.08);
  --radius: 8px;
  --bg-secondary: #f8f8f8;
  --bg-hover-light: #f2f5f9;
  --bg-drag-over: #eef8f5;
  --canvas-bg: #ffffff;
  --canvas-border: #b8b8b8;
  --preview-bg: #d7d7d7;
  --focus-border: #7eb6ff;
  --focus-shadow: rgba(126, 182, 255, 0.2);
  --error-color: #d14343;
  --disabled-bg: #b7c9c5;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-page: #1a1a1a;
    --bg-card: #2d2d2d;
    --bg-head: #1f3a4a;
    --bg-toolbar: #0d0d0d;
    --text-main: #e8eef5;
    --text-muted: #a0aec0;
    --line: #404449;
    --accent: #12b89a;
    --accent-dark: #0f9882;
    --input-bg: #3a3f47;
    --shadow: 0 3px 12px rgba(0, 0, 0, 0.3);
    --bg-secondary: #252525;
    --bg-hover-light: #3a4250;
    --bg-drag-over: #1a3a33;
    --canvas-bg: #2d2d2d;
    --canvas-border: #404449;
    --preview-bg: #1f1f1f;
    --focus-border: #5eb3ff;
    --focus-shadow: rgba(94, 179, 255, 0.2);
    --error-color: #ff6b6b;
    --disabled-bg: #5a6f6a;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Manrope', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--text-main);
  background: var(--bg-page);
}

.page {
  width: min(1160px, calc(100% - 28px));
  margin: 22px auto;
  display: grid;
  grid-template-columns: minmax(330px, 1fr) minmax(420px, 1fr);
  gap: 24px;
  align-items: start;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  background: var(--bg-head);
  border-bottom: 1px solid var(--line);
  padding: 22px 24px;
}

.card-footer {
  border-top: 1px solid var(--line);
  padding: 18px 24px;
  background: var(--bg-secondary);
}

.controls-card {
  min-height: 740px;
  display: flex;
  flex-direction: column;
}

.controls-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.title-wrap h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.03em;
  line-height: 1;
}

.title-wrap p {
  margin: 12px 0 0;
  color: var(--text-muted);
  font-size: 15px;
}

.mode-switch {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
  min-width: 130px;
}

.mode-btn {
  border: 1px solid var(--line);
  background: var(--bg-card);
  color: var(--text-main);
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 16px;
  font-weight: 600;
}

.mode-btn.active {
  background: var(--accent);
  color: #ffffff;
  border-color: transparent;
}

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

.controls-body {
  padding: 18px 24px 10px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field label {
  font-size: 16px;
  font-weight: 600;
}

.required {
  color: var(--error-color);
}

.field-inline {
  align-items: flex-start;
}

input,
select {
  height: 52px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font: inherit;
  font-size: 16px;
  color: var(--text-main);
  background: var(--input-bg);
  padding: 8px 14px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--focus-border);
  box-shadow: 0 0 0 3px var(--focus-shadow);
}

.file-picker {
  height: 52px;
  border: 1px solid var(--line);
  border-radius: 7px;
  display: grid;
  grid-template-columns: 120px 108px 1fr;
  overflow: hidden;
  background: var(--bg-card);
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.file-picker.drag-over {
  border-color: var(--accent);
  background: var(--bg-drag-over);
  box-shadow: 0 0 0 3px rgba(15, 125, 103, 0.14);
}

.file-label,
.file-btn,
.file-name {
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-size: 16px;
}

.file-label,
.file-btn {
  border-right: 1px solid var(--line);
}

.file-btn {
  cursor: pointer;
  user-select: none;
  background: var(--bg-head);
}

.file-btn:hover {
  background: var(--bg-hover-light);
}

.file-name {
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.controls-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.submit-btn,
.download-btn {
  border: 0;
  background: var(--accent);
  color: #ffffff;
  border-radius: 8px;
  padding: 10px 28px;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.15s ease;
}

.secondary-btn {
  border: 1px solid var(--line);
  background: var(--bg-card);
  color: var(--text-main);
  border-radius: 8px;
  padding: 8px 18px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.15s ease;
}

.secondary-btn:hover {
  background: var(--bg-hover-light);
  transform: translateY(-2px);
}

.secondary-btn:active {
  transform: translateY(0);
}

.submit-btn:hover,
.download-btn:hover {
  background: var(--accent-dark);
  transform: translateY(-2px);
}

.submit-btn:active,
.download-btn:active {
  transform: translateY(0);
}

.download-btn:disabled {
  background: var(--disabled-bg);
  cursor: not-allowed;
}

.print-btn:disabled {
  color: var(--text-muted);
  background: var(--bg-hover-light);
  cursor: not-allowed;
}

.branding-copy {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
}

.preview-card {
  display: flex;
  flex-direction: column;
  min-height: 740px;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
}

.preview-header h2 {
  margin: 0;
  font-size: 22px;
}

.preview-header p {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
}

.preview-toolbar {
  height: 58px;
  background: var(--bg-toolbar);
  color: #f5f5f5;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
}

.toolbar-page {
  font-weight: 700;
  min-width: 64px;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 4px;
  padding: 4px 8px;
}

.toolbar-btn {
  border: 0;
  background: transparent;
  color: #f5f5f5;
  width: 34px;
  height: 34px;
  border-radius: 4px;
  font-size: 19px;
  font-weight: 700;
  cursor: pointer;
}

.toolbar-btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

.zoom-label {
  margin-left: auto;
  font-weight: 700;
}

.preview-shell {
  position: relative;
  height: 530px;
  overflow: auto;
  background: var(--preview-bg);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 10px;
}

.empty-message {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--text-muted);
  font-size: 16px;
  padding: 20px;
}

#previewCanvas {
  display: none;
  background: var(--canvas-bg);
  border: 1px solid var(--canvas-border);
  transform-origin: top left;
}

.preview-footer {
  display: flex;
  justify-content: center;
  gap: 12px;
  background: var(--bg-secondary);
}

.crop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(18, 22, 34, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 16px;
  z-index: 50;
  overflow: auto;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.crop-overlay.active {
  opacity: 1;
  visibility: visible;
}

.crop-card {
  width: min(520px, 100%);
  max-height: calc(100dvh - 32px);
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.95);
  transition: transform 0.25s ease;
}

.crop-overlay.active .crop-card {
  transform: scale(1);
}

.crop-header {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 14px 18px;
  background: var(--bg-head);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 16px;
  font-weight: 600;
}

.crop-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.crop-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.crop-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  overflow: auto;
}

#cropCanvas {
  width: 100%;
  max-height: calc(100dvh - 170px);
  height: auto;
  background: var(--preview-bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: grab;
  touch-action: none;
}

#cropCanvas.dragging {
  cursor: grabbing;
}

.crop-controls {
  width: 100%;
  display: grid;
  grid-template-columns: 60px 1fr;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}

.crop-controls input[type="range"] {
  height: 28px;
}

.crop-help {
  grid-column: 1 / -1;
  font-size: 13px;
  color: var(--text-muted);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  border: 0;
  padding: 0;
  clip: rect(0 0 0 0);
  overflow: hidden;
}

@media (max-width: 960px) {
  .page {
    grid-template-columns: 1fr;
  }
  .controls-card,
  .preview-card {
    min-height: auto;
  }
  .preview-shell {
    height: 440px;
  }
}

/* ── Love Banner Popup Styles ── */
@keyframes slideInDown {
  from { opacity: 0; transform: translate(-50%, -50%) translateY(-60px) scale(0.9); }
  to   { opacity: 1; transform: translate(-50%, -50%) translateY(0) scale(1); }
}

@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  25%       { transform: scale(1.1); }
  50%       { transform: scale(1); }
}

@keyframes shimmer {
  0%, 100% { background-position: -1000px 0; }
  50%       { background-position: 1000px 0; }
}

.love-banner {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 9999;
  animation: slideInDown 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.love-banner-content {
  position: relative;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 25%, #f093fb 50%, #4facfe 75%, #00f2fe 100%);
  background-size: 400% 400%;
  animation: shimmer 8s ease infinite;
  border-radius: 20px;
  padding: 40px 50px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3), 0 0 40px rgba(102, 126, 234, 0.4);
  text-align: center;
  min-width: 320px;
  max-width: 500px;
  backdrop-filter: blur(10px);
  border: 2px solid rgba(255, 255, 255, 0.2);
}

/* ── FIXED: banner close button – works on both mobile and desktop ── */
.love-banner-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: rgba(255, 255, 255, 0.35);
  border: 2px solid rgba(255, 255, 255, 0.6);
  color: white;
  font-size: 22px;
  line-height: 1;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
  font-weight: 700;
  /* Prevent 300ms tap delay on mobile */
  touch-action: manipulation;
  /* Ensure the button is always on top and tappable */
  z-index: 10;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.love-banner-close:hover,
.love-banner-close:focus-visible {
  background: rgba(255, 255, 255, 0.55);
  transform: rotate(90deg) scale(1.1);
  border-color: rgba(255, 255, 255, 0.9);
  outline: none;
}

.love-banner-close:active {
  transform: rotate(90deg) scale(0.95);
}

.love-banner-heart {
  font-size: 60px;
  animation: heartbeat 1.5s ease infinite;
  margin-bottom: 15px;
  display: block;
}

.love-banner-title {
  margin: 0 0 10px 0;
  font-size: 32px;
  font-weight: 700;
  color: white;
  text-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.love-banner-text {
  margin: 0 0 20px 0;
  font-size: 24px;
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  font-weight: 600;
}

.love-banner-whatsapp {
  display: inline-block;
  background: rgba(255, 255, 255, 0.95);
  color: #667eea;
  padding: 12px 28px;
  border-radius: 50px;
  text-decoration: none;
  font-weight: 700;
  font-size: 16px;
  transition: all 0.3s ease;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
  border: 2px solid white;
  cursor: pointer;
  touch-action: manipulation;
}

.love-banner-whatsapp:hover {
  background: white;
  transform: translateY(-3px);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
  color: #764ba2;
}

.love-banner-whatsapp span {
  margin-right: 8px;
  font-size: 18px;
}

@media (max-width: 600px) {
  .love-banner-content {
    padding: 30px 25px;
    min-width: 280px;
    max-width: calc(100vw - 30px);
  }
  .love-banner-title { font-size: 26px; }
  .love-banner-text  { font-size: 20px; }
  .love-banner-heart { font-size: 50px; }
  .love-banner-whatsapp { font-size: 14px; padding: 10px 22px; }
  .love-banner-close {
    width: 44px;
    height: 44px;
    font-size: 20px;
    top: 10px;
    right: 10px;
  }
}
