*{
    box-sizing:border-box;
}

:root{
    font-family:"Yu Gothic","Meiryo",sans-serif;
    color:#222;
    background:#f3f5f7;
}

body{
    margin:0;
    background:#f3f5f7;
    color:#222;
    line-height:1.7;
}

button,
select{
    font:inherit;
}

.app-header{
    background:#173b67;
    color:white;
    padding:28px 20px;
}

.header-inner{
    width:min(960px,100%);
    margin:0 auto;
}

.app-header h1{
    margin:2px 0 4px;
    font-size:32px;
    line-height:1.3;
}

.app-header p{
    margin:0;
}

.app-label{
    font-size:14px;
    font-weight:bold;
    opacity:.9;
}

main{
    width:min(960px,calc(100% - 32px));
    margin:28px auto 60px;
}

.control-panel{
    background:white;
    border:1px solid #d9dee5;
    border-radius:12px;
    padding:28px;
    box-shadow:0 4px 14px rgba(0,0,0,.06);
}

.panel-heading{
    display:flex;
    justify-content:space-between;
    align-items:flex-start;
    gap:20px;
    margin-bottom:20px;
}

.panel-heading h2{
    margin:0;
}

.step-label{
    margin:0 0 2px;
    color:#1768ac;
    font-size:13px;
    font-weight:bold;
    letter-spacing:.08em;
}

.version-label{
    display:inline-flex;
    align-items:center;
    min-height:32px;
    border-radius:999px;
    padding:4px 12px;
    background:#eaf3fb;
    color:#12558d;
    font-size:14px;
    font-weight:bold;
}

.form-grid{
    display:grid;
    grid-template-columns:repeat(2,minmax(180px,1fr));
    gap:20px;
}

.form-item{
    display:flex;
    flex-direction:column;
    gap:7px;
}

.form-item-wide{
    grid-column:1 / -1;
}

.form-item label{
    font-weight:bold;
}

.form-item select{
    width:100%;
    min-height:48px;
    padding:8px 12px;
    border:1px solid #9ba8b6;
    border-radius:7px;
    background:white;
    font-size:16px;
}

.form-item select:focus{
    outline:3px solid rgba(23,104,172,.18);
    border-color:#1768ac;
}

.form-item option:disabled{
    color:#7d8791;
}

.field-note{
    margin:0;
    color:#5c6873;
    font-size:13px;
}

.difficulty-guide{
    display:flex;
    gap:10px;
    align-items:baseline;
    margin-top:22px;
    padding:12px 14px;
    border-left:5px solid #1768ac;
    background:#f1f6fa;
}

.difficulty-guide strong{
    flex:0 0 auto;
    color:#173b67;
}

.button-area{
    display:flex;
    flex-wrap:wrap;
    gap:12px;
    margin-top:24px;
}

button{
    min-height:50px;
    border:none;
    border-radius:8px;
    padding:10px 24px;
    font-size:16px;
    font-weight:bold;
    cursor:pointer;
    background:#1768ac;
    color:white;
}

button:hover{
    background:#12558d;
}

button:focus-visible{
    outline:3px solid rgba(23,104,172,.28);
    outline-offset:2px;
}

.secondary-button{
    background:#e7edf3;
    color:#22303d;
}

.secondary-button:hover{
    background:#d5e0ea;
}

.status-message{
    min-height:1.7em;
    margin:16px 0 0;
    color:#4f5c68;
}

.worksheet-section{
    margin-top:32px;
}

.problem-page,
.answer-page{
    background:white;
    border:1px solid #cfd5dc;
    padding:36px;
    margin-bottom:28px;
    box-shadow:0 4px 14px rgba(0,0,0,.06);
}

.worksheet-heading{
    display:flex;
    justify-content:space-between;
    align-items:flex-end;
    gap:20px;
    border-bottom:3px solid #222;
    padding-bottom:12px;
}

.worksheet-heading h2{
    margin:0;
    font-size:28px;
}

.worksheet-brand{
    margin:0 0 2px;
    color:#555;
    font-size:13px;
}

.student-info{
    min-width:230px;
    display:flex;
    align-items:flex-end;
    gap:10px;
}

.name-line{
    display:inline-block;
    flex:1;
    height:28px;
    border-bottom:1px solid #222;
}

.worksheet-meta{
    display:flex;
    flex-wrap:wrap;
    gap:18px;
    margin-top:10px;
    color:#4d5964;
    font-size:14px;
}

.instruction{
    margin:24px 0;
    padding:10px 14px;
    border-left:5px solid #173b67;
    background:#f1f5f8;
    font-weight:bold;
}

#questions,
#answers{
    background:white;
    border:1px solid #cfd5dc;
    padding:20px;
    margin-top:10px;
}

#questions{
    columns:2;
    column-gap:56px;
}

#questions p{
    break-inside:avoid;
    min-height:54px;
    margin:0 0 18px;
    font-size:20px;
    font-weight:bold;
}

#answers p{
    break-inside:avoid;
    margin:0 0 16px;
}

.answer-explanation{
    color:#4a5560;
}

.answer-note{
    margin:20px 0;
    padding:12px 16px;
    border:1px solid #9ba8b6;
    background:#f7f8fa;
}

@media (max-width:650px){
    .app-header h1{
        font-size:26px;
    }

    .form-grid{
        grid-template-columns:1fr;
    }

    .form-item-wide{
        grid-column:auto;
    }

    .difficulty-guide,
    .worksheet-heading{
        align-items:flex-start;
        flex-direction:column;
    }

    .student-info{
        width:100%;
        min-width:0;
    }

    #questions{
        columns:1;
    }

    .problem-page,
    .answer-page{
        padding:24px;
    }
}

@media print{
    @page{
        size:A4;
        margin:12mm;
    }

    body{
        background:white;
    }

    .app-header,
    .control-panel{
        display:none;
    }

    main{
        width:100%;
        margin:0;
    }

    .worksheet-section{
        margin:0;
    }

    .problem-page,
    .answer-page{
        border:none;
        box-shadow:none;
        margin:0;
        padding:0;
    }

    .problem-page{
        page-break-after:always;
    }

    .worksheet-heading > div:first-child{
        flex:1 1 auto;
        min-width:0;
    }

    .worksheet-heading h2{
        font-size:20px;
        line-height:1.3;
        white-space:nowrap;
        letter-spacing:-.02em;
    }

    .student-info{
        flex:0 0 170px;
        min-width:170px;
    }

    #questions{
        columns:2;
    }

    button{
        display:none;
    }
}
