:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #ec4899;
    --accent: #8b5cf6;
    --background: #f8fafc;
    --surface: #ffffff;
    --text: #1e293b;
    --text-light: #64748b;
    --success: #22c55e;
    --error: #ef4444;
    --radius-lg: 24px;
    --radius-md: 16px;
    --shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.1);
    --bg-gradient-1: #e0f2fe;
    --bg-gradient-2: #fce7f3;
}

body.dark-mode {
    --background: #0f172a;
    --surface: #1e293b;
    --text: #f8fafc;
    --text-light: #94a3b8;
    --shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
    --bg-gradient-1: #1e1b4b;
    --bg-gradient-2: #312e81;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    font-family: 'Outfit', sans-serif;
    background: var(--background);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    background-image: radial-gradient(circle at 0% 0%, var(--bg-gradient-1) 0%, transparent 50%), radial-gradient(circle at 100% 100%, var(--bg-gradient-2) 0%, transparent 50%);
    transition: background-color 0.3s, background-image 0.3s, color 0.3s;
}

/* Mobile-first adjustments */
.app-container {
    width: 100%;
    max-width: 600px;
    padding: 10px;
    /* Reduced from 20px */
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow-y: auto;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    /* Reduced from 10px */
    margin-bottom: 10px;
    /* Reduced from 20px */
}

.logo {
    font-family: 'Comic Neue', cursive;
    font-weight: 700;
    font-size: 24px;
    color: var(--primary);
}

.stats-mini {
    background: var(--surface);
    padding: 8px 16px;
    border-radius: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    font-size: 14px;
    font-weight: 500;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: background 0.2s;
}

.icon-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

/* Base View Styles */
.view {
    flex: 1;
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.3s ease-out;
}

.hidden {
    display: none !important;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Mode Selection */
h1 {
    font-family: 'Comic Neue', cursive;
    font-weight: 700;
    font-size: 32px;
    line-height: 1.2;
    margin-bottom: 30px;
}

.mode-grid {
    display: grid;
    gap: 16px;
}

.mode-card {
    background: var(--surface);
    border: none;
    padding: 24px;
    border-radius: var(--radius-lg);
    text-align: left;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: relative;
    overflow: hidden;
}

.mode-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 6px;
    height: 100%;
    background: var(--primary);
}

.mode-card:nth-child(2)::before {
    background: var(--secondary);
}

.mode-card:nth-child(3)::before {
    background: var(--accent);
}

.mode-card:active {
    transform: scale(0.98);
}

.mode-card .icon {
    font-size: 32px;
    margin-bottom: 8px;
}

.mode-card .title {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
}

.mode-card .subtitle {
    font-size: 14px;
    color: var(--text-light);
}

/* Topic Selection Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--surface);
    padding: 24px;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 400px;
    text-align: center;
    box-shadow: var(--shadow);
}

.topic-list {
    display: grid;
    gap: 12px;
    margin: 20px 0;
}

.topic-btn {
    padding: 16px;
    border: 2px solid var(--primary);
    background: transparent;
    border-radius: var(--radius-md);
    color: var(--primary);
    font-weight: 600;
    font-size: 16px;
    cursor: pointer;
}

.topic-btn:hover {
    background: var(--primary);
    color: white;
}

.close-modal {
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
}

/* Game View */
.game-header {
    display: flex;
    gap: 16px;
    align-items: center;
    margin-bottom: 24px;
}

.back-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
}

.progress-bar-container {
    flex: 1;
    height: 8px;
    background: #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--primary);
    width: 10%;
    /* dynamic */
    transition: width 0.3s ease;
}

.problem-area {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 15px;
    /* Reduced from 30px */
    box-shadow: var(--shadow);
    margin-bottom: 16px;
    /* Reduced from 24px */
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}

/* ... existing styles ... */

.hints-container {
    text-align: center;
    min-height: 40px;
    /* Reserve space for hint button/text */
    display: flex;
    align-items: center;
    justify-content: center;
}

.problem-text {
    font-size: 24px;
    line-height: 1.4;
    font-weight: 500;
}

.problem-visual {
    margin-bottom: 20px;
    width: 100%;
    max-width: 400px;
    /* Min height to avoid jumpiness */
    min-height: 50px;
}

.interaction-area {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
}

#answer-input {
    flex: 1;
    padding: 16px;
    font-size: 24px;
    border: 3px solid #e2e8f0;
    border-radius: var(--radius-md);
    text-align: center;
    font-family: 'Outfit', sans-serif;
    outline: none;
    transition: border-color 0.2s;
}

#answer-input:focus {
    border-color: var(--primary);
}

.primary-btn {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    padding: 0 32px;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
    transition: transform 0.1s;
}

.primary-btn:active {
    transform: scale(0.96);
}

.secondary-btn {
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
    border-radius: var(--radius-md);
    padding: 12px 24px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}

.feedback-area {
    background: #f0fdf4;
    border-radius: var(--radius-md);
    padding: 12px;
    /* Reduced from 16px */
    margin-bottom: 12px;
    /* Reduced from 24px */
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.feedback-message {
    font-weight: 700;
    font-size: 18px;
    margin-bottom: 8px;
    color: var(--success);
}

.feedback-area.error {
    background: #fef2f2;
}

.feedback-area.error .feedback-message {
    color: var(--error);
}

.explanation {
    font-size: 16px;
    color: var(--text);
    margin-bottom: 16px;
    line-height: 1.5;
    background: rgba(255, 255, 255, 0.6);
    padding: 10px;
    border-radius: 8px;
}

.controls {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.hints-container {
    text-align: center;
}

.hint-btn {
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 14px;
    cursor: pointer;
    text-decoration: underline;
}

.hint-text {
    margin-top: 8px;
    font-style: italic;
    color: var(--text-light);
    font-size: 14px;
}

/* Results View */
.results-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 40px;
    text-align: center;
    box-shadow: var(--shadow);
    margin: auto 0;
}

.score-circle {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    font-weight: 700;
    margin: 30px auto;
    box-shadow: 0 8px 20px rgba(99, 102, 241, 0.4);
}

.stats-grid {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-bottom: 30px;
}

.stat-item {
    display: flex;
    flex-direction: column;
}

.stat-item .label {
    font-size: 14px;
    color: var(--text-light);
}

.stat-item .value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
}

/* Mobile UX Improvements */
.interaction-area {
    display: flex;
    flex-direction: column;
    /* Stack input row and keypad */
    gap: 12px;
    /* Reduced from 16px */
    margin-bottom: 12px;
    /* Reduced from 24px */
}

.control-row {
    display: flex;
    gap: 8px;
    width: 100%;
}

#answer-input {
    flex: 1;
    /* Takes available space */
    min-width: 0;
    /* Prevents overflow */
    padding: 12px;
    font-size: 24px;
    text-align: center;
    border: 3px solid #e2e8f0;
    border-radius: var(--radius-md);
    font-family: 'Outfit', sans-serif;
    outline: none;
    transition: border-color 0.2s;
}

#answer-input:focus {
    border-color: var(--primary);
}

.icon-only {
    padding: 0;
    width: 48px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.virtual-keypad {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.key-btn {
    flex: 1 0 18%;
    /* 5 buttons per row roughly */
    max-width: 20%;
    height: 54px;
    background: white;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    font-size: 24px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    transition: all 0.1s;
    touch-action: manipulation;
    /* fast tap */
    font-family: 'Outfit', sans-serif;
}

.key-btn:active {
    background: #f1f5f9;
    transform: scale(0.95);
}

/* Make primary Check button distinct but icon-based on mobile */
#check-btn {
    padding: 0;
    width: 60px;
    /* Slightly wider */
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Settings Modal Styles */
.settings-group {
    margin-bottom: 24px;
    text-align: left;
}

.settings-group label {
    display: block;
    font-size: 14px;
    color: var(--text-light);
    margin-bottom: 8px;
    font-weight: 500;
}

.language-selector {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.lang-btn {
    padding: 12px;
    background: transparent;
    border: 2px solid #e2e8f0;
    border-radius: var(--radius-md);
    color: var(--text);
    font-size: 16px;
    text-align: left;
    cursor: pointer;
    font-family: 'Outfit', sans-serif;
    transition: all 0.2s;
}

.lang-btn.active {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.05);
    color: var(--primary);
    font-weight: 600;
}

.theme-toggle {
    width: 100%;
    padding: 12px;
    background: var(--surface);
    border: 2px solid #e2e8f0;
    border-radius: var(--radius-md);
    color: var(--text);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: 'Outfit', sans-serif;
}

.close-modal-settings {
    width: 100%;
    margin-top: 10px;
}

.visual-toggles-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.toggle-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text);
    cursor: pointer;
    background: var(--surface);
    /* Or slight contrast? */
    padding: 8px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
}

.toggle-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary);
}