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

body {
  font-family: "Segoe UI", sans-serif;
  background: #f0f2f5;
  color: #222;
  min-height: 100vh;
  padding: 24px 16px;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
}

/* Site footer */
.site-footer {
  margin-top: 28px;
  padding-top: 18px;
  border-top: 1px solid #e5e7eb;
  text-align: center;
  color: #9ca3af;
  font-size: 0.85rem;
}
.footer-links a {
  color: #6b7280;
  text-decoration: none;
}
.footer-links a:hover { color: #4f46e5; text-decoration: underline; }
.footer-links .sep { margin: 0 8px; color: #d1d5db; }
.footer-copy { margin-top: 6px; }

/* Legal pages (privacy / terms) */
.legal {
  max-width: 760px;
  margin: 0 auto;
  background: white;
  border-radius: 12px;
  padding: 32px 32px 28px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.legal h1 { font-size: 1.5rem; margin-bottom: 6px; }
.legal .updated { color: #9ca3af; font-size: 0.85rem; margin-bottom: 24px; }
.legal h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: #374151;
  margin: 26px 0 8px;
}
.legal p { line-height: 1.8; margin: 8px 0; color: #374151; }
.legal ul { margin: 8px 0 8px 1.3em; }
.legal li { line-height: 1.8; color: #374151; }
.legal a { color: #4f46e5; }
.legal .back { display: inline-block; margin-top: 28px; color: #6b7280; text-decoration: none; }
.legal .back:hover { color: #4f46e5; text-decoration: underline; }
.legal .biz { margin-top: 18px; color: #6b7280; font-size: 0.9rem; }

h1 {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: #1a1a2e;
}

.lead {
  font-size: 0.95rem;
  line-height: 1.6;
  color: #6b7280;
  margin: 0 0 20px;
  max-width: 720px;
}

/* Mode selector + Upload row */
.upload-row {
  display: flex;
  gap: 12px;
  align-items: stretch;
  margin-bottom: 20px;
}

.mode-selector {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.mode-btn {
  padding: 10px 20px;
  border: 2px solid #4f46e5;
  border-radius: 8px;
  background: white;
  color: #4f46e5;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  flex: 1;
}

.mode-btn.active {
  background: #4f46e5;
  color: white;
}

/* Upload area */
.upload-area {
  flex: 1;
  border: 2px dashed #a5b4fc;
  border-radius: 12px;
  background: white;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.upload-area:hover, .upload-area.drag-over {
  border-color: #4f46e5;
  background: #eef2ff;
}

.upload-area p { color: #6b7280; font-size: 1rem; margin: 0; }

/* Workspace */
.panels {
  display: grid;
  grid-template-columns: 1fr 328px;
  gap: 16px;
  align-items: start;
}

.panel {
  background: white;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  width: 100%;
}

/* Side ad column (stacked panels) */
.ad-side-col {
  position: sticky;
  top: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Side ad panel */
.ad-side-panel {
  background: white;
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}

.ad-side-label {
  font-size: 0.7rem;
  color: #9ca3af;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: center;
  margin-bottom: 8px;
}

.ad-side-link {
  display: block;
  text-decoration: none;
}

/* Actual ad creative image (300x250) */
.ad-img {
  display: block;
  width: 300px;
  height: 250px;
  max-width: 100%;
  margin: 0 auto;
  border-radius: 10px;
  transition: transform 0.1s, box-shadow 0.15s;
}
.ad-img:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
}

.ad-side-banner {
  background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
  border: 2px solid #e5e7eb;
  border-radius: 10px;
  width: 300px;
  height: 250px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
  cursor: pointer;
}

.ad-side-banner:hover {
  border-color: #4f46e5;
  background: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 100%);
  transform: translateY(-1px);
}

.ad-side-text {
  font-size: 0.95rem;
  font-weight: 600;
  color: #6b7280;
}

.ad-side-sub {
  font-size: 0.75rem;
  color: #9ca3af;
}

.panel h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: #374151;
}

/* Panel header with zoom bar */
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.panel-header h3 { margin-bottom: 0; }

.zoom-bar { display: flex; align-items: center; gap: 4px; }

.zoom-btn {
  width: 28px;
  height: 28px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: white;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s;
}
.zoom-btn:hover { background: #f3f4f6; }
.zoom-reset { width: auto; padding: 0 8px; font-size: 0.78rem; }

#zoom-label {
  font-size: 0.83rem;
  color: #6b7280;
  min-width: 40px;
  text-align: center;
}

/* Canvas */
.canvas-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
  width: 100%;
  height: 396px;
  cursor: default;
}

.canvas-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f9fafb;
  color: #9ca3af;
  font-size: 0.9rem;
  text-align: center;
  line-height: 1.7;
  pointer-events: none;
}

.canvas-placeholder.hidden { display: none; }

#canvas-transform {
  position: relative;
  display: inline-block;
  line-height: 0;
  transform-origin: 0 0;
  will-change: transform;
}

#canvas-input, #canvas-overlay {
  display: block;
}

#canvas-overlay {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none; /* toggled in JS */
}

/* Operation hints bar */
.op-hints {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  padding: 8px 10px;
  margin-top: 6px;
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
}

.op-hint {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.78rem;
  color: #6b7280;
  white-space: nowrap;
}

.op-icon {
  font-size: 0.85rem;
  color: #9ca3af;
}

/* Controls */
.controls {
  margin-top: 14px;
}

.hint {
  font-size: 0.83rem;
  color: #6b7280;
  margin-bottom: 10px;
  line-height: 1.5;
}

.hint-main {
  font-size: 1rem;
  font-weight: 600;
  color: #1e3a5f;
  background: #eff6ff;
  border-left: 4px solid #4f46e5;
  padding: 12px 16px;
  border-radius: 0 8px 8px 0;
  margin-bottom: 14px;
  line-height: 1.6;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.row label {
  font-size: 0.88rem;
  min-width: 100px;
  color: #374151;
}

.color-box {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid #d1d5db;
  background: #ccc;
}

#color-label { font-size: 0.83rem; color: #6b7280; }

input[type=range] {
  flex: 1;
  min-width: 100px;
  accent-color: #4f46e5;
}

/* Buttons */
.btn-primary {
  background: #4f46e5;
  color: white;
  border: none;
  padding: 9px 20px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary:hover:not(:disabled) { background: #4338ca; }
.btn-primary:disabled { background: #a5b4fc; cursor: not-allowed; }

.btn-secondary {
  background: white;
  color: #4f46e5;
  border: 1.5px solid #4f46e5;
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-secondary:hover { background: #eef2ff; }

.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

/* Brush buttons */
.brush-row {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.brush-btn {
  padding: 7px 14px;
  border-radius: 7px;
  border: 1.5px solid #d1d5db;
  background: white;
  font-size: 0.83rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.brush-btn.active { border-color: #4f46e5; background: #eef2ff; color: #4f46e5; }
#btn-fg.active { border-color: #16a34a; background: #dcfce7; color: #16a34a; }
#btn-bg.active { border-color: #dc2626; background: #fee2e2; color: #dc2626; }
#btn-poly-fg.active { border-color: #16a34a; background: #dcfce7; color: #16a34a; }
#btn-poly-bg.active { border-color: #dc2626; background: #fee2e2; color: #dc2626; }

.poly-color-btn {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: border-color 0.15s, transform 0.1s;
}
.poly-color-btn:hover { transform: scale(1.15); }
.poly-color-btn.active { border-color: #4f46e5; box-shadow: 0 0 0 2px white, 0 0 0 4px #4f46e5; }

/* Ad popup overlay */
.ad-popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
}

.ad-popup-dialog {
  background: white;
  border-radius: 16px;
  padding: 32px 28px 28px;
  max-width: 380px;
  width: 90%;
  box-shadow: 0 24px 64px rgba(0, 0, 0, .35);
  animation: popupIn 0.2s ease;
}

@keyframes popupIn {
  from { opacity: 0; transform: scale(0.94) translateY(8px); }
  to   { opacity: 1; transform: scale(1)    translateY(0);   }
}

.ad-popup-header {
  text-align: center;
  margin-bottom: 20px;
}

.ad-complete-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: #dcfce7;
  color: #16a34a;
  border-radius: 50%;
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 10px;
}

.ad-popup-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: #111827;
  margin-bottom: 0;
}

.ad-label {
  font-size: 0.72rem;
  color: #9ca3af;
  text-align: center;
  margin-bottom: 6px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.ad-banner-link {
  display: block;
  text-decoration: none;
}

.ad-banner-placeholder {
  background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
  border: 2px solid #e5e7eb;
  border-radius: 10px;
  width: 300px;
  height: 250px;
  max-width: 100%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

.ad-banner-placeholder:hover {
  border-color: #4f46e5;
  background: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 100%);
  transform: translateY(-1px);
}

.ad-banner-inner {
  text-align: center;
}

.ad-banner-text {
  display: block;
  font-size: 1rem;
  font-weight: 600;
  color: #6b7280;
}

.ad-banner-sub {
  display: block;
  font-size: 0.8rem;
  color: #9ca3af;
  margin-top: 4px;
}

.ad-popup-footer {
  margin-top: 20px;
  text-align: center;
}

.ad-status {
  font-size: 0.82rem;
  color: #6b7280;
  margin-bottom: 12px;
  min-height: 1.2em;
  transition: color 0.2s;
}

.ad-download-btn {
  width: 100%;
  padding: 12px;
  font-size: 1rem;
}

.ad-download-btn:disabled {
  background: #d1d5db;
  color: #9ca3af;
  cursor: not-allowed;
}

/* Loading overlay */
.loading {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  color: white;
  font-size: 1.1rem;
  font-weight: 600;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255,255,255,.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-right: 14px;
}

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