/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    overflow: hidden;
    font-family: system-ui, -apple-system, sans-serif;
    font-size: 13px;
    background: #111;
    color: #e0e0e0;
}

/* ── Viewport (always full-screen) ───────────────────────────────────────── */
#viewport {
    position: fixed;
    inset: 0;
    overflow: hidden;
}

#viewport canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

/* ── Panel icon buttons ───────────────────────────────────────────────────── */
.panel-btn {
    position: fixed;
    top: 14px;
    z-index: 30;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(12, 12, 18, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    backdrop-filter: blur(8px);
    transition: color 0.15s, border-color 0.15s, background 0.15s, opacity 0.2s ease;
}

.panel-btn:hover  { color: #e0e0e0; border-color: rgba(255, 255, 255, 0.25); }
.panel-btn.active { color: #e8d45a; border-color: rgba(191, 170, 50, 0.7); background: rgba(191, 170, 50, 0.12); }

body.settings-panel-open #browser-btn,
body.browser-panel-open #settings-btn,
body.loading-active #settings-btn {
    opacity: 0;
    pointer-events: none;
}

#browser-btn  { left: 14px; }
#settings-btn { right: 14px; }

/* ── Panel backdrop ───────────────────────────────────────────────────────── */
#panel-backdrop {
    position: fixed;
    inset: 0;
    z-index: 19;
    background: rgba(0, 0, 0, 0.35);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#panel-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
}

/* ── Shared panel shell ───────────────────────────────────────────────────── */
.slide-panel {
    position: fixed;
    top: 0;
    bottom: 0;
    z-index: 20;
    width: 340px;
    display: flex;
    flex-direction: column;
    background: rgba(10, 10, 16, 0.96);
    backdrop-filter: blur(18px);
    color: #e0e0e0;
    transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Browser panel (left) ─────────────────────────────────────────────────── */
#browser-panel {
    left: 0;
    border-right: 1px solid rgba(255, 255, 255, 0.07);
    transform: translateX(-100%);
}

#browser-panel.open { transform: translateX(0); }

/* ── Settings panel (right) ───────────────────────────────────────────────── */
#settings-panel {
    right: 0;
    border-left: 1px solid rgba(255, 255, 255, 0.07);
    transform: translateX(100%);
}

#settings-panel.open { transform: translateX(0); }

/* ── Panel header ─────────────────────────────────────────────────────────── */
.panel-header {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    flex-shrink: 0;
    min-height: 66px;
}

#browser-panel .panel-header { justify-content: flex-end; }

.panel-title {
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #bfaa32;
}

/* ── Panel sections ───────────────────────────────────────────────────────── */
.panel-section {
    padding: 10px 12px;
    flex-shrink: 0;
}

.section-label {
    font-size: 10px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.35);
    margin-bottom: 8px;
}

/* ── Variant selector ─────────────────────────────────────────────────────── */
#variant-selector {
    display: flex;
    gap: 8px;
}

.variant-btn {
    flex: 1;
    padding: 4px;
    background: rgba(255, 255, 255, 0.04);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    cursor: pointer;
    transition: border-color 0.15s;
}

.variant-btn img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: contain;
    display: block;
    border-radius: 3px;
}

.variant-btn:hover  { border-color: rgba(191, 170, 50, 0.5); }
.variant-btn.active { border-color: #bfaa32; }

/* ── Search input ─────────────────────────────────────────────────────────── */
#search-input {
    width: 100%;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: #e0e0e0;
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s;
}

#search-input::placeholder { color: rgba(255, 255, 255, 0.3); }
#search-input:focus { border-color: rgba(191, 170, 50, 0.6); }
#search-input::-webkit-search-cancel-button { display: none; }

/* ── Gender filters ───────────────────────────────────────────────────────── */
.gender-filters {
    display: flex;
    gap: 6px;
    padding-top: 0;
}

.gender-filter {
    flex: 1;
    padding: 5px 0;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 5px;
    color: rgba(255, 255, 255, 0.5);
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.gender-filter:hover  { color: #e0e0e0; border-color: rgba(255,255,255,0.2); }
.gender-filter.active {
    background: rgba(191, 170, 50, 0.15);
    border-color: rgba(191, 170, 50, 0.5);
    color: #e8d45a;
}

/* ── Motion grid ──────────────────────────────────────────────────────────── */
#motion-grid-wrap {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px 12px 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.12) transparent;
}

#motion-grid-wrap::-webkit-scrollbar { width: 4px; }
#motion-grid-wrap::-webkit-scrollbar-track { background: transparent; }
#motion-grid-wrap::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 2px; }

#motion-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    padding-bottom: 8px;
}

#scroll-sentinel {
    grid-column: 1 / -1;
    height: 1px;
}

/* ── Motion card ──────────────────────────────────────────────────────────── */
.motion-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 6px;
    cursor: pointer;
    overflow: hidden;
    transition: border-color 0.15s, background 0.15s;
}

.motion-card:hover  { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.18); }
.motion-card.active { border-color: #bfaa32; background: rgba(191, 170, 50, 0.1); }

.card-thumb {
    width: 100%;
    aspect-ratio: 1;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.2);
}

.card-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.card-info {
    padding: 6px 7px 7px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.card-name {
    font-size: 11px;
    line-height: 1.3;
    color: #d0d0d0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-gender {
    display: inline-block;
    font-size: 9px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 1px 5px;
    border-radius: 3px;
    align-self: flex-start;
}

.card-gender.male   { background: rgba(80, 140, 220, 0.2); color: #80b0f0; }
.card-gender.female { background: rgba(220, 80, 140, 0.2); color: #f080b0; }

/* ── Panel footer ─────────────────────────────────────────────────────────── */
.panel-footer {
    padding: 8px 14px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.3);
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    flex-shrink: 0;
}

/* ── Settings panel content ───────────────────────────────────────────────── */
.settings-body {
    flex: 1;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.12) transparent;
}

.settings-section { padding: 16px 16px 12px; }
.settings-section + .settings-section { border-top: 1px solid rgba(255, 255, 255, 0.07); }
.settings-section--footer { padding-top: 4px; }

.reset-btn {
    width: 100%;
    padding: 8px;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 7px;
    color: rgba(255, 255, 255, 0.45);
    font-size: 12px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}
.reset-btn:hover {
    color: #e06060;
    border-color: rgba(220, 80, 80, 0.4);
}

.settings-section-title {
    font-size: 10px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.35);
    margin-bottom: 12px;
}

.settings-sub-label {
    font-size: 11px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.7);
    margin: 12px 0 6px;
}

.settings-info-panel {
    margin-top: 12px;
}

.settings-info-panel.hidden {
    display: none;
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 4px 0;
    gap: 8px;
}

.info-label { font-size: 11px; font-weight: 500; color: rgba(255, 255, 255, 0.7); flex-shrink: 0; }

.info-value {
    color: #d0d0d0;
    text-align: right;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.perspective-options {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
}

.render-mode-options {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
}

.perspective-btn {
    padding: 9px 0;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 5px;
    color: rgba(255, 255, 255, 0.5);
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.perspective-btn:hover { color: #e0e0e0; border-color: rgba(255, 255, 255, 0.2); }
.perspective-btn.active {
    background: rgba(191, 170, 50, 0.15);
    border-color: rgba(191, 170, 50, 0.5);
    color: #e8d45a;
}

/* ── Loading overlay ──────────────────────────────────────────────────────── */
#loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    pointer-events: none;
    z-index: 5;
}

#loader.active { display: flex; }

.loader-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top: 3px solid #bfaa32;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

#loader-name {
    font-size: 12px;
    color: rgba(17, 17, 17, 0.72);
    max-width: 200px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

/* ── Toast notification ───────────────────────────────────────────────────── */
#toast {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    padding: 9px 16px;
    border-radius: 6px;
    font-size: 13px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 5;
}

#toast.toast-visible { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.toast-error {
    background: rgba(200, 60, 60, 0.92);
    color: #fff;
    border: 1px solid rgba(255, 100, 100, 0.4);
}

/* ── Render stats ─────────────────────────────────────────────────────────── */
#render-stats {
    position: fixed;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 30;
    display: flex;
    gap: 6px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

#render-stats.visible {
    opacity: 1;
}

.render-stat {
    height: 38px;
    padding: 0 10px;
    display: flex;
    align-items: center;
    gap: 5px;
    background: rgba(12, 12, 18, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    backdrop-filter: blur(8px);
}

.render-stat__label {
    font-size: 10px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.45);
}

.render-stat__value {
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
    color: #f3f0d2;
}

/* ── Background color picker ──────────────────────────────────────────────── */
.bg-color-input {
    width: 32px;
    height: 24px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 5px;
    background: none;
    cursor: pointer;
    flex-shrink: 0;
}
.bg-color-input::-webkit-color-swatch-wrapper { padding: 2px; }
.bg-color-input::-webkit-color-swatch         { border: none; border-radius: 3px; }
.bg-color-input::-moz-color-swatch            { border: none; border-radius: 3px; }

/* ── Toggle switch ────────────────────────────────────────────────────────── */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    user-select: none;
}

.toggle-label { font-size: 11px; font-weight: 500; color: rgba(255, 255, 255, 0.7); }

.toggle-switch { position: relative; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; position: absolute; }

.toggle-track {
    display: block;
    width: 36px;
    height: 20px;
    background: rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    transition: background 0.2s;
    position: relative;
}

.toggle-track::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 14px;
    height: 14px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    transition: transform 0.2s, background 0.2s;
}

.toggle-switch input:checked + .toggle-track {
    background: rgba(191, 170, 50, 0.55);
}

.toggle-switch input:checked + .toggle-track::after {
    transform: translateX(16px);
    background: #e8d45a;
}

/* ── Animation controls bar ───────────────────────────────────────────────── */
#animation-controls {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(16px);
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 0 4px;
    min-width: 320px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    filter: drop-shadow(0 2px 12px rgba(0, 0, 0, 0.9));
}

#animation-controls.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0);
}

.ctrl-buttons {
    display: flex;
    align-items: center;
    gap: 4px;
}

.ctrl-btn {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(12, 12, 18, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    backdrop-filter: blur(8px);
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.ctrl-btn:hover {
    color: #e0e0e0;
    border-color: rgba(255, 255, 255, 0.25);
}

.ctrl-btn svg,
.ctrl-btn svg * {
    pointer-events: none;
}

.ctrl-btn--play {
    width: 38px;
    height: 38px;
    color: rgba(255, 255, 255, 0.6);
    border-color: rgba(255, 255, 255, 0.12);
    background: rgba(12, 12, 18, 0.85);
    margin: 0 2px;
}

.ctrl-btn--play:hover {
    color: #e0e0e0;
    border-color: rgba(255, 255, 255, 0.25);
}

/* Progress row */
.ctrl-progress-row {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.ctrl-frame-label {
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    text-shadow: 0 0 6px rgba(0,0,0,1), 0 1px 3px rgba(0,0,0,1);
    min-width: 32px;
    text-align: right;
    flex-shrink: 0;
    letter-spacing: 0.02em;
}

.ctrl-frame-label--total {
    text-align: left;
    color: rgba(255, 255, 255, 0.55);
}

/* Progress bar */
.ctrl-progress {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 5px;
    border-radius: 3px;
    outline: none;
    cursor: pointer;
    filter: drop-shadow(0 1px 3px rgba(0,0,0,0.8));
    background: linear-gradient(
        to right,
        #e8d45a 0%,
        #e8d45a var(--fill, 0%),
        rgba(255, 255, 255, 0.25) var(--fill, 0%),
        rgba(255, 255, 255, 0.25) 100%
    );
}

.ctrl-progress::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid #e8d45a;
    cursor: pointer;
    transition: transform 0.1s;
    box-shadow: 0 0 0 3px rgba(0,0,0,0.4);
}

.ctrl-progress::-webkit-slider-thumb:hover { transform: scale(1.25); }

.ctrl-progress::-moz-range-thumb {
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid #e8d45a;
    cursor: pointer;
    box-shadow: 0 0 0 3px rgba(0,0,0,0.4);
}


/* ── Mobile ───────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    .slide-panel { width: 100vw; }
    #animation-controls { min-width: calc(100vw - 32px); }
}

/* ── WebGL error ──────────────────────────────────────────────────────────── */
#viewport > div[style] { color: #fff; padding: 20px; }
