/* ═══════════════════════════════════════════════════════════════════
   Audio Player MP3 — Front-end Player Styles
   Dark theme (default) + Light theme
   Cross-browser: Chrome, Firefox, Safari, Edge, iOS, Android
   ═══════════════════════════════════════════════════════════════════ */

/* ── CSS Custom Properties ──────────────────────────────────────── */
:root,
[data-apm-theme="dark"] {
    --apm-bg         : #0d0d1a;
    --apm-surface    : #16162a;
    --apm-surface2   : #1e1e36;
    --apm-surface3   : #252540;
    --apm-border     : rgba(255,255,255,0.08);
    --apm-primary    : #7c3aed;
    --apm-primary-l  : #a78bfa;
    --apm-accent     : #06d6a0;
    --apm-text       : #e2e8f0;
    --apm-text-muted : #94a3b8;
    --apm-text-dim   : #64748b;
    --apm-glow       : rgba(124,58,237,0.35);
    --apm-glow-a     : rgba(6,214,160,0.2);
    --apm-shadow     : 0 8px 32px rgba(0,0,0,0.5);
    --apm-shadow-sm  : 0 2px 8px rgba(0,0,0,0.4);
    --apm-radius     : 20px;
    --apm-radius-sm  : 10px;
    --apm-bar-bg     : rgba(255,255,255,0.08);
    --apm-bar-thumb  : #fff;
    --apm-mini-bg    : rgba(13,13,26,0.92);
}

[data-apm-theme="light"] {
    --apm-bg         : #f1f5f9;
    --apm-surface    : #ffffff;
    --apm-surface2   : #f8fafc;
    --apm-surface3   : #f1f5f9;
    --apm-border     : rgba(0,0,0,0.08);
    --apm-primary    : #7c3aed;
    --apm-primary-l  : #6d28d9;
    --apm-accent     : #059669;
    --apm-text       : #1e293b;
    --apm-text-muted : #64748b;
    --apm-text-dim   : #94a3b8;
    --apm-glow       : rgba(124,58,237,0.12);
    --apm-glow-a     : rgba(5,150,105,0.08);
    --apm-shadow     : 0 8px 32px rgba(0,0,0,0.12);
    --apm-shadow-sm  : 0 2px 8px rgba(0,0,0,0.08);
    --apm-radius     : 20px;
    --apm-radius-sm  : 10px;
    --apm-bar-bg     : rgba(0,0,0,0.10);
    --apm-bar-thumb  : #7c3aed;
    --apm-mini-bg    : rgba(255,255,255,0.94);
}

/* ── Reset ──────────────────────────────────────────────────────── */
.apm-wrap *,
.apm-wrap *::before,
.apm-wrap *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ── Outer wrapper ──────────────────────────────────────────────── */
.apm-wrap {
    position: relative;
    display: flex;
    flex-direction: column;
    background: var(--apm-bg);
    border-radius: var(--apm-radius);
    overflow: hidden;
    box-shadow: var(--apm-shadow);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--apm-text);
    min-height: 420px;
    transition: background 0.35s, color 0.35s;
}

.apm-wrap.apm-fullscreen {
    border-radius: 0;
    height: 100vh !important;
}

/* ── Main player layout ─────────────────────────────────────────── */
.apm-player {
    display: flex;
    flex: 1;
    height: 100%;
    overflow: hidden;
}

/* Left column */
.apm-left {
    display: flex;
    flex-direction: column;
    flex: 0 0 300px;
    padding: 24px 20px 20px;
    gap: 16px;
    border-right: 1px solid var(--apm-border);
    background: var(--apm-surface);
    overflow: hidden;
}

/* Right column */
.apm-right {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--apm-surface2);
    overflow: hidden;
}

/* ── Visualizer + Artwork ───────────────────────────────────────── */
.apm-visualizer-wrap {
    position: relative;
    flex: 0 0 auto;
    aspect-ratio: 1 / 1;
    border-radius: var(--apm-radius-sm);
    overflow: hidden;
    background: var(--apm-surface3);
    box-shadow: 0 0 0 1px var(--apm-border), var(--apm-shadow-sm);
}

.apm-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0.85;
}

.apm-artwork-wrap {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.apm-artwork {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.apm-artwork-placeholder {
    width: 56px;
    height: 56px;
    color: var(--apm-text-dim);
    opacity: 0.5;
}

/* iOS: no Web Audio → canvas stays empty, show a soft pulse on the artwork */
.apm-wrap.apm-ios-mode .apm-visualizer-wrap {
    animation: apm-ios-pulse 2.4s ease-in-out infinite;
}
.apm-wrap.apm-ios-mode.apm-paused .apm-visualizer-wrap {
    animation: none;
}

@keyframes apm-ios-pulse {
    0%, 100% { box-shadow: 0 0 0 0   var(--apm-glow); }
    50%       { box-shadow: 0 0 24px 6px var(--apm-glow); }
}

.apm-artwork-placeholder svg {
    width: 100%;
    height: 100%;
}

/* ── Track info ─────────────────────────────────────────────────── */
.apm-info {
    text-align: center;
}

.apm-playlist-name {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--apm-primary-l);
    margin-bottom: 6px;
}

.apm-track-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--apm-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.apm-track-artist {
    font-size: 14px;
    color: var(--apm-text-muted);
    margin-top: 3px;
}

.apm-track-album {
    font-size: 12px;
    color: var(--apm-text-dim);
    margin-top: 2px;
}

.apm-track-genre {
    display: inline-block;
    margin-top: 8px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    background: linear-gradient(135deg, var(--apm-primary), var(--apm-accent));
    color: #fff;
    line-height: 1.5;
}

/* ── Progress bar ───────────────────────────────────────────────── */
.apm-progress-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
}

.apm-time-current,
.apm-time-total {
    font-size: 11px;
    color: var(--apm-text-muted);
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
    min-width: 32px;
}

.apm-time-total {
    text-align: right;
}

.apm-progress-bar {
    position: relative;
    flex: 1;
    height: 4px;
    background: var(--apm-bar-bg);
    border-radius: 2px;
    cursor: pointer;
}

.apm-progress-fill {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    border-radius: 2px;
    background: linear-gradient(90deg, var(--apm-primary), var(--apm-accent));
    pointer-events: none;
    transition: width 0.1s linear;
}

.apm-progress-thumb {
    position: absolute;
    top: 50%;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--apm-bar-thumb);
    transform: translate(-50%, -50%) scale(0);
    transition: transform 0.15s;
    pointer-events: none;
    box-shadow: 0 0 0 2px var(--apm-primary);
    left: 0;
}

.apm-progress-bar:hover .apm-progress-thumb,
.apm-progress-bar:focus-within .apm-progress-thumb {
    transform: translate(-50%, -50%) scale(1);
}

/* Range input overlay (invisible, handles interaction) */
.apm-seek,
.apm-volume {
    position: absolute;
    inset: -8px 0;
    width: 100%;
    height: calc(100% + 16px);
    opacity: 0;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
    padding: 0;
    background: transparent;
}

/* ── Controls ───────────────────────────────────────────────────── */
.apm-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

/* ── Buttons ────────────────────────────────────────────────────── */
.apm-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--apm-text-muted);
    cursor: pointer;
    transition: background 0.2s, color 0.2s, transform 0.15s, box-shadow 0.2s;
    padding: 0;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

.apm-btn svg {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    pointer-events: none;
}

.apm-btn:hover,
.apm-btn:focus-visible {
    background: var(--apm-surface3);
    color: var(--apm-text);
}

.apm-btn:active {
    transform: scale(0.92);
}

.apm-btn.active {
    color: var(--apm-accent);
}

/* Play button */
.apm-btn-play {
    width: 56px;
    height: 56px;
    background: var(--apm-primary);
    color: #fff;
    box-shadow: 0 0 20px var(--apm-glow);
}

.apm-btn-play:hover,
.apm-btn-play:focus-visible {
    background: var(--apm-primary-l);
    color: #fff;
    box-shadow: 0 0 28px var(--apm-glow);
}

.apm-btn-play svg {
    width: 28px;
    height: 28px;
}

/* Repeat mode indicator dot */
.apm-btn-repeat[data-mode="one"]::after {
    content: '1';
    position: absolute;
    font-size: 8px;
    font-weight: 800;
    color: var(--apm-accent);
    bottom: 4px;
    right: 4px;
    line-height: 1;
}

.apm-btn-repeat {
    position: relative;
}

/* ── Bottom row: volume + actions ───────────────────────────────── */
.apm-bottom-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.apm-volume-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
}

.apm-volume-bar {
    position: relative;
    flex: 1;
    height: 4px;
    background: var(--apm-bar-bg);
    border-radius: 2px;
    cursor: pointer;
    max-width: 80px;
}

.apm-volume-fill {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    border-radius: 2px;
    background: var(--apm-primary-l);
    pointer-events: none;
}

.apm-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* iOS hardware-volume hint (replaces the volume slider) */
.apm-ios-vol-hint {
    font-size: 11px;
    color: var(--apm-text-dim);
    white-space: nowrap;
    opacity: 0.75;
    letter-spacing: 0.02em;
}

/* ── Playlist header ────────────────────────────────────────────── */
.apm-playlist-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px 10px;
    border-bottom: 1px solid var(--apm-border);
    flex-shrink: 0;
}

.apm-playlist-header .apm-track-count {
    flex: 1;
}

.apm-playlist-label {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--apm-text-muted);
}

.apm-track-count {
    font-size: 11px;
    color: var(--apm-text-dim);
}

/* ── Sort select ────────────────────────────────────────────────── */
.apm-sort-select {
    font-size: 11px;
    font-weight: 600;
    padding: 4px 22px 4px 8px;
    border-radius: 6px;
    border: 1px solid var(--apm-border);
    background: var(--apm-surface3);
    color: var(--apm-text-muted);
    cursor: pointer;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%2394a3b8' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 7px center;
    transition: border-color 0.2s, color 0.2s;
    flex-shrink: 0;
}

.apm-sort-select:hover,
.apm-sort-select:focus {
    border-color: var(--apm-primary);
    color: var(--apm-text);
}

.apm-sort-select option {
    background: var(--apm-surface);
    color: var(--apm-text);
}

[data-apm-theme="light"] .apm-sort-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%2364748b' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
}

/* ── Filter bar ─────────────────────────────────────────────────── */
.apm-filter-bar {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 16px 10px;
    border-bottom: 1px solid var(--apm-border);
    flex-shrink: 0;
}

/* Search input */
.apm-search-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--apm-surface3);
    border: 1px solid var(--apm-border);
    border-radius: 8px;
    padding: 0 10px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.apm-search-wrap:focus-within {
    border-color: var(--apm-primary);
    box-shadow: 0 0 0 3px var(--apm-glow);
}

.apm-search-icon {
    width: 14px;
    height: 14px;
    color: var(--apm-text-dim);
    flex-shrink: 0;
    pointer-events: none;
}

.apm-search {
    flex: 1;
    min-width: 0;
    border: none;
    background: transparent;
    color: var(--apm-text);
    font-size: 13px;
    padding: 8px 0;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.apm-search::placeholder {
    color: var(--apm-text-dim);
}

/* Hide native clear button in webkit */
.apm-search::-webkit-search-cancel-button,
.apm-search::-webkit-search-decoration { display: none; }

.apm-search-clear {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--apm-text-dim);
    border-radius: 50%;
    padding: 0;
    transition: background 0.15s, color 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.apm-search-clear svg {
    width: 14px;
    height: 14px;
    pointer-events: none;
}

.apm-search-clear:hover {
    background: var(--apm-surface);
    color: var(--apm-text);
}

.apm-search-clear[hidden] { display: none; }

/* Genre filter pills — wrapper with arrows */
.apm-genre-filters-wrap {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
}

/* Left / Right scroll arrow buttons */
.apm-genre-arrow {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 1px solid var(--apm-border);
    background: var(--apm-surface3);
    color: var(--apm-text-muted);
    cursor: pointer;
    padding: 0;
    transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
}

.apm-genre-arrow svg {
    width: 16px;
    height: 16px;
    pointer-events: none;
}

.apm-genre-arrow:hover {
    background: var(--apm-primary);
    border-color: var(--apm-primary);
    color: #fff;
}

.apm-genre-arrow:active  { transform: scale(0.9); }
.apm-genre-arrow[hidden] { display: none; }

/* Genre filter pills */
.apm-genre-filters {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
    flex: 1;
    min-width: 0;
    scroll-behavior: smooth;
}

.apm-genre-filters:empty { display: none; }
.apm-genre-filters::-webkit-scrollbar { display: none; }

.apm-genre-btn {
    flex-shrink: 0;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    padding: 4px 10px;
    border-radius: 20px;
    border: 1px solid var(--apm-border);
    background: transparent;
    color: var(--apm-text-muted);
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
    line-height: 1.5;
}

.apm-genre-btn:hover {
    background: var(--apm-surface3);
    color: var(--apm-text);
}

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

/* "All" button active */
.apm-genre-btn[data-genre=""].active {
    background: var(--apm-primary);
    border-color: var(--apm-primary);
    color: #fff;
    box-shadow: 0 0 10px var(--apm-glow);
}

/* Genre-specific active colors — Malagasy genres */
.apm-genre-btn.active { color: #fff; }

/* Traditional / Folk */
.apm-genre-btn[data-genre="hiragasy"].active,
.apm-genre-btn[data-genre="vakodrazana"].active,
.apm-genre-btn[data-genre="bagasy"].active,
.apm-genre-btn[data-genre="kalony"].active {
    background: #d97706; border-color: #d97706;
    box-shadow: 0 0 10px rgba(217,119,6,0.4);
}

/* Dance / Rhythm */
.apm-genre-btn[data-genre="salegy"].active,
.apm-genre-btn[data-genre="tsapiky"].active {
    background: #06d6a0; border-color: #06d6a0;
    box-shadow: 0 0 10px rgba(6,214,160,0.35);
    color: #0a0a1a;
}

/* Ceremonial */
.apm-genre-btn[data-genre="beko"].active,
.apm-genre-btn[data-genre="malesa"].active,
.apm-genre-btn[data-genre="basesa"].active {
    background: #6366f1; border-color: #6366f1;
    box-shadow: 0 0 10px rgba(99,102,241,0.4);
}

/* Gospel */
.apm-genre-btn[data-genre="gospel"].active {
    background: #9333ea; border-color: #9333ea;
    box-shadow: 0 0 10px rgba(147,51,234,0.4);
}

/* Jazz */
.apm-genre-btn[data-genre="jazz"].active {
    background: #eab308; border-color: #eab308;
    box-shadow: 0 0 10px rgba(234,179,8,0.4);
    color: #0a0a1a;
}

/* Rap */
.apm-genre-btn[data-genre="rap"].active {
    background: #f97316; border-color: #f97316;
    box-shadow: 0 0 10px rgba(249,115,22,0.4);
}

/* Rock */
.apm-genre-btn[data-genre="rock"].active {
    background: #ef4444; border-color: #ef4444;
    box-shadow: 0 0 10px rgba(239,68,68,0.4);
}

/* Reggae */
.apm-genre-btn[data-genre="reggae"].active {
    background: #22c55e; border-color: #22c55e;
    box-shadow: 0 0 10px rgba(34,197,94,0.4);
    color: #0a0a1a;
}

/* Pop */
.apm-genre-btn[data-genre="pop"].active {
    background: #ec4899; border-color: #ec4899;
    box-shadow: 0 0 10px rgba(236,72,153,0.4);
}

/* Variété */
.apm-genre-btn[data-genre="variete"].active {
    background: #0ea5e9; border-color: #0ea5e9;
    box-shadow: 0 0 10px rgba(14,165,233,0.4);
    color: #0a0a1a;
}

/* No results message */
.apm-no-results {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 40px 20px;
    color: var(--apm-text-dim);
    font-size: 13px;
    text-align: center;
}

.apm-no-results svg {
    width: 32px;
    height: 32px;
    opacity: 0.4;
}

.apm-no-results[hidden] { display: none; }

/* ── Track list ─────────────────────────────────────────────────── */
.apm-track-list {
    list-style: none;
    overflow-y: auto;
    flex: 1;
    scrollbar-width: thin;
    scrollbar-color: var(--apm-surface3) transparent;
    -webkit-overflow-scrolling: touch;
}

.apm-track-list::-webkit-scrollbar {
    width: 4px;
}

.apm-track-list::-webkit-scrollbar-track {
    background: transparent;
}

.apm-track-list::-webkit-scrollbar-thumb {
    background: var(--apm-surface3);
    border-radius: 2px;
}

/* ── Track item ─────────────────────────────────────────────────── */
.apm-track-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    cursor: pointer;
    border-bottom: 1px solid var(--apm-border);
    transition: background 0.15s;
    position: relative;
}

.apm-track-item:last-child {
    border-bottom: none;
}

.apm-track-item:hover {
    background: var(--apm-surface3);
}

.apm-track-item.is-active {
    background: linear-gradient(90deg, rgba(124,58,237,0.12), transparent);
}

.apm-track-item.is-active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--apm-primary);
    border-radius: 0 2px 2px 0;
}

.apm-track-num {
    font-size: 12px;
    color: var(--apm-text-dim);
    min-width: 20px;
    text-align: center;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

.apm-track-item.is-active .apm-track-num {
    color: var(--apm-primary-l);
}

/* Equalizer animation for playing track */
.apm-track-item.is-playing .apm-track-num {
    position: relative;
    overflow: hidden;
}

.apm-track-item.is-playing .apm-track-num::before {
    content: '▶';
    color: var(--apm-accent);
    animation: apm-pulse 1s ease-in-out infinite;
}

@keyframes apm-pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.4; }
}

.apm-track-art {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--apm-surface3);
}

.apm-track-art-placeholder {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    background: var(--apm-surface3);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--apm-text-dim);
}

.apm-track-art-placeholder svg {
    width: 18px;
    height: 18px;
}

.apm-track-meta {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.apm-track-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--apm-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.apm-track-item.is-active .apm-track-name {
    color: var(--apm-primary-l);
}

.apm-track-by {
    font-size: 12px;
    color: var(--apm-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.apm-track-dur {
    font-size: 11px;
    color: var(--apm-text-dim);
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

/* Play count — visible on desktop, hidden on tablet & mobile */
.apm-track-plays {
    display: block;
    font-size: 11px;
    color: var(--apm-text-dim);
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
    min-width: 40px;
    text-align: right;
    white-space: nowrap;
}

.apm-track-plays::before {
    content: '▶ ';
    font-size: 9px;
    opacity: 0.6;
}

/* Hidden on tablet & mobile */
@media (max-width: 1024px) {
    .apm-track-plays { display: none; }
}

/* Genre tag in track list */
.apm-genre-tag {
    flex-shrink: 0;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 20px;
    white-space: nowrap;
    /* default: primary gradient */
    background: rgba(124, 58, 237, 0.15);
    color: var(--apm-primary-l);
    border: 1px solid rgba(124, 58, 237, 0.25);
}

/* Per-genre colour accents — Malagasy genres */

/* Traditional / Folk */
.apm-genre-tag[data-genre="hiragasy"],
.apm-genre-tag[data-genre="vakodrazana"],
.apm-genre-tag[data-genre="bagasy"],
.apm-genre-tag[data-genre="kalony"] {
    background: rgba(217, 119, 6, 0.12);
    color: #fbbf24;
    border-color: rgba(217, 119, 6, 0.25);
}

/* Dance / Rhythm */
.apm-genre-tag[data-genre="salegy"],
.apm-genre-tag[data-genre="tsapiky"] {
    background: rgba(6, 214, 160, 0.12);
    color: var(--apm-accent);
    border-color: rgba(6, 214, 160, 0.25);
}

/* Ceremonial */
.apm-genre-tag[data-genre="beko"],
.apm-genre-tag[data-genre="malesa"],
.apm-genre-tag[data-genre="basesa"] {
    background: rgba(99, 102, 241, 0.12);
    color: #818cf8;
    border-color: rgba(99, 102, 241, 0.25);
}

/* Gospel */
.apm-genre-tag[data-genre="gospel"] {
    background: rgba(147, 51, 234, 0.12);
    color: #c084fc;
    border-color: rgba(147, 51, 234, 0.25);
}

/* Jazz */
.apm-genre-tag[data-genre="jazz"] {
    background: rgba(234, 179, 8, 0.12);
    color: #facc15;
    border-color: rgba(234, 179, 8, 0.25);
}

/* Rap */
.apm-genre-tag[data-genre="rap"] {
    background: rgba(249, 115, 22, 0.12);
    color: #fb923c;
    border-color: rgba(249, 115, 22, 0.25);
}

/* Rock */
.apm-genre-tag[data-genre="rock"] {
    background: rgba(239, 68, 68, 0.12);
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.25);
}

/* Reggae */
.apm-genre-tag[data-genre="reggae"] {
    background: rgba(34, 197, 94, 0.12);
    color: #4ade80;
    border-color: rgba(34, 197, 94, 0.25);
}

/* Pop */
.apm-genre-tag[data-genre="pop"] {
    background: rgba(236, 72, 153, 0.12);
    color: #f472b6;
    border-color: rgba(236, 72, 153, 0.25);
}

/* Variété */
.apm-genre-tag[data-genre="variete"] {
    background: rgba(14, 165, 233, 0.12);
    color: #38bdf8;
    border-color: rgba(14, 165, 233, 0.25);
}

/* Light theme adjustments for genre tags */
[data-apm-theme="light"] .apm-genre-tag {
    background: rgba(124, 58, 237, 0.08);
    color: var(--apm-primary);
}

[data-apm-theme="light"] .apm-genre-tag[data-genre="hiragasy"],
[data-apm-theme="light"] .apm-genre-tag[data-genre="vakodrazana"],
[data-apm-theme="light"] .apm-genre-tag[data-genre="bagasy"],
[data-apm-theme="light"] .apm-genre-tag[data-genre="kalony"] {
    background: rgba(161, 98, 7, 0.08);
    color: #a16207;
}

[data-apm-theme="light"] .apm-genre-tag[data-genre="salegy"],
[data-apm-theme="light"] .apm-genre-tag[data-genre="tsapiky"] {
    background: rgba(5, 150, 105, 0.08);
    color: #059669;
}

[data-apm-theme="light"] .apm-genre-tag[data-genre="beko"],
[data-apm-theme="light"] .apm-genre-tag[data-genre="malesa"],
[data-apm-theme="light"] .apm-genre-tag[data-genre="basesa"] {
    background: rgba(79, 70, 229, 0.08);
    color: #4f46e5;
}

[data-apm-theme="light"] .apm-genre-tag[data-genre="gospel"] {
    background: rgba(126, 34, 206, 0.08);
    color: #7e22ce;
}

[data-apm-theme="light"] .apm-genre-tag[data-genre="jazz"] {
    background: rgba(161, 98, 7, 0.08);
    color: #854d0e;
}

[data-apm-theme="light"] .apm-genre-tag[data-genre="rap"] {
    background: rgba(194, 65, 12, 0.08);
    color: #c2410c;
}

[data-apm-theme="light"] .apm-genre-tag[data-genre="rock"] {
    background: rgba(239, 68, 68, 0.08);
    color: #dc2626;
}

[data-apm-theme="light"] .apm-genre-tag[data-genre="reggae"] {
    background: rgba(22, 163, 74, 0.08);
    color: #16a34a;
}

[data-apm-theme="light"] .apm-genre-tag[data-genre="pop"] {
    background: rgba(190, 24, 93, 0.08);
    color: #be185d;
}

[data-apm-theme="light"] .apm-genre-tag[data-genre="variete"] {
    background: rgba(2, 132, 199, 0.08);
    color: #0284c7;
}

/* ── Share modal ────────────────────────────────────────────────── */
.apm-share-modal {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    animation: apm-fadeIn 0.2s ease;
}

.apm-share-modal[hidden] {
    display: none;
}

@keyframes apm-fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.apm-share-inner {
    background: var(--apm-surface);
    border-radius: var(--apm-radius);
    padding: 28px 32px;
    min-width: 280px;
    max-width: 380px;
    width: 90%;
    position: relative;
    box-shadow: var(--apm-shadow);
    border: 1px solid var(--apm-border);
    animation: apm-slideUp 0.25s ease;
}

@keyframes apm-slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

.apm-share-inner h3 {
    font-size: 18px;
    font-weight: 700;
    color: var(--apm-text);
    margin-bottom: 20px;
}

.apm-share-btns {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.apm-share-btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 11px 16px;
    border-radius: var(--apm-radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    border: 1px solid var(--apm-border);
    background: var(--apm-surface2);
    color: var(--apm-text);
    transition: background 0.15s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
}

.apm-share-btn svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.apm-share-btn:hover {
    background: var(--apm-surface3);
    transform: translateX(2px);
}

.apm-share-copy    { color: var(--apm-text); }
.apm-share-twitter { color: #000; }
.apm-share-facebook{ color: #1877f2; }
.apm-share-whatsapp{ color: #25d366; }

[data-apm-theme="dark"] .apm-share-twitter { color: #fff; }

.apm-share-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none;
    border: none;
    color: var(--apm-text-muted);
    font-size: 22px;
    cursor: pointer;
    line-height: 1;
    padding: 4px;
    border-radius: 4px;
    transition: color 0.15s;
}

.apm-share-close:hover { color: var(--apm-text); }

/* ── Mini floating player ───────────────────────────────────────── */
.apm-mini-player {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    background: var(--apm-mini-bg);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    backdrop-filter: blur(20px) saturate(180%);
    border-top: 1px solid var(--apm-border);
    box-shadow: 0 -4px 24px rgba(0,0,0,0.2);
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.4,0,0.2,1);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--apm-text);
}

.apm-mini-player.is-visible {
    transform: translateY(0);
}

.apm-mini-progress {
    height: 3px;
    background: var(--apm-bar-bg);
    width: 100%;
}

.apm-mini-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--apm-primary), var(--apm-accent));
    transition: width 0.25s linear;
    border-radius: 0 1.5px 1.5px 0;
}

.apm-mini-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    max-width: 900px;
    margin: 0 auto;
}

.apm-mini-art-wrap {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
    background: var(--apm-surface3);
    display: flex;
    align-items: center;
    justify-content: center;
}

.apm-mini-art {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.apm-mini-art-placeholder {
    color: var(--apm-text-dim);
    width: 22px;
    height: 22px;
}

.apm-mini-art-placeholder svg {
    width: 100%;
    height: 100%;
}

.apm-mini-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.apm-mini-title {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    color: var(--apm-text);
}

.apm-mini-artist {
    font-size: 11px;
    color: var(--apm-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.apm-mini-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.apm-btn-mini {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--apm-text-muted);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.15s, color 0.15s, transform 0.1s;
}

.apm-btn-mini svg {
    width: 20px;
    height: 20px;
    pointer-events: none;
}

.apm-btn-mini:hover { background: var(--apm-surface3); color: var(--apm-text); }
.apm-btn-mini:active { transform: scale(0.9); }

.apm-btn-mini-play {
    width: 40px;
    height: 40px;
    background: var(--apm-primary);
    color: #fff;
}

.apm-btn-mini-play:hover {
    background: var(--apm-primary-l);
    color: #fff;
}

.apm-btn-mini-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--apm-text-dim);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0;
    margin-left: 4px;
    transition: color 0.15s, background 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.apm-btn-mini-close:hover {
    background: var(--apm-surface3);
    color: var(--apm-text);
}

/* ── Error ──────────────────────────────────────────────────────── */
.apm-error {
    color: #ef4444;
    padding: 12px 16px;
    background: rgba(239,68,68,0.1);
    border-radius: 8px;
    border: 1px solid rgba(239,68,68,0.3);
    font-size: 14px;
    margin: 8px 0;
}

/* ── Fullscreen adjustments ─────────────────────────────────────── */
.apm-wrap:-webkit-full-screen { width: 100%; height: 100vh; }
.apm-wrap:-moz-full-screen    { width: 100%; height: 100vh; }
.apm-wrap:fullscreen          { width: 100%; height: 100vh; }

.apm-wrap.apm-fullscreen .apm-left  { flex: 0 0 340px; }

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 700px) {
    .apm-player {
        flex-direction: column;
    }

    /* ── Left panel: compact horizontal layout on mobile ─────────── */
    .apm-left {
        flex: 0 0 auto;
        flex-direction: row;        /* artwork + info side by side  */
        flex-wrap: wrap;            /* controls drop to full-width rows */
        align-items: flex-start;
        border-right: none;
        border-bottom: 1px solid var(--apm-border);
        padding: 12px 14px;
        gap: 10px;
    }

    /* Small square artwork */
    .apm-visualizer-wrap {
        flex: 0 0 76px;
        width: 76px;
        height: 76px;
        max-height: none;
        border-radius: 8px;
        align-self: center;
    }

    /* Info sits to the right of artwork */
    .apm-info {
        flex: 1;
        min-width: 0;
        text-align: left;
        align-self: center;
    }

    /* Hide secondary info to keep the compact area readable */
    .apm-track-album,
    .apm-track-genre { display: none; }

    .apm-playlist-name { margin-bottom: 3px; }
    .apm-track-title   { font-size: 15px; }

    /* Progress, controls, volume: each on its own full-width row */
    .apm-progress-wrap,
    .apm-controls,
    .apm-bottom-row {
        flex: 0 0 100%;
        width: 100%;
    }

    /* ── Right panel ────────────────────────────────────────────── */
    .apm-right {
        flex: 1;
    }

    /* Track list: fixed max-height → scrolls instead of expanding */
    .apm-track-list {
        max-height: 272px;   /* ≈ 5 tracks × 52px + 12px scroll hint */
    }

    /* Genre tags take too much horizontal room on mobile → hide */
    .apm-genre-tag { display: none; }

    /* Slightly tighter track rows on mobile */
    .apm-track-item {
        padding: 8px 14px;
        gap: 10px;
    }

    .apm-track-art,
    .apm-track-art-placeholder {
        width: 36px;
        height: 36px;
    }

    .apm-wrap {
        min-height: 560px;
    }

    .apm-mini-inner {
        padding: 8px 12px;
    }
}

/* ── Very small phones (≤ 480px) ────────────────────────────────── */
@media (max-width: 480px) {
    /* Even more compact artwork */
    .apm-visualizer-wrap {
        flex: 0 0 64px;
        width: 64px;
        height: 64px;
    }

    /* Hide playlist label to save vertical space */
    .apm-playlist-name { display: none; }

    .apm-controls { gap: 4px; }
    .apm-btn-play { width: 48px; height: 48px; }
    .apm-btn-play svg { width: 24px; height: 24px; }

    .apm-filter-bar { padding: 8px 12px; }
    .apm-search     { font-size: 14px; } /* prevent iOS zoom on focus */

    .apm-share-inner { padding: 20px; }
}

/* ── Tablet (701px – 1024px) ────────────────────────────────────── */
/* Desktop layout (side-by-side columns) but track list needs a cap  */
@media (min-width: 701px) and (max-width: 1024px) {
    .apm-track-list {
        max-height: 390px;   /* ≈ 6 tracks × 62px + breathing room */
    }

    .apm-genre-tag { display: none; }
}

/* ── Accessibility ──────────────────────────────────────────────── */
.apm-btn:focus-visible,
.apm-btn-mini:focus-visible,
.apm-share-btn:focus-visible,
.apm-track-item:focus-visible {
    outline: 2px solid var(--apm-primary);
    outline-offset: 2px;
}

/* ── Transitions ────────────────────────────────────────────────── */
.apm-wrap,
.apm-surface,
.apm-btn,
.apm-track-item {
    transition-duration: 0.3s;
    transition-timing-function: ease;
}
