/* Using system fonts to avoid loading errors */
:root {
    --neon-blue: #00f2ff;
    --neon-yellow: #fff200;
    --neon-red: #ff004c;
    --glass-bg: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.2);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

#start-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #050505;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.5s;
}

#start-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

body {
    background: #050505;
    color: white;
    font-family: system-ui, -apple-system, sans-serif;
    overflow: hidden;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

#app-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    background: radial-gradient(ellipse at 50% 40%, #1a0a2e 0%, #0d0618 40%, #050208 100%);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 2rem;
}

/* Background Overlay for Mindspace feel */
#app-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, transparent 20%, rgba(0, 0, 0, 0.8) 100%);
    pointer-events: none;
}

/* Bill Cipher Character */
#bill-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 350px;
    /* Slightly larger to accommodate all sprites */
    height: 350px;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.3s ease-out;
    /* Smoother tracking */
}

#bill-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    animation: float 3s ease-in-out infinite;
}

#thinking-bg,
#ritual-fire,
#bill {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    /* CRITICAL: keeps aspect ratio constant within the box */
    pointer-events: none;
}

#thinking-bg {
    width: 100%;
    height: 100%;
    transform: translate(0px, 34px) scale(0.55);
    /* Micro-tweak: shifted UP and RIGHT to correct bottom-left clipping */
    opacity: 0;
    transition: opacity 0.5s ease;
    z-index: 5;
    mix-blend-mode: color-dodge;
}

#ritual-fire {
    width: 100%;
    height: 100%;
    opacity: 0;
    z-index: 20;
    /* On top of everything during ritual */
    mix-blend-mode: screen;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

#bill {
    z-index: 10;
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 0 15px rgba(255, 242, 0, 0.4));
    transition: opacity 0.3s ease, filter 0.1s ease, transform 0.1s ease;
}

#bill.speaking-glow {
    filter: drop-shadow(0 0 30px rgba(255, 255, 0, 1)) drop-shadow(0 0 50px rgba(255, 255, 255, 0.9));
    transform: scale(1.02);
    transition: filter 0.05s ease, transform 0.05s ease;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-20px);
    }
}

/* Fire Aura */
#fire-overlay {
    position: absolute;
    top: -20%;
    left: -20%;
    width: 140%;
    height: 140%;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    mix-blend-mode: screen;
}

.fire-active #fire-overlay {
    opacity: 0.8;
}

/* Rift */
#rift-container {
    position: absolute;
    top: 60%;
    left: 70%;
    width: 100px;
    height: 100px;
    opacity: 0;
    transition: opacity 0.5s ease;
}

/* Blinking animation logic */
.blinking {
    animation: blink-anim 0.15s ease-in-out;
}

@keyframes blink-anim {

    0%,
    100% {
        transform: scaleY(1);
    }

    50% {
        transform: scaleY(0.1);
    }
}

button {
    background: transparent;
    border: 1px solid var(--neon-blue);
    color: var(--neon-blue);
    padding: 0.8rem 1.2rem;
    border-radius: 10px;
    font-family: inherit;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

button:hover {
    background: var(--neon-blue);
    color: #000;
    box-shadow: 0 0 15px var(--neon-blue);
}

button:active {
    transform: scale(0.95);
}

/* API Controls (Buttons at bottom) */
#api-controls {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

#controls-row {
    display: flex;
    gap: 1rem;
    align-items: center;
}

#connect-btn,
#mic-btn {
    width: 55px;
    height: 55px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    font-size: 1.6rem;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s ease;
    cursor: pointer;
    padding: 0;
}

#connect-btn {
    border: 2px solid var(--neon-blue);
    color: var(--neon-blue);
}

#connect-btn:hover {
    background: var(--neon-blue);
    box-shadow: 0 0 20px var(--neon-blue);
    transform: scale(1.1);
}

#mic-btn {
    border: 2px solid var(--neon-red);
    color: var(--neon-red);
}

#mic-btn:hover:not(:disabled) {
    background: var(--neon-red);
    box-shadow: 0 0 20px var(--neon-red);
    transform: scale(1.1);
}

#mic-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

#connection-status {
    font-size: 0.8rem;
    color: #aaa;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-weight: bold;
}

/* Dialogue Box (Subtitles style) */
#dialogue-container {
    position: relative;
    z-index: 100;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 242, 0, 0.5);
    box-shadow: 0 0 15px rgba(255, 242, 0, 0.2);
    padding: 1rem 2rem;
    margin: 0 auto;
    min-height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    border-radius: 30px;
    max-width: 80%;
}

#dialogue {
    font-size: 1.4rem;
    line-height: 1.4;
    font-weight: bold;
    color: white;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

/* Appearance glitch effect */
.glitch {
    animation: glitch-anim 0.2s infinite;
}

@keyframes glitch-anim {
    0% {
        transform: translate(-50%, -50%) skew(2deg);
        opacity: 0.8;
    }

    50% {
        transform: translate(-48%, -52%) skew(-2deg);
        opacity: 1;
    }

    100% {
        transform: translate(-50%, -50%) skew(1deg);
        opacity: 0.9;
    }
}

@keyframes shake {
    0% {
        transform: translate(1px, 1px) rotate(0deg);
    }

    10% {
        transform: translate(-1px, -2px) rotate(-1deg);
    }

    20% {
        transform: translate(-3px, 0px) rotate(1deg);
    }

    30% {
        transform: translate(3px, 2px) rotate(0deg);
    }

    40% {
        transform: translate(1px, -1px) rotate(1deg);
    }

    50% {
        transform: translate(-1px, 2px) rotate(-1deg);
    }

    60% {
        transform: translate(-3px, 1px) rotate(0deg);
    }

    70% {
        transform: translate(3px, 1px) rotate(-1deg);
    }

    80% {
        transform: translate(-1px, -1px) rotate(1deg);
    }

    90% {
        transform: translate(1px, 2px) rotate(0deg);
    }

    100% {
        transform: translate(1px, -2px) rotate(-1deg);
    }
}

/* Click-to-Start Overlay */
#start-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: radial-gradient(ellipse at center, rgba(10, 5, 30, 0.95) 0%, #000 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    cursor: pointer;
    transition: opacity 0.5s ease;
}

#start-content {
    text-align: center;
    animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {

    0%,
    100% {
        opacity: 0.7;
        transform: scale(1);
    }

    50% {
        opacity: 1;
        transform: scale(1.05);
    }
}