:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --bg-app: #f8fafc;
    --bg-sidebar: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    /* A4 Dimensions in pixels (approx at 96dpi) */
    --a4-width: 210mm;
    --a4-height: 297mm;
}

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

body {
    font-family: 'Outfit', 'Inter', sans-serif;
    background-color: var(--bg-app);
    color: var(--text-main);
    overflow: hidden;
    /* Hide body scroll, sidebar and main will handle */
}

.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar Styling */
.sidebar {
    width: 320px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.02);
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.logo-icon {
    font-size: 24px;
    background: var(--primary);
    color: white;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
}

.logo h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-main);
}

.logo h1 span {
    color: var(--primary);
}

.config-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.config-section label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
}

select,
input[type="number"],
input[type="text"] {
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
    width: 100%;
}

select:focus,
input:focus {
    border-color: var(--primary);
}

.toggle-section {
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
}

/* Switch styling */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #cbd5e1;
    transition: .4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
}

input:checked+.slider {
    background-color: var(--primary);
}

input:checked+.slider:before {
    transform: translateX(20px);
}

.slider.round {
    border-radius: 34px;
}

.slider.round:before {
    border-radius: 50%;
}

.button-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: auto;
}

.primary-btn {
    background-color: var(--primary);
    color: white;
    border: none;
    padding: 14px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

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

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

.export-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.secondary-btn {
    background-color: white;
    color: var(--text-main);
    border: 1px solid var(--border);
    padding: 12px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background 0.2s;
}

.secondary-btn:hover {
    background-color: #f1f5f9;
}

.sidebar-footer {
    margin-top: 12px;
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
}

.sidebar-footer .brand {
    font-weight: 700;
    color: var(--primary);
    margin-top: 4px;
}

/* Preview Area Styling */
.preview-area {
    flex: 1;
    overflow: auto;
    padding: 40px;
    display: flex;
    justify-content: center;
    background-color: #e2e8f0;
}

#worksheet-wrapper {
    box-shadow: var(--shadow-lg);
}

.a4-page {
    width: var(--a4-width);
    height: var(--a4-height);
    background-color: white;
    padding: 10mm 15mm;
    display: flex;
    flex-direction: column;
    position: relative;
    box-sizing: border-box;
    overflow: hidden;
    /* Prevent multi-page spill */
}

.a4-page.exporting {
    box-shadow: none;
    margin: 0;
    transform: scale(1) !important;
}

.worksheet-header {
    margin-bottom: 25px;
    border-bottom: 2px solid #334155;
    padding-bottom: 12px;
    position: relative;
}

.header-top h2 {
    font-size: 22px;
    color: #1e293b;
    margin-bottom: 12px;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.header-info {
    display: flex;
    justify-content: space-between;
    gap: 20px;
}

.info-item {
    flex: 1;
    display: flex;
    align-items: baseline;
    font-size: 14px;
    font-weight: 600;
}

.info-item .line {
    flex: 1;
    margin-left: 5px;
    border-bottom: 1px solid #94a3b8;
}

.difficulty-badge {
    position: absolute;
    top: 52px;
    right: 0;
    font-size: 11px;
    background: #f1f5f9;
    padding: 2px 10px;
    border-radius: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 700;
}

/* Questions Grid */
.questions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px 50px;
    flex: 1;
    align-content: start;
}

.question-card {
    display: grid;
    grid-template-columns: 30px 1fr 20px 70px;
    align-items: center;
    font-size: 17.5px;
    padding: 10px 0;
    border-bottom: 1px dashed #f1f5f9;
}

.q-number {
    font-weight: 700;
    color: #475569;
}

.q-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.q-content-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
}

.fraction {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    vertical-align: middle;
    line-height: 1.1;
}

.numerator {
    border-bottom: 1.5px solid black;
    padding: 0 4px;
}

.denominator {
    padding: 0 4px;
}

.operator {
    font-weight: 500;
    font-size: 20px;
}

.equals {
    font-weight: 500;
}

.answer-box {
    width: 60px;
    height: 40px;
    border: 1px dashed #cbd5e1;
    margin-left: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: var(--primary);
}

.answer-box.hidden {
    border: 1.5px solid #e2e8f0;
    color: transparent;
}

.worksheet-footer {
    margin-top: auto;
    text-align: center;
    font-size: 10px;
    color: #94a3b8;
    border-top: 1px solid #f1f5f9;
    padding-top: 10px;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .app-container {
        flex-direction: column;
        overflow-y: auto;
    }

    .sidebar {
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 20px;
        gap: 16px;
    }

    .preview-area {
        padding: 20px 10px;
        background-color: #cbd5e1;
        overflow-x: hidden;
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    #worksheet-wrapper {
        transform-origin: top center;
        /* Default scale for tablet-like widths */
        transform: scale(0.8);
        margin-bottom: -150px;
        /* Adjust for whitespace after scale */
    }
}

@media (max-width: 768px) {
    #worksheet-wrapper {
        /* Scale more for mobile to fit screen width */
        transform: scale(0.45);
        margin-bottom: -450px;
    }

    .button-group {
        display: grid;
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    #worksheet-wrapper {
        /* Even smaller for narrow mobile */
        transform: scale(0.35);
        margin-bottom: -550px;
    }

    .logo h1 {
        font-size: 18px;
    }
}

/* Print Specifics */
@media print {
    body {
        background: white;
        overflow: visible;
    }

    .sidebar {
        display: none !important;
    }

    .preview-area {
        padding: 0 !important;
        background: white !important;
        overflow: visible !important;
        display: block !important;
    }

    #worksheet-wrapper {
        transform: scale(1) !important;
        box-shadow: none !important;
        margin: 0 !important;
    }

    .a4-page {
        margin: 0 !important;
        box-shadow: none !important;
        width: 210mm !important;
        height: 297mm !important;
    }
}