/* ============================================
   Animations
   ============================================ */

@keyframes popup-enter {
    from {
        transform: translateY(16px) scale(0.97);
        opacity: 0;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

@keyframes backdrop-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 0.55;
    }
    100% {
        transform: scale(2.2);
        opacity: 0;
    }
}

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


/* ============================================
   Popup System
   ============================================ */

.popup-stack {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    pointer-events: none;
}

.popup-stack.active {
    pointer-events: auto;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    animation: backdrop-in 0.25s ease-out;
}

.popup {
    width: auto;
    min-width: min(480px, 90vw);
    max-width: min(600px, 92vw);
    max-height: 85vh;
    padding: 0;
    overflow: hidden;
    background: var(--bg-popup);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    opacity: 0;
}

.popup[anim-state="enter"] {
    animation: popup-enter 0.3s ease-out forwards;
}

.popup[anim-state="stay"] {
    opacity: 1;
}

.popup[anim-state="leave"] {
    animation: popup-enter 0.3s ease-out reverse forwards;
}

.popup-content {
    padding: 28px 32px;
    line-height: 1.6;
    overflow-y: auto;
    flex: 1;
}

.popup-content img {
    width: 100%;
    border-radius: var(--radius-sm);
}

.popup h1, .popup h2, .popup h3,
.popup h4, .popup h5, .popup b {
    color: var(--accent);
}

.popup li {
    margin-left: 1.5em;
    margin-top: 0.4em;
    color: var(--text-dim);
}

.popup .btn-row {
    display: flex;
    gap: 10px;
    padding: 16px 32px 24px;
    justify-content: flex-end;
}

.popup .btn {
    padding: 10px 24px;
    font-size: 0.95em;
    font-weight: 600;
    font-family: inherit;
    border-radius: var(--radius-sm);
    border: none;
    background: var(--accent-dim);
    color: #fff;
    cursor: pointer;
    transition: var(--transition);
}

.popup .btn:hover {
    background: var(--accent);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px var(--accent-dim);
}

.popup .btn:active {
    transform: translateY(0) scale(0.97);
}

.popup .btn.ghost {
    background: transparent;
    color: var(--text-dim);
    border: 1px solid var(--border);
}

.popup .btn.ghost:hover {
    color: var(--text);
    border-color: var(--text-faint);
    box-shadow: none;
}


/* ============================================
   Mic Calibration (inside popup)
   ============================================ */

.mic-check {
    gap: 20px;
    padding: 12px 0;
}

.mic-check .label-upper {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 3px;
    color: var(--text);
}

.mic-check .sentence {
    font-size: 18px;
    font-style: italic;
    font-weight: 300;
    color: var(--text-dim);
    max-width: 400px;
    text-align: center;
    line-height: 1.65;
}

.mic-check .sentence::before {
    content: '\201C';
    color: var(--text-faint);
    margin-right: 2px;
}

.mic-check .sentence::after {
    content: '\201D';
    color: var(--text-faint);
    margin-left: 2px;
}

/* Timer */
.mic-check .timer {
    font-size: 28px;
    font-weight: 300;
    font-variant-numeric: tabular-nums;
    color: #fff;
    opacity: 0;
    transition: opacity var(--transition);
}

.mic-check.recording .timer {
    opacity: 1;
}

/* Mic button + pulse rings */
.mic-wrapper {
    position: relative;
    width: 140px;
    height: 140px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pulse-ring {
    position: absolute;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    border: 2px solid var(--mic-on);
    opacity: 0;
    pointer-events: none;
}

.mic-check.recording .pulse-ring {
    animation: pulse 2s ease-out infinite;
}

.mic-check.recording .pulse-ring:nth-child(2) {
    animation-delay: 0.6s;
}

.mic-check.recording .pulse-ring:nth-child(3) {
    animation-delay: 1.2s;
}

.mic-btn {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 2;
    transition: background var(--transition), transform 0.15s;
}

.mic-btn svg {
    width: 40px;
    height: 40px;
    fill: #fff;
}

.mic-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.06);
}

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

/* Waveform bars */
.waveform {
    display: flex;
    align-items: center;
    gap: 3px;
    height: 50px;
    opacity: 0;
    transition: opacity 0.4s;
}

.mic-check.recording .mic-btn {
    background: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-hover);
    transition: background 300ms;
}

.mic-check.recording .waveform {
    opacity: 1;
    color: var(--accent);
}

.wave-bar {
    width: 4px;
    border-radius: 2px;
    background: var(--accent);
    height: 8px;
    transition: height 0.05s;
}

/* Status & hint */
.mic-check .status {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--accent);
    height: 18px;
    opacity: 0;
    transition: opacity 0.3s;
}

.mic-check.recording .status {
    animation: blink 1.2s ease-in-out infinite;
    color: var(--mic-on);
}

.mic-check .hint {
    font-size: 14px;
    color: var(--text-dim);
    transition: opacity 0.3s;
}

.mic-check.recording .hint {
    opacity: 0;
}

.align-center {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
    padding: 12px 0;
}