﻿/* =========================================
   Memory Math Challenge & Abacus Stylesheet
   ========================================= */

.memory-math-page {
    width: 100%;
    padding: 20px 10px 40px;
    box-sizing: border-box;
}

.memory-math-container {
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
}

/* Screen Toggle Utility Class */
.memory-math-hidden {
    display: none !important;
}

/* =========================================
   Header Section
   ========================================= */

.memory-math-header {
    text-align: center;
    margin-bottom: 15px;
}

.memory-math-icon {
    font-size: 26px;
    margin-bottom: 6px;
}

.memory-math-header h1 {
    margin: 0 0 8px;
    color: #1a252c;
    font-size: 24px;
    font-weight: 800;
    line-height: 1.2;
}

.memory-math-header p {
    max-width: 600px;
    margin: 0 auto;
    color: #556068;
    font-size: 14px;
    line-height: 1.5;
}

/* =========================================
   1. Setup Screen
   ========================================= */

.memory-math-setup {
    max-width: 550px;
    margin: 0 auto;
    padding: 15px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
}

    .memory-math-setup h2 {
        margin: 0 0 20px;
        text-align: center;
        color: #065fd0;
        font-size: 22px;
        font-weight: 700;
    }

.math-form-group {
    margin-bottom: 10px;
}

    .math-form-group label {
        display: block;
        margin-bottom: 6px;
        color: #222;
        font-size: 14px;
        font-weight: 700;
    }

    .math-form-group select {
        width: 100%;
        min-height: 42px;
        padding: 8px 12px;
        border: 1px solid #cbd5e1;
        border-radius: 8px;
        background: #ffffff;
        color: #1e293b;
        font-size: 14px;
        outline: none;
        cursor: pointer;
        transition: border-color 0.15s ease, box-shadow 0.15s ease;
    }

        .math-form-group select:focus {
            border-color: #065fd0;
            box-shadow: 0 0 0 3px rgba(6, 95, 208, 0.15);
        }

    .math-form-group small {
        display: block;
        margin-top: 5px;
        color: #64748b;
        font-size: 12px;
        line-height: 1.4;
    }

    .math-form-group input[type="checkbox"] {
        width: 16px;
        height: 16px;
        margin-right: 8px;
        accent-color: #065fd0;
        cursor: pointer;
        vertical-align: middle;
    }

/* =========================================
   Buttons
   ========================================= */

.math-start-button {
    display: block;
    width: 100%;
    max-width: 280px;
    min-height: 46px;
    margin: 24px auto 0;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    background: #065fd0;
    color: #ffffff;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

    .math-start-button:hover {
        background: #044da8;
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(6, 95, 208, 0.25);
    }

    .math-start-button:active {
        transform: translateY(0);
    }

.math-end-button {
    display: block;
    margin: 20px auto 0;
    padding: 8px 18px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #ffffff;
    color: #475569;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

    .math-end-button:hover {
        background: #f1f5f9;
        color: #0f172a;
    }

/* =========================================
   2. Game Screen & Parallel Layout
   ========================================= */

.memory-math-game {
    width: 100%;
}

/* Grid layout: Abacus & Math Display side-by-side on desktop */
.math-game-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    align-items: center;
    background: #ffffff;
    padding: 15px;
    border-radius: 14px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
}

.math-display-area {
    text-align: center;
    padding: 10px;
}

.math-level {
    color: #065fd0;
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 12px;
}

.math-display {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 160px;
    font-size: 50px;
    font-weight: 800;
    color: #0f172a;
}

.math-progress {
    margin-top: 8px;
    color: #ce434b;
    font-size: 15px;
    font-weight: 600;
}

/* =========================================
   Abacus Visual Helper Component
   ========================================= */

.memory-abacus {
    width: 100%;
    padding: 18px;
    border-radius: 12px;
    background: #f8fafc;
    border: 2px solid #e2e8f0;
    box-sizing: border-box;
}

.abacus-frame {
    position: relative;
    width: 100%;
    padding: 16px 14px;
    border-radius: 10px;
    box-sizing: border-box;
    background: #1e293b;
    border: 4px solid #0f172a;
}

.abacus-row {
    position: relative;
    height: 44px;
    margin: 8px 0;
    display: flex;
    align-items: center;
}

.abacus-rod {
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 5px;
    transform: translateY(-50%);
    background: #64748b;
    border-radius: 4px;
    z-index: 1;
}

.abacus-beads {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 5px;
    z-index: 2;
    padding-right: 35px; /* Reserve space for digit label */
    box-sizing: border-box;
}

.abacus-bead {
    width: 26px;
    height: 26px;
    flex: 0 0 26px;
    border-radius: 50%;
    background: #475569;
    border: 2px solid #334155;
    box-sizing: border-box;
    transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

    .abacus-bead.active {
        background: #0284c7;
        border-color: #38bdf8;
        transform: translateY(-1px);
        box-shadow: 0 0 8px rgba(56, 189, 248, 0.4);
    }

.abacus-digit {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 15px;
    font-weight: 800;
    color: #f8fafc;
    z-index: 3;
}

.abacus-hint {
    margin-top: 10px;
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
}

/* =========================================
   3. Answer Screen
   ========================================= */

.memory-math-answer {
    max-width: 550px;
    margin: 0 auto;
    text-align: center;
    padding: 24px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
}

    .memory-math-answer h2 {
        margin: 0 0 20px;
        color: #0f172a;
        font-size: 22px;
        font-weight: 700;
    }

.answer-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.answer-option {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 56px;
    padding: 8px 16px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #ffffff;
    color: #0f172a;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

    .answer-option:hover {
        transform: translateY(-1px);
        border-color: #065fd0;
        box-shadow: 0 3px 10px rgba(6, 95, 208, 0.12);
    }

    .answer-option span {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 30px;
        height: 30px;
        flex-shrink: 0;
        border-radius: 50%;
        background: #f1f5f9;
        color: #065fd0;
        font-size: 14px;
        font-weight: 800;
    }

#resultMessage {
    margin-top: 18px;
    font-size: 16px;
    font-weight: 700;
}

/* =========================================
   Mobile Optimization (Stacked Layout)
   ========================================= */

@media (max-width: 680px) {
    .math-game-layout {
        grid-template-columns: 1fr; /* Stacked layout */
        gap: 10px;
        padding: 16px;
    }

    .memory-abacus {
        order: 1; /* Abacus on Top */
        padding: 12px;
    }

    .math-display-area {
        order: 2; /* Math Display Below */
    }

    .math-display {
        min-height: 60px;
        font-size: 40px;
    }

    .abacus-bead {
        width: 20px;
        height: 20px;
        flex: 0 0 20px;
    }

    .abacus-beads {
        gap: 3px;
    }

    .answer-options {
        grid-template-columns: 1fr;
    }
}
/* =========================================
   BlueGrammar Abacus Theme
   ========================================= */
.memory-abacus {
    width: 100%;
    max-width: 320px;
    margin: 0 auto;
    padding: 16px;
    background: #ddf1fe;
    border: 2px solid #f7d8da;
    border-radius: 16px;
    box-shadow: 0 8px 24px rgba(6, 95, 208, 0.08);
}

.abacus-title {
    font-size: 13px;
    font-weight: 700;
    color: #065fd0;
    text-align: center;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.abacus-frame {
    position: relative;
    background: #ffffff;
    border: 4px solid #f7d8da;
    border-radius: 12px;
    padding: 24px 12px 16px;
    box-shadow: inset 0 0 8px rgba(6, 95, 208, 0.05);
}

/* Horizontal Reckoning Bar */
.reckoning-bar {
    position: absolute;
    top: 85px;
    left: 0;
    right: 0;
    height: 8px;
    background: #065fd0;
    border-top: 1px solid #0448a0;
    border-bottom: 1px solid #0448a0;
    z-index: 3;
}

.abacus-columns {
    display: flex;
    justify-content: space-around;
    position: relative;
    z-index: 2;
}

.abacus-col {
    position: relative;
    width: 60px;
    height: 220px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.col-label {
    position: absolute;
    top: -20px;
    font-size: 11px;
    font-weight: 700;
    color: #065fd0;
}

/* Vertical Rod */
.rod {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 4px;
    background: #b3d8f8;
    z-index: 1;
}

/* Upper Deck (Heaven) */
.heaven-deck {
    position: absolute;
    top: 0;
    height: 50px;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    z-index: 2;
}

/* Lower Deck (Earth) */
.earth-deck {
    position: absolute;
    top: 60px;
    bottom: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    gap: 4px;
    z-index: 2;
}

/* Strict Shared Bead Dimensions */
.abacus-bead {
    box-sizing: border-box !important;
    width: 38px !important;
    height: 20px !important;
    min-width: 38px !important;
    min-height: 20px !important;
    max-width: 38px !important;
    max-height: 20px !important;
    border-radius: 10px;
    box-shadow: inset 0 2px 2px rgba(255, 255, 255, 0.4), 0 2px 4px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    margin: 0 auto;
    flex-shrink: 0;
}

    /* Heaven Beads (Red) */
    .abacus-bead.heaven {
        background: linear-gradient(180deg, #e5535b 0%, #ce434b 100%);
        border: 1px solid #b0343b;
    }

    /* Earth Beads (Blue) */
    .abacus-bead.earth {
        background: linear-gradient(180deg, #1d74e8 0%, #065fd0 100%);
        border: 1px solid #0448a0;
    }

    /* Movement Logic towards the Reckoning Bar */
    .abacus-bead.heaven.active {
        transform: translateY(35px);
    }

    .abacus-bead.earth.active {
        transform: translateY(-45px);
    }