/* ---- Fonts ---- */
@font-face {
    font-family: 'Freckle Face';
    src: url('FreckleFace-Regular.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

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

html, body { height: 100%; }

body {
    /* Gentle gradient of blues, slowly drifting */
    background: linear-gradient(-45deg, #0a2a43, #114b6b, #1f7aa6, #5fb8e0, #aee4f5);
    background-size: 400% 400%;
    animation: gradient 24s ease infinite;
    overflow: hidden;            /* bubbles never add scrollbars */
    font-family: 'Freckle Face', 'Segoe UI', system-ui, -apple-system, cursive;
    cursor: default;
    /* Text is non-selectable across the page */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* …except the name input, which must stay editable/selectable */
#custom-name {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

@keyframes gradient {
    0%   { background-position: 0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* Rainbow-collection color overlay — sits above the blue base, below the
   bubbles. Opacity is driven by JS: rises as rainbow bubbles are collected,
   fades back to 0 (revealing the default blue) after a lull. */
#color-overlay {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    opacity: 0;
    transition: opacity 1.6s ease;
    background-size: 300% 300%;
    background-position: 0% 50%;
    animation: gradient 18s ease infinite;
}

/* ---- Centered content ---- */
.container {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100vh;
    text-align: center;
    pointer-events: none;        /* let cursor bubbles spawn over the text too */
}

#float-text {
    color: #ffffff;
    font-weight: 300;
    font-size: clamp(48px, 12vw, 130px);
    letter-spacing: 2px;
    text-shadow: 0 4px 30px rgba(0, 40, 80, 0.45);
    animation: float 6s ease-in-out infinite;
}

.subtitle {
    margin-top: 0.5rem;
    color: rgba(255, 255, 255, 0.8);
    font-size: clamp(16px, 2.5vw, 24px);
    font-weight: 300;
    letter-spacing: 6px;
    text-transform: uppercase;
    text-shadow: 0 2px 16px rgba(0, 40, 80, 0.4);
}

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

/* ---- Name generator ---- */
.namegen {
    margin-top: 2.2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    pointer-events: auto;        /* re-enable clicks inside the centered container */
}

.generated-name {
    min-height: 1.4em;
    padding: 0.4em 0.9em;
    font-size: clamp(24px, 5vw, 46px);
    font-weight: 600;
    letter-spacing: 1px;
    color: #ffffff;
    text-shadow: 0 2px 18px rgba(0, 40, 80, 0.5);
    white-space: nowrap;
}

/* Each rolling word slot */
.generated-name .part {
    display: inline-block;
    transition: transform 0.12s ease;
}
.generated-name .part.rolling {
    color: #d6f3ff;
}
.generated-name .part.settle {
    animation: settle 0.28s cubic-bezier(0.2, 1.4, 0.4, 1);
}

@keyframes settle {
    0%   { transform: translateY(-0.18em) scale(1.12); }
    100% { transform: translateY(0) scale(1); }
}

#custom-name {
    width: min(320px, 80vw);
    padding: 0.6em 1.1em;
    border: 1px solid rgba(255, 255, 255, 0.45);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: #ffffff;
    font: 500 16px/1 'Freckle Face', 'Segoe UI', system-ui, cursive;
    letter-spacing: 0.5px;
    text-align: center;
    outline: none;
    transition: background 0.25s ease, border-color 0.25s ease;
}
#custom-name::placeholder { color: rgba(255, 255, 255, 0.65); }
#custom-name:focus {
    background: rgba(255, 255, 255, 0.28);
    border-color: rgba(255, 255, 255, 0.8);
}

#generate-name {
    padding: 0.7em 1.6em;
    border: 1px solid rgba(255, 255, 255, 0.45);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: #ffffff;
    font: 600 16px/1 'Freckle Face', 'Segoe UI', system-ui, cursive;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 40, 80, 0.3);
    transition: background 0.25s ease, transform 0.15s ease;
}
#generate-name:hover { background: rgba(255, 255, 255, 0.3); }
#generate-name:active { transform: scale(0.95); }
#generate-name:disabled { opacity: 0.6; cursor: default; }

/* ---- Ambient rising bubbles ---- */
.bubbles {
    position: fixed;
    inset: 0;
    z-index: 1;
    overflow: hidden;
    pointer-events: none;
}

.bubble {
    position: absolute;
    bottom: -240px;              /* start just below the viewport */
    border-radius: 50%;
    background: radial-gradient(circle at 30% 25%,
                rgba(255, 255, 255, 0.85),
                rgba(255, 255, 255, 0.25) 40%,
                rgba(174, 228, 245, 0.10) 70%);
    box-shadow: inset 0 0 18px rgba(255, 255, 255, 0.4),
                0 0 22px rgba(174, 228, 245, 0.3);
    animation: rise linear infinite;
    opacity: 0;
    pointer-events: auto;        /* clickable so they can be popped */
    cursor: pointer;
    will-change: transform, opacity;
}

/* Burst when a bubble is popped — snappy so rapid clicks fire instantly */
.bubble.pop {
    animation: none;
    transition: transform 0.12s cubic-bezier(0.2, 0.8, 0.3, 1), opacity 0.12s ease-out;
    transform: scale(1.6) !important;
    opacity: 0 !important;
    pointer-events: none;        /* drop out of hit-testing the instant it pops */
}

/* Expanding ring left behind by a pop */
.pop-ring {
    position: fixed;
    z-index: 3;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.85);
    pointer-events: none;
    transform: translate(-50%, -50%);
    animation: ring 0.3s ease-out forwards;
}

@keyframes ring {
    0%   { opacity: 0.9; transform: translate(-50%, -50%) scale(0.4); }
    100% { opacity: 0;   transform: translate(-50%, -50%) scale(1.8); }
}

/* ---- Giant rainbow bubble ---- */
.bubble.rainbow {
    overflow: hidden;            /* clip the spinning gradient to a circle */
    background: radial-gradient(circle at 30% 25%,
                rgba(255, 255, 255, 0.9),
                rgba(255, 255, 255, 0.15) 40%,
                transparent 62%);
    box-shadow: inset 0 0 30px rgba(255, 255, 255, 0.55),
                0 0 46px rgba(255, 255, 255, 0.5);
}

.bubble.rainbow::before {
    content: '';
    position: absolute;
    inset: -25%;                 /* oversize so rotation always fills the circle */
    border-radius: 50%;
    z-index: -1;                 /* sit behind the white highlight */
    opacity: 0.85;
    background: conic-gradient(from 0deg,
        #ff5252, #ff9f43, #ffe14d, #4dff7a,
        #4dd2ff, #5b6cff, #c14dff, #ff4dbd, #ff5252);
    animation: spin 5s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ---- Confetti (from a popped rainbow bubble) ---- */
.confetti {
    position: fixed;
    z-index: 4;
    pointer-events: none;
    will-change: transform, opacity;
    animation: confetti-burst var(--dur, 1s) cubic-bezier(0.15, 0.7, 0.3, 1) forwards;
}

@keyframes confetti-burst {
    0%   { transform: translate(-50%, -50%) rotate(0deg) scale(1); opacity: 1; }
    100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy)))
                      rotate(var(--rot)) scale(0.9); opacity: 0; }
}

@keyframes rise {
    0%   { transform: translateY(0) translateX(0) scale(0.9); opacity: 0; }
    10%  { opacity: 0.8; }
    50%  { transform: translateY(-55vh) translateX(20px) scale(1); }
    90%  { opacity: 0.7; }
    100% { transform: translateY(-115vh) translateX(-15px) scale(1.05); opacity: 0; }
}

/* ---- Small bubbles that trail the cursor ---- */
.cursor-bubble {
    position: fixed;
    z-index: 3;
    border-radius: 50%;
    pointer-events: none;
    background: radial-gradient(circle at 30% 25%,
                rgba(255, 255, 255, 0.95),
                rgba(190, 232, 248, 0.35) 55%,
                rgba(190, 232, 248, 0) 75%);
    box-shadow: inset 0 0 6px rgba(255, 255, 255, 0.6),
                0 0 8px rgba(190, 232, 248, 0.5);
    animation: pop 1s ease-out forwards;
}

@keyframes pop {
    0%   { transform: translate(-50%, -50%) scale(0.3); opacity: 0.9; }
    70%  { opacity: 0.6; }
    100% { transform: translate(-50%, -160%) scale(1.1); opacity: 0; }
}

/* ---- Floating side menu ---- */
.side-menu { position: fixed; top: 18px; left: 18px; z-index: 6; }

.menu-toggle {
    position: relative;
    z-index: 7;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 50px;
    height: 50px;
    padding: 0 12px;
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 40, 80, 0.3);
    transition: background 0.25s ease, transform 0.15s ease;
}
.menu-toggle:hover { background: rgba(255, 255, 255, 0.28); }
.menu-toggle:active { transform: scale(0.94); }

.menu-toggle .bar {
    display: block;
    height: 3px;
    width: 100%;
    border-radius: 3px;
    background: #ffffff;
    transition: transform 0.3s ease, opacity 0.2s ease;
}
/* Hamburger morphs into an X when open */
.menu-toggle[aria-expanded="true"] .bar:nth-child(1) { transform: translateY(8px) rotate(45deg); }
.menu-toggle[aria-expanded="true"] .bar:nth-child(2) { opacity: 0; }
.menu-toggle[aria-expanded="true"] .bar:nth-child(3) { transform: translateY(-8px) rotate(-45deg); }

.menu-panel {
    position: absolute;
    top: 62px;
    left: 0;
    width: 240px;
    padding: 14px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 18px;
    background: rgba(13, 52, 84, 0.45);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    box-shadow: 0 10px 34px rgba(0, 30, 60, 0.45);
    transform-origin: top left;
    transform: scale(0.85) translateY(-8px);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.1), opacity 0.22s ease;
}
.menu-panel.open {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: auto;
}

.menu-title {
    margin: 4px 6px 12px;
    color: rgba(255, 255, 255, 0.7);
    font-size: 15px;
    font-weight: 400;
    letter-spacing: 3px;
    text-transform: uppercase;
}

.menu-panel ul { list-style: none; }

.menu-panel a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 12px;
    color: #ffffff;
    text-decoration: none;
    font-size: 19px;
    transition: background 0.2s ease, transform 0.15s ease;
}
.menu-panel a:hover { background: rgba(255, 255, 255, 0.16); transform: translateX(3px); }
.menu-panel a:active { background: rgba(255, 255, 255, 0.26); }
.menu-icon { font-size: 22px; }

/* ---- Music toggle button (lower right) ---- */
#sound-toggle {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: #ffffff;
    font: 600 15px/1 'Freckle Face', 'Segoe UI', system-ui, cursive;
    letter-spacing: 1px;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 40, 80, 0.3);
    transition: background 0.25s ease, transform 0.15s ease;
    user-select: none;
}

#sound-toggle:hover { background: rgba(255, 255, 255, 0.28); }
#sound-toggle:active { transform: scale(0.95); }

#sound-toggle .icon-on { display: none; }
#sound-toggle .icon-off { display: inline; }
#sound-toggle[aria-pressed="true"] .icon-on { display: inline; }
#sound-toggle[aria-pressed="true"] .icon-off { display: none; }
#sound-toggle[aria-pressed="true"] { background: rgba(95, 184, 224, 0.45); }

#sound-toggle .icon-off,
#sound-toggle .icon-on { font-size: 18px; line-height: 1; }

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
    /* Keep the gentle rising bubbles (core of the experience, and many
       phones force reduced-motion via Low Power Mode) — but calm the
       flashier effects: rapid color shifts, confetti, cursor trail,
       heading float, and the rainbow's internal spin. */
    #float-text, .cursor-bubble, .confetti, #color-overlay,
    .bubble.rainbow::before { animation: none; }
    .cursor-bubble { opacity: 0.5; }
}
