:root {
    --bg-dark: #0f172a;
    --bg-panel: rgba(30, 41, 59, 0.7);
    --primary: #f43f5e;
    /* TikTok Pink-ish */
    --secondary: #3b82f6;
    /* Blue */
    --accent: #22d3ee;
    /* Cyan */
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', system-ui, sans-serif;
}

body {
    background-color: var(--bg-dark);
    background-image: radial-gradient(circle at 10% 20%, rgba(244, 63, 94, 0.1) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(59, 130, 246, 0.1) 0%, transparent 40%);
    color: var(--text-main);
    min-height: 100vh;
    padding: 0.8rem 1rem 3rem;
    /* Reduced padding for compact view */
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.8rem;
    /* Reduced margin */
    padding-bottom: 0.5rem;
    /* Reduced padding */
    border-bottom: 1px solid var(--border);
}

h1 {
    font-size: 1.8rem;
    background: linear-gradient(to right, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 800;
}

/* Connect Panel */
.connect-panel {
    display: flex;
    gap: 1rem;
    align-items: center;
}

input[type="text"] {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    color: white;
    padding: 0.8rem 1.2rem;
    border-radius: 8px;
    outline: none;
    font-size: 1rem;
    min-width: 250px;
}

input[type="text"]:focus {
    border-color: var(--secondary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}

.btn {
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #e11d48);
    color: white;
    box-shadow: 0 4px 12px rgba(244, 63, 94, 0.4);
}

.btn-primary:hostname {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(244, 63, 94, 0.5);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-danger {
    background: #ef4444;
    color: white;
}

.btn-module {
    background: rgba(30, 41, 59, 0.8);
    border: 1px solid var(--secondary);
    color: var(--secondary);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    font-weight: 600;
    transition: all 0.2s;
    font-size: 0.95rem;
}

.btn-module:hover {
    background: var(--secondary);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

/* Grid Layout */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    /* Smaller min-width for more columns */
    gap: 1rem;
    /* Reduced gap */
}

.panel {
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 12px;
    /* Slightly smaller radius */
    padding: 1rem;
    /* Reduced padding */
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.8rem;
    /* Reduced margin */
}

.panel-title {
    font-size: 1rem;
    /* Reduced font size */
    font-weight: 600;
    color: var(--accent);
}

/* Forms & Controls */
.form-group {
    margin-bottom: 0.6rem;
    /* Reduced margin */
}

label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

select {
    width: 100%;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--border);
    color: white;
    padding: 0.8rem;
    border-radius: 8px;
    outline: none;
}

input[type="range"] {
    width: 100%;
    accent-color: var(--secondary);
}

/* Checkbox List */
.checkbox-list {
    display: grid;
    gap: 0.8rem;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.5rem;
    border-radius: 6px;
    transition: background 0.2s;
}

.checkbox-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

/* Sound List */
.sound-list {
    display: grid;
    gap: 0.8rem;
    max-height: 400px;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.sound-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: rgba(15, 23, 42, 0.6);
    padding: 0.8rem;
    border-radius: 8px;
    border-left: 3px solid var(--secondary);
}

.sound-gift-img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    background: #333;
}

.sound-info {
    flex: 1;
}

.sound-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.sound-trigger {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Status Bar */
.status-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(5px);
    padding: 0.8rem 2rem;
    font-size: 0.9rem;
    display: flex;
    justify-content: space-between;
    border-top: 1px solid var(--border);
}

.status-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ef4444;
}

.dot.connected {
    background: #22c55e;
    box-shadow: 0 0 10px #22c55e;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

/* Custom Dropdown for Images */
.custom-select-container {
    position: relative;
    width: 100%;
    font-size: 0.9rem;
}

.custom-select-trigger {
    background: #334155;
    color: white;
    padding: 8px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    user-select: none;
}

.custom-select-options {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #1e293b;
    border: 1px solid #475569;
    border-radius: 4px;
    max-height: 250px;
    overflow-y: auto;
    z-index: 100;
    display: none;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.custom-select-options.open {
    display: block;
}

.custom-option {
    padding: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.custom-option:hover {
    background: #334155;
}

.custom-option.selected {
    background: #0f172a;
    border-left: 3px solid var(--secondary);
}

.gift-icon-sm {
    width: 20px;
    height: 20px;
    object-fit: cover;
    border-radius: 4px;
}

/* Modal Styles - ADDED FOR ADMIN PANEL */
.modal {
    display: none;
    position: fixed;
    z-index: 9999;
    /* High z-index to be on top of everything */
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.8);
    /* Darker background */
    backdrop-filter: blur(5px);
}

.modal-content {
    background-color: #0f172a;
    margin: 10vh auto;
    /* 10% from top and centered */
    padding: 2rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    position: relative;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
    animation: modalFadeIn 0.3s ease-out;
}

.modal-content--compact {
    padding: 1.5rem;
}

.modal-header {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding-right: 1.5rem;
    /* space for close button */
}

.modal-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.25);
    color: #ef4444;
    box-shadow: 0 10px 30px rgba(239, 68, 68, 0.08);
}

.modal-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: #f8fafc;
    line-height: 1.2;
}

.modal-subtitle {
    margin-top: 2px;
    font-size: 0.85rem;
    color: #94a3b8;
}

.modal-divider {
    height: 1px;
    background: rgba(148, 163, 184, 0.15);
    margin: 1rem 0 1.25rem;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.close-modal {
    color: #94a3b8;
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 1.5rem;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s;
}

.close-modal:hover {
    color: #ef4444;
}

/* Active Session Item */
.active-session-item {
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.3);
    padding: 8px;
    margin-bottom: 5px;
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #f0fdf4;
}

.pulsing-dot {
    width: 8px;
    height: 8px;
    background-color: #22c55e;
    border-radius: 50%;
    box-shadow: 0 0 8px #22c55e;
}

/* ============================================
   MOBILE RESPONSIVE STYLES
   ============================================ */

/* Tablets and smaller (max-width: 768px) */
@media (max-width: 768px) {
    body {
        padding: 1rem;
    }

    header {
        flex-direction: column;
        gap: 1rem;
        align-items: flex-start;
    }

    h1 {
        font-size: 1.5rem;
    }

    .connect-panel {
        flex-direction: column;
        width: 100%;
    }

    input[type="text"] {
        width: 100%;
        min-width: unset;
    }

    .btn {
        width: 100%;
        justify-content: center;
    }

    .panel {
        padding: 1rem;
    }

    .form-group {
        margin-bottom: 1rem;
    }

    /* TTS Settings adjustments */
    #ttsTemplate {
        font-size: 0.75rem;
    }

    /* Admin Panel */
    #adminPanel {
        max-width: 100%;
    }

    /* Whitelist items */
    .whitelist-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .whitelist-item button {
        width: 100%;
    }

    /* Logs */
    #logs {
        max-height: 300px;
        font-size: 0.85rem;
    }

    /* Modal adjustments */
    .modal-content {
        width: 95%;
        max-width: 95%;
        margin: 5% auto;
        padding: 1.5rem;
    }

    /* Bulk add textarea */
    #bulkUsernames {
        min-height: 150px;
    }
}

/* Mobile phones (max-width: 480px) */
@media (max-width: 480px) {
    body {
        padding: 0.5rem;
    }

    h1 {
        font-size: 1.2rem;
    }

    .panel {
        padding: 0.75rem;
    }

    .panel-subtitle {
        font-size: 0.85rem !important;
    }

    input[type="text"],
    input[type="number"],
    input[type="password"],
    select,
    textarea {
        font-size: 16px;
        /* Prevents zoom on iOS */
        padding: 0.7rem 1rem;
    }

    .btn {
        padding: 0.7rem 1.2rem;
        font-size: 0.9rem;
    }

    /* Smaller spacing for form groups */
    .form-group {
        margin-bottom: 0.75rem;
    }

    label {
        font-size: 0.85rem;
    }

    /* Logs smaller on mobile */
    #logs {
        max-height: 200px;
        font-size: 0.8rem;
    }

    /* Stats display */
    .stat-item {
        font-size: 0.8rem;
    }

    /* Active sessions */
    .active-session-item {
        padding: 0.5rem;
        font-size: 0.75rem;
    }

    /* Modal on small screens */
    .modal-content {
        width: 98%;
        margin: 2% auto;
        padding: 1rem;
    }

    .modal-content h3 {
        font-size: 1.1rem;
    }

    /* Close button */
    .close-modal {
        font-size: 1.5rem;
    }

    /* Checkbox items */
    .checkbox-item {
        font-size: 0.8rem !important;
    }

    /* Range inputs */
    input[type="range"] {
        width: 100%;
    }
}

/* Landscape orientation on phones */
@media (max-width: 768px) and (orientation: landscape) {
    #logs {
        max-height: 150px;
    }

    .modal-content {
        max-height: 90vh;
        overflow-y: auto;
    }
}
/* Leaderboard Styles */
.leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    max-height: 250px;
    overflow-y: auto;
    padding-right: 0.4rem;
}

.leaderboard-item {
    display: flex;
    align-items: center;
    background: rgba(15, 23, 42, 0.6);
    padding: 0.5rem 0.8rem;
    border-radius: 8px;
    gap: 0.8rem;
}

.leaderboard-rank {
    font-size: 1.2rem;
    font-weight: bold;
    min-width: 30px;
    text-align: center;
}

.rank-1 .leaderboard-rank { color: #ffd700; text-shadow: 0 0 10px rgba(255, 215, 0, 0.5); }
.rank-2 .leaderboard-rank { color: #c0c0c0; text-shadow: 0 0 10px rgba(192, 192, 192, 0.5); }
.rank-3 .leaderboard-rank { color: #cd7f32; text-shadow: 0 0 10px rgba(205, 127, 50, 0.5); }

.leaderboard-info {
    flex: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.leaderboard-name {
    font-weight: 600;
    font-size: 0.9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 120px;
}

.leaderboard-score {
    font-weight: bold;
    color: var(--primary);
    font-size: 0.9rem;
}

.overlay-link-container {
    margin-top: 0.8rem;
    display: flex;
    gap: 0.5rem;
}

.overlay-input {
    flex: 1;
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.75rem;
    padding: 0.4rem;
    border-radius: 4px;
}

.overlay-copy-btn {
    background: var(--secondary);
    color: white;
    border: none;
    border-radius: 4px;
    padding: 0 0.8rem;
    cursor: pointer;
    font-size: 0.8rem;
}

/* ======== Leaderboard animated styles ======== */

/* Animations */
@keyframes lb-bounce {
  0%, 100% { transform: translateY(0) scale(1); }
  30%       { transform: translateY(-8px) scale(1.2); }
  60%       { transform: translateY(-3px) scale(1.05); }
}
@keyframes lb-sparkle {
  0%   { opacity: 0;   transform: scale(0.5) rotate(0deg); }
  50%  { opacity: 1;   transform: scale(1.3) rotate(15deg); }
  100% { opacity: 0;   transform: scale(0.5) rotate(30deg); }
}
@keyframes lb-glow-gold {
  0%,100% { box-shadow: 0 0 6px 2px rgba(255,215,0,0.4); }
  50%     { box-shadow: 0 0 20px 6px rgba(255,215,0,0.9); }
}
@keyframes lb-glow-silver {
  0%,100% { box-shadow: 0 0 6px 2px rgba(192,192,192,0.4); }
  50%     { box-shadow: 0 0 18px 5px rgba(192,192,192,0.8); }
}
@keyframes lb-glow-bronze {
  0%,100% { box-shadow: 0 0 6px 2px rgba(205,127,50,0.4); }
  50%     { box-shadow: 0 0 16px 5px rgba(205,127,50,0.8); }
}

/* Base leaderboard item */
.leaderboard-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 8px;
  margin-bottom: 4px;
  background: rgba(30, 41, 59, 0.85);
  transition: background 0.3s;
}

/* Top-3 glow cards */
.lb-item-lb-gold   { background: rgba(40,30,5,0.9); animation: lb-glow-gold   2s ease-in-out infinite; border-left: 3px solid #ffd700; }
.lb-item-lb-silver { background: rgba(30,35,42,0.9); animation: lb-glow-silver 2.5s ease-in-out infinite; border-left: 3px solid #c0c0c0; }
.lb-item-lb-bronze { background: rgba(35,25,10,0.9); animation: lb-glow-bronze 3s ease-in-out infinite; border-left: 3px solid #cd7f32; }
.lb-item-normal    { background: rgba(25,32,45,0.7); }

/* Crown bounce */
.lb-crown {
  display: inline-block;
  font-size: 1.3rem;
  animation: lb-bounce 1.4s ease-in-out infinite;
}
.lb-crown-gold   { animation-duration: 1.2s; }
.lb-crown-silver { animation-duration: 1.5s; }
.lb-crown-bronze { animation-duration: 1.8s; }

/* Sparkles */
.lb-sparkles {
  font-size: 0.75rem;
  margin-left: 4px;
  animation: lb-sparkle 1.5s ease-in-out infinite;
}

/* Layout helpers */
.lb-rank  { min-width: 38px; text-align: center; font-weight: bold; font-size: 1.1rem; }
.lb-name  { flex: 1; font-weight: 600; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.lb-score { font-weight: 800; font-size: 1rem; white-space: nowrap; }
