* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Nunito Sans', 'Museo Sans', sans-serif; background: #FFF; color: #231F20; min-height: 100dvh; margin: 0; padding: 0; overflow-x: hidden; }

/* Progress Bar - fixed top */
.progress-container { position: fixed; top: 0; left: 0; width: 100%; height: 5px; z-index: 1100; }
.progress-track { width: 100%; height: 100%; background: #DFDFDF; border-radius: 2.5px; }
.progress-fill { height: 100%; background: #039BE5; border-radius: 2.5px; transition: width 0.3s ease; }

/* Assessment Card */
.assessment-card { background: #FFF; max-width: 1048px; width: 100%; margin: 0 auto; padding: 2rem; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; min-height: 100dvh; box-sizing: border-box; position: relative; }
@media (max-width: 900px) { .assessment-card { padding: 1.5rem 1rem 5rem; min-height: 100dvh; min-width: 100vw; } }

/* Explanation 3 & 4 text box - move up on mobile to avoid button overlap */
@media (max-width: 900px) {
    #screen-explanation3 .elmer-text-card,
    #screen-explanation4 .elmer-text-card { top: 5% !important; font-size: 0.85rem !important; }
}

/* Copyright pinned to bottom */
.copyright { font-size: 0.7rem; color: #B9B9B9; text-align: center; position: absolute; bottom: 1rem; left: 0; right: 0; padding: 0 1rem; }
@media (max-width: 480px) {
    .copyright { max-width: 240px; margin-left: auto; margin-right: auto; line-height: 1.5; }
}
.assessment-card.hidden { display: none; }
.hidden { display: none !important; }
.screen-entering { opacity: 0; }
.screen-visible { opacity: 1; transition: opacity 250ms ease-out; }

/* Question Prompt */
.question-prompt { font-family: 'DM Serif Display', 'Mercury Display', serif; font-size: 1.75rem; color: #231F20; max-width: 680px; margin: 2rem auto 0; line-height: 130%; white-space: pre-line; }
@media (max-width: 900px) { .question-prompt { font-size: 1.25rem; max-width: 100%; margin: 1rem auto 0; } }

/* Section label */
.section-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 1.5px; color: #037DBA; margin-bottom: 0.5rem; font-weight: 600; }

/* Radio Card Options */
.options { display: flex; flex-direction: column; gap: 5px; width: 100%; max-width: 538px; margin-top: 1.5rem; }
.option-card { border: 0.5px solid #DFDFDF; border-radius: 5px; padding: 14px 16px; min-height: 44px; display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 1rem; color: #333; box-shadow: 0px 2px 8px rgba(0,0,0,0.2); transition: all 0.15s; -webkit-tap-highlight-color: transparent; }
.option-card:hover { box-shadow: 0px 2px 12px rgba(0,0,0,0.3); }
.option-card.selected { border: 1px solid #037DBA; color: #037DBA; box-shadow: none; }
@media (max-width: 900px) { .option-card { font-size: 0.9rem; padding: 12px 14px; min-height: 40px; } }

/* Button */
.btn { background: #037DBA; border: 0; border-radius: 23px; color: #FFF; font-family: 'Nunito Sans', sans-serif; font-weight: 500; font-size: 1rem; min-height: 44px; line-height: 19px; padding: 14px 48px; cursor: pointer; text-transform: none; -webkit-tap-highlight-color: transparent; transition: transform 180ms ease-out; }
.btn:hover { background: #00689B; }
.btn:hover:not(:disabled) { transform: scale(1.02); }
.btn.wide { padding: 14px 88px; }
@media (max-width: 900px) { .btn.wide { padding: 14px 48px; width: 100%; max-width: 320px; } }
.btn:disabled { background: #E7E8EC; color: #231F20; cursor: not-allowed; }
.btn.plain { background: none; color: #231F20; padding: 0; }

/* Flash Word */
.flash-word { font-family: 'Nunito Sans', sans-serif; font-size: 80px; font-weight: 500; color: #231F20; }
@media (max-width: 900px) { .flash-word { font-size: 48px; } }
.flash-instructions { font-size: 16px; color: #333; margin-bottom: 1rem; line-height: 1.6; max-width: 500px; }
.word-case { font-size: 20px; margin: 0.25rem 0; }
.word-case.bold { font-weight: 700; font-size: 22px; }

/* Timer */
.timer { font-size: 0.875rem; color: #E91E63; font-weight: 600; margin-top: 0.75rem; }

/* Word recall / Innovation input */
.input-area { width: 100%; max-width: 538px; margin-top: 1.5rem; }
.word-input { width: 100%; padding: 14px 16px; border: 1px solid #DFDFDF; border-radius: 5px; font-size: 16px; font-family: 'Nunito Sans', sans-serif; -webkit-appearance: none; }
.word-input:focus { outline: none; border-color: #037DBA; box-shadow: 0 0 0 2px rgba(3,155,229,0.15); }
.word-tags { display: flex; flex-wrap: wrap; gap: 8px; margin: 1rem 0; min-height: 32px; justify-content: center; }
.word-tag { background: #E7E8EC; padding: 6px 14px; border-radius: 20px; font-size: 0.8rem; color: #333; }

/* Innovation image */
.innovation-img { max-width: 100%; max-height: 280px; border-radius: 8px; margin-bottom: 1rem; box-shadow: 0 2px 12px rgba(0,0,0,0.1); }

/* Results */
.results-title { font-family: 'DM Serif Display', serif; font-size: 1.75rem; margin-bottom: 0.5rem; }
.results-subtitle { color: #5F5F5F; margin-bottom: 2rem; }
.pulse-score { font-size: 4.5rem; font-weight: 700; color: #037DBA; margin-bottom: 0.25rem; }
@media (max-width: 900px) { .pulse-score { font-size: 3.5rem; } }
.pulse-label { font-size: 0.875rem; color: #5F5F5F; margin-bottom: 2rem; }
.factors-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; max-width: 500px; }
@media (max-width: 400px) { .factors-grid { grid-template-columns: 1fr; } }
.factor-card { background: #F5F6FA; border-radius: 8px; padding: 20px 16px; text-align: center; border-top: 3px solid #DFDFDF; }
.factor-card.connectedness { border-top-color: #00B288; }
.factor-card.emotional-balance { border-top-color: #E91E63; }
.factor-card.purpose { border-top-color: #FFCA28; }
.factor-card.clarity { border-top-color: #7B1FA2; }
.factor-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 1px; color: #5F5F5F; margin-bottom: 4px; }
.factor-value { font-size: 2rem; font-weight: 700; }
.factor-value.connectedness { color: #00B288; }
.factor-value.emotional-balance { color: #E91E63; }
.factor-value.purpose { color: #C39400; }
.factor-value.clarity { color: #7B1FA2; }
.factor-desc { font-size: 0.7rem; color: #B9B9B9; margin-top: 4px; }
.btn-restart { margin-top: 2rem; background: none; border: 1px solid #DFDFDF; border-radius: 23px; padding: 12px 32px; color: #5F5F5F; font-size: 0.875rem; cursor: pointer; }
.btn-restart:hover { border-color: #037DBA; color: #037DBA; }

/* Percentile ranking */
.percentile-card { background: #F5F6FA; border-radius: 8px; padding: 20px; margin-bottom: 12px; }
.percentile-title { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 1px; color: #5F5F5F; margin-bottom: 12px; }
.percentile-bar { position: relative; height: 8px; background: #DFDFDF; border-radius: 4px; margin: 8px 0; }
.percentile-fill { position: absolute; left: 0; top: 0; height: 100%; border-radius: 4px; transition: width 0.5s ease; }
.percentile-marker { position: absolute; top: -4px; width: 16px; height: 16px; border-radius: 50%; border: 2px solid #FFF; box-shadow: 0 1px 4px rgba(0,0,0,0.3); transform: translateX(-50%); }
.percentile-labels { display: flex; justify-content: space-between; font-size: 0.65rem; color: #B9B9B9; margin-top: 4px; }
.percentile-result { font-size: 0.9rem; color: #231F20; margin-top: 8px; }

/* Raw scores debug */
.raw-scores { margin-top: 1.5rem; padding: 16px; background: #F5F6FA; border-radius: 8px; width: 100%; max-width: 500px; text-align: left; font-size: 0.75rem; color: #5F5F5F; line-height: 1.8; }

/* Intro */
.intro-text { font-size: 1rem; color: #5F5F5F; max-width: 480px; line-height: 1.6; margin-bottom: 2rem; }
@media (max-width: 900px) { .intro-text { font-size: 0.9rem; padding: 0 0.5rem; } }

/* Mobile touch improvements */
@media (max-width: 900px) {
    body { padding-bottom: 60px; }
    .flash-word { font-size: 40px; }
    .word-case { font-size: 16px; }
    .word-case.bold { font-size: 18px; }
    .flash-instructions { font-size: 14px; }
    .factor-value { font-size: 1.5rem; }
    .factor-label { font-size: 0.65rem; }
    .innovation-img { max-height: 200px; }
    .landing-factors-grid { grid-template-columns: 1fr !important; }
}

/* Landing factors grid */
.landing-factors-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 1.5rem; }

/* Landing split layout */
.landing-split { display: flex; min-height: 100dvh; width: 100%; }
.landing-image { flex: 0 0 50%; background: url('assets/Mask group.svg') center/110% auto no-repeat; position: relative; background-color: #F5F6FA; }
.landing-image::after { display: none; }
.landing-content { flex: 0 0 50%; display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 3rem; position: relative; }
@media (max-width: 900px) {
    .landing-split { flex-direction: column; position: relative; min-height: 100dvh; overflow: hidden; }
    .landing-image { display: block; position: absolute; top: 0; left: 0; right: 0; bottom: 0; flex: none; background-size: cover; background-position: center bottom; z-index: 0; background-color: #fff; }
    .landing-image canvas, .landing-image img { height: 60dvh !important; top: calc(50% + 10px) !important; left: calc(55% - 15px) !important; bottom: auto !important; transform: translate(-50%, -40%) !important; }
    #landing-tip-bubble { top: 50px !important; left: 50% !important; transform: translateX(-50%) !important; margin-top: 100px; max-width: 55vw !important; padding: 10px 16px !important; }
    #landing-tip-bubble p { font-size: 0.85rem !important; }
    .landing-content { position: relative; z-index: 3; flex: none; min-height: 100dvh; padding: 50px 1.5rem 0; background: transparent; justify-content: flex-start !important; align-items: center; }
    .landing-content img[alt="BrainHealth Pulse"] { width: 276px !important; margin-bottom: 0 !important; }
    .landing-content .btn { position: absolute; bottom: 80px; left: 50%; transform: translateX(-50%); z-index: 4; }
    .landing-content .copyright { color: #888; position: absolute; bottom: 1.5rem; left: 0; right: 0; z-index: 4; }
    .landing-factors-grid { grid-template-columns: 1fr !important; }
}

/* History Screen */
.history-card { background: #FFF; max-width: 1048px; width: 100%; margin: 0 auto; padding: 2rem; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; text-align: center; min-height: 100dvh; box-sizing: border-box; position: relative; }
@media (min-width: 600px) { .history-card { padding: 2rem; } }
@media (max-width: 599px) { .history-card { padding: 1rem; } }

/* Button focus indicators for accessibility */
.btn:focus { outline: 2px solid #037DBA; outline-offset: 2px; }
.btn-restart:focus { outline: 2px solid #037DBA; outline-offset: 2px; }
.history-btn { background: #037DBA; border: 0; border-radius: 23px; color: #FFF; font-family: 'Nunito Sans', sans-serif; font-weight: 500; font-size: 1rem; min-height: 44px; min-width: 44px; line-height: 19px; padding: 14px 48px; cursor: pointer; text-transform: none; -webkit-tap-highlight-color: transparent; transition: transform 180ms ease-out; }
.history-btn:hover { background: #00689B; }
.history-btn:hover:not(:disabled) { transform: scale(1.02); }
.history-btn:focus { outline: 2px solid #037DBA; outline-offset: 2px; }
.history-btn.outline { background: none; border: 1px solid #DFDFDF; color: #5F5F5F; }
.history-btn.outline:hover { border-color: #037DBA; color: #037DBA; background: none; }
.history-btn.danger { background: #E91E63; }
.history-btn.danger:hover { background: #C2185B; }

.history-single-msg { color: #5F5F5F; font-size: 0.9rem; margin-top: 1rem; line-height: 1.5; }

/* Pulsating score loader */
@keyframes pulse-loading {
    0%, 100% { opacity: 1.0; }
    50% { opacity: 0.3; }
}
.score-pulsing {
    animation: pulse-loading 1.2s ease-in-out infinite;
}

/* Factor card entrance animation */
@keyframes card-enter {
    from {
        opacity: 0;
        transform: translateY(15px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
.factor-card-hidden { opacity: 0; }
.factor-card-animate { animation: card-enter 350ms ease-out forwards; }

/* Percentile bar grow animation */
@keyframes bar-grow {
    from { width: 0%; }
}
@keyframes marker-move {
    from { left: 0%; }
}
.bar-hidden { width: 0% !important; }
.marker-hidden { left: 0% !important; }
.bar-animate { animation: bar-grow 600ms ease-out forwards; }
.marker-animate { animation: marker-move 600ms ease-out forwards; }

/* Elmer Chat Widget */
#elmer-chat-widget {
    position: fixed;
    bottom: 48px;
    right: 24px;
    width: 68px;
    height: 68px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: filter 0.3s ease, opacity 0.3s ease, transform 0.3s ease;
}
#elmer-chat-widget img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transform: scaleX(-1);
}

/* Dormant state (default) */
#elmer-chat-widget.dormant {
    filter: grayscale(100%);
    opacity: 0.5;
    pointer-events: none;
    cursor: not-allowed;
}

/* Active state */
#elmer-chat-widget.active {
    filter: none;
    opacity: 1;
    pointer-events: auto;
    cursor: pointer;
}

/* Activation animation */
@keyframes elmer-widget-activate {
    0% { transform: scale(1); }
    40% { transform: scale(1.25); }
    70% { transform: scale(0.95); }
    100% { transform: scale(1); }
}
#elmer-chat-widget.activate-anim {
    animation: elmer-widget-activate 0.5s ease-out;
}

/* Typing indicator dot animation */
@keyframes elmer-dot-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* Elmer Chat Panel */
#elmer-chat-panel {
    display: none;
    position: fixed;
    bottom: 124px;
    right: 24px;
    width: 340px;
    height: 440px;
    background: #fff;
    border-radius: 20px;
    border: none;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15), 0 2px 8px rgba(0, 0, 0, 0.08);
    z-index: 9998;
    flex-direction: column;
    overflow: hidden;
    font-family: 'DM Sans', sans-serif;
}
#elmer-chat-panel.open {
    display: flex;
    animation: elmer-panel-in 0.25s ease forwards;
}
@keyframes elmer-panel-in {
    from { opacity: 0; transform: translateY(10px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
/* Speech bubble tail */
#elmer-chat-panel::after {
    content: '';
    position: absolute;
    bottom: -8px;
    right: 28px;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 0 0 4px 0;
    transform: rotate(45deg);
    box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.06);
}

/* Chat Panel Header */
.elmer-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: linear-gradient(135deg, #4A90D9 0%, #357ABD 100%);
    border-radius: 20px 20px 0 0;
}
.elmer-chat-header-title {
    font-weight: 700;
    font-size: 1.05rem;
    color: #fff;
}
.elmer-chat-close-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: rgba(255,255,255,0.15);
    font-size: 1.1rem;
    color: #fff;
    cursor: pointer;
    border-radius: 50%;
    transition: background 0.2s ease;
}
.elmer-chat-close-btn:hover {
    background: rgba(255,255,255,0.3);
}

/* Chat Panel Messages Area */
.elmer-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #FAFCFE;
}

/* Chat Panel Input Area */
.elmer-chat-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid #eef2f7;
    background: #fff;
    border-radius: 0 0 20px 20px;
}
.elmer-chat-input-area input[type="text"] {
    flex: 1;
    height: 44px;
    padding: 0 16px;
    border: 1.5px solid #e0e7ef;
    border-radius: 22px;
    font-size: 0.9rem;
    outline: none;
    font-family: 'DM Sans', sans-serif;
    background: #f8fafb;
    transition: border-color 0.2s ease, background 0.2s ease;
}
.elmer-chat-input-area input[type="text"]:focus {
    border-color: #4A90D9;
    background: #fff;
}
.elmer-chat-send-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    border: none;
    background: linear-gradient(135deg, #4A90D9 0%, #357ABD 100%);
    color: #fff;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, box-shadow 0.2s ease, opacity 0.2s ease;
    box-shadow: 0 2px 8px rgba(74, 144, 217, 0.3);
}
.elmer-chat-send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(74, 144, 217, 0.5);
}
.elmer-chat-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Mobile responsiveness for Chat Panel */
@media (max-width: 480px) {
    #elmer-chat-panel {
        width: calc(100vw - 16px);
        right: 8px;
        left: 8px;
        bottom: 8px;
        height: calc(100dvh - 60px);
        border-radius: 20px;
    }
    #elmer-chat-panel::after {
        display: none;
    }
    #elmer-chat-widget {
        bottom: 56px;
        right: 16px;
        width: 56px;
        height: 56px;
    }
}
@media (max-height: 540px) {
    #elmer-chat-panel {
        height: calc(100dvh - 60px);
        bottom: 8px;
    }
}
/* When keyboard is open on mobile (viewport shrinks) */
@media (max-width: 480px) and (max-height: 480px) {
    #elmer-chat-panel {
        height: calc(100dvh - 16px);
        bottom: 8px;
        border-radius: 16px;
    }
}
