/* ========================================
   MULTIPLICATION TABLE - STYLES
   A fun, playful learning experience
======================================== */

:root {
    /* Vibrant candy-inspired palette */
    --bg-gradient-1: #667eea;
    --bg-gradient-2: #764ba2;
    --bg-gradient-3: #f093fb;
    
    --card-bg: rgba(255, 255, 255, 0.95);
    --card-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    
    --primary: #6c5ce7;
    --primary-dark: #5b4cdb;
    --secondary: #00cec9;
    --accent: #fd79a8;
    --success: #00b894;
    --error: #ff7675;
    --warning: #fdcb6e;
    
    --text-primary: #2d3436;
    --text-secondary: #636e72;
    --text-light: #ffffff;
    
    --number-gradient-1: #f093fb;
    --number-gradient-2: #f5576c;
    
    /* Spacing */
    --space-xs: 0.5rem;
    --space-sm: 0.9rem;
    --space-md: 1.4rem;
    --space-lg: 2rem;
    --space-xl: 2.8rem;
    
    /* Border radius */
    --radius-sm: 12px;
    --radius-md: 20px;
    --radius-lg: 30px;
    --radius-full: 50%;
    
    /* Transitions */
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s ease;
    --transition-slow: 0.5s ease;
}

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

html, body {
    min-height: 100%;
    overflow-y: auto;
}

body {
    font-family: 'Rubik', -apple-system, BlinkMacSystemFont, sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-1) 0%, var(--bg-gradient-2) 50%, var(--bg-gradient-3) 100%);
    background-size: 400% 400%;
    animation: gradientShift 15s ease infinite;
    color: var(--text-primary);
    direction: rtl;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: var(--space-sm) 0;
}

@keyframes gradientShift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

/* ========================================
   ANIMATED BACKGROUND
======================================== */

.bg-animation {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    pointer-events: none;
    z-index: 0;
}

.floating-shape {
    position: absolute;
    font-size: 3rem;
    opacity: 0.15;
    animation: float 20s infinite;
    color: white;
}

.shape-1 { top: 10%; left: 10%; animation-delay: 0s; animation-duration: 25s; }
.shape-2 { top: 20%; right: 15%; animation-delay: -5s; animation-duration: 22s; }
.shape-3 { top: 60%; left: 5%; animation-delay: -10s; animation-duration: 28s; }
.shape-4 { top: 80%; right: 10%; animation-delay: -15s; animation-duration: 24s; }
.shape-5 { top: 5%; left: 50%; animation-delay: -2s; animation-duration: 20s; }
.shape-6 { top: 45%; right: 5%; animation-delay: -8s; animation-duration: 26s; }
.shape-7 { top: 75%; left: 40%; animation-delay: -12s; animation-duration: 23s; }
.shape-8 { top: 35%; left: 80%; animation-delay: -18s; animation-duration: 27s; }

@keyframes float {
    0%, 100% {
        transform: translateY(0) rotate(0deg) scale(1);
    }
    25% {
        transform: translateY(-30px) rotate(10deg) scale(1.1);
    }
    50% {
        transform: translateY(-15px) rotate(-5deg) scale(0.95);
    }
    75% {
        transform: translateY(-25px) rotate(5deg) scale(1.05);
    }
}

/* ========================================
   CONFETTI
======================================== */

#confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    overflow: hidden;
}

.confetti {
    position: absolute;
    width: 12px;
    height: 12px;
    opacity: 0;
    animation: confettiFall 3s ease-out forwards;
}

@keyframes confettiFall {
    0% {
        opacity: 1;
        transform: translateY(-20px) rotate(0deg) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateY(100vh) rotate(720deg) scale(0.5);
    }
}

/* ========================================
   MAIN CONTAINER
======================================== */

.container {
    position: relative;
    z-index: 10;
    width: 100%;
    max-width: 480px;
    padding: var(--space-md);
}

/* ========================================
   SCREENS
======================================== */

.screen {
    display: none;
    animation: fadeIn 0.5s ease;
}

.screen.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========================================
   WELCOME SCREEN
======================================== */

.welcome-content {
    text-align: center;
    background: var(--card-bg);
    padding: var(--space-xl);
    border-radius: var(--radius-lg);
    box-shadow: var(--card-shadow);
}

.mascot {
    margin-bottom: var(--space-md);
    animation: bounce 2s infinite;
}

.mascot img {
    max-width: 220px;
    max-height: 28vh;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-15px); }
}

.welcome-title {
    font-size: 2.4rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: var(--space-xs);
}

.welcome-subtitle {
    font-size: 1.7rem;
    font-weight: 700;
    color: var(--secondary);
    margin-bottom: var(--space-sm);
    animation: pulse 2s infinite;
}

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

.welcome-text {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-lg);
}

/* ========================================
   BUTTONS
======================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 700;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-normal);
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    transition: left 0.5s;
}

.btn:hover::before {
    left: 100%;
}

.btn-start {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: var(--text-light);
    box-shadow: 0 10px 30px rgba(108, 92, 231, 0.4);
}

.btn-start:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 15px 40px rgba(108, 92, 231, 0.5);
}

.btn-start:active {
    transform: translateY(0) scale(0.98);
}

.btn-submit {
    background: linear-gradient(135deg, var(--success), #00a884);
    color: var(--text-light);
    box-shadow: 0 8px 25px rgba(0, 184, 148, 0.4);
    padding: var(--space-sm) var(--space-md);
    flex-shrink: 0;
    white-space: nowrap;
    font-size: 1.1rem;
}

.btn-submit:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 30px rgba(0, 184, 148, 0.5);
}

.btn-submit:active {
    transform: translateY(0);
}

.btn-emoji {
    font-size: 1.1rem;
}

/* ========================================
   SOUND TOGGLE
======================================== */

.sound-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
}

.toggle-label {
    font-size: 1rem;
    font-weight: 600;
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-btn {
    display: flex;
    background: var(--card-bg);
    border: none;
    border-radius: var(--radius-md);
    padding: 4px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    transition: all var(--transition-fast);
}

.toggle-btn:hover {
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.toggle-option {
    padding: var(--space-xs) var(--space-sm);
    border-radius: calc(var(--radius-md) - 4px);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.toggle-option.active {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: white;
    box-shadow: 0 2px 8px rgba(108, 92, 231, 0.4);
}

/* ========================================
   STATS BAR
======================================== */

.stats-bar {
    display: flex;
    justify-content: space-around;
    background: var(--card-bg);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-sm);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.stat-icon {
    font-size: 1.2rem;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.stat-value {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--primary);
}

/* ========================================
   QUESTION CARD
======================================== */

.question-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: var(--space-md);
    box-shadow: var(--card-shadow);
    transition: all var(--transition-normal);
}

.question-card.shake {
    animation: shake 0.5s ease;
}

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

.question-card.celebrate {
    animation: celebrate 0.6s ease;
}

@keyframes celebrate {
    0% { transform: scale(1); }
    25% { transform: scale(1.02); }
    50% { transform: scale(0.98); }
    75% { transform: scale(1.01); }
    100% { transform: scale(1); }
}

.question-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
}

.question-emoji {
    font-size: 1.1rem;
    animation: wiggle 3s infinite;
}

@keyframes wiggle {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-10deg); }
    75% { transform: rotate(10deg); }
}

.question-equation {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    font-size: 2.8rem;
    direction: ltr;
    font-weight: 800;
    margin-bottom: var(--space-md);
    flex-wrap: wrap;
}

.question-equation .number {
    background: linear-gradient(135deg, var(--number-gradient-1), var(--number-gradient-2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    min-width: 40px;
    text-align: center;
}

.question-equation .operator,
.question-equation .equals {
    color: var(--primary);
}

.question-equation .question-mark {
    color: var(--accent);
    animation: pulse 1.5s infinite;
}

/* ========================================
   ANSWER SECTION
======================================== */

.answer-section {
    display: flex;
    gap: var(--space-xs);
    margin-bottom: var(--space-sm);
    width: 100%;
}

.answer-input {
    flex: 1;
    min-width: 0;
    padding: var(--space-xs) var(--space-sm);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 700;
    text-align: center;
    border: 3px solid #e0e0e0;
    border-radius: var(--radius-md);
    outline: none;
    transition: all var(--transition-fast);
    background: #f8f9fa;
}

.answer-input:focus {
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 4px rgba(108, 92, 231, 0.2);
}

.answer-input.correct {
    border-color: var(--success);
    background: rgba(0, 184, 148, 0.1);
}

.answer-input.wrong {
    border-color: var(--error);
    background: rgba(255, 118, 117, 0.1);
    animation: inputShake 0.4s ease;
}

@keyframes inputShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* Hide number input spinners */
.answer-input::-webkit-outer-spin-button,
.answer-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

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

/* ========================================
   FEEDBACK
======================================== */

.feedback {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    padding: var(--space-sm);
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 700;
    animation: slideUp 0.3s ease;
}

.feedback.hidden {
    display: none;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.feedback.success {
    background: linear-gradient(135deg, rgba(0, 184, 148, 0.15), rgba(0, 184, 148, 0.25));
    color: var(--success);
}

.feedback.error {
    background: linear-gradient(135deg, rgba(255, 118, 117, 0.15), rgba(255, 118, 117, 0.25));
    color: var(--error);
}

.feedback-emoji {
    font-size: 1.4rem;
}

/* ========================================
   NUMBER PAD
======================================== */

.number-pad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    margin-top: var(--space-sm);
    direction: ltr; /* Keep standard numpad layout in RTL pages */
}

.num-btn {
    padding: 0.7rem;
    font-family: inherit;
    font-size: 1.3rem;
    font-weight: 700;
    background: var(--card-bg);
    touch-action: manipulation; /* Disable 300ms touch delay */
    -webkit-tap-highlight-color: transparent; /* Remove tap highlight */
    user-select: none; /* Prevent text selection */
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.num-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
}

.num-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.num-btn-wide {
    grid-column: span 2;
}

.num-btn.num-btn-submit {
    background: linear-gradient(135deg, var(--success), #00b894) !important;
    color: white;
}

.num-btn.num-btn-submit:hover {
    background: linear-gradient(135deg, #55efc4, var(--success)) !important;
}

.num-btn.num-btn-clear {
    background: linear-gradient(135deg, var(--error), #e74c3c) !important;
    color: white;
}

.num-btn.num-btn-clear:hover {
    background: linear-gradient(135deg, #ff8787, var(--error)) !important;
}

/* ========================================
   STREAK MILESTONE
======================================== */

.streak-milestone {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: white;
    padding: var(--space-lg) var(--space-xl);
    border-radius: var(--radius-lg);
    font-size: 1.1rem;
    font-weight: 800;
    text-align: center;
    z-index: 100;
    animation: milestonePopup 2s ease forwards;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.streak-milestone.hidden {
    display: none;
}

@keyframes milestonePopup {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.5);
    }
    15% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.1);
    }
    30% {
        transform: translate(-50%, -50%) scale(1);
    }
    70% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8);
    }
}

/* ========================================
   TIMER BAR
======================================== */

.timer-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--card-bg);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-sm);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

.timer-left {
    display: flex;
    align-items: baseline;
    gap: 0.35rem;
}

.timer-display {
    font-size: 1.6rem;
    font-weight: 800;
    min-width: 2.2ch;
    text-align: center;
    transition: color 0.4s ease;
    font-variant-numeric: tabular-nums;
}

.timer-fast   { color: var(--success); }
.timer-medium { color: var(--warning); }
.timer-slow   { color: var(--error);   }

.timer-unit {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.pause-btn {
    padding: 0.45rem 1rem;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: 0 3px 10px rgba(108, 92, 231, 0.3);
}

.pause-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(108, 92, 231, 0.4);
}

.pause-btn:active {
    transform: translateY(0);
}

.pause-btn.is-paused {
    background: linear-gradient(135deg, var(--success), #00a884);
    box-shadow: 0 3px 10px rgba(0, 184, 148, 0.3);
}

/* Dim the question card and number pad while paused */
.question-card.is-paused,
.number-pad.is-paused {
    opacity: 0.45;
    pointer-events: none;
    user-select: none;
}

/* ========================================
   HEATMAP BUTTON
======================================== */

.heatmap-btn {
    background: var(--card-bg);
    border: none;
    border-radius: var(--radius-md);
    padding: var(--space-xs) var(--space-xs);
    font-size: 1.2rem;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    transition: all var(--transition-fast);
    line-height: 1;
}

.heatmap-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

/* ========================================
   HEATMAP MODAL
======================================== */

.heatmap-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    animation: fadeIn 0.2s ease;
}

.heatmap-modal.hidden {
    display: none;
}

.heatmap-content {
    background: white;
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.4);
}

.heatmap-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.heatmap-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
}

.heatmap-close {
    background: #f0f0f0;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast);
    flex-shrink: 0;
}

.heatmap-close:hover {
    background: #e0e0e0;
}

.heatmap-legend {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.legend-swatch {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    flex-shrink: 0;
}

.legend-green  { background: hsl(120, 65%, 50%); }
.legend-yellow { background: hsl(60,  65%, 50%); }
.legend-red    { background: hsl(0,   65%, 50%); }

.heatmap-grid {
    display: grid;
    grid-template-columns: 22px repeat(10, 1fr);
    gap: 2px;
    direction: ltr;
}

.heatmap-label {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-secondary);
    padding: 2px 0;
}

.heatmap-cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    font-weight: 700;
    color: white;
    border-radius: 3px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
    cursor: default;
    transition: transform 0.1s ease;
}

.heatmap-cell:hover {
    transform: scale(1.3);
    z-index: 1;
    position: relative;
}

.heatmap-note {
    text-align: center;
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-top: 0.6rem;
}

/* ========================================
   RESPONSIVE
======================================== */

/* Small phones (portrait ≤ 480px wide) */
@media (max-width: 480px) {
    :root {
        --space-xs: 0.3rem;
        --space-sm: 0.6rem;
        --space-md: 1rem;
        --space-lg: 1.4rem;
        --space-xl: 2rem;
    }

    .container {
        padding: var(--space-sm);
    }

    .mascot img {
        max-width: 160px;
        max-height: 22vh;
    }

    .welcome-title {
        font-size: 1.9rem;
    }

    .welcome-subtitle {
        font-size: 1.4rem;
    }

    .welcome-text {
        font-size: 0.9rem;
    }

    .question-equation {
        font-size: 2.2rem;
    }

    .num-btn {
        padding: 0.45rem;
        font-size: 1.05rem;
    }

    .stat-icon  { font-size: 1rem; }
    .stat-label { font-size: 0.65rem; }
    .stat-value { font-size: 0.95rem; }

    .timer-display { font-size: 1.3rem; }
    .pause-btn     { font-size: 0.85rem; padding: 0.35rem 0.7rem; }
}

/* Short screens (landscape phone or small tablet ≤ 680px tall) */
@media (max-height: 680px) {
    .welcome-content {
        padding: var(--space-md);
    }

    .mascot {
        margin-bottom: var(--space-xs);
    }

    .mascot img {
        max-width: 130px;
        max-height: 14vh;
    }

    .question-card {
        padding: var(--space-sm);
    }

    .question-equation {
        font-size: 2rem;
        margin-bottom: var(--space-sm);
    }

    .stats-bar,
    .timer-bar {
        margin-bottom: var(--space-xs);
    }

    .sound-toggle {
        margin-bottom: var(--space-xs);
    }
}
