* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Calibri, sans-serif;
    user-select: none; /* Prevent text selection to look more like an app */
}

body {
    background-color: #fff;
    color: #333;
    font-size: 14px;
    overflow: hidden;
}

#excel-app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Ribbon Menu */
.ribbon {
    background-color: #f3f2f1;
    border-bottom: 1px solid #d2d0ce;
}

.ribbon-top {
    display: flex;
    justify-content: space-between;
    background-color: #217346;
    color: white;
    padding: 4px 10px;
    font-size: 12px;
}

.window-controls span {
    margin-left: 15px;
    cursor: pointer;
}

.menu-tabs {
    display: flex;
    padding-top: 5px;
    background-color: #f3f2f1;
}

.menu-tab {
    padding: 4px 15px;
    font-size: 13px;
    cursor: pointer;
    border: 1px solid transparent;
    border-bottom: none;
}

.menu-tab.active {
    background-color: #fff;
    border-color: #d2d0ce;
    color: #217346;
    border-bottom: 1px solid #fff;
    margin-bottom: -1px;
    z-index: 1;
}

.toolbar {
    background-color: #fff;
    padding: 8px 10px;
    display: flex;
    gap: 15px;
    border-bottom: 1px solid #e1dfdd;
    align-items: center;
}

.tool-group {
    display: flex;
    align-items: center;
    gap: 5px;
    border-right: 1px solid #e1dfdd;
    padding-right: 15px;
}

.tool-btn {
    background: transparent;
    border: 1px solid transparent;
    padding: 4px 8px;
    cursor: pointer;
    border-radius: 2px;
}

.tool-btn:hover {
    background-color: #f3f2f1;
    border-color: #c8c6c4;
}

/* Formula Bar */
.formula-bar {
    display: flex;
    align-items: center;
    padding: 4px 10px;
    background-color: #fff;
    border-bottom: 1px solid #d2d0ce;
}

.name-box {
    width: 100px;
    border: 1px solid #c8c6c4;
    padding: 2px 5px;
    text-align: center;
    font-size: 12px;
}

.fx-icon {
    color: #666;
    font-style: italic;
    font-weight: bold;
    margin: 0 10px;
}

.formula-input {
    flex-grow: 1;
    border: 1px solid #c8c6c4;
    padding: 2px 5px;
    outline: none;
    font-size: 13px;
}

/* Spreadsheet Area */
.spreadsheet-container {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.spreadsheet-body {
    display: flex;
    flex-grow: 1;
    overflow: hidden;
    position: relative;
}

.corner-header {
    position: absolute;
    top: 0;
    left: 0;
    width: 30px;
    height: 25px;
    background-color: #f3f2f1;
    border-right: 1px solid #c8c6c4;
    border-bottom: 1px solid #c8c6c4;
    z-index: 3;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 10px;
    color: #a19f9d;
}

.column-headers {
    display: flex;
    margin-left: 30px;
    background-color: #f3f2f1;
    border-bottom: 1px solid #c8c6c4;
    overflow: hidden;
}

.col-header {
    width: 80px; /* Default cell width */
    height: 25px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-right: 1px solid #c8c6c4;
    font-size: 12px;
    color: #333;
    flex-shrink: 0;
}

.grid-content {
    display: flex;
    flex-grow: 1;
    overflow: auto;
    position: relative;
}

.row-headers {
    display: flex;
    flex-direction: column;
    width: 30px;
    background-color: #f3f2f1;
    border-right: 1px solid #c8c6c4;
    overflow: hidden;
    flex-shrink: 0;
}

.row-header {
    height: 25px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-bottom: 1px solid #c8c6c4;
    font-size: 12px;
    color: #333;
}

/* Game Grids positioned like Excel cells */
.sheet-view {
    position: absolute;
    top: 0;
    left: 0;
    /* We align the games inside the dummy grid by just rendering them as grids */
}

.game-grid {
    display: grid;
    background-color: #fff;
    border-top: 1px solid #e1dfdd;
    border-left: 1px solid #e1dfdd;
}

/* Base cell styling to look like Excel */
.excel-cell {
    width: 80px;
    height: 25px;
    border-right: 1px solid #e1dfdd;
    border-bottom: 1px solid #e1dfdd;
    display: flex;
    align-items: center;
    justify-content: flex-end; /* Numbers right-aligned */
    padding: 0 4px;
    font-size: 14px;
    position: relative;
    cursor: cell;
}

.excel-cell.selected {
    border: 2px solid #217346;
    z-index: 10;
}

/* -------------------
   SUDOKU STYLES
   ------------------- */
.sudoku {
    grid-template-columns: repeat(9, 80px);
    grid-template-rows: repeat(9, 25px);
}

.sudoku .excel-cell {
    justify-content: center; /* Center Sudoku numbers */
    font-weight: normal;
    color: #000;
}

.sudoku .excel-cell.fixed {
    color: #333; /* Darker for fixed numbers */
}

.sudoku .excel-cell.user-input {
    color: #0052cc; /* Blue for user input */
    font-weight: bold;
}

/* Thicker borders for 3x3 blocks */
.sudoku .excel-cell:nth-child(3n) { border-right: 2px solid #a19f9d; }
.sudoku .excel-cell:nth-child(9n) { border-right: 1px solid #e1dfdd; } /* reset last col */
.sudoku .excel-cell:nth-child(n+19):nth-child(-n+27),
.sudoku .excel-cell:nth-child(n+46):nth-child(-n+54),
.sudoku .excel-cell:nth-child(n+73):nth-child(-n+81) {
    border-bottom: 2px solid #a19f9d;
}

/* -------------------
   2048 STYLES
   ------------------- */
.g2048 {
    grid-template-columns: repeat(4, 80px);
    grid-template-rows: repeat(4, 25px);
}

.g2048 .excel-cell {
    justify-content: right; /* Numbers right-aligned like money */
    font-weight: normal;
    transition: all 0.1s;
}

/* 2048 Colors disguised as financial data */
.val-2 { color: #333; }
.val-4 { color: #333; font-weight: bold; }
.val-8 { background-color: #fce4d6; } /* Light orange */
.val-16 { background-color: #f8cbad; }
.val-32 { background-color: #f4b084; color: white;}
.val-64 { background-color: #ed7d31; color: white; font-weight: bold;}
.val-128 { background-color: #fff2cc; } /* Light yellow */
.val-256 { background-color: #ffe699; }
.val-512 { background-color: #ffd966; }
.val-1024 { background-color: #e2efda; } /* Light green */
.val-2048 { background-color: #c6e0b4; font-weight: bold;}


/* Bottom Tabs */
.sheet-tabs {
    display: flex;
    flex-direction: column;
    background-color: #f3f2f1;
    border-top: 1px solid #c8c6c4;
}

.tabs-row {
    display: flex;
    align-items: center;
}

.tab-controls {
    padding: 0 10px;
    color: #666;
    font-size: 10px;
    cursor: pointer;
}

.tabs {
    display: flex;
    overflow-x: auto;
}

.tab {
    padding: 5px 20px;
    font-size: 12px;
    cursor: pointer;
    border-right: 1px solid #c8c6c4;
    background-color: #e1dfdd;
    color: #333;
}

.tab.active {
    background-color: #fff;
    color: #217346;
    font-weight: 500;
    border-bottom: 2px solid #217346;
}

.status-bar {
    display: flex;
    padding: 2px 10px;
    font-size: 11px;
    color: #333;
    background-color: #f3f2f1;
    border-top: 1px solid #e1dfdd;
    align-items: center;
}

/* Boss Key Mode (Safe Mode) */
.safe-mode .game-grid {
    display: none !important;
}
.safe-mode .dummy-grid {
    display: block !important;
}
.safe-mode .sheet-view { display: none !important; }

/* In normal mode, dummy grid is a background */
.dummy-grid {
    position: absolute;
    top: 0;
    left: 0; /* Offset removed since row-headers are outside */
    z-index: -1;
    width: 2000px;
    height: 1000px;
    background-image: 
        linear-gradient(to right, #e1dfdd 1px, transparent 1px),
        linear-gradient(to bottom, #e1dfdd 1px, transparent 1px);
    background-size: 80px 25px; /* Matches col/row size */
}

/* Fake Dashboard & Theme Toggle */
.window-controls { display: flex; align-items: center; }
.theme-toggle {
    display: inline-block;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background-color: #0b5028;
    color: #fff;
    text-align: center;
    line-height: 20px;
    font-size: 10px;
    cursor: pointer;
    margin-left: 15px;
    user-select: none;
    border: 1px solid #114a29;
}
.sheet-layout {
    display: flex;
    gap: 80px; /* Aligns to exactly 1 column width */
    padding: 50px 80px; /* Aligns to exactly 2 rows down, 1 column right */
}
.fake-dashboard {
    display: flex;
    flex-direction: column;
    gap: 25px; /* Aligns to exactly 1 row height */
    width: 320px; /* Aligns to exactly 4 columns (80px * 4) */
    font-family: 'Segoe UI', sans-serif;
}
.fake-table {
    display: grid;
    grid-template-columns: 240px 80px; /* 3 cols + 1 col = 4 cols (320px) */
    background-color: transparent;
    font-size: 13px;
    border-top: 1px solid #e1dfdd;
    border-left: 1px solid #e1dfdd;
}
.fake-table-header {
    background-color: #dbe5f1; /* Pivot table blue */
    padding: 0 4px;
    font-weight: bold;
    grid-column: span 2;
    height: 25px;
    display: flex;
    align-items: center;
    border-right: 1px solid #e1dfdd;
    border-bottom: 1px solid #e1dfdd;
    color: #333;
}
.fake-table-cell {
    height: 25px;
    display: flex;
    align-items: center;
    padding: 0 4px;
    background-color: #fff;
    border-right: 1px solid #e1dfdd;
    border-bottom: 1px solid #e1dfdd;
    color: #333;
}
.fake-table-cell.label {
    background-color: #f2f2f2;
}
.fake-table-cell.value {
    justify-content: flex-end; /* Right-aligned numbers/values like Excel */
}
.fake-table-cell.total {
    font-weight: bold;
    background-color: #dbe5f1;
    border-top: 1px solid #95b3d7;
}

.fake-chart {
    background-color: #fff;
    border: 1px solid #e1dfdd;
    padding: 15px;
    /* Chart doesn't need to be cell-aligned, floating is fine */
}
.chart-title {
    font-size: 13px;
    font-weight: bold;
    margin-bottom: 15px;
}
.chart-bars {
    display: flex;
    justify-content: space-around;
    height: 120px;
    align-items: flex-end;
}
.bar-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    height: 100%;
    justify-content: flex-end;
}
.bar {
    width: 30px;
    background-color: #5b9bd5;
    border-radius: 2px 2px 0 0;
    transition: height 0.3s ease;
}
#fake-score-bar {
    background-color: #ed7d31;
}

/* Excel Data Validation Modal */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: transparent; /* No dimming to look like a real OS window */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}
.excel-modal {
    background-color: #fff;
    border: 1px solid #aaa;
    box-shadow: 2px 2px 5px rgba(0,0,0,0.3);
    width: 350px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    flex-direction: column;
}
.modal-header {
    background-color: #fff;
    padding: 5px 10px;
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: #000;
}
.modal-close {
    cursor: pointer;
    font-size: 10px;
    padding: 2px 5px;
}
.modal-close:hover { background-color: #e81123; color: white; }
.modal-content {
    display: flex;
    padding: 20px;
    gap: 15px;
    align-items: center;
}
.modal-icon {
    font-size: 32px;
}
.modal-text {
    font-size: 13px;
    line-height: 1.4;
    color: #333;
}
.modal-buttons {
    background-color: #f0f0f0;
    padding: 10px 15px;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    border-top: 1px solid #dfdfdf;
}
.modal-btn {
    padding: 4px 15px;
    font-size: 12px;
    background-color: #e1e1e1;
    border: 1px solid #adadad;
    cursor: pointer;
}
.modal-btn:hover { background-color: #e5f1fb; border-color: #0078d7; }

/* Dark Mode Overrides */
body.dark-mode {
    background-color: #1e1e1e;
    color: #d4d4d4;
}
body.dark-mode .ribbon, body.dark-mode .menu-tabs, body.dark-mode .toolbar, body.dark-mode .formula-bar,
body.dark-mode .column-headers, body.dark-mode .row-headers, body.dark-mode .corner-header,
body.dark-mode .sheet-tabs, body.dark-mode .status-bar, body.dark-mode .game-grid {
    background-color: #2d2d2d;
    border-color: #444;
    color: #d4d4d4;
}
body.dark-mode .ribbon-top {
    background-color: #114a29;
}
body.dark-mode .menu-tab.active {
    background-color: #1e1e1e;
    color: #4CAF50;
    border-color: #444;
}
body.dark-mode .excel-cell, body.dark-mode .col-header, body.dark-mode .row-header {
    border-color: #444;
    color: #d4d4d4;
}
body.dark-mode .sudoku .excel-cell { color: #d4d4d4; }
body.dark-mode .sudoku .excel-cell.user-input { color: #64b5f6; }
body.dark-mode .tab {
    background-color: #333;
    color: #aaa;
    border-color: #444;
}
body.dark-mode .tab.active {
    background-color: #1e1e1e;
    color: #4CAF50;
}
body.dark-mode .dummy-grid {
    background-image: 
        linear-gradient(to right, #444 1px, transparent 1px),
        linear-gradient(to bottom, #444 1px, transparent 1px);
}
body.dark-mode .fake-table, body.dark-mode .fake-chart { background-color: transparent; border-color: #444; }
body.dark-mode .fake-table-header { background-color: #1a365d; border-color: #444; color: #d4d4d4; }
body.dark-mode .fake-table-cell { border-color: #444; background-color: #2d2d2d; color: #d4d4d4; }
body.dark-mode .fake-table-cell.label { background-color: #333; }
body.dark-mode .fake-table-cell.total { background-color: #1a365d; border-top: 1px solid #2b6cb0; }
body.dark-mode .excel-modal { background-color: #2d2d2d; border-color: #555; }
body.dark-mode .modal-header { background-color: #2d2d2d; color: #d4d4d4; }
body.dark-mode .modal-text { color: #d4d4d4; }
body.dark-mode .modal-buttons { background-color: #333; border-top-color: #555; }
body.dark-mode .modal-btn { background-color: #444; border-color: #666; color: #d4d4d4; }
body.dark-mode .modal-btn:hover { background-color: #555; border-color: #888; }

/* -------------------
   V2.0 STYLES
   ------------------- */
/* 로딩 화면 */
#loading-screen { height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; background: #f3f2f1; }
.logo { font-size: 24px; color: #217346; margin-bottom: 20px; font-weight: 600; }
.progress-container { width: 300px; height: 4px; background: #d2d0ce; margin-top: 20px; }
.progress-bar { width: 0%; height: 100%; background: #217346; animation: load 2.5s forwards ease-in-out; }
@keyframes load { 0% { width: 0%; } 20% { width: 10%; } 50% { width: 60%; } 80% { width: 80%; } 100% { width: 100%; } }
.momentum-text { font-size: 12px; color: #666; margin-top: 10px; }

/* 선언문 박스 (README) - 640px x 350px (8x14 cells) */
.declaration-box { 
    margin: 50px 80px; padding: 50px; border: 1px solid #d2d0ce; background: #fffdf0; 
    box-shadow: 3px 3px 0px #ccc; width: 640px; height: 350px; 
    position: relative;
    display: flex; flex-direction: column; justify-content: center;
}
.declaration-box h3 { color: #217346; margin-bottom: 30px; font-size: 18px; }
.declaration-box .kr { font-size: 15px; margin-bottom: 15px; line-height: 1.5; }
.declaration-box .en { font-style: italic; color: #666; font-size: 13px; line-height: 1.5; }
.declaration-box .stamp { position: absolute; bottom: 30px; right: 30px; border: 2px solid #b00; color: #b00; padding: 5px 10px; transform: rotate(-15deg); font-weight: bold; font-family: serif; letter-spacing: 2px; }

/* 다마고찌 UI (My_Pet) - 480px x 300px (6x12 cells) */
#pet-container { 
    margin: 50px 80px; padding: 40px; text-align: center; border: 1px solid #c8c6c4; background: #fff;
    width: 480px; height: 300px; 
    box-shadow: 2px 2px 5px rgba(0,0,0,0.1);
    display: flex; flex-direction: column; justify-content: center; align-items: center;
}
#pet-avatar { font-size: 60px; margin-bottom: 30px; transition: transform 0.3s; }
#pet-dialogue { background: #f3f2f1; border: 1px solid #e1dfdd; padding: 20px; min-height: 80px; margin-bottom: 30px; border-radius: 4px; width: 100%; display: flex; align-items: center; justify-content: center; }
.pet-buttons { display: flex; justify-content: center; gap: 10px; }

/* 스텔스 광고 위젯 */
.stealth-ad { position: fixed; bottom: 50px; right: 20px; width: 240px; height: 150px; border: 1px solid #2b6cb0; background: #fff; font-size: 11px; z-index: 100; box-shadow: 0 2px 4px rgba(0,0,0,0.2); }
.ad-header { background: #dbe5f1; padding: 5px 10px; font-weight: bold; border-bottom: 1px solid #2b6cb0; display: flex; justify-content: space-between; align-items: center; color: #333; }
.ad-header::after { content: 'i'; display: inline-block; width: 14px; height: 14px; border: 1px solid #2b6cb0; border-radius: 50%; text-align: center; line-height: 12px; font-size: 10px; color: #2b6cb0; cursor: pointer; }
.ad-content { display: flex; justify-content: center; align-items: center; height: 115px; color: #999; }

/* Dark Mode Overrides for V2 */
body.dark-mode #loading-screen { background: #1e1e1e; }
body.dark-mode .progress-container { background: #444; }
body.dark-mode .momentum-text { color: #aaa; }
body.dark-mode .declaration-box { background: #2d2d2d; border-color: #444; box-shadow: 3px 3px 0px #111; }
body.dark-mode .declaration-box h3 { color: #4CAF50; }
body.dark-mode .declaration-box .en { color: #888; }
body.dark-mode .declaration-box .stamp { border-color: #e57373; color: #e57373; }
body.dark-mode #pet-container { background: #2d2d2d; border-color: #444; }
body.dark-mode #pet-dialogue { background: #1e1e1e; border-color: #444; color: #d4d4d4; }
body.dark-mode .stealth-ad { background: #2d2d2d; border-color: #444; }
body.dark-mode .ad-header { background: #1a365d; border-color: #444; color: #d4d4d4; }
body.dark-mode .ad-header::after { border-color: #4CAF50; color: #4CAF50; }

