:root {
    --bg-color: #0a0a0a;
    --card-bg: linear-gradient(135deg, #1a1a1a 0%, #151515 100%);
    --text-color: #ffffff;
    --text-secondary: #aaaaaa;
    --accent-color: #70a1ff;
    --danger-color: #ff6b6b;
    --border-color: #333333;
    --cell-bg: #ffffff;
    --cell-text: #000000;
    --cell-active-bg: #f0f8ff;
    --shadow-color: rgba(0, 0, 0, 0.5);
    --theme-toggle-bg: #2a2a2a;
    --theme-toggle-border: #444;
    --modal-bg: linear-gradient(135deg, #1e1e1e 0%, #121212 100%);
    --button-gradient: linear-gradient(135deg, #70a1ff 0%, #5352ed 100%);
    --clear-gradient: linear-gradient(135deg, #ff6b6b 0%, #ee5a24 100%);
    --title-color: #ffffff;
    /* ИСПРАВЛЕНИЕ: цвета ввода и решения */
    --user-input-color: #70a1ff;  /* СИНИЙ для пользовательского ввода */
    --solved-color: #4CAF50;       /* ЗЕЛЕНЫЙ для решения программы */
    --conflict-color: #ff4444;
    --conflict-bg: rgba(255, 68, 68, 0.1);
    --conflict-border: #ff4444;
}

[data-theme="light"] {
    --bg-color: #f5f7fa;
    --card-bg: linear-gradient(135deg, #ffffff 0%, #f0f4f8 100%);
    --text-color: #1a1a1a;
    --text-secondary: #666666;
    --accent-color: #4a6fff;
    --danger-color: #ff4757;
    --border-color: #dddddd;
    --cell-bg: #ffffff;
    --cell-text: #000000;
    --cell-active-bg: #e6f0ff;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --theme-toggle-bg: #ffffff;
    --theme-toggle-border: #ddd;
    --modal-bg: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
    --button-gradient: linear-gradient(135deg, #4a6fff 0%, #3a5fdf 100%);
    --clear-gradient: linear-gradient(135deg, #ff4757 0%, #ff3742 100%);
    --title-color: #000000;
    /* ИСПРАВЛЕНИЕ: цвета ввода и решения (одинаковые в обеих темах) */
    --user-input-color: #4a6fff;   /* СИНИЙ для пользовательского ввода */
    --solved-color: #2E7D32;       /* ЗЕЛЕНЫЙ для решения программы */
    --conflict-bg: rgba(255, 68, 68, 0.15);
    --conflict-border: #ff4444;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'JetBrains Mono', monospace;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background-color 0.3s ease, color 0.3s ease;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    margin: 0;
    touch-action: manipulation;
}

/* Кнопка темы */
.theme-toggle {
    position: fixed;
    top: 12px;
    right: 12px;
    width: 40px;
    height: 40px;
    background: var(--theme-toggle-bg);
    border-radius: 10px;
    border: 2px solid var(--theme-toggle-border);
    cursor: pointer;
    box-shadow: 0 4px 12px var(--shadow-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    z-index: 1000;
    transition: transform 0.2s ease;
    user-select: none;
}

.theme-toggle:hover {
    transform: scale(1.05);
}

.theme-toggle:active {
    transform: scale(0.95);
}

/* Контейнер */
.container {
    width: 100%;
    max-width: 500px;
    height: 100vh;
    max-height: 900px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 16px 30px;
    gap: 20px;
    overflow: hidden;
}

/* Заголовок */
.header {
    text-align: center;
    flex-shrink: 0;
}

.title {
    font-size: clamp(1.8rem, 5vw, 2.5rem);
    font-weight: 800;
    color: var(--title-color);
    letter-spacing: -0.5px;
    margin-bottom: 4px;
}

.subtitle {
    font-size: clamp(0.8rem, 2vw, 0.9rem);
    color: var(--text-secondary);
}

/* Область игры */
.game-area {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    flex: 1;
    justify-content: center;
}

/* Платформа судоку */
.sudoku-platform {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 8px 32px var(--shadow-color);
    border: 1px solid var(--border-color);
    width: 100%;
    max-width: 400px;
}

/* Сетка судоку */
.sudoku-grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 0;
    border: 2px solid var(--border-color);
    background-color: var(--border-color);
    border-radius: 8px;
    width: 100%;
    aspect-ratio: 1;
    max-height: 380px;
}

.sudoku-cell {
    background-color: var(--cell-bg);
    color: var(--cell-text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.2rem, 3vw, 1.8rem);
    font-weight: 600;
    border: 1px solid var(--border-color);
    user-select: none;
    position: relative;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.sudoku-cell.active {
    background-color: var(--cell-active-bg);
    box-shadow: inset 0 0 0 2px var(--accent-color);
    z-index: 1;
}

.sudoku-cell.conflict {
    background-color: var(--conflict-bg) !important;
    border-color: var(--conflict-border) !important;
    color: var(--conflict-color) !important;
}

/* Густые границы для 3x3 блоков */
.sudoku-cell:nth-child(3n):not(:nth-child(9n)) {
    border-right: 2px solid var(--border-color);
}

.sudoku-cell:nth-child(n+19):nth-child(-n+27),
.sudoku-cell:nth-child(n+46):nth-child(-n+54) {
    border-bottom: 2px solid var(--border-color);
}

/* ИСПРАВЛЕНИЕ: цвет пользовательского ввода - СИНИЙ без фона */
.sudoku-cell.user-input {
    color: var(--user-input-color) !important;
    font-weight: 700;
    /* Фон убран */
}

/* ИСПРАВЛЕНИЕ: цвет решенных программой - ЗЕЛЕНЫЙ */
.sudoku-cell.solved {
    color: var(--solved-color) !important;
    font-weight: 700;
}

.cell-input {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    text-align: center;
    font: inherit;
    color: inherit;
    font-weight: inherit;
    cursor: pointer;
    outline: none;
    padding: 0;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    caret-color: transparent;
}

/* Анимация заполнения ячеек (как тополя) */
@keyframes solveAnimation {
    0% {
        opacity: 0;
        transform: scale(0.3) rotate(-5deg);
    }
    50% {
        opacity: 1;
        transform: scale(1.05) rotate(0deg);
    }
    100% {
        opacity: 1;
        transform: scale(1) rotate(0deg);
    }
}

.sudoku-cell.solved-animation {
    animation: solveAnimation 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;
}

/* Виртуальная клавиатура - СКРЫТА ПО УМОЛЧАНИЮ */
.virtual-keyboard {
    display: none;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 400px;
    padding: 0 8px;
    flex-shrink: 0;
}

.virtual-keyboard.show {
    display: flex;
}

.keyboard-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    width: 100%;
}

.number-btn,
.clear-cell-btn {
    width: 100%;
    height: 55px;
    border-radius: 14px;
    font-size: 1.4rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
    box-shadow: 0 6px 16px rgba(0,0,0,0.25);
    user-select: none;
    touch-action: manipulation;
    position: relative;
}

.number-btn {
    background: var(--button-gradient);
    color: white;
}

.clear-cell-btn {
    background: var(--clear-gradient);
    color: white;
    font-size: 1.8rem;
}

.number-btn:active,
.clear-cell-btn:active {
    transform: scale(0.94);
}

/* Контролы */
.controls {
    width: 100%;
    max-width: 400px;
    flex-shrink: 0;
}

.buttons-row {
    display: flex;
    gap: 16px;
    justify-content: center;
}

.solve-btn,
.clear-btn {
    flex: 1;
    padding: 16px 0;
    font-size: 1rem;
    font-weight: 700;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: white;
    min-height: 55px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.25);
    user-select: none;
}

.solve-btn {
    background: var(--button-gradient);
}

.clear-btn {
    background: var(--clear-gradient);
}

.solve-btn:hover,
.clear-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.3);
}

.solve-btn:active,
.clear-btn:active {
    transform: translateY(0);
}

.solve-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

/* Подпись */
.signature {
    font-size: 0.75rem;
    color: var(--text-secondary);
    opacity: 0.8;
    text-align: center;
    margin-top: 8px;
    flex-shrink: 0;
}

/* Модальное окно */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(5px);
}

.modal.show {
    display: flex;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--modal-bg);
    border-radius: 18px;
    width: 100%;
    max-width: 340px;
    overflow: hidden;
    box-shadow: 0 25px 60px rgba(0,0,0,0.6);
    border: 1px solid var(--border-color);
    transform: translateY(20px);
    animation: slideUp 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes slideUp {
    to {
        transform: translateY(0);
    }
}

.modal-header {
    background: var(--button-gradient);
    padding: 20px;
    text-align: center;
    color: white;
    font-weight: 700;
    font-size: 1.2rem;
}

.modal-body {
    padding: 24px 20px;
    text-align: center;
    font-size: 1rem;
    line-height: 1.5;
}

.ok-btn {
    width: 100%;
    padding: 16px;
    background: var(--accent-color);
    color: white;
    border: none;
    font-weight: 700;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.2s ease;
}

.ok-btn:active {
    opacity: 0.9;
}

/* МЕДИА-ЗАПРОСЫ */

/* Мобильные устройства */
@media (max-width: 767px) {
    .container {
        max-height: 700px;
        padding: 50px 12px 20px;
        gap: 16px;
    }
    
    .sudoku-platform {
        max-width: 340px;
        padding: 10px;
    }
    
    .sudoku-grid {
        max-height: 320px;
    }
    
    .sudoku-cell {
        font-size: 1.1rem;
    }
    
    .controls {
        max-width: 340px;
    }
    
    .number-btn,
    .clear-cell-btn {
        height: 50px;
        font-size: 1.3rem;
    }
    
    .clear-cell-btn {
        font-size: 1.6rem;
    }
    
    /* Показываем виртуальную клавиатуру только на мобилках */
    .virtual-keyboard {
        display: flex;
    }
    
    /* Делаем инпуты readOnly чтобы не показывалась системная клавиатура */
    .cell-input {
        pointer-events: auto;
    }
}

/* Очень маленькие экраны */
@media (max-width: 400px) {
    .container {
        padding: 45px 10px 15px;
        gap: 14px;
    }
    
    .title {
        font-size: 1.6rem;
    }
    
    .subtitle {
        font-size: 0.75rem;
    }
    
    .sudoku-platform {
        max-width: 300px;
        padding: 8px;
    }
    
    .sudoku-grid {
        max-height: 280px;
    }
    
    .sudoku-cell {
        font-size: 1rem;
    }
    
    .controls {
        max-width: 300px;
    }
    
    .solve-btn,
    .clear-btn {
        padding: 14px 0;
        font-size: 0.9rem;
        min-height: 50px;
    }
    
    .number-btn,
    .clear-cell-btn {
        height: 48px;
        font-size: 1.2rem;
    }
}

/* ПК версия */
@media (min-width: 768px) {
    .container {
        max-width: 600px;
        max-height: 850px;
        padding: 70px 20px 40px;
        gap: 24px;
    }
    
    .title {
        font-size: 2.8rem;
    }
    
    .subtitle {
        font-size: 1.1rem;
    }
    
    .sudoku-platform {
        max-width: 450px;
        padding: 16px;
        border-radius: 16px;
    }
    
    .sudoku-grid {
        max-height: 400px;
        border-width: 3px;
        border-radius: 10px;
    }
    
    .sudoku-cell {
        font-size: 1.6rem;
    }
    
    .sudoku-cell:nth-child(3n):not(:nth-child(9n)) {
        border-right-width: 3px;
    }
    
    .sudoku-cell:nth-child(n+19):nth-child(-n+27),
    .sudoku-cell:nth-child(n+46):nth-child(-n+54) {
        border-bottom-width: 3px;
    }
    
    /* Виртуальная клавиатура скрыта на ПК */
    .virtual-keyboard {
        display: none !important;
    }
    
    .controls {
        max-width: 450px;
    }
    
    .solve-btn,
    .clear-btn {
        padding: 18px 0;
        font-size: 1.1rem;
        min-height: 60px;
        border-radius: 16px;
    }
    
    .signature {
        font-size: 0.85rem;
    }
}

/* Горизонтальная ориентация */
@media (max-height: 500px) and (orientation: landscape) {
    .container {
        flex-direction: row;
        max-width: 100vw;
        max-height: 100vh;
        padding: 20px;
        gap: 12px;
    }
    
    .header {
        width: 150px;
        text-align: left;
        align-self: flex-start;
        margin-top: 40px;
    }
    
    .title {
        font-size: 1.8rem;
    }
    
    .subtitle {
        font-size: 0.8rem;
    }
    
    .game-area {
        flex: 1;
        max-width: 400px;
        gap: 12px;
    }
    
    .sudoku-platform {
        max-width: 350px;
    }
    
    .sudoku-grid {
        max-height: 300px;
    }
    
    .controls {
        width: 150px;
        max-width: 150px;
        align-self: flex-start;
        margin-top: 40px;
    }
    
    .buttons-row {
        flex-direction: column;
    }
    
    .signature {
        position: absolute;
        bottom: 10px;
        right: 10px;
        margin: 0;
        font-size: 0.7rem;
    }
}

/* Отключение выделения и предотвращение скролла */
* {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

html, body {
    overscroll-behavior: none;
}
