:root {
    --primary: #6c5ce7;
    --secondary: #a29bfe;
    --bg: #f0f3f7;
    --card-bg: #ffffff;
    --text: #2d3436;
    --white: #ffffff;
    --black: #2d3436;
    --correct: #00b894;
    --incorrect: #d63031;
}

body.dark-mode {
    --bg: #1e272e;
    --card-bg: #2d3436;
    --text: #f0f3f7;
    --white: #2d3436;
    --black: #ffffff;
    --secondary: #6c5ce7;
}

body {
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, Roboto, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    transition: background-color 0.3s, color 0.3s;
}

.theme-toggle {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 10px;
}

#dark-mode-toggle {
    background: var(--card-bg);
    border: none;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

#dark-mode-toggle:hover { transform: scale(1.1); }

.container {
    width: 100%;
    max-width: 500px;
    padding: 20px;
}

.screen {
    display: none;
    background: var(--card-bg);
    padding: 40px;
    border-radius: 30px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.05);
    text-align: center;
    animation: fadeIn 0.5s ease;
}

.screen.active {
    display: block;
}

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

h1 { margin-bottom: 10px; font-size: 2rem; }
p { color: #636e72; margin-bottom: 30px; }

.setup-group {
    margin-bottom: 30px;
    text-align: left;
}

.setup-group h3 {
    font-size: 1rem;
    margin-bottom: 15px;
}

.toggle-group {
    display: flex;
    gap: 10px;
}

.toggle-group button {
    flex: 1;
    padding: 12px;
    border: 2px solid #dfe6e9;
    background: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.toggle-group button.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.primary-btn {
    width: 100%;
    padding: 18px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 15px;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
}

.primary-btn:hover {
    background: #5b4cc4;
    transform: scale(1.02);
}

/* Game Styles */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    font-weight: 600;
}

.icon-btn {
    background: var(--card-bg);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1.2rem;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.icon-btn:hover { background: #dfe6e9; }

.stats {
    display: flex;
    gap: 20px;
}

.play-btn {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: none;
    background: var(--secondary);
    color: white;
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    margin-bottom: 20px;
    box-shadow: 0 8px 20px rgba(162, 155, 254, 0.4);
    transition: all 0.2s;
}

.play-btn:active { transform: scale(0.95); }

/* Piano Styles */
#piano-container {
    width: 100%;
    overflow: hidden; /* Prevent container from scrolling */
    display: flex;
    justify-content: center;
}

.piano {
    display: flex;
    justify-content: flex-start; /* Change to flex-start to ensure scrolling works correctly when overflowed */
    height: 200px;
    margin: 40px 0;
    position: relative;
    user-select: none;
    overflow-x: auto;
    padding-bottom: 10px;
    max-width: 100%;
    
    /* Hide scrollbar for IE, Edge and Firefox */
    -ms-overflow-style: none;  /* IE and Edge */
    scrollbar-width: none;  /* Firefox */
}

/* Hide scrollbar for Chrome, Safari and Opera */
.piano::-webkit-scrollbar {
    display: none;
}

/* If piano is smaller than container, we still want it centered */
.piano:not(:empty) {
    justify-content: center;
}

.key {
    cursor: pointer;
    border: 1px solid #ccc;
    position: relative;
    transition: background 0.1s;
}

.key.white {
    width: 40px;
    height: 100%;
    background: white;
    border-radius: 0 0 5px 5px;
    z-index: 1;
}

.key.black {
    width: 28px;
    height: 60%;
    background: var(--black);
    margin-left: -14px;
    margin-right: -14px;
    z-index: 2;
    border-radius: 0 0 3px 3px;
}

.key.disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.key.white:active, .key.white.active { background: #dfe6e9; }
.key.black:active, .key.black.active { background: #4b4b4b; }

.key.active-correct { background: var(--correct) !important; transition: background 0.1s; }
.key.active-incorrect { background: var(--incorrect) !important; transition: background 0.1s; }

.feedback.correct { color: var(--correct); }
.feedback.incorrect { color: var(--incorrect); }

.mistake-stats {
    text-align: left;
    margin: 20px 0;
    max-height: 200px;
    overflow-y: auto;
    padding: 15px;
    background: var(--bg);
    border-radius: 15px;
    font-size: 0.95rem;
}

.mistake-item {
    padding: 8px 0;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    display: flex;
    justify-content: space-between;
}
.mistake-item:last-child { border-bottom: none; }
.total-mistakes {
    margin-top: 15px;
    padding-top: 10px;
    border-top: 2px dashed var(--incorrect);
    font-weight: 700;
    text-align: right;
    color: var(--incorrect);
}

/* Intervals Grid */
#interval-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-top: 20px;
}

#interval-options button {
    padding: 15px;
    border: 1px solid #dfe6e9;
    background: white;
    border-radius: 10px;
    cursor: pointer;
}

.hidden { display: none !important; }

.feedback {
    margin-top: 20px;
    height: 24px;
    font-weight: 700;
}

/* Results */
.score-circle {
    width: 120px;
    height: 120px;
    border: 8px solid var(--primary);
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    margin: 30px auto;
}

#final-score { font-size: 2.5rem; font-weight: 800; color: var(--primary); }
.total { color: #b2bec3; font-weight: 600; }
#result-title { margin-top: 10px; color: var(--primary); }
