:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --secondary: #64748b;
    --bg-app: #f8fafc;
    --bg-sidebar: rgba(255, 255, 255, 0.95);
    --text-main: #0f172a;
    --text-muted: #475569;
    --border: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);

    --worksheet-width: 210mm;
    --worksheet-height: 297mm;
    --printable-padding: 20mm;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-app);
    color: var(--text-main);
    overflow: hidden;
    height: 100vh;
}

h1,
h2,
h3 {
    font-family: 'Outfit', sans-serif;
}

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

/* Sidebar Styling */
.sidebar {
    width: 350px;
    background-color: var(--bg-sidebar);
    backdrop-filter: blur(10px);
    border-right: 1px solid var(--border);
    padding: 2.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.75rem;
    overflow-y: auto;
    z-index: 10;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.02);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.logo-icon {
    background: linear-gradient(135deg, var(--primary), #6366f1);
    color: white;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    font-weight: bold;
    font-size: 1.25rem;
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(to right, var(--primary), #6366f1);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.control-group label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
}

.control-group input,
.control-group select {
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    color: var(--text-main);
    background-color: #f8fafc;
    transition: all 0.2s;
}

.control-group input:focus,
.control-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.toggle-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;
    border-radius: 34px;
}

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

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

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

.button-group {
    margin-top: 1rem;
}

.primary-btn {
    width: 100%;
    padding: 1rem;
    background-color: var(--primary);
    color: white;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.2);
}

.primary-btn:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 10px 15px -3px rgba(37, 99, 235, 0.3);
}

.export-group {
    border-top: 1px solid var(--border);
    padding-top: 1.5rem;
}

.export-group h3 {
    font-size: 0.875rem;
    margin-bottom: 1rem;
    color: var(--text-muted);
}

.export-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.secondary-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem;
    background-color: white;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-main);
    cursor: pointer;
    transition: all 0.2s;
}

.secondary-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background-color: #eff6ff;
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.secondary-btn:active {
    transform: translateY(0);
}

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

/* Preview Area Styling */
.preview-area {
    flex: 1;
    padding: 3rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3rem;
    background-color: #cbd5e1;
    background-image: radial-gradient(#94a3b8 0.5px, transparent 0.5px);
    background-size: 20px 20px;
}

.pages-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4rem;
    width: 100%;
}

.worksheet-page {
    width: var(--worksheet-width);
    height: var(--worksheet-height);
    background-color: white;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: top center;
    flex-shrink: 0;
    margin-bottom: calc(var(--worksheet-height) * (1 - var(--scale, 1)) * -1);
}

.printable-content {
    padding: var(--printable-padding);
    flex: 1;
    display: flex;
    flex-direction: column;
}

.worksheet-header {
    border-bottom: 2px solid #000;
    padding-bottom: 1.5rem;
    margin-bottom: 2rem;
}

.worksheet-header h2 {
    text-align: center;
    font-size: 2rem;
    margin-bottom: 1.5rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.student-info {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 2rem;
}

.info-line {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
}

.info-line span {
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
}

.info-line .line {
    flex: 1;
    border-bottom: 1px solid #666;
    height: 1px;
}

/* Questions Grid */
.questions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: repeat(7, 1fr);
    gap: 1.5rem 4rem;
    flex: 1;
    align-content: space-between;
}

.question-item {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    font-size: 1.2rem;
}

.q-number {
    font-weight: bold;
    min-width: 25px;
}

.q-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
}

/* Fraction Rendering */
.q-content {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    flex-wrap: wrap;
    line-height: normal;
}

/* Fraction Rendering */
.fraction {
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
}

.whole-number {
    font-size: 1.5rem;
    font-weight: 500;
    margin-right: 4px;
    line-height: 1;
}

.fraction-stack {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
}

.numerator {
    border-bottom: 2px solid #000;
    padding: 0 4px;
    min-width: 20px;
    text-align: center;
    font-size: 1.1rem;
    line-height: 1.2;
}

.denominator {
    padding: 0 4px;
    min-width: 20px;
    text-align: center;
    font-size: 1.1rem;
    line-height: 1.2;
}

.operator {
    font-weight: 500;
    font-size: 1.4rem;
    margin: 0 0.5rem;
    line-height: 1;
}

.answer-box {
    margin-left: auto;
    width: 60px;
    height: 60px;
    border: 1px solid #ccc;
    background-color: #fafafa;
}

.answer-line {
    margin-left: auto;
    flex: 1;
    max-width: 100px;
    border-bottom: 1px dashed #666;
    height: 1px;
    margin-top: 1.2rem;
}

/* Footer */
.worksheet-footer {
    border-top: 1px solid #eee;
    padding-top: 1rem;
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: #999;
}

/* Question content tweaks */
.q-content {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    flex-wrap: wrap;
}

.fraction-stack {
    padding: 0 2px;
}

/* Export specific tweaks */
.is-exporting {
    box-shadow: none !important;
    transform: none !important;
}

.is-exporting .printable-content {
    padding: 2.5rem !important;
}

@media print {
    body {
        background: none;
        overflow: visible;
    }

    .sidebar {
        display: none;
    }

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

    .worksheet-page {
        box-shadow: none;
        margin: 0;
        width: 100%;
        height: 100%;
        border: none;
    }
}

/* Custom Scrollbar for premium feel */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f5f9;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}