:root {
    --primary-color: #FFB74D;
    --secondary-color: #FF8A65;
    --bg-color: #FFF3E0; /* Softer warm background */
    --sidebar-bg: #FFE0B2;
    --text-color: #5D4037;
    --cell-bg: #FFFFFF;
    --cell-border: #E0E0E0;
    --cell-hover: #FFF8E1;
    --cell-selected: #FFE0B2;
    --ice-color: #E1F5FE;
    --ice-border: #81D4FA;
    --success-color: #AED581;
    --tips-color: #CE93D8; /* Light Purple */
    --help-color: #80CBC4; /* Light Teal */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: "Microsoft JhengHei", "Heiti TC", sans-serif;
    user-select: none; /* Prevent text selection during game */
}

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

#app {
    display: flex;
    height: 100%;
    width: 100%;
}

/* Sidebar */
#sidebar {
    width: 25%;
    background-color: var(--sidebar-bg);
    padding: 20px;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 5px rgba(0,0,0,0.1);
    z-index: 100;
    transition: transform 0.3s ease;
}

.menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

.menu-header h2 {
    color: var(--secondary-color);
}

.stats-panel {
    background: #FFFFFF;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.stats-panel p {
    font-size: 1.2rem;
    margin: 10px 0;
    font-weight: bold;
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 5px;
    margin-top: 10px;
    margin-bottom: 30px;
}

.level-btn {
    aspect-ratio: 1;
    border: none;
    background: #fff;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    color: var(--text-color);
    transition: all 0.2s;
}

.level-btn.active {
    background: var(--secondary-color);
    color: white;
}

.level-btn:hover {
    background: var(--primary-color);
    color: white;
}

.controls {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn {
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    font-weight: bold;
    transition: transform 0.1s;
}

.btn:active {
    transform: scale(0.98);
}

.btn.primary { background-color: #FFA726; color: white; }
.btn.warning { background-color: #FF7043; color: white; }
.btn.info { background-color: #4DB6AC; color: white; }
.btn.hint { background-color: #7E57C2; color: white; }
.btn.tips { background-color: #AB47BC; color: white; }
.btn.help { background-color: #26A69A; color: white; }

/* Game Area */
#game-area {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    padding: 20px;
}

#mobile-menu-toggle {
    display: none;
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 50;
    background: var(--primary-color);
    border: none;
    color: white;
    padding: 10px 15px;
    border-radius: 5px;
    font-size: 1.2rem;
    cursor: pointer;
}

#grid-container {
    background: rgba(255,255,255,0.3);
    padding: 10px;
    border-radius: 15px;
    display: grid;
    gap: 8px;
    width: 100%;
    max-width: 600px; /* Max width for PC */
    aspect-ratio: 1;
}

.cell {
    background-color: var(--cell-bg);
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 2px 0 rgba(0,0,0,0.05); /* Flat shadow */
    transition: all 0.1s;
    border: 2px solid var(--cell-border);
    color: var(--text-color);
}

.cell:hover {
    background-color: var(--cell-hover);
    transform: translateY(-1px);
}

.cell.selected {
    background-color: var(--cell-selected);
    border-color: var(--primary-color);
    color: var(--text-color);
    box-shadow: inset 0 0 0 2px var(--primary-color);
}

.cell.tip-highlight {
    color: #AB47BC; /* Purple text for tips */
    font-weight: 900;
    border-color: #AB47BC;
}

.cell.help-highlight {
    background-color: #E0F2F1;
    color: #009688;
    border-color: #009688;
}

.cell.frozen {
    background-color: var(--ice-color);
    border-color: var(--ice-border);
    color: #0277BD;
    cursor: not-allowed;
    position: relative;
    overflow: hidden;
}

.cell.frozen::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="M0,0 L100,100 M100,0 L0,100" stroke="rgba(255,255,255,0.5)" stroke-width="5"/></svg>');
    opacity: 0.5;
}

.cell.solved {
    animation: disappear 0.5s forwards;
}

@keyframes disappear {
    to {
        opacity: 0;
        transform: scale(0);
    }
}

/* Responsive Grid Sizes */
.grid-4x4 { grid-template-columns: repeat(4, 1fr); }
.grid-8x8 { grid-template-columns: repeat(8, 1fr); }
.grid-10x10 { grid-template-columns: repeat(10, 1fr); }

/* Mobile Optimizations */
.mobile-only { display: none; }

@media (max-width: 768px) {
    #sidebar {
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        width: 80%; /* Wider menu on mobile */
        max-width: 300px;
        transform: translateX(-100%);
    }

    #sidebar.open {
        transform: translateX(0);
    }

    #mobile-menu-toggle {
        display: block;
    }

    .mobile-only {
        display: block;
    }

    #close-menu-btn {
        background: none;
        border: none;
        font-size: 2rem;
        cursor: pointer;
        color: var(--text-color);
    }

    .game-header-mobile {
        position: absolute;
        top: 20px;
        right: 20px;
        background: rgba(255,255,255,0.8);
        padding: 5px 10px;
        border-radius: 20px;
        font-size: 0.9rem;
        display: flex;
        gap: 10px;
    }

    #grid-container {
        width: 95%;
        max-width: 95vw;
    }
    
    .cell {
        font-size: 1rem; /* Smaller font for mobile 10x10 */
    }
}

/* Modal */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 200;
}

.modal.hidden { display: none; }

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 15px;
    width: 90%;
    max-width: 500px;
    position: relative;
    text-align: center;
    max-height: 80vh;
    overflow-y: auto;
}

.hint-container {
    text-align: left;
    margin-top: 15px;
}

.hint-item {
    padding: 10px;
    border-bottom: 1px solid #eee;
    font-size: 0.95rem;
    line-height: 1.4;
}

.hint-item:last-child {
    border-bottom: none;
}

.close-modal {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 1.5rem;
    cursor: pointer;
}

#celebration-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 300;
}

#celebration-overlay.hidden { display: none; }

.celebration-content {
    background: white;
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    z-index: 301;
    animation: popIn 0.5s ease;
}

@keyframes popIn {
    0% { transform: scale(0); }
    80% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

#confetti-canvas {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
}
