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

:root {
    --bg:         #121212;
    --bg2:        #1e1e1e;
    --bg3:        #2a2a2a;
    --border:     #333;
    --text:       #ffffff;
    --text2:      #aaaaaa;
    --text3:      #666666;
    --accent:     #007bff;
    --accent2:    #0056b3;
    --green:      #2a5a2a;
    --green-text: #7dcc7d;
    --amber:      #5a3a00;
    --amber-text: #ffaa00;
    --danger:     #c0392b;
    --tab-h:      60px;
    --header-h:   52px;
}

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
}

/* ============================================================
   Auth Screen
   ============================================================ */
.auth-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-card {
    background: var(--bg2);
    border-radius: 20px;
    padding: 36px 28px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.5);
    text-align: center;
}

.auth-title {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
}

.auth-subtitle {
    color: var(--text2);
    font-size: 14px;
    margin-bottom: 32px;
}

/* ============================================================
   App Shell
   ============================================================ */
.app {
    display: flex;
    flex-direction: column;
}

/* ── Header ── */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-h);
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 12px;
    z-index: 100;
}

.app-title {
    font-weight: 700;
    font-size: 17px;
    flex: 1;
}

.user-area {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ── User dropdown menu ── */
.user-menu-wrapper {
    position: relative;
}

.user-menu-trigger {
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 10px;
    border-radius: 8px;
    color: var(--text2);
    font-size: 14px;
    transition: background 0.15s;
    max-width: 160px;
}
.user-menu-trigger:active { background: var(--bg3); }
.user-menu-trigger span:first-child {
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-menu-arrow {
    font-size: 22px;
    flex-shrink: 0;
    transition: transform 0.2s;
}
.user-menu-arrow.open { transform: rotate(180deg); }

.user-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 12px;
    min-width: 190px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    z-index: 300;
    overflow: hidden;
}
.user-dropdown.open { display: block; }

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 13px 16px;
    background: none;
    border: none;
    color: var(--text);
    font-size: 15px;
    cursor: pointer;
    text-align: left;
    transition: background 0.1s;
}
.dropdown-item:active { background: var(--bg3); }
.dropdown-item + .dropdown-item { border-top: 1px solid var(--border); }
.dropdown-item.danger { color: #ff6b6b; }

/* ── Scrollable content area ── */
.app-body {
    padding-bottom: var(--tab-h);
}

/* ── Tab bar ── */
.tab-bar {
    flex-shrink: 0;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--tab-h);
    background: var(--bg2);
    border-top: 1px solid var(--border);
    display: flex;
    z-index: 100;
}

.tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text3);
    font-size: 11px;
    padding: 4px 0;
    transition: color 0.15s;
}
.tab-btn.active { color: var(--accent); }
.tab-btn:active { opacity: 0.7; }

.tab-icon { font-size: 20px; line-height: 1; }
.tab-label { font-size: 11px; }

/* ── Tab content ── */
.tab-content { display: none; padding: 12px 12px 8px; }
.tab-content.active { display: block; }

/* ============================================================
   My Queue Blocks
   ============================================================ */
.my-queue {
    background: #0d1f0d;
    border: 1px solid var(--green);
    border-radius: 10px;
    padding: 12px;
    margin: 12px 12px 0;
}

.my-queue .queue-title {
    font-size: 13px;
    color: var(--green-text);
    font-weight: 700;
    margin-bottom: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
}
.queue-toggle-arrow { font-size: 25px; line-height: 1; transition: transform 0.2s; }
.queue-toggle-arrow.collapsed { transform: rotate(-90deg); }

#stickyZone {
    position: sticky;
    top: var(--header-h);
    background: var(--bg);
    z-index: 50;
    margin-top: var(--header-h);
}

.search-bar-sticky {
    padding: 8px 12px 4px;
}

#myQueueList {
    max-height: 120px;
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}
#myQueueList.collapsed { display: none; }

.pending-queue {
    background: #1f1500;
    border: 1px solid var(--amber);
    border-radius: 10px;
    padding: 12px;
    margin: 8px 12px 0;
}

.pending-queue .queue-title { font-size: 13px; color: var(--amber-text); font-weight: 700; margin-bottom: 8px; }

.queue-item { font-size: 13px; color: #ccc; padding: 5px 0; border-bottom: 1px solid #1a3a1a; }
.queue-item:last-child { border-bottom: none; }
.queue-item-mine { color: #fff; font-weight: 600; background: rgba(0,123,255,0.1); border-radius: 4px; padding-left: 4px; }
.queue-pos { color: var(--green-text); font-weight: 700; margin-right: 4px; }
.queue-singer { color: var(--text2); font-size: 11px; margin-right: 4px; }
.queue-now { color: #ffe066; font-size: 12px; margin-right: 4px; }
.queue-wait { color: var(--text2); font-size: 12px; margin-left: 6px; }

#pendingList {
    max-height: 120px;
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.pending-item { font-size: 14px; color: #ccc; padding: 4px 0; border-bottom: 1px solid #3a2000; }
.pending-item:last-child { border-bottom: none; }
.cancel-queue-btn, .cancel-pending-btn {
    background: none; border: none; color: #e05; font-size: 14px;
    cursor: pointer; padding: 0 4px; opacity: 0.7; vertical-align: middle;
}
.cancel-queue-btn:hover, .cancel-pending-btn:hover { opacity: 1; }
.cancel-sent { font-size: 11px; color: var(--text2); font-style: italic; }

.song-ft { font-size: 12px; color: var(--text2); font-style: italic; }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
    display: block;
    width: 100%;
    padding: 13px 20px;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 10px;
    transition: opacity 0.15s, background 0.15s;
    text-align: center;
}
.btn:active { opacity: 0.75; }

.btn-primary  { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--bg3); color: var(--text); }
.btn-ghost    { background: #3a3a3a; color: var(--text2); }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-warn     { background: #f90; color: #000; font-size: 13px; padding: 8px 12px; }

/* ============================================================
   Form Elements
   ============================================================ */
.modal-hint {
    color: var(--text2);
    font-size: 13px;
    margin-bottom: 14px;
    line-height: 1.5;
}

input[type=text],
input[type=password],
input[type=number] {
    width: 100%;
    padding: 12px;
    margin-bottom: 8px;
    border-radius: 10px;
    border: 1px solid var(--border);
    font-size: 16px;
    background: var(--bg3);
    color: var(--text);
    outline: none;
    transition: border-color 0.15s;
}
input:focus { border-color: var(--accent); }
input::placeholder { color: var(--text3); }
input[type=number] { width: 70px; margin-bottom: 0; }

.pw-wrap {
    position: relative;
    margin-bottom: 8px;
}
.pw-wrap input {
    margin-bottom: 0;
    padding-right: 44px;
    width: 100%;
}
.pw-eye {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: var(--text3);
    display: flex;
    align-items: center;
    line-height: 1;
}
.pw-eye.visible { color: var(--accent); }

.form-error {
    color: #ff6b6b;
    font-size: 13px;
    min-height: 18px;
    margin-bottom: 4px;
}

.name-status {
    font-size: 13px;
    min-height: 18px;
    margin-bottom: 4px;
}
.name-status.ok    { color: #6dbf6d; }
.name-status.error { color: #ff6b6b; }

/* ============================================================
   Modals
   ============================================================ */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal {
    background: var(--bg2);
    border-radius: 18px;
    padding: 24px 20px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.7);
}

.modal h3 {
    margin-bottom: 16px;
    font-size: 18px;
    font-weight: 700;
}

.key-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
    color: var(--text2);
    font-size: 15px;
}

.quality-warning {
    background: #3a2000;
    border: 1px solid var(--amber-text);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 14px;
    font-size: 14px;
    color: #ffcc88;
    line-height: 1.5;
}

/* ============================================================
   Search Tab
   ============================================================ */
.search-legend {
    display: flex;
    gap: 14px;
    margin-bottom: 10px;
    font-size: 12px;
    color: var(--text2);
    flex-wrap: wrap;
}

.search-wrap {
    position: relative;
    margin-bottom: 10px;
}
.search-wrap .search-input {
    margin-bottom: 0;
    padding-right: 38px;
}
.search-clear {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--bg3);
    border: none;
    border-radius: 50%;
    color: var(--text2);
    font-size: 16px;
    cursor: pointer;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.wish-btn {
    margin-top: 16px;
    font-size: 14px;
    font-weight: 400;
}

/* ── Song items ── */
.song-item {
    background: var(--bg2);
    padding: 11px 14px;
    border-bottom: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: background 0.1s;
    position: relative;
}
.song-item:active { background: var(--bg3); }

.quality-badge { flex-shrink: 0; font-size: 18px; line-height: 1; }
.song-label { flex: 1; font-size: 15px; line-height: 1.3; }

.star-btn {
    flex-shrink: 0;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 20px;
    padding: 4px 6px;
    line-height: 1;
    opacity: 0.5;
    transition: opacity 0.15s, transform 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.star-btn.active { opacity: 1; }
.star-btn:active { transform: scale(1.2); }

/* ============================================================
   Artists Tab
   ============================================================ */
.artists-sort {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.sort-btn {
    flex: 1;
    padding: 9px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg2);
    color: var(--text2);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s;
}
.sort-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.artist-item {
    background: var(--bg2);
    border-radius: 10px;
    margin-bottom: 6px;
    padding: 11px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: background 0.1s;
}
.artist-item:active { background: var(--bg3); }

.artist-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--bg3);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--text3);
    overflow: hidden;
}
.artist-avatar img { width: 100%; height: 100%; object-fit: cover; }

.artist-info { flex: 1; min-width: 0; }
.artist-name { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.artist-count { font-size: 12px; color: var(--text2); margin-top: 2px; }

.artist-badge {
    flex-shrink: 0;
    background: var(--bg3);
    color: var(--text2);
    font-size: 12px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 20px;
}

/* ── Artist Profile ── */
.artist-back-btn {
    position: fixed;
    top: 52px; /* fallback, overridden by JS */
    left: 0;
    right: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg2);
    border: none;
    border-bottom: 1px solid var(--border);
    color: var(--accent);
    font-size: 15px;
    padding: 10px 16px;
    cursor: pointer;
    width: 100%;
}
#artistProfile {
    padding-top: 44px;
}
.artist-profile-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 0 20px;
    gap: 12px;
}
.artist-profile-avatar {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    background: var(--bg3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 52px;
    color: var(--text3);
    overflow: hidden;
    flex-shrink: 0;
}
.artist-profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
.artist-profile-name {
    font-size: 22px;
    font-weight: 700;
    text-align: center;
}
.artist-profile-count {
    font-size: 13px;
    color: var(--text2);
    margin-top: -6px;
}

/* ============================================================
   Favorites Tab
   ============================================================ */
.fav-list { }

.fav-row {
    position: relative;
    overflow: hidden;
    border-radius: 10px;
    margin-bottom: 6px;
}

.fav-card {
    background: var(--bg2);
    padding: 11px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: transform 0.2s ease;
    border-radius: 10px;
    position: relative;
    z-index: 1;
}
.fav-card:active { background: var(--bg3); }

.fav-card .quality-badge { flex-shrink: 0; font-size: 18px; }
.fav-card .song-label { flex: 1; font-size: 15px; line-height: 1.3; }

.fav-delete-btn {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 70px;
    background: var(--danger);
    border: none;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0 10px 10px 0;
    z-index: 0;
}

.empty-state {
    text-align: center;
    color: var(--text2);
    padding: 48px 20px;
    font-size: 15px;
    line-height: 1.8;
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 16px; }

/* ============================================================
   History Tab
   ============================================================ */
.history-date-inline { font-size: 11px; color: var(--text2); margin-right: 4px; white-space: nowrap; }

/* ============================================================
   Guest login prompt (inside tabs)
   ============================================================ */
.guest-prompt {
    text-align: center;
    padding: 48px 20px;
    color: var(--text2);
    font-size: 15px;
    line-height: 1.8;
}
.guest-prompt .empty-icon { font-size: 48px; margin-bottom: 16px; }
.guest-prompt .btn { max-width: 260px; margin: 16px auto 0; }

/* ============================================================
   Admin Panel
   ============================================================ */
.admin-header {
    font-size: 18px;
    font-weight: 700;
    padding: 16px 16px 8px;
    color: var(--text1);
}

.admin-stats-row {
    display: flex;
    gap: 8px;
    padding: 8px 16px 16px;
    overflow-x: auto;
}

.admin-stat {
    flex: 1;
    min-width: 70px;
    background: var(--card);
    border-radius: 10px;
    padding: 10px 8px;
    text-align: center;
}
.admin-stat-val { font-size: 22px; font-weight: 700; color: var(--accent); }
.admin-stat-lbl { font-size: 11px; color: var(--text2); margin-top: 2px; }

.admin-section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 12px 16px 6px;
}

.admin-users-list { padding: 0 12px 8px; }

.admin-user-card {
    background: var(--card);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: opacity 0.15s;
}
.admin-user-card:active { opacity: 0.7; }
.admin-user-name { font-size: 16px; font-weight: 600; color: var(--text1); margin-bottom: 4px; }
.admin-user-meta { font-size: 12px; color: var(--text2); margin-top: 2px; }

.admin-log-list { padding: 0 12px 80px; }

.admin-log-item {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 8px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    font-size: 13px;
}
.admin-log-time  { color: var(--text2); font-size: 11px; white-space: nowrap; }
.admin-log-user  { font-weight: 600; color: var(--text1); }
.admin-log-action { color: var(--text2); flex: 1; }

.admin-user-detail-name {
    font-size: 20px;
    font-weight: 700;
    padding: 4px 16px 12px;
    color: var(--text1);
}

.admin-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    font-size: 13px;
    color: var(--text1);
}
.admin-empty {
    padding: 10px 16px;
    color: var(--text2);
    font-size: 13px;
    font-style: italic;
}


/* Key stepper (+/-) */
.key-stepper {
    display: flex;
    align-items: center;
    gap: 0;
    background: var(--bg3);
    border-radius: 8px;
    overflow: hidden;
}
.key-step-btn {
    background: transparent;
    border: none;
    color: var(--text1);
    font-size: 20px;
    font-weight: 700;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}
.key-step-btn:active { background: var(--accent); color: #fff; }
.key-val {
    min-width: 36px;
    text-align: center;
    font-size: 17px;
    font-weight: 700;
    color: var(--text2);
    padding: 0 2px;
}
.key-val.nonzero {
    color: var(--accent);
}

/* Favorites: key badge */
.fav-key-badge {
    font-size: 12px;
    font-weight: 700;
    color: var(--accent);
    background: rgba(var(--accent-rgb, 99,102,241), 0.15);
    border-radius: 5px;
    padding: 2px 6px;
    flex-shrink: 0;
    margin-left: auto;
}

/* Favorites: three-dots menu button */
.fav-menu-btn {
    background: transparent;
    border: none;
    color: var(--text2);
    font-size: 20px;
    line-height: 1;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    cursor: pointer;
    flex-shrink: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}
.fav-menu-btn:active { background: var(--bg3); }
