/* === Reset === */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    width: 100%; height: 100%; overflow: hidden;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0a0a14;
    color: #e0e0e0;
    -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }

/* === Viewer === */
#viewer-container {
    width: 100%; height: 100%; position: relative;
}
model-viewer {
    width: 100%; height: 100%;
    background: radial-gradient(ellipse at 50% 40%, #141428 0%, #0a0a14 100%);
    --poster-color: transparent;
}

/* === Loading === */
#loading-screen {
    position: fixed; inset: 0; z-index: 1000;
    display: flex; align-items: center; justify-content: center;
    background: #0a0a14;
    transition: opacity 0.6s ease;
}
#loading-screen.fade-out { opacity: 0; pointer-events: none; }

.loader-content { text-align: center; }
.brand-mark { margin-bottom: 20px; }
.brand-logo { width: 56px; height: 56px; }

.loader-content h2 {
    font-size: 1.4rem; font-weight: 700; margin-bottom: 24px;
    background: linear-gradient(135deg, #6E5FF6, #3B82F6);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text; letter-spacing: -0.02em;
}
.spinner {
    width: 36px; height: 36px; margin: 0 auto 16px;
    border: 3px solid rgba(255,255,255,0.08);
    border-top-color: #6E5FF6; border-right-color: #3B82F6;
    border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-content p { font-size: 0.8rem; color: #666; text-transform: uppercase; letter-spacing: 0.02em; }

/* === Progress bar === */
#progress-bar {
    position: absolute; bottom: 0; left: 0; width: 100%; height: 2px;
    background: rgba(255,255,255,0.05);
}
#progress-fill {
    height: 100%; width: 0%;
    background: linear-gradient(90deg, #6E5FF6, #3B82F6);
    transition: width 0.3s ease;
}

/* === Top bar === */
#top-bar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 20;
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px;
    background: linear-gradient(180deg, rgba(10,10,20,0.7) 0%, transparent 100%);
    pointer-events: none;
}
#top-bar > * { pointer-events: auto; }

.top-bar-brand { display: flex; align-items: center; gap: 10px; }
.top-bar-logo { width: 32px; height: 32px; }
.top-bar-text { display: flex; flex-direction: column; gap: 1px; }
.top-bar-name {
    font-size: 0.95rem; font-weight: 700; line-height: 1.1;
    background: linear-gradient(135deg, #6E5FF6, #3B82F6);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text; letter-spacing: -0.02em;
}
.top-bar-label { font-size: 0.65rem; font-weight: 500; color: #888; text-transform: uppercase; letter-spacing: 0.06em; }

#info-toggle {
    width: 36px; height: 36px; border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.1);
    background: rgba(20,20,40,0.6);
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    color: #999; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.2s, color 0.2s;
}
#info-toggle:active { background: rgba(110,95,246,0.2); color: #fff; }

/* === Info panel === */
#info-content {
    position: fixed; top: 56px; right: 16px; z-index: 25;
    background: rgba(18,18,35,0.95);
    backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    border-radius: 14px; padding: 18px; width: 230px;
    border: 1px solid rgba(110,95,246,0.12);
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
#info-content h3 { font-size: 0.9rem; font-weight: 600; color: #fff; margin-bottom: 6px; }
#info-content p { font-size: 0.78rem; color: #888; margin-bottom: 10px; }

.structure-list {
    list-style: none; padding: 0; margin: 0 0 12px;
    display: flex; flex-wrap: wrap; gap: 5px 12px;
}
.structure-list li { display: flex; align-items: center; gap: 6px; font-size: 0.75rem; color: #aaa; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot-brain     { background: #d9a6b0; }
.dot-skull     { background: #e6d9c0; }
.dot-face      { background: #e0c5a6; }
.dot-tumor     { background: #e62626; }
.dot-ventricle { background: #4d80e6; }

.info-link {
    display: block; margin-top: 10px; padding-top: 10px;
    border-top: 1px solid rgba(255,255,255,0.06);
    font-size: 0.75rem; color: #6E5FF6; text-decoration: none;
}
.info-link:hover { color: #3B82F6; }

/* === Part label === */
#part-label {
    position: fixed; top: 70px; left: 50%; transform: translateX(-50%); z-index: 20;
    background: rgba(110,95,246,0.9);
    border-radius: 10px; padding: 8px 18px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
    animation: label-in 0.25s ease-out;
}
#part-label span { font-size: 0.85rem; font-weight: 600; color: #fff; }

@keyframes label-in {
    from { opacity: 0; transform: translateX(-50%) translateY(-6px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* === Toast === */
#toast {
    position: fixed; bottom: 140px; left: 50%; transform: translateX(-50%);
    z-index: 20;
    background: rgba(10,10,20,0.85);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(110,95,246,0.15);
    border-radius: 12px; padding: 10px 18px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    animation: toast-in 0.3s ease-out;
    max-width: 90vw; text-align: center;
}
#toast.fade-out { animation: toast-out 0.3s ease-in forwards; }
#toast span { font-size: 0.82rem; font-weight: 500; color: #ddd; }

@keyframes toast-in {
    from { opacity: 0; transform: translateX(-50%) translateY(8px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes toast-out {
    from { opacity: 1; transform: translateX(-50%) translateY(0); }
    to   { opacity: 0; transform: translateX(-50%) translateY(8px); }
}

/* === Zoom slider === */
#zoom-control {
    position: fixed; bottom: 136px; left: 50%; transform: translateX(-50%);
    z-index: 20;
    display: flex; align-items: center; gap: 8px;
    background: rgba(10,10,20,0.7);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px; padding: 8px 14px;
    max-width: 260px; width: 70vw;
}
.zoom-icon { color: #888; flex-shrink: 0; }

#zoom-slider {
    -webkit-appearance: none; appearance: none;
    width: 100%; height: 4px;
    background: rgba(255,255,255,0.12);
    border-radius: 2px; outline: none;
}
#zoom-slider::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 20px; height: 20px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6E5FF6, #3B82F6);
    border: 2px solid rgba(255,255,255,0.3);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(110,95,246,0.4);
}
#zoom-slider::-moz-range-thumb {
    width: 20px; height: 20px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6E5FF6, #3B82F6);
    border: 2px solid rgba(255,255,255,0.3);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(110,95,246,0.4);
}

/* === Enter AR button === */
#enter-ar-btn {
    position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
    z-index: 20;
    display: flex; align-items: center; gap: 8px;
    background: linear-gradient(135deg, #6E5FF6, #3B82F6);
    color: #fff; padding: 14px 28px; font-size: 0.95rem;
    font-family: 'Inter', sans-serif; font-weight: 600;
    border: none; border-radius: 14px; cursor: pointer;
    box-shadow: 0 4px 20px rgba(110,95,246,0.35), 0 0 40px rgba(59,130,246,0.1);
    transition: transform 0.15s, opacity 0.15s;
}
#enter-ar-btn:active { transform: translateX(-50%) scale(0.96); }
#enter-ar-btn svg { width: 20px; height: 20px; }

/* === Bottom bar === */
#bottom-bar {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 15;
    padding: 14px 16px;
    background: linear-gradient(0deg, rgba(10,10,20,0.7) 0%, transparent 100%);
    text-align: center; pointer-events: none;
}
.powered-by {
    pointer-events: auto; font-size: 0.72rem; color: #555;
    text-decoration: none; letter-spacing: 0.01em;
}
.powered-by strong { color: #777; font-weight: 600; }
.powered-by:hover { color: #999; }
.powered-by:hover strong { color: #6E5FF6; }

/* === Mobile === */
@media (max-width: 480px) {
    #zoom-control { bottom: 120px; max-width: 220px; }
    #enter-ar-btn { bottom: 64px; padding: 12px 24px; font-size: 0.9rem; }
    #info-content { width: 200px; right: 12px; }
    #top-bar { padding: 10px 12px; }
}

/* === Safe areas === */
@supports (padding-top: env(safe-area-inset-top)) {
    #top-bar { padding-top: calc(12px + env(safe-area-inset-top)); }
    #info-content { top: calc(56px + env(safe-area-inset-top)); right: calc(16px + env(safe-area-inset-right)); }
    #zoom-control { bottom: calc(136px + env(safe-area-inset-bottom)); }
    #enter-ar-btn { bottom: calc(80px + env(safe-area-inset-bottom)); }
    #bottom-bar { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
}

/* === AR overlay (WebXR DOM overlay on Android) === */
#ar-overlay {
    position: fixed; inset: 0; z-index: 30;
    display: flex; flex-direction: column; justify-content: space-between;
    padding: 20px 16px;
    pointer-events: none;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}
#ar-overlay > * { pointer-events: auto; }

#ar-status-bar {
    align-self: center;
    background: rgba(0,0,0,0.65);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    border-radius: 12px; padding: 10px 20px;
    max-width: 90vw; text-align: center;
}
#ar-status-text {
    font-size: 0.82rem; font-weight: 500; color: #fff;
}

#ar-controls {
    display: flex; justify-content: center; gap: 12px;
    padding-bottom: env(safe-area-inset-bottom, 16px);
}
.ar-ctrl-btn {
    display: flex; align-items: center; gap: 6px;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 12px; padding: 12px 20px;
    color: #fff; font-size: 0.85rem; font-weight: 600;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}
.ar-ctrl-btn:active {
    background: rgba(110,95,246,0.5);
    transform: scale(0.96);
}
.ar-ctrl-btn svg { flex-shrink: 0; }

/* === iOS AR tips modal === */
#ar-tips-modal {
    position: fixed; inset: 0; z-index: 100;
    display: flex; align-items: center; justify-content: center;
}
.ar-tips-backdrop {
    position: absolute; inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.ar-tips-card {
    position: relative; z-index: 1;
    background: rgba(18,18,35,0.97);
    border: 1px solid rgba(110,95,246,0.2);
    border-radius: 18px; padding: 28px 24px;
    width: 280px; max-width: 90vw;
    box-shadow: 0 12px 40px rgba(0,0,0,0.6);
}
.ar-tips-close {
    position: absolute; top: 12px; right: 14px;
    background: none; border: none; color: #666;
    font-size: 1.4rem; cursor: pointer; line-height: 1;
}
.ar-tips-close:active { color: #fff; }

.ar-tips-card h3 {
    font-size: 1.05rem; font-weight: 700; color: #fff; margin-bottom: 16px;
    background: linear-gradient(135deg, #6E5FF6, #3B82F6);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
}
.ar-tips-list {
    list-style: none; padding: 0; margin: 0 0 14px;
}
.ar-tips-list li {
    font-size: 0.85rem; color: #bbb; margin-bottom: 8px; padding-left: 6px;
}
.ar-tips-list li::before {
    content: ''; display: inline-block;
    width: 6px; height: 6px; border-radius: 50%;
    background: #6E5FF6; margin-right: 10px;
    vertical-align: middle;
}
.ar-tips-list strong { color: #fff; font-weight: 600; }

.ar-tips-note {
    font-size: 0.78rem; color: #777; margin-bottom: 18px; line-height: 1.4;
}
.ar-tips-btn {
    display: block; width: 100%;
    background: linear-gradient(135deg, #6E5FF6, #3B82F6);
    color: #fff; padding: 13px 24px; font-size: 0.95rem;
    font-family: 'Inter', sans-serif; font-weight: 600;
    border: none; border-radius: 12px; cursor: pointer;
    box-shadow: 0 4px 16px rgba(110,95,246,0.3);
    transition: transform 0.1s;
}
.ar-tips-btn:active { transform: scale(0.97); }
