/* ============================================================
   Project System - Styles
   ============================================================ */

/* Library becomes a column: top bar + row wrapper */
#model-library.model-library {
    flex-direction: column;
}

/* Row wrapper holds the sidebar + content (original library layout) */
.ps-library-row {
    display: flex;
    flex: 1 1 0%;
    min-height: 0;
    width: 100%;
}

/* ---- Library Top Bar ---- */
.ps-library-topbar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: var(--sp-2) var(--sp-5);
    background: #ffffff;
    border-bottom: 1px solid #e5e5ea;
    flex-shrink: 0;
    z-index: 50;
    gap: var(--sp-3);
    min-height: var(--ctl-h);
    box-sizing: border-box;
}

.ps-topbar-right {
    display: flex;
    gap: var(--sp-3);
}

/* Left group: Back (when visible) + the "Get the app" cross-promo button. margin-right:auto
   pushes Save/Load to the right edge; the bar's own gap keeps spacing uniform. */
.ps-topbar-left {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    margin-right: auto;
    min-width: 0;
}
.ps-topbar-left .ps-back-btn { margin-right: 0; } /* the group owns the auto margin now */

/* Cross-promo button — accent-tinted so it reads as an invitation, not a tool.
   Compound selector: this block sits above the .ps-topbar-btn base rule, so it must
   out-rank it rather than rely on source order. */
.ps-topbar-btn.ps-getapp-btn {
    background: rgba(0, 122, 255, 0.08);
    border-color: rgba(0, 122, 255, 0.35);
    color: #007AFF;
    font-weight: 600;
}
.ps-topbar-btn.ps-getapp-btn svg { color: #007AFF; }
.ps-topbar-btn.ps-getapp-btn:hover { background: rgba(0, 122, 255, 0.14); box-shadow: none; }
.ps-topbar-btn.ps-getapp-btn:active { background: rgba(0, 122, 255, 0.2); }
.ps-topbar-btn.ps-getapp-btn span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.ps-topbar-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-3) var(--sp-7);
    border: 1px solid #e5e5ea;
    border-radius: var(--r-md);
    background: #f5f5f7;
    color: #1d1d1f;
    font-size: var(--fs-label);
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, box-shadow 0.15s;
    -webkit-tap-highlight-color: transparent;
    line-height: 1;
    min-height: var(--ctl-h-sm);
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
}

.ps-topbar-btn:hover {
    background: #eaeaec;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.ps-topbar-btn:active {
    background: #ddd;
    transform: scale(0.97);
}

.ps-topbar-btn svg {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    color: #555;
}

.ps-back-btn {
    background: transparent;
    border-color: transparent;
    margin-right: auto;
    color: #007AFF;
}

.ps-back-btn svg {
    color: #007AFF;
}

.ps-back-btn:hover {
    background: rgba(0, 122, 255, 0.08);
    box-shadow: none;
}

.ps-back-btn:active {
    background: rgba(0, 122, 255, 0.12);
}

/* ---- Overlay (shared by Save dialog & Project browser) ---- */
.ps-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: psFadeIn 0.15s ease;
}

@keyframes psFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ---- Save Dialog ---- */
.ps-save-dialog {
    background: #1e1e1e;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--r-lg);
    padding: var(--sp-9) var(--sp-9) var(--sp-8);
    width: 90%;
    max-width: 380px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    animation: psSlideUp 0.2s ease;
}

@keyframes psSlideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.ps-dialog-title {
    margin: 0 0 var(--sp-6);
    font-size: var(--fs-title);
    font-weight: 600;
    color: #fff;
}

.ps-name-input {
    width: 100%;
    box-sizing: border-box;
    padding: var(--sp-4) var(--sp-5);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: var(--r-sm);
    background: rgba(255, 255, 255, 0.07);
    color: #fff;
    font-size: var(--fs-input);
    outline: none;
    transition: border-color 0.15s;
}

.ps-name-input:focus {
    border-color: #007aff;
}

/* ---- Overwrite existing project list ---- */
.ps-overwrite-section {
    margin-top: var(--sp-5);
}

.ps-overwrite-label {
    font-size: var(--fs-caption);
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: var(--sp-2);
}

.ps-overwrite-list {
    max-height: 180px;
    overflow-y: auto;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--r-sm);
    background: rgba(0, 0, 0, 0.2);
}

.ps-overwrite-item {
    display: flex;
    align-items: center;
    gap: var(--sp-4);
    padding: var(--sp-3) var(--sp-4);
    cursor: pointer;
    transition: background 0.12s;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.ps-overwrite-item:last-child {
    border-bottom: none;
}

.ps-overwrite-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

.ps-overwrite-item.ps-overwrite-selected {
    background: rgba(0, 122, 255, 0.2);
    outline: 1px solid rgba(0, 122, 255, 0.5);
    outline-offset: -1px;
    border-radius: var(--r-sm);
}

.ps-overwrite-thumb {
    width: 36px;
    height: 36px;
    border-radius: var(--r-sm);
    background: rgba(255, 255, 255, 0.07);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--icon-md);
    overflow: hidden;
}

.ps-overwrite-info {
    flex: 1;
    min-width: 0;
}

.ps-overwrite-name {
    font-size: var(--fs-body);
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ps-overwrite-date {
    font-size: var(--fs-caption);
    color: rgba(255, 255, 255, 0.4);
    margin-top: 1px;
}

.ps-btn-row {
    display: flex;
    justify-content: flex-end;
    gap: var(--sp-3);
    margin-top: var(--sp-7);
}

.ps-btn {
    padding: var(--sp-3) var(--sp-8);
    border: none;
    border-radius: var(--r-sm);
    font-size: var(--fs-label);
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.ps-btn-cancel {
    background: rgba(255, 255, 255, 0.1);
    color: #ccc;
}

.ps-btn-cancel:hover { background: rgba(255, 255, 255, 0.16); }

.ps-btn-save {
    background: #007aff;
    color: #fff;
}

.ps-btn-save:hover { background: #0068d6; }

/* ---- Project Browser Panel ---- */
.ps-browser-panel {
    background: #1e1e1e;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--r-lg);
    width: 92%;
    max-width: 520px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    animation: psSlideUp 0.2s ease;
    overflow: hidden;
}

.ps-browser-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--sp-7) var(--sp-9) var(--sp-5);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.ps-browser-close {
    background: none;
    border: none;
    color: #aaa;
    font-size: var(--icon-lg);
    line-height: 1;
    cursor: pointer;
    padding: 0 var(--sp-1);
}

.ps-browser-close:hover { color: #fff; }

.ps-browser-grid {
    padding: var(--sp-6);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: var(--sp-4);
}

.ps-browser-empty {
    text-align: center;
    color: #888;
    padding: 40px 0;
    font-size: var(--fs-body);
}

/* Scroll container holding the Cloud / Local sections */
.ps-browser-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.ps-section-label {
    padding: var(--sp-5) var(--sp-7) 2px;
    font-size: var(--fs-caption);
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #9aa0a8;
}

/* Cloud-synced badge on a project card preview */
.ps-project-cloud-badge {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    color: #6cb8ff;
    font-size: 11px;
    line-height: 18px;
    text-align: center;
}

/* ============================================================
   WebGL Home menu — replaces the in-app model library on real
   WebGL builds (the library lives on the website instead).
   Only visible when <body> has .is-webgl-build.
   ============================================================ */
.ps-webgl-home { display: none; }
.is-webgl-build #model-library { position: relative; }
.is-webgl-build .ps-library-row { display: none !important; }
.is-webgl-build .ps-library-topbar { display: none !important; }
.is-webgl-build .ps-webgl-home {
    display: flex;
    position: absolute;
    inset: 0;
    z-index: 30;
    align-items: center;
    justify-content: center;
    background: #f5f5f7;
}
.ps-webgl-home-inner {
    width: 320px;
    max-width: 86vw;
    display: flex;
    flex-direction: column;
    gap: var(--sp-5);
}
.ps-webgl-home-title {
    font-size: var(--fs-label);
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #86868b;
    text-align: center;
    margin-bottom: var(--sp-1);
}
.ps-home-btn {
    display: flex;
    align-items: center;
    gap: var(--sp-5);
    width: 100%;
    padding: var(--sp-6) var(--sp-8);
    border: 1px solid #d2d2d7;
    border-radius: var(--r-md);
    background: #fff;
    color: #1d1d1f;
    font-size: var(--fs-input);
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.12s, border-color 0.12s, transform 0.08s;
}
.ps-home-btn:hover { background: #f0f0f3; }
.ps-home-btn:active { transform: scale(0.99); }
.ps-home-btn svg { width: var(--icon-md); height: var(--icon-md); flex-shrink: 0; }
.ps-home-btn--primary { background: #007AFF; border-color: #007AFF; color: #fff; }
.ps-home-btn--primary:hover { background: #0066d6; }
.ps-home-btn--ghost {
    background: transparent;
    border-color: transparent;
    color: #007AFF;
    justify-content: center;
    font-size: var(--fs-label);
    padding: var(--sp-4);
}
.ps-home-btn--ghost:hover { background: rgba(0, 122, 255, 0.08); }

/* ---- Project Card ---- */
.ps-project-card {
    display: flex;
    align-items: center;
    gap: var(--sp-5);
    padding: var(--sp-4) var(--sp-5);
    border-radius: var(--r-md);
    background: rgba(255, 255, 255, 0.04);
    cursor: pointer;
    transition: background 0.15s;
    position: relative;
}

.ps-project-card:hover {
    background: rgba(255, 255, 255, 0.09);
}

.ps-project-preview {
    position: relative;
    width: 56px;
    height: 56px;
    border-radius: var(--r-sm);
    background-color: #333;
    background-size: cover;
    background-position: center;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.ps-project-info {
    flex: 1;
    min-width: 0;
}

.ps-project-name {
    font-size: var(--fs-body);
    font-weight: 500;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ps-project-details {
    font-size: var(--fs-caption);
    color: #888;
    margin-top: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ps-project-delete {
    background: none;
    border: none;
    color: #fff;
    font-size: 20px;
    padding: var(--sp-1) var(--sp-3);
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.15s, transform 0.15s;
    flex-shrink: 0;
}

.ps-project-delete:hover {
    opacity: 1;
    transform: scale(1.05);
}

/* ---- Toast ---- */
.ps-toast {
    position: fixed;
    bottom: calc(24px + env(safe-area-inset-bottom)); /* clear the home indicator on notched phones */
    left: 50%;
    transform: translateX(-50%) translateY(12px);
    background: #333;
    color: #fff;
    padding: var(--sp-4) var(--sp-9);
    border-radius: var(--r-md);
    font-size: var(--fs-body);
    font-weight: 500;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 20000;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.ps-toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
