:root {
    --bg-color: #f0f4f8;
    --primary: #6c5ce7;
    --primary-hover: #5b4bc4;
    --secondary: #00cec9;
    --text-main: #2d3436;
    --text-muted: #636e72;
    --glass-bg: rgba(255, 255, 255, 0.75);
    --glass-border: rgba(255, 255, 255, 0.4);
    --success: #00b894;
    --error: #d63031;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
    background-attachment: fixed;
    font-family: 'Outfit', sans-serif;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: 40px;
    padding-bottom: 40px;
    color: var(--text-main);
    overflow-x: hidden;
    position: relative;
}

/* Background gradient blobs */
.blob {
    position: fixed;
    filter: blur(80px);
    z-index: -1;
    opacity: 0.6;
}

.blob-1 {
    top: -100px;
    left: -100px;
    width: 400px;
    height: 400px;
    background: #a29bfe;
    border-radius: 50%;
}

.blob-2 {
    bottom: -100px;
    right: -100px;
    width: 300px;
    height: 300px;
    background: #fd79a8;
    border-radius: 50%;
}

.app-container {
    width: 95%;
    max-width: 800px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

header {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 20px 30px;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

.header-top {
    display: flex;
    justify-content: center;
    align-items: center;
}

h1 {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Tabs */
.tabs {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.tab-btn {
    background: rgba(255, 255, 255, 0.5);
    color: var(--text-main);
    border: 2px solid transparent;
    padding: 10px 20px;
    border-radius: 20px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    font-size: 1rem;
}

.tab-btn:hover {
    background: rgba(255, 255, 255, 0.8);
}

.tab-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 15px rgba(108, 92, 231, 0.3);
}

/* Views */
.view-section {
    display: none;
    animation: fadeIn 0.4s ease;
}

.view-section.active {
    display: flex;
}

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

.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 30px;
    padding: 40px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.1);
    flex-direction: column;
    align-items: center;
    gap: 30px;
}

/* Controls Header (Dropdown, Score, Buttons) */
.controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    flex-wrap: wrap;
    gap: 15px;
    border-bottom: 2px dashed var(--glass-border);
    padding-bottom: 20px;
}

.selector-group {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
}

select {
    padding: 8px 15px;
    border-radius: 15px;
    border: 2px solid transparent;
    background: rgba(255,255,255,0.9);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
    outline: none;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

select:focus {
    border-color: var(--secondary);
}

.score-tracker {
    font-size: 1.1rem;
    font-weight: 600;
    background: var(--primary);
    color: white;
    padding: 8px 16px;
    border-radius: 30px;
    box-shadow: 0 4px 15px rgba(108, 92, 231, 0.3);
}

.secondary-btn {
    background: var(--secondary);
    color: white;
    padding: 10px 20px;
    border-radius: 20px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 206, 201, 0.3);
    font-family: inherit;
    transition: all 0.2s ease;
}

.secondary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 206, 201, 0.4);
}

/* Question Area */
.question-container {
    display: flex;
    align-items: center;
    gap: 15px;
    font-size: 4rem;
    font-weight: 800;
    color: var(--text-main);
    text-shadow: 2px 2px 4px rgba(0,0,0,0.05);
}

.operator, .equals {
    color: var(--primary);
    font-size: 3.5rem;
}

form {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 20px;
    align-items: center;
}

input {
    width: 100%;
    max-width: 300px;
    padding: 15px 20px;
    font-size: 2rem;
    font-weight: 600;
    text-align: center;
    border: 3px solid transparent;
    border-radius: 15px;
    outline: none;
    background: rgba(255, 255, 255, 0.9);
    color: var(--text-main);
    box-shadow: inset 0 2px 6px rgba(0,0,0,0.05);
    transition: all 0.3s ease;
    font-family: inherit;
}

input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input[type=number] {
    -moz-appearance: textfield;
}

input:focus {
    border-color: var(--secondary);
    box-shadow: 0 0 0 4px rgba(0, 206, 201, 0.2);
}

input.success {
    background: #e8f8f5;
    border-color: var(--success);
    color: var(--success);
}

input.error {
    background: #fdedec;
    border-color: var(--error);
    color: var(--error);
}

.primary-btn {
    background: var(--primary);
    color: white;
    font-size: 1.2rem;
    font-weight: 600;
    padding: 15px 40px;
    border: none;
    border-radius: 30px;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(108, 92, 231, 0.3);
    transition: all 0.2s ease;
    font-family: inherit;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.primary-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(108, 92, 231, 0.4);
}

.primary-btn:active {
    transform: translateY(1px);
}

.feedback {
    min-height: 24px;
    font-size: 1.2rem;
    font-weight: 600;
    opacity: 0;
    transition: opacity 0.3s;
}

.feedback.show {
    opacity: 1;
}

.feedback.correct {
    color: var(--success);
}

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

/* Flashcards Grid */
.flashcards-grid-inner {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 20px;
    width: 100%;
}

.flashcard {
    background: white;
    border-radius: 15px;
    padding: 20px;
    text-align: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
    border: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    aspect-ratio: 4 / 3;
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary);
    transition: transform 0.2s;
    cursor: pointer;
    position: relative;
    transform-style: preserve-3d;
}

.flashcard:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.1);
}

.flashcard .flipped-answer {
    position: absolute;
    bottom: 5px;
    right: 10px;
    font-size: 0.9rem;
    color: #ccc;
    transform: rotate(180deg); /* Easy self-checking when cut out */
}

/* Reference Table 20x20 */
.table-wrapper {
    width: 100%;
    overflow: hidden;
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    border: 1px solid var(--glass-border);
    background: white;
}

table {
    border-collapse: collapse;
    width: 100%;
    table-layout: fixed;
}

th, td {
    padding: clamp(1px, 0.4vw, 8px);
    text-align: center;
    border: 1px solid #eee;
    font-weight: 600;
    font-size: clamp(0.45rem, 1.2vw, 1rem);
}

th {
    background: var(--primary);
    color: white;
    position: sticky;
    top: 0;
    z-index: 2;
}

/* Freeze the first column */
td:first-child, th:first-child {
    position: sticky;
    left: 0;
    background: var(--primary);
    color: white;
    z-index: 3;
}
td:first-child {
    background: #f8f9fa;
    color: var(--primary);
    z-index: 1;
}

td:hover {
    background-color: #f1f2f6;
    cursor: crosshair;
}

.highlight-row {
    background-color: rgba(108, 92, 231, 0.3) !important;
}

.highlight-col {
    background-color: rgba(108, 92, 231, 0.3) !important;
}

/* Ad Container */
.ad-container {
    background: rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border: 2px dashed rgba(0, 0, 0, 0.1);
    border-radius: 15px;
    min-height: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.ad-placeholder-text {
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

/* Animations */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.shake {
    animation: shake 0.5s;
}

/* Print Styles */
@media screen {
    .print-only { display: none !important; }
}

@media print {
    .no-print, .screen-only {
        display: none !important;
    }
    
    @page {
        margin: 0.5in;
        size: auto;
    }

    body {
        background: none;
        padding: 0;
        margin: 0;
    }
    
    .app-container {
        max-width: 100%;
        width: 100%;
        margin: 0;
        gap: 0;
    }
    
    .glass-panel {
        background: none;
        box-shadow: none;
        border: none;
        padding: 0;
    }
    
    #view-flashcards {
        display: block !important;
    }
    
    .print-only {
        display: block !important;
    }
    
    .print-flashcard-pages {
        display: flex;
        flex-direction: column;
        width: 100%;
    }
    
    .print-page {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        grid-template-rows: repeat(3, 1fr);
        gap: 0;
        width: 100%;
        height: 95vh;
        page-break-after: always;
        break-after: page;
        box-sizing: border-box;
    }
    
    .print-card {
        border: 1px dashed #bbb;
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 3rem;
        font-weight: 800;
        color: #000;
        page-break-inside: avoid;
        break-inside: avoid;
    }
}

/* Responsive */
@media (max-width: 600px) {
    .question-container {
        font-size: 3rem;
    }
    .operator, .equals {
        font-size: 2.5rem;
    }
    .controls {
        flex-direction: column;
    }
    .flashcards-grid-inner {
        grid-template-columns: repeat(2, 1fr);
    }
}
