:root {
    --magisk-orange: #ff7f59;
    --magisk-dark: #0f0c29;
    --magisk-purple: #302b63;
    --panel-bg: rgba(255, 255, 255, 0.03);
    --panel-border: rgba(255, 255, 255, 0.08);
    --input-bg: rgba(0, 0, 0, 0.3);
    --input-border: rgba(255, 255, 255, 0.1);
    --text-white: #ffffff;
    --text-gray: #9ca3af;
    --ring: rgba(255, 127, 89, 0.3);
    --danger: #ef4444;
}

#mgvg-root * {
    box-sizing: border-box;
}

#mgvg-root {
    font-family: 'Outfit', system-ui, sans-serif;
    color: var(--text-white);
    max-width: 100%;
}

/* --- Layout --- */
#mgvg-root .wrap {
    max-width: 760px;
    margin: 0 auto;
    padding: 16px 14px 32px;
}

/* --- Cards --- */
#mgvg-root .card.glass-card {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 1.5rem;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    padding: 24px;
    margin-bottom: 20px;
    color: var(--text-white);
}

#mgvg-root .card.no-border {
    background: transparent;
    border: none;
    box-shadow: none;
    backdrop-filter: none;
    padding: 0;
}

/* --- Typography --- */
#mgvg-root .section-title {
    font-family: 'Fredoka', sans-serif;
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 4px 0 16px;
    font-size: 18px;
    font-weight: 700;
    color: var(--magisk-orange);
}

/* --- Inputs --- */
#mgvg-root .formgrid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

#mgvg-root .field {
    position: relative;
}

#mgvg-root .input,
#mgvg-root .textarea {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 0.75rem;
    padding: 16px 24px !important;
    font-size: 16px;
    font-family: 'Outfit', sans-serif;
    color: var(--text-white);
    transition: all 0.2s ease;
    box-sizing: border-box;
}

#mgvg-root .textarea {
    min-height: 120px;
    resize: none;
    line-height: 1.5;
}

#mgvg-root .input:focus,
#mgvg-root .textarea:focus {
    outline: none;
    border-color: var(--magisk-orange);
    box-shadow: 0 0 0 4px rgba(255, 127, 89, 0.1);
}

#mgvg-root .input::placeholder,
#mgvg-root .textarea::placeholder {
    color: var(--text-gray);
    font-size: 14px;
    opacity: 0.7;
}

/* Error Messages */
#mgvg-root .inerr {
    position: absolute;
    bottom: -18px;
    right: 4px;
    color: var(--danger);
    font-size: 12px;
    display: none;
}

#mgvg-root .inerr.show {
    display: block;
}

#mgvg-root .input.err,
#mgvg-root .textarea.err {
    border-color: var(--danger);
}

/* --- Checkbox --- */
#mgvg-root .checkline {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    color: var(--text-gray);
    margin-top: 8px;
}

#mgvg-root .checkline a {
    color: var(--magisk-orange);
    text-decoration: none;
    font-weight: 500;
}

#mgvg-root .checkline input[type=checkbox] {
    accent-color: var(--magisk-orange);
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* --- Recording Stage --- */
#mgvg-root .stage {
    display: grid;
    place-items: center;
    min-height: 180px;
    position: relative;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--panel-border);
    border-radius: 1.5rem;
    overflow: hidden;
}

#mgvg-root .row {
    display: grid;
    grid-template-columns: 1fr 14px 1fr;
    align-items: stretch;
    gap: 10px;
}

#mgvg-root .rec-col {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#mgvg-root .centered {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
    display: grid;
    place-items: center;
    gap: 8px;
    width: 100%;
}

#mgvg-root #bgWave {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    opacity: 0.5;
}

/* Circle Button */
#mgvg-root .circle {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    position: relative;
    background: var(--magisk-orange);
    box-shadow: 0 0 20px rgba(255, 127, 89, 0.5);
    z-index: 1;
    cursor: pointer;
    border: none;
    transition: transform 0.2s, box-shadow 0.2s;
}

#mgvg-root .circle:hover {
    transform: scale(1.05);
    box-shadow: 0 0 30px rgba(255, 127, 89, 0.7);
}

#mgvg-root .innerDisc {
    position: absolute;
    inset: 0;
    margin: auto;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #fff;
    z-index: 2;
    pointer-events: none;
}

#mgvg-root .iconSvg {
    position: relative;
    z-index: 3;
    width: 24px;
    height: 24px;
    fill: var(--magisk-orange);
    display: block;
    margin: auto;
}

#mgvg-root #siriViz {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    z-index: 1;
    pointer-events: none;
}

#mgvg-root .circle .pulse {
    position: absolute;
    inset: -10px;
    border-radius: 50%;
    border: 2px solid var(--magisk-orange);
    opacity: 0;
    z-index: 0;
}

#mgvg-root .circle.recording .pulse {
    animation: pulse 1.5s infinite ease-out;
}

@keyframes pulse {
    0% {
        opacity: 0.8;
        transform: scale(0.9);
    }
    100% {
        opacity: 0;
        transform: scale(1.5);
    }
}

#mgvg-root .timer {
    font-family: 'Space Mono', monospace;
    font-size: 14px;
    color: var(--magisk-orange);
    margin-top: 8px;
    display: none;
}

#mgvg-root .recording ~ #timerRow {
    display: block;
}

/* --- Wave Panel --- */
#mgvg-root .wave-panel {
    width: 100%;
    min-height: 200px;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    padding: 16px;
    position: relative;
    z-index: 20;
}

#mgvg-root .wave-panel.show {
    display: flex;
}

#mgvg-root #wave {
    width: 100%;
    height: 80px;
    background: transparent;
    border: 1px solid var(--panel-border);
    border-radius: 12px;
}

#mgvg-root .player {
    margin-top: 16px;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Player Buttons */
#mgvg-root .pbtn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    border-radius: 999px;
    border: 0;
    cursor: pointer;
    font-family: 'Fredoka', sans-serif;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 12px;
    letter-spacing: 0.5px;
    transition: all 0.2s;
}

#mgvg-root .pbtn.icon {
    width: 48px;
    height: 48px;
    padding: 0;
    background: #fff;
    color: var(--magisk-dark);
}

#mgvg-root .pbtn.light {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
}

#mgvg-root .pbtn.light:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: #fff;
}

/* Timeline */
#mgvg-root .timeline {
    position: relative;
    flex: 1;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 999px;
    overflow: hidden;
}

#mgvg-root .track {
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, var(--magisk-orange), #ff4b1f);
    opacity: 0.3;
}

#mgvg-root .playhead {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 0;
    background: var(--magisk-orange);
}

#mgvg-root .timetext {
    font-family: 'Space Mono', monospace;
    font-size: 11px;
    color: var(--text-gray);
    min-width: 80px;
    text-align: right;
}

/* --- Upload / Divider --- */
#mgvg-root .divider {
    width: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#mgvg-root .divider::before {
    content: "";
    width: 1px;
    height: 60%;
    background: rgba(255, 255, 255, 0.1);
}

#mgvg-root .upload-col {
    display: flex;
    flex-direction: column;
    gap: 8px;
    justify-content: center;
}

#mgvg-root .uploadRow input[type=file] {
    display: none;
}

#mgvg-root .fileName {
    color: var(--text-gray);
    font-size: 12px;
    margin-bottom: 4px;
    display: block;
}

#mgvg-root.no-upload .upload-col,
#mgvg-root.no-upload .divider {
    display: none;
}

#mgvg-root.no-upload .row {
    grid-template-columns: 1fr;
}

/* --- Actions --- */
#mgvg-root .actions {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 8px;
}

#mgvg-root .consent {
    font-size: 12px;
    color: var(--text-gray);
    background: transparent;
    border: 1px dashed rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 12px;
    line-height: 1.4;
}

#mgvg-root .consent a {
    color: var(--magisk-orange);
}

#mgvg-root .send {
    width: 100%;
    padding: 20px;
    background: var(--magisk-orange);
    color: #fff;
    font-family: 'Fredoka', sans-serif;
    font-size: 20px;
    font-weight: 700;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(255, 127, 89, 0.4);
    transition: transform 0.2s, box-shadow 0.2s;
}

#mgvg-root .send:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(255, 127, 89, 0.6);
}

#mgvg-root .send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
}

/* --- FIX FÖR DIVI: Flyttade Popups utanför #mgvg-root --- */
.rec-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    background: rgba(15, 12, 41, 0.95);
    border: 1px solid var(--magisk-orange);
    border-radius: 20px;
    padding: 30px;
    /* Hög Z-index för att ligga över Divi menyer */
    z-index: 999999;
    text-align: center;
    min-width: 300px;
    max-width: 90vw;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
    /* Explicit typsnitt då vi flyttar till body */
    font-family: 'Outfit', sans-serif;
}

.rec-popup.active {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.rec-popup-icon {
    font-size: 40px;
    margin-bottom: 12px;
}

.rec-popup h3 {
    font-family: 'Fredoka', sans-serif;
    color: var(--magisk-orange);
    margin: 0 0 8px;
    font-size: 22px;
}

.rec-popup p {
    color: #ffffff;
    margin: 0;
    line-height: 1.5;
}

/* --- Progress Modal (FIXED) --- */
.progress-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    opacity: 0;
    pointer-events: none;
    z-index: 999990; /* Under modalen men över allt annat */
    transition: opacity .2s;
}

.progress-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.progress-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #1a1a2e;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 32px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity .3s;
    z-index: 999999;
    text-align: center;
    min-width: 320px;
    max-width: 90vw;
    color: #fff;
    font-family: 'Outfit', sans-serif;
}

.progress-modal.active {
    opacity: 1;
}

.progress-modal-bar {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 99px;
    margin-bottom: 12px;
    overflow: hidden;
}

.progress-modal-fill {
    height: 100%;
    background: var(--magisk-orange);
    width: 0%;
    transition: width 0.3s;
}

/* Responsive Adjustments */
@media (max-width: 700px) {
    #mgvg-root .actions {
        flex-direction: column;
    }

    #mgvg-root .row {
        grid-template-columns: 1fr;
    }

    #mgvg-root .divider {
        display: none;
    }

    #mgvg-root .textarea {
        min-height: 180px;
    }
    
    #mgvg-root .player {
        flex-wrap: wrap;
    }

    #mgvg-root .control-buttons {
        width: 100%;
        margin-top: 12px;
        display: flex;
        justify-content: center;
        gap: 12px;
    }

    #mgvg-root .control-buttons .pbtn {
        flex: 1;
    }
}

/* Säkerhetsåtgärd: Göm gammal text */
#mgvg-root .rec-instruction {
    display: none !important;
}