:root {
    --navy-bg: #0f2740;
    --navy-panel: #173754;
    --navy-text: #0f2740;
    --navy-muted: #5b6b7c;
    --orange: #f28c28;
    --orange-hover: #db7412;
    --surface: #f2f4f7;
    --surface-2: #e8edf2;
    --white: #ffffff;
    --border: #d5dce5;
    --success: #157347;
    --danger: #b42318;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 32px 20px 48px;
    font-family: "Segoe UI", Arial, sans-serif;
    background: var(--navy-bg);
    color: var(--white);
}

h1 {
    max-width: 1100px;
    margin: 0 auto 20px;
    font-size: clamp(2rem, 4vw, 3rem);
    line-height: 1.1;
    color: var(--white);
}

.controls,
.meta-panel,
#worksheet,
#scoreBox,
#controlsHelp,
#settingsStatus,
#answerSheet {
    max-width: 1100px;
    margin-left: auto;
    margin-right: auto;
}

.controls,
.meta-panel {
    background: var(--navy-panel);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 18px;
    padding: 20px;
    margin-bottom: 18px;
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.controls label {
    font-weight: 700;
    color: #f5f7fa;
    margin: 0;
    line-height: 1.2;
}

.controls input,
.controls select,
.controls button {
    margin: 0;
    min-height: 44px;
    padding: 10px 12px;
    font-size: 15px;
    border-radius: 10px;
}

.controls input,
.controls select {
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: var(--white);
    color: var(--navy-text);
}

.controls input:focus,
.controls select:focus,
.answer-input:focus {
    outline: 3px solid rgba(242, 140, 40, 0.22);
    border-color: var(--orange);
}

.controls button {
    border: none;
    cursor: pointer;
    background: var(--orange);
    color: #fff;
    font-weight: 700;
    transition: background 0.18s ease;
}

.controls button:hover {
    background: var(--orange-hover);
}

.controls-help {
    max-width: 1100px;
    margin: -6px auto 18px;
    display: grid;
    gap: 8px;
}

.help-item {
    background: rgba(255, 255, 255, 0.1);
    color: #e9f0f7;
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 0.95rem;
}

.help-item strong {
    color: #ffffff;
}

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: #f5f7fa;
}

.checkbox-label input {
    accent-color: var(--orange);
}

.meta-panel {
    color: #f5f7fa;
}

.level-summary {
    margin-top: 6px;
    color: #d8e0e8;
    display: grid;
    gap: 10px;
}

.current-level {
    font-weight: 600;
}

.level-guide-title {
    color: #ffffff;
    font-weight: 700;
    margin-top: 2px;
}

.level-guide-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.level-guide-row span {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 999px;
    padding: 6px 10px;
    color: #eef4fa;
    font-size: 0.95rem;
}

.score-box {
    background: var(--white);
    color: var(--navy-text);
    border-left: 6px solid var(--orange);
    border-radius: 14px;
    padding: 14px 16px;
    margin-bottom: 18px;
    font-size: 18px;
    font-weight: 700;
}

.settings-status {
    background: rgba(255, 255, 255, 0.12);
    color: #f5f7fa;
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 18px;
}

#worksheet {
    display: grid;
    gap: 16px;
}

.question-card {
    background: var(--surface);
    color: var(--navy-text);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 18px;
}

.question-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: start;
    gap: 12px;
}

.regen-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.question-text {
    margin-bottom: 14px;
    line-height: 1.7;
    font-size: 1rem;
    flex: 1 1 320px;
}

.question-text strong {
    color: var(--navy-text);
}

.regen-button {
    border: none;
    border-radius: 10px;
    padding: 10px 12px;
    background: var(--orange);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}

.regen-secondary {
    background: #d9731d;
}

.regen-button:hover {
    background: var(--orange-hover);
}

.small-note {
    display: block;
    margin-top: 7px;
    font-size: 0.92em;
    color: var(--navy-muted);
    font-weight: 600;
}

.answer-input {
    width: 320px;
    max-width: 100%;
    padding: 12px 14px;
    font-size: 16px;
    border: 2px solid #bcc8d4;
    border-radius: 10px;
    background: #ffffff;
    color: var(--navy-text);
}

.working-space-area {
    margin-top: 12px;
    min-height: 88px;
    border: 2px dashed #c5cfda;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.68);
}

.options {
    margin-top: 12px;
    display: grid;
    gap: 10px;
}

.option-row {
    display: block;
    margin: 0;
    padding: 10px 12px;
    background: var(--white);
    border: 1px solid #cfd7e0;
    border-radius: 10px;
    color: var(--navy-text);
}

.option-row input {
    accent-color: var(--orange);
    margin-right: 10px;
}

.feedback {
    margin-top: 12px;
    font-weight: 700;
}

.correct {
    color: var(--success);
}

.incorrect {
    color: var(--danger);
}

.correct-answer {
    margin-top: 8px;
    padding: 10px 12px;
    border-radius: 10px;
    background: #fff7ef;
    border-left: 5px solid var(--orange);
    color: var(--navy-text);
    font-weight: 600;
}

.hidden {
    display: none;
}

.answer-sheet {
    margin-top: 20px;
}

.answer-sheet.hidden {
    display: none !important;
}

.answer-sheet-card {
    background: var(--surface);
    color: var(--navy-text);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 18px;
}

.answer-sheet-card h2 {
    margin: 0 0 16px;
    color: var(--navy-text);
}

.answer-sheet-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 10px 16px;
}

.answer-row {
    background: var(--white);
    border: 1px solid #cfd7e0;
    border-radius: 10px;
    padding: 10px 12px;
    display: flex;
    gap: 8px;
}

@media (max-width: 720px) {
    body {
        padding: 20px 14px 36px;
    }

    .controls,
    .meta-panel,
    .question-card {
        padding: 16px;
    }

    .controls-help {
        margin-top: -4px;
    }

    .question-header {
        flex-direction: column;
        align-items: stretch;
    }

    .regen-actions {
        width: 100%;
    }

    .regen-button {
        flex: 1 1 0;
    }

    .controls input,
    .controls select,
    .controls button {
        width: 100%;
    }

    .checkbox-label {
        width: 100%;
    }
}

@media print {
    .controls,
    .controls-help,
    .meta-panel,
    .score-box,
    .settings-status,
    .feedback,
    .regen-button {
        display: none !important;
    }

    body {
        background: #ffffff;
        color: #000;
        margin: 10mm;
        padding: 0;
    }

    .question-card {
        background: #ffffff;
        border: 1px solid #c8c8c8;
        break-inside: avoid;
    }

    .working-space-area {
        min-height: 140px;
        border: 1px dashed #999;
        background: transparent;
    }

    .question-text,
    .small-note,
    .correct-answer {
        color: #000 !important;
        background: transparent !important;
    }

    .answer-input {
        border: 1px solid #999;
    }

    .answer-sheet {
        display: block !important;
        page-break-before: always;
        margin-top: 0;
    }

    .answer-sheet-card,
    .answer-row {
        background: #ffffff;
        color: #000;
        border: 1px solid #c8c8c8;
        box-shadow: none;
    }
}
