:root {
    /* Color Palette - v4.51 Restored */
    --bg-deep: #0f172a;
    --bg-surface: #1e293b;
    --bg-elevated: #334155;

    --accent: #38bdf8;
    --accent-glow: rgba(56, 189, 248, 0.4);
    --accent-dim: #0ea5e9;

    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;

    --glass-bg: rgba(15, 23, 42, 0.8);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.5);

    --header-h: 72px;
    --radius-lg: 20px;
    --radius-md: 12px;
    --radius-sm: 8px;

    --font-main: 'Assistant', 'Outfit', sans-serif;
}

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

body {
    font-family: var(--font-main);
    background: var(--bg-deep);
    color: var(--text-primary);
    height: 100vh;
    direction: rtl;
    /* Removed restrictive touch-action to allow pinch zoom */
    touch-action: manipulation;
    overflow: hidden;
    position: fixed;
    /* Stop elastic scroll on Safari */
    width: 100%;
}

/* Utilities */
.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
}

/* Header */
.app-header {
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 100;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to bottom, rgba(10, 10, 12, 0.9) 0%, rgba(10, 10, 12, 0) 100%);
}

.header-right {
    display: flex;
    flex-direction: column;
}

.app-title {
    font-size: 1.4rem;
    font-weight: 800;
    background: linear-gradient(45deg, #fff, var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
}

.version-tag {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-weight: 600;
    margin-top: -2px;
}

.header-center {
    max-width: 50%;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

#currentSongTitle {
    font-size: 1.05rem;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.active-vote-btn {
    background: var(--glass-bg);
    border: 1px solid var(--accent);
    color: white;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.1rem;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.active-vote-btn:active {
    transform: scale(0.9);
    background: var(--accent);
}

.active-vote-btn.hidden {
    display: none;
}

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

.header-left {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.leader-btn {
    background: var(--bg-elevated);
    border: 1px solid var(--glass-border);
    color: white;
    padding: 8px 16px;
    border-radius: var(--radius-lg);
    font-family: inherit;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    gap: 6px;
}

.leader-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 0 20px var(--accent-glow);
}

.viewer-count {
    background: rgba(255, 255, 255, 0.05);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Main Viewer */
.app-main {
    height: 100vh;
    padding-top: var(--header-h);
    position: relative;
    overflow: hidden;
}

.song-viewer {
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
    background: #000;
}

.viewer-container {
    width: 100%;
    height: 100%;
    overflow: auto;
    position: relative;
    /* Fully Native Scroll and Zoom */
    scrollbar-width: none;
    -ms-overflow-style: none;
    -webkit-overflow-scrolling: touch;
}

.viewer-container::-webkit-scrollbar {
    display: none;
}

.song-display {
    width: 100%;
    height: 100%;
    min-width: 100%;
    min-height: 100%;
    transform-origin: top left;
    will-change: transform;
    /* Prevent text selection during drag */
    user-select: none;
    -webkit-user-select: none;
}

.song-display iframe {
    display: block;
    width: 100%;
    height: 100%;
    border: none;
    background: white;
}

.song-display img {
    display: block;
    width: 100%;
    height: auto;
    filter: contrast(1.05) brightness(1.02);
}

/* Song Selector */
.song-selector-panel {
    position: fixed;
    inset: 0;
    background: var(--bg-deep);
    z-index: 200;
    display: flex;
    flex-direction: column;
    transition: transform 0.5s cubic-bezier(0.32, 0.72, 0, 1);
}

.song-selector-panel.hidden {
    transform: translateY(100%);
}

.panel-header {
    padding: 24px 20px 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.search-wrapper {
    position: relative;
    flex: 1;
    margin-top: 10px;
    /* Space from close button */
}

.song-search-input {
    width: 100%;
    padding: 14px 20px;
    border-radius: var(--radius-md);
    border: 1px solid var(--glass-border);
    background: var(--bg-surface);
    color: white;
    font-family: inherit;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

.song-search-input:focus {
    border-color: var(--accent);
}

.sort-wrapper {
    display: flex;
    justify-content: flex-end;
}

.song-sort-select {
    padding: 8px 16px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.9rem;
    outline: none;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: all 0.2s ease;
    direction: ltr;
    /* Keeps the arrow cleanly on the right */
}

.song-sort-select:focus,
.song-sort-select:hover {
    border-color: var(--accent);
    color: white;
}

.song-sort-select option {
    background: var(--bg-deep);
    /* Dark background for the dropdown menu items */
    color: white;
    direction: rtl;
    /* Hebrew rendering */
}

.highlight {
    background-color: rgba(241, 196, 15, 0.3);
    color: #f1c40f;
    font-weight: 700;
    border-radius: 3px;
    padding: 0 2px;
}

.close-panel-btn {
    position: absolute;
    top: 24px;
    left: 20px;
    background: var(--bg-elevated);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.song-list-container {
    flex: 1;
    overflow-y: auto;
    padding: 0 20px 100px;
}

.song-item {
    padding: 16px;
    background: var(--bg-surface);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    margin-bottom: 12px;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.song-title {
    flex: 1;
}

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

.vote-badge {
    font-size: 0.9rem;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.05);
    padding: 4px 10px;
    border-radius: 20px;
    transition: all 0.2s;
}

.vote-badge.has-votes {
    color: white;
    background: var(--accent);
    font-weight: 600;
}

.vote-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.vote-btn:hover {
    background: rgba(52, 152, 219, 0.2);
    border-color: var(--accent);
    transform: scale(1.1);
}

.vote-btn:active {
    transform: scale(0.9);
}

.song-item:active {
    transform: scale(0.98);
    background: var(--bg-elevated);
}

.song-title {
    font-weight: 600;
    font-size: 1.1rem;
}

.song-item-arrow {
    color: var(--text-muted);
}

.header-icon-btn {
    background: var(--bg-elevated);
    border: 1px solid var(--glass-border);
    color: white;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.4rem;
    transition: all 0.2s ease;
}

.header-icon-btn:active {
    transform: scale(0.9);
    background: var(--accent);
}

/* Control Drawer */
.control-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: 280px;
    height: 100vh;
    z-index: 300;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
}

.control-drawer.hidden {
    transform: translateX(100%);
}

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

.drawer-header h3 {
    font-size: 1.2rem;
    font-weight: 700;
}

.close-icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
}

.drawer-btn {
    width: 100%;
    padding: 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.03);
    color: white;
    font-family: inherit;
    font-weight: 600;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 12px;
}

.drawer-btn:active {
    background: var(--accent);
    transform: scale(0.98);
}

.drawer-btn.active {
    background: var(--accent);
    box-shadow: 0 0 15px var(--accent-glow);
}

/* Toast */
.toast-container {
    position: fixed;
    top: 90px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    width: calc(100% - 40px);
    max-width: 400px;
}

.toast {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    color: white;
    padding: 14px 20px;
    border-radius: var(--radius-md);
    margin-bottom: 10px;
    font-weight: 500;
    text-align: center;
    animation: slideDown 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

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

.follow-leader-btn {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: white;
    padding: 12px 24px;
    border-radius: var(--radius-full);
    font-family: inherit;
    font-weight: 700;
    font-size: 1rem;
    box-shadow: 0 4px 15px var(--accent-glow);
    border: 1px solid rgba(255, 255, 255, 0.2);
    z-index: 1000;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.follow-leader-btn.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 20px);
}

/* What's New Modal */
.whats-new-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.whats-new-modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.whats-new-content {
    background: var(--bg-elevated);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: 30px;
    width: 90%;
    max-width: 400px;
    text-align: right;
    direction: rtl;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    transform: translateY(0);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.whats-new-modal.hidden .whats-new-content {
    transform: translateY(20px);
}

.whats-new-content h2 {
    font-size: 1.5rem;
    margin-bottom: 16px;
    color: var(--accent);
}

.whats-new-content ul {
    list-style-type: none;
    padding: 0;
    margin-bottom: 24px;
}

.whats-new-content li {
    margin-bottom: 12px;
    font-size: 1rem;
    line-height: 1.5;
    color: var(--text-secondary);
}

.whats-new-content li strong {
    color: var(--text-primary);
}

.whats-new-btn {
    width: 100%;
    padding: 14px;
    border-radius: var(--radius-md);
    border: none;
    background: linear-gradient(135deg, var(--accent), #9b59b6);
    color: white;
    font-weight: 700;
    font-size: 1.1rem;
    cursor: pointer;
    transition: transform 0.2s;
}

.whats-new-btn:active {
    transform: scale(0.97);
}