/* ============================================================
   Science Virtual LAB — 공통 UI 표준 레이아웃 (ui-layout.css)
   ------------------------------------------------------------
   전체 가상실험실 인터페이스 규격 통일 및 오버랩 완전 방지
   1) 하단 중앙: [🔄 초기화][🎥 시점정렬] 글래스 캡슐 바 고정
   2) 우측 상단: [💡 제안하기][🌙 야간 모드] 유틸 + 실시간 데이터 카드
   3) 우측 하단: [🎛 실험 조절] 패널 (호흡운동 스타일 정사각 타일 버튼)
   4) 설정창(.sub-panel): 조절 패널 좌측에 분리 도킹하여 절대 겹치지 않음
   5) 우측 하단 구석: [⛶ 전체화면] 독립 배치
   ============================================================ */

/* ---------------- 1. 하단 중앙 글래스 캡슐 바 (.bottom-control-bar, #bar) ---------------- */
.bottom-control-bar,
body #bar {
    position: fixed !important;
    bottom: 22px !important;
    left: 50% !important;
    right: auto !important;
    top: auto !important;
    transform: translateX(-50%) !important;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
    padding: 6px 14px !important;
    border-radius: 999px !important;
    background: rgba(255, 255, 255, 0.85) !important;
    backdrop-filter: blur(20px) !important;
    -webkit-backdrop-filter: blur(20px) !important;
    border: 1px solid rgba(255, 255, 255, 0.45) !important;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12) !important;
    z-index: 80 !important;
    width: auto !important;
    max-width: calc(100vw - 32px) !important;
    box-sizing: border-box !important;
}

body.dark-mode .bottom-control-bar,
body.dark #bar {
    background: rgba(30, 30, 32, 0.85) !important;
    border-color: rgba(255, 255, 255, 0.15) !important;
}

.bottom-control-bar button,
.bottom-control-bar .control-tab-btn,
.bottom-control-bar .cbtn,
body #bar button,
body #bar .cbtn {
    display: inline-flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 6px !important;
    padding: 8px 16px !important;
    border-radius: 999px !important;
    border: 1px solid rgba(0, 0, 0, 0.08) !important;
    background: rgba(255, 255, 255, 0.92) !important;
    color: #1c1c1e !important;
    font-family: inherit !important;
    font-size: 12.5px !important;
    font-weight: 700 !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
    white-space: nowrap !important;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05) !important;
    line-height: 1 !important;
}

body.dark-mode .bottom-control-bar button,
body.dark-mode .bottom-control-bar .control-tab-btn,
body.dark #bar button,
body.dark #bar .cbtn {
    background: rgba(50, 50, 54, 0.92) !important;
    border-color: rgba(255, 255, 255, 0.12) !important;
    color: #f2f2f7 !important;
}

.bottom-control-bar button:hover,
.bottom-control-bar .control-tab-btn:hover,
.bottom-control-bar .cbtn:hover,
body #bar button:hover,
body #bar .cbtn:hover {
    background: #ffffff !important;
    transform: translateY(-1px) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1) !important;
}

/* ---------------- 2. 우측 상단 유틸 행 및 데이터 카드 ---------------- */
.top-right-bar {
    position: fixed !important;
    top: 15px !important;
    right: 20px !important;
    left: auto !important;
    bottom: auto !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: flex-end !important;
    gap: 8px !important;
    z-index: 50 !important;
    pointer-events: none !important;
    max-width: calc(100vw - 24px) !important;
    max-height: calc(45vh) !important;
}

/* 1행: [💡 제안하기] [🌙 야간 모드] */
.top-right-bar > .tr-util {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 8px !important;
    order: -10 !important;
    flex: 0 0 auto !important;
    max-width: 100% !important;
}

.top-right-bar > *,
.top-right-bar > .tr-util > * {
    pointer-events: auto !important;
}

/* ---------------- 3. 우측 하단 실험 조절 패널 (.side-ctrl-panel) ---------------- */
.side-ctrl-panel {
    position: fixed !important;
    right: 20px !important;
    bottom: 76px !important;
    top: auto !important;
    left: auto !important;
    width: 220px !important;
    max-height: calc(100vh - 180px) !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    overscroll-behavior: contain !important;
    -webkit-overflow-scrolling: touch !important;
    padding: 12px !important;
    border-radius: 18px !important;
    background: rgba(255, 255, 255, 0.84) !important;
    backdrop-filter: blur(20px) !important;
    -webkit-backdrop-filter: blur(20px) !important;
    border: 1px solid rgba(255, 255, 255, 0.4) !important;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.1) !important;
    z-index: 60 !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 8px !important;
    box-sizing: border-box !important;
}

body.dark-mode .side-ctrl-panel,
body.dark .side-ctrl-panel {
    background: rgba(30, 30, 32, 0.84) !important;
    border-color: rgba(255, 255, 255, 0.15) !important;
}

.side-ctrl-panel::-webkit-scrollbar { width: 4px; }
.side-ctrl-panel::-webkit-scrollbar-thumb {
    background: rgba(120, 120, 128, .35);
    border-radius: 2px;
}

.side-ctrl-panel .panel-title {
    font-size: 12px !important;
    font-weight: 800 !important;
    color: #475569 !important;
    letter-spacing: -0.2px !important;
    margin-bottom: 2px !important;
    padding-bottom: 4px !important;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06) !important;
    text-align: center !important;
}

body.dark-mode .side-ctrl-panel .panel-title,
body.dark .side-ctrl-panel .panel-title {
    color: #94a3b8 !important;
    border-bottom-color: rgba(255, 255, 255, 0.1) !important;
}

/* 호흡 운동의 원리 스타일: 2열 네모난 타일 그리드 */
.side-ctrl-panel .ctrl-grid {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
    width: 100% !important;
}

/* 네모난 타일 형태 버튼 규격: 아이콘 상단, 글씨 하단, 글자 잘림 완전 방지 */
.side-ctrl-panel .control-tab-btn,
.side-ctrl-panel .side-btn {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 4px !important;
    width: 100% !important;
    min-height: 56px !important;
    padding: 7px 4px !important;
    border-radius: 14px !important;
    border: 1px solid rgba(0, 0, 0, 0.08) !important;
    background: rgba(255, 255, 255, 0.88) !important;
    color: #1c1c1e !important;
    font-family: inherit !important;
    font-size: 11px !important;
    font-weight: 700 !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
    text-align: center !important;
    line-height: 1.25 !important;
    word-break: keep-all !important;
    white-space: normal !important;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04) !important;
    box-sizing: border-box !important;
}

body.dark-mode .side-ctrl-panel .control-tab-btn,
body.dark-mode .side-ctrl-panel .side-btn,
body.dark .side-ctrl-panel .control-tab-btn {
    background: rgba(50, 50, 54, 0.88) !important;
    border-color: rgba(255, 255, 255, 0.12) !important;
    color: #f2f2f7 !important;
}

.side-ctrl-panel .control-tab-btn span:first-child,
.side-ctrl-panel .side-btn span:first-child {
    font-size: 18px !important;
    line-height: 1 !important;
}

.side-ctrl-panel .control-tab-btn:hover,
.side-ctrl-panel .side-btn:hover {
    background: #ffffff !important;
    transform: translateY(-1px) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08) !important;
}

.side-ctrl-panel .control-tab-btn.active,
.side-ctrl-panel .side-btn.active {
    background: #007aff !important;
    color: #ffffff !important;
    border-color: #007aff !important;
    box-shadow: 0 4px 14px rgba(0, 122, 255, 0.3) !important;
}

/* 아이콘/라벨 분리 마크업 표준: 아이콘은 크게, 한글 라벨은 표준 스케일(11px)로 통일 */
.side-ctrl-panel .control-tab-btn .btn-icon,
.side-ctrl-panel .side-btn .btn-icon {
    display: block !important;
    font-size: 18px !important;
    line-height: 1 !important;
}

.side-ctrl-panel .control-tab-btn .btn-text,
.side-ctrl-panel .side-btn .btn-text {
    display: block !important;
    font-size: 11px !important;
    font-weight: 700 !important;
    line-height: 1.2 !important;
    letter-spacing: -0.2px !important;
    white-space: nowrap !important;
}

/* 홀수 개수 버튼 처리: 마지막 버튼이 가로 전체 차지 */
.side-ctrl-panel .ctrl-grid > button:last-child:nth-child(odd) {
    grid-column: 1 / -1 !important;
}

/* ---------------- 4. 서브 설정창(.sub-panel) 분리 도킹 ---------------- */
@media (min-width: 769px) {
    body .sub-panel {
        position: fixed !important;
        right: 252px !important;
        bottom: 76px !important;
        left: auto !important;
        top: auto !important;
        transform: none !important;
        width: auto !important;
        min-width: 280px !important;
        max-width: 380px !important;
        max-height: calc(100vh - 180px) !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        overscroll-behavior: contain !important;
        -webkit-overflow-scrolling: touch !important;
        z-index: 55 !important;
        border-radius: 18px !important;
        box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12) !important;
    }
    body.svl-no-side .sub-panel {
        right: 20px !important;
    }
}

/* ---------------- 4-1. 중앙 상단 안내 툴팁 표준 위치 ---------------- */
/* 상단 헤더(로고·데이터 카드)와 절대 겹치지 않도록 전 실험실이 같은 높이를 쓴다. */
@media (min-width: 769px) and (min-height: 501px) {
    .center-tooltip,
    #guide-tooltip {
        top: 80px !important;
    }
}

/* 좁은 데스크톱(노트북·교실 프로젝터): 우측 데이터 카드·조절 패널이 중앙까지 넓어지므로
   툴팁을 카드 아래로 내리고 폭도 줄여 수평 겹침을 막는다. */
@media (min-width: 769px) and (max-width: 1339px) and (min-height: 501px) {
    .center-tooltip,
    #guide-tooltip {
        top: 148px !important;
    }
}

@media (min-width: 901px) and (max-width: 1339px) and (min-height: 501px) {
    .center-tooltip,
    #guide-tooltip {
        max-width: min(560px, calc(100vw - 690px)) !important;
    }
}

/* 넓은 화면(≥1340px): 번역문(en·ja·zh·es)이 길어지면 우측 데이터 카드와 수평으로
   겹치므로 카드 왼쪽에서 끊기도록 폭을 제한한다. 한국어 원문은 지금 배치 그대로 둔다. */
@media (min-width: 1340px) and (min-height: 501px) {
    html:not([lang="ko"]):has(.top-right-bar .data-card) .center-tooltip,
    html:not([lang="ko"]):has(.top-right-bar .data-card) #guide-tooltip {
        max-width: min(560px, calc(100vw - 1000px)) !important;
    }
}

/* 모바일 세로 화면: 상단 데이터 카드가 1~2줄로 늘어나므로 카드 아래로 내려 겹침을 막는다. */
@media (max-width: 768px) and (min-height: 501px) {
    .center-tooltip,
    #guide-tooltip {
        top: calc(max(8px, env(safe-area-inset-top)) + 144px) !important;
    }
}

/* ---------------- 5. 우측 하단 전체화면 버튼 고정 ---------------- */
.bottom-right-bar,
#fullscreenBtn {
    position: fixed !important;
    bottom: 22px !important;
    right: 20px !important;
    top: auto !important;
    left: auto !important;
    z-index: 90 !important;
}

/* ---------------- 6. 모바일 / 태블릿 반응형 ---------------- */
@media (max-width: 768px) {
    .bottom-control-bar,
    body #bar {
        bottom: calc(10px + env(safe-area-inset-bottom)) !important;
        padding: 4px 10px !important;
        gap: 6px !important;
        z-index: 80 !important;
    }
    .bottom-control-bar button,
    .bottom-control-bar .control-tab-btn,
    .bottom-control-bar .cbtn,
    body #bar button,
    body #bar .cbtn {
        padding: 6px 12px !important;
        font-size: 11px !important;
    }

    .bottom-right-bar,
    #fullscreenBtn {
        bottom: calc(10px + env(safe-area-inset-bottom)) !important;
        right: 10px !important;
    }

    body .side-ctrl-panel {
        left: auto !important;
        right: max(8px, env(safe-area-inset-right)) !important;
        bottom: calc(64px + env(safe-area-inset-bottom)) !important;
        width: min(220px, calc(100vw - 16px)) !important;
        padding: 8px !important;
        gap: 6px !important;
        max-height: 42vh !important;
        z-index: 60 !important;
    }
    body .side-ctrl-panel .ctrl-grid {
        grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)) !important;
        gap: 6px !important;
    }
    body .side-ctrl-panel .control-tab-btn,
    body .side-ctrl-panel .side-btn {
        min-height: 48px !important;
        padding: 5px 3px !important;
        font-size: 10px !important;
    }
    body .side-ctrl-panel .control-tab-btn .btn-icon,
    body .side-ctrl-panel .side-btn .btn-icon {
        font-size: 15px !important;
    }
    body .side-ctrl-panel .control-tab-btn .btn-text,
    body .side-ctrl-panel .side-btn .btn-text {
        font-size: 10px !important;
    }

    body .sub-panel {
        left: 8px !important;
        right: 8px !important;
        bottom: calc(72px + env(safe-area-inset-bottom) + var(--svl-sideh, 60px)) !important;
        width: auto !important;
        max-width: none !important;
        max-height: min(44vh, calc(100vh - var(--svl-sideh, 60px) - 140px)) !important;
        z-index: 100 !important;
    }
}

/* ============================================================
   [표준] 좌상단 메인(뒤로가기) 버튼 — 화살표와 '메인' 글자 사이 간격 통일
   ------------------------------------------------------------
   flex 컨테이너 안에서는 화살표 <span>과 '메인' 사이의 공백 텍스트가
   렌더링되지 않아 gap 값만 남는다. 페이지마다 gap이 4px·6px·없음으로
   갈려 어떤 실험실은 화살표와 글자가 붙어 보였다.
   -> 모든 실험실의 뒤로가기 링크(a.back-btn)에 같은 간격(6px)을 강제하고,
      화살표 span에 2px를 더해 띄어쓰기 한 칸 분량을 안정적으로 확보한다.
   ============================================================ */
html body a.back-btn,
html body .top-left-bar a.back-btn,
html body #top-left-wrap a.back-btn {
    display: inline-flex !important;
    align-items: center !important;
    gap: 6px !important;
    white-space: nowrap !important;
}
html body a.back-btn > span:first-child,
html body .top-left-bar a.back-btn > span:first-child,
html body #top-left-wrap a.back-btn > span:first-child {
    display: inline-block;
    margin-right: 2px;
}
