:root {
    --primary-color: #1A237E;
    /* Deep Indigo */
    --secondary-color: #455A64;
    /* Slate Grey */
    --accent-color: #3F51B5;
    --background-color: #F5F7FA;
    --surface-color: #FFFFFF;
    --text-color: #212121;
    --border-color: #E0E0E0;
    --shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    --font-heading: 'Inter', sans-serif;
    --font-body: 'Inter', sans-serif;
    --font-mono: 'Roboto Mono', monospace;
}

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

body {
    font-family: var(--font-body);
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
}

/* Layout */
#app {
    min-height: 100vh;
}

.view {
    display: none;
}

.view.active {
    display: block;
}

/* Dashboard */
.dashboard-header {
    background-color: var(--surface-color);
    padding: 2.5rem 1.5rem;
    /* Reduced padding */
    text-align: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    margin-bottom: 2rem;
    /* Reduced margin */
    border-bottom: 1px solid var(--border-color);
}

.dashboard-header h1 {
    color: var(--primary-color);
    font-size: 2.2rem;
    /* Scaled down */
    margin-bottom: 0.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.dashboard-header p {
    color: var(--secondary-color);
    font-size: 1rem;
    /* Scaled down */
    max-width: 550px;
    margin: 0 auto;
}

.topic-grid {
    max-width: 1100px;
    /* Slightly wider to allow more columns */
    margin: 0 auto;
    padding: 0 1.5rem;
    display: grid;
    gap: 2rem;
    /* Reduced gap */
}

.topic-category h2 {
    color: var(--primary-color);
    /* Stronger identity */
    font-size: 1.1rem;
    /* Scaled down */
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--primary-color);
    /* Thinner border */
    display: inline-block;
    padding-bottom: 0.15rem;
}

.topic-cards {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    /* Tighter gap for pills */
}

.topic-card {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 30px;
    /* Pill shape */
    padding: 0.6rem 1.25rem;
    /* Compact pill padding */
    text-align: center;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 120px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.topic-card:not(:disabled):hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(26, 35, 126, 0.12);
    border-color: var(--primary-color);
    background-color: var(--primary-color);
    color: white;
}

.topic-card:not(:disabled):hover h3 {
    color: white;
}

.topic-card h3 {
    color: var(--primary-color);
    font-size: 0.95rem;
    /* Tighter font */
    font-weight: 500;
    margin: 0;
}

.topic-card p {
    color: var(--secondary-color);
    font-size: 0.9rem;
}

.topic-card:disabled,
.topic-cards.disabled .topic-card {
    opacity: 0.6;
    cursor: not-allowed;
    background-color: #f9f9f9;
}

/* App Footer */
.app-footer {
    max-width: 1200px;
    margin: 4rem auto 2rem;
    padding: 2rem;
    text-align: center;
    color: var(--secondary-color);
    font-size: 0.9rem;
    border-top: 1px solid var(--border-color);
}

.app-footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

.app-footer a:hover {
    text-decoration: underline;
}

/* Generator View */
#generator-view {
    display: none;
    /* Hidden by default */
    min-height: 100vh;
}

#generator-view.active {
    display: grid;
    grid-template-columns: 300px 1fr;
}

/* Sidebar */
.sidebar {
    background: var(--surface-color);
    border-right: 1px solid var(--border-color);
    padding: 1.5rem;
    height: 100vh;
    position: sticky;
    top: 0;
    overflow-y: auto;
}

.sidebar-header {
    margin-bottom: 2rem;
}

.back-btn {
    background: none;
    border: none;
    color: var(--secondary-color);
    cursor: pointer;
    font-weight: 500;
    margin-bottom: 1rem;
    padding: 0;
}

.back-btn:hover {
    color: var(--primary-color);
}

.config-group {
    margin-bottom: 1.5rem;
}

.config-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--secondary-color);
}

.config-group select,
.config-group input[type="number"] {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
}

.chips-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.chip {
    padding: 0.5rem 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background: var(--surface-color);
    color: var(--secondary-color);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.chip:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
}

.chip.active {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 2rem;
}

button.btn-primary,
button.btn-secondary {
    padding: 0.75rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    font-family: var(--font-heading);
    transition: background-color 0.2s;
}

button.btn-primary {
    background-color: var(--primary-color);
    color: white;
    border: none;
}

button.btn-primary:hover {
    background-color: #121858;
}

button.btn-secondary {
    background-color: transparent;
    color: var(--primary-color);
    border: 1px solid var(--primary-color);
}

button.btn-secondary:hover {
    background-color: rgba(63, 81, 181, 0.05);
}


/* Preview Area & Worksheet Layout */
.preview-area {
    padding: 2rem;
    background-color: #525659;
    /* Standard PDF viewer background */
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
}

.worksheet-page {
    background: white;
    width: 210mm;
    /* A4 width */
    min-height: 297mm;
    /* A4 height */
    padding: 20mm;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    position: relative;
    display: flex;
    flex-direction: column;
}

.worksheet-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 2px solid var(--text-color);
    padding-bottom: 1rem;
    margin-bottom: 2rem;
}

.header-left h1 {
    font-size: 1.2rem;
    /* Decreased */
    margin-bottom: 0.2rem;
    color: var(--text-color);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.header-left p {
    font-size: 1rem;
    /* Adjusted */
    font-weight: 500;
    color: var(--primary-color);
}

.header-right {
    text-align: right;
    width: 40%;
}

.header-right .field {
    margin-bottom: 0.5rem;
    font-size: 1rem;
    border-bottom: 1px dashed var(--border-color);
    padding-bottom: 2px;
}



.problems-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    /* Default 2 columns */
    gap: 4rem 2rem;
    /* Increased vertical gap from 3rem to 4rem */
    flex-grow: 1;
    align-content: start;
}

.problems-grid.one-column {
    grid-template-columns: 1fr;
    gap: 5rem 0;
}

.answers-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 1.5rem 1rem;
    flex-grow: 1;
    align-content: start;
}

.problem-card {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    break-inside: avoid;
    padding-bottom: 2rem;
    /* Added space specifically for writing answers */
}

.answer-card {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    break-inside: avoid;
    padding-bottom: 0.5rem;
}

.problem-number {
    font-weight: bold;
    font-size: 1.2rem;
    min-width: 1.5rem;
}

.answer-number {
    font-weight: bold;
    font-size: 1rem;
    min-width: 1.2rem;
}

.problem-content {
    flex-grow: 1;
    display: flex;
    justify-content: center;
}

.problem {
    font-family: var(--font-heading);
    font-size: 18px;
    /* High legibility */
    page-break-inside: avoid;
    break-inside: avoid;
    padding: 0.5rem;
    border: 1px dashed transparent;
    /* visual aid in preview only */
}

/* Arithmetic Styles */
.vertical-math {
    display: inline-block;
    text-align: right;
    font-family: var(--font-mono);
    font-size: 1.5rem;
    line-height: 1.2;
}

.vertical-math .row {
    padding-right: 0.5rem;
}

.vertical-math .row.number {
    position: relative;
}

.vertical-math .operator {
    position: absolute;
    right: -1.5rem;
    font-weight: bold;
}

.vertical-math .line {
    border-bottom: 2px solid black;
    margin-top: 2px;
    margin-bottom: 2px;
}

.long-division {
    display: inline-flex;
    align-items: center;
    font-family: var(--font-mono);
    font-size: 1.5rem;
}

.long-division .divisor {
    padding-right: 0.5rem;
}

.long-division .dividend {
    border-left: 2px solid black;
    border-top: 2px solid black;
    padding: 0.2rem 0.5rem;
}

.horizontal-math,
.inline-math {
    font-family: var(--font-mono);
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 4rem;
}

.answer-text {
    font-family: var(--font-mono);
    font-weight: normal;
    font-size: 1rem;
}

/* Visualization Styles (Fractions) */
.fraction-visual {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.fraction-text {
    font-family: var(--font-mono);
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    vertical-align: middle;
    font-size: 1.25em;
}

.numerator {
    border-bottom: 2px solid currentColor;
    padding: 0 4px;
}

.denominator {
    padding: 0 4px;
}

/* Shapes for Fractions */
.shape-circle,
.shape-rect {
    stroke: black;
    stroke-width: 2;
    fill: none;
}

.shape-fill {
    fill: #E0E0E0;
    /* Light grey for printing */
}


.worksheet-footer {
    margin-top: auto;
    text-align: center;
    font-size: 0.8rem;
    color: var(--secondary-color);
    border-top: 1px solid var(--border-color);
    padding-top: 0.5rem;
}

/* Print Styles */
@media print {
    @page {
        size: A4;
        margin: 0;
    }

    body {
        background: white;
    }

    .no-print,
    .dashboard-header,
    .topic-grid,
    .sidebar {
        display: none !important;
    }

    #generator-view {
        display: block !important;
        grid-template-columns: 1fr;
    }

    .preview-area {
        padding: 0;
        background: white;
        display: block;
    }

    .worksheet-page {
        width: 100%;
        min-height: 100vh;
        box-shadow: none;
        padding: 20mm;
        margin: 0;
        page-break-after: always;
    }

    .worksheet-page:last-child {
        page-break-after: auto;
    }
}

/* Mobile Responsive Adjustments */
.mobile-only {
    display: none;
}

@media (max-width: 768px) {
    .mobile-only {
        display: block;
    }

    .dashboard-header {
        padding: 2rem 1rem;
    }

    .dashboard-header h1 {
        font-size: 1.8rem;
    }

    .topic-grid {
        padding: 0 1rem;
    }

    .topic-cards {
        grid-template-columns: 1fr;
    }

    /* Generator Mobile Layout */
    #generator-view.active {
        display: block !important;
        /* Force block to prevent grid track expansion */
        position: relative;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 280px;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: 4px 0 10px rgba(0, 0, 0, 0.1);
        background: white;
        display: none;
        /* Hide from grid/flex flow when closed */
    }

    .sidebar.open {
        transform: translateX(0);
        display: block;
        /* Show when open */
    }

    .sidebar-header {
        display: flex;
        flex-direction: column;
        /* Stack vertically to prevent overlap */
        align-items: flex-start;
        gap: 0.5rem;
        margin-bottom: 1.5rem;
        position: relative;
    }

    .sidebar-header h2 {
        font-size: 1.2rem;
        margin: 0;
        width: 100%;
    }

    .back-btn {
        margin: 0;
        padding: 0;
        font-size: 0.9rem;
    }

    .close-btn {
        position: absolute;
        top: 0;
        right: 0;
        background: none;
        border: none;
        font-size: 1.5rem;
        cursor: pointer;
        color: var(--secondary-color);
    }

    .mobile-floating-actions {
        position: fixed;
        bottom: 1.5rem;
        right: 1.5rem;
        display: flex;
        gap: 0.75rem;
        z-index: 900;
    }

    .floating-btn {
        width: 44px;
        /* Reduced from 50px */
        height: 44px;
        /* Reduced from 50px */
        border-radius: 50%;
        background: var(--primary-color);
        color: white;
        border: none;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        font-size: 1.1rem;
        /* Slightly smaller font */
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        padding: 0;
    }

    .preview-area {
        padding: 1rem 0;
        width: 100%;
        overflow-x: hidden;
        display: block;
        /* Use block to avoid flexbox center overflow pinning */
        position: relative;
    }

    .worksheet-page {
        margin: 0;
        position: relative;
        left: 50% !important;
        margin-left: -396.85px !important;
        /* Center the 210mm box around the viewport center */
        transform-origin: top center;
    }
}

/* Mixed Number Styles */
.mixed-number {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    vertical-align: middle;
}

.whole-part {
    font-size: 1.8rem;
    font-weight: 600;
    line-height: 1;
}