:root {
    --primary-color: #4D96FF;
    --secondary-color: #FF6B6B;
    --accent-color: #FFD93D;
    --success-color: #6BCB77;
    --bg-color: #E3F2FD; /* Light blue background */
    --text-color: #333;
    --font-family: 'Fredoka', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden; /* Prevent body scroll */
}

.container {
    width: 95%;
    max-width: 450px;
    background: white;
    padding: 1.5rem;
    border-radius: 24px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    text-align: center;
    max-height: 98vh; /* Ensure it stays within viewport */
    display: flex;
    flex-direction: column;
    justify-content: space-around;
}

header h1 {
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    font-size: 1.8rem;
}

.mode-selector {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 0.5rem;
}

.mode-btn {
    padding: 8px 16px;
    font-size: 0.9rem;
    border: none;
    border-radius: 12px;
    font-family: var(--font-family);
    font-weight: 600;
    cursor: pointer;
    background: #eee;
    transition: all 0.3s ease;
}

.mode-btn.active {
    background: var(--primary-color);
    color: white;
}

.stats {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    font-weight: 600;
    font-size: 1rem;
}

.operation-display {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin-bottom: 1rem;
    font-size: 2.2rem;
    font-weight: 600;
    flex-wrap: wrap; /* Allow numbers to wrap if too many */
}

.number {
    background: #F0F4FF;
    padding: 5px 10px;
    border-radius: 16px;
    min-width: 60px;
}

.operator {
    color: var(--secondary-color);
}

.input-section input {
    width: 70px;
    height: 70px;
    font-size: 2.5rem;
    text-align: center;
    border: 4px solid var(--primary-color);
    border-radius: 20px;
    font-family: var(--font-family);
    margin-bottom: 0.5rem;
    transition: border-color 0.3s;
    background-color: white;
}

.keypad {
    display: none; /* Hidden by default */
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    max-width: 220px;
    margin: 0 auto 1rem auto;
}

/* Class to show keypad on mobile */
body.is-mobile .keypad {
    display: grid;
}

.key {
    padding: 12px;
    font-size: 1.3rem;
    font-weight: 600;
    font-family: var(--font-family);
    background: #f0f0f0;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.key:hover {
    background: #e0e0e0;
}

.key:active {
    transform: scale(0.95);
    background: var(--accent-color);
}

.keypad .empty {
    visibility: hidden;
}

.input-section input:focus {
    outline: none;
    border-color: var(--accent-color);
}

.feedback {
    height: 25px;
    margin-bottom: 0.5rem;
    font-weight: 600;
    font-size: 1.1rem;
}

.feedback.correct {
    color: var(--success-color);
    animation: bounce 0.5s;
}

.feedback.incorrect {
    color: var(--secondary-color);
}

button#btn-next, button#btn-reset {
    padding: 10px 20px;
    border: none;
    border-radius: 12px;
    font-family: var(--font-family);
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.2s;
}

button#btn-next {
    background: var(--success-color);
    color: white;
    margin-right: 10px;
}

button#btn-reset {
    background: #ddd;
}

button:hover {
    transform: scale(1.05);
}

.hidden {
    display: none;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* Chrome, Safari, Edge, Opera */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Firefox */
input[type=number] {
  -moz-appearance: textfield;
}
