/* Global Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    width: 100%;
    overflow: hidden;
}

/* Reactive hooks (driven by the Web Audio analyser in script.js) */
:root {
    --pulse: 1;
    --energy: 0;
}

/* Animations */
@keyframes gradientFlow {
    0% {
        background-position: 0% 0%;
    }
    25% {
        background-position: 100% 50%;
    }
    50% {
        background-position: 100% 100%;
    }
    75% {
        background-position: 0% 50%;
    }
    100% {
        background-position: 0% 0%;
    }
}

@keyframes breathe {
    0%, 100% {
        transform: scale(1) translateZ(0);
        filter: brightness(1) saturate(1);
    }
    50% {
        transform: scale(1.02) translateZ(0);
        filter: brightness(1.1) saturate(1.2);
    }
}

@keyframes float {
    0%, 100% {
        transform: translateY(0) translateX(0) rotate(0deg);
    }
    33% {
        transform: translateY(-20px) translateX(10px) rotate(120deg);
    }
    66% {
        transform: translateY(10px) translateX(-10px) rotate(240deg);
    }
}

@keyframes shimmer {
    0% {
        opacity: 0;
        transform: translateX(-100%) translateY(-100%) rotate(45deg);
    }
    50% {
        opacity: 0.5;
    }
    100% {
        opacity: 0;
        transform: translateX(100%) translateY(100%) rotate(45deg);
    }
}

@keyframes dance {
    0%, 100% {
        height: 8px;
    }
    50% {
        height: 20px;
    }
}

/* Body Base Styles */
body {
    width: 100%;
    max-width: 100%;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    min-height: 100dvh;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    color: white;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
}

/* Track-specific gradient themes */
body.track-01 {
    background:
        radial-gradient(ellipse at top left, rgba(254, 168, 55, 0.4), transparent 40%),
        radial-gradient(ellipse at bottom right, rgba(89, 62, 103, 0.4), transparent 40%),
        radial-gradient(ellipse at center, rgba(184, 91, 86, 0.3), transparent 60%),
        linear-gradient(135deg,
            #ff0080, #ff8c00, #ff3c00, #8000ff,
            #2c003e, #8000ff, #ff3c00, #ff8c00, #ff0080);
    background-size: 400% 400%;
    animation:
        gradientFlow 20s cubic-bezier(0.4, 0, 0.6, 1) infinite,
        breathe 8s ease-in-out infinite;
}

body.track-02 {
    background:
        radial-gradient(ellipse at top left, rgba(254, 168, 55, 0.4), transparent 40%),
        radial-gradient(ellipse at bottom right, rgba(89, 62, 103, 0.4), transparent 40%),
        radial-gradient(ellipse at center, rgba(184, 91, 86, 0.3), transparent 60%),
        linear-gradient(135deg,
            #ff00ff, #8000ff, #00ffff, #00ffcc,
            #003366, #00ffcc, #00ffff, #8000ff, #ff00ff);
    background-size: 400% 400%;
    animation:
        gradientFlow 20s cubic-bezier(0.4, 0, 0.6, 1) infinite,
        breathe 8s ease-in-out infinite;
}

/* Background Effects */
body::before {
    content: '';
    position: absolute;
    inset: -50%;
    background:
        radial-gradient(circle at 20% 80%, rgba(255, 255, 255, 0.03) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(255, 255, 255, 0.03) 0%, transparent 50%),
        radial-gradient(circle at 40% 40%, rgba(255, 255, 255, 0.02) 0%, transparent 50%);
    animation: float 30s ease-in-out infinite;
    pointer-events: none;
}

body::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    animation: shimmer 8s ease-in-out infinite;
    pointer-events: none;
    mix-blend-mode: overlay;
}

/* Orbs — scale gently with the music's energy (--pulse set from JS) */
.orbs-container {
    position: absolute;
    inset: 0;
    pointer-events: none;
    filter: blur(40px);
    opacity: 0.4;
    transform: scale(var(--pulse));
    will-change: transform;
}

.orb {
    position: absolute;
    border-radius: 50%;
    mix-blend-mode: screen;
}

.orb1 {
    width: min(600px, 80vw);
    height: min(600px, 80vw);
    top: -20%;
    left: -20%;
    animation: float 25s ease-in-out infinite;
}

.orb2 {
    width: min(400px, 60vw);
    height: min(400px, 60vw);
    bottom: -15%;
    right: -15%;
    animation: float 30s ease-in-out infinite reverse;
}

.orb3 {
    width: min(350px, 50vw);
    height: min(350px, 50vw);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation: float 20s ease-in-out infinite 5s;
}

/* Track-specific orb colors */
body.track-01 .orb1 {
    background: radial-gradient(circle, rgba(255, 0, 128, 0.8), transparent);
}

body.track-01 .orb2 {
    background: radial-gradient(circle, rgba(255, 140, 0, 0.8), transparent);
}

body.track-01 .orb3 {
    background: radial-gradient(circle, rgba(128, 0, 255, 0.6), transparent);
}

body.track-02 .orb1 {
    background: radial-gradient(circle, rgba(255, 0, 255, 0.8), transparent);
}

body.track-02 .orb2 {
    background: radial-gradient(circle, rgba(0, 255, 204, 0.8), transparent);
}

body.track-02 .orb3 {
    background: radial-gradient(circle, rgba(0, 255, 255, 0.6), transparent);
}

/* Chord Display */
.chord-display {
    width: 100%;
    max-width: 100%;
    padding-inline: max(16px, env(safe-area-inset-left));
    text-align: center;
    margin-bottom: 40px;
    z-index: 5;
    position: relative;
}

.chord-title {
    font-size: clamp(14px, 3vw, 18px);
    text-transform: uppercase;
    letter-spacing: 3px;
    opacity: 0.7;
    margin-bottom: 15px;
}

.chord-progression {
    font-size: clamp(20px, 4vw, 32px);
    font-weight: 300;
    letter-spacing: 2px;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.7));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    /* fallback first, then the audio-reactive glow */
    text-shadow: 0 0 30px rgba(255, 255, 255, 0.5);
    text-shadow: 0 0 calc(30px + var(--energy) * 25px)
        rgba(255, 255, 255, calc(0.45 + var(--energy) * 0.35));
}

/* Controls */
.controls-container {
    display: flex;
    gap: 20px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    z-index: 10;
    position: relative;
}

.audio-control,
.download-control {
    appearance: none;
    -webkit-appearance: none;
    font-family: inherit;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50px;
    padding: clamp(12px, 3vw, 15px) clamp(20px, 5vw, 30px);
    display: flex;
    align-items: center;
    gap: clamp(10px, 2vw, 15px);
    cursor: pointer;
    touch-action: manipulation;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
    text-decoration: none;
    color: white;
}

.audio-control:hover,
.download-control:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
    box-shadow:
        0 12px 48px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.audio-control:active,
.download-control:active {
    transform: scale(0.98);
}

.icon {
    display: block;
    width: clamp(20px, 5vw, 24px);
    height: clamp(20px, 5vw, 24px);
    position: relative;
    opacity: 0.9;
}

.icon svg {
    width: 100%;
    height: 100%;
    fill: white;
}

.control-text {
    font-size: clamp(12px, 3vw, 14px);
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    opacity: 0.9;
    user-select: none;
}

/* Visualizer */
.visualizer {
    display: flex;
    gap: 3px;
    height: 20px;
    align-items: center;
}

.bar {
    width: 3px;
    background: linear-gradient(to top, rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0.9));
    border-radius: 2px;
    transition: height 0.2s ease;
}

.bar1 { height: 8px; }
.bar2 { height: 12px; }
.bar3 { height: 6px; }
.bar4 { height: 14px; }
.bar5 { height: 10px; }

/* live = alturas fijadas por el analizador de audio (JS) */
.visualizer.live .bar {
    transition: height 80ms linear;
}

/* fallback = sin Web Audio: la animación CSS original */
body.playing .visualizer.fallback .bar {
    animation: dance 0.8s ease-in-out infinite;
}

body.playing .visualizer.fallback .bar1 { animation-delay: 0s; }
body.playing .visualizer.fallback .bar2 { animation-delay: 0.1s; }
body.playing .visualizer.fallback .bar3 { animation-delay: 0.2s; }
body.playing .visualizer.fallback .bar4 { animation-delay: 0.3s; }
body.playing .visualizer.fallback .bar5 { animation-delay: 0.4s; }

body.track-01.playing,
body.track-02.playing {
    animation-duration: 12s, 6s;
}

/* Hint */
.hint {
    position: fixed;
    top: max(env(safe-area-inset-top), 30px);
    left: 50%;
    transform: translateX(-50%);
    font-size: clamp(10px, 2.5vw, 12px);
    font-weight: 400; /* the hint is an <h1> now; keep the original weight */
    text-transform: uppercase;
    letter-spacing: clamp(1px, 0.3vw, 2px);
    opacity: 0.6;
    pointer-events: none;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    padding: 0 20px;
    text-align: center;
    z-index: 5;
}

/* Toast (aviso discreto en lugar de alert) */
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(max(env(safe-area-inset-bottom), 20px) + 76px);
    transform: translateX(-50%) translateY(10px);
    max-width: min(90vw, 420px);
    padding: 10px 18px;
    border-radius: 24px;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(16px) saturate(160%);
    -webkit-backdrop-filter: blur(16px) saturate(160%);
    border: 1px solid rgba(255, 255, 255, 0.18);
    font-size: 13px;
    letter-spacing: 0.4px;
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 200;
}

.toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Navigation Menu */
.nav-menu {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 100;
}

.nav-toggle {
    width: 48px;
    height: 48px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.nav-toggle span {
    width: 20px;
    height: 2px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 2px;
    transition: all 0.3s ease;
}

.nav-toggle:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: scale(1.05);
}

.nav-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translateY(6px);
}

.nav-toggle.active span:nth-child(2) {
    opacity: 0;
}

.nav-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translateY(-6px);
}

.nav-links {
    position: absolute;
    bottom: 70px;
    right: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-menu.open .nav-links {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 25px;
    text-decoration: none;
    color: white;
    transition: all 0.3s ease;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    white-space: nowrap;
    min-width: 200px;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.12);
    transform: translateX(-5px);
    box-shadow: 0 6px 30px rgba(0, 0, 0, 0.15);
}

.nav-link.active {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
}

.track-number {
    font-size: 14px;
    font-weight: 600;
    opacity: 0.9;
    min-width: 25px;
}

.track-chords {
    font-size: 12px;
    opacity: 0.7;
    font-weight: 300;
    letter-spacing: 0.5px;
}

.nav-menu.open .nav-link:nth-child(1) { transition-delay: 0.05s; }
.nav-menu.open .nav-link:nth-child(2) { transition-delay: 0.1s; }
.nav-menu.open .nav-link:nth-child(3) { transition-delay: 0.15s; }
.nav-menu.open .nav-link:nth-child(4) { transition-delay: 0.2s; }

/* Accessibility */
.nav-link:focus-visible,
.nav-toggle:focus-visible,
.audio-control:focus-visible,
.download-control:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: 2px;
}

/* Media Queries */
@media (max-width: 768px) {
    .chord-display {
        padding-inline:
            max(12px, env(safe-area-inset-left))
            max(12px, env(safe-area-inset-right));
    }

    .chord-progression {
        max-width: 100%;
        font-size: clamp(12px, 3.8vw, 18px);
        letter-spacing: clamp(0.2px, 0.25vw, 1px);
        line-height: 1.3;
        white-space: nowrap;
    }

    .controls-container {
        width: 100%;
        max-width: 100%;
        padding-inline: 16px;
        flex-direction: column;
        gap: 15px;
    }

    .audio-control,
    .download-control {
        width: min(200px, 80vw);
        justify-content: center;
    }

    .nav-menu {
        bottom: 20px;
        right: 20px;
    }

    .nav-links {
        right: 0;
        left: auto;
        align-items: flex-end;
    }

    .nav-link {
        min-width: auto;
        max-width: calc(100vw - 60px);
        padding: 10px 16px;
        font-size: 13px;
        justify-content: center;
    }

    .track-number {
        font-size: 14px;
        font-weight: 600;
        min-width: auto;
    }

    .track-chords {
        display: none;
    }

    .nav-toggle {
        width: 44px;
        height: 44px;
    }

    .nav-toggle span {
        width: 18px;
    }
}

@media (max-width: 380px) {
    .nav-link {
        padding: 8px 14px;
        gap: 12px;
    }
}

@media (max-width: 768px) and (orientation: landscape) {
    .nav-menu {
        bottom: 15px;
        right: 15px;
    }

    .nav-toggle {
        width: 40px;
        height: 40px;
    }

    .nav-links {
        bottom: 55px;
        max-height: calc(100vh - 100px);
        overflow-y: auto;
    }
}

@media (prefers-reduced-motion: reduce) {
    body.track-01,
    body.track-02 {
        animation: none;
        background-size: 100% 100%;
    }

    body::before,
    body::after,
    .orb {
        animation: none;
    }

    .bar {
        animation: none !important;
    }

    .toast {
        transition: none;
    }

    .nav-links,
    .nav-link,
    .nav-toggle,
    .nav-toggle span {
        transition: none;
    }
}
