* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: calc(var(--vh, 1vh) * 100);
    width: 100%;
    overflow: auto;
    margin: 0;
    padding: 0;
    background: #fff; /* ✨ default = white */
    position: relative;
}

body {
    font-family: Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.container {
    width: 100%; /* ✨ fullscreen on mobile */
    max-height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: #fff;
    text-align: center;
    padding: 20px;
    margin: 0 auto;
    border-radius: 0;
    box-shadow: none;
    margin: 0;
}

/* --- Desktop / large screen framing --- */
@media (min-width: 768px) {
    body {
        background: #f0f0f0; /* ✨ grey only on desktop */
        padding: 0;
    }

    .container {
        width: 600px;   /* adjust as you like */
        height: auto;
        min-height: 80vh;
        border-radius: 10px;
        box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        margin: auto;
    }
}

h1 {
    margin-bottom: 20px;
    color: #333;
}

.game-info {
    margin-bottom: 20px;
}

.target-sums {
    margin-bottom: 10px;
    font-size: 1.2em;
}

.game-meta {
    font-size: 0.85em;
    color: #666;
    margin-bottom: 8px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 3px;
}

.meta-label {
    color: #888;
}

.meta-separator {
    margin: 0 8px;
    color: #ccc;
}

#bestScore {
    font-weight: bold;
    color: #4CAF50;
}

.share-section {
    margin: 20px 0 10px;
    padding: 10px;
    text-align: center;
    font-size: 16px;
    color: #555;
}

.share-section a {
    color: #4267B2; /* Facebook blue */
    text-decoration: none;
    font-weight: bold;
}

.share-section a:hover {
    text-decoration: underline;
}

#storageInfo {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: #f8f8f8;
    border-top: 1px solid #ddd;
    padding: 8px;
    font-size: 13px;
    color: #666;
    text-align: center;
}

.game-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.game-buttons button {
    padding: 10px 15px;
    font-size: 1em;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    display: inline-block;
    margin: 0 3px;
}

#newGame {
    background-color: #4CAF50;
}

#newGame:hover {
    background-color: #45a049;
}

.game-container {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 20px auto;
    width: fit-content;
}

.game-board {
    position: relative;
    overflow: hidden;
    display: grid;
    grid-template-columns: repeat(4, 80px);
    grid-gap: 5px;
}

.tile {
    width: 80px;
    height: 80px;
    background-color: #e0e0e0;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    border-radius: 5px;
    transition: transform 0.2s ease-in-out, background-color 0.3s;
    position: relative;
}

.tile:hover {
    background-color: #d0d0d0;
}

.tile.sliding {
    z-index: 1;
    position: absolute;
    pointer-events: none;
}

.tile.empty {
    background-color: #fff;
    border: 2px dashed #ccc;
}

.tile.fixed {
    background-color: #ffd700;
    cursor: not-allowed;
}

.tile.light-text {
    color: #f2f2f2;
}

.tile.correct-position {
    border: 3px solid #4CAF50;
}

/* Modal styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background-color: #fefefe;
    margin: 10% auto;
    padding: 30px;
    border: none;
    width: 90%;
    max-width: 500px;
    border-radius: 15px;
    position: relative;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    animation: slideIn 0.3s ease-out;
    max-height: 80vh; /* Limit height and enable scrolling */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

@keyframes slideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.close {
    position: absolute;
    right: 20px;
    top: 15px;
    color: #666;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.3s;
}

.close:hover,
.close:focus {
    color: #000;
}

.target-board {
    display: grid;
    grid-template-columns: repeat(4, 70px);
    grid-gap: 5px;
    margin: 20px auto;
    padding: 10px;
    background: #f5f5f5;
    border-radius: 10px;
    width: fit-content;
}

.target-board .tile {
    width: 70px;
    height: 70px;
    font-size: 22px;
    background-color: white;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.target-board .tile.empty {
    background-color: #f0f0f0;
    border: 2px dashed #ccc;
}

.target-board .tile.fixed {
    background-color: #fff3b0;
    border: none;
}

#showTarget {
    background-color: #7f58af;
}

#showTarget:hover {
    background-color: #6a4a94;
}

#showTarget:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
    opacity: 0.7;
}

#showInstructions {
    background-color: #2196F3;
    font-size: 1.2em;
    width: 44px;
    height: 44px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

#showInstructions:hover {
    background-color: #1976D2;
}

/* Instructions modal specific styles */
#instructionsModal .modal-content {
    text-align: left;
    line-height: 1.6;
}

#instructionsModal h2 {
    color: #333;
    margin-bottom: 20px;
    text-align: center;
}

#instructionsModal p {
    margin-bottom: 15px;
    color: #555;
    font-size: 1.1em;
    padding: 0 10px;
}

.game-options {
    padding: 20px;
}

.option-group {
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.option-group label {
    min-width: 80px;
    color: #333;
}

.option-group input[type="date"],
.option-group select {
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1em;
}

#startNewGame {
    width: 100%;
    padding: 10px;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1em;
    margin-top: 10px;
}

#startNewGame:hover {
    background-color: #45a049;
}

.row-sums {
    display: grid;
    grid-template-rows: repeat(4, 80px);
    grid-gap: 5px;
    margin-left: 15px;
}

.row-sums div {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 12px;
}

.column-sums-container {
    display: flex;
    justify-content: flex-start;
    width: fit-content;
    margin: 0 auto;
}

.column-sums {
    display: grid;
    grid-template-columns: repeat(4, 80px);
    grid-gap: 5px;
    margin: 10px 0;
    margin-left: 0;
}

.column-sums div {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 12px;
}

/* --- Mobile tweaks --- */
@media (max-width: 768px) {
    .container {
        padding: 10px;
        padding-top: 30px; /* Add extra space at the top */
    }

    .game-buttons {
        flex-wrap: wrap;
    }

    .game-buttons button {
        margin: 5px;
    }

    .game-board {
        grid-template-columns: repeat(4, 70px);
        grid-gap: 4px;
    }

    .tile {
        width: 70px;
        height: 70px;
        font-size: 22px;
    }

    .row-sums {
        grid-template-rows: repeat(4, 70px);
        grid-gap: 4px;
        margin-left: 10px;
    }

    .column-sums {
        grid-template-columns: repeat(4, 70px);
        grid-gap: 4px;
    }
}

/* Small mobile devices */
@media (max-width: 480px) {
    .container {
        padding: 5px;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }

    .game-board {
        grid-template-columns: repeat(4, 60px);
        grid-gap: 3px;
    }

    .tile {
        width: 60px;
        height: 60px;
        font-size: 20px;
    }

    .row-sums {
        grid-template-rows: repeat(4, 60px);
        grid-gap: 3px;
        margin-left: 8px;
    }

    .column-sums {
        grid-template-columns: repeat(4, 60px);
        grid-gap: 3px;
    }

    .game-meta {
        flex-direction: row;
        justify-content: center;
        gap: 8px;
        flex-wrap: nowrap;
    }

    .meta-separator {
        display: inline;
        margin: 0 3px;
    }

    h1 {
        font-size: 1.5em;
    }

    .modal-content {
        width: 95%;
        padding: 15px;
        margin: 15% auto;
        max-height: 80vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    }
    
    #instructionsModal .modal-content {
        padding: 12px;
    }
    
    #instructionsModal h2 {
        font-size: 1.3em;
        margin-bottom: 12px;
    }
    
    #instructionsModal p {
        font-size: 0.9em;
        margin-bottom: 10px;
        line-height: 1.4;
    }
    
/* Extra small devices */
@media (max-width: 375px) {
    .container {
        padding-top: 40px; /* Even more space for small devices */
    }
    
    h1 {
        margin-bottom: 15px;
    }
    
    /* Special handling for game meta on very small screens */
    .game-meta {
        font-size: 0.8em;
        gap: 5px;
    }
    
    #instructionsModal p {
        font-size: 0.85em;
        padding: 0 5px;
        margin-bottom: 8px;
    }
    
    #instructionsModal h2 {
        font-size: 1.2em;
        margin-bottom: 10px;
    }
    
    .modal-content {
        padding: 12px 10px;
    }
}

    #storageInfo {
        background-color: white;
        border-top: none;
        padding-bottom: env(safe-area-inset-bottom, 8px);
    }
    
    .share-section {
        margin: 15px 0;
        font-size: 14px;
    }
}

/* iPhone models with notches or dynamic islands */
@media only screen and (max-width: 428px) and (min-height: 800px) and (-webkit-min-device-pixel-ratio: 2) {
    .container {
        padding-top: calc(env(safe-area-inset-top) + 35px); /* Additional padding for devices with notches */
    }
    
    h1 {
        margin-top: 5px; /* Extra margin for title */
    }
}

/* Specific fix for Chrome on iOS */
@supports (-webkit-touch-callout: none) and (not (backdrop-filter: none)) {
    body {
        height: auto;
        min-height: -webkit-fill-available;
        overflow-y: auto;
    }
    
    .container {
        padding-top: 50px; /* Extra padding for Chrome on iOS */
        position: relative;
        height: auto;
        min-height: 95vh;
        overflow-y: auto;
    }
    
    h1 {
        margin-top: 10px;
    }
}

html, body {
    height: 100%;
    width: 100%;
    background-color: #fff !important;
    overscroll-behavior: none;
    background-attachment: fixed;
}


