/* ============================================================
   Science Virtual LAB — 대형 QR 코드 모달 (교실 투사 / 학습지 인쇄용)
   ------------------------------------------------------------
   labs/common/qr-modal.js 와 함께 사용합니다.
   - 실험실 헤더의 [📱 QR code] 캡슐 버튼이 이 모달을 엽니다.
   - index.html 우측 상단 [QR code] 캡슐 버튼도 같은 모달을 씁니다.
   - QR 이미지는 labs/common/lib/qrcode.min.js(로컬 보관)로 생성하므로
     외부 CDN 없이 오프라인 교실에서도 동작합니다.
   ============================================================ */

/* ---------- 1. 여는 버튼 ----------
   각 페이지의 .back-btn / .glass-panel / .glass-pill 룩앤필을 그대로 물려받고,
   <button> 요소의 브라우저 기본 모양만 지웁니다. */
.qr-btn {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin: 0;
    font-family: inherit;
    font-weight: bold;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.qr-btn .qr-btn-icon {
    font-size: 14px;
    line-height: 1;
}

/* 다크 모드에서 아이콘/글자가 묻히지 않도록 */
body.dark-mode .qr-btn,
body.dark .qr-btn {
    color: #f2f2f7;
}

/* 모바일: 글자는 숨기고 아이콘만 (헤더 폭 확보) */
@media (max-width: 600px) {
    .qr-btn .qr-btn-label {
        display: none !important;
    }

    .qr-btn {
        padding-left: 10px !important;
        padding-right: 10px !important;
        min-width: 34px;
    }
}

/* ---------- 2. 오버레이 (반투명 블러) ---------- */
.svl-qr-overlay {
    position: fixed;
    inset: 0;
    z-index: 2600;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(12, 14, 18, 0.42);
    -webkit-backdrop-filter: blur(8px) saturate(130%);
    backdrop-filter: blur(8px) saturate(130%);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.26s ease, visibility 0.26s ease;
}

.svl-qr-overlay.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* ---------- 3. 중앙 화이트 카드 ---------- */
.svl-qr-card {
    position: relative;
    box-sizing: border-box;
    display: grid;
    grid-template-areas: "title" "name" "qr" "url" "hint" "btn";
    justify-items: center;
    align-content: center;
    width: -moz-fit-content;
    width: fit-content;
    max-width: min(560px, 100%);
    max-height: calc(100vh - 48px);
    max-height: calc(100dvh - 48px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 26px 28px 22px;
    border-radius: 28px;
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.06);
    box-shadow: 0 32px 80px rgba(0, 0, 0, 0.32), 0 1px 0 rgba(255, 255, 255, 0.7) inset;
    text-align: center;
    color: #1c1c1e;
    font-family: inherit;
    -webkit-user-select: none;
    user-select: none;
    transform: scale(0.94) translateY(10px);
    opacity: 0;
    transition: transform 0.28s cubic-bezier(0.2, 0.9, 0.3, 1), opacity 0.26s ease;
}

.svl-qr-overlay.is-open .svl-qr-card {
    transform: none;
    opacity: 1;
}

@media (max-width: 600px) {
    .svl-qr-overlay {
        padding: 14px;
    }

    .svl-qr-card {
        padding: 20px 18px 18px;
        border-radius: 24px;
        max-height: calc(100vh - 28px);
        max-height: calc(100dvh - 28px);
    }
}

/* ---------- 4. 헤더 ---------- */
.svl-qr-title {
    grid-area: title;
    margin: 0;
    font-size: 19px;
    font-weight: 800;
    letter-spacing: -0.3px;
    line-height: 1.35;
    color: #111111;
    word-break: keep-all;
}

@media (max-width: 600px) {
    .svl-qr-title {
        font-size: 16.5px;
    }
}

.svl-qr-name {
    grid-area: name;
    display: inline-block;
    max-width: 100%;
    margin: 9px 0 0;
    padding: 4px 13px;
    border-radius: 999px;
    background: #eef2f7;
    color: #2c3e50;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: -0.2px;
    line-height: 1.5;
    word-break: keep-all;
    overflow-wrap: break-word;
}

.svl-qr-name:empty {
    display: none;
}

/* ---------- 5. QR 이미지 ---------- */
.svl-qr-canvas {
    box-sizing: border-box;
    grid-area: qr;
    margin: 18px auto 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    border-radius: 18px;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.07);
    /* 모서리를 잘라내면 QR 모서리(파인더 패턴)가 깎여 인식이 어려워질 수 있어 자르지 않습니다 */
    overflow: visible;
}

.svl-qr-canvas img,
.svl-qr-canvas svg,
.svl-qr-canvas canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    max-height: none !important;
    position: static !important;
    image-rendering: -webkit-optimize-contrast;
}

.svl-qr-url {
    grid-area: url;
    margin: 12px 0 0;
    font-size: 11.5px;
    line-height: 1.5;
    color: #8e8e93;
    word-break: break-all;
    -webkit-user-select: text;
    user-select: text;
}

/* ---------- 6. 안내문 + 닫기 ---------- */
.svl-qr-hint {
    grid-area: hint;
    margin: 14px 0 0;
    font-size: 13px;
    line-height: 1.65;
    color: #6b6b70;
    word-break: keep-all;
    overflow-wrap: break-word;
}

.svl-qr-done {
    -webkit-appearance: none;
    appearance: none;
    grid-area: btn;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 124px;
    height: 44px;
    margin: 18px 0 0;
    padding: 0 24px;
    border: none;
    border-radius: 999px;
    background: #007aff;
    color: #ffffff;
    font-family: inherit;
    font-size: 15px;
    font-weight: bold;
    letter-spacing: -0.2px;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(0, 122, 255, 0.28);
    transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.svl-qr-done:hover {
    background: #0068d9;
    transform: translateY(-1px);
    box-shadow: 0 10px 24px rgba(0, 122, 255, 0.34);
}

.svl-qr-done:active {
    transform: scale(0.97);
}

.svl-qr-close {
    -webkit-appearance: none;
    appearance: none;
    position: absolute;
    top: 10px;
    right: 12px;
    width: 38px;
    height: 38px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #9a9aa0;
    font-family: inherit;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}

.svl-qr-close:hover {
    background: rgba(0, 0, 0, 0.06);
    color: #1c1c1e;
}

.svl-qr-close:focus-visible,
.svl-qr-done:focus-visible,
.qr-btn:focus-visible {
    outline: 2px solid #007aff;
    outline-offset: 2px;
}

/* ---------- 7. 가로 화면(짧은 높이) : QR 왼쪽 · 안내 오른쪽 2단 ---------- */
@media (max-height: 520px) and (orientation: landscape) {
    .svl-qr-card {
        grid-template-areas: "qr title" "qr name" "qr url" "qr hint" "qr btn";
        grid-template-columns: auto minmax(170px, 1fr);
        align-items: center;
        align-content: center;
        justify-items: start;
        column-gap: 22px;
        text-align: left;
        padding: 16px 22px;
        max-width: min(720px, 100%);
    }

    .svl-qr-canvas {
        margin: 0;
    }

    .svl-qr-title {
        font-size: 16px;
        padding-right: 30px;
    }

    .svl-qr-name {
        margin-top: 8px;
    }

    .svl-qr-url,
    .svl-qr-hint {
        margin-top: 8px;
    }

    .svl-qr-hint {
        font-size: 11.5px;
        line-height: 1.5;
    }

    .svl-qr-done {
        margin-top: 12px;
        height: 38px;
        min-width: 104px;
        font-size: 14px;
    }
}

/* ---------- 8. 인쇄 (학습지·배포용) ----------
   모달이 열린 상태에서 인쇄하면 QR 카드만 종이에 담깁니다. */
@media print {
    body.svl-qr-open {
        background: #ffffff !important;
    }

    body.svl-qr-open > *:not(.svl-qr-overlay) {
        display: none !important;
    }

    body.svl-qr-open .svl-qr-overlay {
        position: static !important;
        inset: auto !important;
        display: block !important;
        padding: 0 !important;
        background: #ffffff !important;
        -webkit-backdrop-filter: none !important;
        backdrop-filter: none !important;
        opacity: 1 !important;
        visibility: visible !important;
    }

    body.svl-qr-open .svl-qr-card {
        width: auto !important;
        max-width: none !important;
        max-height: none !important;
        margin: 0 auto !important;
        padding: 8mm !important;
        border: none !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        transform: none !important;
        opacity: 1 !important;
        overflow: visible !important;
        page-break-inside: avoid;
    }

    body.svl-qr-open .svl-qr-close,
    body.svl-qr-open .svl-qr-done {
        display: none !important;
    }

    body.svl-qr-open .svl-qr-canvas {
        box-shadow: none !important;
    }
}

/* ---------- 9. 메인 페이지(index.html) 상단 캡슐 버튼 ---------- */
.nav-tabs .qr-nav-btn {
    -webkit-appearance: none;
    appearance: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 15px;
    border: 1px solid #d9dee3;
    border-radius: 999px;
    background: #ffffff;
    color: #2c3e50;
    font-family: inherit;
    font-size: 14px;
    font-weight: 900;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(44, 62, 80, 0.06);
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.nav-tabs .qr-nav-btn:hover {
    background: #f6f9f8;
    border-color: #c8d2d8;
    color: #1a252f;
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(44, 62, 80, 0.1);
}

.nav-tabs .qr-nav-btn:active {
    transform: scale(0.97);
}

@media (max-width: 600px) {
    .nav-tabs .qr-nav-btn .qr-btn-label {
        display: none;
    }

    .nav-tabs .qr-nav-btn {
        padding: 7px 10px;
    }
}
