/* ============================================================================
   ITE 387: Advanced Programming - Kids Math Game
   Mobile-First, Kid-Friendly, Highly Responsive Stylesheet
   ============================================================================ */

:root {
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --bg-gradient: linear-gradient(135deg, #ffd93d 0%, #ff9f1c 100%);
    --card-bg: #ffffff;
    --text-main: #2d3436;
    --text-muted: #636e72;
    --color-correct: #00b894;
    --color-incorrect: #d63031;
    --color-add: #4a90e2;
    --color-sub: #50c878;
    --color-mul: #ff8c42;
    --color-div: #9b59b6;
    --shadow-soft: 0 10px 25px rgba(0, 0, 0, 0.12);
    --shadow-hover: 0 12px 30px rgba(0, 0, 0, 0.2);
    --radius-card: 24px;
    --radius-btn: 16px;
    --font-family: 'Comic Neue', 'Chalkboard SE', 'Fredoka', 'Comic Sans MS', cursive, sans-serif;
    --touch-min-height: 48px;
}

/* Base & Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    height: 100%;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    font-family: var(--font-family);
    background: var(--bg-gradient);
    color: var(--text-main);
    font-size: 16px;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0;
    padding-bottom: env(safe-area-inset-bottom);
}

/* Top App Bar */
.top-bar {
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    padding: 16px 16px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    z-index: 10;
}

.user-pill {
    background: rgba(255, 255, 255, 0.9);
    padding: 8px 14px;
    border-radius: 20px;
    font-weight: bold;
    font-size: 0.95rem;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
}

.sound-btn {
    margin-left: auto;
    background: white;
    border: 2px solid #a29bfe;
    border-radius: 20px;
    padding: 8px 16px;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: var(--touch-min-height);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.sound-btn:hover {
    background: #f0efff;
}

.sound-btn.muted {
    border-color: #ff7675;
    background: #fff5f5;
    color: #d63031;
}

/* Main Screen Wrapper */
main {
    flex: 1 0 auto;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
}

.screen {
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    animation: fadeIn 0.3s ease-out;
}

.hidden {
    display: none !important;
}

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

/* Header */
header {
    text-align: center;
    margin-bottom: 16px;
}

header h1 {
    font-size: 2rem;
    color: white;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.25);
}

/* Card */
.card {
    background: var(--card-bg);
    border-radius: var(--radius-card);
    padding: 24px 20px;
    box-shadow: var(--shadow-soft);
    width: 100%;
    text-align: center;
}

h2 {
    font-size: 1.6rem;
    color: #ff6b6b;
    margin-bottom: 16px;
}

h3 {
    font-size: 1.25rem;
    color: #4ecdc4;
    margin-bottom: 12px;
}

/* Messages */
.welcome-text {
    font-size: 1.15rem;
    color: #6c5ce7;
    margin-bottom: 16px;
    min-height: 28px;
    font-weight: bold;
}

.validation-message {
    background: #ffe8e8;
    color: var(--color-incorrect);
    border: 2px solid var(--color-incorrect);
    border-radius: 12px;
    padding: 12px 14px;
    margin: 12px 0;
    font-size: 1rem;
    font-weight: bold;
    display: none;
    animation: shake 0.35s ease-in-out;
}

.validation-message.show {
    display: block;
}

/* Inputs */
.input-group {
    margin: 16px 0;
}

.input-group label {
    display: block;
    font-size: 1.15rem;
    font-weight: bold;
    margin-bottom: 8px;
    color: var(--text-main);
}

input[type="text"],
input[type="number"] {
    width: 100%;
    max-width: 320px;
    padding: 14px 16px;
    font-size: 1.25rem;
    border: 3px solid #a29bfe;
    border-radius: 14px;
    text-align: center;
    font-family: inherit;
    font-weight: bold;
    min-height: var(--touch-min-height);
    background: #fdfdfd;
    transition: all 0.2s ease;
}

input[type="text"]:focus,
input[type="number"]:focus {
    outline: none;
    border-color: #6c5ce7;
    background: #fff;
    box-shadow: 0 0 0 4px rgba(108, 92, 231, 0.25);
}

/* Buttons Base */
.btn {
    border: none;
    border-radius: var(--radius-btn);
    cursor: pointer;
    font-family: inherit;
    font-weight: bold;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
    user-select: none;
    touch-action: manipulation;
    min-height: var(--touch-min-height);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}

.btn:active:not(:disabled) {
    transform: scale(0.96);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

/* Button Variants */
.btn-primary {
    background: var(--primary-gradient);
    color: white;
    font-size: 1.25rem;
    padding: 14px 28px;
    width: 100%;
    max-width: 320px;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #e2e8f0;
    color: #475569;
    font-size: 1rem;
    padding: 12px 20px;
}

.btn-secondary:hover:not(:disabled) {
    background: #cbd5e1;
    color: #1e293b;
}

/* Mode Selection Grid */
.section-group {
    margin: 20px 0;
}

.mode-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.btn-mode {
    padding: 16px 12px;
    font-size: 1.1rem;
    color: white;
    border-radius: 16px;
    border: 3px solid transparent;
}

.btn-add { background: linear-gradient(135deg, #4A90E2 0%, #357ABD 100%); }
.btn-sub { background: linear-gradient(135deg, #50C878 0%, #3BA05F 100%); }
.btn-mul { background: linear-gradient(135deg, #FF8C42 0%, #E67632 100%); }
.btn-div { background: linear-gradient(135deg, #9B59B6 0%, #8E44AD 100%); }

.btn-mode.selected,
.btn-questions.selected {
    border-color: #ffd93d;
    box-shadow: 0 0 0 4px #ffd93d, 0 8px 20px rgba(0, 0, 0, 0.25);
    transform: scale(1.04);
}

/* Question Presets */
.question-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.btn-questions {
    background: linear-gradient(135deg, #fca311 0%, #e85d04 100%);
    color: white;
    font-size: 1rem;
    padding: 12px 8px;
    border: 3px solid transparent;
}

/* Action Container */
.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
    margin-top: 24px;
}

/* Progress Bar */
.progress-container {
    width: 100%;
    height: 12px;
    background: #f1f2f6;
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 20px;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #6c5ce7 0%, #00b894 100%);
    border-radius: 10px;
    transition: width 0.35s ease;
}

/* Game Header */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    gap: 10px;
}

.counter {
    font-size: 1rem;
    font-weight: bold;
    color: #6c5ce7;
    background: #f0efff;
    padding: 8px 14px;
    border-radius: 12px;
}

.score {
    font-size: 1.15rem;
    font-weight: bold;
    color: var(--color-correct);
    background: #e8fff8;
    padding: 8px 14px;
    border-radius: 12px;
}

/* Problem Display */
.problem {
    font-size: 2.8rem;
    font-weight: bold;
    color: var(--text-main);
    margin: 16px 0;
    padding: 20px 10px;
    background: linear-gradient(135deg, #fef9e7 0%, #fcf3cf 100%);
    border-radius: 20px;
    border: 4px solid #f39c12;
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    letter-spacing: 2px;
}

/* Answer Section */
.answer-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin: 16px 0;
}

#answer-input {
    font-size: 2.2rem;
    padding: 12px;
    max-width: 220px;
    border-width: 4px;
    height: 64px;
}

/* Feedback Alert */
.feedback {
    font-size: 1.3rem;
    font-weight: bold;
    margin: 14px 0;
    padding: 12px 16px;
    border-radius: 14px;
    min-height: 58px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s ease;
}

.feedback.correct {
    color: var(--color-correct);
    background: #e8fff8;
    border: 3px solid var(--color-correct);
    animation: popIn 0.3s ease;
}

.feedback.incorrect {
    color: var(--color-incorrect);
    background: #ffe8e8;
    border: 3px solid var(--color-incorrect);
    animation: shake 0.35s ease;
}

/* Child-Friendly On-Screen Numpad */
.numpad {
    margin: 16px auto 8px;
    width: 100%;
    max-width: 320px;
}

.numpad-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.numpad-btn {
    background: #f8f9fa;
    color: #2d3436;
    border: 2px solid #e9ecef;
    font-size: 1.6rem;
    height: 56px;
    border-radius: 16px;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.06);
}

.numpad-btn:hover:not(:disabled) {
    background: #eceff1;
}

.numpad-btn:active:not(:disabled) {
    background: #dfe4ea;
    transform: scale(0.92);
}

.numpad-backspace {
    background: #ffeaa7;
    color: #d63031;
    font-size: 1.4rem;
}

.numpad-submit {
    background: #55efc4;
    color: #00b894;
    font-size: 1.5rem;
}

/* Game Over Card */
.game-over-panel {
    padding: 16px 0;
}

.game-over-icon {
    font-size: 3.5rem;
    margin-bottom: 8px;
    animation: bounce 1s infinite alternate ease-in-out;
}

.game-over-score {
    font-size: 2.2rem;
    font-weight: bold;
    color: #6c5ce7;
    margin: 12px 0;
}

.game-over-message {
    font-size: 1.25rem;
    font-weight: bold;
    color: #2d3436;
    margin-bottom: 24px;
}

/* Leaderboard */
.leaderboard-container {
    margin: 16px 0;
}

#leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

#leaderboard-table thead {
    background: var(--primary-gradient);
    color: white;
}

#leaderboard-table th {
    padding: 12px 8px;
    text-align: left;
    font-size: 1rem;
}

#leaderboard-table td {
    padding: 10px 8px;
    border-bottom: 1px solid #edf2f7;
    text-align: left;
}

.leaderboard-row.top-rank {
    background: #fffdf0;
    font-weight: bold;
}

.mode-tag {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: bold;
    color: white;
}

.mode-tag.mode-add { background: var(--color-add); }
.mode-tag.mode-sub { background: var(--color-sub); }
.mode-tag.mode-mul { background: var(--color-mul); }
.mode-tag.mode-div { background: var(--color-div); }

.empty-message,
.empty-card {
    text-align: center;
    padding: 24px;
    color: var(--text-muted);
    font-weight: bold;
}

/* Responsive Mobile Cards for Leaderboard */
.leaderboard-cards {
    display: none;
    flex-direction: column;
    gap: 12px;
}

.leaderboard-card {
    background: #f8f9fa;
    border: 2px solid #e9ecef;
    border-radius: 16px;
    padding: 12px 16px;
    text-align: left;
}

.leaderboard-card.top-card {
    border-color: #ffd93d;
    background: #fffdf2;
}

.card-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    gap: 8px;
}

.card-rank {
    font-size: 1.1rem;
    font-weight: bold;
}

.card-player {
    font-size: 1.1rem;
    font-weight: bold;
    color: #2d3436;
    flex: 1;
}

.card-mode {
    font-size: 0.85rem;
    padding: 4px 8px;
    border-radius: 8px;
    color: white;
}

.card-body-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.95rem;
    color: var(--text-muted);
}

.card-pct {
    font-weight: bold;
    color: var(--color-correct);
}

/* Footer */
footer {
    flex-shrink: 0;
    width: 100%;
    background: rgba(255, 255, 255, 0.85);
    padding: 14px 16px;
    text-align: center;
    font-size: 0.95rem;
    color: var(--text-muted);
    margin-top: auto;
}

/* Keyframe Animations */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-8px); }
    40%, 80% { transform: translateX(8px); }
}

@keyframes popIn {
    0% { transform: scale(0.9); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes bounce {
    from { transform: translateY(0); }
    to { transform: translateY(-8px); }
}

.shake {
    animation: shake 0.35s ease-in-out;
}

/* Responsive Media Queries */
@media (max-width: 640px) {
    header h1 {
        font-size: 1.6rem;
    }

    .card {
        padding: 20px 16px;
    }

    .problem {
        font-size: 2.3rem;
        padding: 16px 8px;
    }

    #answer-input {
        font-size: 1.8rem;
    }

    /* Switch Leaderboard from wide table to mobile cards */
    .table-wrapper {
        display: none;
    }

    .leaderboard-cards {
        display: flex;
    }
}

@media (min-width: 641px) {
    .action-buttons {
        flex-direction: row;
        justify-content: center;
    }

    .btn-primary {
        width: auto;
    }

    header h1 {
        font-size: 2.4rem;
    }

    .card {
        padding: 32px;
    }
}
