html,
body {
    color: #ccc;
    margin: 0;
    padding: 0;
    /* Height handled by p.html inline styles for iOS Safari keyboard fix */
}

#root {
    min-height: 100%;
}

.app-loading {
    display: inline-block;
    position: absolute;
    width: 40px;
    height: 40px;
    left: 0;
    right: 0;
    top: calc(50% - 20px);
    margin: auto;
}

.app-loading img {
    position: absolute;
    height: 25px;
    width: auto;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    margin: auto;
}

.app-loading div {
    box-sizing: border-box;
    display: block;
    position: absolute;
    width: 40px;
    height: 40px;
    margin: 0;
    border: 3.4px solid #7467ef;
    border-radius: 50%;
    animation: app-loading 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
    border-color: #7467ef transparent transparent transparent;
}

.app-loading div:nth-child(1) {
    animation-delay: -0.45s;
}

.app-loading div:nth-child(2) {
    animation-delay: -0.3s;
}

.app-loading div:nth-child(3) {
    animation-delay: -0.15s;
}

@keyframes app-loading {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.gui-not-ready {
    background-color: #400 !important;
    color: #fff !important;
    padding: 12px 18px !important;
    border: dashed 1px #aaa !important;
    border-radius: 5px !important;
}

/* ==================== FANCY NOT READY STYLES ==================== */
.fancy-not-ready-bg {
    min-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #312e81 100%);
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    overflow: hidden;
    position: relative;
}

.bg-orb {
    position: fixed;
    border-radius: 50%;
    filter: blur(60px);
    /* reduced from 100px for performance */
    opacity: 0.3;
    pointer-events: none;
    /* animation: orbFloat 15s ease-in-out infinite; -- disabled for performance */
}

.bg-orb-1 {
    width: 500px;
    height: 500px;
    background: #06b6d4;
    top: -200px;
    left: -200px;
}

.bg-orb-2 {
    width: 400px;
    height: 400px;
    background: #8b5cf6;
    bottom: -150px;
    right: -150px;
    animation-delay: 5s;
}

.bg-orb-3 {
    width: 300px;
    height: 300px;
    background: #ec4899;
    top: 50%;
    right: 10%;
    animation-delay: 10s;
}

@keyframes orbFloat {

    0%,
    100% {
        transform: translate(0, 0) scale(1);
    }

    33% {
        transform: translate(30px, -30px) scale(1.1);
    }

    66% {
        transform: translate(-20px, 20px) scale(0.9);
    }
}

.not-ready-container {
    text-align: center;
    max-width: 520px;
    padding: 20px;
    position: relative;
    z-index: 1;
}

.not-ready-icon {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.2), rgba(236, 72, 153, 0.2));
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 40px;
    position: relative;
    overflow: hidden;
}

.not-ready-icon::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    padding: 3px;
    background: linear-gradient(135deg, #8b5cf6, #ec4899, #06b6d4);
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    /* animation: borderRotate 4s linear infinite; -- disabled for performance */
}

@keyframes borderRotate {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.not-ready-icon svg {
    width: 60px;
    height: 60px;
    /* animation: gentlePulse 3s ease-in-out infinite; -- reduced for performance */
}

@keyframes gentlePulse {

    0%,
    100% {
        transform: scale(1);
        opacity: 0.9;
    }

    50% {
        transform: scale(1.08);
        opacity: 1;
    }
}

.working-dots {
    position: absolute;
    bottom: 25px;
    display: flex;
    gap: 6px;
}

.working-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #8b5cf6;
    animation: dotBounce 1.4s ease-in-out infinite;
}

.working-dot:nth-child(1) {
    animation-delay: 0s;
}

.working-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.working-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes dotBounce {

    0%,
    80%,
    100% {
        transform: scale(0.6);
        opacity: 0.4;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.not-ready-title {
    font-size: 1.8rem;
    font-weight: 700;
    background: linear-gradient(90deg, #fff, #c4b5fd, #fff);
    background-size: 200% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    /* animation: titleShimmer 3s ease infinite; -- disabled for performance */
    margin-bottom: 20px;
}

@keyframes titleShimmer {

    0%,
    100% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }
}

.not-ready-card {
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    padding: 10px 30px;
    margin-top: 35px;
    margin-bottom: 35px;
}

.status-row {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.status-row:last-child {
    border-bottom: none;
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-indicator.active {
    background: #f59e0b;
    box-shadow: 0 0 12px #f59e0b;
    animation: statusPulse 2s ease-in-out infinite;
}

.status-indicator.done {
    background: #10b981;
    box-shadow: 0 0 12px #10b981;
}

.status-indicator.failed {
    background: #ef4444;
    box-shadow: 0 0 12px #ef4444;
}

.status-indicator.pending {
    background: rgba(255, 255, 255, 0.2);
}

@keyframes statusPulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.status-text {
    font-size: 0.95rem;
    color: rgba(255, 255, 255, 0.6);
    text-align: left;
}

.status-text.active {
    color: rgba(255, 255, 255, 0.9);
}

.not-ready-hint {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.4);
    line-height: 1.6;
    margin-bottom: 30px;
}

.not-ready-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

.action-btn {
    padding: 14px 30px;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    border: none;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.action-btn.primary {
    background: linear-gradient(135deg, #8b5cf6, #7c3aed);
    color: #fff;
    box-shadow: 0 8px 25px rgba(139, 92, 246, 0.3);
}

.action-btn.primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 35px rgba(139, 92, 246, 0.4);
}

.action-btn.secondary {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.action-btn.secondary:hover {
    background: rgba(255, 255, 255, 0.12);
}

.action-btn:active {
    transform: scale(0.95);
    opacity: 0.8;
}

.not-ready-footer {
    margin-top: 30px;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.3);
}

.not-ready-footer code {
    color: rgba(255, 255, 255, 0.5);
}

#setup-interrupted {
    display: none;
    opacity: 0;
    transition: opacity 0.5s ease;
}

#setup-interrupted.visible {
    display: flex;
    opacity: 1;
}

/* Hide separator when #setup-interrupted is hidden */
.status-row:has(+ #setup-interrupted:not(.visible)) {
    border-bottom: none;
}

.not-ready-error {
    margin-top: 25px;
    text-align: left;
}

.not-ready-error summary {
    cursor: pointer;
    color: rgba(255, 255, 255, 0.4);
    font-size: 0.85rem;
    margin-bottom: 10px;
}

.not-ready-error pre {
    background: rgba(0, 0, 0, 0.3);
    padding: 15px;
    border-radius: 10px;
    overflow-x: auto;
    font-size: 0.8rem;
    color: #f87171;
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.not-ready-error-section {
    margin-top: 25px;
}

.fix-with-ai-btn {
    margin-top: 15px;
    width: 100%;
}

.fix-with-ai-btn:hover {
    transform: none;
}

.file-error-item {
    margin: 12px 0;
    padding: 10px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    border-left: 3px solid #f87171;
}

.file-error-name {
    font-size: 0.85rem;
    color: #fbbf24;
    font-weight: 600;
    margin-bottom: 6px;
    font-family: monospace;
}

.file-link {
    color: inherit;
    text-decoration: underline;
    text-decoration-style: dotted;
    cursor: pointer;
}

.file-link:hover {
    color: #fff;
    text-decoration-style: solid;
}

.file-error-msg {
    font-size: 0.75rem;
    color: #f87171;
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.stack-trace-details {
    margin-top: 8px;
}

.stack-trace-toggle {
    cursor: pointer;
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.7rem;
    font-family: monospace;
    user-select: none;
}

.stack-trace-toggle:hover {
    color: rgba(255, 255, 255, 0.7);
}

.stack-trace {
    margin-top: 8px !important;
    font-size: 0.65rem !important;
    color: #888 !important;
    max-height: 200px;
    overflow-y: auto;
}

.gui-not-ready {
    display: inline-block;
    padding: 8px 12px;
    margin: 4px;
    background: rgba(251, 191, 36, 0.1);
    border: 1px dashed rgba(251, 191, 36, 0.5);
    border-radius: 4px;
    color: #fbbf24;
    font-size: 0.75rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.gui-not-ready:hover {
    background: rgba(251, 191, 36, 0.35);
    border-color: #fbbf24;
    box-shadow: 0 0 8px rgba(251, 191, 36, 0.5);
    transform: scale(1.02);
}

.gui-not-ready-filename {
    display: block;
    font-size: 0.65rem;
    font-family: monospace;
    opacity: 0.7;
    margin-top: 8px;
}

/* Error overlay close button */
.error-overlay-close {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 10;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.error-overlay-close:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    transform: scale(1.1);
}

.error-overlay-close:active {
    transform: scale(0.95);
}

/* ==================== FANCY LOADER ==================== */
.fancy-loader {
    text-align: center;
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #312e81 100%);
    transition: opacity 0.8s ease-out, transform 0.8s ease-out;
}

.fancy-loader.fade-out {
    opacity: 0;
    transform: scale(0.8);
    pointer-events: none;
}

.blob-container {
    position: relative;
    width: 120px;
    height: 120px;
    margin: 0 auto 16px;
}

.blob {
    position: absolute;
    width: 100%;
    height: 100%;
    background: linear-gradient(45deg, #06b6d4, #8b5cf6, #ec4899);
    background-size: 400% 400%;
    border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%;
    animation: morph 8s ease-in-out infinite, gradient 6s ease infinite;
    filter: blur(1px);
}

.blob::before {
    content: '';
    position: absolute;
    inset: 6px;
    background: linear-gradient(135deg, #0f172a, #1e1b4b);
    border-radius: inherit;
    animation: morph 8s ease-in-out infinite reverse;
}

.blob::after {
    content: '';
    position: absolute;
    inset: 15px;
    background: linear-gradient(45deg, #06b6d4, #8b5cf6);
    background-size: 300% 300%;
    border-radius: 40% 60% 70% 30% / 40% 50% 60% 50%;
    animation: morph 6s ease-in-out infinite, gradient 4s ease infinite reverse;
    opacity: 0.8;
}

@keyframes morph {
    0%,
    100% {
        border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%;
        transform: rotate(0deg) scale(1);
    }

    25% {
        border-radius: 30% 60% 70% 40% / 50% 60% 30% 60%;
        transform: rotate(90deg) scale(1.05);
    }

    50% {
        border-radius: 50% 60% 30% 60% / 30% 60% 70% 40%;
        transform: rotate(180deg) scale(1);
    }

    75% {
        border-radius: 60% 40% 60% 30% / 70% 30% 50% 60%;
        transform: rotate(270deg) scale(1.05);
    }
}

@keyframes gradient {
    0%,
    100% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }
}

.particles {
    position: absolute;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.particle {
    position: absolute;
    width: 3px;
    height: 3px;
    background: #06b6d4;
    border-radius: 50%;
    box-shadow: 0 0 6px #06b6d4, 0 0 12px #8b5cf6;
    animation: float 3s ease-in-out infinite;
}

.particle:nth-child(1) {
    left: 10%;
    top: 20%;
    animation-delay: 0s;
}

.particle:nth-child(2) {
    left: 80%;
    top: 30%;
    animation-delay: 0.5s;
}

.particle:nth-child(3) {
    left: 20%;
    top: 70%;
    animation-delay: 1s;
}

.particle:nth-child(4) {
    left: 70%;
    top: 80%;
    animation-delay: 1.5s;
}

.particle:nth-child(5) {
    left: 50%;
    top: 10%;
    animation-delay: 2s;
}

@keyframes float {
    0%,
    100% {
        transform: translateY(0) scale(1);
        opacity: 0.6;
    }

    50% {
        transform: translateY(-12px) scale(1.2);
        opacity: 1;
    }
}

.loading-text {
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: 0.4em;
    text-transform: uppercase;
    margin-top: 24px;
    margin-left: 1em;
    background: linear-gradient(90deg, #06b6d4, #fff, #ec4899, #06b6d4);
    background-size: 300% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: shimmer 3s linear infinite;
}

@keyframes shimmer {
    0% {
        background-position: 100% 50%;
    }

    100% {
        background-position: -100% 50%;
    }
}

/* Mobile: smaller loader */
@media (max-width: 640px) {
    .blob-container {
        width: 80px;
        height: 80px;
        margin: 0 auto 12px;
    }

    .blob::before {
        inset: 4px;
    }

    .blob::after {
        inset: 10px;
    }

    .particle {
        width: 2px;
        height: 2px;
        box-shadow: 0 0 4px #06b6d4, 0 0 8px #8b5cf6;
    }

    .loading-text {
        font-size: 1rem;
        letter-spacing: 0.3em;
        margin-top: 20px;
        margin-left: 0.8em;
    }
}

@media (max-width: 640px) {
    @keyframes float {
        0%,
        100% {
            transform: translateY(0) scale(1);
            opacity: 0.6;
        }

        50% {
            transform: translateY(-12px) scale(1.2);
            opacity: 1;
        }
    }
}