/* ========== RESET & VARIABLES ========== */
:root {
    --bg: #0f1115;
    /* بدل glass شفاف + blur -> خلفيات شبه صلبة بنفس الإحساس اللوني من غير تكلفة blur */
    --glass: #1a1d24;
    --glass-solid: #1a1d24;
    --border: rgba(255, 255, 255, 0.12);
    --text: #f0f0f5;
    --accent: #00bcd4;
    --accent-glow: rgba(0, 188, 212, 0.4);
    --font-size: 16px;
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --logo-color: #00bcd4;
    --text-color: #f0f0f5;
    --font-weight: 400;
    --card-radius: 16px;
}

body.light {
    --bg: #f5f5f7;
    --glass: #ffffff;
    --glass-solid: #ffffff;
    --border: rgba(0, 0, 0, 0.1);
    --text: #1a1a1a;
    --text-color: #1a1a1a;
    --logo-color: #00838f;
    --accent-glow: rgba(0, 140, 158, 0.25);
}

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

body {
    font-family: var(--font-family);
    background: var(--bg);
    color: var(--text-color);
    min-height: 100vh;
    font-size: var(--font-size);
    font-weight: var(--font-weight);
    padding-bottom: 80px;
}

/* ========== SCROLLBAR ========== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--glass); border-radius: 10px; }
::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #00acc1; }
* { scrollbar-width: thin; scrollbar-color: var(--accent) var(--glass); }

/* ========== NAVBAR ========== */
.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 5%;
    background: var(--glass);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.logo-img {
    height: 40px;
    width: auto;
}

.logo-img:hover { transform: scale(1.05); }

.logo-text {
    font-weight: 700;
    font-size: 1.8rem;
    color: var(--logo-color);
}

.search-container {
    position: relative;
    display: flex;
    align-items: center;
    background: var(--bg);
    border-radius: 20px;
    border: 1px solid var(--border);
    padding: 0 16px;
    width: 650px;
    max-width: 45vw;
}

.search-container:focus-within {
    border-color: var(--accent);
}

.search-icon {
    width: 20px;
    height: 20px;
    cursor: pointer;
    opacity: 0.8;
}

.search-icon:hover { opacity: 1; }

.search {
    flex: 1;
    padding: 12px 0;
    border: none;
    background: transparent;
    color: inherit;
    outline: none;
    font-size: 15px;
    font-family: inherit;
}

.controls {
    display: flex;
    gap: 10px;
    align-items: center;
    position: relative;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
}

.icon-btn:hover {
    background: var(--bg);
    transform: scale(1.08);
}

.icon-btn:active { transform: scale(0.95); }

/* ========== SETTINGS MENU ========== */
.settings-menu {
    position: absolute;
    top: 50px;
    right: 0;
    background: var(--glass-solid);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 10px;
    min-width: 220px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.35);
    z-index: 1001;
    opacity: 0;
    transform: translateY(-8px);
    visibility: hidden;
    transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
    transform-origin: top right;
}

.settings-menu.show {
    opacity: 1;
    transform: translateY(0);
    visibility: visible;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 15px;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    color: var(--text-color);
}

.menu-item:hover {
    background: var(--accent);
    color: #000;
}

.menu-item img { width: 24px; height: 24px; filter: brightness(0.9); }
.menu-item:hover img { filter: brightness(0) invert(1); }

[dir="rtl"] .settings-menu { right: auto; left: 0; transform-origin: top left; }

/* ========== GRID & CARDS ========== */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
    padding: 25px 5%;
}

.card {
    background: var(--glass);
    border: 1px solid var(--border);
    border-radius: var(--card-radius);
    overflow: hidden;
    transition: border-color 0.15s ease;
    cursor: pointer;
    text-align: center;
    /* تخطي رسم الكروت خارج الشاشة - أهم تحسين مع شبكات طويلة */
    content-visibility: auto;
    contain-intrinsic-size: 220px 260px;
    contain: layout paint;
}

.card:hover {
    border-color: var(--accent);
}

.card:active { transform: scale(0.98); }

.filename {
    padding: 12px;
    font-weight: 500;
    font-size: 0.9em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* فولدر فنان (جوه Music/) - صورة الفنان بدل أيقونة 📁 العادية، بنفس
   مقاس صورة/معاينة كارت الملف عشان الشكل يفضل متسق مع باقي الكروت. */
.dir-thumb {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
}

/* بانر اسم وصورة الفنان - ظاهر فوق قائمة أغانيه جوه Music/<فنان> أو أي
   ألبوم جواه. */
.artist-banner {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 5%;
}
.artist-banner img {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    object-fit: cover;
}
.artist-banner span {
    font-size: 1.3em;
    font-weight: 600;
}

/* ========== MODALS ==========
   دمجت القواعد المكررة اللي كانت بتستهدف نفس العناصر مرتين */
.modal-overlay,
#langModal.modal-overlay,
#storageOverlay,
#fontsModal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.75);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.2s ease;
}

body.light .modal-overlay,
body.light #langModal.modal-overlay,
body.light #storageOverlay,
body.light #fontsModal {
    background: rgba(0, 0, 0, 0.45);
}

#langModal.modal-overlay.show,
#storageOverlay.show,
#fontsModal.show,
#appModal.show {
    display: flex;
    opacity: 1;
}

.lang-modal {
    background: var(--glass-solid);
    border: 1px solid var(--border);
    box-shadow: 0 8px 28px rgba(0,0,0,0.35);
    border-radius: 24px;
    padding: 25px;
    position: relative;
    transform: scale(0.95);
    opacity: 0;
    width: 350px;
    max-width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

#storageOverlay.show .lang-modal,
#langModal.modal-overlay.show .lang-modal,
#fontsModal.show .lang-modal,
#appModal.show .lang-modal {
    transform: scale(1);
    opacity: 1;
}

.modal-close-btn {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s ease;
    margin-top: 15px;
    margin-left: auto;
    margin-right: auto;
}

.modal-close-btn:hover {
    background: var(--accent);
}

/* ========== BREADCRUMB ========== */
.breadcrumb {
    padding: 10px 5%;
    color: #888;
    font-size: 14px;
}
.breadcrumb span {
    cursor: pointer;
    color: var(--accent);
}
.breadcrumb span:hover { opacity: 0.8; }

/* ========== AUDIO PLAYER BAR ========== */
#audioPlayerBar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--glass-solid);
    border-top: 1px solid var(--border);
    padding: 12px 16px;
    z-index: 9999;
    transform: translateY(100%);
    transition: transform 0.25s ease;
}

#audioPlayerBar.show { transform: translateY(0); }

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

.audio-info { flex: 1; min-width: 150px; }
.audio-title { font-weight: 600; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.audio-buttons { display: flex; gap: 12px; align-items: center; }
.audio-buttons .icon-btn { width: 40px; height: 40px; }
.audio-progress { flex: 2; min-width: 200px; }

.progress-slider {
    width: 100%;
    height: 4px;
    -webkit-appearance: none;
    background: var(--border);
    border-radius: 2px;
    outline: none;
}

.progress-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
}

.progress-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

/* ========== PLAYLIST PANEL ========== */
#playlistPanel {
    position: fixed;
    top: 70px;
    right: 16px;
    left: auto;
    bottom: 80px;
    width: 400px;
    background: var(--glass-solid);
    border-radius: 24px;
    border: 1px solid var(--border);
    z-index: 9998;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#playlistPanel.show { transform: translateX(0); }

.playlist-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.playlist-header h3 { margin: 0; font-size: 1.2rem; color: var(--accent); }

.playlist-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s ease;
}

.playlist-close:hover {
    background: var(--accent);
}

.playlist-items-container { flex: 1; overflow-y: auto; padding: 8px; }

.playlist-item {
    padding: 12px 16px;
    margin: 4px 0;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background 0.15s ease, color 0.15s ease;
    border-radius: 12px;
    content-visibility: auto;
    contain-intrinsic-size: 48px;
}

.playlist-item:hover {
    background: var(--accent);
    color: #000;
}

.playlist-item.active {
    background: var(--accent);
    color: #000;
}

.playlist-item-number {
    width: 30px;
    font-weight: bold;
    color: var(--accent);
}
.playlist-item.active .playlist-item-number { color: #000; }
.playlist-item-info { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.playlist-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
}

.playlist-footer button {
    width: 100%;
    padding: 10px;
    border-radius: 20px;
    border: none;
    cursor: pointer;
    font-weight: bold;
    background: #d9463a;
    color: white;
    transition: background 0.15s ease;
}

.playlist-footer button:hover {
    background: #f44336;
}

.drag-handle { cursor: grab; opacity: 0.6; font-size: 20px; user-select: none; }
.drag-handle:active { cursor: grabbing; }

/* ========== STORAGE ========== */
#storageFill {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 10px;
    color: #fff;
    font-weight: bold;
    border-radius: 8px;
    height: 100%;
    transition: width 0.25s ease, background 0.25s ease;
}

/* ========== FONT CONTROLS ========== */
.font-section {
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 15px;
}

.font-section h4 { margin: 0 0 10px 0; color: var(--accent); font-size: 1.1em; }

.font-control {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 10px 0;
    flex-wrap: wrap;
}

.font-control label { min-width: 80px; font-size: 0.9em; opacity: 0.9; }
.font-control input[type="range"] { flex: 1; height: 5px; background: var(--border); border-radius: 5px; outline: none; }
.font-control input[type="color"] { width: 50px; height: 40px; border: 1px solid var(--border); border-radius: 8px; background: transparent; cursor: pointer; }
.font-control select { flex: 1; padding: 8px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 12px; color: inherit; font-family: inherit; cursor: pointer; }

.toggle-btn {
    padding: 8px 16px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: inherit;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.toggle-btn.active { background: var(--accent); color: #000; border-color: var(--accent); }
.toggle-btn:hover { transform: scale(1.03); }
.toggle-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ========== PiZone App Modal ========== */
.app-instructions {
    text-align: center;
    line-height: 1.8;
    margin: 16px 0;
    font-size: 0.9em;
    opacity: 0.9;
}
.app-download-btn { width: 100%; padding: 12px 16px; font-size: 1em; }
.app-download-size { font-size: 0.8em; opacity: 0.6; text-align: center; margin-top: 8px; }

.lang-option, .font-option {
    padding: 12px;
    margin: 8px 0;
    border-radius: 12px;
    cursor: pointer;
    border: 1px solid var(--border);
    transition: background 0.15s ease, color 0.15s ease;
    background: var(--bg);
    text-align: center;
}

.lang-option:hover, .font-option:hover {
    background: var(--accent);
    color: #000;
    border-color: var(--accent);
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
    .navbar { flex-wrap: wrap; gap: 10px; padding: 10px 3%; }
    .search-container { width: 100%; max-width: 100%; order: 3; }
    .controls { order: 2; }
    .logo-container { order: 1; }
    .grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 12px;
        padding: 15px 3%;
    }
    #playlistPanel { width: calc(100% - 32px); left: 16px; right: 16px; }
    .audio-controls { flex-wrap: wrap; }
    .audio-info { min-width: 100px; }
    .audio-progress { min-width: 120px; }
}

@media (max-width: 480px) {
    .grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        padding: 10px 2%;
    }
    .icon-btn { width: 36px; height: 36px; }
    .logo-text { font-size: 1.3rem; }
    .logo-img { height: 32px; }
    .card { border-radius: 12px; }
    .filename { font-size: 0.8em; padding: 8px; }
}

/* احترام إعدادات الجهاز لتقليل الحركة */
@media (prefers-reduced-motion: reduce) {
    * { transition-duration: 0.001ms !important; animation-duration: 0.001ms !important; }
}
