:root {
    /* 기본 다크 테마 (초콜릿/차콜 프리미엄) */
    --bg-color: #0F0F12;
    --bg-gradient: linear-gradient(135deg, #1A1A20 0%, #0F0F12 100%);
    --surface-color: #212128;
    --surface-light: #2A2A33;
    --primary-color: #FF9800;
    --primary-hover: #F57C00;
    --accent-color: #00BCD4;
    --error-color: #F44336;
    
    --text-main: #FFFFFF;
    --text-muted: #9E9E9E;
    --text-dark: #121212;
    
    --grid-line: #333333;
    --grid-line-thick: #555555;
    
    --cell-bg: #F9F9F9; /* Paper-like by default even in dark mode for clarity? No, let's keep it dark for dark mode but very subtle */
    --cell-bg: #212128;
    --cell-bg-selected: #5D4037;
    --cell-bg-highlight: #4E342E;
    --cell-bg-cross: #2A2A33;
    --cell-bg-error: #4A1919;
    
    --text-fixed: #FFFFFF;
    --text-user: #FFB74D;
    --text-error: #FF5252;
    
    --sidebar-bg: #15151A;
    --sidebar-hover: #212128;
}

:root[data-theme="light"] {
    /* 라이트 테마 (올리브/베이지 프리미엄, 경쟁사 참고) */
    --bg-color: #E8EBE2;
    --bg-gradient: linear-gradient(135deg, #F1F4EB 0%, #D8DEC5 100%);
    --surface-color: #FFFFFF;
    --surface-light: #EFEFEF;
    --primary-color: #FF9800;
    --primary-hover: #F57C00;
    --accent-color: #00BCD4;
    --error-color: #F44336;
    
    --text-main: #333333;
    --text-muted: #666666;
    --text-dark: #121212;
    
    --grid-line: #D0D0D0;
    --grid-line-thick: #888888;
    
    --cell-bg: #FFFFFF;
    --cell-bg-selected: #FFE0B2;
    --cell-bg-highlight: #FFF3E0;
    --cell-bg-cross: #F4F7F0;
    --cell-bg-error: #FFEBEE;
    
    --text-fixed: #111111;
    --text-user: #E65100;
    --text-error: #D32F2F;
    
    --sidebar-bg: #F5F7F2;
    --sidebar-hover: #E8EBE2;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
    font-family: 'Inter', 'Noto Sans KR', sans-serif;
    background: var(--bg-gradient);
    color: var(--text-main);
    overflow: hidden; /* App Layout will handle scrolling */
    user-select: none;
}

.app-background {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg-gradient); z-index: -1;
}

/* ===============================
   APP LAYOUT (Sidebar + Main)
================================*/
.app-layout {
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--surface-light);
    display: flex;
    flex-direction: column;
    z-index: 50;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 30px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.sidebar-header .logo-icon { font-size: 32px; }
.sidebar-header h1 { font-size: 22px; font-weight: 700; color: var(--primary-color); }

.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0 10px;
    gap: 5px;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 16px;
    font-weight: 600;
    border-radius: 12px;
    transition: all 0.2s;
}
.nav-item:hover { background-color: var(--sidebar-hover); color: var(--text-main); }
.nav-item.active {
    background-color: var(--primary-color);
    color: var(--text-dark);
}
.nav-icon { font-size: 20px; }

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--surface-light);
}
.user-profile { display: flex; align-items: center; gap: 12px; }
.avatar {
    width: 40px; height: 40px; border-radius: 20px;
    background-color: var(--primary-color); color: var(--text-dark);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 18px;
}
.user-info { display: flex; flex-direction: column; }
.username { font-weight: 600; font-size: 15px; }
.user-points { font-size: 13px; color: var(--primary-color); }

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

.mobile-header {
    display: none;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--surface-light);
}
.menu-toggle { background: none; border: none; font-size: 24px; color: var(--text-main); cursor: pointer; }

/* Tabs */
.tab-pane {
    display: none;
    width: 100%;
    height: 100%;
    padding: 20px;
    overflow-y: auto;
}
.tab-pane.active {
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

/* ===============================
   APP CARDS & GAME UI
================================*/
.app-card {
    background-color: var(--surface-color);
    width: 100%;
    max-width: 1200px;
    border-radius: 20px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    padding: 20px 30px;
}
.content-card { padding: 40px; }
.content-card.scrollable { max-height: 90vh; overflow-y: auto; user-select: text; }
.content-card h2 { color: var(--primary-color); font-size: 28px; margin-bottom: 10px; }
.content-card .subtitle { color: var(--text-muted); font-size: 16px; margin-bottom: 30px; line-height: 1.5; }

/* Header Bar */
.app-header {
    display: flex; justify-content: space-between; align-items: center;
    padding-bottom: 20px; margin-bottom: 20px;
    border-bottom: 2px solid var(--surface-light);
}
.header-brand h2 { font-size: 22px; font-weight: 700; color: var(--text-main); }
.header-controls { display: flex; align-items: center; gap: 15px; }

.control-group {
    display: flex; align-items: center; gap: 8px;
    background-color: var(--bg-color); padding: 8px 16px;
    border-radius: 12px; font-size: 16px; font-weight: 600;
}
.control-label { color: var(--text-muted); }
.diff-select { background: none; border: none; color: var(--text-main); font-size: 16px; font-weight: 700; cursor: pointer; outline: none; }
.theme-toggle {
    background-color: var(--bg-color); border: none; font-size: 20px;
    cursor: pointer; width: 40px; height: 40px; border-radius: 20px;
    transition: transform 0.2s;
}

/* Game Layout */
.game-container { display: flex; flex-direction: column; gap: 30px; }
@media (min-width: 1024px) {
    .game-container { flex-direction: row; align-items: flex-start; }
    .game-col-left { flex: 2; display: flex; justify-content: center; }
    .game-col-right { flex: 1; display: flex; flex-direction: column; gap: 20px; }
}

/* Sudoku Board (Paper-like) */
.sudoku-board {
    display: grid; grid-template-columns: repeat(9, 1fr);
    aspect-ratio: 1 / 1; width: 100%; max-width: 65vh;
    background-color: var(--grid-line); gap: 1px;
    border: 4px solid var(--grid-line-thick); border-radius: 4px; /* Less rounded for paper feel */
    overflow: hidden;
}

.cell {
    background-color: var(--cell-bg); display: flex; align-items: center; justify-content: center;
    font-size: clamp(24px, 6.5vw, 38px); font-weight: 800; cursor: pointer;
    transition: background-color 0.1s, transform 0.1s;
}
.cell:nth-child(3n) { border-right: 2px solid var(--grid-line-thick); }
.cell:nth-child(9n) { border-right: none; }
.cell:nth-child(n+19):nth-child(-n+27),
.cell:nth-child(n+46):nth-child(-n+54) { border-bottom: 2px solid var(--grid-line-thick); }

.cell.selected { background-color: var(--cell-bg-selected) !important; }
.cell.cross-highlight { background-color: var(--cell-bg-cross); }
.cell.highlighted { background-color: var(--cell-bg-highlight) !important; }
.cell.fixed { color: var(--text-fixed); font-weight: 900; font-size: clamp(25px, 6.8vw, 40px); }
.cell.user-input { color: var(--text-user); font-weight: 700; font-size: clamp(24px, 6.5vw, 38px); font-family: 'Inter', 'Noto Sans KR', sans-serif; }
.cell.error { color: var(--text-error); background-color: var(--cell-bg-error); animation: shake 0.3s; }

/* Input scaling effect (Haptic visual) */
.cell.pop { animation: popIn 0.2s ease-out; }
@keyframes popIn { 0% { transform: scale(0.8); } 50% { transform: scale(1.1); } 100% { transform: scale(1); } }

/* Pencil Notes */
.cell .notes-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
    width: 100%; height: 100%; padding: 2px;
}
.cell .note-num {
    font-size: 11px; line-height: 1; display: flex; align-items: center; justify-content: center;
    color: var(--text-muted); font-weight: 500; font-family: sans-serif;
}

/* Action Controls & Numpad */
.action-controls { display: flex; justify-content: space-between; gap: 6px; margin-bottom: 8px; }
.action-btn {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; background-color: var(--bg-color); color: var(--text-main);
    border: 1px solid var(--surface-light); border-radius: 8px; padding: 6px 0;
    font-size: 11px; font-weight: 600; cursor: pointer; transition: all 0.2s;
}
.action-btn:active, .action-btn.active { background-color: var(--primary-color); color: var(--text-dark); border-color: var(--primary-color); }
.action-btn .icon { font-size: 16px; }

.numpad { display: grid; grid-template-columns: repeat(9, 1fr); gap: 3px; width: 100%; }
.num-btn {
    background-color: var(--bg-color); color: var(--primary-color);
    border: 1.5px solid var(--surface-light); border-radius: 8px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 5px 0; font-size: 20px; font-weight: 800; cursor: pointer; transition: transform 0.1s, opacity 0.2s;
    min-height: 48px; width: 100%;
}
.num-btn .num-val { font-size: 20px; font-weight: 800; line-height: 1; }
.num-btn .num-count { font-size: 11px; font-weight: 600; color: var(--text-muted); margin-top: 2px; line-height: 1; }
.num-btn:active { transform: scale(0.92); background-color: var(--surface-light); }
.num-btn:disabled, .num-btn.completed { opacity: 0.15; cursor: not-allowed; pointer-events: none; border-color: transparent; }

/* ===============================
   CONTENT TABS (Leaderboard, Article)
================================*/
.leaderboard-table { width: 100%; border-collapse: collapse; margin-top: 20px; }
.leaderboard-table th, .leaderboard-table td { padding: 15px; text-align: left; border-bottom: 1px solid var(--surface-light); }
.leaderboard-table th { color: var(--text-muted); font-weight: 600; }
.leaderboard-table .my-rank { background-color: rgba(255, 152, 0, 0.1); font-weight: bold; border-left: 4px solid var(--primary-color); }

.awards-section { margin-bottom: 30px; padding: 20px; background-color: var(--bg-color); border-radius: 12px; }
.streak-box { font-size: 24px; font-weight: bold; color: var(--text-main); margin-top: 10px; }
.fire-icon { color: #FF5722; }

.article-section h3 { color: var(--primary-color); margin-top: 30px; margin-bottom: 10px; font-size: 20px; }
.article-section p { line-height: 1.7; font-size: 16px; margin-bottom: 15px; color: var(--text-main); }
.article-section strong { color: var(--accent-color); }

.daily-placeholder { text-align: center; padding: 40px 20px; background-color: var(--bg-color); border-radius: 16px; margin-top: 20px; }
.daily-placeholder .big-icon { font-size: 60px; display: block; margin-bottom: 20px; }
.daily-placeholder h3 { font-size: 24px; margin-bottom: 10px; }
.daily-placeholder p { color: var(--text-muted); font-size: 16px; margin-bottom: 5px; }

/* Modals */
.modal {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(0,0,0,0.8); display: none; align-items: center; justify-content: center;
    z-index: 100; backdrop-filter: blur(5px);
}
.modal-content { background-color: var(--surface-color); padding: 40px 30px; border-radius: 20px; text-align: center; width: 90%; max-width: 400px; }
.primary-btn { background-color: var(--primary-color); color: var(--text-dark); border: none; border-radius: 30px; padding: 16px 30px; font-size: 18px; font-weight: 700; cursor: pointer; width: 100%; margin-bottom: 20px; }

/* ===============================
   MOBILE RESPONSIVE
================================*/
@media (max-width: 900px) {
    .app-layout { flex-direction: column; }
    .sidebar {
        position: fixed; left: -280px; top: 0; bottom: 0;
        box-shadow: 10px 0 30px rgba(0,0,0,0.5);
    }
    .sidebar.open { transform: translateX(280px); }
    .mobile-header { display: flex; padding: 8px 12px; }
    .tab-pane { padding: 4px; }
    .app-card { padding: 10px 12px; min-height: calc(100vh - 60px); border-radius: 8px; }
    .app-header { padding-bottom: 8px; margin-bottom: 8px; }
    .control-group { padding: 4px 8px; font-size: 13px; gap: 4px; border-radius: 8px; }
    .diff-select { font-size: 13px; }
    .hide-on-mobile { display: none !important; }
    .numpad { grid-template-columns: repeat(9, 1fr); gap: 3px; }
    .num-btn { height: 46px; min-height: 46px; padding: 2px 0; }
    .num-btn .num-val { font-size: 18px; }
    .num-btn .num-count { font-size: 10px; }
}

@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

/* Print */
@media print {
    body, .app-card, .app-background { background: white !important; color: black !important; margin: 0; padding: 0; box-shadow: none; border-radius: 0; }
    .sidebar, .mobile-header, .app-header, .game-col-right, .tab-pane:not(#tab-home) { display: none !important; }
    .game-container { display: block; }
    .sudoku-board { width: 18cm; height: 18cm; max-width: none; border-color: black; box-shadow: none; margin: 0 auto; }
    .cell { color: black !important; background: white !important; border-color: black !important; font-family: sans-serif; }
}
