/* Portfolio - Main styles. Dark/Light theme, Grid layout, RTL, Tajawal */

:root {
    --bg: #0f172a;
    --card: #1e293b;
    --card-border: rgba(30, 41, 59, 0.8);
    --accent: #38bdf8;
    --accent-dim: #0ea5e9;
    --purple-glow: rgba(139, 92, 246, 0.4);
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --font: 'Tajawal', sans-serif;
    --radius: 12px;
    --header-h: 72px;
    --container: min(1200px, 100% - 2rem);
    --header-bg: rgba(15, 23, 42, 0.85);
    --header-border: rgba(30, 41, 59, 0.8);
    --grid-line: rgba(30, 41, 59, 0.03);
    --gradient-overlay: rgba(15, 23, 42, 0.97);
    --btn-cta-text: #0f172a;
    --skill-border: rgba(56, 189, 248, 0.2);
    --modal-backdrop: rgba(15, 23, 42, 0.85);
    --footer-border: #1e293b;
}

[data-theme="light"] {
    --bg: #f8fafc;
    --card: #ffffff;
    --card-border: rgba(0, 0, 0, 0.08);
    --text: #0f172a;
    --text-muted: #475569;
    --accent: #0284c7;
    --accent-dim: #0369a1;
    --purple-glow: rgba(99, 102, 241, 0.35);
    --header-bg: rgba(248, 250, 252, 0.9);
    --header-border: rgba(0, 0, 0, 0.06);
    --grid-line: rgba(0, 0, 0, 0.04);
    --gradient-overlay: rgba(248, 250, 252, 0.95);
    --btn-cta-text: #ffffff;
    --skill-border: rgba(2, 132, 199, 0.25);
    --modal-backdrop: rgba(15, 23, 42, 0.5);
    --footer-border: rgba(0, 0, 0, 0.08);
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    overflow-x: hidden;
    position: relative;
}
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image:
        radial-gradient(circle at 20% 80%, rgba(56, 189, 248, 0.06) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(139, 92, 246, 0.07) 0%, transparent 45%),
        linear-gradient(180deg, transparent 0%, var(--gradient-overlay) 100%);
    pointer-events: none;
    z-index: 0;
}
[data-theme="light"] body::before {
    background-image:
        radial-gradient(circle at 20% 80%, rgba(2, 132, 199, 0.05) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(99, 102, 241, 0.06) 0%, transparent 45%),
        linear-gradient(180deg, transparent 0%, var(--gradient-overlay) 100%);
}
body::after {
    content: '';
    position: fixed;
    inset: 0;
    background-image: linear-gradient(var(--grid-line) 1px, transparent 1px),
                      linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
    background-size: 64px 64px;
    pointer-events: none;
    z-index: 0;
}
body > .page-loader,
body > .scroll-progress,
body > .site-header,
body > .main-content,
body > .site-footer,
body > #project-modal { position: relative; z-index: 1; }
body.dir-rtl { direction: rtl; text-align: right; }
body.dir-ltr { direction: ltr; text-align: left; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-dim); }

/* Page loader */
.page-loader {
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}
.page-loader.done { opacity: 0; visibility: hidden; pointer-events: none; }
.page-loader::after {
    content: '';
    width: 48px;
    height: 48px;
    border: 3px solid var(--card);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Scroll progress */
.scroll-progress {
    position: fixed;
    top: 0;
    left: 0;
    width: 0%;
    height: 3px;
    background: linear-gradient(90deg, var(--accent), rgba(139, 92, 246, 0.9));
    z-index: 1001;
    transition: width 0.1s ease;
}
body.dir-rtl .scroll-progress { left: auto; right: 0; }

/* Header - grid layout */
.site-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-h);
    background: var(--header-bg);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--header-border);
    z-index: 1000;
    transition: background 0.3s ease, border-color 0.3s ease;
}
.nav-inner {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    align-items: center;
    gap: 1rem;
    max-width: var(--container);
    margin: 0 auto;
    padding: 0 1.5rem;
    height: 100%;
}
.nav-inner > .nav-logo { justify-self: start; }
.nav-inner > .nav-links { justify-self: center; }
.nav-inner > .theme-toggle { justify-self: end; }
.nav-inner > .nav-toggle { justify-self: end; }
.nav-logo { font-weight: 700; font-size: 1.25rem; color: var(--text); text-decoration: none; transition: color 0.2s; }
.nav-links {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-auto-flow: column;
    gap: 1.5rem;
    align-items: center;
}
.nav-links a { color: var(--text-muted); font-weight: 500; transition: color 0.2s; }
.nav-links a:hover, .nav-links a.active { color: var(--accent); }
.lang-switch { display: grid; grid-auto-flow: column; align-items: center; gap: 0.25rem; }
.lang-switch .sep { color: var(--text-muted); }
.lang-switch a { transition: color 0.2s; }
.lang-switch a.active { color: var(--accent); font-weight: 700; }
.theme-toggle {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    background: var(--card);
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.2s, background 0.2s, border-color 0.2s;
}
.theme-toggle:hover { color: var(--accent); }
.theme-toggle svg { width: 20px; height: 20px; }
.theme-toggle .icon-dark { display: none; }
.theme-toggle .icon-light { display: block; }
[data-theme="light"] .theme-toggle .icon-dark { display: block; }
[data-theme="light"] .theme-toggle .icon-light { display: none; }
.nav-toggle {
    display: none;
    width: 28px;
    height: 28px;
    background: none;
    border: none;
    cursor: pointer;
    position: relative;
}
.nav-toggle::before, .nav-toggle::after, .nav-toggle span {
    content: ''; position: absolute; left: 0; right: 0; height: 2px; background: var(--text);
}
.nav-toggle::before { top: 6px; }
.nav-toggle::after { bottom: 6px; }
.nav-toggle span { top: 50%; margin-top: -1px; }
@media (max-width: 900px) {
    .nav-inner > .nav-links { display: none; }
    .nav-inner { grid-template-columns: 1fr auto auto; }
    .nav-inner > .nav-links.open { display: grid; position: fixed; top: var(--header-h); right: 0; width: 260px; background: var(--card); grid-auto-flow: row; padding: 1rem; gap: 0; transform: translateX(0); box-shadow: -4px 4px 20px rgba(0,0,0,0.15); border: 1px solid var(--header-border); z-index: 999; }
    body.dir-rtl .nav-inner > .nav-links.open { right: auto; left: 0; }
    .nav-toggle { display: grid; place-items: center; }
}
@media (max-width: 768px) {
    .nav-links {
        position: fixed;
        top: var(--header-h);
        right: 0;
        width: 260px;
        background: var(--card);
        grid-auto-flow: row;
        padding: 1rem;
        gap: 0;
        transform: translateX(100%);
        transition: transform 0.3s;
        box-shadow: -4px 4px 20px rgba(0,0,0,0.15);
        border: 1px solid var(--header-border);
        z-index: 999;
    }
    body.dir-rtl .nav-links { right: auto; left: 0; transform: translateX(-100%); }
    .nav-links.open { transform: translateX(0); }
    body.dir-rtl .nav-links.open { transform: translateX(0); }
    .nav-links li { width: 100%; }
    .nav-links a, .nav-links .lang-switch { display: block; padding: 0.75rem; }
    .nav-links .lang-switch { display: flex; gap: 0.25rem; }
}

/* Main - centered grid layout */
.main-content {
    display: grid;
    grid-template-columns: 1fr;
    justify-items: center;
    padding-top: var(--header-h);
    min-height: calc(100vh - var(--header-h));
}
.main-content .section { width: 100%; max-width: 100%; box-sizing: border-box; }

.container {
    display: grid;
    justify-items: center;
    max-width: var(--container);
    width: 100%;
    margin: 0 auto;
    padding: 0 1.5rem;
    box-sizing: border-box;
}

/* Section common - grid-centered */
.section {
    display: grid;
    justify-items: center;
    padding: 5rem 0;
    transition: background 0.3s ease, color 0.3s ease;
}
.section > .container { justify-items: center; }
.section-title {
    font-size: clamp(1.75rem, 4vw, 2.5rem);
    font-weight: 800;
    margin: 0 0 2.5rem;
    text-align: center;
    color: var(--text);
    grid-column: 1 / -1;
}
.section.reveal { opacity: 0; transform: translateY(24px); transition: opacity 0.6s ease, transform 0.6s ease; }
.section.reveal.visible { opacity: 1; transform: translateY(0); }

/* Hero */
.section-hero {
    min-height: 100vh;
    display: grid;
    place-items: center;
    position: relative;
    padding: 6rem 1.5rem 4rem;
}
.hero-bg {
    position: absolute;
    inset: 0;
    overflow: hidden;
    background: var(--bg);
}
.hero-bg::before {
    content: '';
    position: absolute;
    inset: -50%;
    background:
        radial-gradient(ellipse 70% 50% at 30% 50%, rgba(56, 189, 248, 0.18) 0%, transparent 55%),
        radial-gradient(ellipse 60% 45% at 70% 40%, rgba(139, 92, 246, 0.2) 0%, transparent 50%),
        radial-gradient(ellipse 50% 40% at 50% 80%, rgba(56, 189, 248, 0.08) 0%, transparent 45%);
    animation: heroGradient 20s ease-in-out infinite alternate;
}
.hero-bg::after {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(circle at 50% 50%, rgba(56, 189, 248, 0.06) 0%, transparent 25%),
        linear-gradient(135deg, transparent 40%, rgba(139, 92, 246, 0.04) 100%);
    animation: heroShimmer 15s ease-in-out infinite;
}
.hero-bg .hero-grid {
    position: absolute;
    inset: 0;
    background-image: linear-gradient(rgba(56, 189, 248, 0.04) 1px, transparent 1px),
                      linear-gradient(90deg, rgba(56, 189, 248, 0.04) 1px, transparent 1px);
    background-size: 80px 80px;
    mask-image: radial-gradient(ellipse 80% 60% at 50% 50%, black 0%, transparent 70%);
    -webkit-mask-image: radial-gradient(ellipse 80% 60% at 50% 50%, black 0%, transparent 70%);
}
.hero-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.35;
    animation: heroOrb 25s ease-in-out infinite;
}
.hero-orb-1 { width: 400px; height: 400px; background: rgba(56, 189, 248, 0.25); top: 10%; left: 10%; animation-delay: 0s; }
.hero-orb-2 { width: 320px; height: 320px; background: rgba(139, 92, 246, 0.3); bottom: 20%; right: 15%; animation-delay: -8s; }
.hero-orb-3 { width: 240px; height: 240px; background: rgba(56, 189, 248, 0.2); top: 50%; left: 60%; animation-delay: -15s; }
[data-theme="light"] .hero-orb-1 { background: rgba(2, 132, 199, 0.2); }
[data-theme="light"] .hero-orb-2 { background: rgba(99, 102, 241, 0.2); }
[data-theme="light"] .hero-orb-3 { background: rgba(2, 132, 199, 0.15); }
[data-theme="light"] .hero-bg .hero-grid { background-image: linear-gradient(rgba(2, 132, 199, 0.06) 1px, transparent 1px), linear-gradient(90deg, rgba(2, 132, 199, 0.06) 1px, transparent 1px); }
@keyframes heroGradient {
    0% { transform: scale(1) rotate(0deg); opacity: 1; }
    100% { transform: scale(1.15) rotate(5deg); opacity: 0.9; }
}
@keyframes heroShimmer {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}
@keyframes heroOrb {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(30px, -20px) scale(1.05); }
    66% { transform: translate(-20px, 25px) scale(0.95); }
}
.hero-inner { position: relative; z-index: 1; text-align: center; max-width: 720px; width: 100%; }
.hero-name { font-size: clamp(2.5rem, 8vw, 4.5rem); font-weight: 800; margin: 0 0 0.5rem; letter-spacing: -0.02em; color: var(--text); }
.hero-title { font-size: clamp(1.1rem, 2.5vw, 1.35rem); color: var(--accent); margin: 0 0 1rem; font-weight: 500; }
.hero-summary { font-size: 1.1rem; color: var(--text-muted); margin: 0 0 1.5rem; line-height: 1.7; }
.hero-typing-wrap { font-size: 1.25rem; color: var(--text-muted); margin: 0 0 2rem; min-height: 1.5em; }
.hero-caret { color: var(--accent); animation: blink 1s step-end infinite; }
@keyframes blink { 50% { opacity: 0; } }
.btn { display: inline-block; padding: 0.85rem 2rem; font-family: var(--font); font-size: 1rem; font-weight: 600; border-radius: var(--radius); transition: transform 0.2s, box-shadow 0.2s; border: none; cursor: pointer; }
.btn-cta { background: linear-gradient(135deg, var(--accent), var(--accent-dim)); color: var(--btn-cta-text); }
.btn-cta:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(56, 189, 248, 0.35); }

/* About */
.about-content { max-width: 680px; width: 100%; justify-self: center; font-size: 1.1rem; color: var(--text-muted); text-align: center; }

/* Skills */
.skills-group { margin-bottom: 2.5rem; width: 100%; max-width: var(--container); justify-self: center; }
.skills-group:last-child { margin-bottom: 0; }
.skills-category { font-size: 1.15rem; font-weight: 700; color: var(--accent); margin: 0 0 1rem; text-align: center; }
.skills-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 1rem; }
.skill-card {
    background: var(--card);
    border: 1px solid var(--skill-border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    text-align: center;
    font-weight: 500;
    transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.3s ease, background 0.3s ease;
}
.skill-card:hover { transform: translateY(-4px); box-shadow: 0 8px 24px rgba(56, 189, 248, 0.15); }

/* Timeline (experience & education) */
.timeline { position: relative; max-width: 700px; width: 100%; justify-self: center; }
.timeline::before { content: ''; position: absolute; top: 0; bottom: 0; width: 2px; background: linear-gradient(180deg, var(--accent), var(--purple-glow)); border-radius: 2px; }
body.dir-rtl .timeline::before { right: 11px; left: auto; }
body.dir-ltr .timeline::before { left: 11px; }
.timeline-item { position: relative; padding-bottom: 2rem; padding-inline-start: 2.5rem; }
body.dir-rtl .timeline-item { padding-inline-start: 0; padding-inline-end: 2.5rem; }
.timeline-marker {
    position: absolute;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 12px var(--accent);
    top: 0.25rem;
}
body.dir-rtl .timeline-marker { right: 6px; left: auto; }
body.dir-ltr .timeline-marker { left: 6px; }
.timeline-content { background: var(--card); border-radius: var(--radius); padding: 1.5rem; border: 1px solid var(--card-border); transition: background 0.3s ease, border-color 0.3s ease; }
.timeline-role { margin: 0 0 0.25rem; font-size: 1.2rem; color: var(--text); }
.timeline-company { margin: 0; font-weight: 600; color: var(--accent); }
.timeline-period { margin: 0 0 0.5rem; font-size: 0.9rem; color: var(--text-muted); }
.timeline-desc { margin: 0; font-size: 0.95rem; color: var(--text-muted); }

/* Certificates */
.cert-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1.5rem; width: 100%; max-width: var(--container); justify-self: center; }
.cert-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 1.5rem;
    border: 1px solid var(--card-border);
    transition: transform 0.25s ease, box-shadow 0.25s ease, background 0.3s ease, border-color 0.3s ease;
}
.cert-card:hover { transform: translateY(-4px); box-shadow: 0 12px 28px rgba(0,0,0,0.15); }
.cert-img-wrap { margin: -1.5rem -1.5rem 1rem; border-radius: var(--radius) var(--radius) 0 0; overflow: hidden; }
.cert-img-wrap img { width: 100%; height: 160px; object-fit: cover; display: block; }
.cert-name { margin: 0 0 0.35rem; font-size: 1.15rem; color: var(--text); }
.cert-issuer, .cert-date { margin: 0; font-size: 0.9rem; color: var(--text-muted); }
.cert-link { display: inline-block; margin-top: 0.75rem; font-weight: 600; }

/* Projects - 3D hover card */
.projects-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1.5rem; width: 100%; max-width: var(--container); justify-self: center; }
.project-card { margin: 0; cursor: pointer; perspective: 800px; }
.project-card-inner {
    background: var(--card);
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--card-border);
    transition: transform 0.4s ease, box-shadow 0.4s ease, background 0.3s ease, border-color 0.3s ease;
    transform-style: preserve-3d;
}
.project-card:hover .project-card-inner {
    transform: rotateY(-4deg) rotateX(2deg) translateZ(8px);
    box-shadow: 0 16px 40px rgba(56, 189, 248, 0.12), 0 0 0 1px rgba(56, 189, 248, 0.1);
}
.project-img { height: 200px; background: linear-gradient(135deg, var(--card) 0%, var(--bg) 100%); overflow: hidden; transition: background 0.3s ease; }
.project-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.project-img-placeholder { background: linear-gradient(135deg, rgba(56, 189, 248, 0.12), rgba(139, 92, 246, 0.12)); }
[data-theme="light"] .project-img-placeholder { background: linear-gradient(135deg, rgba(2, 132, 199, 0.08), rgba(99, 102, 241, 0.08)); }
.project-name { margin: 0; padding: 1.25rem 1.5rem; font-size: 1.15rem; color: var(--text); }

/* Contact */
.contact-inner { max-width: 480px; width: 100%; justify-self: center; text-align: center; }
.contact-item { margin: 0 0 0.75rem; font-size: 1.05rem; color: var(--text-muted); }
.contact-item a { color: var(--accent); }

/* Footer */
.site-footer { padding: 2rem 1.5rem; text-align: center; border-top: 1px solid var(--footer-border); width: 100%; transition: border-color 0.3s ease; }
.footer-copy { margin: 0; font-size: 0.9rem; color: var(--text-muted); }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 2000; display: flex; align-items: center; justify-content: center; padding: 1.5rem; opacity: 0; visibility: hidden; transition: opacity 0.3s ease, visibility 0.3s ease; }
.modal.open { opacity: 1; visibility: visible; }
.modal[hidden] { display: none !important; }
.modal.open[hidden] { display: flex !important; }
.modal-backdrop { position: absolute; inset: 0; background: var(--modal-backdrop); cursor: pointer; transition: background 0.3s ease; }
.modal-box {
    position: relative;
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    max-width: 520px;
    width: 100%;
    max-height: 85vh;
    overflow: auto;
    padding: 2rem;
    box-shadow: 0 24px 48px rgba(0,0,0,0.25);
    transform: scale(0.95);
    transition: transform 0.3s ease, background 0.3s ease, border-color 0.3s ease;
}
.modal.open .modal-box { transform: scale(1); }
.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    border-radius: 50%;
    transition: color 0.2s, background 0.2s;
}
body.dir-rtl .modal-close { right: auto; left: 1rem; }
.modal-close:hover { color: var(--text); background: var(--card); }
.modal-title { margin: 0 0 1rem; font-size: 1.5rem; color: var(--text); }
.modal-body { margin: 0 0 1rem; color: var(--text-muted); line-height: 1.7; }
.modal-tech { margin: 0 0 1rem; font-size: 0.9rem; color: var(--accent); }
.modal-link { display: inline-block; font-weight: 600; }
