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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #0a1628 0%, #1a2a4a 50%, #0d1f3c 100%);
    color: #e0f0ff;
    -webkit-text-size-adjust: none;
}

body {
    display: flex;
    flex-direction: column;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.viewer-container {
    flex: 1 1 auto;
    position: relative;
    width: 100%;
    min-height: 280px;
    overflow: hidden;
}

#canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
    outline: none;
}

#model-viewer-wrap {
    width: 100%;
    height: 100%;
}

model-viewer {
    width: 100%;
    height: 100%;
    background-color: #0a1628;
    --poster-color: #0a1628;
    --progress-bar-color: #00c8ff;
    --progress-mask: #0a1628;
}

.loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0a1628 0%, #1a2a4a 50%, #0d1f3c 100%);
    z-index: 100;
    padding: 20px;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(0, 200, 255, 0.2);
    border-top-color: #00c8ff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading p {
    margin-top: 20px;
    font-size: 16px;
    color: #80d0ff;
    text-align: center;
    word-break: break-word;
}

.progress-bar-wrap {
    width: 200px;
    max-width: 80vw;
    height: 6px;
    background: rgba(0, 200, 255, 0.15);
    border-radius: 3px;
    margin-top: 16px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #00c8ff, #00e0ff);
    border-radius: 3px;
    transition: width 0.15s ease-out;
    width: 0%;
}

.progress-percent {
    margin-top: 10px;
    font-size: 14px;
    color: #00c8ff;
    font-weight: 500;
}

.error {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(20, 30, 50, 0.95);
    padding: 30px;
    border-radius: 12px;
    border: 1px solid rgba(0, 200, 255, 0.3);
    text-align: center;
    z-index: 100;
    max-width: 90vw;
}

.error p {
    color: #ff6080;
    font-size: 16px;
    word-break: break-word;
}

.retry-btn {
    margin-top: 16px;
    font-size: 15px;
    padding: 12px 24px;
}

.hidden {
    display: none !important;
}

.mobile-fallback {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(20, 30, 50, 0.95);
    padding: 24px;
    border-radius: 12px;
    border: 1px solid rgba(0, 200, 255, 0.3);
    text-align: center;
    z-index: 100;
    max-width: 90vw;
}

.mobile-fallback p {
    color: #ff6080;
    font-size: 14px;
    margin-bottom: 16px;
    word-break: break-word;
}

.controls {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    padding: 10px;
    background: rgba(10, 22, 40, 0.85);
    backdrop-filter: blur(10px);
    z-index: 50;
}

.control-row {
    display: flex;
    gap: 10px;
}

.view-buttons {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
}

.btn {
    background: rgba(20, 40, 70, 0.8);
    border: 1px solid rgba(0, 200, 255, 0.4);
    color: #00c8ff;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.btn:active {
    background: rgba(0, 200, 255, 0.2);
    border-color: #00c8ff;
}

.btn.active {
    background: rgba(0, 200, 255, 0.3);
    border-color: #00c8ff;
}

.view-btn {
    padding: 8px 12px;
    font-size: 12px;
}

.model-info {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(20, 30, 50, 0.9);
    padding: 12px;
    border-radius: 10px;
    border: 1px solid rgba(0, 200, 255, 0.3);
    font-size: 13px;
    max-width: 220px;
    backdrop-filter: blur(10px);
    z-index: 50;
    pointer-events: none;
}

.model-info p {
    margin: 3px 0;
    color: #a0d8ff;
}

.model-info strong {
    color: #00c8ff;
}

.download-buttons {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 50;
}

.download-btn {
    background: rgba(0, 200, 255, 0.15);
    border: 1px solid rgba(0, 200, 255, 0.5);
    color: #00c8ff;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 13px;
    text-decoration: none;
    text-align: center;
    transition: all 0.2s;
    backdrop-filter: blur(10px);
    -webkit-tap-highlight-color: transparent;
}

.download-btn:active {
    background: rgba(0, 200, 255, 0.3);
    border-color: #00c8ff;
}

.diagnostics {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.85);
    color: #0f0;
    font-family: monospace;
    font-size: 9px;
    padding: 4px 6px;
    z-index: 300;
    max-height: 22vh;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
    line-height: 1.2;
    border-top: 1px solid #0f0;
}

@media (max-width: 600px) {
    .model-info {
        left: 8px;
        right: auto;
        max-width: 180px;
        font-size: 11px;
        padding: 10px;
    }

    .download-buttons {
        top: 10px;
        right: 8px;
        flex-direction: column;
    }

    .download-btn {
        padding: 6px 10px;
        font-size: 11px;
    }

    .btn {
        padding: 8px 12px;
        font-size: 12px;
    }

    .view-btn {
        padding: 6px 8px;
        font-size: 11px;
    }

    .controls {
        padding: 8px;
        gap: 6px;
    }

    .mobile-fallback {
        padding: 20px;
    }

    .mobile-fallback p {
        font-size: 13px;
    }
}
