:root {
    --bg: #050505;
    --panel: rgba(255, 255, 255, 0.08);
    --panel-strong: rgba(255, 255, 255, 0.92);
    --text: #f7f7f2;
    --muted: #b7b7ae;
    --line: rgba(255, 255, 255, 0.16);
    --accent: #ffffff;
    --accent-2: #d7d7ce;
    --ink: #070707;
    --danger: #ff6f61;
    --radius: 8px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

[hidden] {
    display: none !important;
}

html, body {
    margin: 0;
    min-height: 100%;
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.09), transparent 32%),
        radial-gradient(circle at 74% 10%, rgba(255, 255, 255, 0.12), transparent 28%),
        #050505;
    color: var(--text);
}

body { font-size: 16px; }

a { color: inherit; text-decoration: none; }

.auth-page, .app-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.app-page {
    display: block;
}

.auth-card, .panel, .desktop-panel {
    width: min(100%, 460px);
    padding: 30px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    backdrop-filter: blur(22px);
    box-shadow: 0 30px 90px rgba(0, 0, 0, 0.5);
}

h1, h2 {
    margin: 0 0 12px;
    line-height: 1.12;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.25rem; }

.muted { color: var(--muted); line-height: 1.55; }

.stack { display: grid; gap: 16px; }

label {
    display: grid;
    gap: 8px;
    color: var(--muted);
    font-weight: 700;
}

input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
    padding: 14px 16px;
    font: inherit;
}

select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    padding: 12px 14px;
    font: inherit;
}

input[type="range"] {
    padding: 0;
    accent-color: #ffffff;
}

input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #ffffff;
}

.button, .ghost-button {
    min-height: 46px;
    border: 0;
    border-radius: var(--radius);
    padding: 12px 18px;
    background: var(--accent);
    color: var(--ink);
    font: inherit;
    font-weight: 800;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.button.secondary { background: #dfe7f3; }
.button:hover, .ghost-button:hover, .icon-button:hover:not(:disabled) { transform: translateY(-1px); }

.ghost-button {
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
}

.notice {
    padding: 12px 14px;
    border-radius: var(--radius);
    line-height: 1.45;
}

.notice.danger { background: rgba(255, 107, 107, 0.12); color: #ffd2d2; }
.notice.success { background: rgba(34, 160, 107, 0.14); color: #bcf7dc; }

.topbar, .viewer-ui {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 16px max(18px, env(safe-area-inset-left)) 16px max(18px, env(safe-area-inset-right));
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--line);
}

.viewer-ui {
    position: fixed;
    left: 0;
    right: 0;
}

.brand {
    font-weight: 900;
    letter-spacing: 0;
    text-transform: uppercase;
    font-size: 0.92rem;
}

nav, .viewer-actions, .actions-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.inline-form { margin: 0; display: inline; }

.upload-shell {
    width: min(1180px, 100%);
    margin: 32px auto;
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(280px, 0.9fr);
    gap: 18px;
}

.panel { width: 100%; }

.dropzone {
    position: relative;
    min-height: 210px;
    display: grid;
    place-items: center;
    text-align: center;
    border: 1px dashed rgba(255, 255, 255, 0.42);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.045);
    margin: 18px 0;
    padding: 24px;
}

.dropzone.dragging { border-color: var(--accent); background: rgba(255, 255, 255, 0.1); }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone strong { display: block; font-size: 1.35rem; margin-bottom: 8px; }
.dropzone span { color: var(--muted); }

.progress-wrap { margin: 14px 0; }
.progress-bar { height: 12px; border-radius: 999px; overflow: hidden; background: rgba(255, 255, 255, 0.1); }
.progress-bar span { display: block; width: 0; height: 100%; background: var(--accent); transition: width 160ms ease; }

.results-list, .media-list {
    display: grid;
    gap: 10px;
    margin-top: 16px;
}

.media-item {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 5px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.055);
    color: var(--text);
    text-align: left;
}

.media-item.selected { border-color: var(--accent); background: rgba(255, 255, 255, 0.15); }
.media-item.unsupported { border-color: rgba(255, 120, 120, 0.42); background: rgba(90, 35, 35, 0.24); }
.media-meta { color: var(--muted); font-size: 0.9rem; overflow-wrap: anywhere; }

.media-rank {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--text);
    font-size: 0.78rem;
    font-weight: 900;
}

.media-copy {
    min-width: 0;
    display: grid;
    gap: 4px;
}

.media-copy strong {
    overflow-wrap: anywhere;
}

.order-actions {
    display: flex;
    gap: 6px;
}

.enhance-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-top: 14px;
}

.enhance-controls label {
    font-size: 0.88rem;
}

.enhance-controls select {
    padding: 10px 12px;
}

.icon-button {
    width: 38px;
    min-width: 38px;
    height: 38px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
    font: inherit;
    font-weight: 900;
    cursor: pointer;
}

.media-item .icon-button {
    width: 38px;
}

.icon-button:disabled {
    cursor: not-allowed;
    opacity: 0.35;
}

.compact-button {
    min-height: 38px;
    padding: 8px 12px;
}

.results-list .media-item {
    grid-template-columns: 1fr;
}

.viewer-page {
    min-height: 100vh;
    overflow: hidden;
}

a-scene { height: 100vh; width: 100vw; }

.desktop-panel {
    position: fixed;
    left: 16px;
    bottom: 16px;
    z-index: 4;
    width: min(320px, calc(100vw - 32px));
    padding: 12px;
}

.desktop-panel .actions-row {
    gap: 8px;
    margin-top: 8px;
}

.vr-adjust {
    margin-top: 10px;
    border-top: 1px solid var(--line);
    padding-top: 8px;
}

.vr-adjust summary {
    cursor: pointer;
    color: var(--muted);
    font-weight: 900;
    font-size: 0.86rem;
}

.vr-adjust label {
    margin-top: 8px;
    gap: 4px;
    font-size: 0.82rem;
}

.vr-adjust input[type="range"] {
    height: 18px;
}

.vr-adjust .compact-button {
    min-height: 32px;
    padding: 6px 9px;
    font-size: 0.82rem;
}

.icon-nav {
    width: 48px;
    min-height: 40px;
    padding: 6px 10px;
    font-size: 1.35rem;
    line-height: 1;
}

.horizontal {
    grid-auto-flow: column;
    grid-auto-columns: 46px;
    overflow-x: auto;
    padding: 6px 0 4px;
}

.media-thumb {
    width: 42px;
    height: 48px;
    display: grid;
    place-items: center;
    gap: 2px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    cursor: pointer;
}

.media-thumb.selected {
    background: #ffffff;
    color: #050505;
    border-color: #ffffff;
}

.media-thumb.unsupported {
    background: rgba(90, 35, 35, 0.28);
    border-color: rgba(255, 120, 120, 0.45);
}

.media-thumb.selected.unsupported {
    background: #ffd7d7;
    color: #120606;
}

.thumb-icon {
    font-weight: 900;
    font-size: 1rem;
    line-height: 1;
}

.thumb-index {
    font-size: 0.72rem;
    font-weight: 800;
    opacity: 0.82;
}

.empty-state {
    position: fixed;
    z-index: 6;
    inset: 0;
    display: grid;
    place-content: center;
    text-align: center;
    padding: 24px;
    background: rgba(0, 0, 0, 0.88);
}

.loading-overlay {
    position: fixed;
    z-index: 7;
    left: 50%;
    top: 82px;
    transform: translateX(-50%);
    padding: 10px 14px;
    border-radius: var(--radius);
    background: var(--panel-strong);
    border: 1px solid var(--line);
    color: var(--ink);
    opacity: 0;
    pointer-events: none;
    transition: opacity 160ms ease;
}

.loading-overlay.visible { opacity: 1; }

@media (max-width: 760px) {
    .upload-shell { grid-template-columns: 1fr; margin-top: 16px; }
    .topbar, .viewer-ui { align-items: flex-start; flex-direction: column; }
    .auth-card, .panel { padding: 20px; }
    .desktop-panel { left: 10px; right: auto; bottom: 10px; width: min(320px, calc(100vw - 20px)); max-height: 36vh; overflow: auto; }
    .media-item { grid-template-columns: auto minmax(0, 1fr); }
    .order-actions, .compact-button { grid-column: 2; }
    .order-actions { justify-content: flex-start; }
    .enhance-controls { grid-template-columns: 1fr; }
    h1 { font-size: 1.6rem; }
}
