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

body {
    min-height: 100vh;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-family: "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", sans-serif;
    background: linear-gradient(135deg, #E3F2FD 0%, #FFF8E1 48%, #E8F5E9 100%);
    color: #263238;
}

.entry-back-link {
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 180;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 18px;
    border: 2px solid rgba(76, 175, 80, 0.3);
    border-radius: 999px;
    background: linear-gradient(135deg, #E8F5E9, #C8E6C9);
    color: #2E7D32;
    box-shadow: 0 6px 16px rgba(46, 125, 50, 0.16);
    font-size: 15px;
    font-weight: 800;
    line-height: 1;
    text-decoration: none;
    transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.entry-back-link:hover {
    background: linear-gradient(135deg, #F1F8E9, #C8E6C9);
    box-shadow: 0 8px 20px rgba(46, 125, 50, 0.2);
    transform: translateY(-1px);
}

.entry-back-link:active {
    transform: translateY(0);
}

.header {
    text-align: center;
    margin-bottom: 20px;
    animation: fadeInDown 0.7s ease;
}

.header h1 {
    margin-bottom: 8px;
    color: #1565C0;
    font-size: 40px;
    line-height: 1.2;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.08);
}

.header .subtitle {
    color: #607D8B;
    font-size: 18px;
}

.stats-bar {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 16px;
    margin-bottom: 20px;
    animation: fadeIn 0.8s ease;
}

.stat-card {
    min-width: 96px;
    padding: 12px 22px;
    border-radius: 16px;
    background: #FFFFFF;
    box-shadow: 0 4px 14px rgba(31, 73, 125, 0.1);
    text-align: center;
}

.stat-card .label {
    margin-bottom: 4px;
    color: #78909C;
    font-size: 14px;
}

.stat-card .value {
    color: #263238;
    font-size: 28px;
    font-weight: 800;
}

.stat-card .value.correct {
    color: #43A047;
}

.stat-card .value.wrong {
    color: #F4511E;
}

.stat-card .value.streak {
    color: #FB8C00;
}

.progress-container {
    width: 100%;
    max-width: 760px;
    margin-bottom: 20px;
}

.progress-bar {
    height: 12px;
    overflow: hidden;
    border-radius: 999px;
    background: #DDE7EE;
}

.progress-fill {
    width: 0;
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, #42A5F5, #66BB6A);
    transition: width 0.35s ease;
}

.progress-text {
    margin-top: 7px;
    color: #607D8B;
    font-size: 14px;
    text-align: center;
}

.main-card {
    position: relative;
    width: 100%;
    max-width: 760px;
    padding: 38px;
    overflow: hidden;
    border-radius: 24px;
    background: #FFFFFF;
    box-shadow: 0 10px 34px rgba(31, 73, 125, 0.13);
    text-align: center;
    animation: fadeInUp 0.7s ease;
}

.unit-tag {
    display: inline-block;
    min-height: 30px;
    padding: 6px 16px;
    border-radius: 999px;
    background: #E3F2FD;
    color: #1565C0;
    font-size: 15px;
    font-weight: 700;
}

.difficulty-status {
    margin-top: 10px;
    color: #607D8B;
    font-size: 15px;
    font-weight: 700;
}

.question-display {
    min-height: 116px;
    margin: 18px 0 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #263238;
    font-family: Consolas, "Courier New", monospace;
    font-size: 74px;
    font-weight: 800;
    line-height: 1.15;
    letter-spacing: 0;
    word-break: keep-all;
}

.hint-line {
    min-height: 34px;
    margin-bottom: 18px;
    color: #FB8C00;
    font-size: 20px;
    font-weight: 700;
}

.input-area {
    margin: 18px 0;
}

#answerInput {
    width: 100%;
    max-width: 460px;
    padding: 16px 24px;
    border: 3px solid #BBDEFB;
    border-radius: 16px;
    outline: none;
    background: #FAFAFA;
    color: #263238;
    font-family: Consolas, "Courier New", monospace;
    font-size: 36px;
    font-weight: 800;
    text-align: center;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

#answerInput:focus {
    border-color: #42A5F5;
    background: #FFFFFF;
    box-shadow: 0 0 0 4px rgba(66, 165, 245, 0.18);
}

#answerInput.correct {
    border-color: #4CAF50;
    background: #E8F5E9;
    animation: pulse 0.45s ease;
}

#answerInput.wrong {
    border-color: #FF5722;
    background: #FFEBEE;
    animation: shake 0.45s ease;
}

.feedback {
    min-height: 58px;
    margin-top: 18px;
    font-size: 20px;
}

.correct-msg {
    color: #43A047;
    font-weight: 800;
}

.wrong-msg {
    color: #F4511E;
    font-weight: 700;
}

.info-msg {
    color: #1565C0;
    font-weight: 700;
}

.correct-answer {
    color: #43A047;
    font-weight: 900;
}

.streak-msg {
    margin-top: 8px;
    color: #FB8C00;
    font-weight: 900;
}

.level-msg {
    margin-top: 8px;
    color: #1565C0;
    font-weight: 900;
}

.celebration-banner {
    position: absolute;
    left: 50%;
    top: 86px;
    z-index: 30;
    width: min(92%, 560px);
    padding: 14px 18px;
    border-radius: 16px;
    background: linear-gradient(135deg, #FFF8E1, #E8F5E9);
    color: #1565C0;
    box-shadow: 0 10px 26px rgba(31, 73, 125, 0.18);
    font-size: 20px;
    font-weight: 900;
    line-height: 1.35;
    transform: translateX(-50%);
    animation: celebrationFloat 1.6s ease forwards;
}

.celebration-10 {
    background: linear-gradient(135deg, #E3F2FD, #FFF3E0);
}

.celebration-15,
.celebration-20 {
    background: linear-gradient(135deg, #FFF3E0, #F3E5F5);
    color: #6A1B9A;
}

.celebrate-5 {
    animation: pulse 0.5s ease;
}

.celebrate-10,
.celebrate-15,
.celebrate-20 {
    box-shadow: 0 12px 38px rgba(66, 165, 245, 0.2), 0 0 0 5px rgba(255, 193, 7, 0.16);
}

.rest-reminder {
    position: fixed;
    inset: 0;
    z-index: 260;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(38, 50, 56, 0.38);
}

.rest-reminder-box {
    width: min(92vw, 460px);
    padding: 28px;
    border-radius: 22px;
    background: #FFFFFF;
    box-shadow: 0 16px 44px rgba(0, 0, 0, 0.22);
    text-align: center;
    animation: zoomIn 0.25s ease;
}

.rest-title {
    margin-bottom: 10px;
    color: #2E7D32;
    font-size: 28px;
    font-weight: 900;
}

.rest-text {
    margin-bottom: 20px;
    color: #546E7A;
    font-size: 17px;
    line-height: 1.7;
}

.btn-group {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    margin-top: 20px;
}

.btn {
    min-width: 104px;
    padding: 12px 28px;
    border: 0;
    border-radius: 12px;
    font-family: inherit;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.btn:hover {
    transform: translateY(-2px);
}

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

.btn-primary {
    background: linear-gradient(135deg, #42A5F5, #1E88E5);
    color: #FFFFFF;
    box-shadow: 0 4px 12px rgba(66, 165, 245, 0.35);
}

.btn-hint {
    background: #FFF3E0;
    color: #E65100;
}

.btn-secondary {
    background: #F2F4F6;
    color: #546E7A;
}

.control-panel {
    margin-top: 26px;
    padding-top: 22px;
    border-top: 1px dashed #D8E2EA;
}

.control-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 12px 16px;
    margin-bottom: 12px;
}

.control-label,
.check-label {
    color: #607D8B;
    font-size: 15px;
}

.check-label {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    cursor: pointer;
}

.check-label input {
    width: 17px;
    height: 17px;
}

.music-row {
    padding-top: 2px;
}

#musicVolume {
    width: 170px;
    accent-color: #42A5F5;
    cursor: pointer;
}

select {
    min-width: 126px;
    padding: 9px 14px;
    border: 2px solid #D8E2EA;
    border-radius: 10px;
    outline: none;
    background: #FFFFFF;
    color: #37474F;
    font-family: inherit;
    font-size: 15px;
    cursor: pointer;
}

select:focus {
    border-color: #42A5F5;
}

.keyboard-hint {
    margin-top: 24px;
    padding: 15px;
    border-radius: 12px;
    background: #FAFAFA;
    color: #607D8B;
    font-size: 14px;
}

.keyboard-hint kbd {
    display: inline-block;
    margin: 0 2px;
    padding: 2px 8px;
    border: 1px solid #C9D4DC;
    border-radius: 4px;
    background: #FFFFFF;
    box-shadow: 0 2px 0 #C9D4DC;
    color: #263238;
    font-family: Consolas, "Courier New", monospace;
}

.mistake-btn {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 100;
    width: 58px;
    height: 58px;
    border: 0;
    border-radius: 50%;
    background: #FF5722;
    color: #FFFFFF;
    box-shadow: 0 4px 16px rgba(255, 87, 34, 0.38);
    font-size: 24px;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.mistake-btn:hover {
    transform: scale(1.08);
}

.mistake-btn .badge {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 23px;
    height: 23px;
    display: none;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #FFC107;
    color: #263238;
    font-size: 12px;
    font-weight: 900;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(0, 0, 0, 0.48);
}

.modal-overlay.active {
    display: flex;
}

.modal {
    width: min(92vw, 640px);
    max-height: 84vh;
    overflow-y: auto;
    padding: 30px;
    border-radius: 24px;
    background: #FFFFFF;
    box-shadow: 0 16px 44px rgba(0, 0, 0, 0.2);
    animation: zoomIn 0.25s ease;
}

.modal h2 {
    margin-bottom: 20px;
    color: #1565C0;
    text-align: center;
}

.mistake-modal {
    position: relative;
}

.close-btn {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 50%;
    background: #F2F4F6;
    color: #455A64;
    font-size: 22px;
    cursor: pointer;
}

.mistake-list {
    max-height: 410px;
    overflow-y: auto;
}

.empty-text {
    padding: 42px 10px;
    color: #90A4AE;
    text-align: center;
}

.mistake-item {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    padding: 14px 4px;
    border-bottom: 1px solid #EDF2F5;
    text-align: left;
}

.mistake-question {
    margin-bottom: 6px;
    color: #263238;
    font-family: Consolas, "Courier New", monospace;
    font-size: 24px;
    font-weight: 900;
}

.mistake-answer {
    color: #607D8B;
    font-size: 14px;
}

.mistake-answer span {
    color: #F4511E;
}

.mistake-meta {
    min-width: 130px;
    color: #90A4AE;
    font-size: 12px;
    line-height: 1.55;
    text-align: right;
}

.report-card {
    text-align: center;
}

.report-score {
    margin: 14px 0;
    color: #43A047;
    font-size: 62px;
    font-weight: 900;
}

.report-detail {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    margin: 20px 0;
}

.report-item {
    padding: 13px;
    border-radius: 12px;
    background: #F5F7F8;
}

.report-item .num {
    color: #263238;
    font-size: 28px;
    font-weight: 900;
}

.report-item .txt {
    margin-top: 4px;
    color: #78909C;
    font-size: 14px;
}

.report-actions,
.mistake-actions {
    margin-top: 22px;
}

.star {
    position: absolute;
    pointer-events: none;
    font-size: 32px;
    animation: starPop 1s ease forwards;
}

.confetti {
    position: fixed;
    top: -12px;
    z-index: 80;
    width: 10px;
    height: 10px;
    pointer-events: none;
    animation: confettiFall 3s ease forwards;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-18px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(18px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes zoomIn {
    from { opacity: 0; transform: scale(0.92); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-9px); }
    40% { transform: translateX(9px); }
    60% { transform: translateX(-5px); }
    80% { transform: translateX(5px); }
}

@keyframes starPop {
    0% { transform: scale(0) rotate(0deg); opacity: 1; }
    50% { transform: scale(1.5) rotate(160deg); opacity: 1; }
    100% { transform: scale(0) rotate(320deg) translateY(-46px); opacity: 0; }
}

@keyframes celebrationFloat {
    0% { transform: translate(-50%, 12px) scale(0.92); opacity: 0; }
    18% { transform: translate(-50%, 0) scale(1.04); opacity: 1; }
    78% { transform: translate(-50%, 0) scale(1); opacity: 1; }
    100% { transform: translate(-50%, -16px) scale(0.96); opacity: 0; }
}

@keyframes confettiFall {
    0% { transform: translateY(0) rotate(0deg); opacity: 1; }
    100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

@media (max-width: 768px) {
    body {
        padding: calc(14px + env(safe-area-inset-top, 0px)) 14px 14px;
    }

    .entry-back-link {
        top: calc(10px + env(safe-area-inset-top, 0px));
        left: 10px;
        padding: 0 14px;
        font-size: 14px;
    }

    .header {
        margin-top: 48px;
    }

    .header h1 {
        font-size: 29px;
    }

    .header .subtitle {
        font-size: 16px;
    }

    .stat-card {
        min-width: 78px;
        padding: 10px 14px;
    }

    .stat-card .value {
        font-size: 24px;
    }

    .main-card {
        padding: 24px 18px;
        border-radius: 20px;
    }

    .question-display {
        min-height: 94px;
        font-size: 46px;
    }

    .hint-line {
        font-size: 17px;
    }

    #answerInput {
        max-width: 100%;
        padding: 13px 18px;
        font-size: 30px;
    }

    .btn {
        min-width: 94px;
        min-height: 44px;
        padding: 10px 18px;
        font-size: 16px;
    }

    .control-row {
        align-items: stretch;
    }

    .check-label {
        min-height: 44px;
        padding: 4px 0;
    }

    .check-label input {
        width: 22px;
        height: 22px;
        flex: 0 0 22px;
    }

    #musicVolume {
        min-height: 44px;
    }

    select {
        min-width: 150px;
        min-height: 44px;
    }

    .close-btn {
        width: 44px;
        height: 44px;
    }

    .report-detail {
        grid-template-columns: repeat(2, 1fr);
    }

    .mistake-item {
        display: block;
    }

    .mistake-meta {
        margin-top: 8px;
        text-align: left;
    }
}

@media (max-width: 420px) {
    body {
        padding: calc(10px + env(safe-area-inset-top, 0px)) 10px 10px;
    }

    .header {
        margin-bottom: 12px;
    }

    .header h1 {
        margin-bottom: 5px;
        font-size: 24px;
    }

    .header .subtitle {
        font-size: 14px;
    }

    .stats-bar {
        flex-wrap: nowrap;
        gap: 6px;
        width: 100%;
        margin-bottom: 12px;
    }

    .stat-card {
        flex: 1 1 0;
        min-width: 0;
        padding: 7px 3px;
        border-radius: 12px;
    }

    .stat-card .label {
        margin-bottom: 2px;
        font-size: 12px;
    }

    .stat-card .value {
        font-size: 21px;
    }

    .progress-container {
        margin-bottom: 12px;
    }

    .progress-bar {
        height: 10px;
    }

    .main-card {
        padding: 16px 12px;
        border-radius: 18px;
    }

    .unit-tag {
        min-height: 26px;
        padding: 4px 12px;
        font-size: 13px;
    }

    .difficulty-status {
        margin-top: 6px;
        font-size: 13px;
    }

    .question-display {
        min-height: 70px;
        margin: 10px 0 6px;
        font-size: 38px;
    }

    .hint-line {
        min-height: 26px;
        margin-bottom: 10px;
        font-size: 15px;
    }

    .input-area {
        margin: 10px 0;
    }

    #answerInput {
        padding: 10px 14px;
        font-size: 28px;
    }

    .feedback {
        min-height: 44px;
        margin-top: 10px;
        font-size: 17px;
    }

    .btn-group {
        gap: 8px;
        margin-top: 12px;
    }

    .btn {
        min-width: 88px;
        padding: 10px 14px;
    }

    .control-panel {
        margin-top: 16px;
        padding-top: 14px;
    }

    .control-row {
        gap: 8px 10px;
        margin-bottom: 8px;
    }

    .control-label,
    .check-label {
        display: inline-flex;
        align-items: center;
        font-size: 14px;
    }

    .control-label {
        min-height: 44px;
        white-space: nowrap;
    }

    .control-panel .control-row:not(.music-row) {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr);
        align-items: center;
        justify-content: normal;
    }

    .control-panel .control-row:not(.music-row) select {
        width: 100%;
        min-width: 0;
    }

    .control-panel .control-row:not(.music-row) .check-label {
        grid-column: 1 / -1;
        justify-self: start;
    }

    .mistake-mode-label {
        display: none;
    }

    .music-row {
        align-items: center;
        justify-content: flex-start;
    }

    select {
        flex: 1 1 132px;
        min-width: 132px;
        padding: 8px 10px;
    }

    #musicVolume {
        width: 140px;
        flex: 1 1 140px;
    }

    .keyboard-hint {
        display: none;
    }

    .mistake-btn {
        right: 6px;
        bottom: 96px;
        width: 44px;
        height: 44px;
        font-size: 20px;
    }

    .mistake-btn .badge {
        top: -6px;
        right: -4px;
    }

    .modal-overlay {
        padding: 8px;
    }

    .modal.report-card {
        width: calc(100vw - 16px);
        max-height: calc(100dvh - 16px);
        padding: 14px 12px;
        border-radius: 16px;
        overflow: hidden;
    }

    .report-card h2 {
        margin-bottom: 6px;
        font-size: 20px;
        line-height: 1.2;
    }

    .report-score {
        margin: 6px 0;
        font-size: 36px;
        line-height: 1.05;
    }

    .report-detail {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 6px;
        margin: 8px 0;
    }

    .report-item {
        padding: 7px 6px;
        border-radius: 9px;
    }

    .report-item .num {
        font-size: 20px;
        line-height: 1.1;
    }

    .report-item .txt {
        margin-top: 2px;
        font-size: 11px;
    }

    .report-actions {
        margin-top: 8px;
    }

    .report-card .btn {
        min-height: 38px;
        padding: 8px 12px;
        font-size: 14px;
    }
}
