body {
    font-family: Arial, sans-serif;
    background-color: #f4f4f9;
    color: #333;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    padding: 10px;
    box-sizing: border-box;
}

h1 {
    font-size: clamp(1.5em, 5vw, 3em);
    color: #4a90e2;
    margin: 10px 0 20px 0;
    text-align: center;
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(8, minmax(35px, 1fr));
    grid-template-rows: repeat(8, minmax(35px, 1fr));
    gap: 3px;
    max-width: 90vw;
    max-height: 70vh;
    aspect-ratio: 1;
}

.grid-item {
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: white;
    border: 1px solid #ccc;
    border-radius: 3px;
}

.input-field {
    width: 100%;
    height: 100%;
    text-align: center;
    font-size: clamp(12px, 3vw, 16px);
    border: none;
    border-radius: 3px;
    box-sizing: border-box;
    padding: 0;
    -webkit-appearance: none;
    -moz-appearance: textfield;
}

.input-field::-webkit-outer-spin-button,
.input-field::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.input-field:focus {
    outline: 2px solid #4a90e2;
    outline-offset: -2px;
}

.total-field {
    background-color: #f0f0f0;
    color: #666;
}

.solve-button {
    margin-top: 20px;
    padding: 12px 24px;
    font-size: clamp(14px, 4vw, 18px);
    background-color: #4a90e2;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    min-height: 44px;
    min-width: 120px;
    touch-action: manipulation;
}

.solve-button:hover {
    background-color: #357abd;
}

.solve-button:active {
    transform: scale(0.98);
}

.solution-container {
    margin-top: 30px;
    text-align: center;
    max-width: 90vw;
}

.solution-title {
    font-size: clamp(18px, 4vw, 24px);
    color: #4a90e2;
    margin-bottom: 15px;
}

.solution-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(30px, 1fr));
    grid-template-rows: repeat(7, minmax(30px, 1fr));
    gap: 2px;
    justify-content: center;
    margin: 0 auto;
    max-width: 80vw;
    aspect-ratio: 1;
}

.solution-cell {
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: white;
    border: 1px solid #ccc;
    font-size: clamp(10px, 2.5vw, 14px);
    font-weight: bold;
    border-radius: 2px;
}

.solution-cell.selected {
    background-color: #e24a4a;
    color: white;
}

.no-solution {
    font-size: clamp(16px, 4vw, 20px);
    color: #e74c3c;
    font-weight: bold;
}

/* Tablet and larger screens */
@media (min-width: 768px) {
    body {
        justify-content: center;
        padding: 20px;
    }
    .grid-container {
        grid-template-columns: repeat(8, 50px);
        grid-template-rows: repeat(8, 50px);
        gap: 5px;
        max-width: none;
        max-height: none;
    }
    .input-field {
        font-size: 16px;
    }
    .solution-grid {
        grid-template-columns: repeat(7, 40px);
        grid-template-rows: repeat(7, 40px);
        gap: 3px;
        max-width: none;
    }
    .solution-cell {
        font-size: 14px;
    }
}

/* Prevent zoom on iOS */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    select, textarea, input[type="text"], input[type="password"], 
    input[type="datetime"], input[type="datetime-local"], 
    input[type="date"], input[type="month"], input[type="time"], 
    input[type="week"], input[type="number"], input[type="email"], 
    input[type="url"], input[type="search"], input[type="tel"], 
    input[type="color"] {
        font-size: 16px;
    }
}