* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
}

body {
    overflow: hidden;
    background: #0a0a1a;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

#loading-screen {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0d0d2b 0%, #1a1a4e 40%, #0d2b4e 100%);
    transition: opacity 0.6s ease, visibility 0.6s ease;
}

#loading-screen.hide {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

#loading-screen::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(circle at 20% 30%, rgba(99, 102, 241, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(59, 130, 246, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, rgba(139, 92, 246, 0.1) 0%, transparent 60%);
    animation: bgPulse 4s ease-in-out infinite alternate;
}

@keyframes bgPulse {
    from { opacity: 0.6; }
    to { opacity: 1; }
}

.loading-logo {
    position: relative;
    width: 260px;
    height: auto;
    margin-bottom: 36px;
    z-index: 1;
}

.loading-logo svg,
.loading-logo img {
    width: 100%;
    height: auto;
    object-fit: contain;
    filter: drop-shadow(0 0 18px rgba(255, 255, 255, 0.15));
    animation: logoPulse 2s ease-in-out infinite;
}

.loading-logo.error-state svg,
.loading-logo.error-state img {
    animation: none;
    filter: drop-shadow(0 0 20px rgba(239, 68, 68, 0.6));
}

@keyframes logoPulse {
    0%, 100% {
        filter: drop-shadow(0 0 20px rgba(99, 102, 241, 0.8));
        transform: scale(1);
    }
    50% {
        filter: drop-shadow(0 0 35px rgba(139, 92, 246, 1));
        transform: scale(1.05);
    }
}

.progress-wrapper {
    position: relative;
    width: 280px;
    z-index: 1;
}

.progress-bar-bg {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 99px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #6366f1, #8b5cf6, #3b82f6);
    border-radius: 99px;
    animation: progressAnim 4s ease-in-out forwards;
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.8);
    transition: width 0.4s ease;
}

@keyframes progressAnim {
    0% { width: 0%; }
    40% { width: 55%; }
    70% { width: 75%; }
    90% { width: 88%; }
    100% { width: 95%; }
}

.progress-label {
    margin-top: 12px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.4);
    text-align: center;
    letter-spacing: 0.5px;
}

.dot-anim::after {
    content: '';
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
    0% { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
}

#loading-screen.has-error .progress-wrapper {
    display: none;
}

#error-card {
    display: none;
    margin-top: 8px;
    width: min(340px, calc(100vw - 32px));
    background: rgba(15, 15, 35, 0.85);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 16px;
    padding: 24px;
    text-align: center;
    position: relative;
    z-index: 1;
}

#error-card.show {
    display: block;
}

.error-icon {
    font-size: 32px;
    margin-bottom: 12px;
    display: block;
}

.error-title {
    font-size: 16px;
    font-weight: 600;
    color: #fca5a5;
    margin-bottom: 8px;
}

.error-body {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.5);
    line-height: 1.6;
    margin-bottom: 16px;
}

.error-code {
    display: none;
    font-size: 11px;
    font-family: monospace;
    background: rgba(239, 68, 68, 0.1);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 6px;
    padding: 4px 10px;
    margin-bottom: 16px;
    word-break: break-all;
}

#capacity-hint,
#auto-retry-bar {
    display: none;
    margin-bottom: 16px;
}

#capacity-hint.show,
#auto-retry-bar.show {
    display: block;
}

#capacity-hint,
#auto-retry-bar p {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.35);
    line-height: 1.6;
}

#auto-retry-progress {
    height: 3px;
    background: rgba(99, 102, 241, 0.15);
    border-radius: 99px;
    overflow: hidden;
}

#auto-retry-fill {
    height: 100%;
    width: 100%;
    background: #6366f1;
    border-radius: 99px;
    transition: width linear;
}

.btn-retry {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: rgba(99, 102, 241, 0.2);
    border: 1px solid rgba(99, 102, 241, 0.5);
    border-radius: 10px;
    color: #a5b4fc;
    font-size: 14px;
    font-weight: 500;
    padding: 10px 24px;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s ease, transform 0.1s ease;
}

.btn-retry:hover {
    background: rgba(99, 102, 241, 0.35);
}

.btn-retry:active {
    transform: scale(0.97);
}

#appstream-container {
    width: 100%;
    height: 100%;
    display: none;
}

.loading-logo.error-state.session-ended svg,
.loading-logo.error-state.session-ended img {
    filter: drop-shadow(0 0 22px rgba(99, 102, 241, 0.65));
}

#loading-screen.session-ended #error-card {
    border-color: rgba(99, 102, 241, 0.35);
    background: rgba(15, 15, 35, 0.9);
}

#loading-screen.session-ended .error-title {
    color: #c7d2fe;
}

#loading-screen.session-ended .error-body {
    color: rgba(255, 255, 255, 0.65);
}

#floating-toolbar {
    position: fixed;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 8888;
    display: none;
    align-items: center;
    gap: 6px;
    background: rgba(15, 15, 35, 0.75);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 14px;
    padding: 6px 10px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

.ftb-divider {
    width: 1px;
    height: 22px;
    background: rgba(255, 255, 255, 0.12);
    margin: 0 2px;
}

.ftb {
    position: relative;
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, transform 0.1s ease;
    color: rgba(255, 255, 255, 0.75);
}

.ftb:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.ftb:active {
    transform: scale(0.92);
}

.ftb.active {
    background: rgba(99, 102, 241, 0.25);
    color: #a5b4fc;
    border: 1px solid rgba(99, 102, 241, 0.4);
}

.ftb::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(10, 10, 30, 0.92);
    color: #e2e8f0;
    font-size: 11px;
    white-space: nowrap;
    padding: 4px 8px;
    border-radius: 6px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.ftb:hover::after {
    opacity: 1;
}

.ftb svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.mic-dot {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 7px;
    height: 7px;
    background: #ef4444;
    border-radius: 50%;
    display: none;
    animation: micPulse 1s ease-in-out infinite;
}

.ftb.active .mic-dot {
    display: block;
}

@keyframes micPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.float-panel {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 15, 35, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    padding: 14px;
    z-index: 8887;
    backdrop-filter: blur(12px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

#clipboard-panel {
    width: 280px;
}

.float-panel textarea {
    width: 100%;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: #fff;
    font-size: 13px;
    padding: 8px;
    resize: vertical;
    outline: none;
}

.float-panel-label {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 8px;
    display: block;
}

.float-panel-btn {
    margin-top: 8px;
    width: 100%;
    padding: 8px;
    background: rgba(99, 102, 241, 0.3);
    border: 1px solid rgba(99, 102, 241, 0.5);
    border-radius: 8px;
    color: #a5b4fc;
    font-size: 13px;
    cursor: pointer;
}

.float-panel-btn:hover {
    background: rgba(99, 102, 241, 0.45);
}

.fn-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    width: 264px;
}

.fn-key {
    flex: 1;
    min-width: 48px;
    padding: 8px 4px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 12px;
    cursor: pointer;
    text-align: center;
    transition: background 0.1s;
}

.fn-key:hover {
    background: rgba(99, 102, 241, 0.25);
    color: #a5b4fc;
}

.fn-key:active {
    background: rgba(99, 102, 241, 0.4);
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
    }
}
