:root {
    --primary-color: #007aff;
    --primary-gradient: linear-gradient(135deg, #007aff 0%, #00c6ff 100%);
    --bg-gradient: radial-gradient(circle at 0% 0%, rgba(240, 244, 255, 1) 0%, rgba(255, 255, 255, 1) 100%);
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.4);
    --text-main: #1d1d1f;
    --text-secondary: #86868b;
    --shadow-soft: 0 8px 32px 0 rgba(31, 38, 135, 0.07);
    --border-radius-lg: 24px;
    --border-radius-md: 16px;
    --mainMaxWidth: 600px;
    --desktopMaxWidth: 1000px;
    --questHeight: 25%;
    --page-top-offset: 70px;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    transition: all 0.5s ease-in-out;
    font-family: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--text-main);
    background-color: #f5f5f7;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    overflow-y: auto;
    min-height: 100dvh;
}

.quizGrid {
    display: none;
}

#background {
    position: fixed;
    top: 0;
    left: 0;
    z-index: -1;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 10% 20%, rgba(0, 122, 255, 0.05) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(255, 45, 85, 0.05) 0%, transparent 40%),
        radial-gradient(circle at 50% 50%, rgba(0, 198, 255, 0.03) 0%, transparent 70%);
    background-color: #fbfbfd;
}

#main {
    width: 100%;
    max-width: var(--mainMaxWidth);
    margin: 0 auto;
    position: relative;
    background-color: var(--glass-bg);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    display: flex;
    flex-direction: column;
    padding-top: var(--page-top-offset);
    min-height: 100dvh;
}

body.iframe-embed {
    --page-top-offset: 0px;
    background: transparent;
}

body.iframe-embed #background {
    display: none;
}

body.iframe-embed #main {
    max-width: none;
    min-height: 100dvh;
    padding-top: 0;
    margin: 0;
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

#main::-webkit-scrollbar {
    display: none; /* Hide scrollbar Chrome/Safari */
}

.floating-reset-button,
.floating-back-button {
    position: fixed;
    width: 56px;
    height: 56px;
    padding: 0;
    border: 1px solid rgba(214, 48, 49, 0.18);
    border-radius: 50%;
    background: #fff;
    color: #d62839;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    z-index: 1100;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 56px;
}

.floating-reset-button {
    right: calc(20px + env(safe-area-inset-right));
    bottom: calc(20px + env(safe-area-inset-bottom));
}

.floating-back-button {
    left: calc(20px + env(safe-area-inset-left));
    bottom: calc(20px + env(safe-area-inset-bottom));
    display: none;
}

body.iframe-embed .floating-back-button {
    display: inline-flex;
}

.floating-reset-button:hover,
.floating-back-button:hover {
    background: #fff5f5;
}

.floating-reset-button img,
.floating-back-button img {
    width: 26px;
    height: 26px;
    display: block;
    flex: 0 0 26px;
}

.floating-reset-button:focus-visible,
.floating-back-button:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

@media (min-width: 1024px) {
    :root {
        --page-top-offset: 80px;
    }

    #main {
        max-width: var(--desktopMaxWidth);
        margin: 0 auto;
        border-radius: 0;
        border: none;
        box-shadow: none;
        background-color: transparent;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        padding-top: var(--page-top-offset);
    }
}

#loadingSpinner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    display: none; /* JS will set to flex */
    justify-content: center;
    align-items: center;
    background: rgba(255, 255, 255, 0.8);
    z-index: 9999;
}

.loader {
    width: 48px;
    height: 48px;
    border: 3px solid var(--primary-color);
    border-bottom-color: transparent;
    border-radius: 50%;
    display: inline-block;
    animation: rotation 1s linear infinite;
}

@keyframes rotation {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#popup {
    z-index: 10000;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 500px;
    background: #ffffff;
    padding: 40px 30px;
    border-radius: var(--border-radius-lg);
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    align-items: center;
}

#popup h2 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 24px;
    color: var(--text-main);
    text-align: center;
}

#popup ul {
    padding: 0;
    margin-bottom: 30px;
    list-style: none;
}

#popup li {
    font-size: 15px;
    line-height: 1.6;
    color: var(--text-secondary);
    margin-bottom: 16px;
    position: relative;
    padding-left: 24px;
}

#popup li::before {
    content: "•";
    position: absolute;
    left: 0;
    color: var(--primary-color);
    font-weight: bold;
}

#popup button, #hideInstructions {
    width: 100%;
    padding: 16px;
    background: var(--primary-gradient);
    color: white;
    border: none;
    border-radius: var(--border-radius-md);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

#popup button:active {
    transform: scale(0.98);
}
