:root {
    --bg: #0a0e1a;
    --bg-2: #131826;
    --bg-3: #1a2030;
    --panel: rgba(255, 255, 255, 0.04);
    --panel-2: rgba(255, 255, 255, 0.06);
    --border: rgba(255, 255, 255, 0.08);
    --border-hi: rgba(255, 255, 255, 0.15);
    --text: #e8eaf0;
    --muted: #9aa3b2;
    --gold: #d4af37;
    --gold-2: #f4d27a;
    --teal: #0ea5e9;
    --teal-2: #22d3ee;
    --green: #10b981;
    --red: #ef4444;
    --shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
    --radius: 14px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
}

body {
    background:
        radial-gradient(1200px 600px at 80% -10%, rgba(212, 175, 55, 0.10), transparent 60%),
        radial-gradient(900px 500px at -10% 110%, rgba(14, 165, 233, 0.10), transparent 60%),
        linear-gradient(180deg, #0a0e1a 0%, #0c1120 100%);
    color: var(--text);
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    min-height: 100vh;
    direction: rtl;
    -webkit-font-smoothing: antialiased;
}

/* ===== HEADER ===== */
header.app {
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(14px);
    background: rgba(10, 14, 26, 0.75);
    border-bottom: 1px solid var(--border);
    padding: 14px 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand .logo {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--gold), var(--gold-2));
    display: grid;
    place-items: center;
    color: #1a1408;
    font-weight: 800;
    font-size: 20px;
    box-shadow: 0 6px 20px rgba(212, 175, 55, 0.35);
}

.brand h1 {
    margin: 0;
    font-size: clamp(1rem, 2vw, 1.25rem);
    font-weight: 700;
    letter-spacing: 0.3px;
    background: linear-gradient(90deg, #fff, #f4d27a);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.brand small {
    color: var(--muted);
    font-size: 0.72rem;
    display: block;
    margin-top: 2px;
}

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

.btn {
    appearance: none;
    border: 1px solid var(--border-hi);
    background: var(--panel-2);
    color: var(--text);
    padding: 9px 14px;
    border-radius: 10px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all .2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: inherit;
}

.btn:hover {
    background: rgba(255, 255, 255, 0.10);
    border-color: rgba(255, 255, 255, 0.25);
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: linear-gradient(135deg, var(--gold), var(--gold-2));
    color: #1a1408;
    border: none;
    font-weight: 700;
}

.btn-primary:hover {
    filter: brightness(1.1);
}

.btn-teal {
    background: linear-gradient(135deg, #0ea5e9, #22d3ee);
    color: #061018;
    border: none;
    font-weight: 600;
}

.btn-ghost {
    background: transparent;
}

/* ===== LAYOUT ===== */
.layout {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 20px;
    padding: 20px;
    max-width: 1500px;
    margin: 0 auto;
}

@media (max-width: 1024px) {
    .layout {
        grid-template-columns: 1fr;
    }
}

/* ===== SIDEBAR ===== */
.sidebar {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 18px;
    backdrop-filter: blur(10px);
    overflow: hidden;
    box-shadow: var(--shadow);
    position: sticky;
    top: 84px;
    align-self: start;
    max-height: calc(100vh - 100px);
    display: flex;
    flex-direction: column;
}

.tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.2);
}

.tab-btn {
    flex: 1;
    padding: 14px 8px;
    background: transparent;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 0.85rem;
    font-family: inherit;
    transition: all .2s;
    border-bottom: 2px solid transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.tab-btn .icon {
    font-size: 1.1rem;
}

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

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

.panels {
    overflow-y: auto;
    padding: 18px;
    flex: 1;
}

.panels::-webkit-scrollbar {
    width: 8px;
}

.panels::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

.panel {
    display: none;
    animation: fadeUp .3s ease;
}

.panel.active {
    display: block;
}

@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.group {
    margin-bottom: 18px;
}

.group-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--muted);
    margin-bottom: 10px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.group-title::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border);
}

.field {
    margin-bottom: 10px;
}

.field label {
    display: block;
    font-size: 0.78rem;
    color: var(--muted);
    margin-bottom: 6px;
    font-weight: 500;
}

.field select,
.field input[type="text"],
.field input[type="url"] {
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--bg-3);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 0.88rem;
    font-family: inherit;
    transition: border-color .2s;
}

.field select:focus,
.field input:focus {
    outline: none;
    border-color: var(--gold);
}

.row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: linear-gradient(90deg, var(--gold), var(--gold-2));
    border-radius: 6px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    cursor: pointer;
    border: 2px solid var(--gold);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    cursor: pointer;
    border: 2px solid var(--gold);
}

input[type="color"] {
    width: 100%;
    height: 42px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg-3);
    cursor: pointer;
    padding: 4px;
}

.btn-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.btn-grid .btn {
    justify-content: center;
    width: 100%;
}

.collapsible {
    background: var(--bg-3);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    margin-top: 8px;
    display: none;
    flex-direction: column;
    gap: 10px;
}

.collapsible.show {
    display: flex;
}

.version-toggle {
    display: flex;
    gap: 6px;
    background: var(--bg-3);
    padding: 4px;
    border-radius: 10px;
    border: 1px solid var(--border);
}

.version-toggle button {
    flex: 1;
    padding: 8px;
    background: transparent;
    border: none;
    color: var(--muted);
    cursor: pointer;
    border-radius: 7px;
    font-size: 0.82rem;
    font-family: inherit;
    transition: all .2s;
}

.version-toggle button.active {
    background: linear-gradient(135deg, var(--gold), var(--gold-2));
    color: #1a1408;
    font-weight: 700;
}

/* ===== PREVIEW ===== */
.preview-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
    padding: 10px 0;
}

.preview-frame {
    position: relative;
    padding: 24px;
    border-radius: 20px;
    background: radial-gradient(circle at 50% 0%, rgba(212, 175, 55, 0.08), transparent 70%);
}

.preview-frame::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 20px;
    padding: 1px;
    background: linear-gradient(135deg, rgba(212, 175, 55, 0.4), transparent 50%, rgba(14, 165, 233, 0.3));
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
}

#pages {
    width: min(540px, 80vw);
    aspect-ratio: 1/1;
    position: relative;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.6);
    background-color: #000;
}

#pages::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image: var(--bg-image);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    z-index: 0;
    opacity: var(--bg-opacity, 1);
    pointer-events: none;
    transition: opacity .3s ease;
}

#pages>*:not(.brand-watermark) {
    position: relative;
    z-index: 1;
}

.quran-v1,
.quran-v2 {
    font-size: clamp(1.8em, 5vw, 2.5em);
    line-height: 1.7;
    word-spacing: 0.1em;
    text-align: center;
    user-select: text;
    margin: 1.5em auto;
    color: #fff;
    opacity: 0;
    transition: opacity .3s;
    display: none;
    max-width: 86%;
    overflow-wrap: break-word;
}

.quran-v2 {
    line-height: 1.7;
    word-spacing: 0;
}

.word {
    display: inline-block;
    margin: 0;
    cursor: default;
}

.translation {
    font-family: sans-serif;
    font-size: clamp(1rem, 3vw, 1.2rem);
    color: #fff;
    direction: ltr;
    text-align: center;
    line-height: 1.5;
    word-spacing: 0.2em;
    margin-top: 0.8em;
    padding: 0 0.8em;
    max-width: 90%;
}

.translation[contenteditable="true"] {
    cursor: text;
}

.surah-info {
    font-size: 0.4em;
    font-family: sans-serif;
    color: #fff;
    margin-top: 1em;
    text-align: center;
    direction: ltr;
    letter-spacing: 1px;
}

.brand-watermark {
    font-size: 0.8em;
    font-family: sans-serif;
    color: rgba(255, 255, 255, 0.7);
    position: absolute;
    bottom: 0.8em;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    font-style: italic;
    direction: ltr;
    user-select: text;
    z-index: 2;
}

.preview-toolbar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

/* ===== MODALS ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(6px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

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

.modal-content {
    background: linear-gradient(180deg, #1a2030, #131826);
    border: 1px solid var(--border-hi);
    border-radius: 18px;
    padding: 24px;
    width: 100%;
    max-width: 480px;
    box-shadow: var(--shadow);
    position: relative;
    animation: modalIn .3s ease;
    direction: ltr;
    text-align: left;
    max-height: 90vh;
    overflow-y: auto;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-content h3 {
    margin: 0 0 16px;
    font-size: 1.1rem;
    color: var(--gold);
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    cursor: pointer;
    font-size: 1rem;
    display: grid;
    place-items: center;
    transition: background .2s;
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.15);
}

.modal-content select,
.modal-content input {
    width: 100%;
    padding: 11px;
    border-radius: 10px;
    background: var(--bg-3);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 0.9rem;
    font-family: inherit;
    margin-bottom: 10px;
}

.modal-content select:focus,
.modal-content input:focus {
    outline: none;
    border-color: var(--gold);
}

#searchResults {
    margin-top: 14px;
    max-height: 300px;
    overflow-y: auto;
}

#searchResults p {
    background: var(--bg-3);
    padding: 12px;
    border-radius: 10px;
    margin-bottom: 8px;
    font-size: 0.85rem;
    line-height: 1.5;
    border: 1px solid var(--border);
}

#searchResults button {
    margin-top: 8px;
    padding: 6px 12px;
    font-size: 0.78rem;
    background: linear-gradient(135deg, var(--green), #34d399);
    border: none;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    font-family: inherit;
}

#searchResults button:hover {
    filter: brightness(1.1);
}

#pexelsPreview {
    margin-top: 14px;
    max-height: 320px;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 8px;
}

#pexelsPreview img {
    width: 100%;
    border-radius: 8px;
    cursor: pointer;
    aspect-ratio: 1;
    object-fit: cover;
    transition: transform .2s, box-shadow .2s;
}

#pexelsPreview img:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 18px rgba(212, 175, 55, 0.3);
}

.loading-indicator {
    display: none;
    text-align: center;
    margin: 10px 0;
    color: var(--gold);
    font-weight: 600;
}

/* ===== LOADER ===== */
#loaderOverlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 14, 26, 0.85);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

#loaderOverlay.show {
    display: flex;
}

.loader-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--gold);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ===== TOAST ===== */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: linear-gradient(135deg, #1a2030, #131826);
    border: 1px solid var(--border-hi);
    color: var(--text);
    padding: 12px 22px;
    border-radius: 12px;
    font-size: 0.85rem;
    box-shadow: var(--shadow);
    z-index: 10000;
    opacity: 0;
    transition: all .3s ease;
    max-width: 90%;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ===== MISC ===== */
.hint {
    font-size: 0.72rem;
    color: var(--muted);
    margin-top: 4px;
    line-height: 1.4;
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 0.7rem;
    background: rgba(212, 175, 55, 0.15);
    color: var(--gold);
    font-weight: 600;
}

@media (max-width: 600px) {
    .layout {
        padding: 12px;
        gap: 12px;
    }

    .sidebar {
        position: static;
        max-height: none;
    }

    .btn-grid {
        grid-template-columns: 1fr;
    }

    header.app {
        padding: 12px;
    }

    .panels {
        padding: 14px;
    }
}

/* ===== FOOTER VISITOR COUNTER ===== */
.app-footer {
    text-align: center;
    padding: 24px 20px 30px;
    border-top: 1px solid var(--border);
    margin-top: 10px;
    direction: ltr;
}

.footer-stats {
    display: flex;
    justify-content: center;
    gap: 24px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--panel);
    border: 1px solid var(--border);
    padding: 10px 18px;
    border-radius: 12px;
    backdrop-filter: blur(8px);
    transition: border-color .2s, transform .2s;
}

.stat-item:hover {
    border-color: var(--border-hi);
    transform: translateY(-1px);
}

.stat-icon {
    font-size: 1.1rem;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--gold);
    min-width: 20px;
}

.footer-credit {
    font-size: 0.72rem;
    color: var(--muted);
    letter-spacing: 0.3px;
}

.footer-credit strong {
    color: var(--gold);
    font-weight: 600;
}
