:root {
    --bg-dark: #080a12;
    --panel-bg: rgba(14, 18, 32, 0.92);
    --panel-border: rgba(255, 255, 255, 0.12);
    --accent-gold: #ffb800;
    --accent-cyan: #00f0ff;
    --accent-pink: #ff0077;
    --accent-lime: #39ff14;
    --accent-purple: #b026ff;
    --text-main: #ffffff;
    --text-muted: #94a3b8;
}

* {
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    background-color: var(--bg-dark);
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
    color: var(--text-main);
    touch-action: none;
}

#app {
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
    position: relative;
    background: #060810;
    overflow: hidden;
}

/* Header */
#header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: rgba(10, 13, 24, 0.85);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--panel-border);
    z-index: 25;
    gap: 10px;
    flex-shrink: 0;
}

.back-btn {
    text-decoration: none;
    color: var(--accent-cyan);
    font-weight: 700;
    font-size: 0.85rem;
    padding: 8px 12px;
    background: rgba(0, 240, 255, 0.12);
    border: 1px solid rgba(0, 240, 255, 0.3);
    border-radius: 8px;
    white-space: nowrap;
    transition: all 0.2s;
    min-height: 38px;
    display: flex;
    align-items: center;
}
.back-btn:hover, .back-btn:active {
    background: rgba(0, 240, 255, 0.25);
    transform: scale(0.97);
}

.title-area {
    display: flex;
    align-items: center;
}
.logo-text {
    font-size: 1.15rem;
    font-weight: 900;
    letter-spacing: 0.05em;
    white-space: nowrap;
}
.logo-text span {
    color: var(--accent-gold);
}

/* Energy Pill */
.energy-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(0, 0, 0, 0.45);
    padding: 5px 10px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}
.energy-pill .bolt {
    font-size: 0.85rem;
    color: var(--accent-gold);
}
.energy-track {
    width: 60px;
    height: 8px;
    background: rgba(255, 255, 255, 0.12);
    border-radius: 5px;
    overflow: hidden;
}
.energy-fill {
    height: 100%;
    background: linear-gradient(90deg, #ff9900, #ffee00);
    border-radius: 5px;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 0 8px rgba(255, 238, 0, 0.6);
}
.energy-num {
    font-size: 0.75rem;
    font-weight: 800;
    min-width: 28px;
}

/* Mode Selector Tabs */
.mode-selector {
    display: flex;
    background: rgba(0, 0, 0, 0.5);
    padding: 3px;
    border-radius: 10px;
    gap: 3px;
}
.mode-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: inherit;
    font-weight: 800;
    font-size: 0.8rem;
    padding: 7px 12px;
    border-radius: 7px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.18s ease;
    min-height: 36px;
}
.mode-btn.active {
    background: linear-gradient(135deg, var(--accent-gold), #ff8800);
    color: #000;
    box-shadow: 0 3px 10px rgba(255, 184, 0, 0.35);
}

/* Main Canvas Stage */
#stageContainer {
    flex: 1;
    min-height: 0;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #05070d;
}

#gameCanvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* Freestyle Roam Floating Action Button */
.roam-floating-btn {
    position: absolute;
    top: 14px;
    right: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
    background: linear-gradient(135deg, rgba(255, 0, 119, 0.85), rgba(176, 38, 255, 0.85));
    border: 2px solid rgba(255, 255, 255, 0.4);
    color: #fff;
    font-family: inherit;
    font-weight: 900;
    font-size: 0.85rem;
    padding: 9px 15px;
    border-radius: 30px;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(255, 0, 119, 0.4), 0 0 14px rgba(176, 38, 255, 0.3);
    backdrop-filter: blur(8px);
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 15;
}
.roam-floating-btn:hover {
    transform: scale(1.06);
}
.roam-floating-btn:active {
    transform: scale(0.94);
}
.roam-floating-btn.active-roam {
    background: linear-gradient(135deg, #39ff14, #00bb22);
    color: #000;
    border-color: #fff;
    box-shadow: 0 6px 20px rgba(57, 255, 20, 0.5);
    animation: roamPulse 1.2s infinite alternate;
}

@keyframes roamPulse {
    0% { transform: scale(1); }
    100% { transform: scale(1.05); }
}

.speech-bubble {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%) scale(1);
    background: rgba(12, 16, 28, 0.92);
    border: 2px solid var(--accent-gold);
    color: #ffffff;
    font-weight: 800;
    padding: 8px 18px;
    border-radius: 18px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.6), 0 0 14px rgba(255, 184, 0, 0.35);
    pointer-events: none;
    transition: all 0.22s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 12;
    font-size: 0.9rem;
    white-space: nowrap;
}

/* Footer Control Drawer */
#controlPanel {
    background: var(--panel-bg);
    backdrop-filter: blur(18px);
    border-top: 1px solid var(--panel-border);
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px)) 12px;
    z-index: 25;
    flex-shrink: 0;
    max-height: 48vh;
    overflow-y: auto;
    scrollbar-width: thin;
}

.panel-tab-content {
    display: none;
    flex-direction: column;
    gap: 6px;
    animation: panelSlideUp 0.22s ease-out;
}
.panel-tab-content.active {
    display: flex;
}

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

/* Category Pill Tabs */
.category-strip {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}
.category-strip::-webkit-scrollbar { display: none; }

.cat-pill {
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--text-muted);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
    min-height: 32px;
}
.cat-pill.active {
    background: rgba(0, 240, 255, 0.22);
    border-color: var(--accent-cyan);
    color: #fff;
    box-shadow: 0 0 10px rgba(0, 240, 255, 0.2);
}

/* Part Carousel */
.carousel-container {
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}
.carousel-container::-webkit-scrollbar { display: none; }

.options-carousel {
    display: flex;
    gap: 8px;
    padding: 2px 0;
}

.part-card {
    flex: 0 0 90px;
    height: 62px;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    gap: 2px;
    transition: all 0.18s;
}
.part-card:active {
    transform: scale(0.95);
}
.part-card.selected {
    border-color: var(--accent-gold);
    background: rgba(255, 184, 0, 0.18);
    box-shadow: 0 0 12px rgba(255, 184, 0, 0.35);
}
.part-card .card-icon {
    font-size: 1.25rem;
}
.part-card .card-name {
    font-size: 0.68rem;
    font-weight: 800;
    color: #eee;
}

/* Sub-Bar (Category Color Palette) */
.sub-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(0, 0, 0, 0.4);
    padding: 5px 10px;
    border-radius: 9px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    gap: 8px;
}
.sub-label {
    font-size: 0.72rem;
    font-weight: 800;
    color: var(--accent-cyan);
    letter-spacing: 0.5px;
    white-space: nowrap;
    flex-shrink: 0;
}
.swatches-wrap {
    display: flex;
    gap: 6px;
    align-items: center;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding: 2px 0;
}
.swatches-wrap::-webkit-scrollbar { display: none; }
.swatch-circle {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--c);
    border: 2px solid rgba(255, 255, 255, 0.3);
    cursor: pointer;
    transition: all 0.16s ease;
    box-shadow: 0 0 6px var(--c);
    flex-shrink: 0;
}
.swatch-circle:hover {
    transform: scale(1.15);
    border-color: #ffffff;
}
.swatch-circle.active {
    border-color: #ffffff;
    transform: scale(1.18);
    box-shadow: 0 0 14px var(--c), inset 0 0 4px #fff;
}
.rainbow-circle {
    background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.6);
}

/* Feed Panel */
.feed-header-tip {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 600;
}
.snacks-row {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 2px 0;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}
.snacks-row::-webkit-scrollbar { display: none; }

.snack-touch-card {
    flex: 0 0 105px;
    height: 68px;
    background: rgba(255, 255, 255, 0.06);
    border: 1.5px dashed rgba(255, 255, 255, 0.22);
    border-radius: 10px;
    display: flex;
    align-items: center;
    padding: 5px 7px;
    gap: 6px;
    cursor: pointer;
    transition: all 0.18s;
}
.snack-touch-card:hover, .snack-touch-card:active {
    border-color: var(--accent-lime);
    background: rgba(57, 255, 20, 0.15);
    transform: scale(0.97);
}
.snack-emoji {
    font-size: 1.5rem;
}
.snack-meta {
    display: flex;
    flex-direction: column;
}
.snack-title {
    font-size: 0.74rem;
    font-weight: 800;
}
.snack-tag {
    font-size: 0.64rem;
    color: var(--accent-lime);
    font-weight: 700;
}

/* Dance & Stage Panel */
.dance-controls-grid {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-wrap: wrap;
}
.track-select-box {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1;
    min-width: 170px;
}
.track-label {
    font-size: 0.7rem;
    font-weight: 800;
    color: var(--accent-gold);
}
.track-picker-select {
    background: rgba(0, 0, 0, 0.65);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: #fff;
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 700;
    padding: 7px 10px;
    border-radius: 8px;
    outline: none;
    cursor: pointer;
    min-height: 38px;
}
.dance-action-buttons {
    display: flex;
    gap: 6px;
}
.main-play-btn {
    background: linear-gradient(135deg, var(--accent-lime), #00bb22);
    border: none;
    color: #000;
    font-weight: 900;
    font-size: 0.82rem;
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(57, 255, 20, 0.35);
    min-height: 38px;
    white-space: nowrap;
    transition: transform 0.15s;
}
.main-play-btn.playing {
    background: linear-gradient(135deg, var(--accent-pink), #cc0055);
    color: #fff;
    box-shadow: 0 4px 12px rgba(255, 0, 119, 0.4);
}
.main-play-btn:active {
    transform: scale(0.95);
}
.dance-style-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    font-weight: 800;
    font-size: 0.78rem;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    min-height: 38px;
    white-space: nowrap;
}
.dance-style-btn:active {
    transform: scale(0.95);
}

/* DJ Soundboard */
.touch-soundboard {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 5px;
    margin-top: 2px;
}
.sound-pad {
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.14);
    color: #fff;
    font-family: inherit;
    font-weight: 800;
    font-size: 0.7rem;
    padding: 7px 2px;
    border-radius: 7px;
    cursor: pointer;
    min-height: 34px;
    transition: all 0.1s;
}
.sound-pad:active, .sound-pad.triggered {
    background: var(--accent-pink);
    border-color: #fff;
    transform: scale(0.94);
    box-shadow: 0 0 12px var(--accent-pink);
}

/* Tablets (iPad, Android Tablets: 768px - 1024px) & Aspect Ratio Adaptations */
@media (max-width: 1024px) {
    #header {
        padding: 6px 10px;
        gap: 8px;
    }
    .logo-text {
        font-size: 1rem;
    }
    .mode-btn {
        padding: 6px 10px;
        font-size: 0.76rem;
    }
    #controlPanel {
        padding: 6px 10px calc(8px + env(safe-area-inset-bottom, 0px)) 10px;
        max-height: 40vh;
    }
    .part-card {
        flex: 0 0 84px;
        height: 58px;
    }
    .part-card .card-icon {
        font-size: 1.15rem;
    }
    .part-card .card-name {
        font-size: 0.65rem;
    }
    .sub-bar {
        padding: 4px 8px;
    }
    .swatch-circle {
        width: 22px;
        height: 22px;
    }
}

/* Mobile & Portrait Screens (max-width: 768px) */
@media (max-width: 768px) {
    #header {
        padding: 6px 8px;
        gap: 6px;
        flex-wrap: wrap;
        justify-content: space-between;
    }
    .back-btn {
        padding: 5px 8px;
        font-size: 0.75rem;
        min-height: 30px;
    }
    .title-area {
        order: 1;
    }
    .logo-text {
        font-size: 0.85rem;
    }
    .energy-pill {
        order: 2;
        padding: 3px 8px;
        gap: 4px;
    }
    .energy-track {
        width: 38px;
        height: 6px;
    }
    .energy-num {
        font-size: 0.7rem;
    }
    .mode-selector {
        order: 3;
        width: 100%;
        justify-content: space-around;
        padding: 2px;
        margin-top: 2px;
    }
    .mode-btn {
        flex: 1;
        text-align: center;
        padding: 6px 4px;
        font-size: 0.74rem;
        min-height: 32px;
    }
    .roam-floating-btn {
        top: 8px;
        right: 8px;
        padding: 5px 10px;
        font-size: 0.7rem;
        gap: 4px;
    }
    .speech-bubble {
        top: 8px;
        padding: 5px 12px;
        font-size: 0.75rem;
        max-width: 60%;
        text-overflow: ellipsis;
        overflow: hidden;
    }
    #controlPanel {
        padding: 6px 8px calc(8px + env(safe-area-inset-bottom, 0px)) 8px;
        max-height: 42vh;
        overflow-y: auto;
    }
    .category-strip {
        gap: 4px;
    }
    .cat-pill {
        padding: 5px 10px;
        font-size: 0.74rem;
        min-height: 30px;
    }
    .part-card {
        flex: 0 0 80px;
        height: 54px;
        border-radius: 9px;
        gap: 2px;
    }
    .part-card .card-icon {
        font-size: 1.1rem;
    }
    .part-card .card-name {
        font-size: 0.62rem;
    }
    .sub-bar {
        padding: 4px 8px;
        gap: 6px;
    }
    .sub-label {
        font-size: 0.66rem;
    }
    .swatch-circle {
        width: 20px;
        height: 20px;
    }
    .snack-touch-card {
        flex: 0 0 94px;
        height: 60px;
        padding: 4px 6px;
        gap: 6px;
    }
    .snack-emoji {
        font-size: 1.35rem;
    }
    .snack-title {
        font-size: 0.68rem;
    }
    .snack-tag {
        font-size: 0.58rem;
    }
    .dance-controls-grid {
        gap: 6px;
    }
    .track-select-box {
        min-width: 100%;
    }
    .track-picker-select {
        padding: 5px 8px;
        font-size: 0.76rem;
        min-height: 32px;
    }
    .dance-action-buttons {
        width: 100%;
    }
    .main-play-btn, .dance-style-btn {
        flex: 1;
        padding: 5px 8px;
        font-size: 0.74rem;
        min-height: 32px;
    }
    .touch-soundboard {
        grid-template-columns: repeat(3, 1fr);
        gap: 4px;
    }
    .sound-pad {
        padding: 5px 2px;
        font-size: 0.64rem;
        min-height: 28px;
    }
}

/* Ultra Short Viewports / Horizontal Mobile & Small Tablet Screen Heights */
@media (max-height: 620px) {
    #header {
        padding: 4px 8px;
    }
    .back-btn {
        min-height: 28px;
        padding: 4px 8px;
        font-size: 0.72rem;
    }
    .logo-text {
        font-size: 0.85rem;
    }
    .mode-btn {
        min-height: 28px;
        padding: 4px 8px;
        font-size: 0.7rem;
    }
    #controlPanel {
        padding: 4px 8px calc(6px + env(safe-area-inset-bottom, 0px)) 8px;
        max-height: 38vh;
    }
    .cat-pill {
        min-height: 26px;
        padding: 4px 8px;
        font-size: 0.7rem;
    }
    .part-card {
        flex: 0 0 74px;
        height: 48px;
    }
    .part-card .card-icon {
        font-size: 1rem;
    }
    .part-card .card-name {
        font-size: 0.58rem;
    }
    .sub-bar {
        padding: 3px 6px;
    }
    .swatch-circle {
        width: 18px;
        height: 18px;
    }
    .snack-touch-card {
        height: 52px;
        flex: 0 0 88px;
    }
    .touch-soundboard {
        grid-template-columns: repeat(6, 1fr);
    }
    .sound-pad {
        min-height: 26px;
        padding: 3px 2px;
        font-size: 0.6rem;
    }
}
