@font-face {
    font-family: 'Bravura';
    src: url('https://cdn.jsdelivr.net/gh/musescore/MuseScore@master/fonts/bravura/Bravura.otf') format('opentype');
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: #f0f4f8;
    margin: 0;
    padding: 20px;
}

.container {
    background-color: white;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    max-width: 800px;
    width: 100%;
}

h1 {
    font-family: 'Montserrat', sans-serif;
    margin: 0;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.main-header {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 20px;
    margin-bottom: 30px;
    padding-left: 0;
}

.logo {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transition: transform 0.3s ease, filter 0.3s ease, box-shadow 0.3s ease;
    will-change: transform, filter, box-shadow;
}

#main-logo.pulse {
    animation: logo-pulse 2s infinite ease-in-out;
    filter: drop-shadow(0 0 12px rgba(46, 204, 113, 0.6));
}

@keyframes logo-pulse {
    0% { transform: scale(1); box-shadow: 0 4px 12px rgba(0,0,0,0.15); }
    50% { transform: scale(1.05); box-shadow: 0 8px 24px rgba(46, 204, 113, 0.4); }
    100% { transform: scale(1); box-shadow: 0 4px 12px rgba(0,0,0,0.15); }
}

h1 {
    font-family: 'Montserrat', sans-serif;
    margin: 0;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 5px;
}

h1 .brand {
    font-weight: 900;
    font-size: 2.2rem;
    background: linear-gradient(135deg, #2ecc71, #27ae60);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    color: transparent;
}

h1 .tagline {
    font-weight: 300;
    font-size: 1.4rem;
    color: #34495e;
}

@media (max-width: 600px) {
    .main-header {
        flex-direction: column;
        text-align: center;
        justify-content: center;
        padding-left: 0;
    }
    
    h1 {
        flex-direction: column;
        align-items: center;
        gap: 0;
    }
}

.controls {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 25px;
    flex-wrap: wrap;
    align-items: center;
}

.control-group {
    display: none;
}

label {
    font-weight: bold;
    margin-bottom: 5px;
    color: #7f8c8d;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

select {
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid #ecf0f1;
    background-color: #f8f9fa;
    font-size: 14px;
    cursor: pointer;
    height: 34px;
    box-sizing: border-box;
}

select:hover {
    background-color: #ecf0f1;
}

.btn {
    padding: 8px 20px;
    border-radius: 6px;
    border: none;
    background-color: #3498db;
    color: white;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    height: 34px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn:hover {
    background-color: #2980b9;
}

.btn:active {
    transform: scale(0.98);
}

.btn:disabled {
    background-color: #bdc3c7;
    cursor: not-allowed;
}

.btn-secondary {
    background-color: #95a5a6;
}

.btn-secondary:hover {
    background-color: #7f8c8d;
}

.btn-secondary.active {
    background-color: #2ecc71;
}

.secondary-controls {
    margin-top: 10px;
    align-items: stretch;
}

.control-sub-section {
    position: relative;
    border: 1px solid #bdc3c7;
    border-radius: 8px;
    padding: 10px;
    background-color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 54px;
    box-sizing: border-box;
}

.control-sub-section::before {
    content: attr(data-label);
    position: absolute;
    top: -8px;
    left: 10px;
    background-color: white;
    padding: 0 5px;
    font-size: 11px;
    font-weight: bold;
    color: #7f8c8d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-group {
    display: flex;
    gap: 8px;
    align-items: center;
}

.scale-controls-combined {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 100%;
}

#scale, #key-sig-style {
    height: 34px;
    box-sizing: border-box;
}

#scale {
    min-width: 160px;
}

.tonic-spinner {
    display: flex;
    align-items: center;
    background-color: #f8f9fa;
    border: 1px solid #bdc3c7;
    border-radius: 4px;
    height: 34px;
    padding: 0 0 0 10px;
    box-sizing: border-box;
    overflow: hidden;
    width: 100px;
}

.tonic-display {
    flex: 1;
    font-size: 14px;
    font-weight: bold;
    color: #2c3e50;
    text-align: left;
    user-select: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.spinner-buttons {
    display: flex;
    flex-direction: column;
    height: 100%;
    border-left: 1px solid #bdc3c7;
}

.spinner-btn {
    flex: 1;
    width: 20px;
    padding: 0;
    margin: 0;
    border: none;
    background: #f8f9fa;
    color: #7f8c8d;
    cursor: pointer;
    font-size: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.spinner-btn:hover {
    background: #ecf0f1;
    color: #3498db;
}

.spinner-btn.up {
    border-bottom: 0.5px solid #bdc3c7;
}

.spinner-btn:disabled {
    color: #ecf0f1;
    cursor: not-allowed;
}

.btn-small {
    padding: 6px 12px;
    font-size: 14px;
    min-width: 32px;
}

.loop-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
}

.loop-container label {
    font-size: 10px;
    margin-bottom: 0;
    text-transform: uppercase;
    color: #7f8c8d;
    font-weight: bold;
}

.loop-container input {
    cursor: pointer;
}

.song-selector-group {
    display: flex;
    gap: 2px;
    border: none;
    border-radius: 6px;
    padding: 2px;
    background-color: #f8f9fa;
    height: 100%;
    box-sizing: border-box;
    align-items: center;
}

.song-select {
    height: 34px;
    box-sizing: border-box;
    border: none;
    background: transparent;
    padding: 6px 10px;
    font-size: 14px;
    color: #2c3e50;
    max-width: 225px;
}

.song-select:hover {
    background: rgba(0,0,0,0.05);
}

.playback-buttons {
    display: flex;
    gap: 1px;
    background-color: #ecf0f1;
    border-radius: 4px;
    overflow: hidden;
}

.btn-icon {
    padding: 6px 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: #34495e;
    border-radius: 0;
    height: 34px;
    box-sizing: border-box;
}

.btn-icon:hover {
    background: rgba(0,0,0,0.1);
}

.btn-icon.active {
    background-color: #3498db;
    color: white;
}

.btn-icon.is-playing, .settings-group .btn-icon.is-active {
    background-color: #3498db !important;
    color: white !important;
}

.settings-group {
    display: flex;
    gap: 8px;
}

.settings-group .btn-icon {
    background-color: #f8f9fa;
    border: 1px solid #ddd;
    color: #7f8c8d;
    transition: all 0.2s ease;
}

.settings-group .btn-icon:hover {
    background-color: #e9ecef;
}

#piano-container.hidden {
    display: none;
}

.btn-icon:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: transparent;
}

.harmony-controls-compact {
    display: flex;
    align-items: center;
    gap: 4px;
    background-color: #f8f9fa;
    padding: 2px 4px;
    border-radius: 6px;
    border: none;
    height: 100%;
    box-sizing: border-box;
    position: relative; /* Base for absolute volume container */
}

.harmony-mode-select {
    height: 34px;
    padding: 4px 8px;
    font-size: 13px;
    border-radius: 4px;
    border: 1px solid #bdc3c7;
    background: white;
    box-sizing: border-box;
}

.harmony-toggle-btn {
    padding: 4px;
    background: none;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.volume-control-wrapper {
    position: relative;
    width: 34px;
    height: 34px;
    flex-shrink: 0;
}

.volume-slider-container {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 4px;
    background: #ecf0f1;
    border-radius: 6px;
    transition: width 0.3s ease, background 0.3s ease, box-shadow 0.3s ease;
    width: 34px;
    height: 34px;
    overflow: hidden;
    position: absolute;
    left: 0;
    top: 0;
    z-index: 10;
}

.volume-slider-container:hover {
    width: 130px;
    background: #ffffff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.volume-slider-container input {
    width: 80px;
    flex-shrink: 0;
    cursor: pointer;
}

.harmony-controls i, .controls i {
    display: inline-block;
    vertical-align: middle;
}

#toggle-harmony {
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.computed-notes {
    margin-top: 15px;
    margin-bottom: 10px;
    font-size: 16px;
    font-weight: bold;
    color: #2c3e50;
    min-height: 50px;
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}
.computed-notes > span {
    background: #fdfdfd;
    padding: 6px 10px;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    border: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 46px;
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
    -webkit-user-select: none;
}
.computed-notes > span:hover {
    background: #ffffff;
    border-color: #cbd5e1;
    transform: translateY(-1px);
    box-shadow: 0 3px 6px rgba(0,0,0,0.08);
}
.computed-notes > span.highlight {
    background: #e74c3c;
    color: white;
    border-color: #c0392b;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(231, 76, 60, 0.35);
}
.computed-notes > span.playing {
    background: #2ecc71;
    color: white;
    border-color: #27ae60;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(46, 204, 113, 0.35);
}
.computed-notes > span.highlight.playing {
    background: #f39c12;
    border-color: #e67e22;
    box-shadow: 0 4px 10px rgba(243, 156, 18, 0.35);
}
.computed-notes > span.highlight small, 
.computed-notes > span.playing small {
    color: rgba(255, 255, 255, 0.9);
}
.computed-notes > span small {
    font-size: 10px;
    color: #64748b;
    line-height: 1.1;
}
.computed-notes > span small:first-child {
    font-weight: 700;
}
.computed-notes > span small:last-of-type {
    font-style: italic;
    font-weight: 400;
    margin-bottom: 2px;
}
.note-name {
    display: flex;
    align-items: baseline;
    justify-content: center;
    font-size: 20px;
    line-height: 1.2;
}
.note-accidental {
    font-size: 0.65em;
    margin-left: 1px;
    font-weight: normal;
}

canvas {
    background-color: white;
    cursor: pointer;
    max-width: 100%;
    height: auto;
}

#visualizer-container {
    position: relative;
    width: 100%;
    margin: 20px 0;
    display: flex;
    justify-content: center;
    background-color: #fff;
    border-radius: 8px;
    overflow: hidden;
    min-height: 200px;
}

#audio-visualizer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.15;
    pointer-events: none;
    z-index: 0;
}

#notation-container {
    margin: 0;
    width: 100%;
    display: flex;
    justify-content: center;
    background-color: transparent;
    cursor: pointer;
    min-height: 200px;
    z-index: 1;
    user-select: none;
    -webkit-user-select: none;
    position: relative;
    overflow: hidden;
}

#notation-container svg {
    max-width: 100%;
    height: auto;
    /* transition: opacity 0.3s ease, transform 0.3s ease; */
}
/* Container during transition */
.notation-transitioning svg:not(.notation-clone) {
    opacity: 1;
}

/* Individual Note Groups */
.vf-note-group {
    transition: transform 0.45s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.4s ease;
    transform-origin: center;
}

/* Entering Notes (Identity not in previous scale) */
.vf-note-group.entering {
    opacity: 0;
    transform: translateY(10px) scale(0.8);
    animation: noteEnter 0.5s forwards 0.1s;
}

/* Leaving Notes (Identity not in new scale) */
.vf-note-group.leaving {
    opacity: 0;
    transform: translateY(-10px) scale(0.8);
    pointer-events: none;
}

/* Key Signature/Stave Cross-fade */
.notation-clone {
    position: absolute;
    top: 0;
    /* left is calculated in JS to match current flex alignment */
    pointer-events: none;
    transition: opacity 0.4s ease;
    z-index: 10;
}

.notation-clone.fade-out {
    opacity: 0;
}

@keyframes noteEnter {
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}
.instructions {
    margin-top: 20px;
    color: #7f8c8d;
    font-style: italic;
    margin-bottom: 20px;
}

#piano-container {
    margin-top: 20px;
    display: flex;
    justify-content: center;
    overflow-x: auto;
    padding-bottom: 20px;
}

.piano {
    display: flex;
    position: relative;
    height: 150px;
    user-select: none;
}

.key {
    border: 1px solid #333;
    border-radius: 0 0 5px 5px;
    cursor: pointer;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 10px;
    position: relative;
    transition: all 0.1s ease-out;
    transform-origin: top;
}

.white-key {
    width: 40px;
    height: 150px;
    background: linear-gradient(to bottom, #eee 0%, #fff 8%);
    box-shadow: inset 0 1px 0 #fff, inset 0 -1px 0 #ccc, inset 1px 0 0 #ccc, inset -1px 0 0 #ccc, 0 4px 3px rgba(0,0,0,0.1);
    z-index: 1;
}

.black-key {
    width: 26px;
    height: 90px;
    background: linear-gradient(to bottom, #444 0%, #222 100%);
    box-shadow: inset 0 -1px 2px rgba(255,255,255,0.2), 0 2px 3px rgba(0,0,0,0.4);
    z-index: 2;
    margin-left: -13px;
    margin-right: -13px;
    color: white;
}

.white-key.active {
    background: linear-gradient(to bottom, #fff 0%, #e74c3c 100%);
    border-color: #c0392b;
    transform: perspective(500px) rotateX(-5deg) translateY(2px);
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.2), 0 1px 1px rgba(0,0,0,0.1);
}

.white-key.highlight {
    background: linear-gradient(to bottom, #fff 0%, #e74c3c 100%);
    border-color: #c0392b;
}

.white-key.playing, .white-key.playing.active {
    background: linear-gradient(to bottom, #fff 0%, #2ecc71 100%) !important;
    border-color: #27ae60 !important;
    transform: perspective(500px) rotateX(-5deg) translateY(2px);
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.2), 0 1px 1px rgba(0,0,0,0.1);
}

.white-key.highlight.playing, .white-key.highlight.playing.active {
    background: linear-gradient(to bottom, #fff 0%, #f39c12 100%) !important;
    border-color: #e67e22 !important;
}

.black-key.active {
    background: linear-gradient(to bottom, #555 0%, #c0392b 100%);
    transform: perspective(500px) rotateX(-10deg) translateY(1px);
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.5), 0 1px 1px rgba(0,0,0,0.2);
}

.black-key.highlight {
    background: linear-gradient(to bottom, #555 0%, #c0392b 100%);
}

.black-key.playing, .black-key.playing.active {
    background: linear-gradient(to bottom, #555 0%, #2ecc71 100%) !important;
    transform: perspective(500px) rotateX(-10deg) translateY(1px);
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.5), 0 1px 1px rgba(0,0,0,0.2);
}

.black-key.highlight.playing, .black-key.highlight.playing.active {
    background: linear-gradient(to bottom, #555 0%, #f39c12 100%) !important;
}

.key-label {
    pointer-events: none;
    font-size: 12px;
    font-weight: bold;
}


.white-key .key-label {
    color: #333;
}

.black-key .key-label {
    color: white;
}

.white-key.primary-tonic-key .key-label, .black-key.primary-tonic-key .key-label {
    text-decoration: underline;
    font-weight: 900;
}

.white-key.in-scale {
    background-color: #ecf0f1;
}

.white-key.blue-note-key {
    background-color: #d6eaf8;
    border-color: #3498db;
}

.black-key.blue-note-key {
    background-color: #2980b9;
}

.white-key.blue-note-key .key-label {
    color: #2980b9;
}

.white-key.active .key-label, .black-key.active .key-label,
.white-key.highlight .key-label, .black-key.highlight .key-label,
.white-key.playing .key-label, .black-key.playing .key-label {
    color: white;
}

#note-display-container {
    height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 10px;
}

.note-card {
    background-color: #3498db;
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 24px;
    font-weight: bold;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    opacity: 0;
    transform: translateY(10px) scale(0.9);
    transition: all 0.2s ease-out;
    pointer-events: none;
    z-index: 10;
}

.note-card.show {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.control-sub-section[data-label="Ear Trainer"] {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 120px;
}

/* Guessing Game Animations */
.guess-feedback {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
    pointer-events: none;
    font-size: 5rem;
    font-weight: bold;
    opacity: 0;
}

.success-animation {
    animation: success-burst 1s ease-out forwards;
    color: #2ecc71;
    text-shadow: 0 0 20px rgba(46, 204, 113, 0.5);
}

.failure-animation {
    animation: failure-sink 1.5s ease-in forwards;
    color: #e74c3c;
    text-shadow: 0 0 20px rgba(231, 76, 60, 0.5);
}

@keyframes success-burst {
    0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
    20% { opacity: 1; }
    50% { transform: translate(-50%, -60%) scale(1.2); }
    100% { transform: translate(-50%, -70%) scale(1.5); opacity: 0; }
}

@keyframes failure-sink {
    0% { transform: translate(-50%, -50%); opacity: 0; }
    20% { opacity: 1; }
    80% { transform: translate(-50%, -30%); opacity: 1; }
    100% { transform: translate(-50%, -10%); opacity: 0; }
}

/* Fireworks effect for success */
.firework {
    position: fixed;
    z-index: 999;
    pointer-events: none;
    border-radius: 50%;
    animation: explode 0.8s ease-out forwards;
}

@keyframes explode {
    0% { transform: translate(0, 0); opacity: 1; }
    100% { transform: translate(var(--tx), var(--ty)); opacity: 0; }
}

/* Correct note highlight for guessing mode failure */
.correct-note-highlight {
    animation: fade-out-highlight 3s ease-out forwards;
    background: #2ecc71 !important;
    color: white !important;
    border-color: #27ae60 !important;
    z-index: 5;
}

.correct-note-highlight small {
    color: rgba(255, 255, 255, 0.9) !important;
}

@keyframes fade-out-highlight {
    0% { transform: translateY(-4px) scale(1.05); box-shadow: 0 8px 15px rgba(46, 204, 113, 0.4); opacity: 1; }
    50% { transform: translateY(-4px) scale(1.05); box-shadow: 0 8px 15px rgba(46, 204, 113, 0.4); opacity: 1; }
    100% { transform: translateY(0) scale(1); box-shadow: 0 1px 3px rgba(0,0,0,0.06); opacity: 1; }
}
