:root {
    --primary-color: #007aff;
    --primary-gradient: linear-gradient(135deg, #007aff 0%, #00c6ff 100%);
    --bg-color: #fbfbfd;
    --text-main: #1d1d1f;
    --text-secondary: #6e6e73;
    --glass-bg: rgba(255, 255, 255, 0.72);
    --glass-border: rgba(255, 255, 255, 0.45);
    --border-radius-lg: 24px;
    --border-radius-md: 16px;
    --border-radius-sm: 12px;
    --shadow-soft: 0 10px 35px rgba(35, 62, 120, 0.08);
    --main-max-width: 980px;
    --mobile-font-scale: 1;
    --mobile-font-min: 0px;
    --main-stack-gap: 14px;
    --navbar-height: 66px;
    --page-top-offset: calc(var(--navbar-height) + var(--main-stack-gap) + env(safe-area-inset-top));
}

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

html,
body {
    margin: 0;
    padding: 0;
    min-height: 100%;
}

body {
    font-family: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--text-main);
    background: var(--bg-color);
    overflow-x: hidden;
}

#background {
    position: fixed;
    inset: 0;
    z-index: -1;
    background:
        radial-gradient(circle at 8% 12%, rgba(0, 122, 255, 0.08) 0%, transparent 40%),
        radial-gradient(circle at 92% 78%, rgba(0, 198, 255, 0.08) 0%, transparent 40%),
        radial-gradient(circle at 50% 60%, rgba(255, 45, 85, 0.04) 0%, transparent 70%),
        #fbfbfd;
}

.navbar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(255, 255, 255, 0.72);
    border-bottom: 1px solid var(--glass-border);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 12px 16px;
    z-index: 1000;
}

.navbarLeft,
.navbarRight {
    flex: 1;
    display: flex;
    align-items: center;
}

.navbarLeft {
    justify-content: flex-start;
    gap: 12px;
}

.navbarRight {
    justify-content: flex-end;
    gap: 12px;
}

.navIconButton {
    width: 42px;
    height: 42px;
    border: none;
    background: transparent;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.navIconButton:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.navIconButton img {
    width: 20px;
    height: 20px;
}

.navbar .logo {
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

.navbar .logo img,
.desktop-logo img,
.desktop-logo-mark {
    height: 32px;
    width: auto;
}

.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;
}

.desktop-logo {
    display: flex;
    align-items: center;
    cursor: pointer;
}

.icon-right {
    cursor: default;
}

.icon-right:hover {
    background-color: transparent;
}

.desktop-logo-mark {
    display: flex;
    align-items: center;
}

.desktop-logo:focus-visible,
.navbar .logo:focus-visible,
.navIconButton:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

#main {
    width: 100%;
    max-width: var(--main-max-width);
    margin: 0 auto;
    min-height: 100dvh;
    padding: var(--page-top-offset) 16px calc(24px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    gap: 14px;
}

body.iframe-embed .navbar {
    display: none;
}

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

body.iframe-embed #main {
    max-width: none;
    min-height: 100dvh;
    padding: 0;
}

body.iframe-embed #questionCard,
body.iframe-embed #contentCard {
    border-radius: 0;
}

#questionCard,
#contentCard {
    background: var(--glass-bg);
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-soft);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}

#questionCard {
    min-height: 150px;
    padding: 24px 18px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: center;
    justify-content: center;
    text-align: center;
}

#contentCard {
    min-height: calc(100dvh - 340px);
    padding: 18px 14px;
    display: flex;
    flex-direction: column;
}

#contentCard.results-surface {
    min-height: auto;
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

#questionCard.results-question-card {
    margin-bottom: 2px;
    min-height: 32px;
    padding: 8px 14px;
    gap: 2px;
}

#questionContext {
    margin: 0;
    color: var(--text-secondary);
    font-size: max(var(--mobile-font-min, 0px), calc(13px * var(--mobile-font-scale, 1)));
    font-weight: 600;
    line-height: 1.35;
    max-width: 100%;
    overflow-wrap: normal;
    word-break: normal;
    text-wrap: pretty;
}

#screenTitle {
    margin: 0;
    font-size: clamp(15px, 3.85vw, 24px);
    line-height: 1.2;
    font-weight: 700;
    text-align: center;
    max-width: 100%;
    overflow-wrap: normal;
    word-break: normal;
    text-wrap: balance;
}

#screenHint {
    margin: 0;
    color: var(--text-secondary);
    font-size: max(var(--mobile-font-min, 0px), calc(13px * var(--mobile-font-scale, 1)));
    line-height: 1.5;
    text-align: center;
    max-width: 100%;
    overflow-wrap: normal;
    word-break: normal;
    text-wrap: pretty;
}

#screenContent {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

#screenActions {
    position: static;
    bottom: auto;
    left: auto;
    width: 100%;
    padding: 0;
    z-index: auto;
}

#nextBtn {
    width: 100%;
    margin: 0 auto;
    display: block;
    border: none;
    border-radius: var(--border-radius-md);
    background: var(--primary-gradient);
    color: #ffffff;
    font-size: max(var(--mobile-font-min, 0px), calc(16px * var(--mobile-font-scale, 1)));
    font-weight: 600;
    padding: 15px 16px;
    box-shadow: 0 6px 18px rgba(0, 122, 255, 0.24);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#nextBtn:active {
    transform: scale(0.98);
}

#indicator {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 7px;
    background: #e3e4e8;
    z-index: 1150;
}

#indicatorBall {
    width: 0;
    height: 100%;
    background: var(--primary-gradient);
    transition: width 0.3s ease;
}

.validation-modal {
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.56);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 3000;
}

.validation-modal.open {
    display: flex;
}

.validation-dialog {
    width: min(100%, 560px);
    border-radius: 16px;
    background: #ffffff;
    border: 1px solid #d9dbe1;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.24);
    padding: 22px 18px 18px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    text-align: center;
}

#validationMessage {
    margin: 0;
    color: #1b1f28;
    font-size: max(var(--mobile-font-min, 0px), calc(17px * var(--mobile-font-scale, 1)));
    line-height: 1.45;
    font-weight: 600;
}

#validationDismiss {
    border: none;
    border-radius: 12px;
    background: var(--primary-gradient);
    color: #fff;
    font-size: max(var(--mobile-font-min, 0px), calc(16px * var(--mobile-font-scale, 1)));
    font-weight: 600;
    padding: 13px 14px;
    cursor: pointer;
}

.info-modal {
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.66);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 18px;
    z-index: 3200;
}

.info-modal.open {
    display: flex;
}

.info-dialog {
    width: min(100%, 840px);
    min-height: min(74dvh, 680px);
    border-radius: 22px;
    background: #ffffff;
    border: 1px solid #d9dbe1;
    box-shadow: 0 22px 56px rgba(0, 0, 0, 0.28);
    padding: 22px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 14px;
    text-align: center;
}

#infoModalTitle {
    margin: 0;
    font-size: clamp(26px, 5.2vw, 44px);
    line-height: 1.05;
    max-width: min(100%, 760px);
    margin-inline: auto;
    overflow-wrap: normal;
    word-break: normal;
    text-wrap: balance;
}

#infoModalBody {
    margin: 0 auto;
    max-width: min(100%, 740px);
    font-size: clamp(15px, 2.5vw, 23px);
    line-height: 1.4;
    color: #4c5a74;
    white-space: pre-line;
    overflow-wrap: normal;
    word-break: normal;
    text-wrap: balance;
}

#infoModalDismiss {
    border: none;
    border-radius: 12px;
    background: var(--primary-gradient);
    color: #fff;
    font-size: max(var(--mobile-font-min, 0px), calc(17px * var(--mobile-font-scale, 1)));
    font-weight: 600;
    padding: 13px 18px;
    cursor: pointer;
    width: min(100%, 360px);
    margin: 8px auto 0;
}

.data-modal {
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.66);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 3400;
}

.data-modal.open {
    display: flex;
}

.data-dialog {
    width: min(100%, 1100px);
    height: min(92dvh, 900px);
    border-radius: 20px;
    background: #ffffff;
    border: 1px solid #d9dbe1;
    box-shadow: 0 22px 56px rgba(0, 0, 0, 0.28);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#dataModalTitle {
    margin: 0;
    font-size: clamp(18px, 3.1vw, 30px);
    line-height: 1.2;
    color: #273654;
    text-align: center;
}

#dataExportText {
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    border: 1px solid #d6deed;
    border-radius: 10px;
    padding: 12px;
    background: #f8fbff;
    color: #24324e;
    resize: none;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 12px;
    line-height: 1.45;
}

#dataModalClose {
    border: none;
    border-radius: 12px;
    background: var(--primary-gradient);
    color: #fff;
    font-size: max(var(--mobile-font-min, 0px), calc(16px * var(--mobile-font-scale, 1)));
    font-weight: 600;
    padding: 12px 14px;
    cursor: pointer;
}

@media (min-width: 1024px) {
    :root {
        --main-stack-gap: 18px;
    }

    .navbar {
        padding: 12px 24px;
    }

    .navbar .logo,
    .navbarRight .icon-right {
        display: none;
    }

    .desktop-logo img,
    .desktop-logo-mark {
        height: 30px;
    }

    #main {
        padding-top: var(--page-top-offset);
        padding-left: 24px;
        padding-right: 24px;
        padding-bottom: calc(24px + env(safe-area-inset-bottom));
        gap: 18px;
    }

    #questionCard {
        min-height: 102px;
        padding: 14px 28px;
    }

    #contentCard {
        min-height: calc(100dvh - 330px);
        padding: 28px 26px;
    }

    #contentCard.results-surface {
        min-height: auto;
        padding: 0;
    }

    #screenActions {
        position: static;
        bottom: auto;
        left: auto;
        width: 100%;
        padding: 0;
    }

    #nextBtn {
        width: 100%;
    }
}

@media (max-width: 720px) {
    :root {
        --mobile-font-scale: 0.85;
        --mobile-font-min: 10px;
        --main-stack-gap: 10px;
    }

    #main {
        gap: 10px;
        padding-top: var(--page-top-offset);
        padding-left: 12px;
        padding-right: 12px;
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }

    #questionCard {
        min-height: 104px;
        padding: 14px 12px;
        gap: 4px;
        border-radius: 20px;
    }

    #questionContext {
        font-size: max(var(--mobile-font-min, 0px), calc(11px * var(--mobile-font-scale, 1)));
        line-height: 1.25;
    }

    #screenTitle {
        font-size: clamp(12px, 4.4vw, 17px);
        line-height: 1.15;
    }

    #screenHint {
        font-size: max(var(--mobile-font-min, 0px), calc(11px * var(--mobile-font-scale, 1)));
        line-height: 1.35;
    }

    #contentCard {
        min-height: 0;
        padding: 12px 10px;
        border-radius: 20px;
    }

    #contentCard:not(.results-surface) {
        max-height: calc(100dvh - 260px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        overflow-y: auto;
    }

    #screenContent {
        gap: 10px;
    }

    #screenActions {
        padding-top: 2px;
    }

    #nextBtn {
        border-radius: 14px;
        font-size: max(var(--mobile-font-min, 0px), calc(15px * var(--mobile-font-scale, 1)));
        padding: 13px 14px;
    }

    #infoModalTitle {
        font-size: clamp(22px, 4.4vw, 37px);
    }

    #infoModalBody {
        font-size: clamp(13px, 2.12vw, 19px);
    }
}

@media (max-width: 480px) {
    :root {
        --navbar-height: 62px;
    }

    .navbar {
        padding: 10px 16px;
    }

    .navbarLeft,
    .navbarRight {
        gap: 8px;
    }

    .info-dialog {
        min-height: min(86dvh, 700px);
        border-radius: 18px;
        padding: 18px;
    }

    #infoModalDismiss {
        width: 100%;
    }

    .desktop-logo img,
    .desktop-logo-mark {
        height: 26px;
    }

    .data-dialog {
        border-radius: 16px;
        padding: 12px;
    }
}
