/* --- Global Styles & Resets --- */
:root {
    --panel-bg-color: rgba(15, 15, 25, 0.75); /* Slightly dark blue tint */
    --panel-border-color: #555;
    --text-primary-color: #eee;
    --text-secondary-color: #ccc;
    --button-bg-color: #444;
    --button-border-color: #777;
    --button-hover-bg-color: #555;
    --scrollbar-thumb-color: #666;
    --scrollbar-track-color: #333;
    --input-bg-color: #333;
    --input-border-color: #555;
    --font-main: 'MedievalSharp', cursive;
    --font-button: 'Press Start 2P', cursive;
}

body {
    margin: 0;
    overflow: hidden;
    background-color: #111; /* Fallback */
    color: var(--text-primary-color);
    font-family: var(--font-main); /* Default font */
}

canvas {
    display: block;
}

/* Generic hidden class */
.hidden {
    display: none !important;
}

/* Scrollbar Styling */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track-color); }
::-webkit-scrollbar-thumb { background-color: var(--scrollbar-thumb-color); border-radius: 4px; }
* { scrollbar-width: thin; scrollbar-color: var(--scrollbar-thumb-color) var(--scrollbar-track-color); }


/* --- Loading Screen Styles --- */
#loading-screen { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-image: linear-gradient(rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.1)), url('../assets/images/loadingimage.png'); background-size: cover; background-position: center center; background-repeat: no-repeat; background-color: #1a1a2a; z-index: 20; display: flex; flex-direction: column; justify-content: center; align-items: center; color: #eee; font-family: 'MedievalSharp', cursive; transition: opacity 0.5s ease-out; }
#loading-screen.hidden { opacity: 0; pointer-events: none; display: flex !important; }
#loading-title { font-size: 2.5em; margin-bottom: 20px; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5); }
#loading-progress-container { width: 80%; max-width: 500px; height: 30px; background-color: #333; border: 2px solid #888; border-radius: 15px; overflow: hidden; margin-bottom: 15px; box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.5); }
#loading-progress-bar { width: 0%; height: 100%; background: linear-gradient(to right, #6a11cb 0%, #2575fc 100%); border-radius: 13px; transition: width 0.3s ease-out; text-align: center; line-height: 30px; font-size: 1em; color: #fff; font-weight: bold; text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.7); }
#loading-message { font-size: 1.1em; color: #ccc; }
/* --- End Loading Screen Styles --- */

/* Game Container (Canvas Holder) - Layer 1 */
#game-container { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; pointer-events: none; }
#game-container > canvas { pointer-events: auto; }

/* --- In-Game UI Panel Base Style --- */
.ui-panel {
    position: absolute;
    background-color: var(--panel-bg-color);
    border: 1px solid var(--panel-border-color);
    border-radius: 5px;
    color: var(--text-secondary-color);
    z-index: 5; /* Default layer for HUD, History */
    box-sizing: border-box;
}

/* --- HUD --- */
#hud {
    /* Extends .ui-panel */
    top: 10px; left: 10px;
    padding: 8px 12px;
    font-size: 1em;
    min-width: 180px;
    display: none; /* Initially hidden */
    font-family: var(--font-main);
}
#hud p { margin: 4px 0; }
#hud-turn { font-weight: bold; }
#hud-player-role { font-weight: bold; }
#hud button {
    margin-top: 8px; margin-right: 5px;
    padding: 6px 10px;
    font-family: var(--font-button);
    font-size: 0.7em;
    background-color: var(--button-bg-color);
    border: 1px solid var(--button-border-color);
    color: var(--text-primary-color);
    border-radius: 4px;
    cursor: pointer;
}
#hud button:hover { background-color: var(--button-hover-bg-color); }
#hud button:first-of-type { margin-left: 0; }
#hud button:disabled { opacity: 0.5; cursor: default; }

/* --- Global In-Game Buttons --- */
.global-button {
    position: absolute;
    padding: 8px 12px;
    background-color: var(--panel-bg-color);
    border: 1px solid var(--button-border-color);
    color: var(--text-primary-color);
    font-family: var(--font-button);
    font-size: 0.7em;
    cursor: pointer;
    border-radius: 5px;
    z-index: 5;
    text-align: center;
}
.global-button:hover { background-color: var(--button-hover-bg-color); }

#music-toggle-btn { bottom: 10px; right: 10px; }
#music-toggle-btn.off { color: #aaa; background-color: rgba(50, 50, 50, 0.7); }
#main-menu-btn { bottom: 10px; left: 10px; display: none; }

/* --- START MENU STYLES --- */
#menu-container { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: flex; justify-content: center; align-items: center; z-index: 10; background-color: rgba(0, 0, 0, 0.5); opacity: 0; pointer-events: none; transition: opacity 0.5s ease-in; }
#menu-container.visible { opacity: 1; pointer-events: auto; }
#menu { font-family: var(--font-main); background-color: rgba(30, 30, 45, 0.95); padding: 30px; border-radius: 8px; border: 3px solid #888; box-shadow: 0 0 20px rgba(0, 0, 0, 0.5); text-align: left; min-width: 400px; max-width: 550px; width: 90%; color: #ddd; max-height: 90vh; overflow-y: auto; display: flex; flex-direction: column; }
#menu h1 { margin: 0 auto 25px auto; padding-bottom: 15px; border-bottom: 2px solid #666; color: #eee; font-size: 2.8em; text-align: center; width: 100%; font-family: var(--font-main); }
.menu-nav { list-style: none; padding: 0; margin: 0 0 20px 0; }
.menu-nav-item { padding: 12px 10px; font-size: 1.4em; cursor: pointer; color: #ccc; border-radius: 4px; transition: background-color 0.2s ease, color 0.2s ease; margin-bottom: 5px; display: flex; align-items: center; position: relative; }
.menu-nav-item:hover { background-color: rgba(255, 255, 255, 0.1); color: #fff; }
.menu-nav-item.selected { background-color: rgba(255, 255, 255, 0.2); color: #fff; font-weight: bold; }
.menu-nav-item .selector { display: inline-block; width: 20px; margin-right: 10px; text-align: center; font-family: sans-serif; opacity: 0; transition: opacity 0.2s ease; }
.menu-nav-item.selected .selector { opacity: 1; }
.submenu { margin-left: 30px; padding-left: 15px; border-left: 1px dashed #555; margin-top: 5px; margin-bottom: 15px; max-height: 0; overflow: hidden; transition: max-height 0.4s ease-out; }
.submenu.visible { max-height: 1000px; }
.submenu ul { list-style: none; padding: 0; margin: 0; }
.submenu-item { padding: 8px 5px; font-size: 1.1em; color: #bbb; cursor: pointer; border-radius: 3px; transition: background-color 0.2s ease, color 0.2s ease; display: block; }
.submenu-item:hover { background-color: rgba(255, 255, 255, 0.08); color: #eee; }
.submenu-item.selected-content { background-color: rgba(255, 255, 255, 0.1); color: #eee; font-weight: bold; }
/* Content Inside Submenus */
.submenu-content { padding: 15px; margin-top: 8px; margin-bottom: 8px; border-radius: 4px; }
.submenu-content h3 { margin-top: 0; margin-bottom: 15px; font-size: 1.2em; color: #ddd; text-align: center; border-bottom: 1px solid #555; padding-bottom: 8px; }
.submenu-content h4 {
     margin-top: 10px; margin-bottom: 10px; font-size: 1.1em; color: #ccc;
     border-bottom: 1px dashed #666; padding-bottom: 5px;
 }
 .submenu-content hr {
      border: none; border-top: 1px solid #555; margin: 25px 0 15px 0;
  }
.submenu-content label { display: block; margin: 10px 0 3px; color: #bbb; font-size: 0.9em; }
.submenu-content select,
.submenu-content input[type="email"],
.submenu-content input[type="text"],
.submenu-content input[type="number"] {
    font-family: var(--font-main);
    width: 100%; padding: 8px 10px; margin-bottom: 12px;
    border: 1px solid var(--input-border-color); border-radius: 4px;
    background-color: var(--input-bg-color); color: var(--text-primary-color);
    font-size: 1em; box-sizing: border-box;
}
.submenu-content button {
     padding: 10px 15px; font-size: 1em; cursor: pointer; font-family: var(--font-main);
     background-color: var(--button-bg-color); border: 1px solid var(--button-border-color); color: var(--text-primary-color);
     border-radius: 5px; display: block; width: auto;
     margin: 10px auto 5px auto; text-align: center;
}
.submenu-content button:hover { background-color: var(--button-hover-bg-color); }
.submenu-content button:disabled { opacity: 0.5; cursor: default; }

.submenu-content .action-button {
     padding: 10px 20px; font-size: 1.1em; cursor: pointer; font-family: var(--font-main);
     background-color: #555; border: 1px solid #888; color: var(--text-primary-color); border-radius: 5px;
     display: block; width: 80%; margin: 20px auto 5px auto; text-align: center;
}
 .submenu-content .action-button:hover { background-color: #6a6a6a; }
 .submenu-content .image-button { padding: 0; border: none; background: none; cursor: pointer; display: block; margin: 20px auto 5px auto; }
 .submenu-content .image-button img { display: block; width: 150px; height: auto; transition: filter 0.2s ease; }
 .submenu-content .image-button:hover img { filter: brightness(1.3) drop-shadow(0 0 5px #fff); }
 /* Online Options Specific Styles */
 #online-options-content input[type="email"] { width: calc(100% - 145px); margin-right: 5px; vertical-align: middle; }
 #online-options-content input[type="text"] { width: calc(100% - 95px); margin-right: 5px; vertical-align: middle; }
 #online-options-content button {
     padding: 8px 10px; font-size: 0.9em; background-color: #4a4a4a; border: 1px solid #777;
     vertical-align: middle; margin-top: 5px; font-family: var(--font-main); color: var(--text-primary-color);
     cursor: pointer;
 }
 #online-options-content button:hover { background-color: #5a5a5a; }
 #game-link-area { margin-top: 15px; background-color: #2a2a3a; padding: 10px; border-radius: 4px; display: none; }
 #game-link-area p { margin: 0 0 8px 0; font-size: 0.9em; }
 #game-link-display { background-color: #444; padding: 8px; border-radius: 3px; word-wrap: break-word; margin-bottom: 8px; font-family: monospace; font-size: 0.9em; color: #eee; }
 #game-link-area button { vertical-align: baseline; margin-left: 5px; }
 .submenu-status { font-size: 0.9em; min-height: 1.2em; margin-top: 15px; color: #ffcc00; text-align: center; }

 /* Tournament Styles */
 #tournament-create-section button,
 #tournament-join-section button {
      width: 100%;
  }


/* Settings Submenu */
.setting-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 5px; font-size: 1.1em; color: #bbb; margin-bottom: 5px; }
.setting-item label { margin-right: 15px; }
.setting-item button, .setting-item select {
    font-family: var(--font-main); background-color: var(--button-bg-color); border: 1px solid var(--button-border-color);
    color: var(--text-primary-color); padding: 5px 10px; font-size: 0.9em; border-radius: 4px; cursor: pointer;
}
.setting-item button:hover, .setting-item select:hover { background-color: var(--button-hover-bg-color); }
.setting-item .current-value { font-weight: bold; color: #ddd; min-width: 50px; text-align: right; }
.settings-control { min-width: 100px; text-align: center; }
/* Rules Content */
#rules-content { text-align: left; padding: 15px; margin-top: 5px; margin-bottom: 15px; border-radius: 4px; max-height: 45vh; overflow-y: auto; color: var(--text-secondary-color); font-size: 0.95em; line-height: 1.5; flex-shrink: 0; }
#rules-content h3 { font-family: var(--font-main); font-size: 1.1em; margin-top: 12px; margin-bottom: 6px; color: var(--text-primary-color); border-bottom: 1px dashed #777; padding-bottom: 3px; }
#rules-content h3:first-of-type { margin-top: 0; }
#rules-content p { margin-bottom: 8px; }
#rules-content strong { color: #ddd; font-weight: normal; }
#rules-content ul { list-style: none; padding-left: 15px; }
#rules-content li { margin-bottom: 5px; }
.rules-example { font-family: monospace; background-color: rgba(0,0,0,0.3); padding: 5px 8px; border-radius: 3px; margin: 5px 0 10px 10px; display: inline-block; white-space: pre; }
/* Menu Footer */
#menu-footer { font-family: var(--font-main); font-size: 0.8em; color: #888; text-align: center; margin-top: auto; padding-top: 15px; border-top: 1px solid #444; width: 100%; box-sizing: border-box; }
#menu-footer a { color: #aaa; text-decoration: none; }
#menu-footer a:hover { color: #ddd; text-decoration: underline; }
/* --- END MENU STYLES --- */

/* --- Chat UI --- */
#chat-container {
    /* Extends .ui-panel */
    bottom: 50px; left: 10px;
    width: 300px; max-width: 45%;
    height: 150px;
    z-index: 6;
    display: none; /* Initially hidden */
    flex-direction: column;
}
#chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 8px;
    color: var(--text-secondary-color);
    font-family: var(--font-main);
    font-size: 0.9em;
    line-height: 1.4;
}
#chat-messages p { margin: 0 0 4px 0; word-wrap: break-word; }
#chat-messages .sender-attacker { color: #FFaaaa; }
#chat-messages .sender-defender { color: #aaccff; }
#chat-messages .sender-system { color: #ffff99; font-style: italic; }
#chat-messages .sender-lobby { color: #ccddaa; }
#chat-input-container { display: flex; border-top: 1px solid var(--panel-border-color); }
#chat-input {
    flex-grow: 1; padding: 8px; border: none;
    background-color: rgba(50, 50, 50, 0.8);
    color: var(--text-primary-color);
    font-family: var(--font-main);
    font-size: 0.9em; outline: none; box-sizing: border-box;
    border-bottom-left-radius: 5px;
}

/* --- Move History UI --- */
#move-history-container {
    position: absolute; top: 10px; right: 10px;
    width: 250px; max-width: 40%;
    z-index: 5;
    display: flex; flex-direction: column; align-items: flex-end;
}
#move-history-toggle-btn {
    /* Extends .global-button */
    width: 100%;
    margin-bottom: 5px;
    display: none; /* Initially hidden */
    box-sizing: border-box;
}
#move-history-panel {
    /* Extends .ui-panel */
    width: 100%;
    max-height: 200px;
    display: none; /* Initially hidden */
    overflow: hidden;
}
#move-history-content {
    padding: 10px;
    font-family: var(--font-main);
    font-size: 0.9em;
    line-height: 1.5;
    height: 100%; max-height: inherit;
    overflow-y: auto;
    color: var(--text-secondary-color);
}
#move-history-content p { margin: 0 0 4px 0; word-wrap: break-word; }


/* --- Tournament Lobby Styles --- */
#tournament-lobby-container {
    /* Extends .ui-panel */
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 600px;
    max-width: 90%;
    max-height: 80vh;
    z-index: 15;
    padding: 25px;
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: rgba(20, 15, 35, 0.9);
    border: 2px solid #888;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.4);
    font-family: var(--font-main);
}
#tournament-lobby-container h2 {
     color: #eee; margin-top: 0; margin-bottom: 5px; font-size: 1.8em;
}
#tournament-lobby-id {
     font-size: 0.9em; color: #ccc; margin-bottom: 15px; font-family: monospace;
}
/* Inner container for list and preview */
.lobby-main-content {
    display: flex;
    width: 100%;
    gap: 20px;
    margin-top: 15px;
    margin-bottom: 20px;
    border-top: 1px solid #555;
    border-bottom: 1px solid #555;
    padding: 15px 0;
    flex-grow: 1;
    overflow: hidden;
}
.lobby-player-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 180px;
}
 .lobby-player-section h4 {
     margin-top: 0; margin-bottom: 8px; text-align: center; font-size: 1.1em; color: #ddd;
 }
#tournament-lobby-players {
     list-style: none; padding: 0 10px; margin: 0;
     max-height: 250px;
     overflow-y: auto;
     text-align: left;
     background-color: rgba(0,0,0,0.2);
     border: 1px solid #444;
     border-radius: 3px;
     flex-grow: 1;
 }
 #tournament-lobby-players li {
     padding: 5px 8px; border-bottom: 1px dashed #444; color: var(--text-secondary-color);
 }
  #tournament-lobby-players li:last-child { border-bottom: none; }

/* Bracket Preview Area */
#lobby-bracket-preview {
    flex: 1;
    border: 1px dashed #555;
    background-color: rgba(0,0,0,0.3);
    padding: 10px;
    min-height: 150px;
    max-height: 250px;
    overflow: auto;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #888;
    font-style: italic;
}
#lobby-bracket-preview p { margin: 0; }

#tournament-lobby-host-controls {
     display: none;
     margin-top: 15px; width: 100%; text-align: center;
     flex-shrink: 0;
}
#start-tournament-lobby-btn {
     padding: 10px 20px; font-size: 0.9em; font-family: var(--font-button);
}
#start-tournament-lobby-btn:disabled {
     background-color: #333; border-color: #555; color: #777; cursor: default;
}

#leave-tournament-lobby-btn {
     margin-top: 15px;
     background-color: #883333;
     padding: 8px 15px; font-size: 0.8em; font-family: var(--font-button);
     flex-shrink: 0;
 }
 #leave-tournament-lobby-btn:hover { background-color: #a84444; }

#tournament-lobby-status {
     margin-top: 15px; color: orange; min-height: 1.2em; font-size: 0.9em;
     flex-shrink: 0;
}
/* --- END Tournament Lobby Styles --- */

/* --- Tournament Bracket Styles --- */
#tournament-bracket-container {
    /* Extends .ui-panel */
    position: absolute;
    top: 5%; bottom: 5%; left: 5%; right: 5%;
    z-index: 14;
    padding: 20px;
    display: flex;
    flex-direction: column;
    background-color: rgba(20, 20, 30, 0.9);
    border: 1px solid #888;
}
#tournament-bracket-title {
     text-align: center; margin-bottom: 15px; color: #eee; font-size: 1.8em;
     flex-shrink: 0;
}
#tournament-bracket-rounds {
     flex-grow: 1;
     display: flex;
     flex-wrap: nowrap;
     overflow-x: auto;
     border: 1px solid #444;
     padding: 20px 10px;
     background-color: rgba(10, 10, 15, 0.7);
     border-radius: 5px;
     min-height: 200px;
     align-items: center;
 }
 /* Styles for elements generated by bracket.js */
 .tournament-round {
     display: flex;
     flex-direction: column;
     justify-content: space-around;
     margin: 0 30px;
     min-width: 180px;
     padding: 10px 0;
 }
 .tournament-round h5 {
      text-align: center; color: #ccc; margin-bottom: 10px; font-size: 1em;
 }
 .tournament-match {
      border: 1px solid #666;
      border-radius: 4px;
      padding: 8px 10px;
      margin: 20px 0;
      background-color: rgba(40, 40, 50, 0.8);
      min-height: 60px;
      position: relative;
      font-size: 0.9em;
  }
 .tournament-match .player {
     display: flex;
     justify-content: space-between;
     align-items: center;
     padding: 2px 0;
 }
 .tournament-match .player .name {
     overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 70%;
 }
  .tournament-match .player .score {
      margin-left: 10px; font-weight: bold; color: #eee;
  }
 .spectate-match-btn {
      position: absolute; bottom: 4px; right: 4px;
      font-size: 0.6em !important;
      padding: 3px 6px !important;
      background-color: #3a3a4a !important;
      border-color: #666 !important;
  }
  .spectate-match-btn:hover { background-color: #4a4a5a !important; }

 /* Match state styles */
 .tournament-match.match-finished { opacity: 0.7; border-color: #444; }
 .tournament-match.match-active { border-color: #ffae42; }
 .tournament-match.match-pending { border-color: #666; }

 /* Match separator/status line */
 .match-separator {
     text-align: center; font-size: 0.8em; color: #aaa; margin: 3px 0;
 }
 .match-separator.separator-finished { color: #aaffaa; }
 .match-separator.separator-active { color: #ffae42; font-weight: bold; }

 /* Player row within a match */
 .match-player {
     display: flex; justify-content: space-between; align-items: center;
     padding: 2px 0; font-size: 0.9em; color: #ddd;
 }
 .match-player .name {
     overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 70%;
 }
 .match-player .score { margin-left: 10px; font-weight: bold; color: #eee; }

 /* Winner/loser styles */
 .match-player.player-winner { color: #90EE90; }
 .match-player.player-winner .name { font-weight: bold; }
 .match-player.player-loser { color: #FF7F7F; }
 .match-player.player-loser .name { text-decoration: line-through; opacity: 0.8; }
 .match-player.player-tbd { color: #888; }
 .match-player.player-tbd .name { font-style: italic; }

 /* Accessibility: W/L indicators visible alongside color */
 .match-result-indicator {
     font-size: 0.75em; margin-right: 4px; font-weight: bold;
 }
 .match-result-indicator.indicator-winner { color: #90EE90; }
 .match-result-indicator.indicator-loser { color: #FF7F7F; }

 /* Player self-highlight */
 .match-player.player-self .name { font-style: italic; }

 /* Bracket connector lines between rounds */
 .bracket-connector {
     display: flex; flex-direction: column; justify-content: space-around;
     min-width: 30px; align-self: stretch;
 }
 .bracket-connector-pair {
     flex: 1; position: relative; min-height: 80px;
 }
 .bracket-connector-line {
     position: absolute; border-color: #666; border-style: solid;
 }
 .bracket-connector-line.line-top {
     border-width: 2px 2px 0 0; border-radius: 0 6px 0 0;
     top: 25%; left: 0; right: 0; height: 25%;
 }
 .bracket-connector-line.line-bottom {
     border-width: 0 2px 2px 0; border-radius: 0 0 6px 0;
     top: 50%; left: 0; right: 0; height: 25%;
 }
 .bracket-connector-line.line-horizontal {
     border-width: 2px 0 0 0; top: 50%; left: 50%; right: 0; height: 0;
 }
/* --- END Tournament Bracket Styles --- */


/* --- Themed Modal --- */
#modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 100; display: flex; justify-content: center; align-items: center;
    opacity: 0; pointer-events: none; transition: opacity 0.3s ease;
}
#modal-overlay.visible { opacity: 1; pointer-events: auto; }
#modal-dialog {
    background-color: rgba(30, 25, 45, 0.95);
    border: 2px solid #888; border-radius: 8px;
    padding: 25px 30px; min-width: 300px; max-width: 450px; width: 90%;
    text-align: center; font-family: var(--font-main);
    box-shadow: 0 0 25px rgba(0, 0, 0, 0.6);
}
#modal-title {
    color: #eee; font-size: 1.5em; margin: 0 0 15px 0;
    border-bottom: 1px solid #555; padding-bottom: 10px;
}
#modal-message {
    color: #ccc; font-size: 1.1em; margin: 0 0 20px 0; line-height: 1.4;
}
#modal-buttons {
    display: flex; justify-content: center; gap: 15px;
}
#modal-buttons .global-button {
    position: static; font-family: var(--font-main); font-size: 1em;
    padding: 10px 25px; min-width: 100px;
}
#modal-confirm-btn { background-color: #555; border-color: #888; }
#modal-confirm-btn:hover { background-color: #6a6a6a; }
#modal-cancel-btn { background-color: #883333; border-color: #aa5555; }
#modal-cancel-btn:hover { background-color: #a84444; }

/* --- Game Result Modal --- */
#game-result-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.75);
    z-index: 99; display: flex; justify-content: center; align-items: center;
    opacity: 0; pointer-events: none; transition: opacity 0.4s ease;
}
#game-result-overlay.visible { opacity: 1; pointer-events: auto; }
#game-result-dialog {
    background-color: rgba(25, 20, 40, 0.95);
    border: 3px solid #888; border-radius: 10px;
    padding: 30px 40px; min-width: 320px; max-width: 500px; width: 90%;
    text-align: center; font-family: var(--font-main);
    box-shadow: 0 0 30px rgba(100, 80, 150, 0.3), 0 0 15px rgba(0, 0, 0, 0.5);
}
#game-result-title {
    color: #eee; font-size: 2em; margin: 0 0 10px 0;
}
#game-result-message {
    color: #90EE90; font-size: 1.4em; margin: 0 0 8px 0; font-weight: bold;
}
#game-result-reason {
    color: #aaa; font-size: 1em; margin: 0 0 25px 0; font-style: italic;
}
#game-result-buttons {
    display: flex; justify-content: center; gap: 15px;
}
#game-result-buttons .global-button {
    position: static; font-family: var(--font-main); font-size: 1.1em;
    padding: 12px 30px;
}
/* Color result dialog border based on outcome */
#game-result-dialog.result-win { border-color: #90EE90; }
#game-result-dialog.result-loss { border-color: #FF7F7F; }
#game-result-dialog.result-draw { border-color: #FFD700; }

/* --- Mobile Adaptations --- */
@media (max-width: 768px) {
    /* HUD Adjustments */
    #hud { padding: 6px 10px; font-size: 0.9em; min-width: 150px; }
    #hud p { margin: 3px 0; }
    #hud button { padding: 5px 8px; font-size: 0.65em; margin-top: 6px; }
    /* Global Button Adjustments */
    .global-button { padding: 6px 10px; font-size: 0.65em; }
    /* Chat Adjustments */
    #chat-container { width: 90%; max-width: 90%; left: 5%; bottom: 45px; height: 120px; max-height: 25vh; font-size: 0.85em; }
    #chat-messages { padding: 6px; font-size: 0.9em; }
    #chat-input { padding: 6px; font-size: 0.9em; }
    /* History Adjustments */
    #move-history-container { max-width: 180px; }
    #move-history-toggle-btn { font-size: 0.6em; padding: 5px 8px; }
    #move-history-panel { max-height: 150px; }
    #move-history-content { padding: 8px; font-size: 0.8em; }
    /* Menu Adjustments */
    #menu { min-width: 95%; width: 95%; padding: 15px; max-height: 85vh; }
    #menu h1 { font-size: 2em; margin-bottom: 15px; }
    .menu-nav-item { font-size: 1.2em; padding: 10px 8px; }
    .submenu-item { font-size: 1em; padding: 6px 4px; }
    .submenu { margin-left: 15px; }
    .submenu-content { padding: 10px; }
    .submenu-content label { font-size: 0.85em; }
    .submenu-content select,
    .submenu-content input[type="email"],
    .submenu-content input[type="text"],
    .submenu-content input[type="number"] { font-size: 0.9em; padding: 6px 8px; }
    .submenu-content .action-button { font-size: 1em; padding: 8px 15px; }
    .submenu-content .image-button img { width: 120px; }
    .submenu-content button { padding: 8px 12px; font-size: 0.9em; }
     #online-options-content input[type="email"] { width: calc(100% - 125px); }
     #online-options-content input[type="text"] { width: calc(100% - 80px); }
     #online-options-content button { font-size: 0.8em; padding: 6px 8px; }
     .setting-item { font-size: 1em; }
     .setting-item button, .setting-item select { font-size: 0.8em; }
     #rules-content { font-size: 0.9em; max-height: 40vh; }
     #menu-footer { font-size: 0.7em; }

     /* Modal Mobile */
     #modal-dialog { min-width: 250px; padding: 20px; }
     #modal-title { font-size: 1.3em; }
     #modal-message { font-size: 1em; }
     #game-result-dialog { min-width: 270px; padding: 25px; }
     #game-result-title { font-size: 1.6em; }
     #game-result-message { font-size: 1.2em; }

     /* Tournament Lobby/Bracket Mobile */
     #tournament-lobby-container { width: 95%; padding: 15px; }
     .lobby-main-content { flex-direction: column; gap: 10px; }
     #tournament-lobby-players { max-height: 120px; }
     #lobby-bracket-preview { max-height: 120px; }
     #tournament-bracket-container { top: 2%; bottom: 2%; left: 2%; right: 2%; padding: 10px; }
     #tournament-bracket-rounds { padding: 10px 5px; }
     .tournament-round { margin: 0 10px; min-width: 150px; }
     .tournament-match { padding: 6px 8px; margin: 15px 0; }
}
