/* ==========================================================================
   1. BASE LAYOUT & TYPOGRAPHY
   ========================================================================== */
body {
    font-family: Arial, sans-serif;
    background-color: #f4f4f9;
    color: #333;
    display: flex;
    justify-content: center;
    padding: 20px;
    margin: 0;
}

h1 { 
    margin-top: 0; 
    font-size: 24px; 
}

/* The main cards that hold the game and the connection settings */
.wrapper-box {
    max-width: 450px;
    width: 100%;
    text-align: center;
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

.status-banner { 
    font-weight: bold; 
    font-size: 18px; 
    margin-bottom: 15px; 
    color: #2c3e50; 
}

/* ==========================================================================
   2. BUTTONS & INPUTS
   ========================================================================== */
.action-button { 
    flex: 1; 
    padding: 10px; 
    background-color: #2ecc71; 
    color: white; 
    border: none; 
    border-radius: 5px; 
    cursor: pointer; 
    font-weight: bold; 
    transition: background-color 0.2s; 
}
.action-button:hover { background-color: #27ae60; }

.secondary-btn { background-color: #f39c12; }
.secondary-btn:hover { background-color: #e67e22; }

.reset-button { 
    flex: 1; 
    padding: 10px; 
    margin-top: 0; 
    background-color: #e74c3c; 
    color: white; 
    border: none; 
    border-radius: 5px; 
    cursor: pointer; 
    font-weight: bold; 
    transition: background-color 0.2s; 
}
.reset-button:hover { background-color: #c0392b; }

/* The text input for typing moves */
.input-container { display: flex; justify-content: center; gap: 10px; margin-bottom: 15px; }

#moveInput { 
    padding: 10px; 
    font-size: 16px; 
    border: 2px solid #ccc; 
    border-radius: 5px; 
    width: 60%; 
    transition: border-color 0.2s; 
}
#moveInput:focus { outline: none; border-color: #3498db; }
#moveInput:disabled { background-color: #e9ecef; cursor: not-allowed; }

#submitBtn { 
    padding: 10px 20px; 
    font-size: 16px; 
    background-color: #3498db; 
    color: white; 
    border: none; 
    border-radius: 5px; 
    cursor: pointer; 
    transition: background-color 0.2s; 
}
#submitBtn:hover:not(:disabled) { background-color: #2980b9; }
#submitBtn:disabled { background-color: #bdc3c7; cursor: not-allowed; }


/* ==========================================================================
   3. CONNECTION & PRE-GAME PANEL
   ========================================================================== */
.info-box {
    background-color: #f8f9fa;
    border: 1px solid #e0e0e0;
    padding: 15px;
    border-radius: 8px;
}

.highlight-id {
    color: #2c3e50;
    letter-spacing: 1px;
    font-family: monospace;
    background: #eef5fa;
    padding: 10px;
    border-radius: 5px;
    word-wrap: break-word;
}

#opponent-id-input {
    padding: 10px;
    width: 100%;
    box-sizing: border-box;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-family: monospace;
}

.status-text {
    color: #e67e22;
    font-weight: bold;
    margin-top: 15px;
}


/* ==========================================================================
   4. CHESS BOARD & DATA OUTPUTS (PGN, FEN)
   ========================================================================== */
.board-container { margin-bottom: 20px; width: 100%; }

/* The clickable move hints below the board */
#cheat-sheet { 
    margin-top: 15px; 
    font-size: 14px; 
    line-height: 1.8; 
    text-align: left; 
    background: #f9f9f9; 
    padding: 10px; 
    border-radius: 6px; 
    border: 1px solid #eee; 
}
.piece-group { margin-bottom: 5px; }
.piece-label { font-weight: bold; color: #555; margin-right: 10px; display: inline-block; width: 80px; }
.clickable-move { 
    color: #0066cc; 
    cursor: pointer; 
    margin-right: 8px; 
    padding: 2px 6px; 
    border-radius: 4px; 
    background-color: #eef5fa; 
    transition: background-color 0.2s, color 0.2s; 
    display: inline-block; 
}
.clickable-move:hover { background-color: #3498db; color: white; text-decoration: none; }

/* Output Boxes (PGN / FEN) */
.output-container { margin-top: 15px; text-align: left; }
.output-label { font-weight: bold; color: #555; margin-bottom: 5px; font-size: 14px; margin-top: 0; }
.output-box-wrapper { display: flex; gap: 8px; align-items: stretch; }
.output-box { 
    flex-grow: 1; 
    padding: 10px; 
    background-color: #f1f1f1; 
    border-radius: 5px; 
    font-family: monospace; 
    font-size: 13px; 
    min-height: 20px; 
    word-wrap: break-word; 
    border: 1px solid #ddd; 
    overflow-x: auto; 
    display: flex; 
    align-items: center; 
}

.copy-btn { 
    padding: 0 15px; 
    background-color: #34495e; 
    color: white; 
    border: none; 
    border-radius: 5px; 
    cursor: pointer; 
    font-size: 13px; 
    font-weight: bold; 
    transition: background-color 0.2s; 
}
.copy-btn:hover { background-color: #2c3e50; }
.copy-btn.success { background-color: #27ae60; }

.fen-control-panel { 
    margin-top: 25px; 
    padding: 15px; 
    background-color: #f8f9fa; 
    border: 1px solid #e0e0e0; 
    border-radius: 8px; 
    display: flex; 
    flex-direction: column; 
    gap: 12px; 
}
#fenInput { padding: 10px; font-size: 13px; border: 1px solid #ccc; border-radius: 4px; width: 100%; box-sizing: border-box; font-family: monospace; }
#fenInput:focus { outline: none; border-color: #2ecc71; }
.fen-buttons { display: flex; justify-content: space-between; gap: 10px; }


/* ==========================================================================
   5. LIVE CHAT COMPONENT
   ========================================================================== */
.chat-container {
    margin-top: 25px;
    text-align: left;
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.chat-box {
    height: 150px;
    overflow-y: auto;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 10px;
    margin-bottom: 10px;
    font-size: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-message { padding: 8px 12px; border-radius: 6px; max-width: 80%; word-wrap: break-word; }
.chat-message.self { background-color: #3498db; color: white; align-self: flex-end; border-bottom-right-radius: 0; }
.chat-message.opponent { background-color: #e2e8f0; color: #333; align-self: flex-start; border-bottom-left-radius: 0; }
.chat-message.system { background-color: transparent; color: #7f8c8d; font-size: 12px; font-style: italic; align-self: center; text-align: center; }

.chat-input-wrapper { display: flex; gap: 8px; }
#chatInput { flex-grow: 1; padding: 10px; border: 1px solid #ccc; border-radius: 4px; font-size: 14px; }
#chatInput:focus { outline: none; border-color: #3498db; }
#sendChatBtn { padding: 10px 20px; }


/* ==========================================================================
   6. VISUAL JUICE & EFFECTS
   ========================================================================== */
.material-tracker {
    font-size: 14px; color: #7f8c8d; min-height: 20px;
    display: flex; align-items: center; gap: 5px; margin-top: 5px;
}
.material-tracker span { color: #2ecc71; font-weight: bold; }

.captured-piece {
    width: 18px;
    height: 18px;
    margin-right: -6px; /* Overlaps them slightly like standard chess sites */
    vertical-align: middle;
    opacity: 0.9;
}

.score-diff {
    margin-left: 12px;
    font-size: 13px;
    font-weight: bold;
    color: #7f8c8d;
    vertical-align: middle;
}

/* Last Move Highlight (A subtle yellow-green) */
.highlight-last-move { background-color: rgba(155, 199, 0, 0.41) !important; }

/* Legal Move Dot (Empty square target) */
.legal-move-hint { position: relative; }
.legal-move-hint::after {
    content: '';
    position: absolute; top: 50%; left: 50%;
    width: 25%; height: 25%;
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none; /* Crucial: Lets clicks pass through the dot to the board! */
}

/* Legal Move Capture (Enemy piece - a hollow target ring) */
.legal-move-capture { position: relative; }
.legal-move-capture::after {
    content: '';
    position: absolute; top: 50%; left: 50%;
    width: 80%; height: 80%;
    background-color: transparent;
    border: 4px solid rgba(0, 0, 0, 0.2);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
}


/* ==========================================================================
   7. MODALS & OVERLAYS
   ========================================================================== */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.6); z-index: 9999;
    display: flex; justify-content: center; align-items: center;
}

.modal-content {
    background: #fff; padding: 20px; border-radius: 8px; 
    text-align: center; color: #333; max-width: 300px; width: 90%;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

.promotion-pieces { display: flex; justify-content: space-around; margin-top: 15px; }
.promotion-pieces img { width: 60px; cursor: pointer; transition: transform 0.1s; }
.promotion-pieces img:hover { transform: scale(1.1); }

#modal-close {
    margin-top: 15px; padding: 8px 16px; cursor: pointer;
    background: #3498db; color: white; border: none; border-radius: 4px;
}