:root {
    --theme-bg: #121212;
    --theme-surface: #1E1E1E;
    --theme-text: #E0E0E0;
    --theme-text-muted: #A0A0A0;
    --theme-primary: #90CAF9;
    --theme-secondary: #03DAC6;
    --theme-accent: #FFFFFF;
    --theme-border: #333333;

    /* Condensed Layout */
    --header-height: 48px;
    --sidebar-width: 160px;
    --font-ui: 0.9rem;
    --font-small: 0.8rem;

    /* Base Interaction Colors */
    --theme-playing-bg: rgba(3, 218, 198, 0.15);
    --theme-list-bg: var(--theme-surface);
    --theme-list-hover: rgba(255, 255, 255, 0.05);
    --theme-list-active: rgba(255, 255, 255, 0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    scrollbar-width: thin;
    scrollbar-color: #333 var(--theme-bg);
}

body {
    background-color: var(--theme-bg);
    color: var(--theme-text);
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-size: var(--font-ui);
    line-height: 1.4;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Custom Scrollbar (Webkit) */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--theme-bg);
}

::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Header */
header {
    height: var(--header-height);
    background-color: var(--theme-surface);
    border-bottom: 1px solid var(--theme-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0.75rem;
    flex-shrink: 0;
}

header h1 {
    font-size: 1.1rem;
    color: var(--theme-accent);
    margin: 0;
    cursor: pointer;
    transition: color 0.2s;
}

header h1:hover {
    color: var(--theme-primary);
}

.search-container {
    flex: 1;
    max-width: 350px;
    margin: 0 1rem;
}

#search-input {
    width: 100%;
    background-color: #2C2C2C;
    border: 1px solid var(--theme-border);
    color: var(--theme-text);
    padding: 0.4rem 0.8rem;
    border-radius: 4px;
    /* More squarish for control panel feel */
    outline: none;
    font-size: var(--font-small);
}

#search-input:focus {
    border-color: var(--theme-primary);
}

.header-controls {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--theme-text-muted);
    cursor: pointer;
    font-size: 1rem;
    padding: 0.25rem;
    transition: color 0.15s;
}

.icon-btn:hover {
    color: var(--theme-primary);
}

/* Stop All Button */
.stop-all-btn {
    background: rgba(255, 60, 60, 0.15);
    border: 1px solid #ff3c3c;
    color: #ff3c3c;
    border-radius: 4px;
    padding: 0.2rem 0.5rem;
    cursor: pointer;
    font-size: var(--font-small);
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    transition: all 0.15s;
    white-space: nowrap;
}

.stop-all-btn:hover {
    background: rgba(255, 60, 60, 0.3);
}

/* Volume Slider */
.volume-icon {
    color: var(--theme-text-muted);
    font-size: 0.8rem;
}

#volume-slider {
    width: 70px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--theme-border);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

#volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--theme-primary);
    cursor: pointer;
}

#volume-slider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--theme-primary);
    border: none;
    cursor: pointer;
}

/* Main Layout */
.app-container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
aside {
    width: var(--sidebar-width);
    background-color: var(--theme-bg);
    border-right: 1px solid var(--theme-border);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.category-list {
    list-style: none;
    padding: 0;
}

.category-item {
    padding: 0.25rem 0.6rem;
    cursor: pointer;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    color: var(--theme-text-muted);
    transition: all 0.15s;
    text-transform: capitalize;
    font-weight: 500;
    font-size: var(--font-small);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.category-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--theme-text);
}

.category-item.active {
    background-color: rgba(144, 202, 249, 0.1);
    color: var(--theme-primary);
    border-left: 3px solid var(--theme-primary);
    font-weight: 600;
}

/* Main Content */
main {
    flex: 1;
    background-color: var(--theme-bg);
    overflow-y: auto;
    padding: 0.75rem;
}

/* Homepage Styles */
.homepage-content {
    text-align: center;
    margin-top: 3rem;
    color: var(--theme-text-muted);
}

.homepage-content h2 {
    color: var(--theme-accent);
    margin-bottom: 1rem;
}

/* Global Search Fieldset Styles */
.search-results fieldset {
    border: 1px solid var(--theme-border);
    border-radius: 4px;
    padding: 0.5rem;
    margin-bottom: 1rem;
}

.search-results legend {
    padding: 0 0.5rem;
    font-weight: bold;
    color: var(--theme-primary);
    text-transform: capitalize;
    font-size: var(--font-small);
}

/* Sound Grid */
.sound-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 0.35rem;
    padding-bottom: 1rem;
}

/* Sound Button Styling */
.sound-btn {
    background-color: var(--theme-list-bg);
    border: 1px solid var(--theme-border);
    border-radius: 4px;
    padding: 0.35rem 0.4rem;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--theme-text);
    user-select: none;
    position: relative;
    overflow: hidden;
    font-size: 0.72rem;
    line-height: 1.2;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.15rem;
}

.sound-btn .sound-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.sound-btn .sound-icon {
    display: none !important;
    font-size: 0.85rem;
    opacity: 0.7;
}

body.icons-enabled .sound-btn .sound-icon {
    display: block !important;
}

.sound-btn .sound-label {
    word-break: break-word;
    z-index: 1;
    padding: 0.15rem 0.1rem 0;
    font-size: 0.6rem;
}

.sound-btn .sound-duration {
    font-size: 0.6rem;
    opacity: 0.45;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

/* Favorite Star */
.fav-btn {
    color: var(--theme-border);
    cursor: pointer;
    font-size: 0.65rem;
    transition: color 0.15s;
    z-index: 2;
}

.fav-btn:hover {
    color: #f5a623;
}

.fav-btn.active {
    color: #f5a623;
}

/* Favorites sidebar item */
.category-favorites {
    border-bottom: 1px solid var(--theme-border) !important;
    display: flex;
    align-items: center;
}

.favs-io-sidebar-btn {
    margin-left: auto;
    color: var(--theme-text-muted);
    opacity: 0.5;
    cursor: pointer;
    font-size: 0.75rem;
    padding: 0.1rem 0.2rem;
    transition: opacity 0.15s, color 0.15s;
    position: relative;
    z-index: 10;
}

.favs-io-sidebar-btn:hover {
    opacity: 1;
    color: var(--theme-primary);
}

.sound-btn:hover {
    border-color: var(--theme-primary);
    background-color: var(--theme-list-hover);
}

.sound-btn:active {
    background-color: var(--theme-list-active);
}

.sound-btn.playing {
    border-color: var(--theme-secondary);
    background-color: var(--theme-playing-bg);
    color: var(--theme-secondary);
    font-weight: 600;
    box-shadow: inset 0 0 0 1px var(--theme-secondary);
}

/* Mobile Sidebar Toggle */
.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--theme-text);
    font-size: 1.2rem;
    cursor: pointer;
    margin-right: 0.75rem;
}

/* Slider Toggle Switch */
.setting-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 1.5rem;
}

.setting-toggle label {
    margin: 0;
    cursor: pointer;
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    -webkit-transition: .4s;
    transition: .4s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    -webkit-transition: .4s;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--theme-primary);
}

input:focus+.slider {
    box-shadow: 0 0 1px var(--theme-primary);
}

input:checked+.slider:before {
    -webkit-transform: translateX(26px);
    -ms-transform: translateX(26px);
    transform: translateX(26px);
}

/* Modal tweaks */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background-color: var(--theme-surface);
    border: 1px solid var(--theme-border);
    border-radius: 8px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    transform: translateY(20px);
    transition: transform 0.2s ease;
}

.modal-overlay.open .modal {
    transform: translateY(0);
}

.modal-header {
    padding: 1rem;
    border-bottom: 1px solid var(--theme-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 1.1rem;
    color: var(--theme-accent);
    margin: 0;
}

.close-btn {
    background: none;
    border: none;
    color: var(--theme-text-muted);
    font-size: 1.2rem;
    cursor: pointer;
}

.close-btn:hover {
    color: var(--theme-text);
}

.modal-body {
    padding: 1.5rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--theme-text);
    font-weight: 500;
}

.form-select {
    width: 100%;
    padding: 0.5rem;
    background-color: var(--theme-bg);
    border: 1px solid var(--theme-border);
    color: var(--theme-text);
    border-radius: 4px;
    font-size: var(--font-ui);
    outline: none;
}

.form-select:focus {
    border-color: var(--theme-primary);
}

.modal-footer {
    padding: 1rem;
    border-top: 1px solid var(--theme-border);
    text-align: right;
}

/* Keyboard Help */
.shortcut-table {
    width: 100%;
    border-collapse: collapse;
}

.shortcut-table tr {
    border-bottom: 1px solid var(--theme-border);
}

.shortcut-table td {
    padding: 0.5rem 0.4rem;
    font-size: var(--font-small);
}

.shortcut-table td:first-child {
    white-space: nowrap;
    width: 100px;
    color: var(--theme-text-muted);
}

kbd {
    display: inline-block;
    padding: 0.15rem 0.4rem;
    font-size: 0.75rem;
    font-family: monospace;
    color: var(--theme-text);
    background: var(--theme-bg);
    border: 1px solid var(--theme-border);
    border-radius: 3px;
    min-width: 1.4rem;
    text-align: center;
}

/* Upload */
.upload-btn {
    background: var(--theme-bg);
    border: 1px solid var(--theme-border);
    color: var(--theme-text);
    padding: 0.4rem 0.75rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: var(--font-small);
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    transition: all 0.15s;
}

.upload-btn:hover {
    border-color: var(--theme-primary);
    color: var(--theme-primary);
}

.upload-status {
    margin-top: 0.4rem;
    font-size: var(--font-small);
    color: var(--theme-text-muted);
}

.upload-success {
    color: var(--theme-secondary);
}

.upload-error {
    color: #ff3c3c;
}

.hint-text {
    font-size: var(--font-small);
    color: var(--theme-text-muted);
    margin-top: 0.3rem;
}

/* Responsive */
@media (max-width: 768px) {
    aside {
        position: fixed;
        left: -100%;
        top: var(--header-height);
        bottom: 0;
        z-index: 100;
        transition: left 0.2s ease;
        box-shadow: 4px 0 10px rgba(0, 0, 0, 0.5);
        width: 80%;
        max-width: 300px;
    }

    aside.open {
        left: 0;
    }

    .mobile-menu-btn {
        display: block;
    }

    .search-container {
        margin: 0 0.5rem;
    }

    main {
        padding: 0.5rem;
    }

    .sound-grid {
        gap: 0.4rem;
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }

    .sound-btn {
        min-height: 38px;
    }
}


/* THEME DEFINITIONS */

/* 1. Dark Mode Default (Base :root) */
/* Already defined in :root above, essentially */

/* 2. Antique White */
body.theme-antique-white {
    --theme-bg: #FFF8F0;
    --theme-surface: #FAEBD7;
    --theme-text: #343434;
    --theme-text-muted: #666666;
    /* Computed for readability */
    --theme-primary: #D2B48C;
    /* Light Tan */
    --theme-secondary: #A0522D;
    /* Medium Sienna as accent */
    --theme-accent: #A0522D;
    --theme-border: #D4C5B9;
    --theme-playing-bg: rgba(160, 82, 45, 0.1);
    --theme-list-hover: rgba(0, 0, 0, 0.05);
    /* Standard dark hover on light bg */
    --theme-list-active: rgba(0, 0, 0, 0.1);
}

/* 3. Forest Green */
body.theme-forest-green {
    --theme-bg: #0a1f0a;
    --theme-surface: #112911;
    /* Slightly lighter than bg */
    --theme-text: #e0f2e0;
    --theme-text-muted: #8FBC8F;
    --theme-primary: #228B22;
    --theme-secondary: #3CB371;
    --theme-accent: #00FF00;
    --theme-border: #228B22;
    /* Primary as border */
    --theme-playing-bg: rgba(34, 139, 34, 0.2);
    --theme-list-hover: rgba(255, 255, 255, 0.05);
    --theme-list-active: rgba(255, 255, 255, 0.1);
}

/* 4. Orange Sunset */
body.theme-orange-sunset {
    --theme-bg: #1a0f0a;
    /* Dark Warm */
    --theme-surface: #2d1a10;
    /* Darker warm surface */
    --theme-text: #fff5e6;
    --theme-text-muted: #ffccbc;
    --theme-primary: #D84315;
    --theme-secondary: #FF6F00;
    --theme-accent: #FF9500;
    --theme-border: #4a2c00;
    --theme-playing-bg: rgba(255, 111, 0, 0.15);
    --theme-list-hover: rgba(255, 255, 255, 0.05);
    --theme-list-active: rgba(255, 255, 255, 0.1);
}

/* Specific component tweaks for Light Themes (Antique) */
body.theme-antique-white {
    --theme-list-bg: #FAEBD7;
    --theme-list-hover: rgba(160, 82, 45, 0.08);
    --theme-list-active: rgba(160, 82, 45, 0.15);
}

body.theme-antique-white header {
    border-bottom-color: var(--theme-secondary);
}

body.theme-antique-white #search-input {
    background-color: #FFFFFF;
    border-color: var(--theme-secondary);
}

body.theme-antique-white .sound-btn {
    background-color: #FFFFFF;
    color: #343434;
    border-color: #D4C5B9;
}

body.theme-antique-white .sound-btn:hover {
    background-color: rgba(210, 180, 140, 0.2);
    border-color: var(--theme-secondary);
}

body.theme-antique-white .sound-btn.playing {
    background-color: rgba(160, 82, 45, 0.1);
    color: var(--theme-secondary);
    border-color: var(--theme-secondary);
}

body.theme-antique-white .fav-btn {
    color: #D4C5B9;
}

body.theme-antique-white .sound-btn .sound-icon {
    opacity: 0.6;
}

body.theme-antique-white .search-results fieldset {
    border-color: #D4C5B9;
}

body.theme-antique-white aside {
    background-color: #FFF8F0;
}

body.theme-antique-white .modal {
    background-color: #FAEBD7;
}

body.theme-antique-white kbd {
    background: #FFFFFF;
    border-color: #D4C5B9;
    color: #343434;
}