@import url('https://fonts.googleapis.com/css2?family=Syne:wght@400;600;700;800&family=Space+Mono:wght@400;700&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:       #0a0a0f;
    --surface:  #111118;
    --surface2: #1a1a24;
    --border:   #2a2a3a;
    --accent:   #00ff88;
    --accent2:  #ff3366;
    --text:     #e8e8f0;
    --muted:    #5a5a72;
    --glow:     0 0 20px rgba(0,255,136,0.25);
}

html, body { height: 100%; }

body {
    background-color: var(--bg);
    color: var(--text);
    font-family: 'Space Mono', monospace;
    min-height: 100vh;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 2rem; overflow-x: hidden; position: relative;
    transition: box-shadow 0.3s ease;
}

body.correct-flash { animation: edge-glow 1.2s ease forwards; }

@keyframes edge-glow {
    0%   { box-shadow: inset 0 0 0 rgba(0,255,136,0); }
    20%  { box-shadow: inset 0 0 80px rgba(0,255,136,0.35); }
    100% { box-shadow: inset 0 0 0 rgba(0,255,136,0); }
}

body::before {
    content: ''; position: fixed; inset: 0;
    background-image:
        linear-gradient(rgba(0,255,136,0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0,255,136,0.03) 1px, transparent 1px);
    background-size: 40px 40px; pointer-events: none; z-index: 0;
}

body::after {
    content: ''; position: fixed; inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
    pointer-events: none; z-index: 0; opacity: 0.5;
}

/* ─── MENU ──────────────────────────────────────────────── */
#menuWrap { position: fixed; top: 1rem; left: 1.25rem; z-index: 100; }

.menu-trigger {
    font-family: 'Syne', sans-serif !important; font-weight: 800 !important;
    font-size: 1.2rem !important; letter-spacing: 0 !important;
    width: 36px; height: 36px; padding: 0 !important;
    border: 1px solid var(--border); color: var(--accent);
    display: flex; align-items: center; justify-content: center; border-radius: 2px;
    transition: border-color .2s, box-shadow .2s, background .2s;
}
.menu-trigger:hover { border-color: var(--accent); background: rgba(0,255,136,.06); box-shadow: var(--glow); }

.dropdown {
    position: absolute; top: calc(100% + 8px); left: 0;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 2px; min-width: 200px; overflow: hidden;
    z-index: 200; animation: fadeUp .15s ease both;
}
.dropdown::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0; height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
}
.dropdown.hidden { display: none; }
.dropdown button {
    display: block; width: 100%; text-align: left;
    border: none; border-bottom: 1px solid var(--border); border-radius: 0;
    padding: .7rem 1rem; font-size: .72rem; color: var(--muted);
    background: transparent; letter-spacing: .1em; transition: background .15s, color .15s;
}
.dropdown button:last-child { border-bottom: none; }
.dropdown button:hover { background: var(--surface2); color: var(--text); box-shadow: none; }

/* ─── HISTORY ───────────────────────────────────────────── */
#historyList {
    position: fixed; top: 1rem; right: 1.25rem;
    width: 220px; max-height: calc(100vh - 2rem);
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 2px; overflow-y: auto; z-index: 90;
    display: flex; flex-direction: column;
}
#historyList:empty { display: none; }
#historyList::before {
    content: 'Historia'; display: block; position: sticky; top: 0;
    background: var(--surface); padding: .5rem .75rem;
    font-size: .6rem; letter-spacing: .15em; text-transform: uppercase;
    color: var(--muted); border-bottom: 1px solid var(--border); z-index: 1;
}
#historyList::-webkit-scrollbar { width: 4px; }
#historyList::-webkit-scrollbar-track { background: var(--surface); }
#historyList::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
#historyList::-webkit-scrollbar-thumb:hover { background: var(--accent); }

.history-item {
    display: flex; flex-direction: column; gap: .15rem;
    padding: .55rem .75rem; border-bottom: 1px solid var(--border);
    font-size: .65rem; line-height: 1.4; animation: fadeUp .25s ease both;
}
.history-item:last-child { border-bottom: none; }
.history-item.guessed  { border-left: 2px solid var(--accent); }
.history-item.failed   { border-left: 2px solid var(--accent2); }
.history-item .h-artist { color: var(--muted); font-size: .6rem; }
.history-item .h-title  { color: var(--text); font-weight: 700; }
.history-item .h-time   { color: var(--accent); font-size: .58rem; margin-top: .1rem; }
.history-item.failed .h-time { color: var(--accent2); }

/* ─── MAIN WRAPPER ──────────────────────────────────────── */
#app-wrapper {
    position: relative; z-index: 1;
    width: 100%; max-width: 560px;
    display: flex; flex-direction: column; align-items: center; gap: 2rem;
}

/* ─── HEADING ───────────────────────────────────────────── */
h1 {
    font-family: 'Syne', sans-serif; font-weight: 800;
    font-size: clamp(2.5rem, 8vw, 4rem); letter-spacing: -.02em;
    text-transform: uppercase; color: var(--text);
    position: relative; text-align: center; animation: fadeDown .6s ease both;
}
h1::after {
    content: 'MUSIC QUIZ'; position: absolute; inset: 0; color: var(--accent);
    clip-path: polygon(0 60%, 100% 60%, 100% 70%, 0 70%); filter: blur(1px); opacity: .8;
}

h2 {
    font-family: 'Syne', sans-serif; font-weight: 700;
    font-size: 1.1rem; letter-spacing: .15em;
    text-transform: uppercase; color: var(--muted); text-align: center;
}

/* ─── CARD ──────────────────────────────────────────────── */
.card {
    width: 100%; background: var(--surface);
    border: 1px solid var(--border); border-radius: 2px; padding: 2rem;
    position: relative; animation: fadeUp .5s ease both;
    display: flex; flex-direction: column; gap: 1.25rem;
}
.card::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
}

/* ─── BUTTONS ───────────────────────────────────────────── */
button {
    font-family: 'Space Mono', monospace; font-size: .75rem; font-weight: 700;
    letter-spacing: .15em; text-transform: uppercase; cursor: pointer;
    border: 1px solid var(--accent); background: transparent; color: var(--accent);
    padding: .75rem 1.5rem; border-radius: 2px; position: relative; overflow: hidden;
    transition: background .2s, box-shadow .2s, transform .1s;
}
button:hover { background: rgba(0,255,136,.08); box-shadow: var(--glow); }
button:active { transform: scale(.97); background: rgba(0,255,136,.15); }
button:disabled { border-color: var(--border); color: var(--muted); cursor: not-allowed; background: transparent; box-shadow: none; }

.btn-red { border-color: var(--accent2); color: var(--accent2); }
.btn-red:hover { background: rgba(255,51,102,.08); box-shadow: 0 0 20px rgba(255,51,102,.25); }

#loginBtn { font-size: .9rem; padding: 1rem 2.5rem; border-width: 2px; animation: pulse-border 2s ease-in-out infinite; }
@keyframes pulse-border {
    0%, 100% { box-shadow: 0 0 0 0 rgba(0,255,136,.4); }
    50%       { box-shadow: 0 0 0 8px rgba(0,255,136,0); }
}

#nextRoundBtn { border-color: var(--accent2); color: var(--accent2); }
#nextRoundBtn:hover { background: rgba(255,51,102,.08); box-shadow: 0 0 20px rgba(255,51,102,.25); }

/* ─── INPUTS ────────────────────────────────────────────── */
input[type="text"], input[type="password"], input[type="number"] {
    font-family: 'Space Mono', monospace; font-size: .85rem; width: 100%;
    background: var(--surface2); color: var(--text);
    border: 1px solid var(--border); border-radius: 2px;
    padding: .75rem 1rem; outline: none;
    transition: border-color .2s, box-shadow .2s;
    caret-color: var(--accent);
}
input[type="number"] { width: 70px; text-align: center; }
input[type="text"]::placeholder { color: var(--muted); }
input[type="text"]:focus, input[type="password"]:focus, input[type="number"]:focus {
    border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0,255,136,.1);
}

/* ─── ROWS ──────────────────────────────────────────────── */
.input-row { display: flex; gap: .75rem; }
#loadPlaylistBtn { white-space: nowrap; flex-shrink: 0; }

.itunes-count-row {
    display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
}
.count-label {
    font-size: .7rem; color: var(--muted); letter-spacing: .1em;
    text-transform: uppercase; white-space: nowrap; flex-shrink: 0;
}
#itunesLoadBtn { white-space: nowrap; flex-shrink: 0; }

/* ─── ITUNES TABS ───────────────────────────────────────── */
.itunes-mode-toggle {
    display: flex; gap: 0; border: 1px solid var(--border); border-radius: 2px; overflow: hidden;
}
.itunes-tab {
    flex: 1; padding: .55rem 1rem; font-size: .7rem; letter-spacing: .12em;
    border: none; border-radius: 0; color: var(--muted); background: var(--surface2);
    transition: background .15s, color .15s; box-shadow: none;
}
.itunes-tab:hover { background: var(--surface2); box-shadow: none; color: var(--text); }
.itunes-tab.active { background: rgba(0,255,136,.1); color: var(--accent); border-bottom: 2px solid var(--accent); }
.itunes-tab:first-child { border-right: 1px solid var(--border); }

/* ─── GENRE CHIPS ───────────────────────────────────────── */
.genre-chips {
    display: flex; flex-wrap: wrap; gap: .5rem;
}
.genre-chip {
    padding: .4rem .9rem; font-size: .65rem; letter-spacing: .1em;
    border: 1px solid var(--border); color: var(--muted); background: var(--surface2);
    border-radius: 2px; cursor: pointer; box-shadow: none;
    transition: border-color .15s, color .15s, background .15s;
}
.genre-chip:hover { border-color: var(--accent); color: var(--text); box-shadow: none; background: var(--surface2); }
.genre-chip.active { border-color: var(--accent); color: var(--accent); background: rgba(0,255,136,.08); }

/* ─── SECRET DISPLAY ────────────────────────────────────── */
#secretDisplay {
    font-family: 'Syne', sans-serif;
    font-size: clamp(1.2rem, 4vw, 1.8rem); 
    font-weight: 700;
    color: var(--text); 
    text-align: center; 
    letter-spacing: .08em;
    padding: 1.5rem; 
    background: var(--surface2);
    border: 1px solid var(--border); 
    border-radius: 2px;
    min-height: 80px; 
    display: flex; 
    align-items: center; 
    justify-content: center;
    overflow-wrap: break-word;
    transition: color .3s; 
    position: relative;
}

#secretDisplay::after {
    content: ''; position: absolute; bottom: 0; left: 0; right: 0; height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent2), transparent); opacity: .5;
}

/* ─── MODE TOGGLE ───────────────────────────────────────── */
.mode-toggle {
    display: flex; align-items: center; gap: .75rem;
    font-size: .7rem; color: var(--muted); letter-spacing: .1em;
    text-transform: uppercase; justify-content: center;
}
.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; inset: 0; background: var(--surface2);
    border: 1px solid var(--border); border-radius: 24px; cursor: pointer;
    transition: background .2s, border-color .2s;
}
.slider::before {
    content: ''; position: absolute; width: 16px; height: 16px; left: 3px; top: 50%;
    transform: translateY(-50%); background: var(--muted);
    border-radius: 50%; transition: transform .2s, background .2s;
}
.switch input:checked + .slider { border-color: var(--accent); background: rgba(0,255,136,.1); }
.switch input:checked + .slider::before { transform: translate(20px,-50%); background: var(--accent); }

/* ─── GUESS ROW ─────────────────────────────────────────── */
.guess-row { display: flex; gap: .75rem; }

/* ─── VOLUME ────────────────────────────────────────────── */
.volume-row { display: flex; align-items: center; gap: .75rem; }
.volume-icon { font-size: .6rem; color: var(--muted); flex-shrink: 0; user-select: none; }

input[type="range"] {
    -webkit-appearance: none; appearance: none; width: 100%;
    height: 3px; background: var(--border); border-radius: 2px; outline: none; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%;
    background: var(--accent); cursor: pointer; box-shadow: 0 0 8px rgba(0,255,136,.5);
    transition: transform .15s, box-shadow .15s;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.3); box-shadow: 0 0 14px rgba(0,255,136,.7); }
input[type="range"]::-moz-range-thumb {
    width: 14px; height: 14px; border-radius: 50%; background: var(--accent);
    cursor: pointer; border: none; box-shadow: 0 0 8px rgba(0,255,136,.5);
}

/* ─── CONTROLS ──────────────────────────────────────────── */
.controls-row { display: flex; gap: .75rem; flex-wrap: wrap; }
.controls-row button { flex: 1; min-width: 120px; }

/* ─── TIME PROGRESS ─────────────────────────────────────── */
.time-progress-wrap { display: flex; flex-direction: column; gap: .4rem; }
.time-progress-bar {
    width: 100%; height: 6px; background: var(--surface2);
    border: 1px solid var(--border); border-radius: 3px; overflow: hidden;
}
.time-progress-fill {
    height: 100%; width: 10%;
    background: linear-gradient(90deg, var(--accent), rgba(0,255,136,.5));
    border-radius: 3px; transition: width .4s cubic-bezier(.4,0,.2,1);
    box-shadow: 0 0 8px rgba(0,255,136,.4);
}
.time-labels { position: relative; width: 100%; height: 16px; }
.time-labels span {
    position: absolute; transform: translateX(-50%);
    font-size: .6rem; color: var(--muted); letter-spacing: .05em;
}

/* ─── STATS ─────────────────────────────────────────────── */
.stats-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: .75rem 1rem; background: var(--surface2);
    border: 1px solid var(--border); border-radius: 2px;
    font-size: .75rem; color: var(--muted); letter-spacing: .08em;
}
.stats-row .stat-value { color: var(--accent); font-weight: 700; }

/* ─── WAVEFORM ──────────────────────────────────────────── */
.waveform { display: flex; align-items: center; justify-content: center; gap: 3px; height: 24px; opacity: .4; }
.waveform span { display: block; width: 3px; background: var(--accent); border-radius: 2px; animation: wave 1.2s ease-in-out infinite; }
.waveform span:nth-child(1) { height: 6px;  animation-delay: 0s; }
.waveform span:nth-child(2) { height: 14px; animation-delay: .1s; }
.waveform span:nth-child(3) { height: 20px; animation-delay: .2s; }
.waveform span:nth-child(4) { height: 10px; animation-delay: .3s; }
.waveform span:nth-child(5) { height: 18px; animation-delay: .4s; }
.waveform span:nth-child(6) { height: 8px;  animation-delay: .5s; }
.waveform span:nth-child(7) { height: 16px; animation-delay: .35s; }
.waveform span:nth-child(8) { height: 12px; animation-delay: .15s; }
.waveform span:nth-child(9) { height: 4px;  animation-delay: .45s; }
@keyframes wave { 0%, 100% { transform: scaleY(1); } 50% { transform: scaleY(.3); } }

/* ─── ANIMATIONS ────────────────────────────────────────── */
@keyframes fadeDown { from { opacity: 0; transform: translateY(-20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeUp   { from { opacity: 0; transform: translateY(20px);  } to { opacity: 1; transform: translateY(0); } }

/* ─── SCROLLBAR ─────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }
/* ─── MODAL OVERLAY ─────────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0; z-index: 500;
    background: rgba(10,10,15,0.85);
    backdrop-filter: blur(6px);
    display: flex; align-items: center; justify-content: center;
    padding: 1.5rem;
    animation: fadeIn .2s ease both;
}
.modal-overlay.hidden { display: none; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
    width: 100%; max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 2px;
    padding: 2rem;
    display: flex; flex-direction: column; gap: 1rem;
    position: relative;
    animation: fadeUp .3s ease both;
}

.modal-box::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
}

.modal-close {
    position: absolute; top: .75rem; right: .75rem;
    width: 28px; height: 28px; padding: 0;
    border: 1px solid var(--border); color: var(--muted);
    font-size: .75rem; border-radius: 2px;
    display: flex; align-items: center; justify-content: center;
    box-shadow: none;
}
.modal-close:hover { border-color: var(--accent2); color: var(--accent2); }

.modal-error {
    font-size: .7rem; color: var(--accent2);
    letter-spacing: .1em; text-align: center; min-height: 1rem;
}

/* ─── AUTH TABS ─────────────────────────────────────────── */
.auth-tabs {
    display: flex; border: 1px solid var(--border); border-radius: 2px; overflow: hidden;
}
.auth-tab {
    flex: 1; padding: .55rem 1rem; font-size: .7rem; letter-spacing: .12em;
    border: none; border-radius: 0; color: var(--muted);
    background: var(--surface2); box-shadow: none;
    transition: background .15s, color .15s;
}
.auth-tab:first-child { border-right: 1px solid var(--border); }
.auth-tab.active { background: rgba(0,255,136,.1); color: var(--accent); border-bottom: 2px solid var(--accent); }
.auth-tab:hover:not(.active) { color: var(--text); }

.full-width-btn { width: 100%; padding: .9rem; }

/* ─── SCOREBOARD ─────────────────────────────────────────── */
.user-badge {
    display: flex; align-items: center; gap: .75rem;
    padding: .75rem 1rem; background: var(--surface2);
    border: 1px solid var(--border); border-radius: 2px;
    flex-wrap: wrap;
}

.sb-nick {
    font-family: 'Syne', sans-serif; font-weight: 700;
    font-size: 1rem; color: var(--text); letter-spacing: .05em;
}

.sb-pts {
    font-size: .75rem; color: var(--accent); margin-left: auto;
}

.rank-badge {
    font-size: .6rem; letter-spacing: .15em; text-transform: uppercase;
    border: 1px solid currentColor; padding: .15rem .5rem; border-radius: 2px;
    font-family: 'Space Mono', monospace;
}

.scoreboard-list {
    display: flex; flex-direction: column; gap: .35rem;
    max-height: 320px; overflow-y: auto;
}
.scoreboard-list::-webkit-scrollbar { width: 4px; }
.scoreboard-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.sb-loading {
    text-align: center; color: var(--muted); font-size: .75rem;
    padding: 1.5rem 0; letter-spacing: .1em;
}

.sb-row {
    display: flex; align-items: center; gap: .6rem;
    padding: .5rem .75rem; background: var(--surface2);
    border: 1px solid var(--border); border-radius: 2px;
    font-size: .72rem;
}
.sb-row.sb-me { border-color: var(--accent); background: rgba(0,255,136,.05); }

.sb-pos { color: var(--muted); width: 1.5rem; flex-shrink: 0; font-size: .65rem; }
.sb-name { color: var(--text); font-weight: 700; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-score { color: var(--accent); font-weight: 700; flex-shrink: 0; }

.btn-muted {
    border-color: var(--border); color: var(--muted);
    font-size: .65rem; padding: .5rem 1rem; width: 100%;
}
.btn-muted:hover { border-color: var(--accent2); color: var(--accent2); }

/* ─── SESSION POINTS ─────────────────────────────────────── */
.session-pts {
    font-size: .7rem; color: var(--accent); letter-spacing: .08em;
    transition: color .3s;
}
.session-pts.hidden { display: none; }
.session-pts.pts-flash { animation: pts-pop .5s ease; }

@keyframes pts-pop {
    0%   { transform: scale(1); color: var(--accent); }
    40%  { transform: scale(1.4); color: #fff; }
    100% { transform: scale(1); color: var(--accent); }
}