:root {
    --primary-color: #667eea;
    --secondary-color: #764ba2;
    --bg-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --container-bg: #ffffff;
    --text-color: #333333;
    --grid-border: #333333;
    --cell-bg: #ffffff;
    --cell-hover: #e3f2fd;
    --selected-bg: #2196F3;
    --selected-text: #ffffff;
    --highlight-same: #fff3e0;
    --highlight-related: #f3e5f5;
    --highlight-cage: #ffe0e6;
    --given-bg: #f5f5f5;
    --given-text: #333333;
    --note-color: #757575;
    --error-bg: #ffebee;
    --error-text: #d32f2f;
    --shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
    --primary-color: #764ba2;
    --secondary-color: #667eea;
    --bg-gradient: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    --container-bg: #1f2937;
    --text-color: #f3f4f6;
    --grid-border: #9ca3af;
    --cell-bg: #374151;
    --cell-hover: #4b5563;
    --selected-bg: #60a5fa;
    --selected-text: #ffffff;
    --highlight-same: #4b5563;
    --highlight-related: #374151;
    --highlight-cage: #4c1d1d;
    --given-bg: #374151;
    --given-text: #9ca3af;
    --note-color: #d1d5db;
    --error-bg: #7f1d1d;
    --error-text: #fca5a5;
    --shadow: 0 15px 35px rgba(0, 0, 0, 0.5);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', 'Roboto', sans-serif;
    background: var(--bg-gradient);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px;
    color: var(--text-color);
    transition: background 0.3s ease;
}

.game-container {
    background: var(--container-bg);
    border-radius: 20px;
    box-shadow: var(--shadow);
    padding: 20px;
    max-width: 600px;
    width: 100%;
    text-align: center;
    position: relative;
    transition: background 0.3s ease;
}

.header-controls {
    position: fixed;
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 15px;
    background: var(--container-bg);
    padding: 15px 10px;
    border-radius: 30px;
    box-shadow: var(--shadow);
    z-index: 1000;
}

@media (max-width: 900px) {
    .header-controls {
        position: absolute;
        top: 15px;
        right: 15px;
        transform: none;
        flex-direction: row;
        background: none;
        box-shadow: none;
        padding: 0;
    }
}

.icon-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    transition: transform 0.2s;
}

.icon-btn:hover {
    transform: scale(1.1);
    background: rgba(0, 0, 0, 0.05);
}

h1 {
    color: var(--text-color);
    margin-bottom: 10px;
    font-size: 2.5rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

.game-mode-selector,
.language-switcher {
    margin-bottom: 15px;
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.mode-btn,
.lang-btn {
    padding: 8px 16px;
    border: 2px solid #ddd;
    border-radius: 20px;
    background: var(--container-bg);
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    transition: all 0.3s ease;
    color: var(--text-color);
}

.mode-btn.active,
.lang-btn.active {
    background: linear-gradient(135deg, #FF6B6B, #4ECDC4);
    color: white;
    border-color: transparent;
    transform: scale(1.05);
}

.game-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}

.difficulty-selector {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}

.difficulty-btn {
    padding: 6px 12px;
    border: none;
    border-radius: 15px;
    cursor: pointer;
    font-size: 13px;
    font-weight: bold;
    transition: all 0.3s ease;
    opacity: 0.7;
}

.difficulty-btn.active {
    opacity: 1;
    transform: scale(1.1);
}

.difficulty-btn.easy {
    background: #4CAF50;
    color: white;
}

.difficulty-btn.medium {
    background: #FF9800;
    color: white;
}

.difficulty-btn.hard {
    background: #F44336;
    color: white;
}

.difficulty-btn.expert {
    background: #9C27B0;
    color: white;
}

.timer {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--text-color);
    background: rgba(0, 0, 0, 0.05);
    padding: 8px 16px;
    border-radius: 20px;
}

.sudoku-grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 1px;
    background: var(--grid-border);
    border: 2px solid var(--grid-border);
    border-radius: 8px;
    margin: 20px auto;
    max-width: 450px;
    aspect-ratio: 1;
}

.cell {
    background: var(--cell-bg);
    font-size: 1.5rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    color: var(--text-color);
    user-select: none;
}

/* Notes Grid */
.cell .notes-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.cell .note-num {
    font-size: 0.6rem;
    color: var(--note-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: normal;
}

.cell.given {
    background: var(--given-bg);
    color: var(--given-text);
    font-weight: 900;
}

.cell.selected {
    background: var(--selected-bg) !important;
    color: var(--selected-text);
}

.cell.highlight-same {
    background: var(--highlight-same);
}

.cell.highlight-row-col {
    background: var(--highlight-related);
}

.cell.error {
    background: var(--error-bg) !important;
    color: var(--error-text);
}

/* 3x3 Borders */
.cell:nth-child(3n) {
    border-right: 2px solid var(--grid-border);
}

.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-border);
}

.game-tools {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 15px;
}

.tool-btn {
    padding: 8px 16px;
    border: 1px solid #ddd;
    border-radius: 8px;
    background: var(--container-bg);
    color: var(--text-color);
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s;
}

.tool-btn:hover,
.tool-btn.active {
    background: #e3f2fd;
    border-color: #2196F3;
    color: #1976D2;
}

[data-theme="dark"] .tool-btn:hover,
[data-theme="dark"] .tool-btn.active {
    background: #374151;
    border-color: #60a5fa;
    color: #60a5fa;
}

.number-pad {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 5px;
    margin: 10px auto;
    max-width: 450px;
}

.number-btn {
    padding: 10px 0;
    border: none;
    border-radius: 8px;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    transition: transform 0.2s;
}

.number-btn:hover {
    transform: translateY(-2px);
}

.game-controls {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 20px;
}

.control-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 25px;
    font-weight: bold;
    color: white;
    cursor: pointer;
    transition: transform 0.2s;
}

.control-btn:hover {
    transform: translateY(-2px);
}

.control-btn.new-game {
    background: #4CAF50;
}

.control-btn.hint {
    background: #FF9800;
}

.control-btn.solve {
    background: #9C27B0;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
    background-color: var(--container-bg);
    color: var(--text-color);
    margin: 15% auto;
    padding: 20px;
    border-radius: 10px;
    width: 80%;
    max-width: 500px;
    position: relative;
}

.close-modal {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close-modal:hover {
    color: var(--text-color);
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-top: 20px;
}

.stat-item {
    background: rgba(0, 0, 0, 0.05);
    padding: 15px;
    border-radius: 8px;
    text-align: center;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: bold;
    display: block;
}

.stat-label {
    font-size: 0.9rem;
    opacity: 0.8;
}

/* Settings Modal */
.settings-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 20px;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
}

/* Switch Toggle */
.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
}

input:checked+.slider {
    background-color: var(--primary-color);
}

input:focus+.slider {
    box-shadow: 0 0 1px var(--primary-color);
}

input:checked+.slider:before {
    transform: translateX(24px);
}

.slider.round {
    border-radius: 34px;
}

.slider.round:before {
    border-radius: 50%;
}

@media (max-width: 600px) {
    .number-pad {
        grid-template-columns: repeat(5, 1fr);
    }

    .sudoku-grid {
        font-size: 1.2rem;
    }
}