/* Project viewer: full-screen overlay that shows a project in place.
   Colors and fonts come from the page's own variables (--ink-*, --accent, --font-*). */

html.pv-open { overflow: hidden; }
html.pv-open body { position: fixed; left: 0; right: 0; width: 100%; overflow: hidden; }   /* pinned at its scroll offset, see lockPage() */

/* Fully covered (set by js/project-viewer.js once the overlay has faded in): the page under the viewer is
   not drawn at all and every animation on it is frozen, so the GPU and CPU work only on the open project.
   visibility keeps the page's layout, so the scroll position is untouched and nothing reflows on close.
   With nothing left behind it, the overlay drops its blur (a full-screen blur re-renders every frame the
   project draws) and becomes solid in the same color it already looks. */
html.pv-covered body > *:not(.pv) { visibility: hidden; }
html.pv-covered body > *:not(.pv),
html.pv-covered body > *:not(.pv) *,
html.pv-covered body > *:not(.pv) *::before,
html.pv-covered body > *:not(.pv) *::after { animation-play-state: paused !important; }
html.pv-covered .pv { -webkit-backdrop-filter: none; backdrop-filter: none; background: var(--ink-0, #0f0f12); }

.pv {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    background: rgba(15, 15, 18, 0.94);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    opacity: 0;
    transition: opacity 0.3s ease;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}
.pv[hidden] { display: none; }
.pv:focus { outline: none; }                     /* the viewer itself takes focus on open; no ring around the whole screen */
.pv.on { opacity: 1; }

/* Top bar */
.pv-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: 36px;               /* slim, so the project gets the screen; was 44px */
    padding: 0 max(0.75rem, env(safe-area-inset-right)) 0 max(1rem, env(safe-area-inset-left));
    border-bottom: 1px solid var(--line, rgba(240, 238, 234, 0.08));
    background: var(--ink-0, #0f0f12);
}
.pv-title {
    margin: 0;
    min-width: 0;
    font-family: var(--font-body, sans-serif);
    font-weight: 600;
    font-size: 15px;
    letter-spacing: 0.01em;
    color: var(--text, #f0eeea);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;                            /* clicking the title closes the viewer; it looks the same otherwise */
    -webkit-tap-highlight-color: transparent;   /* no grey flash when tapped on iPhone */
}
.pv-actions { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }
.pv-newtab,
.pv-close {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    min-height: 26px;
    padding: 0 0.65rem;
    border: 1px solid var(--line-strong, rgba(240, 238, 234, 0.14));
    border-radius: 999px;
    background: transparent;
    color: var(--text-dim, #c4c0b8);
    font-family: var(--font-mono, monospace);
    font-size: 12px;
    letter-spacing: 0.02em;
    text-decoration: none;
    cursor: pointer;
    transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.pv-newtab:hover,
.pv-close:hover {
    color: var(--accent, #d4a056);
    border-color: var(--accent, #d4a056);
    background: var(--accent-glow, rgba(212, 160, 86, 0.14));
}
.pv-newtab:focus-visible,
.pv-close:focus-visible { outline: 2px solid var(--accent, #d4a056); outline-offset: 2px; }
.pv-newtab svg,
.pv-close svg { width: 14px; height: 14px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
/* Close turns a soft red on hover: a clear "this closes it" cue without shouting at rest.
   It does the same while the mouse is over the title, which closes the viewer too (.pv-hint-close). */
.pv-close:hover,
.pv-hint-close .pv-close {
    color: #ef6b62;
    border-color: #ef6b62;
    background: rgba(239, 107, 98, 0.14);
}
.pv-close:focus-visible { outline-color: #ef6b62; }
.pv-close kbd {
    font: inherit;
    font-size: 10px;
    padding: 1px 5px;
    border: 1px solid currentColor;
    border-radius: 4px;
    opacity: 0.55;
}

/* The project */
.pv-stage { position: relative; flex: 1; min-height: 0; background: #000; }
.pv-frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block; background: #000; }

/* Loading: the card's thumbnail, blurred, behind a progress bar */
.pv-load {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: grid;
    place-items: center;
    overflow: hidden;
    background: var(--ink-1, #16161a);
    transition: opacity 0.6s ease;
}
.pv-load[hidden] { display: none; }
.pv-load.done { opacity: 0; pointer-events: none; }
.pv-poster {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0.35;
    filter: blur(6px);
    transform: scale(1.05);
}
.pv-poster:not([src]) { display: none; }
.pv-load-box {
    position: relative;
    width: min(420px, calc(100% - 40px));
    padding: 24px 26px 20px;
    border: 1px solid var(--line, rgba(240, 238, 234, 0.08));
    border-radius: 12px;
    background: rgba(15, 15, 18, 0.78);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    color: var(--text, #f0eeea);
}
.pv-load-title {
    margin: 0 0 14px;
    font-family: var(--font-body, sans-serif);
    font-weight: 600;
    font-size: 20px;
    line-height: 1.2;
}
.pv-track { height: 3px; border-radius: 2px; background: rgba(240, 238, 234, 0.12); overflow: hidden; }
.pv-fill { height: 100%; width: 0; border-radius: 2px; background: var(--accent, #d4a056); transition: width 0.3s ease; }
.pv-load-text {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 16px;
    margin: 10px 0 0;
    font-family: var(--font-mono, monospace);
    font-size: 12px;
    letter-spacing: 0.02em;
    color: var(--text-mute, #8a8680);
}
.pv-pct { color: var(--text, #f0eeea); font-variant-numeric: tabular-nums; }
.pv-load.indet .pv-pct { display: none; }
.pv-load.indet .pv-track { position: relative; }
.pv-load.indet .pv-fill { width: 100% !important; opacity: 0.35; }
.pv-load.indet .pv-track::after {
    content: '';
    position: absolute;
    top: 0; bottom: 0;
    width: 40%;
    border-radius: 2px;
    background: var(--accent, #d4a056);
    animation: pv-slide 1.4s ease-in-out infinite;
}
@keyframes pv-slide { from { left: -40%; } to { left: 100%; } }
.pv-load.error .pv-track,
.pv-load.error .pv-pct { display: none; }
.pv-load.error .pv-label { color: var(--text, #f0eeea); }

@media (max-width: 600px) {
    .pv-newtab span { display: none; }               /* icon only on small screens */
    .pv-newtab { padding: 0 0.6rem; }
    .pv-close span,
    .pv-close kbd { display: none; }             /* X icon only on small screens */
    .pv-close { padding: 0 0.6rem; }
    .pv-title { font-size: 14px; }
}

/* Touch screens: thumb-sized buttons (40px) in a bar only just tall enough to hold them */
@media (pointer: coarse) {
    .pv-bar { min-height: 44px; }
    .pv-newtab,
    .pv-close { min-height: 40px; min-width: 40px; justify-content: center; }
    .pv-close kbd { display: none; }             /* no Esc key on a touch screen */
    .pv-newtab svg,
    .pv-close svg { width: 16px; height: 16px; }
}

/* Phone turned sideways: the screen is short, so the bar and buttons slim down a little more */
@media (pointer: coarse) and (max-height: 500px) {
    .pv-bar { min-height: 40px; }
    .pv-newtab,
    .pv-close { min-height: 36px; min-width: 36px; }
}

@media (prefers-reduced-motion: reduce) {
    .pv, .pv-load, .pv-fill, .pv-newtab, .pv-close { transition: none; }
    .pv-load.indet .pv-track::after { animation: none; left: 0; width: 100%; opacity: 0.6; }
}
