/* ===== AR Origami Engine V3.0 — Styles ===== */

:root {
    --bg-primary: #0a0a14;
    --bg-secondary: #12122a;
    --bg-card: #1a1a35;
    --bg-card-hover: #222244;
    --text-primary: #e8e8f0;
    --text-secondary: #a0a0c0;
    --text-muted: #6060a0;
    --accent: #6c5ce7;
    --accent-glow: #a29bfe;
    --mountain: #e17055;
    --valley: #0984e3;
    --boundary: #636e72;
    --success: #00b894;
    --warning: #fdcb6e;
    --danger: #d63031;
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.2s ease;
    --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
}

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

html, body {
    height: 100%;
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-overflow-scrolling: touch;
    /* overflow handled per screen size */
}
html { overflow: hidden; }
body { overflow: auto; }

/* ===== Top Navigation ===== */
#topnav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--bg-secondary);
    border-bottom: 1px solid rgba(108, 92, 231, 0.2);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 12px;
    z-index: 100;
    backdrop-filter: blur(12px);
}

#topnav .logo {
    font-size: 20px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), var(--accent-glow));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    white-space: nowrap;
    cursor: pointer;
}

#topnav .logo .icon { font-size: 24px; margin-right: 4px; }

#topnav .spacer { flex: 1; }

#topnav .nav-btn {
    background: var(--bg-card);
    border: 1px solid rgba(108, 92, 231, 0.3);
    color: var(--text-primary);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    transition: all var(--transition);
    white-space: nowrap;
}
#topnav .nav-btn:hover { background: var(--bg-card-hover); border-color: var(--accent); }
#topnav .nav-btn.active { background: var(--accent); border-color: var(--accent); }
#topnav .nav-btn.ar-btn { background: linear-gradient(135deg, #6c5ce7, #a29bfe); border: none; font-weight: 600; }

/* ===== Main Content Area ===== */
#main {
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    bottom: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

/* ===== Views ===== */
.view { display: none; min-height: 100%; }
.view.active { display: flex; }
#gallery-view { overflow-y: auto; }
#detail-view { overflow: hidden; }
#upload-view { overflow-y: auto; }

/* ===== Gallery View ===== */
#gallery-view {
    flex-direction: column;
    padding: 20px;
    gap: 20px;
}

/* Category tabs */
.category-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(108, 92, 231, 0.15);
}

.category-tab {
    padding: 8px 16px;
    border-radius: 20px;
    background: var(--bg-card);
    border: 1px solid transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 13px;
    transition: all var(--transition);
    white-space: nowrap;
}
.category-tab:hover { color: var(--text-primary); border-color: rgba(108, 92, 231, 0.3); }
.category-tab.active { background: var(--accent); color: #fff; }

/* Model grid */
.model-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
}

.model-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: all var(--transition);
    border: 1px solid rgba(108, 92, 231, 0.1);
}
.model-card:hover {
    transform: translateY(-4px);
    border-color: var(--accent);
    box-shadow: 0 8px 32px rgba(108, 92, 231, 0.2);
}

.model-card .thumb {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
}
.model-card .thumb img { width: 100%; height: 100%; object-fit: cover; }

.model-card .info {
    padding: 12px;
}
.model-card .info .name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    text-transform: capitalize;
}
.model-card .info .meta {
    font-size: 11px;
    color: var(--text-muted);
}

/* ===== Detail View ===== */
#detail-view {
    flex-direction: row;
    height: 100%;
}

#detail-view .panel {
    min-width: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid rgba(108, 92, 231, 0.1);
    overflow: hidden;
}
#detail-view .panel:last-child { border-right: none; }

/* Image panel: narrower */
.panel-images {
    flex: 0 0 380px;
    width: 380px;
    max-width: 45vw;
}
/* 3D panel: takes remaining space */
.panel-3d {
    flex: 1 1 auto;
}

.panel-header {
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid rgba(108, 92, 231, 0.15);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.panel-header h3 {
    font-size: 15px;
    font-weight: 600;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.panel-toggle {
    display: none;
    padding: 4px 10px !important;
    font-size: 16px !important;
}

.panel-body {
    flex: 1;
    overflow: hidden;
    position: relative;
    min-height: 0;
}

/* Step image viewer */
.step-viewer {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    position: relative;
}
.step-viewer img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}
.step-viewer .step-counter {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.8);
    color: #fff;
    padding: 5px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-family: var(--font-mono);
}

.step-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    flex-shrink: 0;
}
.step-nav button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid rgba(108, 92, 231, 0.3);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 18px;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.step-nav button:hover { background: var(--accent); border-color: var(--accent); }
.step-nav button:disabled { opacity: 0.3; cursor: not-allowed; }
.step-nav .slider-container { flex: 1; max-width: 160px; }
.step-nav input[type="range"] { width: 100%; accent-color: var(--accent); }

/* 3D viewer */
#three-container {
    width: 100%;
    height: 100%;
    background: radial-gradient(ellipse at center, #1a1a35 0%, #0a0a14 70%);
    touch-action: pan-x pan-y pinch-zoom;
}
#three-container canvas {
    display: block;
    touch-action: pan-x pan-y pinch-zoom;
}

.viewer-controls {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 10;
    pointer-events: none;
}
.viewer-controls button {
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    background: rgba(26, 26, 53, 0.9);
    border: 1px solid rgba(108, 92, 231, 0.3);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 13px;
    transition: all var(--transition);
    backdrop-filter: blur(8px);
    pointer-events: all;
}
.viewer-controls button:hover { background: var(--accent); border-color: var(--accent); }
.viewer-controls button.playing { background: var(--danger); }

/* ===== Upload View ===== */
#upload-view {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
    padding: 40px;
}

.upload-zone {
    width: 100%;
    max-width: 500px;
    aspect-ratio: 2;
    border: 2px dashed rgba(108, 92, 231, 0.4);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    cursor: pointer;
    transition: all var(--transition);
    background: var(--bg-card);
}
.upload-zone:hover, .upload-zone.drag-over {
    border-color: var(--accent);
    background: var(--bg-card-hover);
    box-shadow: 0 0 48px rgba(108, 92, 231, 0.15);
}
.upload-zone .icon { font-size: 56px; }
.upload-zone .text { font-size: 16px; color: var(--text-secondary); }
.upload-zone .hint { font-size: 12px; color: var(--text-muted); }

#processing-status {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}
#processing-status .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(108, 92, 231, 0.2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Buttons ===== */
.btn {
    padding: 10px 24px;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #5b4bd5; box-shadow: 0 4px 16px rgba(108, 92, 231, 0.4); }
.btn-outline { background: transparent; border: 1px solid rgba(108, 92, 231, 0.4); color: var(--accent); }
.btn-outline:hover { background: rgba(108, 92, 231, 0.1); }
.btn-danger { background: var(--danger); color: #fff; }

/* ===== Modal ===== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 200;
    align-items: center;
    justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 24px;
    max-width: 480px;
    width: 90%;
    border: 1px solid rgba(108, 92, 231, 0.2);
}
.modal h3 { margin-bottom: 16px; font-size: 18px; }
.modal p { color: var(--text-secondary); margin-bottom: 12px; line-height: 1.5; font-size: 14px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    border: 1px solid rgba(108, 92, 231, 0.3);
    color: var(--text-primary);
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    z-index: 300;
    animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
    backdrop-filter: blur(12px);
}
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(20px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; } }
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }

/* ===== Responsive ===== */
@media (max-width: 900px) {
    #detail-view {
        flex-direction: column;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
    }

    .panel-images {
        flex: 0 0 auto;
        min-height: 55vh;
        width: 100%;
        max-width: 100%;
        border-right: none;
        border-bottom: 1px solid rgba(108, 92, 231, 0.15);
    }
    .panel-3d {
        flex: 0 0 auto;
        min-height: 60vh;
    }

    .panel-toggle {
        display: inline-flex;
    }

    /* Toggle: show 3D fullscreen, hide images */
    #detail-view.show-3d .panel-images {
        flex: 0 0 auto;
        min-height: 0;
        height: auto;
        overflow: hidden;
        border-bottom: none;
    }
    #detail-view.show-3d .panel-images .panel-body,
    #detail-view.show-3d .panel-images .step-nav {
        display: none;
    }
    #detail-view.show-3d .panel-images .panel-header {
        padding: 6px 12px;
    }
    #detail-view.show-3d .panel-images .panel-header h3,
    #detail-view.show-3d .panel-images .panel-header span {
        display: none;
    }
    #detail-view.show-3d .panel-3d {
        flex: 1 0 auto;
        min-height: 85vh;
    }

    .model-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
    .category-tab { padding: 6px 12px; font-size: 12px; }
    #topnav { padding: 0 12px; gap: 6px; }
    #topnav .nav-btn { padding: 6px 10px; font-size: 12px; }
    .viewer-controls { bottom: 12px; gap: 6px; }
    .viewer-controls button { padding: 8px 16px; font-size: 12px; }
}

@media (max-width: 500px) {
    .panel-images { flex: 0 0 45%; }
    .panel-3d { flex: 1 1 55%; }
    .model-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
    .panel-header h3 { font-size: 13px; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(108, 92, 231, 0.3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(108, 92, 231, 0.5); }
