body {
    font-family: 'Segoe UI', sans-serif;
    background: #f0f2f5;
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    min-height: 100vh;
}

/* --- УПРАВЛЕНИЕ ЭКРАНАМИ --- */
.view {
    display: none;
    width: 100%;
    animation: fadeIn 0.4s;
    padding: 20px;
    box-sizing: border-box;
}

.view.active {
    display: block;
}

.view.hidden {
    display: none;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- ОБЩИЙ СТИЛЬ КАРТОЧЕК --- */
.menu-box,
.result-box,
.board-card,
.sidebar-card {
    background: white;
    padding: 30px;
    border-radius: 24px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.08);
}

/* --- НАЧАЛЬНОЕ МЕНЮ --- */
.menu-box,
.result-box {
    max-width: 460px;
    margin: 30px auto;
    text-align: center;
}

h1 {
    margin-bottom: 30px;
    color: #2c3e50;
    font-size: 1.8rem;
    font-weight: 800;
}

.form-group {
    margin-bottom: 25px;
    text-align: center;
}

.section-label {
    display: block;
    margin-bottom: 12px;
    font-weight: 700;
    color: #444;
    font-size: 1rem;
    text-align: center;
}

/* Плитки */
.tile-selector {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.tile-selector.two-cols {
    grid-template-columns: 1fr 1fr;
}

.tile-option {
    cursor: pointer;
}

.tile-option input {
    display: none;
}

.tile-card {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 12px 10px;
    border: 2px solid #f0f0f0;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    color: #666;
    background: #fff;
    transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
    height: 100%;
    box-sizing: border-box;
}

.tile-option:hover .tile-card {
    border-color: #ddd;
    transform: translateY(-2px);
}

.tile-option input:checked+.tile-card {
    border-color: #333;
    background: #fff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    color: #000;
    transform: translateY(-2px);
}

.tile-option input[value="easy"]:checked+.tile-card {
    border-color: #28a745;
    background: #e6f9ed;
    color: #155724;
}

.tile-option input[value="medium"]:checked+.tile-card {
    border-color: #ffc107;
    background: #fffbe6;
    color: #856404;
}

.tile-option input[value="hard"]:checked+.tile-card {
    border-color: #dc3545;
    background: #fff0f1;
    color: #721c24;
}

.tile-option input[name="timeMode"]:checked+.tile-card {
    border-color: #007bff;
    background: #f0f7ff;
    color: #004085;
}

/* Инпуты и Настройки */
.form-row {
    display: flex;
    gap: 20px;
    margin-bottom: 30px;
}

.small-group {
    flex: 1;
    text-align: center;
}

.input-label {
    font-size: 0.95rem;
    font-weight: 700;
    color: #555;
    display: block;
    margin-bottom: 8px;
    text-align: center;
}

.input-hint {
    font-size: 0.8rem;
    color: #999;
    margin-top: 6px;
    text-align: center;
}

.number-input {
    width: 100%;
    padding: 12px;
    font-size: 1.2rem;
    text-align: center;
    border: 2px solid #eee;
    border-radius: 12px;
    box-sizing: border-box;
    transition: 0.2s;
    font-weight: bold;
    color: #333;
}

.number-input:focus {
    border-color: #28a745;
    outline: none;
    background: #fff;
}

.settings-box {
    text-align: left;
    background: #ffffff;
    border: 1px solid #f0f0f0;
    padding: 20px;
    border-radius: 16px;
    margin-bottom: 30px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.02);
}

.settings-box h3 {
    margin: 0 0 15px 0;
    font-size: 1.1rem;
    color: #444;
    border-bottom: 2px solid #f5f5f5;
    padding-bottom: 10px;
    text-align: center;
}

.settings-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.setting-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: 0.2s;
    font-size: 1rem;
    color: #555;
    background: #f9f9f9;
}

.setting-item:hover {
    background: #f0f0f0;
}

.setting-item input {
    margin-right: 15px;
    transform: scale(1.3);
    cursor: pointer;
    accent-color: #28a745;
}

.big-btn {
    background: linear-gradient(135deg, #28a745, #218838);
    color: white;
    border: none;
    padding: 16px;
    font-size: 1.2rem;
    border-radius: 12px;
    cursor: pointer;
    width: 100%;
    transition: 0.3s;
    font-weight: 700;
    box-shadow: 0 8px 20px rgba(40, 167, 69, 0.25);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.big-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 25px rgba(40, 167, 69, 0.35);
}

.big-btn:active {
    transform: translateY(-1px);
}


/* --- ИГРОВОЙ МАКЕТ (DESKTOP & IPAD LANDSCAPE) --- */
.main-container {
    display: flex;
    flex-wrap: wrap;
    gap: 25px;
    justify-content: center;
    align-items: stretch;
    /* Одинаковая высота */
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
}

/* 1. ДОСКА */
.board-card {
    flex: 1 1 auto;
    width: auto;
    /* Ограничиваем высоту */
    max-width: 85vh;

    display: flex;
    justify-content: center;
    align-items: center;
    background: white;
    padding: 25px;
    border-radius: 24px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.08);
}

.board-wrapper {
    width: 100%;
    touch-action: none;
}

#board {
    width: 100%;
}

/* 2. МЕНЮ СПРАВА */
.sidebar-card {
    /* Фиксированная ширина, но чуть уже, чтобы влезать на iPad 1024px */
    flex: 0 0 340px;
    width: 340px;

    background: white;
    padding: 30px;
    border-radius: 24px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
}

.sidebar-title {
    margin: 0 0 20px 0;
    font-size: 1.1rem;
    font-weight: 800;
    color: #2c3e50;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ПАНЕЛЬ ПРИБОРОВ */
.game-dashboard {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
}

.info-pill,
.status-pill,
.dashboard-actions {
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 12px;
    height: 56px;
    box-sizing: border-box;
}

.timer-pill {
    background: #333;
    color: #fff;
    font-family: 'Courier New', monospace;
    font-weight: 800;
    font-size: 1.3rem;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.icon-spacer {
    margin-right: 10px;
    display: inline-block;
    transform: translateY(-2px);
}

.progress-pill {
    background: #f8f9fa;
    color: #2c3e50;
    border: 2px solid #eee;
    font-weight: 800;
    font-size: 1.2rem;
}

.status-pill {
    background: #e6f7ff;
    color: #0050b3;
    font-weight: 700;
    font-size: 0.9rem;
    text-align: center;
    border: 1px solid #bae7ff;
    line-height: 1.2;
    padding: 0 5px;
}

.dashboard-actions {
    background: transparent;
    padding: 0;
    gap: 8px;
}

.icon-only-btn {
    flex: 1;
    height: 100%;
    border-radius: 12px;
    font-size: 1.4rem;
    cursor: pointer;
    border: none;
    transition: 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
}

.btn-flip {
    background: #f8f9fa;
    border: 2px solid #e9ecef;
}

.btn-flip:hover {
    background: #e2e6ea;
    border-color: #dbe0e5;
}

.btn-skip {
    background: #fff0f1;
    border: 2px solid #fad7d7;
}

.btn-skip:hover {
    background: #fde8e8;
    border-color: #f5c6cb;
}

.task-indicator {
    background: #fff3cd;
    padding: 8px;
    border-radius: 8px;
    font-size: 0.95rem;
    text-align: center;
    margin-bottom: 15px;
    color: #856404;
    border: 1px solid #ffeeba;
}

.game-stats-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin-bottom: 20px;
    font-size: 0.9rem;
    border: 1px solid #f0f0f0;
    border-radius: 12px;
    overflow: hidden;
}

.game-stats-table td {
    padding: 8px 12px;
    border-bottom: 1px solid #f0f0f0;
    color: #444;
}

.game-stats-table tr:last-child td {
    border-bottom: none;
}

.game-stats-table td:first-child {
    text-align: left;
    font-weight: 600;
    background: #fafafa;
    color: #555;
    width: 60%;
}

.game-stats-table td:last-child {
    text-align: center;
    font-weight: 800;
    font-family: monospace;
    font-size: 1.1rem;
    color: #333;
}

.log-container {
    flex-grow: 1;
    overflow-y: auto;
    min-height: 120px;
    border-top: 1px solid #eee;
    margin-top: 0;
    font-size: 0.85rem;
    display: flex;
    background: #fafafa;
    border-radius: 12px;
    border: 1px solid #f0f0f0;
    overflow: hidden;
}

.log-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #eee;
}

.log-col:last-child {
    border-right: none;
}

.log-header {
    background: #f1f1f1;
    text-align: center;
    padding: 6px;
    font-weight: 700;
    color: #555;
    border-bottom: 1px solid #ddd;
    position: sticky;
    top: 0;
}

.log-list {
    flex-grow: 1;
    overflow-y: auto;
    padding: 6px;
    scrollbar-width: thin;
}

.log-item {
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
    padding: 4px 6px;
    border-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
    border: 1px solid #eee;
}

.move-text {
    font-weight: 700;
    font-size: 0.9rem;
    color: #333;
}

.badge {
    padding: 1px 4px;
    border-radius: 3px;
    color: white;
    margin-left: 5px;
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
}

.bg-check {
    background: #dc3545;
}

.bg-capture {
    background: #007bff;
}

.highlight-found {
    box-shadow: inset 0 0 5px 4px #28a745;
}

.hidden {
    display: none !important;
}

/* Результаты */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 25px;
}

.sum-item {
    background: #ffffff;
    padding: 12px;
    border: 2px solid #f5f5f5;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: transform 0.2s;
}

.sum-item:hover {
    transform: translateY(-2px);
    border-color: #eee;
}

.sum-label {
    font-size: 0.8rem;
    color: #888;
    margin-bottom: 5px;
    font-weight: 600;
    text-transform: uppercase;
}

.sum-val {
    font-size: 1.3rem;
    font-weight: 800;
    color: #2c3e50;
}

.error-text {
    color: #dc3545;
}

.stats-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin-bottom: 30px;
    font-size: 0.95rem;
    border: 1px solid #f0f0f0;
    border-radius: 12px;
    overflow: hidden;
}

.stats-table th {
    background: #f9f9f9;
    color: #666;
    font-weight: 700;
    font-size: 0.8rem;
    padding: 12px;
    text-transform: uppercase;
}

.stats-table td {
    padding: 12px;
    border-top: 1px solid #f0f0f0;
    color: #444;
}

.stats-table td:first-child {
    text-align: left;
    font-weight: 600;
    padding-left: 20px;
}

.result-actions {
    display: flex;
    gap: 15px;
    width: 100%;
    justify-content: center;
}

.action-btn {
    flex: 1;
    border: none;
    padding: 16px;
    font-size: 1.1rem;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.action-btn:hover {
    transform: translateY(-3px);
}

.action-btn:active {
    transform: translateY(-1px);
}

.btn-icon {
    font-size: 1.3rem;
    line-height: 1;
    display: inline-block;
    margin-top: -3px;
}

.btn-text {
    display: inline-block;
    line-height: 1;
}

.btn-success {
    background: linear-gradient(135deg, #28a745, #218838);
    color: white;
    box-shadow: 0 8px 20px rgba(40, 167, 69, 0.25);
}

.btn-success:hover {
    box-shadow: 0 12px 25px rgba(40, 167, 69, 0.35);
    filter: brightness(1.05);
}

.btn-primary {
    background: linear-gradient(135deg, #007bff, #0056b3);
    color: white;
    box-shadow: 0 8px 20px rgba(0, 123, 255, 0.25);
}

.btn-primary:hover {
    box-shadow: 0 12px 25px rgba(0, 123, 255, 0.35);
    filter: brightness(1.05);
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    backdrop-filter: blur(3px);
    animation: fadeIn 0.3s;
}

.modal-box {
    background: white;
    padding: 30px;
    border-radius: 20px;
    text-align: center;
    max-width: 90%;
    width: 350px;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.3);
    animation: popIn 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

.modal-box h2 {
    margin: 0 0 10px 0;
    color: #dc3545;
}

.modal-box p {
    color: #555;
    margin: 0;
    font-size: 1.1rem;
}

@keyframes popIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* --- АДАПТИВНОСТЬ: ТОЛЬКО ДЛЯ ТЕЛЕФОНОВ И УЗКИХ ЭКРАНОВ --- */
/* ПЕРЕКЛЮЧЕНИЕ НА 900px. ВСЁ ЧТО ШИРЕ (ВКЛЮЧАЯ IPAD 1024px) БУДЕТ В 2 СТОЛБЦА */
@media (max-width: 900px) {
    .main-container {
        flex-direction: column;
        align-items: center;
        gap: 15px;
        padding-bottom: 20px;
    }

    .board-card {
        flex: none;
        width: 100%;
        max-width: 55vh;
        /* На телефоне высота важнее */
        aspect-ratio: 1 / 1;
        padding: 10px;
    }

    .sidebar-card {
        flex: none;
        width: 100%;
        max-width: 55vh;
        padding: 20px;
        min-height: auto;
        max-height: 40vh;
        overflow-y: auto;
    }

    .log-container {
        height: 120px;
    }

    .result-actions {
        flex-direction: column;
    }

    .action-btn {
        width: 100%;
    }
}

/* Для горизонтальных телефонов */
@media (max-height: 600px) and (orientation: landscape) {
    .board-card {
        max-width: 85vh;
    }

    .sidebar-card {
        max-width: 85vh;
    }
}