/* [1. 외부 폰트 및 초기화] */
@import url('https://cdn.jsdelivr.net/gh/orioncactus/pretendard/dist/web/static/pretendard.css');
@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+KR:wght@400;700&display=swap');

* { 
    margin: 0; 
    padding: 0; 
    box-sizing: border-box; 
}

/* [2. 테마 변수 정의 - 다크/라이트 모드 색상 관리] */
:root {
    --main-bg: #0d1117;
    --card-bg: #161b22;
    --text-main: #f0f6fc;
    --text-dim: #8b949e;
    --border: #30363d;
    --accent: #58a6ff;
    --btn-bg: #21262d;
}

body.light-mode {
    --main-bg: #ffffff;
    --card-bg: #f6f8fa;
    --text-main: #24292f;
    --text-dim: #57606a;
    --border: #d0d7de;
    --accent: #0969da;
    --btn-bg: #f3f4f6;
}

/* [3. 문서 기본 레이아웃] */
body {
    font-family: 'Pretendard', sans-serif;
    background-color: var(--main-bg);
    color: var(--text-dim);
    display: flex;
    justify-content: center;
    margin: 0;
    padding: 60px 10px 20px 10px;
    padding-bottom: calc(30px + env(safe-area-inset-bottom));
    line-height: 1.75;
    transition: all 0.3s ease;
}

/* [4. 테마 토글 버튼 및 아이콘 스타일] */
.theme-toggle {
    position: fixed; top: 15px; right: 15px; width: 34px; height: 34px;
    border-radius: 50%; background-color: var(--btn-bg); border: 1px solid var(--border);
    cursor: pointer; display: flex; align-items: center; justify-content: center; z-index: 1000;
    transition: all 0.2s;
}

/* 토글 툴팁 */
.theme-toggle::after {
    content: attr(data-tooltip); position: absolute; top: 42px; right: 0;
    background: rgba(0, 0, 0, 0.85); color: #fff; padding: 4px 8px; border-radius: 4px;
    font-size: 11px; white-space: nowrap; opacity: 0; visibility: hidden;
    transition: opacity 0.2s ease, transform 0.2s ease; transform: translateY(-5px); pointer-events: none;
}

/* 아이콘 공통 및 개별 설정 */
.mode-icon { display: none; flex-shrink: 0; }
.icon-system { width: 18px; height: 18px; stroke: var(--text-main); stroke-width: 2.5; stroke-linecap: round; fill: none; }
.half-circle { width: 16px; height: 16px; border-radius: 50%; border: 1.5px solid var(--text-main); background: linear-gradient(90deg, var(--text-main) 50%, transparent 50%); transition: transform 0.3s ease; }

/* 테마 상태에 따른 아이콘 노출 제어 */
body[data-theme="system"] .icon-system { display: block; }
body[data-theme="dark"] .half-circle { display: block; transform: rotate(0deg); }
body[data-theme="light"] .half-circle { display: block; transform: rotate(180deg); }

/* [5. 메인 컨테이너 및 타이포그래피] */
.tutorial-container {
    background-color: var(--card-bg);
    max-width: 1200px; 
    width: 100%;
    padding: 50px 40px;
    box-shadow: 0 0 0 1px var(--border);
    border-radius: 12px;
    border-top: 5px solid var(--accent);
    box-sizing: border-box;
}

h1 { 
    font-size: 2.2rem; 
    margin-bottom: 10px; 
    color: var(--text-main); 
    text-align: center; 
    word-break: keep-all; 
    letter-spacing: -0.03em; 
    font-weight: 600; 
}

h2 { 
    font-size: 1.5rem; 
    color: var(--text-main); 
    margin-top: 50px; 
    margin-bottom: 20px; 
    font-weight: 700; 
    display: flex; 
    align-items: center; 
    gap: 12px; 
    border-bottom: 1px solid var(--border); 
    padding-bottom: 10px; 
}

h3 {
    font-size: 1.2rem;
    color: var(--text-main);
    margin-top: 30px;
    margin-bottom: 15px;
}

.subtitle, .sub-title { 
    text-align: center; 
    color: var(--text-dim); 
    font-size: 1.05rem; 
    margin-bottom: 40px; 
    font-weight: 400; 
    border-bottom: 1px solid var(--border); 
    padding-bottom: 20px; 
    word-break: keep-all; 
}

.section-header { 
    font-size: 0.75rem; 
    font-weight: 600; 
    color: var(--text-dim); 
    margin-top: 25px; 
    margin-bottom: 8px; 
    text-transform: uppercase; 
    border-bottom: 1px solid var(--border); 
    padding-bottom: 4px; 
    letter-spacing: 0.5px; 
}

.section-header:first-of-type { margin-top: 5px; }

p { 
    font-size: 1.05rem; 
    margin-bottom: 1.5em; 
    word-break: keep-all; 
    color: var(--text-main); 
}

strong { 
    color: var(--accent); 
    font-weight: 700; 
}

/* [6. 챕터 리스트 및 카드 컴포넌트] */
.chapter-list { display: flex; flex-direction: column; gap: 8px; }

.chapter-card {
    display: flex; align-items: center; padding: 10px 14px;
    background-color: var(--main-bg); border: 1px solid var(--border);
    border-radius: 6px; cursor: pointer; transition: all 0.2s ease;
    text-decoration: none; color: inherit; position: relative; overflow: hidden;
}

.chapter-card:hover { border-color: var(--text-dim); transform: translateX(2px); }

/* 카드 내부 요소 스타일 */
.bar { position: absolute; left: 0; top: 0; bottom: 0; width: 3px; }
.chapter-info { flex: 1; margin-left: 10px; display: flex; flex-direction: column; justify-content: center; }
.title-row { display: flex; align-items: center; gap: 8px; }

.step-badge { 
    font-size: 0.65rem; 
    font-weight: 600; 
    text-transform: uppercase; 
    display: inline-block; 
    padding: 3px 10px; 
    border-radius: 20px; 
    white-space: nowrap; 
    background-color: rgba(88, 166, 255, 0.15);
    color: var(--accent);
    border: 1px solid rgba(88, 166, 255, 0.4);
}

.chapter-title { font-size: 0.95rem; font-weight: 600; color: var(--text-main); margin: 0; line-height: 1.3; }
.chapter-desc { font-size: 0.75rem; color: var(--text-dim); margin-top: 3px; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.arrow-icon { color: var(--border); font-size: 0.85rem; margin-left: 8px; transition: all 0.2s ease; }
.chapter-card:hover .arrow-icon { color: var(--text-dim); transform: translateX(3px); }
.locked { opacity: 0.5; cursor: default; }

/* [7. 상태별 바(Bar) 색상 정의] */
.s-01 .bar, .s-02 .bar, .s-03 .bar, .s-04 .bar, .s-05 .bar, .s-06 .bar, .s-07 .bar, 
.s-08 .bar, .s-09 .bar, .s-10 .bar, .s-11 .bar, .s-12 .bar, .s-13 .bar, .s-14 .bar, .s-15 .bar,
.s-16 .bar, .s-17 .bar, .s-18 .bar, .s-19 .bar, .s-20 .bar, .s-21 .bar, .s-22 .bar { background-color: #58a6ff; }
.s-gray .bar { background-color: #6e7681; }

/* [8. 콘텐츠 박스 컴포넌트] */
.info-box, .concept-box { 
    background: rgba(88, 166, 255, 0.1);
    border-left: 4px solid var(--accent);
    padding: 20px;
    margin: 30px 0;
    border-radius: 0 8px 8px 0;
}

.concept-box {
    background-color: var(--main-bg); 
    padding: 25px; 
    border-radius: 8px; 
    border: 1px solid var(--border); 
}

.concept-box h3 { 
    margin-top: 0; 
    color: var(--accent); 
    font-size: 1.2rem; 
    margin-bottom: 15px; 
}

.warning-box {
    background: rgba(255, 107, 107, 0.1);
    border-left: 4px solid #ff6b6b;
    padding: 20px;
    margin: 30px 0;
    border-radius: 0 8px 8px 0;
}

.highlight-box {
    background: rgba(88, 166, 255, 0.1);
    border-left: 4px solid var(--accent);
    padding: 20px;
    margin: 30px 0;
    border-radius: 0 8px 8px 0;
}

.formula-box {
    background: var(--main-bg);
    border: 2px solid var(--accent);
    padding: 30px;
    margin: 30px 0;
    border-radius: 12px;
    text-align: center;
}

.formula-box .formula-title {
    color: var(--accent);
    font-weight: bold;
    font-size: 1.1rem;
    margin-bottom: 20px;
}

.tech-spec { 
    background-color: var(--main-bg); 
    padding: 25px; 
    border-radius: 8px; 
    border: 1px solid var(--border); 
    margin-bottom: 30px; 
}

.tech-spec h3 { 
    margin-top: 0; 
    color: var(--accent); 
    font-size: 1.1rem; 
    border-bottom: 1px dashed var(--border); 
    padding-bottom: 10px; 
}

.guide-text { 
    background-color: rgba(88, 166, 255, 0.1); 
    padding: 20px; 
    border-radius: 8px; 
    margin-top: 40px; 
    border: 1px solid rgba(88, 166, 255, 0.2); 
}

/* [9. 피처 및 통계 그리드] */
.feature-list { 
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); 
    gap: 15px; 
    margin: 30px 0; 
}

.feature-item { 
    background: var(--card-bg); 
    padding: 20px; 
    border-radius: 8px; 
    border: 1px solid var(--border); 
    transition: transform 0.2s, box-shadow 0.2s;
}

.feature-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(88, 166, 255, 0.2);
}

.feature-item strong { color: var(--accent); }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin: 30px 0;
}

.stat-card {
    background: var(--main-bg);
    padding: 20px;
    border-radius: 8px;
    border: 2px solid var(--border);
    text-align: center;
}

.stat-number {
    font-size: 2.5rem;
    font-weight: bold;
    color: var(--accent);
    margin: 10px 0;
}

.stat-label {
    font-size: 0.9rem;
    color: var(--text-dim);
}

/* [10. 테이블 스타일] */
.table-wrapper { 
    width: 100%; 
    overflow-x: auto; 
    margin: 30px 0; 
    border-radius: 6px; 
    border: 1px solid var(--border); 
}

.summary-table, .truth-table, .comparison-table, .opt-table { 
    width: 100%; 
    border-collapse: collapse; 
    font-size: 0.95rem; 
    min-width: 600px; 
}

.summary-table th, .truth-table th, .comparison-table th, .opt-table th { 
    background-color: var(--main-bg); 
    color: var(--text-main); 
    padding: 15px; 
    text-align: left; 
    font-weight: 600; 
    border-bottom: 2px solid var(--border);
    border: 1px solid var(--border);
}

.summary-table td, .truth-table td, .comparison-table td, .opt-table td { 
    padding: 15px; 
    border-bottom: 1px solid var(--border); 
    background-color: var(--card-bg); 
    color: var(--text-dim); 
    vertical-align: top;
    border: 1px solid var(--border);
}

.truth-table td {
    text-align: center;
}

.opt-table {
    font-size: 0.9rem;
    min-width: 500px;
}

.opt-table th {
    text-align: left;
}

.highlight-cell, .truth-table .highlight { 
    background-color: rgba(88, 166, 255, 0.2) !important; 
    color: var(--accent) !important; 
    font-weight: bold; 
}

.comparison-table .highlight-cell {
    background-color: rgba(88, 166, 255, 0.15) !important;
}

/* [11. 피규어 및 다이어그램] */
.figure-container { 
    display: flex; 
    justify-content: space-between; 
    gap: 20px; 
    margin: 40px 0; 
    background-color: var(--main-bg); 
    padding: 20px; 
    border-radius: 8px; 
    border: 1px solid var(--border); 
}

.figure-item { 
    flex: 1; 
    text-align: center; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
}

.figure-item svg { 
    width: 100%; 
    max-width: 280px; 
    height: auto; 
    border-radius: 6px; 
    background-color: white; 
    padding: 10px; 
    box-sizing: border-box; 
}

.caption { 
    font-size: 0.85rem; 
    color: var(--text-dim); 
    margin-top: 12px; 
    line-height: 1.4; 
}

.visual-diagram {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 30px 0;
    padding: 20px;
    background: var(--main-bg);
    border-radius: 8px;
    border: 1px solid var(--border);
}

/* [12. 인용문] */
blockquote { 
    background: var(--main-bg); 
    border-left: 4px solid var(--text-dim); 
    margin: 30px 0; 
    padding: 20px; 
    font-family: 'Noto Serif KR', serif; 
    font-style: italic; 
    color: var(--text-main); 
    border-radius: 0 6px 6px 0; 
}

/* [13. 노트북 임베드 - 모바일 최적화 버전] */
.notebook-wrapper { 
    width: 100%; 
    margin-top: 30px; 
    border: 1px solid var(--border); 
    border-radius: 8px; 
    padding: 10px; 
    box-sizing: border-box; 
    background-color: var(--main-bg); 
    overflow: hidden;
    position: relative;
}

.notebook-frame { 
    width: 100%; 
    min-width: 700px;
    border: none; 
    display: block; 
    background-color: white; 
    border-radius: 4px; 
    transition: height 0.2s ease;
    overflow: hidden;
}

/* [14. 리스트 스타일] */
.tech-list { 
    list-style: none; 
    padding: 0; 
}

.tech-list li { 
    margin-bottom: 10px; 
    padding-left: 18px; 
    position: relative; 
}

.tech-list li::before { 
    content: "•"; 
    color: var(--accent); 
    position: absolute; 
    left: 0; 
}

ul, ol {
    margin-left: 25px;
    margin-bottom: 20px;
}

li {
    margin-bottom: 10px;
    line-height: 1.8;
}

/* [15. 인라인 요소] */
.term { 
    font-weight: bold; 
    color: var(--accent); 
    background: rgba(88, 166, 255, 0.15); 
    padding: 2px 8px; 
    border-radius: 4px; 
    margin-right: 5px; 
}

code { 
    background-color: rgba(110, 118, 129, 0.2); 
    padding: 2px 5px; 
    border-radius: 4px; 
    color: var(--accent); 
    font-family: 'Consolas', monospace; 
}

/* [16. 모바일 안내 메시지] */
.mobile-notebook-guide {
    display: none;
}

/* [17. 반응형 레이아웃 설정] */
@media (max-width: 768px) {
    body { padding: 0; }
    .tutorial-container { 
        border-radius: 0; 
        box-shadow: none; 
        padding: 20px 10px; 
        min-height: 100vh; 
    }
    h1 { font-size: 1.8rem; }
    .figure-container { flex-direction: column; }
    .stats-grid { grid-template-columns: 1fr; }
    
    /* 노트북 임베드 모바일 최적화 */
    .notebook-wrapper {
        padding: 5px;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        border-radius: 4px;
    }
    
    .notebook-frame {
        min-width: 700px;
        width: 700px;
        transform: scale(0.9);
        transform-origin: top left;
        margin-bottom: -10%;
    }
    
    /* 스크롤 힌트 */
    .notebook-wrapper::after {
        content: '← 좌우로 스크롤하세요 →';
        position: absolute;
        bottom: 10px;
        left: 50%;
        transform: translateX(-50%);
        background: rgba(88, 166, 255, 0.9);
        color: white;
        padding: 5px 15px;
        border-radius: 20px;
        font-size: 0.75rem;
        pointer-events: none;
        animation: fadeOut 3s forwards;
        z-index: 10;
    }
    
    @keyframes fadeOut {
        0%, 70% { opacity: 1; }
        100% { opacity: 0; }
    }
    
    /* 스크롤바 커스터마이징 */
    .notebook-wrapper::-webkit-scrollbar {
        height: 10px;
    }
    
    .notebook-wrapper::-webkit-scrollbar-track {
        background: var(--card-bg);
        border-radius: 5px;
        margin: 0 10px;
    }
    
    .notebook-wrapper::-webkit-scrollbar-thumb {
        background: var(--accent);
        border-radius: 5px;
    }
    
    .notebook-wrapper::-webkit-scrollbar-thumb:hover {
        background: #4a8fd8;
    }
    
    /* 모바일 안내 메시지 표시 */
    .mobile-notebook-guide {
        display: block;
        background: rgba(255, 193, 7, 0.1);
        border-left-color: #ffc107;
    }
}

/* 더 작은 화면 (480px 이하) */
@media (max-width: 480px) {
    .notebook-frame {
        transform: scale(0.75);
        transform-origin: top left;
        margin-bottom: -25%;
    }
}

/* 매우 작은 화면 (360px 이하) */
@media (max-width: 360px) {
    .notebook-frame {
        transform: scale(0.65);
        transform-origin: top left;
        margin-bottom: -35%;
    }
}

/* 호버 가능 기기에서만 툴팁 표시 */
@media (hover: hover) {
    .theme-toggle:hover::after { opacity: 1; visibility: visible; transform: translateY(0); }
}