/* ---------- reset ---------- */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    outline: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    height: 100%;
    overscroll-behavior: none;
}

body {
    background: #07030f;
    color: #e9e4ff;
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    overflow: hidden;
}

/* ---------- palco ---------- */
#stage {
    position: fixed;
    inset: 0;
    touch-action: none;
    cursor: crosshair;
    isolation: isolate; /* o mix-blend-mode do #glow só mistura dentro do palco */
    background:
        radial-gradient(120% 90% at 50% 0%, #1a0b3a 0%, #0d0520 45%, #07030f 100%),
        #07030f;
}

#scene,
#glow {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}

/* camada de bloom: mesma imagem, borrada e somada por cima */
#glow {
    pointer-events: none;
    mix-blend-mode: screen;
    opacity: .75;
    filter: blur(9px) saturate(1.6);
    transition: opacity .25s ease;
}

#glow.off {
    opacity: 0;
}

#vignette {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(115% 85% at 50% 45%, transparent 55%, rgba(4, 1, 12, .78) 100%);
}

/* ---------- HUD ---------- */
#hud {
    position: fixed;
    top: max(12px, env(safe-area-inset-top));
    right: max(12px, env(safe-area-inset-right));
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
    max-width: calc(100vw - 24px);
    pointer-events: none;
    z-index: 5;
}

.hud-item {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    padding: 5px 10px;
    border-radius: 999px;
    font: 600 11px/1 ui-monospace, "SFMono-Regular", Menlo, monospace;
    letter-spacing: .08em;
    background: rgba(18, 8, 40, .55);
    border: 1px solid rgba(160, 130, 255, .16);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.hud-item i {
    font-style: normal;
    color: #8f7fc4;
}

.hud-item b {
    font-weight: 700;
    color: #d9ccff;
    font-variant-numeric: tabular-nums;
}

/* ---------- painel ---------- */
#panel {
    position: fixed;
    z-index: 6;
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
    border-radius: 20px;
    background: rgba(16, 7, 36, .62);
    border: 1px solid rgba(160, 130, 255, .18);
    box-shadow: 0 18px 50px rgba(0, 0, 0, .55), inset 0 1px 0 rgba(255, 255, 255, .06);
    backdrop-filter: blur(18px) saturate(1.3);
    -webkit-backdrop-filter: blur(18px) saturate(1.3);
    overflow: hidden;
}

#panel-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: none;
    border: 0;
    color: inherit;
    cursor: pointer;
    font: 600 12px/1 inherit;
    letter-spacing: .1em;
    text-transform: uppercase;
}

.grip {
    width: 26px;
    height: 3px;
    border-radius: 999px;
    background: linear-gradient(90deg, #5aff3c, #af3cff);
    flex: none;
}

.panel-title {
    flex: 1;
    text-align: left;
    color: #b9a9f0;
}

.chev {
    width: 8px;
    height: 8px;
    border-right: 2px solid #b9a9f0;
    border-bottom: 2px solid #b9a9f0;
    transform: rotate(45deg) translate(-2px, -2px);
    transition: transform .25s ease;
}

#panel.collapsed .chev {
    transform: rotate(-135deg) translate(-2px, -2px);
}

#panel-body {
    display: grid;
    gap: 16px;
    padding: 2px 16px 16px;
    max-height: 52vh;
    overflow-y: auto;
    overscroll-behavior: contain;
}

#panel.collapsed #panel-body {
    display: none;
}

.row {
    display: grid;
    gap: 10px;
}

.lbl {
    font-size: 11px;
    letter-spacing: .06em;
    color: #9284c4;
    text-transform: uppercase;
}

.lbl b {
    color: #e4dbff;
    font-variant-numeric: tabular-nums;
}

/* botões principais */
.transport {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.key {
    min-height: 44px;
    padding: 0 6px;
    border-radius: 12px;
    border: 1px solid rgba(160, 130, 255, .2);
    background: rgba(255, 255, 255, .045);
    color: #e4dbff;
    font: 600 12px/1 inherit;
    cursor: pointer;
    transition: background .15s ease, border-color .15s ease, transform .08s ease;
}

.key:hover {
    background: rgba(255, 255, 255, .1);
}

.key:active {
    transform: scale(.96);
}

#btn-play {
    border-color: rgba(90, 255, 60, .35);
    background: rgba(90, 255, 60, .1);
    color: #b6ffa2;
}

/* chips */
.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chip {
    min-height: 38px;
    padding: 0 14px;
    border-radius: 999px;
    border: 1px solid rgba(160, 130, 255, .2);
    background: rgba(255, 255, 255, .04);
    color: #b6abdd;
    font: 600 12px/1 inherit;
    cursor: pointer;
    transition: all .15s ease;
}

.chip:active {
    transform: scale(.95);
}

.chip[data-active="true"] {
    color: #0a0418;
    background: #b9a9f0;
    border-color: transparent;
}

#brush .chip[data-type="1"][data-active="true"] {
    background: #5aff3c;
    box-shadow: 0 0 16px rgba(90, 255, 60, .5);
}

#brush .chip[data-type="2"][data-active="true"] {
    background: #af3cff;
    color: #fff;
    box-shadow: 0 0 16px rgba(175, 60, 255, .5);
}

#brush .chip[data-type="3"][data-active="true"] {
    background: #eaf3ff;
    box-shadow: 0 0 16px rgba(200, 225, 255, .5);
}

/* sliders */
.slider {
    display: grid;
    gap: 8px;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 28px;
    background: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
    height: 4px;
    border-radius: 999px;
    background: rgba(160, 130, 255, .22);
}

input[type="range"]::-moz-range-track {
    height: 4px;
    border-radius: 999px;
    background: rgba(160, 130, 255, .22);
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    margin-top: -8px;
    border-radius: 50%;
    background: #e6dcff;
    border: 3px solid #6c4bd6;
    box-shadow: 0 0 12px rgba(140, 100, 255, .6);
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #e6dcff;
    border: 3px solid #6c4bd6;
    box-shadow: 0 0 12px rgba(140, 100, 255, .6);
}

/* ---------- desktop ---------- */
@media (min-width: 760px) {
    #panel {
        right: auto;
        top: max(14px, env(safe-area-inset-top));
        bottom: auto;
        width: 300px;
    }

    #panel-body {
        max-height: calc(100vh - 120px);
    }

    .chip,
    .key {
        min-height: 36px;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
    }
}
