:root {
    --primary-color: #7b2cbf;
    --primary-hover: #5a189a;
    --accent-color: #e0aaff;
    --bg-dark: #10002b;
    --card-bg: rgba(36, 0, 70, 0.4);
    --border-color: rgba(224, 170, 255, 0.2);
}

body {
    background: linear-gradient(135deg, var(--bg-dark) 0%, #240046 100%);
    min-height: 100vh;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    color: #f8f9fa;
}

h1.text-primary {
    color: var(--accent-color) !important;
    text-shadow: 0 4px 15px rgba(224, 170, 255, 0.3);
}

.form-label {
    color: var(--accent-color);
    letter-spacing: 0.5px;
}

.form-select {
    background-color: rgba(16, 0, 43, 0.6);
    border: 1px solid var(--border-color);
    color: #fff;
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
}

.form-select:focus {
    background-color: rgba(36, 0, 70, 0.8);
    border-color: var(--accent-color);
    box-shadow: 0 0 0 0.25rem rgba(224, 170, 255, 0.25);
    color: #fff;
}

.form-select option {
    background-color: var(--bg-dark);
    color: #fff;
}

.card {
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    background-color: var(--card-bg) !important;
    border: 1px solid var(--border-color) !important;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3) !important;
    transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
}

.chord-card {
    cursor: pointer;
}

.chord-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 12px 40px 0 rgba(123, 44, 191, 0.4) !important;
    border-color: var(--accent-color) !important;
}

.chord-degree {
    font-size: 0.9rem;
    color: var(--accent-color);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.chord-name {
    font-size: 2.5rem;
    font-weight: 700;
    margin: 10px 0;
    color: #fff;
    white-space: nowrap; /* Essential for overflow detection */
    transition: font-size 0.2s ease;
}

.chord-notes {
    font-size: 1rem;
    color: #adb5bd;
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}

.note-badge {
    background: rgba(123, 44, 191, 0.2);
    border: 1px solid rgba(123, 44, 191, 0.4);
    border-radius: 6px;
    padding: 2px 8px;
    font-size: 0.85rem;
    color: var(--accent-color);
}

/* Keyboard Styling */
#keyboard {
    position: relative;
    display: inline-flex;
    height: 180px;
    border-radius: 8px;
    background: rgba(16, 0, 43, 0.8);
    padding: 10px 20px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border-color);
    margin: 0 auto;
}

.key {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    padding-bottom: 12px;
    font-size: 0.9rem;
    font-weight: bold;
    user-select: none;
    transition: all 0.2s ease-in-out;
}

.key.white {
    width: 44px;
    height: 150px;
    background-color: #f8f9fa;
    color: #adb5bd; /* Default degree color when not active */
    z-index: 1;
    border-radius: 0 0 6px 6px;
    border: 1px solid #dee2e6;
    border-top: none;
}

.key.black {
    width: 28px;
    height: 100px;
    background-color: #212529;
    color: #495057;
    z-index: 2;
    margin-left: -14px;
    margin-right: -14px;
    border-radius: 0 0 4px 4px;
    border: 1px solid #111;
    border-top: none;
    box-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}

/* Fix left margin for the very first black key to avoid overlapping container padding */
.key.black:first-child {
    margin-left: 0;
}
.key.black:last-child {
    margin-right: 0;
}

/* Base scale colors */
.key.scale-note {
    background-color: #74c69d; /* Light green */
    color: #1b4332;
    border-color: #52b788;
}

.key.scale-root {
    background-color: #2d6a4f; /* Medium Dark green */
    color: #d8f3dc;
    border-color: #1b4332;
}

/* Hover chord colors */
.key.chord-note {
    background-color: #ffb703 !important; /* Light orange */
    color: #111 !important;
    border-color: #e85d04 !important;
}

.key.chord-root {
    background-color: #fb8500 !important; /* Dark orange */
    color: #fff !important;
    border-color: #d00000 !important;
}

.key-degree {
    pointer-events: none;
}

/* MIDI active colors */
.key.midi-active {
    background-color: #4cc9f0 !important; /* Bright blue */
    color: #fff !important;
    border-color: #4361ee !important;
    box-shadow: inset 0 0 10px rgba(76, 201, 240, 0.5);
}

/* Range indicator for overflow MIDI notes */
.range-indicator {
    position: absolute;
    bottom: 5px;
    right: 5px;
    font-size: 0.7rem;
    color: #4cc9f0;
    font-weight: bold;
    pointer-events: none;
    animation: blink 1s infinite alternate;
}

@keyframes blink {
    from { opacity: 0.2; }
    to { opacity: 1; }
}

/* Chord card drag state */
.chord-card.dragging {
    opacity: 0.45;
    transform: scale(0.96);
    box-shadow: 0 0 0 2px rgba(123, 44, 191, 0.7);
}

/* Touch selected state (mobile tap) */
@keyframes touchSelectedPulse {
    0%   { box-shadow: 0 0 0 2px rgba(123, 44, 191, 0.9), 0 0 16px 4px rgba(123, 44, 191, 0.4); }
    50%  { box-shadow: 0 0 0 3px rgba(167, 89, 255, 1),    0 0 28px 8px rgba(123, 44, 191, 0.6); }
    100% { box-shadow: 0 0 0 2px rgba(123, 44, 191, 0.9), 0 0 16px 4px rgba(123, 44, 191, 0.4); }
}
.chord-card.touch-selected {
    animation: touchSelectedPulse 1.6s ease-in-out infinite;
    border-color: rgba(167, 89, 255, 0.9) !important;
}

/* Notebook area scrollbar */
.notebook-area::-webkit-scrollbar {
    height: 6px;
}
.notebook-area::-webkit-scrollbar-track {
    background: rgba(255,255,255,0.05);
    border-radius: 4px;
}
.notebook-area::-webkit-scrollbar-thumb {
    background: rgba(123, 44, 191, 0.5);
    border-radius: 4px;
}

/* Responsive Keyboard syncing exactly with Bootstrap breakpoints */
@media (max-width: 1200px) {
    #keyboard { height: 160px; padding: 10px 15px; }
    .key.white { width: 38px; height: 130px; }
    .key.black { width: 24px; height: 85px; margin-left: -12px; margin-right: -12px; }
    .key { font-size: 0.85rem; padding-bottom: 10px; }
}

@media (max-width: 992px) {
    #keyboard { height: 130px; padding: 8px 12px; }
    .key.white { width: 30px; height: 105px; }
    .key.black { width: 18px; height: 65px; margin-left: -9px; margin-right: -9px; }
    .key { font-size: 0.8rem; padding-bottom: 8px; }
}

@media (max-width: 768px) {
    #keyboard { height: 100px; padding: 6px 10px; }
    .key.white { width: 22px; height: 80px; border-radius: 0 0 4px 4px; }
    .key.black { width: 14px; height: 50px; margin-left: -7px; margin-right: -7px; border-radius: 0 0 3px 3px; }
    .key { font-size: 0.7rem; padding-bottom: 6px; }
}

@media (max-width: 576px) {
    #keyboard { height: 80px; padding: 4px 6px; border-radius: 4px; }
    .key.white { width: 14px; height: 60px; border-radius: 0 0 2px 2px; }
    .key.black { width: 10px; height: 38px; margin-left: -5px; margin-right: -5px; border-radius: 0 0 2px 2px; }
    .key { font-size: 0; padding-bottom: 2px; } /* hide the text, too small to read */
    .key.scale-root .key-degree, .key.scale-note .key-degree { font-size: 0.5rem; } /* only show degree if it has one */
}
