/* 과학캔버스 기본 템플릿 변수 */
:root {
    --primary: #00d2ff;
    --secondary: #3a7bd5;
    --bg-dark: #050814;
    --text-light: #f0f4f8;
    --sub-text: #9ca3af;
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --sim-bg: #f0f2f5;
    --sim-card: #ffffff;
    --sim-text: #1e293b;
}

* {
    margin: 0; padding: 0; box-sizing: border-box;
    font-family: 'Pretendard', sans-serif; touch-action: manipulation;
}

body {
    background-color: var(--sim-bg); color: var(--sim-text);
    display: flex; flex-direction: column; min-height: 100vh;
}

header.site-nav {
    padding: 1.5rem 5%; display: flex; justify-content: space-between; align-items: center;
    position: fixed; width: 100%; top: 0; z-index: 1000;
    background: rgba(5, 8, 20, 0.95); backdrop-filter: blur(10px); border-bottom: 1px solid var(--glass-border);
}

.logo {
    font-size: 1.2rem; font-weight: 800;
    background: linear-gradient(to right, var(--primary), var(--secondary));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent; text-decoration: none;
}

.nav-tag {
    font-size: 0.85rem; font-weight: 700; color: var(--primary);
    border: 1px solid var(--primary); padding: 4px 12px; border-radius: 20px;
    letter-spacing: 0.5px; text-decoration: none; transition: all 0.3s ease;
}
.nav-tag:hover { background: var(--primary); color: var(--bg-dark); }

main { flex: 1; padding: 140px 20px 60px; display: flex; flex-direction: column; align-items: center; }

.sim-header { max-width: 1100px; width: 100%; text-align: center; margin-bottom: 30px; }
.sim-header h1 { font-size: 2.2rem; color: #0f172a; margin-bottom: 12px; font-weight: 800; }
.sim-header p { font-size: 1.05rem; color: #64748b; line-height: 1.7; margin-top: 0; word-break: keep-all; }

.sim-container {
    background: var(--sim-card); padding: 40px; border-radius: 24px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.08); display: flex; flex-direction: column;
    gap: 20px; max-width: 1100px; width: 100%; margin-bottom: 40px;
}

/* 3D 캔버스 래퍼 */
#canvas-wrapper {
    position: relative; width: 100%; height: 650px; background-color: #050505;
    border-radius: 16px; overflow: hidden; box-shadow: inset 0 0 30px rgba(0,0,0,0.6);
}

/* [핵심] 최신 모바일 브라우저 주소창 동적 높이 대응 (100dvh) */
#canvas-wrapper.fullscreen {
    position: fixed; top: 0; left: 0; width: 100vw; 
    height: 100vh; height: 100dvh; 
    max-width: none; border-radius: 0; z-index: 9999; margin: 0; padding: 0;
}

/* 컨트롤 레이아웃 */
#top-left-controls { position: absolute; top: 20px; left: 20px; z-index: 30; }
#top-right-controls { position: absolute; top: 20px; right: 20px; z-index: 30; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }

.icon-horizontal { display: flex; gap: 8px; }
.icon-vertical { display: flex; flex-direction: column; gap: 8px; }

.icon-btn {
    background: rgba(15, 23, 42, 0.8); color: white; border: 1px solid #444;
    border-radius: 8px; width: 42px; height: 42px; cursor: pointer; 
    display: flex; justify-content: center; align-items: center; font-size: 1.1rem;
    transition: all 0.3s ease;
    z-index: 50;
}
.icon-btn:hover { background: #333; }
.active-play { background: var(--primary); color: #000; border-color: var(--primary); }
.active-tool { background: var(--secondary); color: #fff; border-color: var(--secondary); }

#time-badge { 
    background: rgba(0,0,0,0.6); padding: 8px 12px; border-radius: 8px; color: var(--primary); 
    text-align: center; border: 1px solid rgba(255,255,255,0.2); font-weight: 700; font-size: 0.95rem; 
}

/* 팝업 공통 스타일 */
.popup-slider-container {
    position: absolute; right: 70px; z-index: 40;
    background: rgba(15, 23, 42, 0.95); padding: 15px 20px; border-radius: 12px;
    border: 1px solid #444; display: flex; flex-direction: column; gap: 10px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.7); backdrop-filter: blur(8px);
    min-width: 260px; visibility: hidden; opacity: 0; transform: translateX(10px);
    transition: all 0.3s ease;
}
.popup-slider-container.active { visibility: visible; opacity: 1; transform: translateX(0); }

#planet-popup { top: 120px; }

.popup-title {
    display: flex; justify-content: space-between; align-items: center; 
    font-weight: 600; color: var(--primary); font-size: 0.95rem; margin-bottom: 8px;
    width: 100%;
}

select.ui-select { 
    width: 100%; padding: 8px; border-radius: 6px; background: #222; color: #fff; 
    border: 1px solid #555; outline: none; cursor: pointer; font-size: 0.9rem;
}

/* 체크박스 그룹 스타일 */
.checkbox-group { display: flex; flex-direction: column; gap: 12px; }
.checkbox-group label {
    display: flex; align-items: center; gap: 10px;
    color: #f0f4f8; font-size: 0.9rem; cursor: pointer; font-weight: 500;
}
.checkbox-group input[type="checkbox"] { accent-color: var(--primary); width: 16px; height: 16px; cursor: pointer; }

/* 좌측 하단 기능 아이콘 및 패널 */
#minimapOpenBtn { position: absolute; bottom: 20px; left: 20px; z-index: 30; }
#phaseOpenBtn { position: absolute; bottom: 70px; left: 20px; z-index: 30; }

.left-panel {
    position: absolute; left: 20px; z-index: 40;
    background: rgba(5, 8, 20, 0.85); padding: 12px 16px 16px; border-radius: 12px;
    border: 1px solid var(--glass-border); backdrop-filter: blur(5px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    display: flex; flex-direction: column; align-items: center;
    visibility: hidden; opacity: 0; transform: translateY(10px);
    transition: opacity 0.3s ease, visibility 0.3s;
}
.left-panel.active { visibility: visible; opacity: 1; transform: translateY(0); }

#apparent-panel { bottom: 20px; }
#phase-panel { bottom: 70px; }

/* 2D 캔버스 겹치기 및 스케일링 */
.canvas-stack { 
    position: relative; width: 100%; max-width: 340px; aspect-ratio: 340/180; margin-top: 5px; 
}
.canvas-stack canvas { 
    position: absolute; top: 0; left: 0; width: 100%; height: 100%; 
    border-radius: 8px; border: 1px solid #333; 
}
#apparentBgCanvas { background-color: #0a0a0a; z-index: 1; }
#apparentCanvas { background-color: transparent; z-index: 2; border: none; }

.panel-canvas { 
    width: 100%; max-width: 120px; height: auto; aspect-ratio: 1; 
    background-color: #0a0a0a; border-radius: 8px; border: 1px solid #333; margin-top: 5px; 
}

/* 하단 설명 섹션 */
.table-section { 
    background: var(--sim-card); padding: 40px; border-radius: 24px; 
    box-shadow: 0 20px 40px rgba(0,0,0,0.05); max-width: 1100px; width: 100%; 
    box-sizing: border-box; overflow-x: auto;
}
.table-section h2 { margin-top: 0; color: #0f172a; border-left: 6px solid var(--primary); padding-left: 15px; font-size: 1.5rem; margin-bottom: 25px; }
.ref-grid { 
    display: grid; 
    /* PC 화면에서 무조건 2칸씩 꽉 차게 배치 */
    grid-template-columns: repeat(2, 1fr); 
    gap: 24px; 
}
.ref-card { background: #fff; padding: 24px; border-radius: 16px; box-shadow: 0 4px 12px rgba(0,0,0,0.04); border: 1px solid #f1f5f9; }
.ref-card h3 { color: var(--secondary); margin-bottom: 12px; font-size: 1.1rem; }
.ref-card p { color: #475569; line-height: 1.65; font-size: 0.95rem; margin-bottom: 12px; word-break: keep-all; }

.site-footer {
    padding: 60px 5%; border-top: 1px solid var(--glass-border);
    text-align: center; background: #050814; color: var(--sub-text);
}
.contact-info { color: #fff; margin-bottom: 20px; font-size: 0.95rem; }
.contact-info a { color: var(--sub-text); text-decoration: none; margin-left: 10px; transition: color 0.3s; }
.contact-info a:hover { color: var(--primary); }
.footer-links { display: flex; justify-content: center; align-items: center; gap: 15px; flex-wrap: wrap; }
.footer-links a { color: var(--sub-text); text-decoration: none; font-size: 0.85rem; transition: color 0.3s; }
.footer-links a:hover { color: var(--primary); }

/* =========================================
   [모바일 환경 반응형 완벽 대응]
   ========================================= */
@media (max-width: 800px) {
    main { padding-top: 100px; }
    .sim-container { padding: 20px; }
    
    #canvas-wrapper { height: 550px; }
    
    #minimapOpenBtn { bottom: 40px; left: 15px; }
    #phaseOpenBtn { bottom: 95px; left: 15px; }
    #top-left-controls { top: 15px; left: 15px; }
    #top-right-controls { top: 15px; right: 15px; }
    
    .left-panel { left: 10px; bottom: 40px; padding: 12px; }
    #apparent-panel { width: calc(100% - 20px); max-width: 360px; }
    #phase-panel { width: auto; min-width: 160px; }
    .popup-slider-container { right: 15px; max-width: calc(100% - 80px); }
    .canvas-stack { width: 100%; max-width: 340px; aspect-ratio: 340/180; height: auto; }
    .canvas-stack canvas { width: 100%; height: 100%; }
    .panel-canvas { width: 100%; max-width: 120px; height: auto; aspect-ratio: 1; }
    
    /* 모바일에서는 세로 1줄로 배치 */
    .ref-grid { grid-template-columns: 1fr; }
}

/* =========================================
   [레일리 기준 시뮬레이션 전용 추가 스타일]
   ========================================= */
#canvas-wrapper.split-view {
    display: flex;
    flex-direction: column;
    padding: 0;
    /* 기존 높이 650px 유지 */
}

.view-panel {
    width: 100%;
    position: relative;
    cursor: crosshair; /* 마우스 줌 가능함을 암시 */
}

.pattern-panel {
    flex: 1.2;
    background-color: #000;
}

.graph-panel {
    flex: 1;
    background-color: #0a0a0a;
    border-top: 1px solid #333;
}

.view-panel canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* 설정 팝업 위치 조정 */
#settings-popup {
    top: 70px;
}