:root {
    --bg: #12071f;
    --panel: rgba(16, 10, 26, 0.92);
    --panel-border: rgba(212, 175, 55, 0.25);
    --gold: #d4af37;
    --gold-light: #f4e4bc;
    --text: #fdf8f0;
}

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

body {
    font-family: 'Noto Sans Arabic', 'Amiri', sans-serif;
    background: radial-gradient(120% 120% at 15% 10%, #2b1550 0%, #1a0a2e 45%, #0d1b2a 100%);
    color: var(--text);
    min-height: 100vh;
}

.app {
    max-width: 1200px;
    margin: 0 auto;
    padding: 30px 20px 50px;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 30px;
}

.title-wrap {
    display: flex;
    align-items: center;
    gap: 16px;
}

.moon {
    font-size: 50px;
    color: var(--gold);
    text-shadow: 0 0 20px rgba(212, 175, 55, 0.5);
}

.app-header h1 {
    font-family: 'Amiri', serif;
    font-size: 2rem;
    color: var(--gold);
}

.app-header p {
    color: var(--gold-light);
}

.primary {
    padding: 14px 22px;
    border-radius: 14px;
    border: none;
    background: linear-gradient(135deg, var(--gold) 0%, #b8962e 100%);
    color: #1a0a2e;
    font-family: 'Noto Sans Arabic', sans-serif;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.15s;
}

.primary:hover {
    transform: scale(1.03);
}

.primary:disabled {
    opacity: 0.6;
    cursor: wait;
}

/* ===== Layout ===== */
.layout {
    display: grid;
    grid-template-columns: 1fr minmax(320px, 420px);
    gap: 24px;
    align-items: start;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 18px;
    padding: 20px;
    position: relative;
    z-index: 1;
}

.preview-panel {
    z-index: 1;
    display: grid;
    gap: 14px;
    align-content: start;
}

.editor-panel {
    z-index: 10;
    position: relative;
}

/* ===== التبويبات ===== */
.tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 16px;
    position: relative;
    z-index: 20;
    padding-bottom: 8px;
    background: var(--panel);
}

.tab-btn {
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid rgba(212, 175, 55, 0.4);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    cursor: pointer;
    font-family: 'Noto Sans Arabic', sans-serif;
    font-size: 0.85rem;
    pointer-events: auto;
    position: relative;
    z-index: 25;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.2s, border-color 0.2s;
}

.tab-btn:hover {
    background: rgba(212, 175, 55, 0.12);
}

.tab-btn.active {
    background: rgba(212, 175, 55, 0.25);
    border-color: var(--gold);
}

.tab-panel {
    display: none;
    position: relative;
    z-index: 15;
}

.tab-panel.active {
    display: block;
}

/* ===== الحقول ===== */
.section {
    display: grid;
    gap: 12px;
    margin-bottom: 22px;
}

.section h2 {
    color: var(--gold-light);
    font-size: 1rem;
}

label {
    color: var(--gold-light);
    font-size: 0.9rem;
}

input[type="text"],
textarea {
    width: 100%;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid rgba(212, 175, 55, 0.35);
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    font-family: 'Noto Sans Arabic', sans-serif;
    font-size: 0.95rem;
}

input[type="text"]:focus,
textarea:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.2);
}

select {
    width: 100%;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid rgba(212, 175, 55, 0.35);
    background-color: #1e1232;
    color: #ffffff;
    font-family: 'Noto Sans Arabic', sans-serif;
    font-size: 0.95rem;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23d4af37' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: left 12px center;
    padding-left: 32px;
    cursor: pointer;
}

select option {
    background-color: #1e1232;
    color: #ffffff;
    padding: 10px;
    font-family: 'Noto Sans Arabic', sans-serif;
}

select:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.2);
}

input[type="range"] {
    width: 100%;
}

/* ===== أزرار ===== */
.select-grid,
.templates,
.frames {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.select-btn,
.template-btn,
.frame-btn,
.wrap-btn,
.align-btn,
.ghost-btn {
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid rgba(212, 175, 55, 0.4);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    cursor: pointer;
    font-family: 'Noto Sans Arabic', sans-serif;
    font-size: 0.85rem;
    transition: background 0.15s, border-color 0.15s;
}

.select-btn:hover,
.template-btn:hover,
.frame-btn:hover,
.wrap-btn:hover,
.align-btn:hover,
.ghost-btn:hover {
    background: rgba(212, 175, 55, 0.12);
}

.select-btn.active,
.template-btn.active,
.frame-btn.active,
.wrap-btn.active,
.align-btn.active,
.ghost-btn.active {
    background: rgba(212, 175, 55, 0.25);
    border-color: var(--gold);
}

.control-row {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 10px;
    align-items: center;
    color: var(--gold-light);
    font-size: 0.9rem;
}

.wrap-controls,
.align-controls {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.align-controls {
    grid-template-columns: repeat(3, 1fr);
}

.buttons-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

/* ===== رفع الصورة ===== */
.file-label {
    display: block;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px dashed rgba(212, 175, 55, 0.5);
    background: rgba(255, 255, 255, 0.05);
    color: var(--gold-light);
    text-align: center;
    cursor: pointer;
    transition: background 0.15s;
}

.file-label:hover {
    background: rgba(212, 175, 55, 0.1);
}

.file-label input[type="file"] {
    display: none;
}

/* ===== المعاينة ===== */
.preview-stage {
    background: radial-gradient(120% 120% at 10% 10%, rgba(255,255,255,0.08), transparent 60%);
    padding: 24px;
    border-radius: 20px;
    display: flex;
    justify-content: center;
    position: relative;
    z-index: 0;
}

/* ===== البطاقة ===== */
.card {
    width: 360px;
    height: 520px;
    border-radius: 24px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 30px 70px rgba(0, 0, 0, 0.45);
}

.card-surface {
    position: absolute;
    inset: 0;
    border-radius: 24px;
    background: radial-gradient(120% 120% at 10% 10%, #2b1550 0%, #1a0a2e 45%, #12061f 100%);
}

.card-bg-image {
    position: absolute;
    inset: 0;
    border-radius: 24px;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0.5;
    display: none;
    z-index: 1;
}

.card-content {
    position: absolute;
    inset: 0;
    z-index: 2;
}

/* ===== القوالب ===== */
.card.classic .card-surface {
    background: radial-gradient(120% 120% at 10% 10%, #2b1550 0%, #1a0a2e 45%, #12061f 100%);
}

.card.modern .card-surface {
    background: linear-gradient(145deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
}

.card.minimal .card-surface {
    background: #fdf8f0;
}

.card.royal .card-surface {
    background: linear-gradient(145deg, #2c1810 0%, #4a1c1c 50%, #1a0a0a 100%);
}

.card.noor .card-surface {
    background: radial-gradient(120% 120% at 20% 10%, #fff1b8 0%, #f3c86b 40%, #a86b2b 100%);
}

.card.dunes .card-surface {
    background: linear-gradient(160deg, #1b2430 0%, #212d3b 35%, #caa66b 100%);
}

.card.oasis .card-surface {
    background: radial-gradient(120% 120% at 20% 10%, #1f6f5c 0%, #123c35 55%, #0b2421 100%);
}

.card.midnight .card-surface {
    background: linear-gradient(160deg, #0a0a1a 0%, #101035 40%, #1a1a50 70%, #0d0d2b 100%);
}

.card.sahara .card-surface {
    background: linear-gradient(145deg, #c2956b 0%, #a67c52 35%, #8b5e3c 65%, #6b4226 100%);
}

.card.ruby .card-surface {
    background: radial-gradient(120% 120% at 30% 20%, #7a1030 0%, #5c0a20 45%, #3a0515 75%, #1a0208 100%);
}

.card.emerald .card-surface {
    background: radial-gradient(120% 120% at 25% 15%, #0d5c3f 0%, #0a4a32 40%, #073824 70%, #042015 100%);
}

.card.ivory .card-surface {
    background: linear-gradient(145deg, #f5f0e8 0%, #ece4d4 40%, #ddd2be 70%, #cfc3aa 100%);
}

.card.cosmos .card-surface {
    background: radial-gradient(120% 120% at 50% 30%, #1a0533 0%, #0d0022 35%, #15063a 60%, #08001a 100%);
}

/* قوالب رمضانية وعيدية */
.card.ramadan-gold .card-surface {
    background: linear-gradient(160deg, #1a0a2e 0%, #2b1550 30%, #3d1f70 60%, #1a0a2e 100%);
    box-shadow: inset 0 0 80px rgba(212, 175, 55, 0.15);
}

.card.eid-mubarak .card-surface {
    background: linear-gradient(145deg, #0a3d2f 0%, #1a6b4a 35%, #2d8f65 60%, #0a3d2f 100%);
}

.card.lantern .card-surface {
    background: radial-gradient(circle at 50% 20%, #4a2c0a 0%, #2a1805 40%, #1a0f03 70%, #0d0702 100%);
}

.card.crescent .card-surface {
    background: radial-gradient(120% 120% at 70% 15%, #1a1a40 0%, #0d0d25 40%, #060614 70%, #020208 100%);
}

.card.mosque .card-surface {
    background: linear-gradient(180deg, #1a0a30 0%, #2b1550 40%, #1a0a30 70%, #0d0518 100%);
}

.card.dates .card-surface {
    background: linear-gradient(145deg, #3d2b1f 0%, #5c3d28 35%, #7a5233 60%, #3d2b1f 100%);
}

.card.tarawih .card-surface {
    background: radial-gradient(120% 120% at 50% 80%, #0d1b3a 0%, #0a1428 40%, #060d1a 70%, #03060d 100%);
}

/* ===== الإطارات ===== */
.card.frame-thin::after,
.card.frame-double::after,
.card.frame-double::before,
.card.frame-ornate::after,
.card.frame-golden::after,
.card.frame-golden::before,
.card.frame-dashed::after,
.card.frame-glow::after,
.card.frame-corners::after,
.card.frame-elegant::after,
.card.frame-elegant::before,
.card.frame-arabesque::after,
.card.frame-shadow::after,
.card.frame-neon::after {
    content: '';
    position: absolute;
    border-radius: 20px;
    border: 1px solid rgba(212, 175, 55, 0.6);
    pointer-events: none;
    z-index: 5;
}

.card.frame-thin::after {
    inset: 16px;
}

.card.frame-double::after {
    inset: 14px;
}

.card.frame-double::before {
    inset: 28px;
    border-color: rgba(212, 175, 55, 0.35);
}

.card.frame-ornate::after {
    inset: 12px;
    border-radius: 22px;
    background-image:
        radial-gradient(circle at 20% 20%, rgba(212, 175, 55, 0.3) 0, transparent 40%),
        radial-gradient(circle at 80% 20%, rgba(212, 175, 55, 0.3) 0, transparent 40%),
        radial-gradient(circle at 20% 80%, rgba(212, 175, 55, 0.3) 0, transparent 40%),
        radial-gradient(circle at 80% 80%, rgba(212, 175, 55, 0.3) 0, transparent 40%);
}

.card.frame-golden::after {
    inset: 10px;
    border: 2px solid rgba(212, 175, 55, 0.8);
    border-radius: 18px;
    box-shadow: 0 0 8px rgba(212, 175, 55, 0.3), inset 0 0 8px rgba(212, 175, 55, 0.15);
}

.card.frame-golden::before {
    inset: 16px;
    border: 1px solid rgba(212, 175, 55, 0.4);
    border-radius: 16px;
}

.card.frame-dashed::after {
    inset: 14px;
    border: 2px dashed rgba(212, 175, 55, 0.6);
    border-radius: 18px;
}

.card.frame-glow::after {
    inset: 12px;
    border: 1px solid rgba(212, 175, 55, 0.7);
    border-radius: 20px;
    box-shadow: 0 0 12px rgba(212, 175, 55, 0.4), 0 0 24px rgba(212, 175, 55, 0.15), inset 0 0 12px rgba(212, 175, 55, 0.1);
}

.card.frame-corners::after {
    inset: 14px;
    border: none;
    border-radius: 0;
    background:
        linear-gradient(rgba(212, 175, 55, 0.7), rgba(212, 175, 55, 0.7)) top left / 30px 2px no-repeat,
        linear-gradient(rgba(212, 175, 55, 0.7), rgba(212, 175, 55, 0.7)) top left / 2px 30px no-repeat,
        linear-gradient(rgba(212, 175, 55, 0.7), rgba(212, 175, 55, 0.7)) top right / 30px 2px no-repeat,
        linear-gradient(rgba(212, 175, 55, 0.7), rgba(212, 175, 55, 0.7)) top right / 2px 30px no-repeat,
        linear-gradient(rgba(212, 175, 55, 0.7), rgba(212, 175, 55, 0.7)) bottom left / 30px 2px no-repeat,
        linear-gradient(rgba(212, 175, 55, 0.7), rgba(212, 175, 55, 0.7)) bottom left / 2px 30px no-repeat,
        linear-gradient(rgba(212, 175, 55, 0.7), rgba(212, 175, 55, 0.7)) bottom right / 30px 2px no-repeat,
        linear-gradient(rgba(212, 175, 55, 0.7), rgba(212, 175, 55, 0.7)) bottom right / 2px 30px no-repeat;
}

/* إطارات جديدة */
.card.frame-elegant::after {
    inset: 10px;
    border: 1px solid rgba(212, 175, 55, 0.5);
    border-radius: 20px;
}

.card.frame-elegant::before {
    inset: 14px;
    border: 2px solid rgba(212, 175, 55, 0.3);
    border-radius: 18px;
    box-shadow: inset 0 0 20px rgba(212, 175, 55, 0.08);
}

.card.frame-arabesque::after {
    inset: 8px;
    border: 3px solid transparent;
    border-radius: 20px;
    border-image: repeating-linear-gradient(
        45deg,
        rgba(212, 175, 55, 0.6) 0px,
        rgba(212, 175, 55, 0.6) 4px,
        transparent 4px,
        transparent 8px,
        rgba(212, 175, 55, 0.3) 8px,
        rgba(212, 175, 55, 0.3) 12px,
        transparent 12px,
        transparent 16px
    ) 3;
    border-radius: 0;
}

.card.frame-shadow::after {
    inset: 16px;
    border: none;
    border-radius: 18px;
    box-shadow: 
        0 0 0 1px rgba(212, 175, 55, 0.3),
        0 0 15px rgba(212, 175, 55, 0.1),
        inset 0 0 15px rgba(212, 175, 55, 0.08),
        0 0 30px rgba(212, 175, 55, 0.05);
}

.card.frame-neon::after {
    inset: 12px;
    border: 2px solid rgba(212, 175, 55, 0.9);
    border-radius: 18px;
    box-shadow:
        0 0 5px rgba(212, 175, 55, 0.6),
        0 0 15px rgba(212, 175, 55, 0.4),
        0 0 30px rgba(212, 175, 55, 0.2),
        0 0 50px rgba(212, 175, 55, 0.1),
        inset 0 0 5px rgba(212, 175, 55, 0.3),
        inset 0 0 15px rgba(212, 175, 55, 0.1);
}

/* ===== عناصر البطاقة ===== */
.editable {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    cursor: move;
    user-select: none;
    transform-origin: center;
    z-index: 3;
}

.editable.selected {
    outline: 1px dashed rgba(212, 175, 55, 0.8);
    outline-offset: 4px;
}

.editable.locked {
    cursor: not-allowed;
}

.card-title {
    font-family: 'Amiri', serif;
    font-size: 36px;
    color: var(--gold);
    text-align: center;
}

.card-name {
    font-size: 24px;
    color: var(--text);
    text-align: center;
}

.card-message {
    font-size: 16px;
    color: var(--gold-light);
    width: 240px;
    line-height: 1.6;
    text-align: center;
}

.card-footer {
    display: flex;
    align-items: center;
    gap: 14px;
    color: var(--gold);
}

.card-logo {
    width: 110px;
    height: 110px;
}

.card-logo img,
.card-corner-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.card-corner-logo {
    width: 46px;
    height: 46px;
    right: 22px;
    bottom: 26px;
    top: auto;
    left: auto;
    position: absolute;
    z-index: 4;
}

.card-header {
    position: absolute;
    top: 18px;
    left: 20px;
    right: 20px;
    display: flex;
    justify-content: space-between;
    color: var(--gold);
    font-size: 24px;
    pointer-events: none;
}

.card-header,
.card-footer .card-lantern {
    display: none;
}

.helper {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.85rem;
}

/* ===== رابط الإدارة ===== */
.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ===== شريط الروابط ===== */
.links-bar {
    display: flex;
    justify-content: center;
    gap: 16px;
    padding: 20px 0 10px;
    margin-top: 20px;
}

.social-link {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--panel-border);
    background: rgba(255, 255, 255, 0.05);
    color: var(--gold-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.social-link:hover {
    background: rgba(212, 175, 55, 0.15);
    border-color: var(--gold);
    transform: scale(1.1);
}

/* ===== شبكة المقاسات ===== */
.sizes-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}

.size-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 8px;
    border-radius: 12px;
    border: 1px solid var(--panel-border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, transform 0.15s;
}

.size-btn:hover {
    border-color: var(--gold-light);
    background: rgba(212, 175, 55, 0.08);
    transform: translateY(-1px);
}

.size-btn.active {
    border-color: var(--gold);
    background: rgba(212, 175, 55, 0.15);
    box-shadow: 0 0 12px rgba(212, 175, 55, 0.2);
}

.size-icon {
    font-size: 1.4rem;
    color: var(--gold-light);
    line-height: 1;
}

.size-label {
    font-size: 0.82rem;
    font-weight: 600;
    font-family: 'Noto Sans Arabic', sans-serif;
}

.size-dim {
    font-size: 0.7rem;
    color: var(--gold-light);
    opacity: 0.7;
    direction: ltr;
}

.custom-size-section {
    margin-top: 8px;
}

.custom-size-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    margin-bottom: 12px;
}

.custom-size-field {
    flex: 1;
}

.custom-size-field label {
    display: block;
    font-size: 0.78rem;
    margin-bottom: 4px;
    color: var(--gold-light);
}

.custom-size-field input {
    width: 100%;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid var(--panel-border);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
    font-size: 0.9rem;
    text-align: center;
    direction: ltr;
}

.custom-size-x {
    font-size: 1.1rem;
    color: var(--gold-light);
    padding-bottom: 8px;
}

.current-size-info {
    text-align: center;
    padding: 10px;
    margin-top: 12px;
    border-radius: 10px;
    background: rgba(212, 175, 55, 0.08);
    border: 1px solid rgba(212, 175, 55, 0.15);
    font-size: 0.85rem;
    color: var(--gold-light);
    direction: ltr;
}

.current-size-info strong {
    color: var(--gold);
}

/* ===== Responsive ===== */
@media (max-width: 980px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .preview-stage {
        padding: 16px;
    }
}
