/* 
 * ============================================================================
 * ![NagiSwipe Library Core CSS] 
 * Drop-in gallery library
 * 
 * NagiSwipe v1.0.1
 * Copyright (c) 2026 Lichiphen
 * Licensed under the MIT License
 * https://gitlab.com/lichiphen/nagiswipe/-/blob/main/LICENSE
 * ============================================================================
 */

.ns-viewer {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
    overflow: hidden;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.ns-bg {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    opacity: 0;
    transition: opacity 0.25s linear;
    will-change: opacity;
}

.ns-stage {
    position: absolute;
    inset: 0;
    overflow: visible;
}

.ns-img-wrap {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    display: block;
    will-change: transform;
    pointer-events: none;
    backface-visibility: hidden;
    transform: translateZ(0);
}

.ns-img {
    position: absolute;
    top: 0;
    left: 0;
    max-width: none;
    max-height: none;
    transform-origin: 0 0; /* 左上を基準に変形 */
    object-fit: contain;
    will-change: transform;
    user-select: none;
    -webkit-user-select: none;
    pointer-events: auto;
    -webkit-user-drag: none;
    backface-visibility: hidden;
    transition: opacity 0.4s ease-out, filter 0.4s ease-out;
}

/* 高解像度（メイン）画像設定 */
.ns-img-highres {
    z-index: 2;
    opacity: 0;
    transition: opacity 0.4s ease-out;
}

/* ローディング完了後の表示 */
.ns-img-loaded .ns-img-highres {
    opacity: 1;
}

.ns-ui {
    position: absolute;
    inset: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    z-index: 10000;
}

/* Icons / Buttons */
.ns-btn {
    appearance: none;
    background: transparent;
    border: none;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.72);
    pointer-events: auto;
    transition: color 0.2s, opacity 0.2s, transform 0.12s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;

    padding: 0; /* size is defined per-button (close/prev/next) */
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    outline: none;
}

.ns-btn:hover {
    color: rgba(255, 255, 255, 1);
}

.ns-btn:focus {
    outline: none;
}

.ns-btn svg {
    display: block;
    width: 32px;
    height: 32px;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
    pointer-events: none;
}

.ns-close {
    top: 12px;
    right: 12px;
    width: 48px;
    height: 48px;
    color: #fff;
    z-index: 3; /* ensure above arrows */
}
.ns-close::before {
    content: "✕";
    font-size: 24px;
    line-height: 1;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.ns-zoom {
    top: 12px;
    right: 64px; /* Left of close button */
    width: 48px;
    height: 48px;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    opacity: 0.85;
}
.ns-zoom:active { opacity: 0.6; transform: scale(0.95); }

@media (hover: hover) and (pointer: fine) {
    .ns-viewer.ns-is-zoomed .ns-stage,
    .ns-viewer.ns-is-zoomed .ns-img { cursor: grab; }

    .ns-viewer.ns-dragging .ns-stage,
    .ns-viewer.ns-dragging .ns-img { cursor: grabbing; }
}

/* Arrow Positioning */
.ns-prev {
    top: 50%;
    left: calc(env(safe-area-inset-left, 0px) + 6px);
    transform: translateY(-50%);
    width: 56px;
    height: 56px;
    border-radius: 999px;
    background: rgba(0,0,0,0.1);
    backdrop-filter: blur(1px);
    opacity: 0.65;
    z-index: 2;
}

.ns-next {
    top: 50%;
    right: calc(env(safe-area-inset-right, 0px) + 6px);
    transform: translateY(-50%);
    width: 56px;
    height: 56px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(1px);
    opacity: 0.65;
    z-index: 2;
}

.ns-prev:active, .ns-next:active {
    transform: translateY(-50%) scale(0.96);
    opacity: 0.9;
}

/* Mobile Adjustments */
@media (hover: none) and (pointer: coarse) {
    .ns-btn {
        opacity: 1; 
    }
    .ns-prev, .ns-next {
        width: 52px;
        height: 52px;
    }
}


/* Visual centering tweaks for chevrons - Optical alignment */
.ns-prev svg { transform: translateX(-2px); }
.ns-next svg { transform: translateX(2px); }

/* ========================================
   ローディングスピナー
   高解像度画像読み込み中に表示
   ======================================== */
.ns-loading-spinner {
    position: fixed; /* 親のサイズが0になったのでfixedで画面基準にする */
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px; /* translateなどを使わずmarginでセンタリング */
    border: 3px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: ns-spin 0.8s infinite linear;
    z-index: 10;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.25s ease-out;
}

.ns-loading-spinner.ns-visible {
    opacity: 1;
}

@keyframes ns-spin {
    to { transform: rotate(360deg); }
}

/* ========================================
   ズームカーソル（PC環境向け）
   zoom-in: ズーム可能時、zoom-out: ズーム中
   ======================================== */
@media (hover: hover) and (pointer: fine) {
    .ns-viewer.ns-can-zoom:not(.ns-is-zoomed):not(.ns-dragging) .ns-img {
        cursor: zoom-in;
    }
    
    .ns-viewer.ns-is-zoomed:not(.ns-dragging) .ns-img {
        cursor: zoom-out;
    }
}
