/* Safe area insets for notched phones */
.safe-area-inset {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
    padding-bottom: env(safe-area-inset-bottom);
}

/* Feedback animations */
.feedback-correct {
    color: #22c55e;
    animation: pulse-correct 0.5s ease-out;
}

.feedback-incorrect {
    color: #ef4444;
    animation: shake 0.5s ease-out;
}

@keyframes pulse-correct {
    0% {
        transform: scale(1);
        opacity: 0;
    }
    50% {
        transform: scale(1.2);
        opacity: 1;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    20%, 60% {
        transform: translateX(-5px);
    }
    40%, 80% {
        transform: translateX(5px);
    }
}

/* Answer button states */
.answer-btn:disabled {
    cursor: default;
    opacity: 1;
}

.answer-btn:disabled:not(.bg-green-100):not(.bg-red-100):not(.dark\:bg-green-900):not(.dark\:bg-red-900) {
    opacity: 0.5;
}

/* Piano keyboard styles */
.piano-container {
    max-width: 100%;
    margin: 0 auto;
}

.piano-keyboard {
    position: relative;
    display: flex;
    height: 140px;
    max-width: 100%;
    border-radius: 0 0 8px 8px;
    overflow: hidden;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

@media (min-width: 640px) {
    .piano-keyboard {
        height: 160px;
    }
}

.piano-labels {
    display: flex;
    justify-content: space-between;
    padding: 8px 4px 0;
}

.piano-label {
    font-size: 12px;
    font-weight: 500;
    color: #6b7280;
}

.dark .piano-label {
    color: #9ca3af;
}

.piano-key {
    border: none;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none;
    appearance: none;
}

.white-key {
    flex: 1;
    background: linear-gradient(to bottom, #ffffff 0%, #f5f5f5 100%);
    border-right: 1px solid #d1d5db;
    border-bottom: 3px solid #9ca3af;
    min-width: 0;
    z-index: 1;
}

.white-key:last-of-type {
    border-right: none;
}

@media (hover: hover) {
    .white-key:hover {
        background: linear-gradient(to bottom, #f0f0f0 0%, #e8e8e8 100%);
    }

    .white-key:active {
        background: linear-gradient(to bottom, #e0e0e0 0%, #d8d8d8 100%);
        border-bottom-width: 1px;
        margin-top: 2px;
    }
}

.black-key {
    position: absolute;
    top: 0;
    width: 8%;
    height: 55%;
    background: linear-gradient(to bottom, #1f2937 0%, #111827 100%);
    border-radius: 0 0 4px 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3), inset 0 -1px 2px rgba(255, 255, 255, 0.1);
    z-index: 2;
}

@media (hover: hover) {
    .black-key:hover {
        background: linear-gradient(to bottom, #374151 0%, #1f2937 100%);
    }

    .black-key:active {
        background: linear-gradient(to bottom, #111827 0%, #0a0a0a 100%);
        height: 53%;
    }
}

/* Touch feedback (JS-controlled for iOS compatibility) */
.white-key.pressed {
    background: linear-gradient(to bottom, #e0e0e0 0%, #d8d8d8 100%);
    border-bottom-width: 1px;
    margin-top: 2px;
}

.black-key.pressed {
    background: linear-gradient(to bottom, #111827 0%, #0a0a0a 100%);
    height: 53%;
}

/* Piano key disabled states */
.piano-key.disabled {
    cursor: default;
    pointer-events: none;
}

.white-key.disabled {
    opacity: 0.6;
}

.black-key.disabled {
    opacity: 0.6;
}

.white-key.correct {
    background: linear-gradient(to bottom, #86efac 0%, #4ade80 100%) !important;
    border-bottom-color: #16a34a;
}

.white-key.incorrect {
    background: linear-gradient(to bottom, #fca5a5 0%, #f87171 100%) !important;
    border-bottom-color: #dc2626;
}

.black-key.correct {
    background: linear-gradient(to bottom, #16a34a 0%, #15803d 100%) !important;
}

.black-key.incorrect {
    background: linear-gradient(to bottom, #dc2626 0%, #b91c1c 100%) !important;
}

/* Dark mode piano adjustments */
.dark .white-key {
    background: linear-gradient(to bottom, #f9fafb 0%, #e5e7eb 100%);
    border-right-color: #9ca3af;
}

.dark .white-key:hover {
    background: linear-gradient(to bottom, #e5e7eb 0%, #d1d5db 100%);
}

.dark .white-key .key-label {
    color: #1f2937;
}

/* VexFlow SVG styling for dark mode */
.dark #staff svg,
.dark .mini-staff svg {
    filter: invert(1) hue-rotate(180deg);
}

/* Mini staff in mistakes list */
.mini-staff {
    width: 150px;
    height: 110px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
}

.mini-staff svg {
    display: block;
}

/* Staff container */
#staff-container {
    transition: transform 0.2s ease;
    min-height: 120px;
}

/* Responsive staff SVG */
#staff svg {
    max-width: 100%;
    height: auto;
}

/* Disable text selection on buttons for mobile */
button {
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Prevent pull-to-refresh on mobile */
body {
    overscroll-behavior-y: contain;
}

/* Focus styles for accessibility */
button:focus-visible,
input:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* Disabled button state */
button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Smooth transitions for theme changes */
* {
    transition-property: background-color, border-color;
    transition-duration: 150ms;
}

/* Override for animations that need different transitions */
.feedback-correct,
.feedback-incorrect,
#progress-bar {
    transition: none;
}

/* Mode Carousel */
.mode-carousel {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.carousel-chevron {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background-color: #e5e7eb;
    color: #374151;
    border: none;
    cursor: pointer;
    transition: background-color 0.15s, transform 0.1s;
}

.dark .carousel-chevron {
    background-color: #374151;
    color: #e5e7eb;
}

.carousel-chevron:hover {
    background-color: #d1d5db;
}

.dark .carousel-chevron:hover {
    background-color: #4b5563;
}

.carousel-chevron:active {
    transform: scale(0.95);
}

.mode-display {
    min-width: 120px;
    text-align: center;
}

/* Mode Description */
.mode-description {
    text-align: center;
    padding: 0.75rem 1rem;
    background-color: #e5e7eb;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    color: #374151;
    font-size: 0.95rem;
}

.dark .mode-description {
    background-color: #374151;
    border-color: #4b5563;
    color: #d1d5db;
}

/* Modifier Description */
.modifier-description {
    margin-top: 1.5rem;
    text-align: center;
    padding: 0.75rem 1rem;
    background-color: #e5e7eb;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    color: #374151;
    font-size: 0.9rem;
    line-height: 1.5;
    display: none;
}

.modifier-description.active {
    display: block;
}

.dark .modifier-description {
    background-color: #374151;
    border-color: #4b5563;
    color: #d1d5db;
}

/* Modifiers */
.modifiers {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

@media (min-width: 640px) {
    .modifiers {
        flex-direction: row;
        justify-content: center;
        gap: 2rem;
    }
}

.modifier-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
}

.modifier-option input[type="checkbox"] {
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 0.25rem;
    border: 1px solid #d1d5db;
    cursor: pointer;
    accent-color: #3b82f6;
}

.dark .modifier-option input[type="checkbox"] {
    border-color: #4b5563;
}

.modifier-option span {
    color: #374151;
    font-weight: 500;
}

.dark .modifier-option span {
    color: #e5e7eb;
}

.modifier-option.hidden {
    display: none;
}

.modifier-option input[type="checkbox"]:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.modifier-option:has(input:disabled) {
    cursor: not-allowed;
}

.modifier-option:has(input:disabled) span {
    opacity: 0.7;
}

/* Sound Mode Interface */
.sound-interface {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    padding: 1.5rem;
}

.mic-permission-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    background-color: #3b82f6;
    color: white;
    font-weight: 600;
    font-size: 1.1rem;
    border: none;
    border-radius: 0.75rem;
    cursor: pointer;
    transition: background-color 0.15s, transform 0.1s;
}

.mic-permission-btn:hover {
    background-color: #2563eb;
}

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

.mic-permission-btn svg {
    width: 24px;
    height: 24px;
}

/* Listening Indicator */
.listening-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.sound-wave {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 60px;
}

.sound-wave-bar {
    width: 6px;
    background-color: #3b82f6;
    border-radius: 3px;
    animation: sound-wave-pulse 1s ease-in-out infinite;
}

.sound-wave-bar:nth-child(1) { height: 20px; animation-delay: 0s; }
.sound-wave-bar:nth-child(2) { height: 35px; animation-delay: 0.1s; }
.sound-wave-bar:nth-child(3) { height: 50px; animation-delay: 0.2s; }
.sound-wave-bar:nth-child(4) { height: 35px; animation-delay: 0.3s; }
.sound-wave-bar:nth-child(5) { height: 20px; animation-delay: 0.4s; }

@keyframes sound-wave-pulse {
    0%, 100% { transform: scaleY(0.5); opacity: 0.5; }
    50% { transform: scaleY(1); opacity: 1; }
}

.listening-text {
    font-size: 1.1rem;
    color: #6b7280;
    font-weight: 500;
}

.dark .listening-text {
    color: #9ca3af;
}

.detected-note {
    font-size: 2rem;
    font-weight: 700;
    color: #1f2937;
    min-height: 2.5rem;
}

.dark .detected-note {
    color: #f3f4f6;
}

.detection-progress {
    display: flex;
    gap: 8px;
}

.detection-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: #d1d5db;
    transition: background-color 0.15s;
}

.dark .detection-dot {
    background-color: #4b5563;
}

.detection-dot.active {
    background-color: #3b82f6;
}

.detection-dot.matched {
    background-color: #22c55e;
}

/* Sound Error Message */
.sound-error {
    text-align: center;
    padding: 1.5rem;
    background-color: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 0.75rem;
    color: #991b1b;
}

.dark .sound-error {
    background-color: #450a0a;
    border-color: #7f1d1d;
    color: #fca5a5;
}

.sound-error-title {
    font-weight: 600;
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.sound-error-message {
    font-size: 0.95rem;
}

/* Piano keyboard in sound mode (display only) */
.piano-keyboard.display-only .piano-key {
    cursor: default;
    pointer-events: none;
}

.piano-keyboard.display-only .white-key {
    opacity: 0.7;
}

.piano-keyboard.display-only .black-key {
    opacity: 0.7;
}

/* Sound Input Method Segmented Control */
.sound-input-toggle {
    display: inline-flex;
    border-radius: 0.5rem;
    overflow: hidden;
    border: 2px solid #3b82f6;
}

.sound-input-btn {
    padding: 0.4rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    background-color: transparent;
    color: #3b82f6;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.15s, color 0.15s;
    user-select: none;
    -webkit-user-select: none;
}

.sound-input-btn.sound-input-btn-active {
    background-color: #3b82f6;
    color: #ffffff;
}

.dark .sound-input-toggle {
    border-color: #60a5fa;
}

.dark .sound-input-btn {
    color: #60a5fa;
}

.dark .sound-input-btn.sound-input-btn-active {
    background-color: #3b82f6;
    color: #ffffff;
}
