body {
    font-family: sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: #d7d0c4;
}

.screen {
    display: none;
    /* Hide screens by default */
    width: 100%;
    max-width: 900px;
    /* Max width for content */
    margin: 0 auto;
    /* Center content */
    flex-direction: column;
    /* Children stack vertically */
    align-items: center;
    /* Children centered horizontally */
    justify-content: center;
    /* Default: Center content vertically */
    padding: 20px;
    box-sizing: border-box;
    text-align: center;
    /* Center text within screens */
    flex-grow: 1;
    /* Allow screen to take available space */
}

#intro-screen.active {
    justify-content: flex-start;
    /* Align intro content (incl footer) towards top initially */
}


.screen.active {
    display: flex;
    /* Show active screen using flex */
}

.intro-background-image {
    max-width: 80%;
    /* Adjust as needed */
    height: auto;
    border-radius: 10px;
    margin-bottom: 20px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.intro-text {
    font-size: 1.1em;
    color: #000000;
    margin-bottom: 30px;
    line-height: 1.6;
    max-width: 600px;
    /* Limit text width */
}

.intro-controls button,
.intro-controls .rules-link {
    /* Style link like a button if desired */
    padding: 12px 25px;
    font-size: 1.1em;
    cursor: pointer;
    border-radius: 5px;
    border: 1px solid #888;
    background-color: #e4cfa9;
    /* Match board theme */
    color: #333;
    text-decoration: none;
    /* Remove underline from link */
    margin: 10px;
    display: inline-block;
    /* Allow margins */
    transition: background-color 0.2s ease;
}

.intro-controls .rules-link {
    background-color: #f0f0f0;
    /* Different style for secondary action */
}

.intro-controls button:hover,
.intro-controls .rules-link:hover {
    background-color: #c8a97e;
    /* Darken board theme */
    border-color: #555;
}

.intro-controls .rules-link:hover {
    background-color: #e0e0e0;
    /* Darken secondary */
}


/* --- NEW: Settings Screen Specific Styles --- */
#settings-screen h2 {
    margin-bottom: 20px;
    color: #555;
}

.settings {
    /* Keep existing styles, but ensure they work in the new layout */
    margin-bottom: 20px;
    /* Increased spacing */
    width: auto;
    /* Allow shrinking */
    max-width: 350px;
    /* Limit width */
}

.settings-controls {
    margin-top: 20px;
    display: flex;
    gap: 15px;
    justify-content: center;
}

.settings-controls button {
    padding: 10px 20px;
    font-size: 1em;
    cursor: pointer;
    border-radius: 5px;
    border: 1px solid #888;
    background-color: #f0f0f0;
}

#start-game-button {
    background-color: #a8d8a8;
    /* Greenish for start */
}

#start-game-button:hover {
    background-color: #8fbc8f;
}

#back-to-intro-button {
    background-color: #f0f0f0;
}

#back-to-intro-button:hover {
    background-color: #e0e0e0;
}


/* --- Game Screen Specific Styles --- */
#game-screen {
    /* No specific styles needed unless layout changes */
    justify-content: flex-start;
    /* Align game board to top */
}

#game-board {
    border: 2px solid #333;
    background-color: #e4cfa9;
    /* Wood-like color */
    padding: 10px;
    display: inline-block;
    /* Shrink to content */
    margin: 20px 0;
}

.player-area {
    border: 1px dashed #aaa;
    margin-bottom: 10px;
    padding: 5px;
}

.player-area:last-child {
    margin-bottom: 0;
}

.player-area .info {
    text-align: center;
    font-weight: bold;
    margin-bottom: 5px;
    color: #555;
}

.row {
    display: flex;
    justify-content: center;
    /* Center holes horizontally */
    margin-bottom: 5px;
    /* Space between rows */
}

.row:last-child {
    margin-bottom: 0;
}

.hole {
    width: 60px;
    height: 60px;
    border: 2px solid #6b4f2d;
    /* Darker wood color */
    border-radius: 10px;
    /* Slightly rounded holes */
    margin: 5px;
    background-color: #c8a97e;
    /* Inner hole color */
    position: relative;
    /* For positioning stones */
    display: flex;
    /* Use flexbox for stone container */
    flex-wrap: wrap;
    /* Allow stones to wrap */
    align-content: flex-start;
    /* Start stones at the top */
    padding: 2px;
    /* Small padding inside hole */
    overflow: hidden;
    /* Hide stones overflowing */
    box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
    /* Inner shadow */
}

.hole .hole-index {
    position: absolute;
    top: -18px;
    /* Position above the hole */
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    color: #333;
    background-color: rgba(255, 255, 255, 0.7);
    padding: 1px 3px;
    border-radius: 3px;
    white-space: nowrap;
    /* Prevent wrapping */
}


/* --- Visual Row Ordering --- */

/* Player 2 Home Row (Top): Visually 8 down to 1 */
#player2-area .home-row {
    flex-direction: row-reverse;
    /* Reverses the elements with indices 7 down to 0 */
}

/* Player 2 Fighting Row (Second): Visually 9 up to 16 */
#player2-area .fighting-row {
    /* Default flex-direction: row; is correct */
}

/* Player 1 Fighting Row (Third): Visually 16 down to 9 */
#player1-area .fighting-row {
    flex-direction: row-reverse;
    /* Reverses the elements with indices 8 up to 15 */
}

/* Player 1 Home Row (Bottom): Visually 1 up to 8 */
#player1-area .home-row {
    /* Default flex-direction: row; is correct */
}


.stone {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.3);
    margin: 1px;
    /* Tiny space between stones */
    flex-shrink: 0;
    /* Prevent stones from shrinking */
}

/* Add cursor pointer for clickable holes */
.clickable:hover {
    cursor: pointer;
    border-color: #3498db;
    /* Highlight on hover */
    background-color: #d8ba8e;
}

.clickable.valid-move {
    border-color: #2ecc71;
    /* Green border for valid moves */
}

.player-area.active-player {
    border-color: #e74c3c;
    /* Highlight active player */
    border-style: solid;
}

#message-area {
    margin-top: 15px;
    font-size: 1.2em;
    font-weight: bold;
    color: #c0392b;
    height: 20px;
    /* Reserve space */
    text-align: center;
}


/* Prevent user selection during interaction */
body {
    user-select: none;
    /* Standard */
    -webkit-user-select: none;
    /* Safari */
    -moz-user-select: none;
    /* Firefox */
    -ms-user-select: none;
    /* IE/Edge */
}

.settings {
    margin-bottom: 15px;
    padding: 10px;
    background-color: #eee;
    border-radius: 5px;
    border: 1px solid #ccc;
    display: inline-block;
    /* Allows hiding/showing easily */
    vertical-align: top;
    /* Align settings blocks nicely if side-by-side */
}

/* Style for the depth input area */
#expert-settings label {
    margin-right: 5px;
    /* Adjust spacing */
    font-weight: bold;
}

#expert-settings input[type="number"] {
    width: 50px;
    /* Make number input smaller */
    padding: 5px;
    border: 1px solid #ccc;
    border-radius: 3px;
}

#expert-settings .depth-info {
    font-size: 0.8em;
    color: #666;
    margin-left: 5px;
}

/* Optional styling for the button container */
.controls {
    margin-top: 20px;
    display: flex;
    /* Align buttons side-by-side */
    gap: 15px;
    /* Add space between buttons */
    justify-content: center;
    /* Center buttons horizontally */
}

/* Style for the buttons */
.controls button {
    padding: 10px 20px;
    font-size: 1em;
    cursor: pointer;
    border-radius: 5px;
    border: 1px solid #888;
    background-color: #f0f0f0;
}

.controls button:hover {
    background-color: #e0e0e0;
    border-color: #555;
}

.hint-highlight {
    outline: 4px solid #007bff;
    /* Bright blue outline */
    outline-offset: 1px;
    box-shadow: 0 0 15px rgba(0, 123, 255, 0.7);
    /* Glowing effect */
    border-color: #007bff !important;
    /* Override normal border */
    background-color: #cce5ff;
    /* Light blue background */
    transition: outline 0.2s ease-in-out, box-shadow 0.2s ease-in-out, background-color 0.2s ease-in-out;
}

.legal-footer {
    font-size: xx-small;
    color: grey;
    text-align: center;
    width: 100%;
    /* Takes width of its container */
    max-width: 800px;
    /* Match intro content width */
    padding: 10px 0 5px 0;
    /* Adjust padding */

    /* Remove fixed positioning properties if they exist */
    /* position: fixed; */
    /* bottom: 0; */
    /* left: 0; */
    /* background-color: #e8e8e8; */
    /* z-index: 100; */
    /* border-top: 1px solid #ccc; */

    /* **** ADD margin-top: auto **** */
    margin-top: auto;
    /* Pushes footer to the bottom of the flex container (#intro-screen) */
}




@media (max-width: 768px) {

    /* Adjust breakpoint for tablets/large phones */
    body {
        padding: 10px;
        /* Reduce body padding */
        padding-bottom: 50px;
        /* Keep space for potential fixed elements if added later, or adjust */
    }

    .screen {
        padding: 15px;
        /* Reduce screen padding */
    }

    #intro-screen h1 {
        font-size: 1.8em;
        /* Slightly smaller title */
    }

    .intro-text {
        font-size: 1em;
        /* Adjust intro text size */
        max-width: 95%;
    }

    .intro-controls button,
    .intro-controls .rules-link {
        padding: 10px 20px;
        font-size: 1em;
    }

    .settings {
        padding: 8px;
    }

    .settings-controls button {
        padding: 8px 15px;
        font-size: 0.9em;
    }

    #game-board {
        /* Scaling will be handled below, ensure margin allows centering */
        margin: 15px 0;
    }

    .hole {
        /* Base hole size might need slight reduction even before scaling */
        /* width: 50px; */
        /* height: 50px; */
    }

    .stone {
        /* Base stone size might need slight reduction */
        /* width: 8px; */
        /* height: 8px; */
    }

    #message-area {
        font-size: 1.1em;
    }

    .controls button {
        padding: 8px 15px;
        font-size: 0.9em;
    }

}

@media (max-width: 480px) {

    /* Adjust breakpoint for smaller phones */
    body {
        font-size: 14px;
        /* Adjust base font size for small screens */
    }

    #intro-screen h1 {
        font-size: 1.5em;
    }

    .intro-background-image {
        max-width: 95%;
        /* Allow image to fill more width */
    }

    /* --- Scale down the game board significantly --- */
    #game-board {
        /* Use transform to scale the entire board */
        transform: scale(0.65);
        /* Adjust scale factor as needed */
        /* Adjust origin if needed, default is center */
        /* transform-origin: top center; */
        /* May need negative margin to compensate for scaling space */
        margin: -30px auto;
        /* Adjust margin based on scale factor */
    }

    /* Add margin below the scaled board to push controls down */
    #game-screen.active #game-board {
        margin-bottom: -20px;
        /* Adjust as needed */
    }

    #message-area {
        font-size: 1em;
        margin-top: 0;
        /* Reduce top margin due to scaled board */
    }

    .controls {
        margin-top: 5px;
        /* Reduce top margin */
    }

}

@media (orientation: portrait) and (max-width: 768px),
(orientation: portrait) and (max-height: 768px) {

    /* Only apply when game screen is active */
    #game-screen.active #orientation-warning {
        display: flex;
        /* Show the warning message */
        flex-grow: 1;
        /* Allow it to take space */
    }

    #game-screen.active #game-board,
    #game-screen.active .controls,
    #game-screen.active #message-area {
        display: none;
        /* Hide game elements */
    }
}

/* Styles for LANDSCAPE orientation (Optional: Explicitly reset if needed) */
/* This ensures that if the above rule applied, things go back to normal in landscape */
@media (orientation: landscape) and (max-height: 768px) {
    /* Target landscape on phone-like devices */

    #game-screen.active #orientation-warning {
        display: none;
        /* Ensure warning is hidden */
    }

    /* Ensure game elements are displayed correctly */
    /* Use the original display values */
    #game-screen.active #game-board {
        display: inline-block;
        /* Apply scaling if needed for smaller landscape views too */
        /* Consider a different scale factor for landscape? */
        /* transform: scale(0.8); */
        /* margin: -20px auto; */
    }

    #game-screen.active #message-area {
        display: block;
        /* Or flex, or inline, check its default */
    }

    #game-screen.active .controls {
        display: flex;
    }

    /* Adjust board scale for landscape if needed */
    /* Example: slightly larger scale for landscape */
    @media (max-width: 800px) and (max-height: 500px) {

        /* Example landscape breakpoint */
        #game-screen.active #game-board {
            transform: scale(0.75);
            margin: -25px auto;
            margin-bottom: -15px;
        }

        #message-area {
            font-size: 1em;
            margin-top: 0;
        }

        .controls {
            margin-top: 0;
        }
    }
}