:root {
    --bg-color: #0a0e1a;
    --bg-card: rgba(22, 28, 45, 0.85);
    --text-color: #e2e8f0;
    --text-muted: #94a3b8;
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --accent: #10b981;
    --accent-hover: #059669;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --secondary: #475569;
    --border: rgba(255, 255, 255, 0.08);
    --glow-blue: rgba(99, 102, 241, 0.3);
    --glow-green: rgba(16, 185, 129, 0.3);
    --glow-gold: rgba(251, 191, 36, 0.3);
    --glow-pink: rgba(236, 72, 153, 0.3);
    --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-color);
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(99, 102, 241, 0.08), transparent 60%),
        radial-gradient(ellipse at 80% 20%, rgba(16, 185, 129, 0.06), transparent 50%);
    color: var(--text-color);
    min-height: 100vh;
    padding: 1.5rem;
    line-height: 1.5;
}

.container { max-width: 1280px; margin: 0 auto; }

/* ---- HEADER ---- */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.header-left h1 {
    font-size: 1.75rem;
    font-weight: 800;
    background: linear-gradient(135deg, #818cf8, #a78bfa, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

#lang-select {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: white;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
}
#lang-select option { background: #161c2d; }

.status-panel {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-card);
    padding: 0.5rem 1rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    font-size: 0.85rem;
}

.status-dot { width: 10px; height: 10px; border-radius: 50%; transition: all 0.3s; }
.status-dot.disconnected { background: var(--danger); box-shadow: 0 0 8px var(--danger); }
.status-dot.live { background: var(--accent); box-shadow: 0 0 12px var(--accent); animation: pulse 1.5s infinite; }
.status-dot.offline { background: #f59e0b; box-shadow: 0 0 8px #f59e0b; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ---- GLASS PANEL ---- */
.glass-panel {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    transition: transform 0.2s, box-shadow 0.2s;
}

/* ---- CONNECT BAR ---- */
.connect-bar {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    align-items: center;
}

input[type="text"], input[type="number"], select {
    background: rgba(10, 14, 26, 0.7);
    border: 1px solid var(--border);
    color: white;
    padding: 0.6rem 0.8rem;
    border-radius: 8px;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.3s;
}
input:focus, select:focus { border-color: var(--primary); }
select option { background: #161c2d; }

#username-input { flex: 1; }

/* ---- BUTTONS ---- */
button {
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
button:active { transform: scale(0.97); }

.btn-primary, #connect-btn { background: var(--primary); color: white; }
.btn-primary:hover, #connect-btn:hover { background: var(--primary-hover); box-shadow: 0 4px 15px var(--glow-blue); }

.btn-accent { background: var(--accent); color: white; }
.btn-accent:hover { background: var(--accent-hover); }

.btn-secondary, #reset-btn { background: var(--secondary); color: white; }
.btn-secondary:hover { background: #64748b; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: var(--danger-hover); }

.full-w { width: 100%; }

/* ---- STATS ---- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

@media (max-width: 900px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 4px; height: 100%;
    border-radius: 4px 0 0 4px;
}

.card-diamond::before { background: linear-gradient(to bottom, #60a5fa, #3b82f6); }
.card-time::before { background: linear-gradient(to bottom, #a78bfa, #8b5cf6); }
.card-usd::before { background: linear-gradient(to bottom, #34d399, #10b981); }
.card-vnd::before { background: linear-gradient(to bottom, #fbbf24, #f59e0b); }

.stat-icon { font-size: 2rem; opacity: 0.8; }
.stat-label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 1.6rem; font-weight: 800; line-height: 1.2; }
.stat-sub { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }

.stats-grid-5 { grid-template-columns: repeat(5, 1fr); }
@media (max-width: 900px) { .stats-grid-5 { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 600px) { .stats-grid-5 { grid-template-columns: repeat(2, 1fr); } }

.card-viewer::before { background: linear-gradient(to bottom, #38bdf8, #0ea5e9); }
.card-total-view::before { background: linear-gradient(to bottom, #a78bfa, #7c3aed); }
.card-follow::before { background: linear-gradient(to bottom, #4ade80, #22c55e); }
.card-like::before { background: linear-gradient(to bottom, #fb7185, #e11d48); }
.card-share::before { background: linear-gradient(to bottom, #fbbf24, #d97706); }

.summary-card {
    background: linear-gradient(135deg, rgba(99,102,241,0.15), rgba(139,92,246,0.1));
    border: 1px solid rgba(99,102,241,0.3);
    border-radius: 12px;
    padding: 1.25rem;
    margin-bottom: 1rem;
}
.summary-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 0.75rem; flex-wrap: wrap; gap: 0.5rem;
}
.summary-header h3 { font-size: 1.1rem; color: #a78bfa; }
.btn-summary {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white; font-size: 0.8rem; padding: 0.4rem 1rem;
}
.btn-summary:hover { box-shadow: 0 4px 12px var(--glow-blue); }

/* ---- MAIN GRID ---- */
.main-grid {
    display: grid;
    grid-template-columns: 1fr 1.3fr;
    gap: 1.5rem;
}

@media (max-width: 900px) {
    .main-grid { grid-template-columns: 1fr; }
}

.left-col { display: flex; flex-direction: column; gap: 1.5rem; }
.right-col { display: flex; flex-direction: column; gap: 1.5rem; }

/* ---- LEADERBOARD ---- */
.leaderboard h2 { font-size: 1.1rem; margin-bottom: 0.75rem; }
.leaderboard ul { list-style: none; }
.leaderboard li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0.5rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
    transition: background 0.2s;
}
.leaderboard li:hover { background: rgba(255,255,255,0.03); border-radius: 6px; }
.leaderboard li:last-child { border-bottom: none; }
.rank { font-weight: bold; color: #fbbf24; margin-right: 0.4rem; }

/* ---- BGM ---- */
.bgm-panel h2 { font-size: 1.1rem; margin-bottom: 0.5rem; }
.bgm-controls { display: flex; gap: 0.5rem; margin-bottom: 0.75rem; }
.bgm-controls select { flex: 1; }

.volume-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}
.volume-row input[type="range"] {
    flex: 1;
    -webkit-appearance: none;
    height: 6px;
    background: rgba(255,255,255,0.15);
    border-radius: 3px;
    outline: none;
}
.volume-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px; height: 16px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 6px var(--glow-blue);
}
.volume-row span { font-size: 0.8rem; color: var(--text-muted); min-width: 35px; text-align: right; }

/* ---- SETTINGS ---- */
.settings-panel h2 { font-size: 1.1rem; margin-bottom: 0.75rem; }

.settings-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.6rem;
    font-size: 0.9rem;
}
.settings-row input[type="number"] { width: 110px; }

.help-text { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.75rem; line-height: 1.4; }

.divider { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }

/* ---- AUDIO ROW ---- */
.audio-row {
    display: grid;
    grid-template-columns: 1.2fr 1.5fr auto;
    gap: 8px;
    background: rgba(0,0,0,0.25);
    padding: 10px;
    border-radius: 10px;
    margin-bottom: 8px;
    border: 1px solid rgba(255,255,255,0.04);
    align-items: center;
}

.audio-col { display: flex; flex-direction: column; gap: 4px; }
.audio-col select, .audio-col input[type="text"] { width: 100%; font-size: 0.8rem; padding: 0.4rem; }
.audio-col input[type="file"] { font-size: 0.7rem; padding: 3px; background: rgba(255,255,255,0.04); border-radius: 4px; color: var(--text-muted); }
.audio-col label { font-size: 0.75rem; color: var(--text-muted); }

.audio-actions { display: flex; flex-direction: column; gap: 4px; }

.btn-sm {
    padding: 0.35rem 0.6rem;
    font-size: 0.75rem;
    border-radius: 6px;
}

.btn-update { background: var(--accent); color: white; }
.btn-update:hover { background: var(--accent-hover); }
.btn-del { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
.btn-del:hover { background: var(--danger); color: white; }

.btn-add-effect {
    width: 100%;
    margin-top: 0.75rem;
    border: 2px dashed var(--primary);
    background: rgba(99, 102, 241, 0.1);
    color: #818cf8;
    font-size: 0.9rem;
}
.btn-add-effect:hover { background: rgba(99, 102, 241, 0.2); }

/* ---- NOTIFICATIONS ---- */
#notification-area {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 50;
    max-height: 80vh;
    overflow: hidden;
}

.notification {
    background: rgba(10, 14, 26, 0.95);
    border: 1px solid var(--accent);
    color: white;
    padding: 0.75rem 1rem;
    border-radius: 10px;
    box-shadow: 0 4px 20px var(--glow-green);
    animation: slideIn 0.35s ease-out, fadeOut 0.5s ease-in 4s forwards;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.85rem;
}
.notification img { width: 40px; height: 40px; border-radius: 6px; }

@keyframes slideIn {
    from { transform: translateX(120%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
@keyframes fadeOut { to { opacity: 0; pointer-events: none; } }

/* ---- TAB NAV ---- */
.tab-nav {
    display: flex;
    gap: 0;
    margin-bottom: 1.5rem;
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border);
    overflow: hidden;
}

.tab-btn {
    flex: 1;
    padding: 0.8rem 1.5rem;
    border-radius: 0;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.95rem;
    font-weight: 600;
    border: none;
    transition: all 0.2s;
}
.tab-btn:hover { background: rgba(255,255,255,0.05); color: var(--text-color); }
.tab-btn.active {
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    color: white;
    box-shadow: 0 4px 15px var(--glow-blue);
}

.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn 0.3s ease; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---- HISTORY ---- */
.history-card {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem;
    margin-bottom: 1rem;
    transition: border-color 0.2s;
}
.history-card:hover { border-color: var(--primary); }

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.history-header h3 {
    font-size: 1rem;
    font-weight: 700;
    color: #818cf8;
}

.history-actions { display: flex; gap: 0.5rem; }

.history-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.history-stat {
    background: rgba(255,255,255,0.03);
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
}
.history-stat .hs-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; }
.history-stat .hs-value { font-size: 1.1rem; font-weight: 700; }

.history-gifters {
    font-size: 0.8rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    padding-top: 0.5rem;
}
.history-gifters span { color: #fbbf24; font-weight: 600; }

.btn-excel {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    font-size: 0.8rem;
    padding: 0.4rem 0.8rem;
}
.btn-excel:hover { box-shadow: 0 4px 10px var(--glow-green); }

.btn-del-hist {
    background: transparent;
    border: 1px solid var(--danger);
    color: var(--danger);
    font-size: 0.8rem;
    padding: 0.4rem 0.8rem;
}
.btn-del-hist:hover { background: var(--danger); color: white; }

/* ---- GIFTS CATALOG ---- */
.gifts-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 0.75rem; flex-wrap: wrap; gap: 0.75rem;
}
.gifts-header h2 { margin: 0; font-size: 1.2rem; }
.gifts-controls { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.gifts-controls select, .gifts-controls input { min-width: 140px; }

.gifts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(125px, 1fr));
    gap: 12px; margin-top: 1rem;
}
.gift-card {
    background: rgba(0,0,0,0.3); border: 1px solid var(--border);
    border-radius: 12px; padding: 12px; text-align: center;
    position: relative; cursor: default;
    transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
}
.gift-card:hover {
    transform: translateY(-3px);
    border-color: rgba(99,102,241,0.4);
    box-shadow: 0 8px 20px rgba(0,0,0,0.3);
}
.gift-card img { width: 64px; height: 64px; object-fit: contain; margin-bottom: 6px; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3)); }
.gift-card .gift-name { font-size: 0.75rem; font-weight: 600; line-height: 1.2; margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gift-card .gift-coins { font-size: 0.7rem; color: #fbbf24; font-weight: 700; }
.gift-fav-btn {
    position: absolute; top: 6px; right: 6px;
    width: 26px; height: 26px; border-radius: 50%; border: none;
    background: transparent; color: rgba(255,255,255,0.5); font-size: 18px;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: all 0.25s; padding: 0; line-height: 1;
}
.gift-fav-btn:hover { color: rgba(239,68,68,0.8); transform: scale(1.15); }
.gift-fav-btn.active { color: #ef4444; transform: scale(1.1); }
.gift-card.favorited { border-color: rgba(239,68,68,0.3); }

/* ---- CUSTOM GIFT SELECT ---- */
.custom-gift-select {
    position: relative;
    width: 100%;
    outline: none;
}
.cgs-trigger {
    background: rgba(10, 14, 26, 0.7);
    border: 1px solid var(--border);
    color: white;
    padding: 0.4rem 0.6rem;
    border-radius: 8px;
    font-size: 0.8rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    transition: border-color 0.3s;
}
.custom-gift-select:focus .cgs-trigger,
.cgs-trigger:hover {
    border-color: var(--primary);
}
.cgs-options {
    position: absolute;
    top: 100%;
    left: 0; right: 0;
    max-height: 250px;
    overflow-y: auto;
    background: #1e293b;
    border: 1px solid rgba(255,255,255,0.1);
    z-index: 100;
    display: none;
    border-radius: 6px;
    margin-top: 4px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
}
.cgs-options.open {
    display: block;
}
.cgs-option {
    padding: 0.5rem;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.85rem;
}
.cgs-option:hover {
    background: rgba(255,255,255,0.1);
}
.cgs-img {
    width: 20px; height: 20px; object-fit: contain;
}
.cgs-lbl {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---- MODAL UI ---- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(5px);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
}
.modal-content {
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.15);
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    animation: modal-pop 0.3s ease-out;
}
@keyframes modal-pop {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

/* Custom Modal scrollbar */
#modal-gifts-grid::-webkit-scrollbar {
    width: 6px;
}
#modal-gifts-grid::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 4px;
}
#modal-gifts-grid::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.1);
}

/* ---- FOOTER ---- */
.app-footer {
    margin-top: 3rem;
    padding: 1.5rem 0;
    text-align: center;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.8rem;
    letter-spacing: 0.3px;
}
