/* General Page Structure */
body {
    background:
        radial-gradient(circle at 10% 12%, rgba(244, 211, 94, 0.22), transparent 38%),
        radial-gradient(circle at 90% 85%, rgba(29, 120, 116, 0.24), transparent 36%),
        linear-gradient(145deg, #f7fff7, #e7f5f2);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    color: #343a40;
    line-height: 1.6;
}

main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 3rem 2rem;
}

/* Game Section */
#game-section {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    padding: 2.5rem;
    margin-bottom: 3rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.sudoku-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.controls {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
}

.controls label {
    font-weight: 500;
}

select#size {
    font-size: 1rem;
    padding: 0.5rem 0.8rem;
    border-radius: 6px;
    border: 1px solid #ced4da;
}

#newGame, #checkSolution, #computerSolution {
    border: none;
    background: linear-gradient(135deg, #1d7874, #0d3b66);
    color: #ffffff;
    padding: 0.55rem 0.9rem;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#newGame:hover, #checkSolution:hover, #computerSolution:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(13, 59, 102, 0.24);
}

#sudoku-board {
    display: grid;
    --sudoku-board-px: min(92vw, 540px);
    --sudoku-grid-size: 9;
    border: 5px solid #1f2933;
    border-radius: 14px;
    box-shadow: 0 16px 36px rgba(17, 25, 40, 0.14), inset 0 1px 0 rgba(255, 255, 255, 0.7);
    background:
        radial-gradient(circle at 18% 14%, rgba(241, 248, 255, 0.8), transparent 52%),
        linear-gradient(150deg, #ffffff, #f4f7fb);
    max-width: 100%;
    width: 540px;
    height: 540px;
    width: var(--sudoku-board-px);
    height: var(--sudoku-board-px);
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    grid-template-columns: repeat(var(--sudoku-grid-size), 1fr);
    grid-template-rows: repeat(var(--sudoku-grid-size), 1fr);
    overflow: hidden;
}

.sudoku-cell {
    width: 100%;
    height: 100%;
    font-size: 1.1rem;
    font-size: clamp(1rem, 3.35vw, 1.55rem);
    text-align: center;
    border: 1px solid #ced4da;
    outline: none;
    transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
    box-sizing: border-box;
    border-radius: 0;
    touch-action: manipulation;
    color: #1f2933;
    background: rgba(255, 255, 255, 0.96);
    font-weight: 600;
    caret-color: #0d3b66;
    -webkit-appearance: none;
    appearance: none;
}

@supports not (width: var(--sudoku-board-px)) {
    #sudoku-board {
        width: 92vw;
        height: 92vw;
        max-width: 540px;
        max-height: 540px;
    }
}

.sudoku-cell:focus {
    background-color: #edf5ff;
    box-shadow: inset 0 0 0 2px rgba(29, 120, 116, 0.38);
}

.sudoku-cell.fixed {
    background: linear-gradient(145deg, #d4dae2, #c2c9d3);
    font-weight: bold;
    color: #1f2933;
}

.sudoku-cell.fixed:disabled {
    background-color: #bcc3cc;
    color: #1f2933;
    opacity: 1;
    -webkit-text-fill-color: #1f2933;
    cursor: not-allowed;
}

.sudoku-cell.editable {
    background: rgba(255, 255, 255, 0.98);
}

.sudoku-cell.invalid {
    background: #ffe3e3;
    color: #8f1e1e;
    box-shadow: inset 0 0 0 2px rgba(208, 44, 44, 0.34);
}

.sector-top { border-top: 2px solid #343a40; }
.sector-left { border-left: 2px solid #343a40; }
.sector-bottom { border-bottom: 2px solid #343a40; }
.sector-right { border-right: 2px solid #343a40; }

#message {
    font-size: 1.1rem;
    font-weight: 500;
    min-height: 24px;
    width: min(100%, 1000px);
    text-align: center;
    padding: 0 0.5rem;
    box-sizing: border-box;
    overflow-wrap: anywhere;
    word-break: break-word;
    white-space: normal;
    color: #3b4856;
}

/* Internal Navigation / More Games */
.internal-nav {
    text-align: center;
    margin-bottom: 3rem;
}

.internal-nav h3 {
    font-size: 2.5rem;
    font-weight: 600;
    color: #003366;
    margin-top: 0;
    margin-bottom: 2rem;
}

.game-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
}

.game-btn {
    background: #f8f9fa;
    border-radius: 10px;
    text-align: center;
    padding: 1.5rem;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: 1px solid #e9ecef;
    color: #343a40;
    text-decoration: none;
}

.game-btn:hover {
    transform: translateY(-8px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.1);
}

.game-btn img {
    width: 100%;
    height: 180px;
    object-fit: cover;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.game-btn span {
    font-size: 1.3rem;
    font-weight: 600;
}

/* Info Sections & Cards */
.info-section {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    padding: 2.5rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-bottom: 3rem;
}

.info-card.full-width {
    grid-column: 1 / -1;
}

.info-card h2 {
    font-size: 2rem;
    font-weight: 600;
    color: #003366;
    margin-top: 0;
    margin-bottom: 1.5rem;
}

.info-card p, .info-card li, .info-card dd {
    color: #343a40;
}

.info-card ul, .info-card dl {
    padding-left: 20px;
}

.info-card dt {
    font-weight: bold;
    color: #005f9e;
    margin-top: 1rem;
}

/* Responsive Design */
@media (max-width: 992px) {
    .info-section {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    main {
        padding: 2rem 1rem;
    }
    #game-section, .info-section {
        padding: 2rem;
    }
    .internal-nav h3, .info-card h2 {
        font-size: 2rem;
    }
    .sudoku-cell {
        font-size: clamp(1rem, 4.3vw, 1.35rem);
        min-height: 38px;
    }
    .controls {
        flex-direction: column;
        width: 100%;
        gap: 0.75rem;
    }
}

@media (max-width: 540px) {
    #game-section {
        padding: 1.5rem;
    }
    #sudoku-board {
        max-width: 96vw;
        border-width: 4px;
        border-radius: 12px;
    }
    .sudoku-cell {
        font-size: clamp(1rem, 5vw, 1.25rem);
        min-height: 36px;
    }
    #newGame, #checkSolution, #computerSolution {
        width: 100%;
        max-width: 260px;
    }

    #message {
        font-size: 1rem;
        width: 100%;
    }

    .game-difficulty-controls {
        width: 100%;
        justify-content: center;
        gap: 0.5rem;
    }

    .game-difficulty-controls .diff-btn {
        min-width: 88px;
    }
}

@media (orientation: portrait) and (max-width: 480px) {
    #game-section {
        padding: 1.25rem;
    }
    #sudoku-board {
        max-width: 94vw;
    }
    .sudoku-cell {
        font-size: clamp(1rem, 5.4vw, 1.22rem);
    }
    #newGame, #checkSolution, #computerSolution {
        width: 100%;
        max-width: 220px;
    }

    #message {
        width: 100%;
    }
}

@media (orientation: portrait) and (max-width: 430px) {
    #sudoku-board {
        max-width: 92vw;
    }
    .sudoku-cell {
        font-size: clamp(1rem, 5.5vw, 1.2rem);
    }
    #newGame, #checkSolution, #computerSolution {
        max-width: 200px;
    }
}

@media (orientation: landscape) and (max-height: 520px) {
    #game-section {
        padding: 0.85rem;
    }
    #sudoku-board {
        max-width: 94vw;
        border-width: 4px;
        border-radius: 10px;
    }
    .sudoku-cell {
        font-size: min(3.6vw, 3.9vh);
        min-height: 24px;
    }
    #newGame, #checkSolution, #computerSolution {
        width: 100%;
        max-width: 210px;
        padding: 0.45rem 0.7rem;
        font-size: 0.88rem;
    }

    .controls {
        gap: 0.45rem;
    }

    #message {
        font-size: 0.92rem;
        min-height: 18px;
    }
}

@media (orientation: landscape) and (max-height: 430px) {
    .sudoku-container {
        gap: 0.65rem;
    }

    .controls {
        flex-direction: row;
        justify-content: center;
        flex-wrap: wrap;
        gap: 0.35rem;
    }

    .controls label {
        font-size: 0.9rem;
    }

    select#size {
        min-height: 34px;
        padding: 0.35rem 0.55rem;
    }

    .game-difficulty-controls {
        width: auto;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
        gap: 0.35rem;
    }

    .game-difficulty-controls .difficulty-label {
        font-size: 0.78rem;
    }

    .game-difficulty-controls .diff-btn,
    #newGame,
    #checkSolution,
    #computerSolution {
        width: auto;
        min-height: 34px;
        font-size: 0.8rem;
        padding: 0.38rem 0.58rem;
    }
}

@media (max-width: 430px) and (min-height: 780px) {
    #game-section {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }

    #sudoku-board {
        border-radius: 13px;
        box-shadow: 0 14px 30px rgba(17, 25, 40, 0.13), inset 0 1px 0 rgba(255, 255, 255, 0.72);
    }
}

/* iOS Safari compatibility: keep form controls at 16px to prevent zoom on focus. */
@supports (-webkit-touch-callout: none) {
    select#size {
        font-size: 16px;
    }
}

@media (orientation: landscape) and (max-height: 700px) and (min-width: 900px) {
    .intro-header {
        padding: 2.1rem 1rem;
    }

    .intro-text h1 {
        font-size: 2rem;
        margin-bottom: 0.45rem;
    }

    .intro-text p {
        font-size: 1rem;
    }

    main {
        padding-top: 1.6rem;
    }

    #game-section {
        padding: 1.6rem;
    }
}

@media (max-width: 360px) {
    #game-section {
        padding: 1rem;
    }

    .controls {
        gap: 0.55rem;
    }

    select#size {
        font-size: 16px;
        padding: 0.42rem 0.65rem;
    }

    .sudoku-cell {
        font-size: clamp(1rem, 6vw, 1.15rem);
        min-height: 32px;
    }

    #newGame, #checkSolution, #computerSolution {
        max-width: 180px;
        font-size: 0.86rem;
    }
}
