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

body {
    font-family: 'Microsoft YaHei', Arial, sans-serif;
    background-color: #f5f5f5;
    padding: 20px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

h1 {
    text-align: center;
    color: #333;
    margin-bottom: 30px;
    font-size: 28px;
}

/* 设置面板样式 */
.settings-panel {
    background: white;
    border-radius: 12px;
    padding: 25px;
    margin-bottom: 30px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.settings-row {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 20px;
}

.setting-group {
    flex: 1;
    min-width: 200px;
    max-width: 200px;
}

.setting-group label {
    display: block;
    font-weight: bold;
    margin-bottom: 8px;
    color: #555;
}

.setting-group select,
.setting-group input {
    width: 100%;
    padding: 10px 15px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.3s;
}

.setting-group select:focus,
.setting-group input:focus {
    outline: none;
    border-color: #4CAF50;
}

.buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

.btn {
    padding: 12px 30px;
    font-size: 18px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: bold;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.btn-generate {
    background: linear-gradient(135deg, #4CAF50, #45a049);
    color: white;
}

.btn-generate:hover {
    background: linear-gradient(135deg, #45a049, #3d8b40);
    transform: translateY(-2px);
}

.btn-print {
    background: linear-gradient(135deg, #2196F3, #1976D2);
    color: white;
}

.btn-print:hover {
    background: linear-gradient(135deg, #1976D2, #1565C0);
    transform: translateY(-2px);
}

.btn-back {
    background: #666;
    color: white;
    margin-bottom: 20px;
    padding: 8px 20px;
    font-size: 16px;
}

.btn-back:hover {
    background: #555;
}

/* 题目区域样式 - A4竖版预览 */
.problems-container {
    background: white;
    border-radius: 4px;
    padding: 15mm 12mm;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    /* A4竖版尺寸：210mm x 297mm */
    width: 210mm;
    min-height: 297mm;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
}

.problems-header {
    text-align: center;
    margin-bottom: 8mm;
    flex-shrink: 0;
}

.problems-title {
    font-size: 20px;
    margin-bottom: 8px;
    color: #333;
}

.problems-info {
    color: #666;
    font-size: 14px;
}

/* 横式布局 - 填满整页 */
.problems-horizontal {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px 12px;
    flex: 1;
    align-content: space-evenly;
}

.problem-horizontal {
    font-size: 20px;
    padding: 8px;
    display: flex;
    align-items: center;
}

.problem-horizontal .index {
    min-width: 35px;
    color: #999;
}

.problem-horizontal .num {
    min-width: 30px;
    text-align: center;
}

.problem-horizontal .op {
    min-width: 20px;
    text-align: center;
    color: black;
    font-weight: bold;
}

.problem-horizontal .equals {
    margin: 0 6px;
}

.problem-horizontal .answer-box {
    border-bottom: 2px solid #333;
    min-width: 45px;
    height: 25px;
}

/* 数字分解配置区样式 */
.decompose-options {
    display: none;
    flex-basis: 100%;
    margin-top: 10px;
    padding: 15px;
    background: #f9f9f9;
    border-radius: 8px;
    border: 1px dashed #ddd;
}

.decompose-options.show {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
}

/* 树形分解网格布局 */
.problems-tree-grid {
    display: grid;
    gap: 15px 10px;
    flex: 1;
    align-content: start;
    padding: 10px 0;
}

/* 树形分解题目样式 */
.problem-tree {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px;
    min-width: 80px;
}

/* 顶部数字 */
.tree-top {
    font-size: 22px;
    font-weight: bold;
    margin-bottom: 5px;
}

/* 分支线容器 (SVG) */
.tree-branches-svg {
    height: 30px;
    width: 100%;
    margin-bottom: 5px;
}

/* 底部数字/方框容器 */
.tree-bottom {
    display: flex;
    justify-content: space-between;
    width: 100%;
}

.tree-node-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}



/* 底部方框 */
.tree-box {
    width: 28px;
    height: 28px;
    border: 2px solid #333;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

/* 底部数字（已填的） */
.tree-num {
    width: 28px;
    height: 28px;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 竖式布局 - 填满整页 */
.problems-vertical {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 15px 20px;
    flex: 1;
    align-content: space-evenly;
}

.problem-vertical {
    font-size: 18px;
    font-family: 'Courier New', monospace;
    text-align: right;
    padding: 8px;
}

.problem-vertical .line {
    padding: 3px 8px;
    min-width: 60px;
    display: inline-block;
}

.problem-vertical .second-line {
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

.problem-vertical .op {
    color: #4CAF50;
    font-weight: bold;
    margin-right: 3px;
}

.problem-vertical .divider {
    border-top: 2px solid #333;
    margin: 3px 0;
}

.problem-vertical .answer-line {
    min-height: 22px;
}

/* 菜单页面样式 */
.menu-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 60vh;
    gap: 40px;
    flex-wrap: wrap;
}

.menu-card {
    background: white;
    border-radius: 16px;
    padding: 40px;
    width: 300px;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s, box-shadow 0.3s;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.menu-card:hover {
    transform: translateY(-10px);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
}

.menu-icon {
    font-size: 60px;
    margin-bottom: 20px;
}

.menu-title {
    font-size: 24px;
    font-weight: bold;
    color: #333;
    margin-bottom: 10px;
}

.menu-desc {
    color: #666;
    font-size: 14px;
    line-height: 1.5;
}

/* 打印样式 */
@media print {
    body {
        background: white;
        padding: 0;
        margin: 0;
        font-size: 12pt;
    }

    .settings-panel,
    h1,
    .btn-back {
        display: none !important;
    }

    .container {
        max-width: 100%;
        padding: 0;
    }

    .problems-container {
        box-shadow: none;
        padding: 10mm 12mm;
        border-radius: 0;
        width: 100%;
        height: auto;
        min-height: 100%;
        display: flex;
        flex-direction: column;
    }

    /* 确保标题和题目在一起 */
    .problems-header {
        margin-bottom: 5mm;
        page-break-after: avoid;
        flex-shrink: 0;
    }

    .problems-title {
        font-size: 16pt;
        margin-bottom: 3mm;
    }

    .problems-info {
        font-size: 11pt;
        margin-bottom: 0;
    }

    /* 横式打印布局 - 填满整页 */
    .problems-horizontal {
        grid-template-columns: repeat(4, 1fr);
        gap: 3mm 5mm;
        flex: 1;
        align-content: space-evenly;
        page-break-before: avoid;
    }

    .problem-horizontal {
        font-size: 12pt;
        padding: 1mm 0;
        page-break-inside: avoid;
    }

    .problem-horizontal .num {
        min-width: 28px;
    }

    .problem-horizontal .op {
        margin: 0 3px;
    }

    .problem-horizontal .equals {
        margin: 0 3px;
    }

    .problem-horizontal .answer-box {
        min-width: 35px;
        height: 18px;
    }

    /* 树形分解打印样式 */
    .problems-tree-grid {
        gap: 4mm 3mm;
        align-content: start;
    }

    .problem-tree {
        padding: 2mm;
        min-width: 18mm;
        page-break-inside: avoid;
    }

    .tree-top {
        font-size: 14pt;
        margin-bottom: 2mm;
    }

    .tree-branches-svg {
        height: 8mm;
    }

    .tree-box {
        width: 7mm;
        height: 7mm;
        font-size: 11pt;
    }

    .tree-num {
        width: 7mm;
        height: 7mm;
        font-size: 18pt;
    }

    /* 竖式打印布局 - 填满整页 */
    .problems-vertical {
        grid-template-columns: repeat(6, 1fr);
        gap: 4mm 6mm;
        flex: 1;
        align-content: space-evenly;
        page-break-before: avoid;
    }

    .problem-vertical {
        font-size: 11pt;
        padding: 2mm;
        page-break-inside: avoid;
    }

    .problem-vertical .line {
        padding: 1mm 3mm;
        min-width: 40px;
    }

    .problem-vertical .answer-line {
        min-height: 16px;
    }

    @page {
        size: A4 portrait;
        margin: 8mm;
    }

    /* 分页符控制 */
    .page-break {
        page-break-before: always;
    }
}

/* 响应式调整 */
@media (max-width: 600px) {
    .settings-row {
        flex-direction: column;
    }

    .setting-group {
        min-width: 100%;
        max-width: 100%;
    }

    h1 {
        font-size: 22px;
    }

    .menu-container {
        gap: 20px;
    }

    .menu-card {
        width: 100%;
        padding: 25px;
    }
}