/* ==========================================================================
   Eid Adha Card Generator — Arabic Islamic Design
   ========================================================================== */

:root {
  --color-bg: #f7f1e6;
  --color-bg-2: #efe5d0;
  --color-ink: #1f1a14;
  --color-muted: #6b5d49;
  --color-accent: #b8860b;
  --color-accent-soft: #d4af37;
  --color-emerald: #0e6b54;
  --color-emerald-deep: #084a3a;
  --color-royal: #2c1a4f;
  --color-cream: #fff8e7;
  --color-line: #d8c79c;

  --shadow-card: 0 30px 80px -20px rgba(60, 40, 10, 0.35),
                 0 10px 30px -10px rgba(60, 40, 10, 0.2);
  --shadow-soft: 0 6px 20px -8px rgba(60, 40, 10, 0.25);

  --radius: 16px;
  --radius-sm: 10px;

  --font-display: "Aref Ruqaa", "Amiri", serif;
  --font-body: "Cairo", "Reem Kufi", system-ui, sans-serif;
  --font-quran: "Amiri", "Lateef", serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-body);
  color: var(--color-ink);
  background: var(--color-bg);
  background-image:
    radial-gradient(circle at 20% 10%, rgba(212, 175, 55, 0.12) 0, transparent 40%),
    radial-gradient(circle at 80% 90%, rgba(14, 107, 84, 0.08) 0, transparent 40%),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='80' height='80' viewBox='0 0 80 80'><g fill='none' stroke='%23b8860b' stroke-opacity='0.06' stroke-width='1'><path d='M40 5l8 16 18 2-13 13 3 18-16-9-16 9 3-18-13-13 18-2z'/><circle cx='40' cy='40' r='30'/></g></svg>");
  background-attachment: fixed;
  min-height: 100vh;
  line-height: 1.55;
}

/* -------------------------- Layout (hero = content section) -------------------------- */
.container.hero {
  max-width: 1180px;
  margin: 0 auto;
  padding: 40px 24px 60px;
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 36px;
  align-items: start;
}

@media (max-width: 980px) {
  .container.hero { grid-template-columns: 1fr; gap: 28px; }
}

/* -------------------------- Form Panel -------------------------- */
.panel-card {
  background: linear-gradient(180deg, #fffdf6, #fbf4e3);
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-soft);
  position: sticky;
  top: 24px;
}

.panel-heading {
  text-align: center;
  margin: 0 0 22px;
  padding-bottom: 16px;
  border-bottom: 1px dashed var(--color-line);
}
.brand-title {
  font-family: var(--font-display);
  font-size: 24px;
  color: var(--color-accent);
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  letter-spacing: 0.5px;
}
.brand-sub {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--color-muted);
}
.title-deco { color: var(--color-accent-soft); font-size: 18px; opacity: 0.85; }

.field { margin-bottom: 18px; }
.field label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
  color: var(--color-ink);
  font-size: 14px;
}
.field-hint { margin: 6px 2px 0; font-size: 12px; color: var(--color-muted); }

input[type="text"] {
  width: 100%;
  padding: 12px 14px;
  font-family: var(--font-body);
  font-size: 15px;
  border: 1.5px solid var(--color-line);
  border-radius: var(--radius-sm);
  background: #fffaf0;
  color: var(--color-ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[type="text"]:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.22);
}

/* File drop */
.file-drop {
  position: relative;
  border: 2px dashed var(--color-line);
  border-radius: var(--radius-sm);
  background: #fffaf0;
  padding: 18px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.file-drop:hover { border-color: var(--color-accent); background: #fff5dd; }
.file-drop.is-dragging { border-color: var(--color-accent); background: #fff1cf; }
.file-drop input[type="file"] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer;
}
.file-drop-content {
  display: flex; flex-direction: column; align-items: center;
  gap: 6px; color: var(--color-muted);
}
.file-drop-content svg { color: var(--color-accent); }
.file-drop-title { font-weight: 600; color: var(--color-ink); font-size: 14px; }
.file-drop-hint { font-size: 12px; color: var(--color-muted); }

.file-preview {
  display: flex; align-items: center; justify-content: center; position: relative;
}
.file-preview img {
  max-width: 110px;
  max-height: 110px;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
  padding: 6px;
  box-shadow: var(--shadow-soft);
}

/* Template grid */
.template-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.template-thumb {
  appearance: none;
  background: #fffaf0;
  border: 2px solid var(--color-line);
  border-radius: var(--radius-sm);
  padding: 8px;
  cursor: pointer;
  display: flex; flex-direction: column; gap: 6px; align-items: stretch;
  font-family: var(--font-body);
  color: var(--color-ink);
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.template-thumb:hover { transform: translateY(-2px); box-shadow: var(--shadow-soft); }
.template-thumb.is-active {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.25);
}
.thumb-preview {
  height: 60px;
  border-radius: 6px;
  position: relative;
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.thumb-sheep { font-size: 24px; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.25)); }
.thumb-label { font-size: 12px; font-weight: 600; text-align: center; color: var(--color-muted); }

.thumb-1 { background: radial-gradient(circle at 50% 50%, #fff8e7, #f0d97c 65%, #b8860b); }
.thumb-2 { background: radial-gradient(circle at 50% 50%, #d8f0e3, #0e6b54 65%, #084a3a); }
.thumb-3 { background: radial-gradient(circle at 50% 50%, #e8dffb, #2c1a4f 70%, #14092a); }
.thumb-4 {
  background:
    linear-gradient(135deg, #cfe2ee 0%, #ffffff 50%, #e3a35a 100%);
}

/* Primary button */
.primary-btn {
  width: 100%;
  margin-top: 8px;
  padding: 14px 18px;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  color: #fff8e7;
  background: linear-gradient(180deg, #c8961b, #8c6a10);
  border: 1px solid #6e530a;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  box-shadow: 0 6px 14px -4px rgba(140, 106, 16, 0.55), inset 0 1px 0 rgba(255,255,255,0.25);
  transition: transform 0.1s, box-shadow 0.15s;
}
.primary-btn:hover { transform: translateY(-1px); box-shadow: 0 10px 22px -6px rgba(140, 106, 16, 0.6); }
.primary-btn:active { transform: translateY(0); }
.primary-btn:disabled {
  opacity: 0.72;
  cursor: not-allowed;
  transform: none;
  box-shadow: 0 4px 10px -4px rgba(140, 106, 16, 0.35);
}
.primary-btn:disabled:hover { transform: none; }

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 248, 231, 0.35);
  border-top-color: #fff8e7;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: -3px;
  margin-left: 6px;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* -------------------------- Preview Panel -------------------------- */
.preview-panel {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.card-stage { width: 100%; display: flex; justify-content: center; }
.stage-hint { color: var(--color-muted); font-size: 14px; text-align: center; margin: 0; }

/* -------------------------- Card (1:1 square) -------------------------- */
.card {
  width: 600px;
  max-width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  box-shadow: var(--shadow-card);
  isolation: isolate;
  direction: rtl;
  font-family: var(--font-display);
}

/* Frame layer (SVG mosaic tile frame) */
.card .frame-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}
.card .frame-layer img,
.card .frame-layer svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Background base of the card (inside the frame) */
.card .card-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
}

/* Content area inside the frame (single-row mosaic = 60/600 = 10%) */
.card .card-inner {
  position: absolute;
  inset: 12%;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2% 2%;
  gap: 14px;
}

.card .eid-greeting {
  font-family: var(--font-display);
  font-size: 40px;
  line-height: 1.3;
  margin: 0;
  letter-spacing: 0.5px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.15);
  white-space: nowrap;
}
.card .eid-subtitle {
  font-family: var(--font-quran);
  font-size: 18px;
  margin: 0;
  opacity: 0.88;
  line-height: 1.5;
  max-width: 92%;
}

.card .user-image-wrap {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background: rgba(255,255,255,0.4);
  flex-shrink: 0;
}
.card .user-image-wrap img {
  width: 100%; height: 100%; object-fit: cover;
}
.card .user-image-bg {
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}
.card .user-image-wrap.is-empty {
  background:
    repeating-linear-gradient(45deg,
      rgba(0,0,0,0.04) 0,
      rgba(0,0,0,0.04) 6px,
      transparent 6px,
      transparent 12px),
    rgba(255,255,255,0.55);
}
.card .placeholder-text {
  font-family: var(--font-body);
  font-size: 16px;
  font-weight: 600;
  opacity: 0.55;
}

.card .from-block {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 6px 20px;
  border-radius: 12px;
  max-width: 96%;
  flex-shrink: 0;
}
.card .from-label {
  font-family: var(--font-body);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0;
  opacity: 0.8;
  flex-shrink: 0;
}
.card .name-text {
  font-family: var(--font-display);
  font-size: 32px;
  margin: 0;
  padding: 0;
  line-height: 1.2;
  white-space: nowrap;
  background: transparent !important;
  border: none !important;
}

.card .sheep-row {
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.card .sheep-row svg { width: 64px; height: 64px; }

.card .ornament-line {
  width: 50%;
  height: 12px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 12'><g fill='none' stroke='%23000' stroke-opacity='0.55' stroke-width='1'><path d='M10 6h180'/><path d='M100 1l4 5-4 5-4-5z' fill='%23000' fill-opacity='0.45'/><circle cx='60' cy='6' r='2'/><circle cx='140' cy='6' r='2'/></g></svg>");
  background-repeat: no-repeat;
  background-position: center;
  opacity: 0.7;
}

/* ===== Template 1: Gold Classic ===== */
.card[data-template="1"] .card-bg {
  background:
    radial-gradient(ellipse at 50% 30%, #fff8e7 0%, #f6e7b8 55%, #e8c870 100%);
}
.card[data-template="1"] {
  color: #3a2a08;
}
.card[data-template="1"] .from-block {
  background: rgba(255, 248, 231, 0.7);
  border: 1px solid rgba(58, 42, 8, 0.3);
}
.card[data-template="1"] .user-image-wrap {
  border: 6px solid #b8860b;
  outline: 4px solid #fff8e7;
}

/* ===== Template 2: Emerald ===== */
.card[data-template="2"] .card-bg {
  background:
    radial-gradient(ellipse at 50% 30%, #d8f0e3 0%, #5fa68c 50%, #0e6b54 100%);
}
.card[data-template="2"] { color: #fff8e7; }
.card[data-template="2"] .from-block {
  background: rgba(255, 248, 231, 0.18);
  border: 1px solid rgba(212, 175, 55, 0.7);
}
.card[data-template="2"] .name-text { color: #fff8e7; }
.card[data-template="2"] .user-image-wrap {
  border: 6px solid #d4af37;
  outline: 4px solid rgba(255, 248, 231, 0.4);
}

/* ===== Template 3: Royal Purple ===== */
.card[data-template="3"] .card-bg {
  background:
    radial-gradient(ellipse at 50% 30%, #d8c2ff 0%, #5c3a9e 45%, #2c1a4f 100%);
}
.card[data-template="3"] { color: #fff8e7; }
.card[data-template="3"] .from-block {
  background: rgba(212, 175, 55, 0.18);
  border: 1px solid rgba(212, 175, 55, 0.8);
}
.card[data-template="3"] .name-text { color: #ffe9a3; }
.card[data-template="3"] .user-image-wrap {
  border: 6px solid #d4af37;
  outline: 4px solid rgba(212, 175, 55, 0.4);
}
.card[data-template="3"] .eid-greeting { color: #ffe9a3; }

/* ===== Template 4: Desert/Light Mosaic (closest to user reference) ===== */
.card[data-template="4"] .card-bg {
  background:
    radial-gradient(ellipse at 50% 40%, #ffffff 0%, #f0f7fb 55%, #dceaf3 100%);
}
.card[data-template="4"] { color: #1c2e3e; }
.card[data-template="4"] .from-block {
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(28, 46, 62, 0.2);
}
.card[data-template="4"] .name-text { color: #1c2e3e; }
.card[data-template="4"] .user-image-wrap {
  border: 6px solid #5b8db3;
  outline: 4px solid #ffffff;
}
.card[data-template="4"] .ornament-line { filter: brightness(0.6); }

/* -------------------------- Footer -------------------------- */
.site-footer {
  text-align: center;
  padding: 20px;
  color: var(--color-muted);
  font-size: 14px;
}

/* -------------------------- Responsive Card Scaling -------------------------- */
@media (max-width: 640px) {
  .card { width: 100%; }
  .card .eid-greeting { font-size: 28px; }
  .card .name-text { font-size: 22px; }
  .card .message-text { font-size: 15px; }
  .card .user-image-wrap { width: 90px; height: 90px; }
  .card .sheep-row svg { width: 42px; height: 42px; }
}
