* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: Arial, sans-serif;
    background-color: #2e2754;
    color: #fff;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    margin: 0;
    padding: 0;
}
#pageLogo {
    height: 36px; /* You can adjust this value as needed */
    width: auto;  /* This will maintain the aspect ratio of your logo */
    display: block; /* Ensures the image behaves as a block element */
    vertical-align: middle; /* Helps with alignment if there were other inline elements */
}
#gameContainer {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    padding: 5px;
    max-width: 1200px;
    margin: 0 auto;
    overflow: hidden;
    position: relative;
}

#header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 9998;
    padding: 8px 10px;
    background-color: rgba(78, 69, 124, 0.8);
    border-radius: 10px;
    margin-bottom: 5px;
    backdrop-filter: blur(10px);
}

#title {
    font-size: clamp(20px, 3vw, 32px);
    font-weight: bold;
}

#helpBtn {
    background-color: #7c5ce6;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    position: relative;
    transition: background-color 0.3s;
}

#helpBtn:hover {
    background-color: #9b7dff;
}

.tooltip {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 10px;
    background-color: rgba(0, 0, 0, 0.95);
    color: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.2);
    display: none;
    z-index: 9999;
    width: 350px;
    max-height: 60vh;
    overflow-y: auto;
}

.tooltip.show {
    display: block;
}

.tooltip h3 {
    margin-bottom: 10px;
    color: #4ecdc4;
}

.tooltip p {
    margin-bottom: 8px;
    line-height: 1.5;
}

#gameInfo {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    background-color: rgba(78, 69, 124, 0.8);
    border-radius: 5px;
    margin-bottom: 5px;
    backdrop-filter: blur(10px);
}

#currentPlayer {
    font-size: clamp(16px, 2vw, 20px);
    font-weight: bold;
    color: #ffd93d;
}

#endTurnBtn {
    padding: 8px 16px;
    font-size: clamp(14px, 1.5vw, 16px);
    cursor: pointer;
    background-color: #7c5ce6;
    color: white;
    border: none;
    border-radius: 5px;
    transition: background-color 0.3s;
}

#endTurnBtn:hover {
    background-color: #9b7dff;
}

#mapContainer {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    overflow: hidden;
    padding: 5px;
    padding-bottom: 80px;
    container-type: size;
}

#map {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
    background-color: rgba(46, 39, 84, 0.6);
    padding: 5px;
    border-radius: 5px;
    width: min(100%, calc(100cqh - 90px));
    height: min(100%, calc(100cqh - 90px));
    aspect-ratio: 1;
    margin: 0 auto;
    backdrop-filter: blur(5px);
}

.territory {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 2px solid #000;
    cursor: pointer;
    transition: all 0.3s ease;
    border-radius: 5px;
    position: relative;
    font-weight: bold;
    overflow: hidden;
    padding: 2px;
}

.territory:hover {
    transform: scale(1.05);
    box-shadow: 0 0 10px rgba(255,255,255,0.3);
    z-index: 10;
}

.territory.selected {
    box-shadow: 0 0 15px rgba(255,255,255,0.8);
    transform: scale(1.1);
    z-index: 20;
}

.territory.attackable {
    border-color: #ffaa00;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% { border-width: 2px; }
    50% { border-width: 4px; }
    100% { border-width: 2px; }
}

.territory.attacking-player1 {
    border-color: #ff6b6b;
    border-width: 4px;
    box-shadow: 0 0 20px rgba(255, 107, 107, 0.8);
    z-index: 30;
}

.territory.attacking-player2 {
    border-color: #f7dc6f;
    border-width: 4px;
    box-shadow: 0 0 20px rgba(247, 220, 111, 0.8);
    z-index: 30;
}

.territory.attacking-player3 {
    border-color: #45b7d1;
    border-width: 4px;
    box-shadow: 0 0 20px rgba(69, 183, 209, 0.8);
    z-index: 30;
}

.territory.attacking-player4 {
    border-color: #8e8e8e;
    border-width: 4px;
    box-shadow: 0 0 20px rgba(142, 142, 142, 0.8);
    z-index: 30;
}

.territory.defending {
    border-color: #ffffff;
    border-width: 4px;
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.8);
    z-index: 30;
}

.dice-count {
    font-size: clamp(20px, 5vmin, 36px);
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
    line-height: 1;
    font-weight: bold;
}

.dice-increment {
    position: absolute;
    bottom: 5px;
    color: #4CAF50;
    font-size: clamp(14px, 3vmin, 20px);
    font-weight: bold;
    animation: fadeUp 8s ease-out forwards;
    pointer-events: none;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
}

@keyframes fadeUp {
    0% {
        opacity: 0;
        transform: translateY(10px);
    }
    5% {
        opacity: 1;
        transform: translateY(0);
    }
    95% {
        opacity: 1;
        transform: translateY(0);
    }
    100% {
        opacity: 0;
        transform: translateY(-10px);
    }
}

.territory-id {
    font-size: clamp(8px, 1vw, 12px);
    opacity: 0.7;
}

.player-stats {
    display: flex;
    gap: 5px;
    padding: 6px;
    background-color: rgba(78, 69, 124, 0.8);
    border-radius: 5px;
    position: fixed;
    bottom: 5px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 20px);
    max-width: 1180px;
    z-index: 50;
    backdrop-filter: blur(10px);
}

.player-stat {
    flex: 1;
    text-align: center;
    padding: 4px 3px;
    border-radius: 5px;
    font-size: clamp(10px, 1.2vw, 12px);
    min-height: 50px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    line-height: 1.2;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.8), -1px -1px 2px rgba(0,0,0,0.8), 1px -1px 2px rgba(0,0,0,0.8), -1px 1px 2px rgba(0,0,0,0.8);
    font-weight: bold;
    cursor: pointer; /* Added for visual feedback on clickable player stat boxes */
}

.player-stat div {
    margin: 1px 0;
    color: #ffffff;
}

#battleResult {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(135deg, rgba(20,20,40,0.98) 0%, rgba(40,20,60,0.98) 100%);
    padding: 0;
    border-radius: 20px;
    display: none;
    z-index: 1000;
    text-align: center;
    box-shadow: 0 0 50px rgba(255,255,255,0.3), inset 0 0 30px rgba(255,255,255,0.1);
    border: 2px solid rgba(255,255,255,0.2);
    width: min(90vw, 500px);
    max-height: 85vh;
    overflow-y: auto;
}

#battleResult h2 {
    background: linear-gradient(90deg, #ff6b6b 0%, #f7dc6f 25%, #45b7d1 50%, #9b7dff 75%, #ff6b6b 100%);
    background-size: 200% 100%;
    animation: gradientShift 3s ease infinite;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    color: transparent;
    font-size: clamp(24px, 5vw, 32px);
    margin: 0;
    padding: 15px 10px;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-weight: bold;
}

@keyframes gradientShift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.battle-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 15px;
    gap: 15px;
}

@media (min-width: 480px) {
    .battle-content {
        flex-direction: row;
        justify-content: space-around;
        align-items: stretch;
        padding: 20px;
    }
}

.battle-player {
    width: 100%;
    max-width: 200px;
    background: rgba(255,255,255,0.05);
    border-radius: 15px;
    padding: 15px;
    border: 1px solid rgba(255,255,255,0.1);
    transition: all 0.3s ease;
}

@media (min-width: 480px) {
    .battle-player {
        flex: 1;
        max-width: none;
    }
}

.battle-player.attacker {
    box-shadow: inset 0 0 20px rgba(255,107,107,0.3);
}

.battle-player.defender {
    box-shadow: inset 0 0 20px rgba(69,183,209,0.3);
}

.battle-player h3 {
    margin: 0 0 10px 0;
    font-size: clamp(16px, 3vw, 20px);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.battle-player.attacker h3 {
    color: #ff6b6b;
    text-shadow: 0 0 15px rgba(255,107,107,0.8);
}

.battle-player.defender h3 {
    color: #45b7d1;
    text-shadow: 0 0 15px rgba(69,183,209,0.8);
}

.dice-container {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 5px;
    margin: 10px 0;
    min-height: 40px;
}

.dice-roll {
    font-size: clamp(28px, 6vw, 40px);
    display: inline-block;
    animation: rollDice 0.5s ease-out;
    background: rgba(255,255,255,0.1);
    border-radius: 8px;
    width: clamp(35px, 8vw, 50px);
    height: clamp(35px, 8vw, 50px);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    line-height: 1;
}

@keyframes rollDice {
    0% { 
        transform: rotate(0deg) scale(0.5);
        opacity: 0;
    }
    50% { 
        transform: rotate(180deg) scale(1.2);
    }
    100% { 
        transform: rotate(360deg) scale(1);
        opacity: 1;
    }
}

.battle-total {
    font-size: clamp(16px, 3vw, 22px);
    font-weight: bold;
    margin-top: 10px;
    padding: 8px;
    background: rgba(255,255,255,0.1);
    border-radius: 8px;
}

.battle-vs {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(20px, 4vw, 28px);
    font-weight: bold;
    color: #ffd93d;
    text-shadow: 0 0 15px rgba(255,217,61,0.8);
    padding: 5px;
    margin: -5px 0;
}

@media (min-width: 480px) {
    .battle-vs {
        padding: 0 10px;
        margin: 0;
    }
}

#battleOutcome {
    background: rgba(0,0,0,0.3);
    padding: 15px;
    border-top: 1px solid rgba(255,255,255,0.2);
}

#battleOutcome h2 {
    margin: 0;
    font-size: clamp(20px, 4vw, 28px);
    text-transform: uppercase;
    letter-spacing: 1px;
    animation: pulseGlow 1s ease-in-out infinite;
}

@keyframes pulseGlow {
    0%, 100% { opacity: 0.8; }
    50% { opacity: 1; }
}

@keyframes fadeInOut {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8);
    }
    20% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    80% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.9);
    }
}

@keyframes zoomIn {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.7);
    }
    100% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

#gameOver {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(0,0,0,0.95);
    padding: 40px;
    border-radius: 10px;
    display: none;
    z-index: 1000;
    text-align: center;
    box-shadow: 0 0 40px rgba(255,255,255,0.5);
}

#newGameBtn, .newGameBtn {
    padding: 15px 30px;
    font-size: 18px;
    cursor: pointer;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 5px;
    transition: background-color 0.3s;
}

#newGameBtn:hover, .newGameBtn:hover {
    background-color: #9b7dff;
}

#reinforcementInfo {
    text-align: center;
    margin-top: 5px;
    opacity: 0.8;
    font-size: clamp(10px, 1.2vw, 12px);
}

.player-stat.active {
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.8);
    transform: scale(1.05);
    border: 2px solid white;
}

.ally-checkbox-container {
    margin-top: 5px;
    display: none;
    align-items: center;
    justify-content: center;
    gap: 5px;
    position: relative;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ally-checkbox-container input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: #4CAF50;
}

.ally-checkbox-container label {
    font-size: clamp(10px, 1.2vw, 12px);
    cursor: pointer;
    color: #ffffff;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
}

.ally-tooltip {
    display: inline-block;
    width: 16px;
    height: 16px;
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    text-align: center;
    line-height: 16px;
    font-size: 10px;
    cursor: help;
    position: relative;
}

.ally-tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    white-space: normal;
    font-size: 12px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    margin-bottom: 5px;
    width: 200px;
    text-align: left;
    line-height: 1.4;
    z-index: 1000;
}

.ally-tooltip:hover::after {
    opacity: 1;
}

.player-stat.allied {
    box-shadow: 0 0 20px rgba(76, 175, 80, 0.6);
    border: 2px solid #4CAF50;
    animation: allyPulse 2s ease-in-out infinite;
}

@keyframes allyPulse {
    0%, 100% {
        box-shadow: 0 0 20px rgba(76, 175, 80, 0.6);
    }
    50% {
        box-shadow: 0 0 30px rgba(76, 175, 80, 0.8);
    }
}

.attack-arrow {
    position: fixed;
    z-index: 999;
    pointer-events: none;
}

@keyframes arrowPulse {
    0%, 100% {
        opacity: 0.8;
        filter: brightness(1);
    }
    50% {
        opacity: 1;
        filter: brightness(1.2);
    }
}

.bot-phrase {
    position: fixed;
    z-index: 10001; 
    animation: phraseAppear 5s ease-out forwards;
}

.chat-bubble-content {
    background-color: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 10px 15px;
    border-radius: 15px;
    font-size: 14px;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
    border: 2px solid;
    border-color: inherit;
    max-width: 200px;
    text-align: center;
}

.chat-bubble-tail {
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 10px solid rgba(0, 0, 0, 0.9);
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
}

@keyframes phraseAppear {
    0% {
        opacity: 0;
        transform: translateX(-50%) translateY(10px);
    }
    20% {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
    80% {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
    100% {
        opacity: 0;
        transform: translateX(-50%) translateY(-10px);
    }
}

#languageSelector {
    background-color: #7c5ce6;
    color: white;
    border: none;
    padding: 8px;
    border-radius: 5px;
    cursor: pointer;
}

/* --- Battle Log Tooltip Styles --- */
.battle-log-tooltip {
    width: 100vw;
    left: 0;
    margin-left: 0;
    margin-right: 0;
    max-height: 50vh;
    overflow-y: auto;
    position: fixed;
    z-index: 10000;
    text-align: left;
    font-size: 13px;
    line-height: 1.5;
    padding: 15px;
    background-color: rgba(0, 0, 0, 0.97);
    border-top: 1px solid rgba(255, 255, 255, 0.15);
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
    border-left: none;
    border-right: none;
    box-shadow: 0 0 25px rgba(255, 255, 255, 0.15);
}

.battle-log-tooltip h3 {
    font-size: 18px;
    color: #50fa7b;
    margin-top: 0;
    margin-bottom: 12px;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
    padding-bottom: 8px;
}

.battle-log-entries {
    /* Styles like max-height and overflow-y are removed for single scrollbar */
}

.battle-log-entries hr {
    border: 0;
    height: 1px;
    background-color: rgba(255, 255, 255, 0.15);
    margin: 10px 0;
}

.battle-log-entries b {
    color: #8be9fd;
    font-weight: bold;
}

#battleLogTooltip {
    display: none;
}
/* --- End Battle Log Tooltip Styles --- */