body {
    font-family: 'Comic Sans MS', 'Chalkboard SE', 'Marker Felt', sans-serif; /* 可爱字体 */
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-color: #f0e4f7; /* 淡紫色背景 */
    margin: 0;
    padding: 10px; /* Add some padding to prevent content touching edges */
    box-sizing: border-box; /* Ensure padding doesn't expand body beyond 100% */
}

.container {
    background-color: #ffffff;
    padding: 25px;
    border-radius: 15px; /* 更圆的边角 */
    box-shadow: 0 5px 15px rgba(0,0,0,0.15);
    text-align: center;
    width: 90%; /* Control max width */
    max-width: 600px; /* Set a max-width for larger screens */
    display: flex; /* Ensure it is a flex container */
    flex-direction: column; /* Stack children vertically */
    max-height: 100vh; /* Constrain height to viewport */
    overflow-y: auto; /* Ensure this is active for the container */
    padding-bottom: 50px; /* Added significant padding at the bottom of the container */
    box-sizing: border-box; /* Ensure padding is included in height calculation if not already */
}

h1 {
    color: #6a0dad; /* 紫色标题 */
    margin-bottom: 25px;
}

.difficulty-selection, .game-area, #feedback, #score-display {
    margin-bottom: 25px;
}

#numbers-display, #options-display, #selected-notes {
    display: flex;
    justify-content: center;
    gap: 12px; /* 略微增加间距 */
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.number-card, .option-card, .selected-card {
    padding: 10px 15px; /* Base padding */
    border: 2px solid #d1c4e9;
    border-radius: 10px;
    background-color: #f3e5f5;
    font-size: 1.1em;  /* Base font size */
    min-width: 55px;   /* Base min-width, reduced slightly */
    text-align: center;
    box-sizing: border-box; /* Ensure padding/border included in width/height */
}

.option-card {
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, background-color 0.2s ease;
    /* Adjusting padding specifically for option cards if they need to be smaller */
    padding: 8px 10px; 
    font-size: 1em; /* Slightly smaller font for option cards specifically */
    min-width: 50px; /* Further reduced min-width for option cards */
}

.option-card:hover {
    background-color: #e1bee7; /* 悬停时变深的淡紫色 */
    transform: translateY(-3px); /* 轻微上浮效果 */
}

.option-card .option-note-name {
    font-weight: bold;
    font-size: 1.1em;
    color: #4a148c; /* 深紫色音名 */
}

.option-card .option-solfege {
    font-size: 0.9em;
    color: #7b1fa2; /* 中紫色唱名 */
}

/* Selected card styling to match option card structure */
.selected-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.selected-card .option-note-name {
    font-weight: bold;
    font-size: 1.1em;
    color: #4a148c;
}

.selected-card .option-solfege {
    font-size: 0.9em;
    color: #7b1fa2;
}


button {
    padding: 12px 20px;
    font-size: 1em;
    border: none;
    border-radius: 8px; /* 更圆的按钮 */
    background-color: #7e57c2; /* 可爱的紫色按钮 */
    color: white;
    cursor: pointer;
    margin: 5px;
    transition: background-color 0.2s ease; /* 平滑过渡 */
}

button:hover {
    background-color: #5e35b1; /* 悬停时变深 */
}

button:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
}

#feedback {
    font-size: 1.1em;
    padding: 10px;
    border-radius: 5px;
}

#feedback.correct {
    color: #388e3c; /* 深绿色 */
    background-color: #e8f5e9; /* 淡绿色背景 */
    font-weight: bold;
}

#feedback.incorrect {
    color: #d32f2f; /* 深红色 */
    background-color: #ffebee; /* 淡红色背景 */
    font-weight: bold;
}

#score-display {
    font-size: 1.2em;
    color: #6a0dad;
}

/* Style for select dropdown */
select#difficulty {
    padding: 8px 12px;
    border-radius: 8px;
    border: 2px solid #d1c4e9;
    background-color: #f3e5f5;
    font-family: inherit; /* Use the same font as the body */
    font-size: 0.95em;
    color: #4a148c;
    margin-right: 10px;
}

/* Style for labels */
label[for="difficulty"] {
    color: #6a0dad;
    font-weight: bold;
    margin-right: 5px;
}

/* Game Mode Selection */
.mode-selection-area {
    margin-bottom: 25px;
    display: flex;
    justify-content: center;
    gap: 10px;
}

.mode-button {
    padding: 10px 20px;
    font-size: 1em;
    border: 2px solid transparent; /* Transparent border to maintain size on active */
    border-radius: 8px;
    background-color: #e1bee7; /* Lighter purple for inactive mode buttons */
    color: #6a0dad;
    cursor: pointer;
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

.mode-button.active-mode {
    background-color: #7e57c2; /* Purple from main buttons for active mode */
    color: white;
    border-color: #5e35b1; /* Darker border for active state */
    font-weight: bold;
}

.mode-button:not(.active-mode):hover {
    background-color: #ce93d8;
}

/* Game Modes Wrapper and Cards */
.game-modes-wrapper {
    position: relative;
    height: 380px; 
    margin-bottom: 20px; /* Keep this reasonable, primary spacing is AFTER this block */
    width: 100%;
    flex-shrink: 0; 
}

.game-mode-card {
    background-color: #fff;
    /* border: 1px solid #d1c4e9; /* Can be removed if wrapper has border and clips */
    border-radius: 10px;
    padding: 15px;
    /* box-shadow: 0 2px 8px rgba(0,0,0,0.1); /* Can be on wrapper or card */
    position: absolute;
    width: 100%;
    height: 100%; /* Fill the fixed height of the wrapper */
    top: 0;
    left: 0;
    transition: transform 0.5s ease-in-out, opacity 0.5s ease-in-out, z-index 0.5s ease-in-out;
    opacity: 0;
    transform: scale(0.95) translateY(20px);
    z-index: 1;
    display: none;
    overflow-y: auto; /* Crucial: Card's internal content will scroll if it exceeds wrapper's fixed height */
    box-sizing: border-box;
}

.game-mode-card.active {
    opacity: 1;
    transform: scale(1) translateY(0);
    z-index: 2;
    display: block; /* Show active card */
}

.game-mode-card.inactive-stacked {
    /* Style for the card that is "behind" in the stack (optional visual cue) */
    transform: scale(0.9) translateY(10px) translateX(-10px) rotate(-2deg);
    opacity: 0.7;
    z-index: 0;
    display: block;
}

.game-mode-card h2 {
    color: #6a0dad;
    margin-top: 0;
    margin-bottom: 15px;
}

/* Sequence Mode Specific Styles */
#sequence-numbers-display {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-bottom: 15px;
}

.sequence-number-box {
    width: 40px;
    height: 40px;
    border: 1px solid #ccc;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1em;
    border-radius: 5px;
    background-color: #f9f9f9;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.sequence-number-box.correct {
    background-color: #c8e6c9; /* Light green */
    border-color: #66bb6a;
    color: #2e7d32;
}

.sequence-number-box.incorrect {
    background-color: #ffcdd2; /* Light red */
    border-color: #ef5350;
    color: #c62828;
}

#sequence-options-display .option-card {
    /* Options in sequence mode might be fewer, adjust styling if needed */
    padding: 8px 12px; /* Slightly smaller if they contain less text */
}

#user-selection-display h3 {
    color: #6a0dad;
    font-size: 1.1em;
    margin-bottom: 10px;
}

/* Responsive adjustments for smaller screens */
@media (max-width: 600px) {
    body {
        padding: 5px; /* Reduce body padding on small screens */
    }
    .container {
        padding: 15px;
        padding-bottom: 40px; /* Added padding at the bottom for small screens */
        width: 98%;    /* Allow container to be wider */
    }
    h1 {
        font-size: 1.8em; /* Slightly smaller title */
        margin-bottom: 15px;
    }
    .mode-button {
        padding: 8px 12px;
        font-size: 0.9em;
    }
    select#difficulty, button {
        padding: 10px 12px;
        font-size: 0.9em;
    }
    .number-card, .option-card, .selected-card {
        padding: 6px 8px;   /* Further reduce padding for cards on small screens */
        font-size: 0.9em;   /* Further reduce font for cards on small screens */
        min-width: 40px;    /* Further reduce min-width for cards on small screens */
    }
    .option-card {
        /* Specific overrides for option-card on small screens if needed */
        padding: 5px 6px; 
        font-size: 0.85em;
        min-width: 35px;
    }
    .option-card .option-note-name {
        font-size: 0.9em; /* Adjust inner elements if card font size changed */
    }
    .option-card .option-solfege {
        font-size: 0.75em; /* Adjust inner elements */
    }
    .selected-card .option-note-name {
        font-size: 1em;
    }
    .selected-card .option-solfege {
        font-size: 0.8em;
    }
    #numbers-display, #options-display, #selected-notes {
        gap: 8px; /* Reduce gap between cards */
        margin-bottom: 15px;
    }
    .game-modes-wrapper {
        height: 330px; 
        margin-bottom: 15px; 
    }
    .game-mode-card {
        padding: 12px;
    }
    #sequence-numbers-display {
        gap: 5px; /* Smaller gap for sequence boxes */
    }
    .sequence-number-box {
        width: 30px;  /* Smaller sequence boxes */
        height: 30px;
        font-size: 0.85em;
    }
    #score-display {
        font-size: 1.1em;
        margin-bottom: 10px; /* Ensure score is not too close to bottom */
    }
    /* Ensure game content doesn't push score off-screen too easily */
    /* display: flex; flex-direction: column; max-height: 100vh; are already set */
    #feedback,
    #score-display,
    #checkAnswer,
    #nextLevel {
        margin-top: 8px;
        margin-bottom: 8px; /* Reduced this for small screens too */
        /* flex-shrink: 0; is inherited */
    }
} 

#nextLevel, #checkAnswer { /* Explicitly target these buttons if they are the ones being obscured */
    margin-top: 20px; /* Increased margin-top for these specific buttons */
} 

/* General spacing for elements that appear below the game modes wrapper */
#feedback,
#score-display,
#checkAnswer,
#nextLevel {
    margin-top: 10px; 
    margin-bottom: 10px; /* Reduced this as container padding-bottom will handle end-space */
    flex-shrink: 0; /* Prevent these from shrinking */
}

#checkAnswer,
#nextLevel { /* These are the main action buttons below the game area */
    margin-top: 20px; /* Increased margin-top for these specific buttons */
    margin-bottom: 15px; /* Ensure some space below them too */
} 