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

h1, h2, h3, h4, h5, h6, p, a, span, div, li, ul, ol, button, input, label, cite {
    font-family: 'Alegreya Sans', sans-serif;
    font-weight: 400;
    font-style: normal;
}

.hidden {
    display: none !important;
}

html, body {
    margin: 0;
    background: #24282f;
    color: #ccc;
    min-height: 100vh;
}

/* Main container styles */
.viewport {
    width: 100%;
    display: flex;
    min-height: 100vh;
    background: rgba(36, 40, 47, 0.9);
    padding: 20px;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.wrapper {
    position: relative;
    width: 90%;
    max-width: 800px;
}

#MainMenuContext,
#MentalMathContext {
    position: relative;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    padding: 20px;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #2d3748;
    border-radius: 10px;
}

#MainMenuContext.hidden, 
#MentalMathContext.hidden {
    display: none !important;
}

/* Animations */
.fade-out {
    animation: fadeOut 0.5s ease-out forwards;
}

.fade-in {
    animation: fadeIn 0.5s ease-in forwards;
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Button Groups */
.button-group {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.center {
    justify-content: center;
    text-align: center;
    align-items: center;
}

/* Question Display */
#test-question {
    font-size: 48px;
    text-align: center;
    margin: 20px 0;
    color: #fff;
}

/* Layout Helpers */
.full-width {
    width: 100%;
}

.three-quarter-width {
    width: 75%;
}

.half-width {
    width: 50%;
}

.quarter-width {
    width: 25%;
}

.spacer-10 {
    height: 10px;
}

.spacer-20 {
    height: 20px;
}

/* Citations */
cite {
    display: block;
    font-style: normal;
    font-size: 1em;
    text-align: left;
    padding: 20px;
    background-color: #373d47;
    border-radius: 5px;
    color: #F5F5F5;
    margin: 10px 0;
}

.cite-border-blue {
    border-left: #06a2d4 5px solid;
}

.cite-border-green {
    border-left: #0ad406 5px solid;
}

.cite-border-red {
    border-left: #d40606 5px solid;
}

.bg-white {
    background-color: #fff;
    color: #000;
}

/* Lists */
ul {
    text-align: left;
    line-height: 1.8;
    padding-left: 20px;
}

/* Calculator Animation */
.calculator-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 10px;
    padding: 20px;
    width: 300px;
}

.calculator-animation {
    font-size: 3rem;
    font-weight: bold;
    color: gray;
    display: flex;
    gap: 1rem;
}

.AnimationNumber, .AnimationOperator, .AnimationEqual-sign, .AnimationResult {
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
}

.appear {
    opacity: 1;
}

.slide-in {
    animation: slide-in 0.5s ease forwards;
}

@keyframes slide-in {
    0% {
        transform: translateX(-100%);
        opacity: 0;
    }
    100% {
        transform: translateX(0);
        opacity: 1;
    }
}

.shake-in {
    animation: shake-in 0.5s ease forwards;
}

@keyframes shake-in {
    0%, 100% { transform: translateX(0); opacity: 1; }
    25% { transform: translateX(-10px); }
    50% { transform: translateX(10px); }
    75% { transform: translateX(-10px); }
}

.fall-in {
    animation: fall-in 0.5s ease forwards;
}

@keyframes fall-in {
    0% {
        transform: translateY(-50%);
        opacity: 0;
    }
    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

.twist-in {
    animation: twist-in 0.5s ease forwards;
}

@keyframes twist-in {
    0% {
        transform: rotateY(90deg);
        opacity: 0;
    }
    100% {
        transform: rotateY(0);
        opacity: 1;
    }
}

/* Buttons */
button {
    padding: 10px 20px;
    border: none;
    cursor: pointer;
    border-radius: 8px;
    font-size: 16px;
    transition: all 0.3s ease;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.btn-type-2 {
    background: linear-gradient(135deg, #3f4a7e 0%, #261636 100%);
    color: white;
    padding: 15px 30px;
    font-weight: bold;
    min-width: 200px;
}

.btn-outline {
    background: linear-gradient(135deg, #3f4a7e 0%, #261636 100%);
    color: white;
}

.btn-outline-secondary {
    background: #4a5568;
    color: white;
}

#home_mentalmath {
    background-color: #28a745;
    color: white;
    position: absolute;
    top: 20px;
    left: 20px;
}

/* Input Field */
#mentalMathUserInput {
    padding: 15px;
    margin: 10px 0;
    font-size: 30px;
    height: 50px;
    text-align: center;
    border: 2px solid #667eea;
    border-radius: 8px;
    background: #1a202c;
    color: white;
    width: 300px;
}

#mentalMathUserInput:focus {
    outline: none;
    border-color: #764ba2;
    box-shadow: 0 0 15px rgba(102, 126, 234, 0.5);
}

#UsernameInput {
    padding: 15px;
    margin: 10px 0;
    font-size: 30px;
    height: 50px;
    text-align: center;
    border: 2px solid #667eea;
    border-radius: 8px;
    background: #1a202c;
    color: white;
    width: 300px;
}

#usernameSaveBtn {
    width: 200px;
}

#UsernameInput:focus {
    outline: none;
    border-color: #764ba2;
    box-shadow: 0 0 15px rgba(102, 126, 234, 0.5);
}

.input-hint {
    color: #a0aec0;
    font-size: 14px;
}

kbd {
    background-color: #f8f9fa;
    color: #373d47;
    border-radius: 5px;
    padding: 5px 10px;
    margin: 0 5px;
    font-family: monospace;
}

.textShortcut {
    font-size: 1.3em;
    color: #FFFFFF;
}

#mentalMathUserInput:focus ~ .textShortcut {
    animation: shortcutKey 1s infinite;
}

@keyframes shortcutKey {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.06); }
}

/* Answer Validation Animations */
.wrongAnswerInputed {
    animation: onWrongAnswer 0.5s forwards;
}

.correctAnswerInputed {
    animation: onCorrectAnswer 0.5s forwards;
}

.emptyInputed {
    animation: onEmptyAnswer 0.5s forwards;
}

.shake-fade-in {
    animation: shaked-Fade-In 0.5s forwards;
}

@keyframes onEmptyAnswer {
    0%, 100% {
        border-color: #667eea;
        box-shadow: #ffc107 0 0 0;
    }
    25%, 75% {
        border-color: #ffc107;
        box-shadow: #ffc107 0 0 30px;
    }
}

@keyframes onCorrectAnswer {
    0%, 100% {
        border-color: #667eea;
        box-shadow: #0ad406 0 0 0;
    }
    25%, 75% {
        border-color: #28a745;
        box-shadow: #0ad406 0 0 30px;
    }
}

@keyframes onWrongAnswer {
    0%, 100% {
        border-color: #667eea;
        box-shadow: #dc3545 0 0 0;
    }
    25%, 75% {
        border-color: #dc3545;
        box-shadow: #dc3545 0 0 30px;
    }
}

@keyframes shaked-Fade-In {
    0% { transform: translateX(-10px); opacity: 0; }
    25% { transform: translateX(10px); opacity: 1; }
    50% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
    100% { transform: translateX(0); opacity: 1; }
}

/* Modals */
.Modal-type-1 {
    display: block;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: rgba(0, 0, 0, 0.6);
}

.Modal-content {
    background-color: #24282f;
    margin: 10% auto;
    padding: 40px;
    border-radius: 10px;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    max-width: 600px;
    width: 900%;
}

.Modal-content h1 {
    color: #fff;
}

.ModalAppear {
    animation: ModalAppearAnim 0.4s forwards;
}

.ModalDisappear {
    animation: ModalDisappearAnim 0.4s forwards;
}

@keyframes ModalAppearAnim {
    0% {
        opacity: 0;
        transform: scale(0.4);
    }
    30% {
        opacity: 0.8;
        transform: scale(1.1);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes ModalDisappearAnim {
    0% {
        opacity: 1;
        transform: scale(1);
    }
    100% {
        opacity: 0;
        transform: scale(0.5);
    }
}

/* Timer */
.circle-timer-container {
    position: absolute;
    right: 10px;
    top: 10px;
    font-size: 2.5rem;
}

.progress-circle {
    position: relative;
    transform: rotate(-90deg);
}

.background-circle {
    fill: none;
    stroke: #282c34;
    stroke-width: 4;
}

.foreground-circle {
    fill: none;
    stroke: white;
    stroke-width: 4;
    stroke-dasharray: 283;
    stroke-dashoffset: 0;
    animation: countdown 30s linear forwards;
}

.timer-text {
    position: absolute;
    font-size: 1.4em;
    color: white;
    z-index: 1;
    top: 0px;
    text-align: center;
    width: 100%;
}

@keyframes countdown {
    from { stroke-dashoffset: 0; }
    to { stroke-dashoffset: 283; }
}

/* Settings Panel */
.settings-cogwheel {
    position: absolute;
    right: 20px;
    top: 20px;
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    transition: all 0.3s ease;
    z-index: 999;
    color: white;
}

.settings-cogwheel:hover {
    transform: rotate(90deg) scale(1.1);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

.settings-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.settings-overlay.show {
    opacity: 1;
}

.settings-panel {
    position: fixed;
    top: 0;
    right: -400px;
    width: 400px;
    height: 100%;
    background-color: #2d3748;
    color: #ffffff;
    box-shadow: -5px 0 15px rgba(0, 0, 0, 0.3);
    z-index: 1001;
    overflow-y: auto;
    transition: right 0.3s ease;
}

.settings-panel.show {
    right: 0;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background-color: #1a202c;
    border-bottom: 2px solid #4a5568;
}

.settings-header h2 {
    margin: 0;
    font-size: 24px;
    font-weight: bold;
}

.settings-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
}

.settings-close:hover {
    transform: scale(1.2);
    color: #f56565;
}

.settings-content {
    padding: 20px;
}

.settings-section {
    margin-bottom: 30px;
}

.settings-section h3 {
    font-size: 18px;
    margin-bottom: 15px;
    color: #a0aec0;
    border-bottom: 1px solid #4a5568;
    padding-bottom: 8px;
}

.toggle-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.toggle-item {
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 10px;
    background-color: #1a202c;
    border-radius: 8px;
    transition: background-color 0.2s ease;
}

.toggle-item:hover {
    background-color: #2d3748;
}

.toggle-item input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin-right: 12px;
    cursor: pointer;
    accent-color: #667eea;
}

.toggle-label {
    font-size: 16px;
    user-select: none;
}

.number-setting {
    margin: 15px 0;
    padding: 15px;
    background-color: #1a202c;
    border-radius: 8px;
}

.number-setting label {
    display: block;
    margin-bottom: 10px;
    font-weight: 600;
    color: #e2e8f0;
}

.number-control {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

.btn-control {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-control:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.number-value {
    font-size: 28px;
    font-weight: bold;
    min-width: 50px;
    text-align: center;
    color: #667eea;
}

.hint {
    display: block;
    margin-top: 8px;
    font-size: 12px;
    color: #a0aec0;
    text-align: center;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px 30px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
}

/* Loading Spinner */
.spinner {
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

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

/* Responsive Design */
@media (max-width: 768px) {
    .wrapper {
        width: 95%;
    }
    
    .settings-panel {
        width: 100%;
        right: -100%;
    }
    
    .calculator-animation {
        font-size: 2rem;
    }
    
    .button-group {
        flex-direction: column;
        width: 100%;
    }
    
    .btn-type-2 {
        width: 100%;
    }
    
    .three-quarter-width {
        width: 95%;
    }
}

/* BUTTON PACK .css */
.btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    padding: 0.75rem 1.5rem;
    border-radius: 0.375rem;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.3s ease;
    cursor: pointer;
    border: 2px solid transparent;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.btn:hover {
    transform: translateY(-2px);
}

.btn-primary {
    background-color: #6366f1;
    color: white;
}
.btn-primary:hover {
    background-color: #4f46e5;
}

.btn-secondary {
    background-color: #3b82f6;
    color: white;
}
.btn-secondary:hover {
    background-color: #2563eb;
}

.btn-success {
    background-color: #10b981;
    color: white;
}
.btn-success:hover {
    background-color: #059669;
}

.btn-warning {
    background-color: #f59e0b;
    color: white;
}
.btn-warning:hover {
    background-color: #d97706;
}

.btn-danger {
    background-color: #ef4444;
    color: white;
}
.btn-danger:hover {
    background-color: #dc2626;
}

.btn-outline {
    background-color: transparent;
    border: 2px solid #3b82f6;
    color: #3b82f6;
}
.btn-outline:hover {
    background-color: #3b82f6;
    color: white;
}

.btn-outline-secondary {
    background-color: transparent;
    border: 2px solid #6366f1;
    color: #6366f1;
}
.btn-outline-secondary:hover {
    background-color: #6366f1;
    color: white;
}

/* Luxury color scheme */
.btn-outline-premium {
    background-color: transparent;
    border: 2px solid #f59e0b;
    color: #f59e0b;
}

.btn-outline-premium:hover {
    background-color: #3b82f6;
    border: 2px solid #3b82f6;
    color: white;
}

.btn-gradient {
    background: linear-gradient(90deg, #34d399, #3b82f6);
    color: white;
}
.btn-gradient:hover {
    background: linear-gradient(90deg, #10b981, #2563eb);
}

.btn-soft {
    background-color: #e5e7eb;
    color: #374151;
}
.btn-soft:hover {
    background-color: #d1d5db;
}

.btn-pill {
    background-color: #f472b6;
    color: white;
    border-radius: 9999px;
}
.btn-pill:hover {
    background-color: #ec4899;
}

/* Utility Classes */
.text-center {
    text-align: center;
}

.mt-8 {
    margin-top: 2rem;
}

.grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}




.fill:hover,
.fill:focus {
    box-shadow: inset 0 0 0 4em var(--hover);
}

.fill-white:hover,
.fill-white:focus {
    box-shadow: inset 0 0 0 4em var(--hover);
}

.pulse:hover,
.pulse:focus {
    -webkit-animation: pulse 1s;
    animation: pulse 1s;
    box-shadow: 0 0 0 2em transparent;
}

.pulse-infinite:hover,
.pulse-infinite:focus {
    -webkit-animation: pulse 1s infinite;
    animation: pulse 1s infinite;
    box-shadow: 0 0 0 2em transparent;
}

@-webkit-keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 var(--hover);
    }
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 var(--hover);
    }
}
.close:hover,
.close:focus {
    box-shadow: inset -3.5em 0 0 0 var(--hover), inset 3.5em 0 0 0 var(--hover);
}

.raise:hover,
.raise:focus {
    box-shadow: 0 0.5em 0.5em -0.4em var(--hover);
    transform: translateY(-0.25em);
}

.up:hover,
.up:focus {
    box-shadow: inset 0 -3.25em 0 0 var(--hover);
}

.slide:hover,
.slide:focus {
    box-shadow: inset 6.5em 0 0 0 var(--hover);
}

.offset {
    box-shadow: 0.3em 0.3em 0 0 var(--color), inset 0.3em 0.3em 0 0 var(--color);
}
.offset:hover, .offset:focus {
    box-shadow: 0 0 0 0 var(--hover), inset 6em 3.5em 0 0 var(--hover);
}

.offset-reverse {
    box-shadow: 0 0 0 0 var(--hover), inset 6em 3.5em 0 0 var(--hover);
}

.offset-reverse:hover, .offset-reverse:focus {
    box-shadow: 0.3em 0.3em 0 0 var(--color), inset 0.3em 0.3em 0 0 var(--color);
}

.fill {
    --color: #a972cb;
    --hover: #cb72aa;
}

.fill-white {
    --color: #fff;
    --hover: #1973bc;
}

.pulse {
    --color: #ef6eae;
    --hover: #ef8f6e;
}

.pulse-infinite {
    --color: #ef6eae;
    --hover: #ef8f6e;
}

.close {
    --color: #ff7f82;
    --hover: #ffdc7f;
}

.raise {
    --color: #ffa260;
    --hover: #e5ff60;
}

.up {
    --color: #e4cb58;
    --hover: #94e458;
}

.slide {
    --color: #8fc866;
    --hover: #66c887;
}

.offset {
    --color: #19bc8b;
    --hover: #1973bc;
}

.offset-reverse {
    --color: #19bc8b;
    --hover: #1973bc;
}

.btn-type-2 {
    color: var(--color);
    transition: 0.25s;
}

.btn-type-2:hover, .btn-type-2:focus {
    border-color: var(--hover);
    color: #fff;
}

.btn-type-2 {
    background: none;
    border: 2px solid;
    font: inherit;
    line-height: 1;
    margin: 0.5em;
    padding: 1em 2em;
}

code {
    color: #e4cb58;
    font: inherit;
}


/* === MOBILE RESPONSIVE FIXES (<= 480px) === */
@media (max-width: 820px) {

    .wrapper {
        width: 100%;
        padding: 0 8px;
    }

    #MainMenuContext,
    #MentalMathContext {
        padding: 15px;
        border-radius: 8px;
    }

    /* Question text */
    #test-question {
        line-height: 1.2;
        margin: 15px 0;
    }

    /* Input field */
    #mentalMathUserInput {
        font-size: 22px;
        width: 100%;
        max-width: none;
        height: 48px;
    }

    /* Prevent animation text from being oversized */
    .calculator-animation {
        font-size: 1.7rem;
        gap: 0.5rem;
    }

    /* Button groups become full width */
    .button-group {
        flex-direction: column;
        gap: 12px;
        width: 100%;
    }

    .btn-type-2,
    .btn,
    button {
        width: 100%;
        min-width: 0 !important;
        padding: 12px;
        font-size: 16px;
    }

    /* Prevent overflow of layout helpers */
    .three-quarter-width,
    .half-width,
    .quarter-width {
        width: 100%;
    }


    /* Modal responsiveness */
    .Modal-content {
        width: 90% !important;
        padding: 20px !important;
        margin: 30% auto !important;
        max-width: none !important;
    }

    /* Settings cogwheel smaller + reposition */
    .settings-cogwheel {
        width: 42px;
        height: 42px;
        top: 15px;
        right: 15px;
    }

    /* Settings panel becomes full width */
    .settings-panel {
        width: 100% !important;
        right: -100% !important;
    }

    /* Slightly reduce animation exaggeration */
    .AnimationNumber,
    .AnimationOperator,
    .AnimationEqual-sign,
    .AnimationResult {
        transition: opacity 0.35s ease-in-out;
    }

    #home_mentalmath {
        position: relative;
        top: 0;
        left: 0;
    }

    .circle-timer-container {
        position: relative;
        top: 0;
        right: 0;
        transform: scale(1);
    }

    .timer-text {
        position: fixed;
        top: 10px;
        left: 30px;
        font-size: 1.2em;
    }
}
