:root {
    --pencil-color: #ffcc00;
    --paper-white: #ffffff;
    --line-blue: #a3d4ff;
    --line-red: #ffb3b3;
    --text-color: #333;
    --correct-red: #ff4757;
    --incorrect-gray: #747d8c;
    --grade-1: #ff6b81;
    --grade-2: #1e90ff;
    --grade-3: #ffa502;
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Zen Maru Gothic', sans-serif;
    background-color: #f0f8ff;
    color: var(--text-color);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

.notebook-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    background:
        linear-gradient(90deg, var(--line-blue) 1px, transparent 1px) 0 0,
        linear-gradient(var(--line-blue) 1px, transparent 1px) 0 0;
    background-size: 40px 40px;
    opacity: 0.3;
}

.header-decoration {
    padding: 20px;
    display: flex;
    justify-content: space-around;
    font-size: 2rem;
}

.supplies {
    animation: bounce 3s ease-in-out infinite;
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0) rotate(0);
    }

    50% {
        transform: translateY(-10px) rotate(10deg);
    }
}

.container {
    max-width: 700px;
    margin: 20px auto;
    padding: 20px;
    width: 100%;
    flex: 1;
}

.pencil-progress-container {
    height: 40px;
    background: #e1eaf3;
    border-radius: 20px;
    margin-bottom: 30px;
    position: relative;
    overflow: hidden;
    border: 3px solid #cedae7;
}

.pencil-head {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.5rem;
    z-index: 2;
    transition: left 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.pencil-trace {
    height: 100%;
    width: 0;
    background: var(--pencil-color);
    transition: width 0.5s ease;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.1);
}

.screen {
    display: none;
    background: white;
    padding: 40px 30px;
    border-radius: 15px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
    border: 1px solid #ddd;
    text-align: center;
    position: relative;
    border-right: 15px solid #bdc3c7;
    /* ノートの綴じ目風 */
}

.screen.active {
    display: block;
    animation: turnPage 0.4s ease-out;
}

@keyframes turnPage {
    from {
        transform: rotateY(-10deg);
        opacity: 0;
    }

    to {
        transform: rotateY(0);
        opacity: 1;
    }
}

.badge-kids {
    display: inline-block;
    padding: 5px 20px;
    background: var(--grade-1);
    color: white;
    font-weight: 900;
    border-radius: 50px;
    margin-bottom: 20px;
}

h1 {
    font-size: 2.8rem;
    color: #2c3e50;
    margin-bottom: 20px;
    line-height: 1.2;
}

.drill-illustration {
    font-size: 6rem;
    margin: 30px 0;
}

.btn {
    padding: 15px 40px;
    font-size: 1.3rem;
    font-weight: 700;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: 0.3s;
    font-family: 'Zen Maru Gothic', sans-serif;
    box-shadow: 0 5px 0 #7f8c8d;
}

.btn:active {
    transform: translateY(3px);
    box-shadow: none;
}

.btn.jumbo {
    background: var(--grade-2);
    color: white;
    font-size: 1.5rem;
    padding: 18px 50px;
    box-shadow: 0 6px 0 #2980b9;
}

.back-link {
    display: block;
    margin-top: 25px;
    color: #7f8c8d;
    text-decoration: none;
    font-weight: bold;
}

.quiz-info {
    display: flex;
    justify-content: space-between;
    font-weight: bold;
    color: #7f8c8d;
    margin-bottom: 10px;
}

.grade-label {
    padding: 5px 15px;
    border-radius: 5px;
    color: white;
    background: var(--grade-1);
    display: inline-block;
    margin-bottom: 20px;
}

.question-paper {
    background: #fff9c4;
    /* 藁半紙風の色 */
    padding: 30px;
    border-radius: 10px;
    border: 2px dashed #d1ccc0;
    margin-bottom: 30px;
}

#question-text {
    font-size: 1.8rem;
    margin-bottom: 20px;
    color: #2f3542;
}

.kanji-box {
    font-size: 5rem;
    font-weight: 700;
    color: #2f3542;
    height: 120px;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 3px solid #eee;
    background: white;
    width: 140px;
    margin: 0 auto;
}

.choices-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.choice-btn {
    padding: 20px;
    font-size: 1.5rem;
    font-weight: 700;
    background: white;
    border: 3px solid #e1eaf3;
    border-radius: 15px;
    cursor: pointer;
    transition: 0.2s;
    font-family: 'Zen Maru Gothic', sans-serif;
}

.choice-btn:hover {
    background: #f1f2f6;
    border-color: #ced6e0;
}

.choice-btn.correct {
    background: #ffeb3b;
    border-color: var(--correct-red);
    color: var(--correct-red);
}

.choice-btn.incorrect {
    background: #f1f2f6;
    color: #a4b0be;
    border-color: #ced6e0;
}

.feedback-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 40px;
    z-index: 10;
    border-radius: 15px;
}

.hanamaru-icon {
    font-size: 8rem;
    margin-bottom: 20px;
    animation: pop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes pop {
    0% {
        transform: scale(0);
        opacity: 0;
    }

    80% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.explanation-balloon {
    background: #fff;
    padding: 20px;
    border-radius: 15px;
    border: 3px solid var(--grade-2);
    margin-bottom: 20px;
    position: relative;
    max-width: 100%;
    text-align: left;
}

.explanation-balloon::after {
    content: '';
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    border: 10px solid transparent;
    border-bottom-color: var(--grade-2);
}

.btn.next-page {
    background: var(--grade-2);
    color: white;
    width: 100%;
    box-shadow: 0 5px 0 #2980b9;
}

.final-score-box {
    margin: 30px 0;
}

#final-results {
    font-size: 2rem;
    font-weight: 900;
    color: var(--correct-red);
}

.rank-display {
    font-size: 3.5rem;
    margin: 20px 0;
    font-weight: 900;
    color: var(--grade-3);
    text-shadow: 2px 2px 0 #fff, -2px -2px 0 #fff;
}

footer {
    text-align: center;
    padding: 20px;
    font-size: 0.8rem;
    color: #7f8c8d;
}

.hidden {
    display: none !important;
}

@media (max-width: 600px) {
    .container {
        padding: 10px;
    }

    .screen {
        padding: 30px 15px;
    }

    h1 {
        font-size: 2rem;
    }

    .choices-container {
        grid-template-columns: 1fr;
    }
}