/* ========================================
   1. CSS 변수 (다크 모드 / 라이트 모드)
======================================== */
:root {
    --sidebar-width: 260px;
    
    --bg-main: #0f172a;
    --bg-sidebar: #1e293b;
    --bg-card: #1e293b;
    --bg-card-hover: #334155;
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    
    --border-color: #334155;
    
    --brand-primary: #3b82f6;
    --brand-hover: #2563eb;
    --brand-danger: #ef4444;
    --brand-danger-hover: #dc2626;
    --brand-success: #10b981;

    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.3), 0 2px 4px -1px rgba(0,0,0,0.2);
    --shadow-modal: 0 25px 50px -12px rgba(0,0,0,0.5);
}

body.light-mode {
    --bg-main: #f4f7f6;
    --bg-sidebar: #ffffff;
    --bg-card: #ffffff;
    --bg-card-hover: #f8fafc;
    
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    
    --border-color: #e2e8f0;
    
    --shadow-md: 0 10px 15px -3px rgba(0,0,0,0.05);
    --shadow-modal: 0 20px 40px rgba(0,0,0,0.1);
}

/* ========================================
   2. 전역 리셋 및 기본 레이아웃
======================================== */
* {
    margin: 0; padding: 0; box-sizing: border-box;
    font-family: 'Pretendard', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    /* 쏠림 현상 해결: body에 있던 display:flex 삭제 후 기본 블록 유지 */
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ========================================
   3. 사이드바 (Sidebar)
======================================== */
.sidebar {
    position: fixed; /* 화면 왼쪽에 완벽 고정 */
    top: 0; left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex; flex-direction: column;
    z-index: 100;
    transition: background-color 0.3s, border-color 0.3s;
}

.sidebar-header { padding: 24px; border-bottom: 1px solid var(--border-color); }
.sidebar-header h2 { font-size: 1.5rem; color: var(--brand-primary); }

.user-profile { padding: 20px 24px; display: flex; align-items: center; gap: 15px; border-bottom: 1px solid var(--border-color); }
.avatar {
    width: 40px; height: 40px; background: linear-gradient(135deg, var(--brand-primary), #8b5cf6);
    border-radius: 50%; display: flex; justify-content: center; align-items: center; font-weight: bold; font-size: 1.2rem; color: white;
}
.user-info { display: flex; flex-direction: column; }
.user-name { font-weight: 600; font-size: 1rem; }
.user-rank { font-size: 0.8rem; color: var(--text-secondary); }

.menu-list { flex: 1; padding: 20px 0; overflow-y: auto; list-style: none; }
.menu-title { padding: 15px 24px 5px; font-size: 0.75rem; font-weight: bold; color: var(--text-secondary); text-transform: uppercase; }
.menu-item a {
    display: flex; align-items: center; gap: 12px; padding: 12px 24px; color: var(--text-primary);
    text-decoration: none; font-weight: 500; transition: all 0.2s;
}
.menu-item a:hover { background-color: var(--bg-card-hover); color: var(--brand-primary); }
.menu-item.active a { background-color: rgba(59, 130, 246, 0.1); color: var(--brand-primary); border-right: 4px solid var(--brand-primary); }
.menu-item .material-icons { font-size: 20px; }

.sidebar-footer { padding: 15px 24px; border-top: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.action-icon-btn { background: none; border: none; color: var(--text-secondary); cursor: pointer; padding: 8px; border-radius: 8px; transition: 0.2s; }
.action-icon-btn:hover { background-color: var(--bg-card-hover); color: var(--brand-primary); }

/* ========================================
   4. 메인 콘텐츠 (대시보드)
======================================== */
.main-content {
    /* 쏠림 현상 해결: 사이드바 너비만큼 왼쪽 여백을 확실하게 밀어줌 */
    margin-left: var(--sidebar-width);
    padding: 40px;
    min-height: 100vh;
}

.top-header { margin-bottom: 40px; }
.top-header h1 { font-size: 2.2rem; margin-bottom: 8px; }
.top-header p { color: var(--text-secondary); font-size: 1.1rem; }

.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 20px; margin-bottom: 40px; }
.widget-card { background-color: var(--bg-card); border: 1px solid var(--border-color); border-radius: 16px; padding: 24px; display: flex; flex-direction: column; gap: 15px; box-shadow: var(--shadow-md); transition: transform 0.3s; }
.widget-card:hover { transform: translateY(-5px); }
.widget-icon { width: 48px; height: 48px; border-radius: 12px; display: flex; justify-content: center; align-items: center; font-size: 24px; }
.streak-widget .widget-icon { background-color: rgba(239, 68, 68, 0.1); color: var(--brand-danger); }
.solve-widget .widget-icon { background-color: rgba(16, 185, 129, 0.1); color: var(--brand-success); }
.rival-widget .widget-icon { background-color: rgba(139, 92, 246, 0.1); color: #8b5cf6; }
.rank-widget .widget-icon { background-color: rgba(245, 158, 11, 0.1); color: #f59e0b; }
.widget-info h3 { font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 5px; }
.highlight-text { font-size: 1.5rem; font-weight: bold; margin-bottom: 5px; }
.widget-info p { font-size: 0.85rem; color: var(--text-secondary); }
.status-online { color: var(--brand-success) !important; font-weight: 600; }

.recent-actions h2 { margin-bottom: 20px; font-size: 1.5rem; }
.action-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(350px, 1fr)); gap: 20px; }
.action-card { background-color: var(--bg-card); border: 1px solid var(--border-color); border-radius: 16px; padding: 30px; box-shadow: var(--shadow-md); }
.action-card h3 { font-size: 1.3rem; margin-bottom: 10px; }
.action-card p { color: var(--text-secondary); margin-bottom: 20px; line-height: 1.5; }

/* 공통 버튼 */
.primary-btn { background-color: var(--brand-primary); color: white; border: none; padding: 12px 24px; border-radius: 8px; font-weight: 600; font-size: 1rem; cursor: pointer; transition: 0.2s; }
.primary-btn:hover { background-color: var(--brand-hover); }
.primary-btn.danger { background-color: var(--brand-danger); }
.primary-btn.danger:hover { background-color: var(--brand-danger-hover); }
.full-width { width: 100%; }
.secondary-btn { background-color: transparent; color: var(--text-primary); border: 1px solid var(--border-color); padding: 12px 24px; border-radius: 8px; font-weight: 600; cursor: pointer; transition: 0.2s; }
.secondary-btn:hover { background-color: var(--bg-card-hover); }

/* ========================================
   5. [3차] 문제 풀이 화면 (IDE) 전용 레이아웃
======================================== */
.solve-page-body { overflow: hidden; } /* IDE 화면 스크롤 방지 */

.solve-layout {
    display: flex;
    flex-direction: row;
    padding: 0; /* IDE는 대시보드 여백(40px) 제거 */
    height: 100vh;
}

.problem-panel { width: 40%; background-color: var(--bg-main); border-right: 1px solid var(--border-color); padding: 30px; overflow-y: auto; }
.problem-header { margin-bottom: 25px; }
.badge { display: inline-block; padding: 4px 8px; border-radius: 4px; font-size: 0.8rem; font-weight: bold; color: white; margin-bottom: 10px; }
.level-2 { background-color: #f59e0b; }
.problem-content { line-height: 1.6; color: var(--text-secondary); }
.problem-content h3 { color: var(--text-primary); margin: 15px 0 5px; font-size: 1.1rem; }
.problem-content ul { padding-left: 20px; margin-bottom: 15px; }
.io-box { background-color: var(--bg-card); padding: 15px; border-radius: 8px; border: 1px solid var(--border-color); font-family: monospace; font-size: 0.95rem; }

.editor-panel { width: 60%; display: flex; flex-direction: column; background-color: #1e1e1e; }
body.light-mode .editor-panel { background-color: #ffffff; }

.editor-toolbar { padding: 10px 20px; background-color: var(--bg-card); border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.language-select { width: 200px; padding: 8px; }

.editor-container { flex: 1; overflow: hidden; position: relative; }
.CodeMirror { height: 100% !important; font-family: 'Consolas', 'Courier New', monospace; font-size: 16px; }

.terminal-section { height: 200px; background-color: #0d1117; border-top: 1px solid var(--border-color); display: flex; flex-direction: column; transition: margin-bottom 0.3s cubic-bezier(0.4, 0, 0.2, 1); }
body.light-mode .terminal-section { background-color: #f1f5f9; }
.terminal-section.collapsed { margin-bottom: -200px; }
.terminal-header { padding: 5px 15px; background-color: rgba(255,255,255,0.05); display: flex; justify-content: space-between; align-items: center; font-size: 0.85rem; font-weight: bold; }
.terminal-body { flex: 1; padding: 15px; overflow-y: auto; font-family: monospace; font-size: 0.95rem; color: #10b981; }
.terminal-body.error { color: #ef4444; }

.editor-actions { padding: 15px 20px; background-color: var(--bg-card); border-top: 1px solid var(--border-color); display: flex; justify-content: flex-end; gap: 10px; z-index: 10; }

/* ========================================
   6. 모달 창 및 팝업 (완벽한 UX)
======================================== */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
    display: flex; justify-content: center; align-items: center; z-index: 1000;
    opacity: 1; visibility: visible; transition: all 0.3s ease;
}
.modal-overlay.hidden { opacity: 0; visibility: hidden; }

.modal-content {
    background-color: var(--bg-card); width: 100%; max-width: 400px;
    border-radius: 20px; padding: 30px; box-shadow: var(--shadow-modal);
    transform: translateY(0) scale(1); transition: all 0.3s ease; border: 1px solid var(--border-color);
}
.modal-overlay.hidden .modal-content { transform: translateY(20px) scale(0.95); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 25px; }
.close-btn { background: none; border: none; font-size: 24px; color: var(--text-secondary); cursor: pointer; }
.close-btn:hover { color: var(--text-primary); }

.input-group { margin-bottom: 20px; }
.input-group label { display: block; margin-bottom: 8px; font-size: 0.9rem; font-weight: 500; }
.input-group input, .modern-select { width: 100%; padding: 12px 15px; border-radius: 8px; border: 1px solid var(--border-color); background-color: var(--bg-main); color: var(--text-primary); font-size: 1rem; transition: 0.2s; }
.input-group input:focus, .modern-select:focus { outline: none; border-color: var(--brand-primary); }

.divider { text-align: center; margin: 20px 0; position: relative; }
.divider::before { content: ''; position: absolute; left: 0; top: 50%; width: 100%; height: 1px; background-color: var(--border-color); z-index: 1; }
.divider span { background-color: var(--bg-card); padding: 0 10px; color: var(--text-secondary); position: relative; z-index: 2; font-size: 0.85rem; }
.social-btn { width: 100%; padding: 12px; border-radius: 8px; border: 1px solid var(--border-color); background-color: transparent; color: var(--text-primary); font-weight: 600; cursor: pointer; transition: 0.2s; }
.social-btn:hover { background-color: var(--bg-main); }

.setting-item { margin-bottom: 20px; }
.setting-item label { display: block; margin-bottom: 10px; font-weight: 500; }
.flex-row { display: flex; justify-content: space-between; align-items: center; }
.switch { position: relative; display: inline-block; width: 44px; height: 24px; margin: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--border-color); transition: .4s; border-radius: 24px; }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: var(--brand-primary); }
input:checked + .slider:before { transform: translateX(20px); }

/* 성공 팝업 애니메이션 */
.text-center { text-align: center; }
.success-content { animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.success-icon { font-size: 60px; margin-bottom: 10px; animation: bounce 2s infinite; }
.reward-box { margin-top: 15px; padding: 10px; background-color: rgba(245, 158, 11, 0.1); border: 1px solid rgba(245, 158, 11, 0.3); border-radius: 8px; display: inline-block; }

@keyframes popIn { 0% { transform: scale(0.5); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes bounce { 0%, 20%, 50%, 80%, 100% { transform: translateY(0); } 40% { transform: translateY(-20px); } 60% { transform: translateY(-10px); } }
/* 로그인 모달 하단 버튼 디자인 추가 */
#toggle-auth-btn { border: none; font-size: 0.9rem; margin-top: 5px; }
#toggle-auth-btn:hover { color: var(--brand-primary); }
/* ========================================
   7. 서브 페이지 전용 디자인 (문제 목록, 랭킹, 커뮤니티)
======================================== */
.page-header { margin-bottom: 30px; border-bottom: 1px solid var(--border-color); padding-bottom: 15px; }
.page-header h2 { font-size: 1.8rem; display: flex; align-items: center; gap: 10px; }

/* 문제 목록 (challenges.html) */
.challenge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 20px; }
.challenge-card {
    background-color: var(--bg-card); border: 1px solid var(--border-color);
    border-radius: 12px; padding: 25px; display: flex; flex-direction: column; transition: 0.2s;
}
.challenge-card:hover { transform: translateY(-3px); border-color: var(--brand-primary); }
.challenge-meta { display: flex; justify-content: space-between; margin-bottom: 15px; }
.challenge-title { font-size: 1.2rem; font-weight: bold; margin-bottom: 10px; }
.challenge-desc { color: var(--text-secondary); font-size: 0.9rem; flex-grow: 1; margin-bottom: 20px; line-height: 1.5; }

/* 랭킹 (ranking.html) */
.ranking-list { display: flex; flex-direction: column; gap: 12px; max-width: 800px; }
.rank-item {
    display: flex; align-items: center; background-color: var(--bg-card);
    border: 1px solid var(--border-color); border-radius: 12px; padding: 15px 25px;
}
.rank-item:hover { background-color: var(--bg-card-hover); }
.rank-item.top-3 { background: linear-gradient(90deg, rgba(59, 130, 246, 0.05), var(--bg-card)); border-left: 4px solid var(--brand-primary); }
.rank-number { width: 60px; font-size: 1.3rem; font-weight: bold; color: var(--text-secondary); }
.top-3 .rank-number { color: var(--brand-primary); }
.rank-user { flex-grow: 1; display: flex; align-items: center; gap: 15px; font-weight: bold; }
.rank-score { font-weight: bold; color: var(--brand-success); font-size: 1.1rem; }

/* 커뮤니티 (community.html) */
.community-controls { display: flex; justify-content: flex-end; margin-bottom: 20px; }
.post-list { display: flex; flex-direction: column; gap: 15px; }
.post-item { background-color: var(--bg-card); border: 1px solid var(--border-color); border-radius: 12px; padding: 20px 25px; cursor: pointer; transition: 0.2s; }
.post-item:hover { border-color: var(--brand-primary); }
.post-title { font-size: 1.1rem; font-weight: bold; margin-bottom: 8px; }
.post-info { font-size: 0.85rem; color: var(--text-secondary); display: flex; gap: 15px; }