:root {
    --primary-color: #4f883d;
    --text-color: #333;
    --bg-color: #f7f9fc;
    --panel-bg: #ffffff;
    --border-color: #ddd;
    --font-family: 'Inter', sans-serif;
    --font-mono: 'Courier New', Courier, monospace;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-color);
}

/* Radio Group Styling */
.radio-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.radio-option {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 0.95rem;
}

.radio-option input[type="radio"] {
    width: 18px;
    height: 18px;
    margin: 0;
    appearance: auto;
    accent-color: var(--primary-color);
}

.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Sidebar Settings */
.settings-panel {
    background-color: var(--panel-bg);
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.settings-panel h1 {
    margin: 0 0 10px 0;
    font-size: 1.5rem;
    font-weight: 600;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

label {
    font-size: 0.9rem;
    font-weight: 500;
}

input[type="text"],
input[type="number"] {
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1rem;
    width: 100%;
}

fieldset {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    margin: 0;
}

fieldset legend {
    padding: 0 6px;
    font-weight: 600;
    font-size: 0.85rem;
    color: #666;
}

.row {
    display: flex;
    gap: 12px;
}

.col {
    flex: 1;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 14px;
    font-size: 1.1rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s;
    margin-top: 0;
}


.btn-primary:hover {
    background-color: #3e702e;
}

/* Preview Area */
.preview-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 20px;
    background-color: #ededed;
    overflow-y: auto;
}

.paper {
    background: white;
    width: 100%;
    max-width: 210mm;
    /* A4 widthish */
    min-height: 297mm;
    /* A4 height */
    padding: 40px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    position: relative;
    box-sizing: border-box;
    /* IMPORTANT for padding */
}

.paper h2 {
    text-align: center;
    margin-bottom: 30px;
    font-size: 2rem;
    color: #000;
}

.problems-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px 40px;
    flex: 1;
    align-content: start;
}

.problem-item {
    font-size: 1.5rem;
    font-family: monospace;
    /* helper for alignment */
    padding: 10px;
    border-bottom: 1px dashed #eee;
    /* lightweight guide */
}

/* Vertical Layout Styles - Refactored for better alignment & N addends */
.problem-item.vertical {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-end;
    margin: 0 auto;
    font-family: var(--font-mono);
    /* Monospace helps alignment */
    font-size: 2rem;
    line-height: 1.2;
    border-bottom: none;
    position: relative;
    padding-right: 15px;
    /* space for operator */
}

/* Container for the number stack */
.problem-item.vertical .numbers-col {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    width: 100%;
}

.problem-item.vertical .number-row {
    width: 100%;
    text-align: right;
    padding-right: 5px;
}

/* The operator positioned relative to the last number row */
.problem-item.vertical .operator-symbol {
    position: absolute;
    bottom: 2px;
    /* aligns with last row roughly */
    left: -20px;
    /* hang to the left */
    font-size: 2rem;
    width: 20px;
    text-align: right;
}

/* The horizontal line */
.problem-item.vertical .calc-line {
    width: 120%;
    /* extend a bit */
    height: 2px;
    background-color: #000;
    margin-top: 5px;
    margin-right: -10px;
    /* shift right slightly */
}

/* Numbering (1). etc) */
.problem-item.vertical .problem-number {
    position: absolute;
    top: 5px;
    left: -70px;
    /* Push to left side */
    font-size: 1.2rem;
    color: #666;
    font-family: var(--font-family);
    /* keep numbering sans-serif */
}

.paper-footer {
    margin-top: auto;
    text-align: center;
    font-size: 0.8rem;
    color: #888;
    border-top: 1px solid #eee;
    padding-top: 10px;
}

.preview-note {
    margin-top: 10px;
    font-size: 0.9rem;
    color: #777;
}

/* Responsive >= 920px */
@media (min-width: 920px) {
    .app-container {
        flex-direction: row;
    }

    .settings-panel {
        width: 320px;
        border-bottom: none;
        border-right: 1px solid var(--border-color);
        height: 100vh;
        overflow-y: auto;
        position: sticky;
        top: 0;
    }

    .preview-area {
        height: 100vh;
    }

    .paper {
        margin-top: 20px;
        margin-bottom: 20px;
        transform-origin: top center;
    }
}