/* =====================================================================
 * p2p.css — Shared styles for P2P multiplayer UI panel
 * Included by all multiplayer game pages.
 * ===================================================================== */

/* Hide elements with the .hidden utility class */
.hidden { display: none !important; }

/* Online panel wrapper */
.online-panel {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 18px 20px;
    margin-bottom: 20px;
    text-align: left;
}

/* Sub-panels (host / join) */
.p2p-sub-panel {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
}

.p2p-label {
    font-size: 1.05rem;
    margin-bottom: 8px;
    opacity: 0.9;
}

/* Room code display row */
.p2p-code-row {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
}

.p2p-code {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.82rem;
    background: rgba(0, 0, 0, 0.4);
    padding: 10px 14px;
    border-radius: 8px;
    flex: 1;
    word-break: break-all;
    border: 2px solid rgba(255, 255, 255, 0.2);
    user-select: all;
    cursor: text;
}

.p2p-copy-btn {
    padding: 10px 16px;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.7);
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    font-size: 0.95rem;
    white-space: nowrap;
    transition: background 0.2s;
    flex-shrink: 0;
    min-height: 44px;
}
.p2p-copy-btn:hover { background: rgba(255, 255, 255, 0.35); }
.p2p-copy-btn:focus { outline: 4px solid #f39c12; outline-offset: 2px; }

/* Status messages */
.p2p-status {
    font-size: 1rem;
    opacity: 0.85;
    margin-top: 8px;
    min-height: 1.5em;
}
.p2p-status.error   { color: #e74c3c; opacity: 1; font-weight: bold; }
.p2p-status.success { color: #2ecc71; opacity: 1; font-weight: bold; }

/* Join code input row */
.p2p-join-row {
    display: flex;
    gap: 10px;
    align-items: center;
}
.p2p-join-row .player-input {
    flex: 1;
    font-size: 1rem;
    padding: 12px 14px;
    text-align: left;
    letter-spacing: 0.04em;
}

.p2p-join-btn {
    padding: 12px 20px;
    background: #27ae60;
    color: #fff;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: bold;
    white-space: nowrap;
    transition: background 0.2s;
    flex-shrink: 0;
    min-height: 52px;
}
.p2p-join-btn:hover    { background: #219a52; }
.p2p-join-btn:focus    { outline: 4px solid #f39c12; outline-offset: 2px; }
.p2p-join-btn:disabled { background: #7f8c8d; cursor: default; }

/* =====================================================================
 * Chat bubble & panel — injected into DOM only when playing online
 * ===================================================================== */

#p2p-chat-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #2980b9;
    border: none;
    cursor: pointer;
    font-size: 1.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
    z-index: 1000;
    transition: background 0.2s, transform 0.15s;
}
#p2p-chat-bubble:hover  { background: #3498db; transform: scale(1.08); }
#p2p-chat-bubble:focus  { outline: 4px solid #f39c12; outline-offset: 2px; }

#p2p-chat-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    border-radius: 9px;
    background: #e74c3c;
    border: 2px solid #fff;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 700;
    color: #fff;
    line-height: 1;
}
#p2p-chat-badge.visible { display: flex; }

#p2p-chat-panel {
    position: fixed;
    bottom: 92px;
    right: 24px;
    width: 320px;
    max-height: 420px;
    background: #1a1a2e;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55);
    display: flex;
    flex-direction: column;
    z-index: 999;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.15);
}
#p2p-chat-panel.hidden { display: none; }

#p2p-chat-header {
    padding: 12px 16px;
    background: #16213e;
    font-weight: bold;
    font-size: 1rem;
    color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

#p2p-chat-close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 4px;
    transition: color 0.15s;
}
#p2p-chat-close:hover { color: #fff; }

#p2p-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 100px;
}

.p2p-chat-msg {
    max-width: 82%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 0.92rem;
    line-height: 1.4;
    word-break: break-word;
}
.p2p-chat-msg.sent {
    align-self: flex-end;
    background: #2980b9;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.p2p-chat-msg.received {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.12);
    color: #eee;
    border-bottom-left-radius: 4px;
}

#p2p-chat-input-row {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background: #16213e;
    flex-shrink: 0;
}

#p2p-chat-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    color: #fff;
    padding: 8px 14px;
    font-size: 0.95rem;
    outline: none;
    min-width: 0;
}
#p2p-chat-input::placeholder { color: rgba(255, 255, 255, 0.4); }
#p2p-chat-input:focus { border-color: rgba(255, 255, 255, 0.5); }

#p2p-chat-send {
    background: #27ae60;
    border: none;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    cursor: pointer;
    color: #fff;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}
#p2p-chat-send:hover { background: #219a52; }
#p2p-chat-send:focus { outline: 4px solid #f39c12; outline-offset: 2px; }

/* Sender name label inside each chat bubble */
.p2p-chat-sender {
    display: block;
    font-size: 0.75rem;
    font-weight: bold;
    margin-bottom: 3px;
    opacity: 0.85;
}
.p2p-chat-msg.sent     .p2p-chat-sender { color: rgba(255, 255, 255, 0.9); text-align: right; }
.p2p-chat-msg.received .p2p-chat-sender { color: #5dade2; }

.p2p-chat-text { display: block; }

/* Name input row injected at top of online panel by p2p.js */
.p2p-name-row {
    margin-bottom: 14px;
    padding-bottom: 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}
.p2p-name-row .p2p-label { display: block; margin-bottom: 6px; }

/* Validation error highlight for name inputs */
.p2p-name-error {
    border-color: #e74c3c !important;
    outline: 2px solid rgba(231, 76, 60, 0.5);
}

/* =====================================================================
 * Spectator mode
 * ===================================================================== */

/* Fixed banner at the top of the page for spectators */
#p2p-spectator-bar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 44px;
    background: rgba(0, 0, 0, 0.82);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    z-index: 1100;
    font-size: 1rem;
    font-weight: bold;
    letter-spacing: 0.02em;
}

#p2p-spectator-quit {
    color: #f39c12;
    text-decoration: underline;
    cursor: pointer;
}

/* Push page content below the bar */
body.p2p-spectating {
    padding-top: 44px;
}

/* Block all game interactions; chat/bar remain interactive via higher z-index */
body.p2p-spectating #game-screen,
body.p2p-spectating #showdown-overlay {
    pointer-events: none;
}

/* Ensure chat bubble and panel are still clickable */
#p2p-chat-bubble,
#p2p-chat-panel,
#p2p-spectator-bar {
    pointer-events: auto;
}
