:root {
    --bg-color: #f8f9fa;
    --text-color: #212529;
    --text-secondary: #6c757d;
    --card-bg: #ffffff;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --border: #e5e7eb;
    --modal-overlay: rgba(0, 0, 0, 0.5);
    --hover-bg: rgba(0,0,0,0.05);

    /* Badges */
    --badge-synced-bg: #d1fae5;
    --badge-synced-text: #065f46;
    --badge-plain-bg: #f3f4f6;
    --badge-plain-text: #374151;
    --badge-inst-bg: #fef3c7;
    --badge-inst-text: #92400e;
}

[data-theme="dark"] {
    --bg-color: #111827;
    --text-color: #f3f4f6;
    --text-secondary: #9ca3af;
    --card-bg: #1f2937;
    --primary: #60a5fa;
    --primary-hover: #3b82f6;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
    --border: #374151;
    --modal-overlay: rgba(0, 0, 0, 0.7);
    --hover-bg: rgba(255,255,255,0.1);

    --badge-synced-bg: #064e3b;
    --badge-synced-text: #ecfdf5;
    --badge-plain-bg: #374151;
    --badge-plain-text: #f3f4f6;
    --badge-inst-bg: #78350f;
    --badge-inst-text: #fcd34d;
}

/* Reset & Base */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background-color 0.15s, color 0.15s;
}

.card, .modal-content, .search-box, button, input {
    transition: background-color 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
}

#theme-toggle {
    position: absolute; top: 20px; right: 20px;
    background: transparent; border: none; color: var(--text-color);
    cursor: pointer; border-radius: 50%; padding: 8px; z-index: 10;
    width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center;
}
#theme-toggle:hover { background-color: var(--hover-bg); }

.container {
    width: 100%; max-width: 800px; margin: 0 auto; padding: 20px;
    flex: 1; display: flex; flex-direction: column;
}

/* Header & Search */
header { text-align: center; margin-top: 15vh; transition: margin-top 0.5s ease; }
header.active { margin-top: 0; margin-bottom: 30px; }
.logo {
    font-size: 3rem;
    font-weight: 700;
    letter-spacing: -1px;
    margin-bottom: 0.5rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
}
.highlight { color: var(--primary); }
.subtitle { color: var(--text-secondary); margin-bottom: 2rem; }

.search-wrapper {
    position: relative;
    max-width: 600px;
    margin: 0 auto;
    z-index: 100;
}

.search-box {
    display: flex; background: var(--card-bg);
    border: 2px solid var(--border); border-radius: 50px;
    padding: 5px 5px 5px 20px; box-shadow: var(--shadow);
    align-items: center;
    gap: 5px;
    width: 100%;
    position: relative;
    z-index: 102;
    transition: border-radius 0.2s, border-color 0.2s;
}

.search-box.history-open {
    border-radius: 15px 15px 0 0;
    border-bottom-color: transparent;
}

.search-box:focus-within { border-color: var(--primary); }
#search-input { flex: 1; min-width: 0; border: none; background: transparent; font-size: 1.1rem; color: var(--text-color); outline: none; }
#search-btn {
    background-color: var(--primary); color: white; border: none;
    border-radius: 50%; width: 48px; height: 48px;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    flex: 0 0 48px;
}
#search-btn:hover { background-color: var(--primary-hover); }

/* Results */
.results-grid { display: flex; flex-direction: column; gap: 15px; width: 100%; }

.card {
    background-color: var(--card-bg); border-radius: 12px;
    padding: 20px; box-shadow: var(--shadow);
    border: 1px solid var(--border);
    cursor: pointer; animation: fadeIn 0.4s ease-out forwards;
    display: flex; justify-content: space-between; align-items: flex-start;
}
.card:hover { transform: translateY(-2px); border-color: var(--primary); }

.card-info { display: flex; flex-direction: column; gap: 4px; margin-right: 15px; width: 100%; }
.card-info h3 { font-size: 1.2rem; line-height: 1.3; font-weight: 600; }
.card-info .artist { font-weight: 600; color: var(--primary); font-size: 0.95rem; }
.card-info .album { font-size: 0.9rem; color: var(--text-secondary); font-style: italic; }

.card-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; min-width: 80px; }
.duration { font-size: 0.8rem; font-family: monospace; background: var(--border); padding: 2px 6px; border-radius: 4px; color: var(--text-secondary); }

/* Badges */
.badge-container { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.badge { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; padding: 2px 6px; border-radius: 4px; letter-spacing: 0.5px; }
.badge.synced { background-color: var(--badge-synced-bg); color: var(--badge-synced-text); }
.badge.plain { background-color: var(--badge-plain-bg); color: var(--badge-plain-text); }

/* Status */
#status-container { text-align: center; margin: 30px 0; }
.hidden { display: none !important; }
.loader { border: 4px solid var(--border); border-top: 4px solid var(--primary); border-radius: 50%; width: 30px; height: 30px; animation: spin 1s linear infinite; margin: 0 auto 10px; }

/* Modal */
.modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: var(--modal-overlay); z-index: 1000;
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
    display: flex; justify-content: center; align-items: center;
}

.modal-content {
    background: var(--card-bg); width: 90%; max-width: 700px; height: 85vh;
    border-radius: 16px; display: flex; flex-direction: column;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    position: relative;
}

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

.track-info { flex: 1; margin-right: 15px; }
#modal-title { font-size: 1.4rem; line-height: 1.2; font-weight: 700; }
#modal-artist { color: var(--primary); font-weight: 600; font-size: 1rem; }
#modal-album { color: var(--text-secondary); font-size: 0.9rem; margin-top: 2px; }

/* Right side controls */
.header-controls { display: flex; flex-direction: column; align-items: flex-end; gap: 12px; }

#close-modal {
    background: transparent; border: none; color: var(--text-color);
    padding: 6px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s;
}

/* Close Button Hover Effect */
#close-modal:hover { background-color: var(--hover-bg); }

.format-toggle { background: var(--border); border-radius: 8px; padding: 4px; display: flex; }
.format-toggle button {
    background: transparent; border: none; color: var(--text-secondary);
    padding: 6px 12px; border-radius: 6px; font-size: 0.85rem; font-weight: 600;
    cursor: pointer;
}
.format-toggle button.active { background: var(--card-bg); color: var(--text-color); box-shadow: 0 1px 3px rgba(0,0,0,0.1); }

.modal-body { flex: 1; overflow-y: auto; padding: 20px; background: rgba(0,0,0,0.02); }
#lyrics-display { white-space: pre-wrap; font-family: 'Inter', sans-serif; line-height: 1.8; font-size: 1rem; }

/* Footer Actions */
.modal-actions {
    padding: 10px 20px; border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end; align-items: center; gap: 12px;
    background: var(--card-bg);
    border-bottom-left-radius: 16px; border-bottom-right-radius: 16px;
}

.action-btn {
    padding: 8px;
    border-radius: 12px; border: 1px solid var(--border);
    background: var(--bg-color); color: var(--text-color);
    font-weight: 600; font-size: 1rem;
    display: inline-flex; align-items: center; justify-content: center; 
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.action-btn .btn-text {
    max-width: 0;
    opacity: 0;
    margin-left: 0;
    white-space: nowrap;
    overflow: hidden;
    transition: max-width 0.3s ease, opacity 0.2s ease, margin 0.3s ease;
}

.action-btn:hover .btn-text {
    max-width: 150px;
    opacity: 1;
    margin-left: 8px;
}

.action-btn:hover { background: var(--border); }
.action-btn.primary { background: var(--primary); color: white; border-color: var(--primary); }
.action-btn.primary:hover { background: var(--primary-hover); }
.action-btn:disabled { opacity: 0.5; cursor: not-allowed; background: var(--border); color: var(--text-secondary); }

footer { text-align: center; padding: 20px; font-size: 0.8rem; opacity: 0.6; }
footer a { color: var(--primary); text-decoration: none; }

@keyframes spin { 100% { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* Mobile Full Screen View */
@media (max-width: 600px) {
    .modal-content {
        width: 100%; height: 100%; max-width: none; border-radius: 0;
    }
    .modal-actions { border-radius: 0; }
}

@media (max-width: 480px) {
    #theme-toggle {
        top: 12px;
        right: 12px;
        width: 36px;
        height: 36px;
        padding: 6px;
    }
    .search-box {
        padding: 4px 4px 4px 12px;
        gap: 4px;
    }
    #search-input { font-size: 1rem; }
    #search-btn {
        width: 40px;
        height: 40px;
        flex: 0 0 40px;
    }
    #toggle-advanced {
        width: 32px;
        height: 32px;
        flex: 0 0 32px;
    }
    .divider-vertical { height: 20px; margin: 0 2px; }
}

/* Advanced Search & Misc */
.advanced-search-toggle { margin: 10px 0 20px; text-align: center; }
.text-btn { background: none; border: none; color: var(--primary); cursor: pointer; font-size: 0.9rem; text-decoration: underline; padding: 5px; }
.text-btn:hover { color: var(--primary-hover); }

.advanced-search { 
    display: flex; gap: 10px; margin: 25px auto 30px; width: 100%; max-width: 600px;
    flex-wrap: wrap; animation: fadeIn 0.3s ease;
}
.advanced-search.hidden { display: none; }
.input-group { flex: 1; min-width: 150px; }
.input-group.full-width { flex-basis: 100%; }
.advanced-search input {
    width: 100%; padding: 10px 15px; border-radius: 20px; border: 1px solid var(--border);
    background: var(--card-bg); color: var(--text-color); outline: none; transition: all 0.2s;
}
.advanced-search input:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2); }

.badge.instrumental { background-color: var(--badge-inst-bg); color: var(--badge-inst-text); }
.search-note { text-align: center; margin: 30px 0; color: var(--text-secondary); opacity: 0.8; padding-bottom: 20px; font-size: 0.9rem; }

#toggle-advanced {
    background: transparent; border: none; color: var(--text-secondary);
    cursor: pointer; padding: 8px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    transition: color 0.2s, background-color 0.2s;
    flex: 0 0 36px;
    width: 36px;
    height: 36px;
}
#toggle-advanced:hover, #toggle-advanced.active { color: var(--primary); background-color: var(--hover-bg); }

.divider-vertical {
    width: 1px; height: 24px; background-color: var(--border); margin: 0 4px;
}

/* Disabled State for Main Input */
#search-input:disabled {
    cursor: not-allowed;
    opacity: 0.5;
    background: transparent;
}

/* Search History */
.search-history {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: -2px;
    z-index: 103;
    
    background: var(--card-bg);
    border: 2px solid var(--border);
    border-top: none;
    
    border-bottom-left-radius: 15px;
    border-bottom-right-radius: 15px;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    
    width: 100%;
    padding-top: 5px;
    
    box-shadow: var(--shadow);
    overflow: hidden;
    animation: fadeIn 0.2s ease;
    transform-origin: top;
}

.search-box:focus-within ~ .search-history, 
.search-history:hover {
    border-color: var(--primary);
}

.search-history.hidden { display: none; }

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 15px;
    border-bottom: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 600;
    background: rgba(0,0,0,0.02);
}

#clear-history {
    background: transparent;
    border: none;
    color: var(--primary);
    cursor: pointer;
    font-size: 0.75rem;
    padding: 2px 5px;
}
#clear-history:hover { background: var(--hover-bg); border-radius: 4px; }

.history-list {
    display: flex;
    flex-direction: column;
    max-height: 300px;
    overflow-y: auto;
}

.history-item {
    padding: 8px 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between; /* To push delete button right */
    gap: 10px;
    transition: background 0.1s;
    border-bottom: 1px solid var(--border);
    color: var(--text-color);
    font-size: 0.95rem;
}
.history-item:last-child { border-bottom: none; }
.history-item:hover { background: var(--hover-bg); }
.history-list.keyboard-nav .history-item:hover { background: transparent; }
.history-item.active {
    background: var(--hover-bg);
}

.history-item-content {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    overflow: hidden;
}

.history-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-icon {
    font-size: 1.1rem;
    color: var(--text-secondary);
    opacity: 0.7;
}

.btn-remove-item {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 4px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0; /* Hidden by default */
    transition: opacity 0.2s, background-color 0.2s;
}

.history-item:hover .btn-remove-item {
    opacity: 1;
}

.history-list.keyboard-nav .history-item:hover .btn-remove-item {
    opacity: 0;
}

.btn-remove-item:hover {
    background-color: var(--hover-bg);
    color: var(--text-color);
}

.btn-remove-item .material-icons-round {
    font-size: 1rem;
}

.advanced-search-toggle { display: none; }

.meta-id {
    font-family: monospace;
    font-size: 0.8rem;
    color: var(--text-secondary);
    opacity: 0.7;
    margin-top: 4px;
    letter-spacing: 0.5px;
}

.id-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
}

.id-wrapper .meta-id {
    margin-top: 0;
}

.icon-btn-small {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 2px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.6;
    transition: all 0.2s;
}

.icon-btn-small:hover {
    background-color: var(--hover-bg);
    opacity: 1;
    color: var(--primary);
}

.icon-btn-small .material-icons-round {
    font-size: 14px;
}
