/* =========================================
   APPLE STYLE - iOS DESIGN LANGUAGE
   ========================================= */

:root {
    /* Bảng màu chuẩn iOS */
    --system-bg: #F2F2F7;         /* Nền xám nhạt đặc trưng của iOS */
    --card-bg: #FFFFFF;           /* Nền trắng thẻ */
    --primary-text: #1C1C1E;      /* Chữ đen tuyền */
    --secondary-text: #8E8E93;    /* Chữ xám phụ */
    --apple-blue: #007AFF;        /* Xanh dương tương tác */
    --apple-green: #34C759;       /* Xanh lá thành công */
    --apple-red: #FF3B30;         /* Đỏ cảnh báo */
    
    /* Màu cho bảng Sudoku */
    --grid-line: #D1D1D6;         /* Viền mỏng bên trong (xám nhạt) */
    --grid-thick: #2C2C2E;        /* Viền đậm chia khối (đen xám đậm) */
    
    --cell-highlight: #E5F1FF;    /* Xanh dương rất nhạt cho ô đang chọn */
    --cross-highlight: #F5F5F5;   /* Xám cực nhạt cho khoanh vùng */
    --numpad-bg: #E5E5EA;         /* Màu nút bấm bàn phím */
}

/* --- 1. KHÓA CHẶT MÀN HÌNH (SỬA LỖI IPHONE / SAFARI) --- */
html, body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
    background-color: var(--system-bg);
    color: var(--primary-text);
    -webkit-font-smoothing: antialiased;
    
    margin: 0;
    padding: 0;
    width: 100vw;
    height: 100dvh; /* Lấy chính xác 100% chiều cao thực của trình duyệt điện thoại */
    
    /* Vô hiệu hóa mọi thao tác cuộn, kéo nảy (rubber-band) của điện thoại */
    overflow: hidden; 
    overscroll-behavior: none; 
    touch-action: none; 
    user-select: none; 
    -webkit-user-select: none; 
}

/* --- 2. CẤU TRÚC APP TỰ ĐỘNG CĂN CHỈNH --- */
.screen {
    width: 100%;
    max-width: 420px;
    height: 100%; /* Trải dài toàn bộ màn hình */
    margin: 0 auto; /* Căn giữa theo chiều ngang trên màn hình máy tính */
    padding: 10px 15px 20px 15px; /* Căn lề an toàn */
    box-sizing: border-box;
    display: none;
    
    /* Ép tất cả thành 1 cột và tự động dàn đều vào giữa (Không bị khoảng trắng thừa) */
    flex-direction: column;
    justify-content: center;
}

.screen.active {
    display: flex; /* Bật cấu trúc cột cho màn hình đang hiển thị */
}

/* =========================================
   MÀN HÌNH 1: MENU CHÍNH
   ========================================= */

.brand {
    text-align: center;
    margin-bottom: 32px;
}

.brand .logo-icon {
    font-size: 56px;
    margin-bottom: 8px;
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.1));
}

.brand h1 {
    font-size: 34px;
    font-weight: 800;
    letter-spacing: -0.5px; 
    margin: 0;
}

.brand p {
    color: var(--secondary-text);
    font-size: 17px;
    margin-top: 4px;
}

.menu-box {
    background: var(--card-bg);
    padding: 24px 20px;
    border-radius: 20px; /* Góc bo tròn lớn chuẩn Apple */
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.04); 
}

.divider {
    height: 1px;
    background-color: #E5E5EA;
    margin: 24px 0;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.form-group label {
    font-weight: 600;
    font-size: 15px;
    color: var(--primary-text);
}

.select-wrapper {
    position: relative;
}

.select-wrapper select {
    width: 100%;
    padding: 14px 16px;
    font-size: 17px;
    font-weight: 600;
    color: var(--primary-text);
    background-color: var(--system-bg);
    border: none; 
    border-radius: 12px;
    appearance: none; /* Xóa mũi tên mặc định */
    outline: none;
}

/* Icon mũi tên tuỳ chỉnh */
.select-wrapper::after {
    content: "▼"; 
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--secondary-text);
    font-size: 12px;
    pointer-events: none;
}

/* Nút bấm Menu */
.btn-large {
    width: 100%;
    padding: 16px;
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.4px;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    transition: transform 0.1s, opacity 0.2s;
}

.btn-large:active {
    transform: scale(0.96); /* Lún xuống khi chạm */
    opacity: 0.8;
}

.btn-primary { background-color: var(--apple-blue); color: white; }
.btn-continue { background-color: var(--apple-green); color: white; }

/* =========================================
   MÀN HÌNH 2: BÀN CHƠI GAME
   ========================================= */

/* --- HEADER --- */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding: 0 4px; 
}

.game-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 1.5px;
}

.game-header button {
    background: transparent;
    border: none;
    color: var(--apple-blue);
    font-size: 16px;
    font-weight: 500;
    padding: 8px 0;
    cursor: pointer;
    min-width: 50px; /* Ép 2 nút 2 bên bằng nhau để tiêu đề vào giữa */
}

.game-header button:active { opacity: 0.5; }
#btn-back { text-align: left; }
#btn-solve { text-align: right; }
#btn-back .icon { font-weight: bold; font-size: 18px; margin-right: 2px; }

/* --- BẢNG SUDOKU 9x9 --- */
#sudoku-board {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    
    border: 2.5px solid var(--grid-thick); /* Viền bao ngoài đậm */
    border-radius: 6px; 
    overflow: hidden;
    
    width: 100%;
    aspect-ratio: 1 / 1; /* Ép hình vuông tuyệt đối */
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    background-color: var(--card-bg);
    
    touch-action: none; /* Khóa vuốt trên bảng */
    margin: 0 auto 15px auto; /* Lề dưới nhỏ để nhường chỗ cho phím số */
}

/* Các ô nhỏ bên trong */
.cell {
    width: 100%;
    height: 100%;
    text-align: center;
    font-size: 22px;
    font-family: inherit;
    background-color: var(--card-bg);
    color: var(--apple-blue); 
    font-weight: 500;
    cursor: pointer;
    caret-color: transparent; /* Tắt nháy con trỏ văn bản */
    
    /* Sửa lỗi đẩy khung trên iPhone Safari */
    box-sizing: border-box;
    padding: 0;
    margin: 0;
    -webkit-appearance: none; 
    border-radius: 0;         
    
    /* Kẻ viền mỏng */
    border: none;
    border-right: 1px solid var(--grid-line);
    border-bottom: 1px solid var(--grid-line);
    outline: none;
}

/* Tắt viền mỏng ở cột và hàng cuối cùng */
.cell:nth-child(9n) { border-right: none; }
.cell:nth-last-child(-n+9) { border-bottom: none; }

/* Kẻ viền nét đứt (đậm) để chia khối 3x3 */
.border-right { border-right: 2px solid var(--grid-thick) !important; }
.border-bottom { border-bottom: 2px solid var(--grid-thick) !important; }

/* Trạng thái các ô */
.fixed-cell {
    color: var(--primary-text); 
    font-weight: 600; 
    background-color: var(--card-bg); 
}

.cell.active { background-color: var(--cell-highlight) !important; }
.cell.highlight-cross { background-color: var(--cross-highlight); }
.cell.highlight-number { background-color: #E2E8F0; }


/* --- BÀN PHÍM SỐ (1 DÒNG MOBILE FIRST) --- */
.numpad {
    display: flex; 
    flex-direction: row;
    justify-content: space-between; 
    align-items: center;
    gap: 4px; /* Khe hở rất nhỏ giữa các phím */
    width: 100%;
    margin-top: 5px;
    touch-action: none; /* Khóa vuốt trên bàn phím */
}

.numpad button {
    flex: 1; /* Tự động chia đều 10 phần */
    height: 44px; /* Chiều cao chuẩn dễ bấm */
    font-size: 20px;
    font-family: inherit;
    font-weight: 500;
    border: none;
    border-radius: 8px; 
    background-color: var(--numpad-bg);
    color: var(--primary-text);
    cursor: pointer;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    
    /* Hiệu ứng chuyển mượt mà (dùng cho cả khi bấm và khi ẩn) */
    transition: background-color 0.1s, opacity 0.3s ease, transform 0.3s ease;
}

.numpad button:active {
    background-color: #C7C7CC;
}

/* Nút xóa */
.numpad .clear-btn {
    background-color: transparent;
    color: var(--apple-red);
    font-size: 22px; 
    flex: 1.2; /* Nút xoá rộng hơn xíu */
}

.numpad .clear-btn:active { background-color: #EAEAEB; }

/* Chức năng tàng hình (Khi điền đủ 9 số) */
.numpad button.hidden-btn {
    opacity: 0 !important;
    pointer-events: none; /* Khóa click */
    transform: scale(0.5); /* Thu nhỏ trước khi biến mất */
}
