:root {
    /* === SYSTEM DEFAULT: LIGHT MODE (Premium Scientific) === */
    --primary-color: #2563eb;
    /* Royal Blue */
    --secondary-color: #4f46e5;
    /* Indigo */
    --accent-red: #dc2626;
    /* Red */
    --bg-main: #f0f4f8;
    /* Soft Blue-Grey background */
    --bg-card: #ffffff;
    /* Pure White */
    --glass-bg: rgba(255, 255, 255, 0.75);
    --glass-border: rgba(203, 213, 225, 0.6);
    --text-main: #1e293b;
    /* Slate 800 */
    --text-muted: #64748b;
    /* Slate 500 */
    --shadow-soft: 0 10px 30px -10px rgba(0, 0, 0, 0.1);
    --shadow-glow: 0 0 15px rgba(37, 99, 235, 0.2);

    /* Fonts */
    --font-ar: 'Tajawal', sans-serif;
    --font-en: 'Outfit', sans-serif;
}

@import url('css_dropdown.css');

[data-theme="dark"] {
    --primary-color: #00f2ff;
    /* Cyan Neon */
    --secondary-color: #7000ff;
    /* Purple Neon */
    --accent-red: #ff0055;
    --bg-main: #0f172a;
    /* Slate 900 */
    --bg-card: #1e293b;
    /* Slate 800 */
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-main: #e2e8f0;
    --text-muted: #94a3b8;
    --shadow-soft: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px rgba(0, 242, 255, 0.2);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font-en);
}

body {
    background: var(--bg-main);
    color: var(--text-main);
    min-height: 100vh;
    font-family: var(--font-ar);
    line-height: 1.6;
    overflow-x: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Light Mode Background Decoration */
body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at top right, var(--primary-color), transparent 70%),
        radial-gradient(circle at bottom left, var(--secondary-color), transparent 70%);
    opacity: 0.08;
    /* Subtle on light mode */
    z-index: -1;
    pointer-events: none;
}

[data-theme="dark"] body::before {
    opacity: 0.15;
}

/* === Layout === */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.main-grid {
    display: grid;
    grid-template-columns: 280px 1fr 280px;
    gap: 30px;
    padding: 20px;
    flex: 1;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

/* === Navigation === */
.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 5%;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--glass-border);
    position: sticky;
    top: 0;
    z-index: 100;
    transition: background 0.3s;
}

[data-theme="dark"] .navbar {
    background: rgba(15, 23, 42, 0.6);
}

.logo {
    font-size: 1.6rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-main);
    letter-spacing: -0.5px;
}

.logo i {
    color: var(--primary-color);
    filter: drop-shadow(0 0 5px var(--primary-color));
}

.nav-links {
    display: flex;
    gap: 20px;
    align-items: center;
}

/* Language Selector */
.lang-select-container {
    position: relative;
    display: flex;
    align-items: center;
}

#lang-select {
    padding: 8px 12px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    background: var(--bg-card);
    color: var(--text-main);
    cursor: pointer;
    font-family: var(--font-en);
    font-size: 0.9rem;
    outline: none;
    transition: all 0.2s;
}

#lang-select:hover {
    border-color: var(--primary-color);
}

.nav-links a {
    text-decoration: none;
    color: var(--text-muted);
    font-weight: 600;
    transition: color 0.3s;
    font-family: var(--font-ar);
    font-size: 0.95rem;
}

.nav-links a:hover,
.nav-links a.active {
    color: var(--primary-color);
}

/* === Calculator Core === */
.calculator-wrapper {
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.calculator-glass {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 32px;
    padding: 30px;
    width: 100%;
    max-width: 480px;
    box-shadow: var(--shadow-soft);
    transition: transform 0.3s ease, box-shadow 0.3s;
}

.calculator-glass:hover {
    box-shadow: 0 30px 60px -15px rgba(0, 0, 0, 0.15);
}

[data-theme="dark"] .calculator-glass:hover {
    box-shadow: 0 30px 60px -15px rgba(0, 0, 0, 0.6);
}

.calc-display {
    background: var(--bg-card);
    border-radius: 20px;
    padding: 24px;
    margin-bottom: 24px;
    text-align: right;
    border: 1px solid var(--glass-border);
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.03);
}

[data-theme="dark"] .calc-display {
    background: rgba(0, 0, 0, 0.3);
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.5);
}

.history-view {
    font-size: 0.9rem;
    color: var(--text-muted);
    height: 1.5rem;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: 'Courier New', monospace;
}

.current-input {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-main);
    font-size: 2.8rem;
    text-align: right;
    font-family: var(--font-en);
    outline: none;
    font-weight: 500;
}

.result-preview {
    height: 1.4rem;
    font-size: 1.1rem;
    color: var(--text-muted);
    opacity: 0.7;
    font-weight: 500;
}

/* Controls */
.calc-controls {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
    align-items: center;
}

.mode-toggles {
    background: rgba(0, 0, 0, 0.05);
    /* Light mode toggle bg */
    border-radius: 12px;
    padding: 4px;
    display: flex;
    gap: 4px;
}

[data-theme="dark"] .mode-toggles {
    background: rgba(255, 255, 255, 0.05);
}

.mode-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 6px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 700;
    transition: all 0.2s;
    font-family: var(--font-en);
}

.mode-btn.active {
    background: var(--bg-card);
    color: var(--primary-color);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] .mode-btn.active {
    background: var(--primary-color);
    color: #000;
}

.icon-btn,
.history-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s;
}

.icon-btn:hover,
.history-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--primary-color);
}

[data-theme="dark"] .icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Keyboard */
.calc-keyboard {
    display: grid;
    gap: 12px;
}

.key-group {
    display: grid;
    gap: 12px;
}

.basic {
    grid-template-columns: repeat(4, 1fr);
}

.scientific {
    grid-template-columns: repeat(5, 1fr);
    margin-bottom: 8px;
}

/* Buttons */
.btn {
    height: 52px;
    border: none;
    border-radius: 16px;
    font-size: 1.25rem;
    cursor: pointer;
    background: var(--bg-card);
    color: var(--text-main);
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.02);
    border: 1px solid var(--glass-border);
    transition: all 0.15s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
    font-weight: 500;
}

[data-theme="dark"] .btn {
    background: rgba(255, 255, 255, 0.03);
    box-shadow: none;
}

.btn:active {
    transform: translateY(2px);
    box-shadow: none !important;
}

.btn:hover {
    background: #f8fafc;
    border-color: var(--primary-color);
    color: var(--primary-color);
}

[data-theme="dark"] .btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn.action-scifi {
    grid-row: span 2;
    height: auto;
    background: var(--primary-color);
    color: white;
    box-shadow: 0 4px 15px rgba(37, 99, 235, 0.3);
    border: none;
}

[data-theme="dark"] .btn.action-scifi {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    box-shadow: var(--shadow-glow);
}

.btn.action-scifi:hover {
    filter: brightness(1.1);
    color: white;
}

.btn.action-red {
    color: var(--accent-red);
    background: rgba(220, 38, 38, 0.05);
    border-color: rgba(220, 38, 38, 0.2);
}

[data-theme="dark"] .btn.action-red {
    background: rgba(255, 0, 85, 0.1);
    border-color: transparent;
}

.btn.op {
    color: var(--primary-color);
    font-size: 1.4rem;
    background: rgba(37, 99, 235, 0.05);
}

[data-theme="dark"] .btn.op {
    background: rgba(255, 255, 255, 0.03);
}

.btn.func {
    font-size: 0.85rem;
    height: 42px;
    color: var(--text-muted);
    font-weight: 600;
    border-radius: 12px;
}

/* === Ads & History === */
.ad-space {
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Ad Container */
.ad-container {
    background: transparent;
    width: 100%;
    min-height: 250px;
    display: flex;
    justify-content: center;
    border-radius: 16px;
    overflow: hidden;
}

[data-theme="dark"] .ad-container {
    background: rgba(255, 255, 255, 0.01);
}

.history-panel {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    padding: 24px;
    border-radius: 24px;
    max-height: 500px;
    overflow-y: auto;
    position: relative;
}

.history-panel h3 {
    margin-bottom: 15px;
    font-size: 1.1rem;
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 12px;
    color: var(--text-main);
}

#full-history-list div {
    padding: 12px;
    border-bottom: 1px solid var(--glass-border);
    font-size: 0.95rem;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s;
    margin-bottom: 4px;
}

#full-history-list div:hover {
    background: rgba(0, 0, 0, 0.03);
    color: var(--primary-color);
}

[data-theme="dark"] #full-history-list div:hover {
    background: rgba(255, 255, 255, 0.05);
}

#clear-history {
    margin-top: 15px;
    width: 100%;
    padding: 10px;
    background: var(--bg-card);
    color: var(--accent-red);
    border: 1px solid rgba(220, 38, 38, 0.2);
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

#clear-history:hover {
    background: var(--accent-red);
    color: white;
}

/* === SEO Content === */
.seo-content {
    background: var(--bg-card);
    padding: 80px 20px;
    margin-top: 60px;
    border-top: 1px solid var(--glass-border);
    text-align: center;
}

[data-theme="dark"] .seo-content {
    background: var(--bg-main);
}

.content-container {
    max-width: 1000px;
    margin: 0 auto;
}

.seo-content h1 {
    font-size: 2.8rem;
    margin-bottom: 24px;
    color: var(--text-main);
    font-weight: 900;
}

.seo-content p {
    color: var(--text-muted);
    font-size: 1.1rem;
    max-width: 700px;
    margin: 0 auto;
}

.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 40px;
    margin: 60px 0;
}

.feature-card {
    background: var(--bg-main);
    padding: 40px;
    border-radius: 24px;
    border: 1px solid transparent;
    transition: all 0.3s;
}

[data-theme="dark"] .feature-card {
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
}

.feature-card:hover {
    transform: translateY(-8px);
    border-color: var(--primary-color);
}

.feature-card i {
    font-size: 3rem;
    color: var(--primary-color);
    margin-bottom: 24px;
    background: rgba(37, 99, 235, 0.1);
    width: 80px;
    height: 80px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 20px;
    margin-left: auto;
    margin-right: auto;
}

.long-content {
    text-align: right;
    line-height: 2;
    color: var(--text-muted);
    background: var(--bg-main);
    padding: 40px;
    border-radius: 24px;
    margin-top: 40px;
}

[data-theme="dark"] .long-content {
    background: var(--bg-card);
}

.long-content h2 {
    color: var(--text-main);
    margin: 30px 0 15px 0;
    font-size: 1.8rem;
}

/* === Footer === */
footer {
    padding: 50px 20px;
    border-top: 1px solid var(--glass-border);
    text-align: center;
    color: var(--text-muted);
    background: var(--bg-main);
}

[data-theme="dark"] footer {
    background: #020617;
}

.footer-links {
    margin-bottom: 25px;
    display: flex;
    justify-content: center;
    gap: 30px;
}

.footer-links a {
    color: var(--text-main);
    text-decoration: none;
    font-weight: 600;
}

/* === Responsive === */
@media (max-width: 1024px) {
    .main-grid {
        grid-template-columns: 1fr;
    }

    .left-ad,
    .right-ad {
        display: none;
    }
}

@media (max-width: 480px) {
    .calculator-glass {
        padding: 20px;
        border-radius: 24px;
        background: var(--bg-card);
        /* Less transparency on mobile */
    }

    [data-theme="dark"] .calculator-glass {
        background: rgba(30, 41, 59, 0.8);
    }

    .current-input {
        font-size: 2.2rem;
    }

    .btn {
        height: 48px;
        font-size: 1.1rem;
    }

    .seo-content h1 {
        font-size: 2rem;
    }

    .logo span {
        font-size: 1.2rem;
    }
}