/* ══════════════════════════════════════
   معايدة الامداد — Safaa Palette
   Mobile-First Optimized
   ══════════════════════════════════════ */

:root {
    --navy: #1A3A6C;
    --navy-dark: #0E2248;
    --gold: #C4943A;
    --gold-hover: #a67a2e;
    --gold-bg: #F5EDD6;
    --surface: #FFFFFF;
    --surface-secondary: #EBEEf4;
    --border: #CDD5E0;
    --text-primary: #0C1929;
    --text-secondary: #374151;
    --text-muted: #6B7A8D;
    --bg: #F4F6F9;
    --font-body: 'IBM Plex Sans Arabic', sans-serif;
    --font-card: 'Noto Naskh Arabic', 'IBM Plex Sans Arabic', serif;
    --radius: 1rem;
    --radius-lg: 1.5rem;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html {
    scroll-behavior: smooth;
    height: 100%;
}

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text-primary);
    direction: rtl;
    min-height: 100%;
    min-height: 100dvh;
    touch-action: manipulation;
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
}

/* ──── Progress Bar ──── */
.progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    padding: calc(12px + var(--safe-top)) 16px 12px;
    background: rgba(244, 246, 249, 0.95);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    gap: 12px;
}

.progress-track {
    flex: 1;
    height: 4px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--navy), var(--gold));
    border-radius: 4px;
    transition: width 0.4s ease;
}

.btn-back {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-back:active {
    transform: scale(0.95);
    background: var(--surface-secondary);
}

/* ──── Steps ──── */
.step {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 0 20px;
    opacity: 0;
    visibility: hidden;
    transition: none;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
}

.step.active {
    opacity: 1;
    visibility: visible;
}

/* Splash stays centered */
#step-splash {
    align-items: center;
    background: linear-gradient(160deg, var(--navy-dark) 0%, var(--navy) 50%, #1e4a85 100%);
    overflow: hidden;
}

.step-content {
    width: 100%;
    max-width: 480px;
    padding: calc(70px + var(--safe-top)) 0 calc(24px + var(--safe-bottom));
    min-height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.step-title {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--text-primary);
    text-align: center;
    width: 100%;
}

.step-divider {
    width: 48px;
    height: 2px;
    background: var(--gold);
    margin: 12px auto 24px;
    opacity: 0.5;
}

/* ──── Splash Screen ──── */
.splash-container {
    text-align: center;
    padding: 40px 20px;
}

.splash-icon {
    width: 90px;
    height: 90px;
    border-radius: 30%;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 28px;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

.splash-title {
    font-size: 1.8rem;
    font-weight: 800;
    color: white;
    margin-bottom: 12px;
    letter-spacing: -0.5px;
}

.splash-subtitle {
    font-size: 0.9rem;
    color: rgba(255,255,255,0.55);
    line-height: 1.8;
    max-width: 280px;
    margin: 0 auto;
}

.splash-divider {
    width: 48px;
    height: 2px;
    background: var(--gold);
    margin: 28px auto;
    opacity: 0.4;
}

.splash-btn {
    margin-top: 8px;
    font-size: 1.05rem;
    padding: 16px 44px;
}

/* ──── Buttons ──── */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 28px;
    background: var(--navy);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 52px;
    -webkit-appearance: none;
}

.btn-primary:hover {
    background: var(--navy-dark);
}

.btn-primary:active {
    transform: scale(0.97);
}

.btn-primary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 28px;
    background: var(--surface);
    color: var(--text-primary);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 52px;
    -webkit-appearance: none;
}

.btn-secondary:hover {
    background: var(--surface-secondary);
}

.btn-secondary:active {
    transform: scale(0.97);
}

.btn-new {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 14px;
    background: transparent;
    color: var(--text-muted);
    border: none;
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 12px;
    -webkit-appearance: none;
}

.btn-new:hover {
    color: var(--text-primary);
}

/* ──── Occasion Grid ──── */
.occasion-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    width: 100%;
}

.occasion-card {
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px 14px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-appearance: none;
}

.occasion-card:active {
    transform: scale(0.97);
    border-color: var(--navy);
}

.occasion-card.selected {
    border-color: var(--navy);
    background: rgba(26, 58, 108, 0.04);
}

.occasion-icon {
    font-size: 2.2rem;
    margin-bottom: 10px;
    display: block;
}

.occasion-name {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* ──── Template Grid ──── */
.template-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    width: 100%;
}

.template-card {
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    border: 3px solid transparent;
    transition: all 0.2s;
    aspect-ratio: 9 / 16;
}

.template-card:active {
    transform: scale(0.96);
}

.template-card.selected {
    border-color: var(--gold);
    box-shadow: 0 4px 20px rgba(196, 148, 58, 0.3);
}

.template-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.template-card .template-name {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px;
    background: linear-gradient(transparent, rgba(0,0,0,0.7));
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
    text-align: center;
}

.template-check {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--gold);
    color: white;
    display: none;
    align-items: center;
    justify-content: center;
}

.template-card.selected .template-check {
    display: flex;
}

/* ──── Name Input Step ──── */
.step-name-content {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.preview-container {
    position: relative;
    width: 100%;
    max-width: min(240px, 55vw);
    aspect-ratio: 9 / 16;
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    background: var(--surface-secondary);
}

.preview-canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
}

.preview-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.7);
}

.preview-loading.hidden {
    display: none;
}

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

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

.name-input-wrapper {
    position: relative;
    width: 100%;
    max-width: 320px;
    margin-bottom: 16px;
}

.name-input {
    width: 100%;
    padding: 14px 16px;
    padding-left: 55px;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--font-body);
    /* 16px minimum to prevent iOS zoom */
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
    outline: none;
    transition: border-color 0.2s;
    -webkit-appearance: none;
    appearance: none;
}

.name-input::placeholder {
    color: var(--text-muted);
    font-weight: 400;
}

.name-input:focus {
    border-color: var(--navy);
    box-shadow: 0 0 0 3px rgba(26, 58, 108, 0.1);
}

.name-char-count {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 500;
    pointer-events: none;
}

.btn-generate {
    width: 100%;
    max-width: 320px;
    font-size: 1rem;
}

/* ──── Result ──── */
.step-result-content {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.result-card-wrapper {
    width: 100%;
    max-width: min(300px, 70vw);
    aspect-ratio: 9 / 16;
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 24px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
}

.result-canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
}

.result-actions {
    display: flex;
    gap: 12px;
    width: 100%;
    max-width: 340px;
}

.btn-share {
    flex: 1;
}

.btn-download {
    flex: 1;
}

/* ──── Responsive ──── */
@media (max-width: 380px) {
    .splash-title {
        font-size: 1.5rem;
    }

    .step-title {
        font-size: 1.2rem;
    }

    .occasion-card {
        padding: 16px 10px;
    }

    .occasion-icon {
        font-size: 1.8rem;
    }

    .preview-container {
        max-width: min(200px, 55vw);
    }

    .result-card-wrapper {
        max-width: min(240px, 65vw);
    }
}

/* Short screens (landscape or small phones) */
@media (max-height: 600px) {
    .step-content {
        padding-top: calc(55px + var(--safe-top));
    }

    .preview-container {
        max-width: min(140px, 30vh);
    }

    .result-card-wrapper {
        max-width: min(160px, 35vh);
    }

    .splash-icon {
        width: 60px;
        height: 60px;
    }

    .splash-title {
        font-size: 1.4rem;
    }

    .splash-divider {
        margin: 16px auto;
    }
}

@media (min-width: 768px) {
    .template-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .occasion-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ──── Scrollbar ──── */
::-webkit-scrollbar {
    width: 0;
}
