:root {
    --bg-color: #0f172a;
    --sidebar-bg: #1e293b;
    --card-bg: #ffffff;
    --text-color: #f8fafc;
    --text-muted: #94a3b8;
    --border-color: #334155;
    --code-bg: #282c34;
    
    /* 카드(밝은 배경) 내부 텍스트 색상 */
    --card-text: #1e293b;
    --card-heading: #0f172a;
    --card-muted: #475569;

    /* 기본 강조 색상 (HTML 오렌지 테마) */
    --primary-color: #E44D26;
    --secondary-color: #F16529;
    --accent-color: #FF8A65;
    --accent-primary: #E44D26;
    --accent-hover: #F16529;

    /* 코드 하이라이팅용 색상 (Atom One Dark 테마 기반) */
    --hl-tag: #e06c75;
    --hl-attr: #d19a66;
    --hl-val: #98c379;
    --hl-cmt: #5c6370;
    --hl-kw: #c678dd;
    --hl-func: #61afef;
    --hl-num: #d19a66;
    --hl-prop: #56B6C2;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Pretendard', 'Inter', -apple-system, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh;
    display: flex;
    overflow: hidden;
}

/* App Container */
.app-container {
    display: flex;
    width: 100vw;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 1.5rem 0;
    flex-shrink: 0;
    position: relative;
    transition: margin-left 0.3s ease;
}

.sidebar.collapsed {
    margin-left: -280px;
}

.sidebar-toggle-btn {
    position: absolute;
    top: 50%;
    right: -30px;
    transform: translateY(-50%);
    width: 30px;
    height: 60px;
    background-color: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-left: none;
    border-radius: 0 8px 8px 0;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    font-size: 1.2rem;
    box-shadow: 2px 0 5px rgba(0,0,0,0.2);
    transition: background-color 0.2s, color 0.2s;
}

.sidebar-toggle-btn:hover {
    background-color: var(--accent-primary);
    color: #ffffff;
}

.sidebar-header {
    padding: 0 1.5rem 1.5rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1rem;
}

.sidebar-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent-primary);
    line-height: 1.4;
}

.nav-links {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0 1rem;
    flex: 1;
    overflow-y: auto;
}

.nav-item {
    padding: 0.85rem 1.25rem;
    border-radius: 0.5rem;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.nav-item svg {
    width: 1.4em;
    height: 1.4em;
    min-width: 1.4em;
    flex-shrink: 0;
}

.nav-item:hover {
    background-color: rgba(228, 77, 38, 0.1);
    color: var(--text-color);
}

.nav-item.active {
    background-color: rgba(228, 77, 38, 0.2);
    color: var(--accent-primary);
    border-left: 4px solid var(--accent-primary);
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

/* Main Content */
.main-content {
    flex: 1;
    overflow-y: auto;
    scroll-behavior: smooth;
    padding: 2.5rem 4rem;
}

.section {
    display: none;
    animation: fadeIn 0.4s ease-in-out;
    max-width: 900px;
    margin: 0 auto;
}

.section.active {
    display: block;
}

/* Restoring Headers and Constraints */
header { 
    text-align: center; 
    margin-bottom: 40px; 
    padding: 40px 0; 
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color)); 
    color: white; 
    border-radius: 15px; 
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1); 
    max-width: 900px; 
    margin: 0 auto 40px auto; 
}
header h1 { color: white; margin: 0; font-size: 2.5em; text-shadow: 1px 1px 2px rgba(0,0,0,0.2); }
header p { color: white; font-size: 1.15em; opacity: 0.92; font-weight: bold; margin-top: 8px; }

.container > section, .section > section { 
    background: var(--card-bg); 
    padding: 30px; 
    margin: 0 auto 30px auto; 
    border-radius: 15px; 
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25); 
    color: var(--card-text); 
    max-width: 900px; 
    transition: transform 0.3s ease, box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    z-index: 1;
    border: 1px solid rgba(0, 0, 0, 0.06);
}
.container > section:hover, .section > section:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.08);
    z-index: 2;
}

.container > section p, .section > section p, 
.container > section ul, .section > section ul,
.container > section li, .section > section li,
.container > section div, .section > section div {
    color: var(--card-text);
}
.container > section p, .section > section p {
    line-height: 1.7;
    letter-spacing: -0.01em;
}

.section h2, .container section h2 { 
    border-bottom: 3px solid transparent; 
    border-image: linear-gradient(90deg, var(--primary-color), var(--secondary-color), transparent) 1; 
    padding-bottom: 12px; 
    margin-bottom: 20px; 
    font-size: 1.4em; 
    color: var(--card-heading); 
    display: inline-block; 
    margin-top: 0; 
    letter-spacing: -0.02em;
}
.section h3, .container section h3 {
    color: var(--primary-color);
    margin-bottom: 15px;
    margin-top: 25px;
    font-size: 1.2em;
}

/* Code container setup */
pre {
    background-color: var(--code-bg) !important;
    color: #abb2bf !important;
    padding: 20px !important;
    border-radius: 10px !important;
    margin: 20px 0 !important;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.5);
    border: 1px solid #1e2227;
    overflow-x: auto;
    font-family: 'Fira Code', 'Consolas', monospace;
    font-size: 0.95em !important;
    line-height: 1.6 !important;
}

pre code {
    background-color: transparent !important;
    color: inherit !important;
    padding: 0 !important;
    border-radius: 0 !important;
    border: none !important;
    font-weight: normal !important;
}

/* Code Highlight Classes (HTML 특화) */
.tag { color: var(--hl-tag); }
.attr { color: var(--hl-attr); }
.val { color: var(--hl-val); }
.cmt { color: var(--hl-cmt); font-style: italic; }
.kw { color: var(--hl-kw); }
.fn { color: var(--hl-func); }
.num { color: var(--hl-num); }
.prop { color: var(--hl-prop); }

/* Inline Code */
.container > section code, .section > section code {
    background-color: rgba(100, 100, 120, 0.1);
    color: #c7254e;
    padding: 2px 7px;
    border-radius: 4px;
    font-size: 0.92em;
    font-weight: 500;
    border: 1px solid rgba(100, 100, 120, 0.12);
    font-family: 'Consolas', 'Monaco', monospace;
}

/* 🐍 비유 박스 (Metaphor Box) */
.metaphor {
    background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
    border-left: 6px solid var(--primary-color);
    border-radius: 0 14px 14px 0;
    padding: 22px 26px;
    margin: 24px 0;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
    color: #44403c;
}
.metaphor:hover {
    transform: translateX(3px);
    border-left-width: 8px;
}
.metaphor::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 80px;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.35));
    pointer-events: none;
}
.metaphor-icon {
    font-size: 1.8em;
    margin-right: 12px;
    vertical-align: middle;
}
.metaphor strong {
    color: #92400e;
    font-size: 1.05em;
}
.metaphor code {
    color: #9a3412 !important;
    background-color: rgba(154, 52, 18, 0.1) !important;
}

/* Lists */
ul, ol {
    margin-left: 2rem;
    margin-bottom: 1rem;
    line-height: 1.6;
}
li {
    margin-bottom: 0.5rem;
}

/* 퀴즈/미션 박스 */
.mission-box {
    background: linear-gradient(135deg, #faf5ff 0%, #f3e8ff 100%);
    border: 2px dashed #8b5cf6;
    border-radius: 14px;
    padding: 28px;
    margin-top: 30px;
    box-shadow: 0 4px 16px rgba(139, 92, 246, 0.08);
    position: relative;
    overflow: hidden;
    color: #3b0764;
}
.mission-box::before {
    content: '🎯';
    position: absolute;
    top: -5px;
    right: 15px;
    font-size: 3em;
    opacity: 0.08;
}
.mission-box h2 {
    color: #6d28d9 !important;
    border-bottom: 3px solid transparent !important;
    border-image: linear-gradient(90deg, #6d28d9, #a78bfa, transparent) 1 !important;
}
.mission-box p {
    color: #3b0764 !important;
}

/* Quiz Options */
.quiz-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 10px;
}
.quiz-option {
    background-color: #fff;
    border: 1px solid #c4b5fd;
    padding: 10px 15px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    color: #1e1b4b;
}
.quiz-option:hover {
    border-color: var(--primary-color);
    background-color: #faf5ff;
}
.quiz-option.correct {
    background-color: rgba(16, 185, 129, 0.15);
    border-color: #10b981;
    color: #065f46;
    font-weight: bold;
}
.quiz-option.wrong {
    background-color: rgba(239, 68, 68, 0.15);
    border-color: #ef4444;
    color: #991b1b;
}

/* Details/Summary 토글 */
details {
    background-color: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 0;
    overflow: hidden;
    transition: all 0.3s ease;
    margin-top: 16px;
}
details[open] {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}
details summary {
    padding: 14px 20px;
    cursor: pointer;
    font-weight: 600;
    color: var(--primary-color);
    background: linear-gradient(90deg, rgba(228, 77, 38, 0.05), transparent);
    border-radius: 12px;
    transition: background 0.2s ease;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
}
details summary::before {
    content: '▶';
    font-size: 0.7em;
    transition: transform 0.3s ease;
    display: inline-block;
}
details[open] summary::before {
    transform: rotate(90deg);
}
details summary:hover {
    background: linear-gradient(90deg, rgba(228, 77, 38, 0.12), transparent);
}
details > div, details > p {
    padding: 16px 20px;
    border-top: 1px solid #e2e8f0;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
    background-color: white;
    color: #333;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    border: none;
}
th, td {
    padding: 12px 15px;
    text-align: left;
    border: 1px solid #f1f5f9;
}
th {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    font-weight: 600;
    letter-spacing: 0.02em;
}
tr:nth-child(even) td {
    background-color: #f8fafc;
}
tr:hover td {
    background-color: #fef3c7;
    transition: background-color 0.2s ease;
}

/* 요약 박스 (Summary Box) */
.summary-box {
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border: 2px solid #38bdf8;
    box-shadow: 0 4px 16px rgba(56, 189, 248, 0.1);
    padding: 30px;
    border-radius: 15px;
    margin: 50px auto 30px auto;
    max-width: 900px;
    position: relative;
    overflow: hidden;
    color: #0c4a6e;
}
.summary-box::before {
    content: '📌';
    position: absolute;
    top: -5px;
    right: 15px;
    font-size: 3em;
    opacity: 0.08;
}
.summary-box h2 {
    color: #0c4a6e;
    border-bottom: 2px solid #38bdf8;
    padding-bottom: 10px;
}
.summary-box li {
    margin-bottom: 8px;
    line-height: 1.7;
    color: #0c4a6e;
}
.summary-box p {
    color: #0c4a6e !important;
}
.summary-box strong {
    color: #075985;
}

/* === HTML 교육 전용 라이브 프리뷰 박스 === */
.live-preview-container {
    display: flex;
    flex-direction: column;
    border: 2px solid #475569;
    border-radius: 12px;
    overflow: hidden;
    margin: 20px 0;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

.preview-header {
    background-color: #1e293b;
    padding: 10px 15px;
    border-bottom: 2px solid #475569;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
    color: #94a3b8;
    font-size: 0.9em;
    letter-spacing: 0.03em;
}
.preview-header span::before {
    content: '💻 ';
}

.preview-content {
    display: flex;
    flex-direction: column;
}

@media (min-width: 768px) {
    .preview-content {
        flex-direction: row;
    }
}

.preview-editor, .preview-result {
    flex: 1;
    padding: 15px;
}

/* 코드 편집 영역: 밝은 글씨가 반드시 보이도록 !important 사용 */
.preview-editor {
    background-color: #1e1e2e !important;
    color: #cdd6f4 !important;
    border-right: 2px solid #475569;
}

.preview-editor textarea {
    width: 100%;
    height: 100%;
    min-height: 350px;
    background: transparent !important;
    color: #cdd6f4 !important;
    border: none;
    font-family: 'Fira Code', 'Consolas', monospace;
    font-size: 0.95em;
    line-height: 1.6;
    resize: vertical;
    outline: none;
    tab-size: 2;
}

/* 결과 미리보기 영역 */
.preview-result {
    background-color: #fff;
    min-height: 350px;
    border-top: 2px solid #e2e8f0;
}

@media (min-width: 768px) {
    .preview-result {
        border-top: none;
    }
}

.preview-result iframe {
    width: 100%;
    height: 100%;
    min-height: 350px;
    border: none;
}

/* Animations & Scrollbar */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
::-webkit-scrollbar-track {
    background: var(--bg-color); 
}
::-webkit-scrollbar-thumb {
    background: var(--border-color); 
    border-radius: 5px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted); 
}
