/* Key/Tonic Display (upper left corner of editor) */
.key-tonic-display {
    position: absolute;
    top: 4px;
    left: 4px;
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid #d1d5db;
    border-radius: 4px;
    padding: 6px 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    z-index: 100;
    user-select: none;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
}

.key-tonic-display:empty,
.key-tonic-display.all-hidden {
    display: none;
}

.key-sig-display-svg {
    display: block;
    width: 70px;
    height: auto;
    cursor: pointer;
    margin-bottom: 2px;
}

.key-sig-display-svg:hover {
    opacity: 0.8;
}

.key-sig-display-svg.hidden {
    display: none;
}

.key-sig-display-text {
    display: block;
    font-size: 11px;
    font-weight: 700;
    color: #374151;
    white-space: nowrap;
    cursor: pointer;
}

.key-sig-display-text:hover {
    color: #3b82f6;
}

.key-sig-display-text.hidden {
    display: none;
}

.tonic-display-text {
    display: block;
    font-size: 11px;
    font-weight: 500;
    color: #374151;
    white-space: nowrap;
    cursor: pointer;
}

.tonic-display-text:hover {
    color: #3b82f6;
}

.tonic-display-text.hidden {
    display: none;
}

/* Help button */
.key-tonic-help {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid #9ca3af;
    background: #f3f4f6;
    color: #6b7280;
    font-size: 10px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
}

.key-tonic-help:hover {
    background: #e5e7eb;
    border-color: #6b7280;
    color: #374151;
}

/* Help modal - positioned within editor section */
.key-tonic-help-modal {
    position: absolute;
    top: 8px;
    left: 8px;
    right: 8px;
    bottom: 8px;
    background: white;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 200;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.key-tonic-help-modal.hidden {
    display: none;
}

.key-tonic-help-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid #e5e7eb;
    background: #f9fafb;
    flex-shrink: 0;
}

.key-tonic-help-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #1f2937;
}

.key-tonic-help-close {
    width: 28px;
    height: 28px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    background: white;
    font-size: 18px;
    color: #6b7280;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
    transition: all 0.15s;
}

.key-tonic-help-close:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
    color: #374151;
}

.key-tonic-help-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

.key-tonic-help-content h4 {
    margin: 16px 0 8px 0;
    font-size: 14px;
    font-weight: 600;
    color: #374151;
}

.key-tonic-help-content h4:first-child {
    margin-top: 0;
}

.key-tonic-help-content p {
    margin: 0 0 10px 0;
    font-size: 13px;
    line-height: 1.6;
    color: #4b5563;
}

.key-tonic-help-content ul,
.key-tonic-help-content ol {
    margin: 8px 0 12px 0;
    padding-left: 20px;
    font-size: 13px;
    line-height: 1.6;
    color: #4b5563;
}

.key-tonic-help-content li {
    margin-bottom: 4px;
}

.key-tonic-help-content strong {
    color: #1f2937;
}

.key-tonic-help-content em {
    font-style: italic;
}

/* Key Signature Selector Modal */
.key-sig-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.key-sig-modal.hidden {
    display: none;
}

.key-sig-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    /* backdrop-filter disabled - causes freezes in Epiphany/WebKit */
}

.key-sig-container {
    position: relative;
    background: white;
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    max-width: 90vw;
    max-height: 90vh;
    overflow: hidden;
    z-index: 1;
    animation: key-sig-fade-in 0.3s ease-out;
}

@keyframes key-sig-fade-in {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.key-sig-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem 2rem;
    border-bottom: 1px solid #e5e7eb;
    background: linear-gradient(to bottom, #f9fafb, #ffffff);
}

.key-sig-header h2 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
    color: #1f2937;
}

.key-sig-close-btn {
    background: none;
    border: none;
    font-size: 2rem;
    line-height: 1;
    color: #6b7280;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.key-sig-close-btn:hover {
    background: #f3f4f6;
    color: #1f2937;
}

.key-sig-body {
    padding: 2rem;
    overflow-y: auto;
    max-height: calc(90vh - 120px);
}

/* Circle of Fifths Layout */
.key-sig-circle {
    position: relative;
    width: 600px;
    height: 600px;
    margin: 0 auto 2rem;
}

.key-sig-item {
    position: absolute;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 12px;
    padding: 8px;
    background: white;
    border: 2px solid #e5e7eb;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.key-sig-item:hover {
    transform: scale(1.1);
    border-color: #3b82f6;
    box-shadow: 0 10px 25px rgba(59, 130, 246, 0.3);
    z-index: 10;
}

.key-sig-item.selected {
    border-color: #2563eb;
    background: #eff6ff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.key-sig-item img {
    display: block;
    width: 130px;
    height: auto;
    pointer-events: none;
}

.key-sig-item-label {
    display: block;
    font-size: 11px;
    line-height: 1.3;
    text-align: center;
    color: #374151;
    margin-top: 4px;
}

.key-sig-item-label strong {
    font-weight: 700;
    color: #1f2937;
}

/* Position items in a circle - 12 positions like a clock */
/* Radius from center */
.key-sig-item[data-position="0"] {
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
}

.key-sig-item[data-position="1"] {
    top: 60px;
    right: 110px;
    transform: rotate(0deg);
}

.key-sig-item[data-position="2"] {
    top: 140px;
    right: 40px;
}

.key-sig-item[data-position="3"] {
    top: 250px;
    right: 20px;
}

.key-sig-item[data-position="4"] {
    top: 370px;
    right: 40px;
}

.key-sig-item[data-position="5"] {
    bottom: 60px;
    right: 110px;
}

.key-sig-item[data-position="6"],
.key-sig-item[data-position="6-alt"] {
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
}

.key-sig-item[data-position="6-alt"] {
    bottom: 20px;
    left: 50%;
    transform: translateX(-120%);
}

.key-sig-item[data-position="7"] {
    bottom: 60px;
    left: 110px;
}

.key-sig-item[data-position="8"] {
    top: 370px;
    left: 40px;
}

.key-sig-item[data-position="9"] {
    top: 250px;
    left: 20px;
}

.key-sig-item[data-position="10"] {
    top: 140px;
    left: 40px;
}

.key-sig-item[data-position="11"] {
    top: 60px;
    left: 110px;
}

/* Footer */
.key-sig-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem 2rem;
    border-top: 1px solid #e5e7eb;
    background: #f9fafb;
    margin: -2rem -2rem 0;
}

.key-sig-mode-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
}

.key-sig-mode-toggle input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

.key-sig-mode-toggle span {
    font-size: 0.95rem;
    color: #374151;
}

.key-sig-selected {
    font-size: 0.95rem;
    color: #6b7280;
}

.key-sig-selected strong {
    color: #1f2937;
    font-weight: 600;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .key-sig-circle {
        width: 500px;
        height: 500px;
    }

    .key-sig-item img {
        width: 104px;
    }
}

@media (max-width: 640px) {
    .key-sig-circle {
        width: 400px;
        height: 400px;
    }

    .key-sig-item img {
        width: 78px;
    }

    .key-sig-header h2 {
        font-size: 1.25rem;
    }
}
