@import url('https://fonts.googleapis.com/css2?family=Chakra+Petch:ital,wght@0,600;0,700;0,800;1,700&family=Nunito:wght@400;600;700;800;900&family=Bangers&display=swap');

:root {
    --bg-color: #071527;
    --pattern-img: url('math-pattern-dark.svg');
    --nav-bg: rgba(0, 0, 0, 0.45);
    --nav-btn-bg: rgba(255, 255, 255, 0.12);
    --nav-btn-color: #ffffff;
    --panel-bg: linear-gradient(145deg, #0264b3 0%, #004c8c 100%);
    --panel-shadow: 0 20px 50px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(255, 255, 255, 0.12);
    --hud-bg: rgba(0, 0, 0, 0.35);
    --hud-border: rgba(255, 255, 255, 0.15);
    --input-bg: #ffffff;
    --input-color: #0b1a2d;
    --input-border: #F1C40F;
    --input-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
    --btn-bg: #F1C40F;
    --btn-color: #004c8c;
    --modal-bg: #004c8c;
}

[data-theme="light"] {
    --bg-color: #eef3f8;
    --pattern-img: url('math-pattern-light.svg');
    --nav-bg: rgba(255, 255, 255, 0.75);
    --nav-btn-bg: rgba(0, 76, 140, 0.08);
    --nav-btn-color: #004c8c;
    --panel-bg: linear-gradient(145deg, #0077c8 0%, #005a9c 100%);
    --panel-shadow: 0 20px 50px rgba(0, 50, 110, 0.25), 0 0 0 1px rgba(255, 255, 255, 0.4);
    --hud-bg: rgba(0, 0, 0, 0.2);
    --hud-border: rgba(255, 255, 255, 0.25);
    --input-bg: #ffffff;
    --input-color: #091e36;
    --input-border: #F1C40F;
    --input-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    --btn-bg: #F1C40F;
    --btn-color: #004c8c;
    --modal-bg: #005a9c;
}

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

body {
    font-family: 'Nunito', sans-serif;
    background-color: var(--bg-color);
    background-image: var(--pattern-img);
    background-repeat: repeat;
    background-size: 220px 220px;
    color: #ffffff;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
    padding: 70px 20px 30px 20px;
    transition: background-color 0.3s ease;
}

/* Top Navigation Bar */
.top-nav {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 32px);
    max-width: 580px;
    background: var(--nav-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--hud-border);
    border-radius: 50px;
    padding: 8px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 40;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}

.nav-brand {
    font-family: 'Chakra Petch', 'Bangers', cursive, sans-serif;
    font-weight: 800;
    font-size: 1.5rem;
    letter-spacing: 2px;
    color: #F1C40F;
}

.nav-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-btn {
    background: var(--nav-btn-bg);
    color: var(--nav-btn-color);
    border: 1px solid var(--hud-border);
    border-radius: 50%;
    width: 38px;
    height: 38px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.25s ease;
    outline: none;
    padding: 0;
}

.nav-btn:hover {
    background: #F1C40F;
    color: #004c8c;
    transform: scale(1.1);
}

.svg-icon {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    fill: none;
    transition: stroke 0.2s ease;
}

.btn-icon {
    display: inline-block;
    vertical-align: middle;
    margin-right: 6px;
    margin-top: -2px;
}

/* Main Container */
main {
    width: 100%;
    max-width: 580px;
    margin: auto;
}

/* Arcade Game Panel */
.game-panel {
    background: var(--panel-bg);
    border-radius: 24px;
    box-shadow: var(--panel-shadow);
    padding: 38px 30px;
    text-align: center;
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
}

.title {
    font-family: 'Bangers', cursive, sans-serif;
    letter-spacing: 2.5px;
    font-size: 3.2rem;
    line-height: 1.1;
    color: #ffffff;
    text-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    margin-bottom: 8px;
}

.subtitle {
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.92);
    margin-bottom: 24px;
    line-height: 1.5;
}

.hint-text {
    font-size: 0.88rem;
    color: #F1C40F;
}

/* Menu Screen */
#menu {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 16px 0;
}

.menu-stats {
    background: var(--hud-bg);
    padding: 12px 28px;
    border-radius: 14px;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    border: 1px solid var(--hud-border);
}

/* Top HUD Dashboard */
.hud-dashboard {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.hud-card {
    background: var(--hud-bg);
    border: 1px solid var(--hud-border);
    border-radius: 14px;
    padding: 10px 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: all 0.25s ease;
}

.hud-card.timer-critical {
    background: rgba(220, 38, 38, 0.4) !important;
    border-color: #ef4444 !important;
    animation: pulseCritical 0.8s infinite alternate;
}

@keyframes pulseCritical {
    from { transform: scale(1); }
    to { transform: scale(1.04); }
}

.hud-label {
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 1px;
    color: rgba(255, 255, 255, 0.7);
}

.hud-val {
    font-family: 'Chakra Petch', sans-serif;
    font-weight: 700;
    font-size: 2.1rem;
    letter-spacing: 1px;
    color: #ffffff;
}

.highlight {
    color: #F1C40F !important;
}

/* Progress Bar */
.progress-container {
    width: 100%;
    height: 8px;
    background-color: rgba(0, 0, 0, 0.35);
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 22px;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #F1C40F, #f39c12);
    width: 0%;
    transition: width 0.3s ease;
    border-radius: 8px;
}

/* Large Equation Display with Unambiguous Font */
#question-wrapper {
    margin: 8px 0 18px 0;
}

.math-equation {
    font-family: 'Chakra Petch', sans-serif;
    font-weight: 800;
    font-size: 5rem;
    letter-spacing: 2px;
    color: #ffffff;
    text-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
    display: inline-block;
    padding: 4px 20px;
    border-radius: 16px;
    transition: transform 0.15s ease;
}

/* Form & Input */
form {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.input-label {
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: rgba(255, 255, 255, 0.85);
}

.input-box-wrapper {
    position: relative;
    display: inline-block;
}

input[type="number"] {
    font-family: 'Chakra Petch', sans-serif;
    font-weight: 800;
    width: 230px;
    height: 72px;
    font-size: 2.8rem;
    text-align: center;
    border-radius: 14px;
    border: 3px solid var(--input-border);
    background-color: var(--input-bg);
    color: var(--input-color);
    box-shadow: var(--input-shadow);
    outline: none;
    transition: all 0.2s ease;
    caret-color: #0071C5;
}

input[type="number"]:focus {
    transform: scale(1.03);
    box-shadow: 0 0 25px rgba(241, 196, 15, 0.8);
    border-color: #ffffff;
}

/* Hide Spinners */
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type=number] {
    -moz-appearance: textfield;
}

/* Buttons */
.button {
    background-color: var(--btn-bg);
    color: var(--btn-color);
    font-family: 'Chakra Petch', 'Bangers', cursive, sans-serif;
    font-weight: 800;
    font-size: 1.35rem;
    letter-spacing: 1.5px;
    border-radius: 12px;
    padding: 12px 32px;
    cursor: pointer;
    border: none;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.3);
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.button:hover {
    background-color: #ffffff;
    color: #004c8c;
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

.button:active {
    transform: translateY(1px);
}

.submit-btn {
    padding: 10px 36px;
    font-size: 1.25rem;
    margin-top: 4px;
}

.pulse-btn {
    animation: btnPulse 2s infinite ease-in-out;
}

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

/* Game Over Card */
.game-over-box {
    background: var(--hud-bg);
    border: 2px solid rgba(241, 196, 15, 0.6);
    border-radius: 18px;
    padding: 24px 20px;
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    animation: fadeIn 0.3s ease-out;
}

.game-over-title {
    font-family: 'Bangers', cursive, sans-serif;
    font-size: 2.8rem;
    letter-spacing: 2px;
    color: #ef4444;
}

.game-over-score {
    font-size: 1.5rem;
    font-weight: 700;
}

.record-banner {
    background-color: #F1C40F;
    color: #0b1a2d;
    font-weight: 900;
    padding: 6px 18px;
    border-radius: 20px;
    font-size: 1rem;
    letter-spacing: 1px;
}

/* Animations */
.correct-flash {
    animation: flashGreen 0.25s ease;
}

@keyframes flashGreen {
    0% { transform: scale(1); filter: brightness(1); }
    50% { transform: scale(1.08); color: #4ade80; }
    100% { transform: scale(1); filter: brightness(1); }
}

.shake-error {
    animation: shakeInput 0.3s ease;
}

@keyframes shakeInput {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-8px); }
    40%, 80% { transform: translateX(8px); }
}

/* Modal Overlay & Card */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    z-index: 100;
    animation: fadeIn 0.2s ease;
}

.modal-card {
    background: var(--modal-bg);
    border: 2px solid #F1C40F;
    border-radius: 20px;
    padding: 32px 28px;
    max-width: 480px;
    width: 100%;
    color: #ffffff;
    position: relative;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.85);
}

.modal-close {
    position: absolute;
    top: 14px;
    right: 18px;
    background: transparent;
    border: none;
    color: #ffffff;
    font-size: 2rem;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.modal-close:hover {
    color: #F1C40F;
}

.modal-title {
    font-family: 'Bangers', cursive, sans-serif;
    font-size: 2.2rem;
    letter-spacing: 2px;
    color: #F1C40F;
    margin-bottom: 12px;
}

.modal-desc {
    font-size: 1rem;
    line-height: 1.5;
    margin-bottom: 20px;
    color: rgba(255, 255, 255, 0.95);
}

.modal-section {
    background: rgba(0, 0, 0, 0.25);
    padding: 16px;
    border-radius: 14px;
    margin-bottom: 20px;
    text-align: left;
}

.modal-section h3 {
    font-size: 1.1rem;
    color: #F1C40F;
    margin-bottom: 10px;
}

.modal-section ul {
    list-style-position: inside;
    font-size: 0.92rem;
    line-height: 1.6;
}

.modal-footer {
    font-size: 0.88rem;
    text-align: center;
    color: rgba(255, 255, 255, 0.8);
}

.modal-links {
    margin-top: 6px;
}

.modal-links a {
    color: #F1C40F;
    text-decoration: none;
    font-weight: 700;
}

.modal-links a:hover {
    text-decoration: underline;
}

.form-hidden {
    display: none !important;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.96); }
    to { opacity: 1; transform: scale(1); }
}

/* Mobile Responsiveness */
@media (max-width: 600px) {
    body {
        padding: 60px 14px 20px 14px;
    }

    .game-panel {
        padding: 26px 16px;
    }

    .title {
        font-size: 2.5rem;
    }

    .math-equation {
        font-size: 3.8rem;
    }

    input[type="number"] {
        width: 190px;
        height: 64px;
        font-size: 2.3rem;
    }
}
