:root {
  --bg: #e0f2fe;
  --surface: #1a1a2e;
  --card: #16213e;
  --border: #2d2d5e;
  --accent: #e94560;
  --accent2: #0f3460;
  --gold: #f5a623;
  --text: #fffffe;
  --muted: #a7a9be;
  --success: #2ecc71;
}

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

body {
  background: #ffffff;
  font-family: 'Nunito', sans-serif;
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  user-select: none;
}

body::before {
  display: none;
}

html[dir="rtl"] body {
  direction: rtl;
}

.container {
  position: relative;
  z-index: 1;
  max-width: 1300px;
  margin: 0 auto;
  padding: 28px 24px;
}

/* ── HOME GALLERY ── */
.home-section {
  color: #182133;
}

.home-hero {
  max-width: 860px;
  margin: 0 auto 32px;
  text-align: center;
}

.site-brand {
  margin-bottom: 10px;
  color: #e94560;
  font-size: 0.95rem;
  font-weight: 900;
}

.home-section h1 {
  font-family: 'Fredoka One', cursive;
  color: #7c2cff;
  font-size: clamp(2rem, 5vw, 3.9rem);
  line-height: 1.05;
  text-align: center;
  margin: 0;
}

.home-intro {
  max-width: 720px;
  margin: 16px auto 0;
  color: #465166;
  font-size: 1.08rem;
  font-weight: 700;
  line-height: 1.55;
}

.seo-preview {
  width: min(230px, 62vw);
  margin: 22px auto 0;
}

.seo-preview img {
  display: block;
  width: 100%;
  height: auto;
  border: 2px dashed #f59e0b;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.14);
}

.language-switcher {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.12);
  backdrop-filter: blur(6px);
}

.language-icon {
  width: 18px;
  height: 18px;
  color: #4b5563;
  flex: 0 0 auto;
}

.language-icon circle,
.language-icon path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.language-select {
  min-width: 118px;
  height: 34px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  background: #f3f4f6;
  color: #1f2937;
  font-family: 'Nunito', sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 0 30px 0 12px;
  cursor: pointer;
}

.language-select:focus {
  border-color: #7c2cff;
  outline: none;
  box-shadow: 0 0 0 3px rgba(124, 44, 255, 0.18);
}

.gallery-section,
.how-to-section {
  margin-top: 34px;
}

.home-section h2 {
  font-family: 'Fredoka One', cursive;
  color: #172033;
  font-size: clamp(1.35rem, 3vw, 2rem);
  line-height: 1.15;
  text-align: center;
  margin: 0 0 18px;
}

.canvas-gallery {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 20px;
}

.how-to-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  list-style: none;
  counter-reset: how-to;
  max-width: 1120px;
  margin: 0 auto;
}

.how-to-list li {
  counter-increment: how-to;
  min-height: 116px;
  border: 2px solid #d8e3f2;
  border-radius: 12px;
  background: #ffffff;
  color: #273246;
  padding: 18px;
  font-size: 0.98rem;
  font-weight: 800;
  line-height: 1.35;
  box-shadow: 0 10px 18px rgba(15, 23, 42, 0.1);
}

.how-to-list li::before {
  content: counter(how-to);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  margin-bottom: 12px;
  border-radius: 50%;
  background: #e94560;
  color: #ffffff;
  font-size: 0.9rem;
  font-weight: 900;
}

.canvas-card {
  --card-accent: #ff5ba7;
  appearance: none;
  width: 100%;
  min-width: 0;
  border: 2px dashed var(--card-accent);
  border-radius: 14px;
  background: #ffffff;
  padding: 12px;
  color: #172033;
  cursor: pointer;
  box-shadow: 0 10px 18px rgba(15, 23, 42, 0.15);
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.canvas-card:hover,
.canvas-card:focus-visible {
  background: #fbfdff;
  box-shadow: 0 16px 28px rgba(15, 23, 42, 0.2);
  transform: translateY(-3px);
  outline: none;
}

.thumb-wrap {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 4px;
  background: #fff;
}

.thumb-wrap img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.canvas-title {
  display: block;
  min-height: 24px;
  margin-top: 8px;
  color: #172033;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
}

.theme-pink { --card-accent: #ff5ba7; }
.theme-blue { --card-accent: #0ea5ff; }
.theme-green { --card-accent: #10b981; }
.theme-orange { --card-accent: #f59e0b; }
.theme-violet { --card-accent: #8b5cf6; }
.theme-cyan { --card-accent: #06b6d4; }
.theme-lime { --card-accent: #84cc16; }
.theme-amber { --card-accent: #f97316; }

/* ── MAIN LAYOUT ── */
.layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 20px;
  align-items: start;
}

/* ── PANEL ── */
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel h3 {
  font-family: 'Fredoka One', cursive;
  font-size: 1rem;
  color: var(--gold);
  letter-spacing: 0.5px;
}

.back-home-btn {
  width: 100%;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-family: 'Nunito', sans-serif;
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.back-home-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--gold);
}

/* ── UPLOAD ── */
#uploadSection {
  grid-column: 1 / -1;
}

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: 16px;
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
  background: var(--card);
  position: relative;
  overflow: hidden;
}

.upload-zone::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(233,69,96,0.05), transparent 70%);
  opacity: 0;
  transition: opacity 0.3s;
}

.upload-zone:hover { border-color: var(--accent); }
.upload-zone:hover::before { opacity: 1; }
.upload-zone.drag-over { border-color: var(--accent); background: rgba(233,69,96,0.08); transform: scale(1.01); }

.upload-icon { font-size: 3.5rem; margin-bottom: 12px; display: block; }
.upload-zone h2 { font-family: 'Fredoka One', cursive; font-size: 1.5rem; color: var(--text); margin-bottom: 6px; }
.upload-zone p { color: var(--muted); font-size: 0.88rem; }

.upload-hint {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.hint-chip {
  padding: 4px 12px;
  border-radius: 20px;
  background: var(--accent2);
  font-size: 0.75rem;
  color: #a0c4ff;
  font-weight: 600;
}

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

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(233,69,96,0.5);
  cursor: pointer;
}

/* ── PROCESS BUTTON ── */
.process-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #c23152);
  color: white;
  font-family: 'Fredoka One', cursive;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 20px rgba(233,69,96,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.process-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(233,69,96,0.4); }
.process-btn:active { transform: translateY(0); }
.process-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ── PROGRESS ── */
.progress-wrap {
  background: var(--border);
  border-radius: 8px;
  height: 6px;
  overflow: hidden;
  display: none;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  width: 0%;
  transition: width 0.3s;
  border-radius: 8px;
}

.status-text {
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
  min-height: 18px;
}

/* ── CANVAS AREA ── */
.canvas-area {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.65);
  background: #e2e8f0;
  height: calc(100vh - 48px);
  min-height: 520px;
  cursor: default;
  touch-action: none;
}

.canvas-area.has-image {
  max-width: 100%;
}

.canvas-area.is-dragging {
  cursor: default;
}

.canvas-stack {
  position: absolute;
  top: 50%;
  left: 50%;
  display: block;
  transform-origin: center center;
  background-image:
    linear-gradient(45deg, #ccc 25%, transparent 25%),
    linear-gradient(-45deg, #ccc 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #ccc 75%),
    linear-gradient(-45deg, transparent 75%, #ccc 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
  background-color: white;
  box-shadow: 0 20px 25px -5px rgba(0,0,0,0.18), 0 10px 10px -5px rgba(0,0,0,0.12);
  border-radius: 8px;
  overflow: hidden;
  cursor: default;
  line-height: 0;
}

.canvas-area.is-dragging .canvas-stack {
  cursor: default;
}

.canvas-stack canvas {
  position: absolute;
  top: 0; left: 0;
  /* no width/height 100% — let canvases be their natural pixel size */
}

/* Layer 1: original image */
#imageCanvas {
  z-index: 1;
  pointer-events: none;
}

/* Layer 2: color fill — transparent, drawn over image */
#colorCanvas {
  z-index: 2;
  pointer-events: none;
}

/* Layer 3: hit-test canvas — fully invisible, captures all clicks */
#hitCanvas {
  z-index: 3;
  cursor: default;
  opacity: 0;
}

.canvas-area.is-dragging #hitCanvas {
  cursor: default;
}

.zoom-controls {
  position: absolute;
  right: 12px;
  top: 12px;
  z-index: 8;
  display: none;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.18);
  backdrop-filter: blur(8px);
}

.canvas-area.has-image .zoom-controls {
  display: flex;
}

.zoom-controls button {
  min-width: 36px;
  height: 34px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: white;
  color: #334155;
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  cursor: pointer;
}

.zoom-controls button:hover {
  background: #f1f5f9;
}

#zoomLabel {
  min-width: 58px;
  font-size: 0.78rem;
}

.canvas-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  color: var(--muted);
  gap: 12px;
}

.canvas-placeholder span { font-size: 3rem; }
.canvas-placeholder p { font-size: 0.88rem; }

/* ── COLOR PALETTE ── */
.colors-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
}

.color-btn {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

.color-btn:hover { transform: scale(1.12); }
.color-btn.active {
  border-color: white;
  transform: scale(1.15);
  box-shadow: 0 0 12px rgba(255,255,255,0.4);
}

.custom-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.custom-wrap label {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 700;
  flex: 1;
}

.custom-wrap input[type="color"] {
  width: 40px; height: 30px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  background: none;
}

/* ── TOOL BUTTONS ── */
.tool-btn {
  width: 100%;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--text);
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tool-btn:hover { background: rgba(255,255,255,0.06); border-color: var(--accent); }
.tool-btn.active { background: rgba(233,69,96,0.15); border-color: var(--accent); color: #ff8fa3; }

/* ── STATS ── */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat-box {
  background: var(--surface);
  border-radius: 10px;
  padding: 10px;
  text-align: center;
}

.stat-box .val {
  font-family: 'Fredoka One', cursive;
  font-size: 1.4rem;
  color: var(--gold);
}

.stat-box .lbl {
  font-size: 0.68rem;
  color: var(--muted);
  margin-top: 2px;
}

/* ── TOOLTIP ── */
.tooltip {
  position: fixed;
  background: rgba(0,0,0,0.85);
  color: white;
  padding: 5px 12px;
  border-radius: 8px;
  font-size: 0.75rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 1000;
  border: 1px solid var(--border);
}

.tooltip.show { opacity: 1; }

/* ── LOADING OVERLAY ── */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15,14,23,0.85);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
  z-index: 10;
  border-radius: 16px;
}

.loading-overlay.show { display: flex; }

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

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

.loading-overlay p {
  color: var(--muted);
  font-size: 0.88rem;
}

/* ── HIDDEN ── */
.hidden { display: none !important; }

/* ── EXPORT ── */
.export-btn {
  width: 100%;
  padding: 10px;
  border-radius: 10px;
  border: 1.5px solid var(--gold);
  background: rgba(245,166,35,0.1);
  color: var(--gold);
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 8px;
}

.export-btn:hover { background: rgba(245,166,35,0.2); }

/* ── OPACITY PREVIEW ── */
.current-color-preview {
  width: 100%;
  height: 32px;
  border-radius: 8px;
  border: 2px solid var(--border);
  transition: background 0.2s;
  box-shadow: inset 0 0 8px rgba(0,0,0,0.3);
}

@media (max-width: 768px) {
  .container { padding: 20px 14px; }
  .home-hero { margin-bottom: 24px; }
  .home-intro { font-size: 0.98rem; }
  .gallery-section,
  .how-to-section { margin-top: 26px; }
  .canvas-gallery {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
  }
  .how-to-list {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .how-to-list li { min-height: 0; }
  .canvas-card { padding: 8px; border-radius: 12px; }
  .canvas-title { font-size: 0.88rem; min-height: 22px; }
  .layout { grid-template-columns: 1fr; }
  #uploadSection { grid-column: 1; }
}
