/*
 * Na3wa — Islamic Obituary Card Generator
 * assets/css/style.css
 * Custom styles on top of Tailwind CSS (play CDN).
 */

/* ─── CSS Variables ────────────────────────────────────────────────────────── */
:root {
    --bg:         #0c0c0f;
    --surface:    #161619;
    --surface-2:  #1e1e23;
    --border:     #2a2a32;
    --border-2:   #3a3a45;
    --gold:       #c8a84b;
    --gold-light: #e0c875;
    --gold-dark:  #9a7830;
    --green:      #2a7a4a;
    --green-light:#3a9a5c;
    --text-1:     #f5f5f7;
    --text-2:     #a0a0b0;
    --text-3:     #6a6a7a;
    --danger:     #e05050;
    --radius:     16px;
    --radius-sm:  10px;
    --shadow:     0 4px 24px rgba(0,0,0,.5);
    --font-ar:    'Cairo', 'Tajawal', sans-serif;
    --font-en:    'Inter', sans-serif;
}

/* ─── Base ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html {
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    background: var(--bg);
    color: var(--text-1);
    font-family: var(--font-ar);
    min-height: 100dvh;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
}

[dir="ltr"] body,
[dir="ltr"] * {
    font-family: var(--font-en);
}

/* ─── Alpine.js Cloak ───────────────────────────────────────────────────────── */
[x-cloak] { display: none !important; }

/* ─── App Shell ─────────────────────────────────────────────────────────────── */
#app {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    max-width: 480px;
    margin: 0 auto;
    position: relative;
    background: var(--bg);
}

/* Screen transitions */
.screen-enter {
    animation: fadeSlideIn 0.25s ease-out forwards;
}
@keyframes fadeSlideIn {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ─── Wizard Header ─────────────────────────────────────────────────────────── */
.wiz-header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px 10px;
}

.wiz-header__top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.wiz-logo {
    font-size: 18px;
    font-weight: 700;
    color: var(--gold);
    letter-spacing: 0.01em;
}

/* Progress dots */
.step-dots {
    display: flex;
    gap: 6px;
    align-items: center;
}
.step-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--border-2);
    transition: all 0.3s ease;
}
.step-dot.active {
    background: var(--gold);
    width: 22px;
    border-radius: 4px;
}
.step-dot.done {
    background: var(--green);
}

/* Progress bar */
.progress-bar {
    height: 3px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 8px;
}
.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--gold-dark), var(--gold));
    border-radius: 2px;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Save status badge */
.save-badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 20px;
    transition: all 0.3s ease;
}
.save-badge.saving { background: #2a2a20; color: var(--gold); }
.save-badge.saved  { background: #1a2a1a; color: var(--green-light); }

/* ─── Wizard Content ────────────────────────────────────────────────────────── */
.wiz-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px 16px;
    -webkit-overflow-scrolling: touch;
}

.step-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-1);
    margin-bottom: 4px;
}
.step-subtitle {
    font-size: 14px;
    color: var(--text-2);
    margin-bottom: 24px;
}

/* ─── Form Fields ───────────────────────────────────────────────────────────── */
.field-group {
    margin-bottom: 20px;
}

.field-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-2);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.field-input {
    width: 100%;
    min-height: 52px;
    background: var(--surface-2);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-1);
    font-size: 16px; /* 16px prevents iOS zoom */
    font-family: inherit;
    padding: 14px 16px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    -webkit-appearance: none;
}
.field-input::placeholder { color: var(--text-3); }
.field-input:focus {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(200,168,75,.15);
}
.field-input.textarea {
    min-height: 88px;
    resize: vertical;
}

/* Gender toggle */
.gender-toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.gender-btn {
    min-height: 52px;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--border);
    background: var(--surface-2);
    color: var(--text-2);
    font-size: 16px;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.gender-btn.active {
    border-color: var(--gold);
    background: rgba(200,168,75,.12);
    color: var(--gold);
}
.gender-btn:active { transform: scale(0.97); }

/* Toggle switch */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface-2);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    cursor: pointer;
    gap: 12px;
}
.toggle-row:active { opacity: 0.85; }
.toggle-text {
    font-size: 15px;
    color: var(--text-1);
    flex: 1;
    line-height: 1.4;
}
.toggle-switch {
    position: relative;
    width: 44px;
    height: 26px;
    flex-shrink: 0;
}
.toggle-switch input {
    position: absolute;
    opacity: 0;
    width: 0; height: 0;
}
.toggle-track {
    display: block;
    width: 44px;
    height: 26px;
    background: var(--border-2);
    border-radius: 13px;
    transition: background 0.2s;
    position: relative;
}
.toggle-track::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
input:checked + .toggle-track { background: var(--green); }
input:checked + .toggle-track::after { transform: translateX(18px); }

/* Optional badge */
.optional-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 20px;
    background: var(--surface-2);
    border: 1px solid var(--border-2);
    color: var(--text-3);
    margin-inline-start: 8px;
    text-transform: uppercase;
}

/* Section divider inside steps */
.section-divider {
    margin: 24px 0 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    font-weight: 700;
    color: var(--gold);
    text-transform: uppercase;
    letter-spacing: 0.07em;
    display: flex;
    align-items: center;
    gap: 8px;
}
.section-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* ─── Wizard Footer ─────────────────────────────────────────────────────────── */
.wiz-footer {
    position: sticky;
    bottom: 0;
    z-index: 20;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 12px 16px;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 10px;
    align-items: center;
}
.wiz-footer.first-step {
    grid-template-columns: 1fr;
}

/* ─── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 50px;
    padding: 0 20px;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
    background: linear-gradient(135deg, var(--gold-dark), var(--gold));
    color: #0c0c0f;
    box-shadow: 0 4px 16px rgba(200,168,75,.25);
}
.btn-primary:hover { box-shadow: 0 4px 20px rgba(200,168,75,.4); }
.btn-primary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-ghost {
    background: var(--surface-2);
    color: var(--text-2);
    border: 1.5px solid var(--border);
}
.btn-ghost:hover { border-color: var(--border-2); color: var(--text-1); }

.btn-green {
    background: linear-gradient(135deg, var(--green), var(--green-light));
    color: white;
}

.btn-danger {
    background: transparent;
    color: var(--danger);
    border: 1.5px solid var(--danger);
}
.btn-danger:hover { background: rgba(224,80,80,.1); }

.btn-icon {
    min-height: 44px;
    min-width: 44px;
    padding: 0;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text-2);
    border: 1.5px solid var(--border);
    font-size: 18px;
}
.btn-icon:hover { color: var(--text-1); border-color: var(--border-2); }
.btn-icon:disabled { opacity: 0.3; cursor: not-allowed; transform: none; }

.btn-full { width: 100%; }

/* ─── Template Cards (Step 1) ───────────────────────────────────────────────── */
.template-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.template-card {
    position: relative;
    aspect-ratio: 1;
    border-radius: var(--radius);
    border: 2.5px solid transparent;
    cursor: pointer;
    overflow: hidden;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}
.template-card:active { transform: scale(0.97); }
.template-card.selected {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(200,168,75,.3), var(--shadow);
}
.template-card__thumb {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px;
    text-align: center;
}
.template-card__name {
    font-size: 13px;
    font-weight: 700;
    margin-top: 8px;
    letter-spacing: 0.02em;
}
.template-card__verse {
    font-size: 10px;
    opacity: 0.7;
    line-height: 1.6;
    margin-top: 4px;
}
.template-card__check {
    position: absolute;
    top: 8px;
    inset-inline-end: 8px;
    width: 24px;
    height: 24px;
    background: var(--gold);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    color: #0c0c0f;
    font-weight: 900;
    opacity: 0;
    transition: opacity 0.2s;
}
.template-card.selected .template-card__check { opacity: 1; }

/* Template Themes */
.tmpl-dark-classic {
    background: linear-gradient(160deg, #0a0a14 0%, #1a1630 50%, #0a0a14 100%);
    --t-border: #c8a84b;
    --t-text: #fff;
    --t-accent: #c8a84b;
}
.tmpl-green-islamic {
    background: linear-gradient(160deg, #041a0e 0%, #0a2a18 50%, #041a0e 100%);
    --t-border: #c8a84b;
    --t-text: #fff;
    --t-accent: #6abf8a;
}
.tmpl-white-marble {
    background: linear-gradient(160deg, #f5ede0 0%, #faf4ec 50%, #f0e8d8 100%);
    --t-border: #3a2008;
    --t-text: #1a0a00;
    --t-accent: #8a4a10;
}
.tmpl-royal-blue {
    background: linear-gradient(160deg, #060f24 0%, #0f1e40 50%, #060f24 100%);
    --t-border: #a0c0e8;
    --t-text: #fff;
    --t-accent: #90b8e0;
}

/* Template inner border decorative frame */
.tmpl-frame {
    width: 80%;
    height: 80%;
    border: 1.5px solid var(--t-border, #c8a84b);
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
}
.tmpl-frame::before {
    content: '';
    position: absolute;
    inset: 4px;
    border: 0.5px solid var(--t-border, #c8a84b);
    opacity: 0.5;
    border-radius: 2px;
}

/* ─── Welcome Screen ────────────────────────────────────────────────────────── */
.welcome-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px 24px;
    text-align: center;
    gap: 0;
}

.welcome-logo {
    font-size: 48px;
    line-height: 1;
    margin-bottom: 8px;
}

.welcome-title {
    font-size: 28px;
    font-weight: 900;
    color: var(--gold);
    margin-bottom: 8px;
}

.welcome-subtitle {
    font-size: 15px;
    color: var(--text-2);
    max-width: 280px;
    line-height: 1.6;
    margin-bottom: 40px;
}

.welcome-draft-box {
    width: 100%;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.welcome-draft-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--gold);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.welcome-draft-name {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-1);
}

.welcome-actions {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.welcome-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-3);
    font-size: 12px;
    margin: 4px 0;
}
.welcome-divider::before,
.welcome-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* ─── Na3wa Card ────────────────────────────────────────────────────────────── */
.card-wrapper {
    width: 100%;
    padding: 16px;
}

#na3wa-card {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    box-shadow: 0 8px 40px rgba(0,0,0,.6);
}

/* Card theme backgrounds */
#na3wa-card.tmpl-dark-classic {
    background: linear-gradient(160deg, #0a0a14 0%, #1a1630 50%, #0a0a14 100%);
    --card-border: #c8a84b;
    --card-text-1: #ffffff;
    --card-text-2: #e8e0c0;
    --card-accent: #c8a84b;
    --card-dua: #a09060;
}
#na3wa-card.tmpl-green-islamic {
    background: linear-gradient(160deg, #041a0e 0%, #0a2a18 50%, #041a0e 100%);
    --card-border: #c8a84b;
    --card-text-1: #ffffff;
    --card-text-2: #d0e8d8;
    --card-accent: #c8a84b;
    --card-dua: #80b890;
}
#na3wa-card.tmpl-white-marble {
    background: linear-gradient(160deg, #f5ede0 0%, #faf4ec 50%, #f0e8d8 100%);
    --card-border: #3a2008;
    --card-text-1: #1a0a00;
    --card-text-2: #4a3020;
    --card-accent: #8a4a10;
    --card-dua: #7a6050;
}
#na3wa-card.tmpl-royal-blue {
    background: linear-gradient(160deg, #060f24 0%, #0f1e40 50%, #060f24 100%);
    --card-border: #90b8e0;
    --card-text-1: #ffffff;
    --card-text-2: #c0d8f0;
    --card-accent: #90b8e0;
    --card-dua: #6090c0;
}

/* Outer decorative frame */
.card-outer-frame {
    position: absolute;
    inset: 10px;
    border: 1.5px solid var(--card-border, #c8a84b);
    border-radius: 6px;
    pointer-events: none;
    z-index: 1;
}
.card-outer-frame::before {
    content: '';
    position: absolute;
    inset: 5px;
    border: 0.5px solid var(--card-border, #c8a84b);
    border-radius: 3px;
    opacity: 0.5;
}

/* Corner ornaments */
.card-corner {
    position: absolute;
    width: 20px;
    height: 20px;
    z-index: 2;
}
.card-corner svg { fill: var(--card-border, #c8a84b); }
.card-corner.tl { top: 6px; left: 6px; }
.card-corner.tr { top: 6px; right: 6px; transform: scaleX(-1); }
.card-corner.bl { bottom: 6px; left: 6px; transform: scaleY(-1); }
.card-corner.br { bottom: 6px; right: 6px; transform: scale(-1,-1); }

/* Card content area */
.card-body {
    position: absolute;
    inset: 22px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 0;
    z-index: 3;
    overflow: hidden;
    padding: 8px 10px;
}

.card-bismillah {
    font-size: clamp(7px, 1.8vw, 11px);
    color: var(--card-accent, #c8a84b);
    opacity: 0.8;
    margin-bottom: 2px;
    font-weight: 400;
    letter-spacing: 0.02em;
}
.card-verse {
    font-size: clamp(8px, 2vw, 12px);
    color: var(--card-accent, #c8a84b);
    font-weight: 600;
    margin-bottom: 6px;
    letter-spacing: 0.03em;
}
.card-title {
    font-size: clamp(14px, 4vw, 22px);
    font-weight: 900;
    color: var(--card-text-1, #fff);
    letter-spacing: 0.02em;
    line-height: 1.2;
    margin-bottom: 4px;
}
.card-ornament {
    color: var(--card-accent, #c8a84b);
    font-size: clamp(10px, 2.5vw, 14px);
    margin: 4px 0;
    letter-spacing: 0.3em;
}
.card-divider {
    width: 60%;
    height: 1px;
    background: var(--card-border, #c8a84b);
    margin: 4px auto;
    opacity: 0.5;
}
.card-announces {
    font-size: clamp(9px, 2.2vw, 13px);
    color: var(--card-text-2, #e8e0c0);
    margin-bottom: 2px;
}
.card-deceased-name {
    font-size: clamp(16px, 5vw, 28px);
    font-weight: 900;
    color: var(--card-text-1, #fff);
    line-height: 1.2;
    margin: 4px 0 8px;
}
.card-section {
    width: 100%;
    text-align: start;
    font-size: clamp(8px, 2vw, 11px);
    color: var(--card-text-2, #e8e0c0);
    line-height: 1.7;
    padding: 4px 0;
}
.card-section-label {
    color: var(--card-accent, #c8a84b);
    font-weight: 700;
    display: inline;
}
.card-dua {
    font-size: clamp(7px, 1.7vw, 10px);
    color: var(--card-dua, #a09060);
    font-style: italic;
    text-align: center;
    margin-top: 4px;
    line-height: 1.5;
    padding: 0 8px;
}

/* ─── Editor Screen ─────────────────────────────────────────────────────────── */
.editor-toolbar {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 10px 16px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-shrink: 0;
}
.editor-toolbar::-webkit-scrollbar { display: none; }

.tool-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    border-radius: 8px;
    background: var(--surface-2);
    border: 1.5px solid var(--border);
    color: var(--text-2);
    font-size: 15px;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.15s;
    padding: 0 8px;
    gap: 4px;
    font-family: inherit;
    font-weight: 600;
    white-space: nowrap;
}
.tool-btn:active { transform: scale(0.95); }
.tool-btn.active { background: rgba(200,168,75,.15); border-color: var(--gold); color: var(--gold); }

.editor-engine-notice {
    background: linear-gradient(135deg, #1a1506, #2a2010);
    border: 1.5px solid var(--gold-dark);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin: 0 16px 16px;
    display: flex;
    gap: 12px;
    align-items: flex-start;
}
.engine-notice-icon {
    font-size: 20px;
    flex-shrink: 0;
    margin-top: 1px;
}
.engine-notice-text {
    font-size: 13px;
    color: var(--gold-light);
    line-height: 1.5;
}
.engine-notice-title {
    font-weight: 700;
    margin-bottom: 2px;
    color: var(--gold);
}

/* ─── Preview / Export Screen ───────────────────────────────────────────────── */
.preview-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.preview-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px;
}

.export-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

/* ─── App Header Bar (Editor/Preview) ──────────────────────────────────────── */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
    gap: 8px;
}
.app-header__title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-1);
}
.app-header__actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

/* ─── Utility ───────────────────────────────────────────────────────────────── */
.text-gold  { color: var(--gold); }
.text-green { color: var(--green-light); }
.text-muted { color: var(--text-2); }
.text-faint { color: var(--text-3); }

.divider {
    height: 1px;
    background: var(--border);
    margin: 8px 0;
}

/* Spinner */
@keyframes spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}
.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,.3);
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* ─── Language switch link ──────────────────────────────────────────────────── */
.lang-link {
    font-size: 12px;
    color: var(--text-3);
    text-decoration: none;
    padding: 4px 8px;
    border-radius: 20px;
    border: 1px solid var(--border);
    transition: all 0.2s;
}
.lang-link:hover { color: var(--gold); border-color: var(--gold-dark); }

/* ─── Scrollbar (desktop) ───────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 2px; }

/* ─── Fabric.js Canvas Container ────────────────────────────────────────────── */
#fabric-container {
    width: 100%;
    padding: 12px;
    flex: 1;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    overflow-y: auto;
}

/* The <canvas> element itself (Fabric replaces the DOM canvas). */
#na3wa-canvas {
    display: block;
    border-radius: 12px;
    box-shadow: 0 8px 40px rgba(0,0,0,.6);
    /* Fabric's upper-canvas is absolute-positioned over this. */
}

/* Fabric.js upper-canvas (interaction layer) inherits the border-radius. */
.upper-canvas {
    border-radius: 12px !important;
}

/* Canvas wrapper that Fabric injects */
.canvas-container {
    border-radius: 12px;
    box-shadow: 0 8px 40px rgba(0,0,0,.6);
}

/* ─── Fabric selection handles style override ──────────────────────────────── */
/* Handled by Fabric internally; just ensure touch targets are big enough. */
