@font-face {
    font-family: 'Dicey';
    src: url('../assets/dicey/Dicey.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

body, html {
    margin: 0;
    padding: 0;
    touch-action: manipulation;
    height: 100%;
}

body {
    font-family: 'Arial', sans-serif;
    background-color: #1a1a1a; /* Dark background */
    color: #e0e0e0; /* Light text */
    margin: 0;
    padding: 0;
    touch-action: manipulation;
}

/* New wrapper for centering content */
.main-content-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - 70px); /* Adjust 70px based on actual header height if needed */
}

.container {
    background-color: #2c2c2c; /* Slightly lighter dark background for container */
    border-radius: 16px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5); /* Adjusted shadow for dark theme */
    padding: 24px;
    width: 100%;
    max-width: 800px; /* Kept max-width, good for landscape tablets */
    /* margin: 0 auto 24px auto; Remove centering margin, wrapper handles it */
    margin-top: 30px;
    margin-bottom: 11px;
}

h1 {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%; /* Make it span the full width */
    background-color: #1f1f1f; /* Slightly different dark background */
    padding: 9px 0 7px;
    z-index: 100; /* Ensure it stays on top */
    text-align: center;
    margin: 0 0 24px 0; /* Remove top/bottom margin, keep bottom */
    color: #8f8f8f; /* Lighter text color */
    font-size: 16px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4); /* Add subtle shadow */
    box-sizing: border-box; /* Include padding in width calculation */
}

.battlefield {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
}

.player {
    width: 48%;
    padding: 16px;
    box-sizing: border-box;
    border-radius: 8px;
    position: relative;
    overflow: hidden;
}

.player .outcome-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -43%);
    width: 100%; /* Adjusted from 100% */
    height: auto;
    pointer-events: none; /* Prevent interaction with the overlay */
    z-index: 10; /* Ensure it's on top */
    /* Consider adding a slight filter if needed for dark theme */
    /* filter: brightness(0.8); */
    opacity: 1; /* Start fully visible */
    transition: opacity 0.6s ease-out; /* Smooth transition for opacity */
    pointer-events: none; /* Let parent handle interaction */
}

/* --- End Added Overlay CSS --- */
.attacker {
    background-color: rgba(255, 100, 100, 0.1); /* Slightly adjusted alpha */
    border: 1px solid rgba(255, 100, 100, 0.3); /* Add subtle border */
}

.defender {
    background-color: rgba(100, 100, 255, 0.1); /* Slightly adjusted alpha */
    border: 1px solid rgba(100, 100, 255, 0.3); /* Add subtle border */
}

.player-label {
    position: relative;
    z-index: 14;
    text-align: center;
    font-size: 24px;
    font-weight: bold;
    margin-bottom: 16px;
}

.player.has-overlay {
    text-align: center;
}

.player.attacker.loser .player-label {
    color: #673434;
}

.player.defender.loser .player-label {
    color: #344667;
}

.player.winner .player-label {
    display: inline-block;
    opacity: 1;
    padding: 4px 10px;
    border-radius: 6px;
    box-shadow: 2px 2px 2px 2px rgba(0, 0, 0, .1);
    color: #fff;
}

.player.attacker.winner .player-label {
    background: #912929;
}

.player.defender.winner .player-label {
    background: #295191;
}

.attacker .player-label {
    color: #ff6464; /* Brighter red for dark theme */
}

.defender .player-label {
    color: #64a0ff; /* Brighter blue for dark theme */
}

.dice-control {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
    align-items: center;
}

.troops-control {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 20px;
}

.troops-counter {
    margin-top: 10px;
    display: flex;
    align-items: center;
}

.troops-label {
    font-size: 18px;
    font-weight: bold;
    margin-right: 10px;
    color: #cccccc; /* Lighter gray */
}

.troops-number {
    font-size: 22px;
    font-weight: bold;
    margin: 0 15px;
    min-width: 30px;
    text-align: center;
}

.original-troops {
    font-size: 14px;
    opacity: 0.6; /* Keep opacity */
    margin-top: 5px;
    color: #aaaaaa; /* Light gray */
}

.dice-set {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    justify-content: center;
}

.dice-placeholder {
    width: 50px;
    height: 50px;
    margin: 5px;
    border-radius: 12px;
    opacity: 0.3;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.3s, transform 0.2s, box-shadow 0.3s;
}

.attacker .dice-placeholder.selected,
.attacker .dice-placeholder.active {
    background-color: #6e2e2e; /* Darker red background */
    border: 1px dashed #ff6464;
}

.dice-placeholder {
    background-color: rgba(255, 255, 255, .15);
    opacity: 0.5;
}

.defender .dice-placeholder.selected,
.defender .dice-placeholder.active {
    background-color: #2e2e6e; /* Darker blue background */
    border: 1px dashed #64a0ff;
}

.dice-placeholder.active {
    opacity: 0.5; /* Adjusted opacity */
    cursor: pointer;
}

.dice-placeholder.selected {
    opacity: 1.0;
    transform: scale(1.1);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.2); /* Lighter shadow */
}

.dice-placeholder.active.selected {
    opacity: 1.0;
    border-style: solid;
}

.dice-area {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    min-height: 100px;
    margin-top: 10px;
    position: relative; /* Ensure z-index is applied */
    z-index: 11; /* Higher than outcome-overlay */
}

button {
    background-color: #555; /* Darker button background */
    color: #ffffff; /* White text */
    border: 1px solid #777; /* Subtle border */
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 18px;
    cursor: pointer;
    transition: background-color 0.3s, transform 0.2s, border-color 0.3s;
    user-select: none;
}

button:active {
    transform: scale(0.95);
}

button:hover {
    background-color: #777; /* Lighter gray on hover */
    border-color: #999;
}

button:disabled {
    background-color: #444; /* Darker disabled state */
    color: #888; /* Dimmed text */
    border-color: #555;
    cursor: not-allowed;
    transform: none;
}

.count-btn {
    width: 40px;
    height: 40px;
    font-size: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
}

.die {
    width: 70px;
    height: 70px;
    margin: 5px;
    background-color: #3e3e3e; /* Darker die background */
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Dicey', Arial, sans-serif; /* Use Dicey font */
    font-size: 48px; /* Adjust size for dice font */
    font-weight: normal; /* Dice font might not need bold */
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4); /* Adjusted shadow */
    position: relative;
    transition: transform 0.5s, box-shadow 0.5s, background-color 0.3s;
    border: 1px solid #555; /* Subtle border */
    line-height: 70px; /* Explicitly match height for centering */
}

.attacker .die {
    background-color: #b33939; /* Different red for attacker die */
    color: white;
    border-color: #d9534f;
}

.defender .die {
    background-color: #3939b3; /* Different blue for defender die */
    color: white;
    border-color: #5353d9;
}

/* Apply specific pulse animations */
.attacker .die.winner {
    animation: pulse-attacker 1.5s infinite;
    box-shadow: 0 0 15px #ff8a8a; /* Light red */
    border-color: #ff8a8a;
}

.defender .die.winner {
    animation: pulse-defender 1.5s infinite;
    box-shadow: 0 0 15px #8a8aff; /* Light blue */
    border-color: #8a8aff;
}

.die.loser {
    opacity: 0.6;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); /* Adjusted shadow */
    background-color: #555; /* Grey out loser */
    border-color: #666;
}

.has-overlay .die.loser {
    opacity: 1;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    background-color: #3d3d3d;
    border-color: #3d3d3d;
}

/* Value-specific die styles for manual positioning */
.die span {
    position: relative;
}

.die.die-val-1 span { /* Corresponds to 'k' */
    top: -5px;
    left: -1px;
}
.die.die-val-2 span { /* Corresponds to 'l' */
    top: -5px;
    left: -1px;
}
.die.die-val-3 span { /* Corresponds to 'm' */
    top: -4px;
    left: 5px;
}
.die.die-val-4 span { /* Corresponds to 'n' */
    top: -5px;
    left: 4px;
}
.die.die-val-5 span { /* Corresponds to 'o' */
    top: -5px;
    left: 5px;
}
.die.die-val-6 span { /* Corresponds to 'p' */
    top: -5px;
    left: 5px;
}

.btn-container {
    display: flex;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
    margin: 20px 0;
}

.roll-btn, .roll-again-btn {
    font-size: 20px;
    padding: 14px 30px;
    background-color: #28a745; /* Green */
    border-color: #1e7e34;
    min-width: 160px;
}

.new-battle-btn {
    font-size: 20px;
    padding: 14px 30px;
    background-color: #ffc107; /* Amber/Yellow */
    color: #1a1a1a; /* Dark text for contrast */
    border-color: #d39e00;
    min-width: 160px;
}

.roll-btn:hover, .roll-again-btn:hover {
    background-color: #218838; /* Darker green */
    border-color: #155724;
}

.new-battle-btn:hover {
    background-color: #e0a800; /* Darker amber */
    border-color: #b38600;
}

.result {
    text-align: center;
    font-size: 24px;
    font-weight: bold;
    margin: 50px 0 20px;
    min-height: 50px;
    color: #e0e0e0; /* Light text */
}

.battle-history {
    margin-top: 30px;
    border-top: 1px solid #555; /* Darker border */
    padding-top: 15px;
}

.battle-history h2 {
    text-align: center;
    font-size: 20px;
    margin-bottom: 15px;
    color: #ffffff; /* White heading */
}

.history-entry {
    padding: 10px;
    background-color: #3a3a3a; /* Darker background for entries */
    border: 1px solid #555; /* Subtle border */
    border-radius: 8px;
    margin-bottom: 10px;
    font-size: 16px;
    color: #cccccc; /* Lighter text */
}

.setup-phase {
    text-align: center;
}

.setup-heading {
    font-size: 22px;
    margin-bottom: 15px;
    color: #ffffff; /* White */
}

.setup-form {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 150px;
    margin-bottom: 20px;
}

.setup-group {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.setup-label {
    font-size: 48px;
    font-weight: bold;
    margin-bottom: 20px;
    color: #cccccc; /* Lighter gray */
}

.setup-input {
    width: 140px;
    height: 50px;
    font-size: 32px;
    text-align: center;
    border: 2px solid #555;
    border-radius: 8px;
    background-color: #444;
    color: #e0e0e0;
}

.attacker-input {
    border-color: #ff6464; /* Keep border color */
}

.defender-input {
    border-color: #64a0ff; /* Keep border color */
}

.start-battle-btn {
    font-size: 20px;
    padding: 15px 30px;
    background-color: #007bff; /* Standard blue */
    border-color: #0056b3;
    min-width: 200px;
    margin-top: 20px;
}

.start-battle-btn:hover {
    background-color: #0056b3; /* Darker blue */
    border-color: #003d80;
}

/* Styles for Preset Buttons */
.preset-buttons {
    display: flex;
    justify-content: center;
    gap: 8px; /* Space between buttons */
    margin-top: 10px;
}

.preset-btn {
    padding: 6px 12px; /* Smaller padding than main buttons */
    font-size: 32px;   /* Smaller font size */
    min-width: 30px;   /* Adjust width as needed */
    background-color: #4a4a4a; /* Slightly different background */
    border: 1px solid #666;
    border-radius: 6px;
    cursor: pointer;
    color: #e0e0e0;
    transition: background-color 0.2s, transform 0.1s;
}

.preset-btn:hover {
    background-color: #5e5e5e;
}

.preset-btn:active {
    transform: scale(0.95);
}

.preset-btn.attacker-preset {
    border-color: rgba(255, 100, 100, 0.5);
}

.preset-btn.defender-preset {
    border-color: rgba(100, 100, 255, 0.5);
}
/* End Preset Button Styles */

.round-casualty-icon {
    width: 48px; /* Adjust size as needed */
    height: 48px;
    vertical-align: middle; /* Align icon with text */
    margin: 0 2px; /* Add small spacing around icon */
    position: relative;
    top: -4px;
}

.dice-rolling {
    animation: rolling 0.5s ease-in-out infinite;
}

.battle-overview .troops-remaining {
    display: flex;
    justify-content: space-between;
    flex-direction: row;
    margin-bottom: 15px; /* Added margin */
}

.battle-overview .troop-icon {
    display: inline-block;
    width: 48px;
    height: 48px;
    margin-left: -7px;
}

.battle-overview .troop-representation {
    width: 48%;
    box-sizing: border-box;
    padding: 12px 17px;
}

.battle-overview .troop-representation.defender .troop-icon {
    float: right;
}

.battle-stats {
    margin-top: 20px;
    display: flex;
    justify-content: space-between;
}

.battle-stats > div {
    width: 48%;
    display: flex;
    box-sizing: border-box;
    padding: 5px 0px; /* Adjusted padding */
    background: none !important;
}

.battle-stats > div > div {
    display: flex;
    align-items: center;
}

.battle-stats > div > div .value {
    font-size: 32px;
    color: #ffffff; /* Ensure stat values are white */
}

.battle-stats > div > div img {
    width: 48px;
    height: 48px;
    display: inline-block;
    margin-right: 2px;
}

.battle-stats > div > div + div {
    margin-left: 10px;
}

.battle-stats > div.defender {
    justify-content: end;
}

@keyframes rolling {
    0% { transform: rotate(0deg); }
    25% { transform: rotate(-5deg); }
    75% { transform: rotate(5deg); }
    100% { transform: rotate(0deg); }
}

/* Define new pulse animations */
@keyframes pulse-attacker {
    0% { box-shadow: 0 0 10px #ff8a8a; }
    50% { box-shadow: 0 0 20px #ff6464, 0 0 30px #ff8a8a; } /* Enhanced red glow */
    100% { box-shadow: 0 0 10px #ff8a8a; }
}

@keyframes pulse-defender {
    0% { box-shadow: 0 0 10px #8a8aff; }
    50% { box-shadow: 0 0 20px #64a0ff, 0 0 30px #8a8aff; } /* Enhanced blue glow */
    100% { box-shadow: 0 0 10px #8a8aff; }
}

/* Prevent text selection on buttons */
* {
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .container {
        padding: 16px; /* Reduce padding on smaller screens */
    }

    .battlefield {
        flex-direction: column;
    }

    .player {
        width: auto;
        margin-bottom: 20px;
        padding: 12px; /* Reduce padding */
    }

    .die {
        width: 50px; /* Smaller dice */
        height: 50px;
        font-size: 36px; /* Adjust size for smaller dice */
        line-height: 50px; /* Match smaller height */
    }

    .dice-placeholder {
        width: 40px; /* Smaller placeholders */
        height: 40px;
        margin: 3px;
        border-radius: 8px;
    }

    .dice-set {
        gap: 5px; /* Reduced gap */
        margin-bottom: 10px;
    }

    .dice-area {
        min-height: 70px; /* Adjust min height */
    }

    .btn-container {
        flex-direction: column;
        align-items: center;
        gap: 10px; /* Reduced gap */
    }

    .roll-btn, .roll-again-btn, .new-battle-btn {
        width: 100%;
        max-width: 250px;
        font-size: 18px; /* Slightly smaller font */
        padding: 12px 20px; /* Adjust padding */
    }

    .setup-form {
        flex-direction: column; /* Stack setup vertically */
        align-items: center;
        gap: 15px;
    }

    .setup-input {
        width: 100px; /* Smaller inputs */
        height: 35px;
        font-size: 16px;
    }

    .start-battle-btn {
        font-size: 18px;
        padding: 12px 25px;
        max-width: 250px;
        width: 100%;
    }

    .battle-overview .troop-representation {
        padding: 8px 12px; /* Adjust padding */
    }

    .battle-stats > div > div .value {
        font-size: 24px; /* Smaller stats */
    }

    .battle-stats > div > div img {
        width: 36px; /* Smaller icons */
        height: 36px;
    }
}

/* Tablet Landscape Specific Adjustments (Optional but good practice) */
@media (min-width: 769px) and (max-width: 1280px) and (orientation: landscape) {
    .container {
        max-width: 95%; /* Allow container to use more width */
    }

    .die {
        width: 60px; /* Slightly smaller dice than desktop */
        height: 60px;
        font-size: 42px; /* Adjust size */
        line-height: 60px; /* Match medium height */
    }

    .die.die-val-1 span { /* Corresponds to 'k' */
        top: -5px;
        left: -1px;
    }
    .die.die-val-2 span { /* Corresponds to 'l' */
        top: -5px;
        left: -1px;
    }
    .die.die-val-3 span { /* Corresponds to 'm' */
        top: -4px;
        left: 5px;
    }
    .die.die-val-4 span { /* Corresponds to 'n' */
        top: -5px;
        left: 4px;
    }
    .die.die-val-5 span { /* Corresponds to 'o' */
        top: -5px;
        left: 5px;
    }
    .die.die-val-6 span { /* Corresponds to 'p' */
        top: -4px;
        left: 5px;
    }

    .dice-placeholder {
        width: 50px;
        height: 50px;
    }

    .battle-stats > div > div .value {
        font-size: 28px; /* Adjust stat size */
    }

     .battle-stats > div > div img {
        width: 40px;
        height: 40px;
    }
}
