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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: #fff;
    color: #322449;
    min-height: 100vh;
}

/* ---- Password Gate ---- */
#password-gate {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: #322449;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}

#password-gate.gate-hidden {
    display: none;
}

.gate-box {
    text-align: center;
    max-width: 340px;
    padding: 0 20px;
}

.gate-box p {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 16px;
}

.gate-input {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    font-size: 15px;
    color: #322449;
    background: #fff;
    outline: none;
    transition: border-color 0.2s;
}

.gate-input:focus {
    border-color: #fff;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.2);
}

.gate-input::placeholder {
    color: #a898b8;
}

.gate-btn {
    margin-top: 12px;
    width: 100%;
    padding: 10px 14px;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    color: #322449;
    background: #fff;
    cursor: pointer;
    transition: opacity 0.15s;
}

.gate-btn:hover {
    opacity: 0.9;
}

.gate-error {
    margin-top: 10px;
    font-size: 13px;
    color: #ff6b6b;
    min-height: 20px;
}

@keyframes gateShake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-6px); }
    40%, 80% { transform: translateX(6px); }
}

.gate-shake {
    animation: gateShake 0.4s ease-in-out;
}

#app {
    max-width: 720px;
    margin: 0 auto;
    padding: 32px 20px;
    overflow-x: clip;
}

/* ---- Speech Area (fixed height — never shifts stage below) ---- */
#speech-area {
    position: relative;
    height: 130px;
    max-width: 505px;
    margin: 0 auto 16px;
}

/* ---- Speech Bubble (above the composition) ---- */
.speech-bubble {
    position: relative;
    background: #322449;
    color: #fff;
    border-radius: 16px;
    padding: 16px 20px;
}

/* Arrow pointing down toward the head */
.speech-bubble::before {
    content: "";
    position: absolute;
    bottom: -12px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 12px solid #322449;
}

.speech-bubble::after {
    display: none;
}

.speech-text {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 12px;
    line-height: 1.4;
    text-align: center;
}

/* ---- Search ---- */
#search-container {
    position: relative;
}

#search-input {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    font-size: 15px;
    color: #322449;
    background: #fff;
    outline: none;
    transition: border-color 0.2s;
}

#search-input:focus {
    border-color: #fff;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.2);
}

#search-input::placeholder {
    color: #a898b8;
}

.dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    color: #322449;
    border: 2px solid #322449;
    border-top: none;
    border-radius: 0 0 8px 8px;
    max-height: 280px;
    overflow-y: auto;
    z-index: 100;
}

.dropdown-item {
    padding: 10px 14px;
    cursor: pointer;
    font-size: 14px;
    border-bottom: 1px solid rgba(50, 36, 73, 0.1);
    transition: background 0.15s;
}

.dropdown-item:last-child {
    border-bottom: none;
}

.dropdown-item:hover {
    background: rgba(50, 36, 73, 0.06);
}

.hidden {
    display: none !important;
}

/* ---- DJ Toast Bubbles ---- */
.toast-bubble {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    background: #322449;
    color: #fff;
    padding: 8px 14px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    pointer-events: none;
    z-index: 50;
}

/* Downward arrow matching the speech bubble style */
.toast-bubble::before {
    content: "";
    position: absolute;
    bottom: -12px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 12px solid #322449;
}

.toast-bubble.show {
    animation: toastIn 0.3s ease-out;
}

.toast-bubble.fade-out {
    animation: toastOut 0.4s ease-in forwards;
}

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

@keyframes toastOut {
    from { opacity: 1; transform: translateY(0) scale(1); }
    to { opacity: 0; transform: translateY(-8px) scale(0.9); }
}

/*
 * ---- Stage: visual composition ----
 *
 * Figma canvas positions (absolute):
 *   youtube_placeholder : (175, 366)  480 x 270   ← anchor
 *   edm head            : (372, 118)  130 x 119
 *   edm spkr1 (left)    : (169, 113)  111 x 116
 *   edm skpr  (right)   : (562, 108)  112 x 111
 *   edm decks frame     : (-43,-132) 1000 x 1001
 *
 * Composition origin = (169, 108)  — top-left of rightmost speaker
 * All positions below are (canvas - origin).
 *
 *   left speaker  : (  0,   5)  111 x 116
 *   right speaker : (393,   0)  112 x 111
 *   head          : (203,  10)  130 x 119
 *   player        : (  6, 258)  480 x 270
 *   composition   :  505 x 528
 *
 * Decks SVG viewBox "140 150 640 680" maps to frame coords.
 *   Frame origin in canvas: (-43, -132)
 *   SVG origin in canvas : (-43+140, -132+150) = (97, 18)
 *   In composition coords : (97-169, 18-108) = (-72, -90)
 *   Size: 640 x 680 (at 1:1 with Figma)
 */

#stage {
    position: relative;
    width: 505px;
    height: 618px;
    margin: 0 auto 24px;
    overflow: visible;
}

/* Decks background — behind everything, extends beyond stage bounds */
#decks-img {
    position: absolute;
    left: -72px;
    top: 0px;
    width: 640px;
    height: 680px;
    z-index: 0;
}

/* Speakers */
.speaker {
    position: absolute;
    z-index: 1;
}

.speaker img {
    width: 100%;
    height: 100%;
    display: block;
}

#spkr-left {
    left: 0px;
    top: 95px;
    width: 111px;
    height: 116px;
}

#spkr-right {
    left: 393px;
    top: 90px;
    width: 112px;
    height: 111px;
}

/* Speaker pulse animation when playing */
#stage.grooving .speaker img {
    animation: speakerPulse 0.5s ease-in-out infinite;
    transform-origin: center center;
}

@keyframes speakerPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.06); }
}

/* DJ Head */
#dj-character {
    position: absolute;
    left: 203px;
    top: 100px;
    width: 130px;
    height: 119px;
    z-index: 2;
    cursor: pointer;
}

.dj-head-img {
    width: 100%;
    height: 100%;
    display: block;
}

/* Head bob animation when playing */
#stage.grooving #dj-character {
    animation: headBob 0.5s ease-in-out infinite;
}

@keyframes headBob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

/* Player area — sits on the desk */
#player-area {
    position: absolute;
    left: 6px;
    top: 348px;
    width: 480px;
    height: 270px;
    z-index: 3;
}

#player-placeholder {
    width: 100%;
    height: 100%;
    background: #1a1025;
    border-radius: 4px;
}

#youtube-player-container {
    width: 100%;
    height: 100%;
}

#youtube-player-container iframe {
    width: 100%;
    height: 100%;
    border-radius: 4px;
}

/* ---- Tracklist ---- */
#tracklist-area {
    margin-top: 80px;
    max-width: 505px;
    margin-left: auto;
    margin-right: auto;
}

#tracklist-area h2 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 12px;
    color: #322449;
}

#tracklist {
    list-style: none;
    counter-reset: track;
}

#tracklist li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(50, 36, 73, 0.1);
    font-size: 14px;
    color: #322449;
}

#tracklist li::before {
    counter-increment: track;
    content: counter(track) ".";
    font-weight: 600;
    min-width: 28px;
    font-variant-numeric: tabular-nums;
}

#tracklist li.current {
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 3px;
}

#tracklist li.replacing {
    animation: replacePulse 0.8s ease-in-out infinite;
}

@keyframes replacePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.track-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.track-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.btn-feedback {
    background: none;
    border: none;
    border-radius: 6px;
    width: 32px;
    height: 32px;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, transform 0.1s;
    color: #322449;
}

.btn-feedback:hover {
    background: rgba(50, 36, 73, 0.08);
}

.btn-feedback:active {
    transform: scale(0.92);
}

.btn-feedback.voted {
    background: #322449;
    color: #fff;
}

.btn-feedback[disabled] {
    cursor: default;
    opacity: 0.4;
}

.btn-feedback[disabled].voted {
    opacity: 1;
}

/* ---- End of Mix ---- */
#mix-end {
    margin-top: 16px;
    padding: 12px 20px;
    background: #322449;
    color: #fff;
    border-radius: 8px;
    text-align: center;
    font-weight: 700;
    font-size: 15px;
    letter-spacing: 0.5px;
}

/* ---- Mobile viewport scaling ---- */
@media (max-width: 560px) {
    #stage {
        --scale: calc((100vw - 40px) / 505);
        transform: scale(var(--scale));
        transform-origin: top center;
        height: calc(618px * var(--scale));
    }

    #speech-area {
        max-width: 100%;
    }

    #tracklist-area {
        max-width: 100%;
    }
}
