* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f5f5f5;
    color: #333;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

h1 {
    text-align: center;
    color: #2c3e50;
    margin-bottom: 30px;
}

h2 {
    color: #34495e;
    margin-bottom: 20px;
}

.practice-section {
    background-color: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    margin-bottom: 30px;
}

.practice-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
    padding: 15px;
    background-color: #f8f9fa;
    border-radius: 6px;
}

.chord-display, .timer, .score, .remaining-questions {
    font-size: 1.2em;
    font-weight: bold;
}

.chord-type-selection {
    margin: 20px 0;
}

.chord-type-selection label {
    margin-right: 20px;
}

.input-mode-selection {
    margin: 20px 0;
}

.input-mode-selection label {
    margin-right: 20px;
}

.midi-status {
    margin: 10px 0;
    padding: 10px;
    background-color: #f5f5f5;
    border-radius: 5px;
}

button {
    display: block;
    width: 100%;
    padding: 12px;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 1.1em;
    cursor: pointer;
    margin: 20px 0;
}

button:hover {
    background-color: #2980b9;
}

.piano-keyboard {
    display: none;
    justify-content: center;
    margin-top: 30px;
    position: relative;
    height: 200px;
    background-color: #f8f9fa;
    padding: 20px 5px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.piano-keyboard .chord-display {
    position: absolute;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    font-size: 3em;
    font-weight: bold;
    color: #2c3e50;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

.piano-keyboard .chord-text {
    font-size: 1.2em;
    margin-left: 10px;
}

.key {
    position: relative;
    border: 1px solid #ccc;
    border-radius: 0 0 5px 5px;
    cursor: pointer;
    transition: background-color 0.1s;
}

.key.white {
    width: 45px;
    height: 180px;
    background-color: white;
    z-index: 1;
}

.key.black {
    width: 35px;
    height: 120px;
    background-color: black;
    margin-left: -17.5px;
    margin-right: -17.5px;
    z-index: 2;
}

.key.pressed {
    background-color: #e0e0e0;
}

.key.black.pressed {
    background-color: #333;
}

.key.selected {
    background-color: #3498db;
}

.key.correct {
    background-color: #2ecc71;
}

.key.incorrect {
    background-color: #e74c3c;
}

#practiceResult {
    display: none; /* デフォルトでは非表示 */
    text-align: center;
    font-size: 1.2em;
    margin: 20px 0;
    min-height: 30px;
}

#practiceResult:not(:empty) {
    display: block; /* 内容がある場合のみ表示 */
}

#practiceResult.correct {
    color: #2ecc71;
}

#practiceResult.incorrect {
    color: #e74c3c;
}

#practiceResult.practice-complete {
    color: #3498db;
    font-weight: bold;
}

.chord-text {
    font-size: 2em;
    font-weight: bold;
    color: #333;
    margin-left: 10px;
    padding: 5px 10px;
    background-color: #f0f0f0;
    border-radius: 5px;
}

.timer, .score, .remaining-questions {
    display: none; /* デフォルトでは非表示 */
}

/* レスポンシブデザイン */
@media screen and (max-width: 768px) {
    .container {
        padding: 10px;
    }

    .practice-info {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }

    .chord-type-selection {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .chord-type-selection label {
        margin-right: 0;
    }

    .piano-keyboard {
        height: 150px;
        padding: 10px;
    }

    .key.white {
        width: 30px;
        height: 130px;
    }

    .key.black {
        width: 20px;
        height: 80px;
        margin-left: -10px;
        margin-right: -10px;
    }
}

@media screen and (max-width: 480px) {
    .container {
        padding: 5px;
    }

    h1 {
        font-size: 1.3em;
    }

    h2 {
        font-size: 1.1em;
    }

    .practice-section {
        padding: 10px;
    }

    .chord-type-selection {
        grid-template-columns: 1fr;
    }

    .practice-info {
        padding: 10px;
    }

    .chord-display, .timer, .score, .remaining-questions {
        font-size: 0.9em;
    }

    #practiceResult {
        font-size: 0.9em;
        min-height: 20px;
    }

    .piano-keyboard {
        height: 120px;
        padding: 5px;
    }

    .key.white {
        width: 25px;
        height: 110px;
    }

    .key.black {
        width: 15px;
        height: 70px;
        margin-left: -7.5px;
        margin-right: -7.5px;
    }
}

/* タッチデバイス向けの最適化 */
@media (hover: none) {
    .key {
        touch-action: manipulation;
    }

    button {
        min-height: 44px; /* iOSの推奨タップ領域サイズ */
    }

    .chord-type-selection label,
    .input-mode-selection label {
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    input[type="checkbox"],
    input[type="radio"] {
        width: 20px;
        height: 20px;
        margin-right: 8px;
    }
}

/* 練習モード実行時のレイアウト */
.practice-mode-active .practice-section {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background-color: white;
    padding: 5px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.practice-mode-active .practice-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 5px;
    padding: 5px;
}

.practice-mode-active .chord-display {
    display: block;
    text-align: center;
    font-size: 4em;
    font-weight: bold;
    margin-bottom: 20px;
    color: #2c3e50;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

.practice-mode-active .chord-text {
    font-size: 1.2em;
    margin-left: 10px;
}

.practice-mode-active .timer,
.practice-mode-active .score,
.practice-mode-active .remaining-questions {
    display: block;
    text-align: center;
    font-size: 1.2em;
    margin: 5px 0;
}

.practice-mode-active .chord-type-selection,
.practice-mode-active .input-mode-selection,
.practice-mode-active #midiStatus {
    display: none;
}

.practice-mode-active #startPractice {
    display: block;
    position: fixed;
    top: 5px;
    right: 5px;
    width: auto;
    padding: 5px 10px;
    z-index: 101;
    background-color: #e74c3c;
    font-size: 0.9em;
}

.practice-mode-active #startPractice:hover {
    background-color: #c0392b;
}

.practice-mode-active .piano-keyboard {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 45vh;
    margin-top: 0;
    padding: 10px;
    background-color: #f8f9fa;
    z-index: 99;
}

.practice-mode-active #practiceResult {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(255, 255, 255, 0.9);
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    z-index: 101;
}

/* タブレット向けのレイアウト */
@media screen and (max-width: 1024px) {
    .practice-mode-active .practice-section {
        padding: 3px;
    }

    .practice-mode-active .practice-info {
        padding: 3px;
    }

    .practice-mode-active .chord-display {
        font-size: 3.5em;
        margin-bottom: 15px;
    }

    .practice-mode-active .timer,
    .practice-mode-active .score,
    .practice-mode-active .remaining-questions {
        font-size: 1.1em;
    }

    .practice-mode-active #startPractice {
        top: 3px;
        right: 3px;
        padding: 4px 8px;
        font-size: 0.8em;
    }

    .practice-mode-active .piano-keyboard {
        height: 40vh;
        padding: 5px 2px;
    }

    .key.white {
        width: 40px;
        height: calc(40vh - 10px);
    }

    .key.black {
        width: 30px;
        height: calc(30vh - 10px);
        margin-left: -15px;
        margin-right: -15px;
    }

    .practice-mode-active .piano-keyboard .chord-display {
        font-size: 2.5em;
        top: -50px;
    }
}

/* スマートフォン向けのレイアウト */
@media screen and (max-width: 768px) {
    .practice-mode-active .practice-info {
        flex-direction: column;
        gap: 3px;
    }

    .practice-mode-active .chord-display {
        font-size: 3em;
        margin-bottom: 10px;
    }

    .practice-mode-active .timer,
    .practice-mode-active .score,
    .practice-mode-active .remaining-questions {
        font-size: 1em;
    }

    .practice-mode-active #startPractice {
        top: 2px;
        right: 2px;
        padding: 3px 6px;
        font-size: 0.7em;
    }

    .practice-mode-active .piano-keyboard {
        height: 35vh;
        padding: 5px 1px;
    }

    .key.white {
        width: 35px;
        height: calc(35vh - 10px);
    }

    .key.black {
        width: 25px;
        height: calc(25vh - 10px);
        margin-left: -12.5px;
        margin-right: -12.5px;
    }

    .practice-mode-active .piano-keyboard .chord-display {
        font-size: 2em;
        top: -40px;
    }
}

/* 横向き表示の最適化 */
@media screen and (orientation: landscape) {
    .practice-mode-active .practice-section {
        padding: 3px;
    }

    .practice-mode-active .practice-info {
        flex-direction: row;
        gap: 5px;
    }

    .practice-mode-active .chord-display {
        font-size: 3.8em;
        margin-bottom: 15px;
    }

    .practice-mode-active .timer,
    .practice-mode-active .score,
    .practice-mode-active .remaining-questions {
        font-size: 1.1em;
    }

    .practice-mode-active .piano-keyboard {
        height: 50vh;
        padding: 5px 1px;
    }

    .key.white {
        width: 60px;
        height: calc(50vh - 10px);
    }

    .key.black {
        width: 45px;
        height: calc(35vh - 10px);
        margin-left: -22.5px;
        margin-right: -22.5px;
    }

    .practice-mode-active .piano-keyboard .chord-display {
        font-size: 2.8em;
        top: -55px;
    }
}

.practice-section h2 {
    display: none; /* デフォルトでは非表示 */
}

.practice-section .instructions {
    display: block;
    margin-bottom: 20px;
    padding: 15px;
    background-color: #f8f9fa;
    border-radius: 6px;
    line-height: 1.6;
}

.practice-section .instructions h3 {
    color: #2c3e50;
    margin-bottom: 10px;
}

.practice-section .instructions ol {
    padding-left: 20px;
}

.practice-section .instructions li {
    margin-bottom: 8px;
}

.practice-mode-active .practice-section h2 {
    display: block; /* 練習モード時のみ表示 */
}

.practice-mode-active .practice-section .instructions {
    display: none; /* 練習モード時は非表示 */
}

.chord-display {
    display: none; /* デフォルトでは非表示 */
} 