/* ==========================================================================
   Teste de Extensão Vocal Pro v1.1 — Responsive Frontend
   ========================================================================== */

:root {
    --tev-primary: #0a1f3d;
    --tev-primary-dark: #061327;
    --tev-primary-light: #1a3a6e;
    --tev-accent: #fbbf24;
    --tev-bg: #0a1f3d;
    --tev-bg-light: #1a3a6e;
    --tev-text: #1f2937;
    --tev-text-light: #6b7280;
    --tev-white: #ffffff;
    --tev-black-key: #1a1a1a;
    --tev-success: #10b981;
    --tev-error: #ef4444;
    --tev-active: #ef4444;
    --tev-confirmed: #10b981;
    --tev-target: #fbbf24;
    --tev-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    --tev-radius: 12px;
    --tev-transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Base
   ========================================================================== */
.tev-app {
    font-family: 'Montserrat', 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    max-width: 1400px;
    margin: 1.5rem auto;
    padding: 1.5rem;
    background: var(--tev-bg);
    border-radius: var(--tev-radius);
    box-shadow: var(--tev-shadow);
    color: var(--tev-text);
    line-height: 1.5;
    overflow: hidden; /* prevents any overflow from breaking layout */
}

.tev-section {
    margin-bottom: 1.25rem;
}

/* Name Input
   ========================================================================== */
.tev-name-input {
    display: block;
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
    padding: 0.85rem 1.5rem;
    font-family: inherit;
    font-size: 1.1rem;
    font-weight: 500;
    text-align: center;
    background: var(--tev-bg-light);
    border: 2px solid transparent;
    border-radius: var(--tev-radius);
    color: var(--tev-white);
    transition: var(--tev-transition);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

.tev-name-input:focus {
    outline: none;
    border-color: var(--tev-accent);
    background: var(--tev-primary-light);
    box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.2);
}

.tev-name-input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.tev-name-input:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

/* Title
   ========================================================================== */
.tev-title-section {
    text-align: center;
}

.tev-title {
    color: var(--tev-white);
    font-size: clamp(1.3rem, 4vw, 2.2rem);
    font-weight: 800;
    letter-spacing: 1.5px;
    margin: 0;
    padding: 0;
}

/* Keyboard — KEY RESPONSIVE BEHAVIOR
   ========================================================================== */
.tev-keyboard-section {
    background: var(--tev-bg-light);
    padding: 1rem;
    border-radius: var(--tev-radius);
    border: 2px solid rgba(255, 255, 255, 0.1);
}

.tev-keyboard-wrapper {
    /* On desktop, normal width */
    width: 100%;
    /* IMPORTANT: keep the keyboard on a single line, scaled */
    overflow: visible;
    position: relative; /* v5.1.2: needed for absolute-positioned detected indicator */
    position: relative;
}

.tev-piano {
    display: block;
    width: 100%;
    height: auto;
    /* viewBox is 1800x320, preserveAspectRatio xMidYMid meet will scale */
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

/* SVG Keys
   ========================================================================== */
.tev-key-white {
    fill: #ffffff;
    stroke: #1a1a1a;
    stroke-width: 1.5;
    transition: fill 0.1s ease, filter 0.1s ease;
    cursor: pointer;
}

.tev-key-white:hover {
    fill: #f0f0f0;
}

.tev-key-white.tev-active {
    fill: var(--tev-active) !important;
    filter: drop-shadow(0 0 8px rgba(239, 68, 68, 0.7));
}

.tev-key-white.tev-confirmed {
    fill: var(--tev-confirmed) !important;
    filter: drop-shadow(0 0 6px rgba(16, 185, 129, 0.5));
}

.tev-key-white.tev-vocalize-target {
    fill: var(--tev-target) !important;
    filter: drop-shadow(0 0 10px rgba(251, 191, 36, 0.8));
    animation: tev-pulse-target 1s ease-in-out infinite;
}

.tev-key-black {
    fill: var(--tev-black-key);
    stroke: #000;
    stroke-width: 1;
    transition: fill 0.1s ease, filter 0.1s ease;
    cursor: pointer;
}

.tev-key-black:hover {
    fill: #333;
}

.tev-key-black.tev-active {
    fill: var(--tev-active) !important;
    filter: drop-shadow(0 0 8px rgba(239, 68, 68, 0.7));
}

.tev-key-black.tev-confirmed {
    fill: var(--tev-confirmed) !important;
    filter: drop-shadow(0 0 6px rgba(16, 185, 129, 0.5));
}

.tev-key-black.tev-vocalize-target {
    fill: var(--tev-target) !important;
    filter: drop-shadow(0 0 10px rgba(251, 191, 36, 0.8));
    animation: tev-pulse-target 1s ease-in-out infinite;
}

/* v5.1: Detected note indicator (bolinha verde em cima da tecla) */
.tev-detected-indicator {
    position: absolute;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #10b981;
    box-shadow: 0 0 16px rgba(16, 185, 129, 0.9), 0 0 4px rgba(255, 255, 255, 0.8);
    pointer-events: none;
    z-index: 100;
    transition: left 0.08s linear, top 0.08s linear, background 0.15s ease;
    border: 3px solid #fff;
    display: none;
}

.tev-detected-indicator.tev-detected-off {
    background: #ef4444;
    box-shadow: 0 0 12px rgba(239, 68, 68, 0.8), 0 0 4px rgba(255, 255, 255, 0.6);
}

.tev-detected-indicator.tev-detected-half {
    background: #fbbf24;
    box-shadow: 0 0 12px rgba(251, 191, 36, 0.8), 0 0 4px rgba(255, 255, 255, 0.6);
}

.tev-keyboard-wrapper {
    position: relative;
}

    font-family: 'Montserrat', sans-serif;
    font-size: 14px;
    fill: #555;
    text-anchor: middle;
    pointer-events: none;
    user-select: none;
    font-weight: 600;
}

.tev-key-label-black {
    font-family: 'Montserrat', sans-serif;
    font-size: 11px;
    fill: #fff;
    text-anchor: middle;
    pointer-events: none;
    user-select: none;
    font-weight: 600;
}

.tev-ruler-label {
    font-family: 'Montserrat', sans-serif;
    font-size: 14px;
    fill: rgba(255, 255, 255, 0.7);
    text-anchor: middle;
    pointer-events: none;
    user-select: none;
}

@keyframes tev-pulse-target {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

@keyframes tev-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.tev-key-white.tev-active,
.tev-key-black.tev-active {
    animation: tev-pulse 0.6s ease-in-out infinite;
}

/* Classification bars
   ========================================================================== */
.tev-classification-bars {
    margin-top: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.tev-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.tev-bar-label {
    flex: 0 0 110px;
    text-align: right;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--tev-white);
}

.tev-bar-fill {
    flex: 1;
    height: 18px;
    background: linear-gradient(90deg, transparent 0%, var(--bar-color, #888) 100%);
    border-radius: 4px;
    opacity: 0.4;
    transition: var(--tev-transition);
}

.tev-bar.tev-bar-active .tev-bar-fill {
    opacity: 1;
    box-shadow: 0 0 12px var(--bar-color, #888);
}

/* Controls
   ========================================================================== */
.tev-controls-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

/* Gender Selector (v4) */
.tev-gender-selector {
    display: flex;
    gap: 0.5rem;
    background: rgba(0, 0, 0, 0.3);
    padding: 0.5rem 1rem;
    border-radius: var(--tev-radius);
    flex-wrap: wrap;
    justify-content: center;
}

.tev-gender-label {
    color: var(--tev-white);
    cursor: pointer;
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: var(--tev-transition);
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.tev-gender-label:hover {
    background: rgba(255, 255, 255, 0.1);
}

.tev-gender-label input {
    cursor: pointer;
    margin: 0;
}

.tev-gender-label:has(input:checked) {
    background: var(--tev-accent);
    color: var(--tev-primary-dark);
    font-weight: 700;
}

/* Button row (v4) */
.tev-btn-row {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: center;
}

.tev-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.85rem 2rem;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    border: none;
    border-radius: var(--tev-radius);
    cursor: pointer;
    transition: var(--tev-transition);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    min-width: 180px;
}

.tev-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.tev-btn-primary {
    background: var(--tev-accent);
    color: var(--tev-primary-dark);
}

.tev-btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(251, 191, 36, 0.4);
}

.tev-btn-secondary {
    background: #ef4444;
    color: var(--tev-white);
}

.tev-btn-secondary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(239, 68, 68, 0.4);
}

.tev-btn-vocalize {
    background: #8b5cf6;
    color: var(--tev-white);
}

.tev-btn-vocalize:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(139, 92, 246, 0.4);
}

.tev-btn-vocalize-stop {
    background: #ef4444;
    color: var(--tev-white);
}

.tev-btn-warmup {
    background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
    color: var(--tev-white);
}

.tev-btn-freetest {
    background: linear-gradient(135deg, #14b8a6 0%, #0d9488 100%);
    color: var(--tev-white);
}
.tev-btn-freetest:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(20, 184, 166, 0.4);
}
.tev-btn-freetest.tev-btn-freetest-active {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    animation: tev-blink 1.5s ease-in-out infinite;
}
.tev-btn-warmup:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(249, 115, 22, 0.4);
}

.tev-btn-warmup-play {
    background: #f97316;
    color: var(--tev-white);
}

.tev-btn-warmup-stop {
    background: #ef4444;
    color: var(--tev-white);
}

/* v5.1.4: Botão "Carregar MIDI" (label disfarçado de button + input file escondido) */
.tev-btn-warmup-upload {
    background: #6366f1;
    color: var(--tev-white);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}
.tev-btn-warmup-upload:hover {
    background: #4f46e5;
}
.tev-warmup-upload-input {
    /* o input fica visualmente escondido, mas acessível pelo label */
}

.tev-btn-icon {
    font-size: 1.2rem;
}

/* Live Readout
   ========================================================================== */
.tev-live-readout {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1rem 2rem;
    width: 100%;
    background: rgba(0, 0, 0, 0.3);
    padding: 0.75rem 1rem;
    border-radius: var(--tev-radius);
    color: var(--tev-white);
}

.tev-readout-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
    min-width: 90px;
}

.tev-readout-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.7;
    font-weight: 500;
}

.tev-readout-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--tev-accent);
    font-variant-numeric: tabular-nums;
    min-width: 60px;
    text-align: center;
}

/* Progress bar
   ========================================================================== */
.tev-progress {
    width: 100%;
    height: 6px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 3px;
    overflow: hidden;
}

.tev-progress-bar {
    height: 100%;
    width: 0%;
    background: var(--tev-accent);
    transition: width 0.1s linear;
}

/* Results
   ========================================================================== */
.tev-results-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    margin-top: 1.5rem;
    animation: tev-fade-in 0.5s ease;
}

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

.tev-result-box {
    width: 100%;
    background: var(--tev-bg-light);
    padding: 1rem 1.5rem;
    border-radius: var(--tev-radius);
    text-align: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.tev-result-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.7);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.4rem;
}

.tev-result-value {
    font-size: clamp(1.3rem, 3vw, 1.8rem);
    font-weight: 800;
    color: var(--tev-accent);
}

/* Warmup Section (v4) */
.tev-warmup-section {
    background: linear-gradient(135deg, #7c2d12 0%, #431407 100%);
    padding: 1.5rem;
    border-radius: var(--tev-radius);
    margin-top: 1.5rem;
    border: 2px solid #f97316;
    animation: tev-fade-in 0.5s ease;
}

.tev-warmup-header h3 {
    color: var(--tev-white);
    margin: 0 0 0.5rem 0;
    font-size: 1.2rem;
}

.tev-warmup-desc {
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.9rem;
    margin: 0 0 1rem 0;
}

.tev-warmup-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.tev-warmup-select {
    flex: 1;
    min-width: 200px;
    padding: 0.75rem 1rem;
    font-family: inherit;
    font-size: 1rem;
    border: 2px solid transparent;
    border-radius: var(--tev-radius);
    background: var(--tev-bg);
    color: var(--tev-white);
    cursor: pointer;
}

.tev-warmup-select:focus {
    outline: none;
    border-color: #f97316;
}

.tev-warmup-info {
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.9rem;
    padding: 0.75rem;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    margin-bottom: 0.5rem;
}

.tev-warmup-info strong {
    color: #fb923c;
}

.tev-warmup-current {
    color: #fb923c;
    font-size: 1.1rem;
    font-weight: 600;
    text-align: center;
    padding: 0.5rem;
}

/* Vocalize Section
   ========================================================================== */
.tev-vocalize-section {
    background: var(--tev-bg-light);
    padding: 1.5rem;
    border-radius: var(--tev-radius);
    margin-top: 1.5rem;
    border: 2px solid #8b5cf6;
    animation: tev-fade-in 0.5s ease;
}

.tev-vocalize-header h3 {
    color: var(--tev-white);
    margin: 0 0 0.5rem 0;
    font-size: 1.2rem;
}

.tev-vocalize-desc {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.9rem;
    margin: 0 0 1rem 0;
}

.tev-vocalize-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.tev-vocalize-select {
    flex: 1;
    min-width: 200px;
    padding: 0.75rem 1rem;
    font-family: inherit;
    font-size: 1rem;
    border: 2px solid transparent;
    border-radius: var(--tev-radius);
    background: var(--tev-bg);
    color: var(--tev-white);
    cursor: pointer;
    transition: var(--tev-transition);
}

.tev-vocalize-select:focus {
    outline: none;
    border-color: #8b5cf6;
}

.tev-vocalize-info {
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.9rem;
    padding: 0.75rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    margin-bottom: 0.5rem;
}

.tev-vocalize-info strong {
    color: #8b5cf6;
}

.tev-vocalize-current {
    color: var(--tev-accent);
    font-size: 1.1rem;
    font-weight: 600;
    text-align: center;
    padding: 0.5rem;
}

/* Status
   ========================================================================== */
.tev-status {
    text-align: center;
    color: var(--tev-white);
    font-size: 0.9rem;
    min-height: 1.5rem;
    padding: 0.4rem;
}

.tev-status.tev-status-error {
    color: #fca5a5;
    font-weight: 600;
}

.tev-status.tev-status-success {
    color: #6ee7b7;
    font-weight: 600;
}

.tev-recording-indicator {
    display: inline-block;
    width: 10px;
    height: 10px;
    background: #ef4444;
    border-radius: 50%;
    margin-right: 0.5rem;
    animation: tev-blink 1s ease-in-out infinite;
    vertical-align: middle;
}

@keyframes tev-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* ==========================================================================
   RESPONSIVE — KEY FIX: keyboard fits mobile width
   ========================================================================== */

/* Mobile: < 768px */
@media (max-width: 768px) {
    .tev-app {
        margin: 0.5rem;
        padding: 1rem;
    }
    .tev-title {
        font-size: 1.2rem;
        letter-spacing: 1px;
    }
    .tev-keyboard-section {
        padding: 0.5rem;
    }
    /* KEYBOARD: scale down to fit width without horizontal scroll */
    .tev-piano {
        width: 100%;
        max-height: 200px;
    }
    .tev-key-label {
        font-size: 10px;
    }
    .tev-key-label-black {
        font-size: 8px;
    }
    .tev-ruler-label {
        font-size: 9px;
    }
    .tev-bar-label {
        flex: 0 0 90px;
        font-size: 0.75rem;
    }
    .tev-btn {
        padding: 0.75rem 1.5rem;
        font-size: 0.95rem;
        min-width: 150px;
    }
    .tev-live-readout {
        gap: 0.5rem 1rem;
        padding: 0.5rem;
    }
    .tev-readout-item {
        min-width: 70px;
    }
    .tev-readout-value {
        font-size: 1rem;
    }
    .tev-vocalize-section {
        padding: 1rem;
    }
    .tev-vocalize-controls {
        flex-direction: column;
    }
    .tev-vocalize-select {
        min-width: 0;
        width: 100%;
    }
}

/* Small mobile: < 480px */
@media (max-width: 480px) {
    .tev-app {
        margin: 0;
        padding: 0.75rem;
        border-radius: 0;
    }
    .tev-title {
        font-size: 1rem;
        letter-spacing: 0.5px;
    }
    .tev-piano {
        max-height: 160px;
    }
    .tev-key-label {
        font-size: 8px;
    }
    .tev-key-label-black {
        font-size: 7px;
    }
    .tev-ruler-label {
        font-size: 7px;
    }
    .tev-bar-label {
        flex: 0 0 80px;
        font-size: 0.7rem;
    }
    .tev-bar-fill {
        height: 14px;
    }
    .tev-live-readout {
        flex-direction: column;
        gap: 0.5rem;
    }
    .tev-btn {
        width: 100%;
        min-width: 0;
    }
}

/* Tablet: 769-1024px */
@media (min-width: 769px) and (max-width: 1024px) {
    .tev-piano {
        max-height: 220px;
    }
    .tev-key-label {
        font-size: 12px;
    }
    .tev-ruler-label {
        font-size: 11px;
    }
}

/* Desktop: > 1024px */
@media (min-width: 1025px) {
    .tev-piano {
        max-height: 320px;
    }
    .tev-key-label {
        font-size: 16px;
    }
    .tev-key-label-black {
        font-size: 12px;
    }
    .tev-ruler-label {
        font-size: 16px;
    }
}
