/**
 * BAB Online Component Styles
 * Replaces 200+ inline styles from ui.js and game.js
 */

/* ==========================================================================
   Utility Classes
   ========================================================================== */

.hidden {
    display: none !important;
}

.fade-out {
    opacity: 0;
    transition: opacity 0.3s ease;
}

/* ==========================================================================
   Modal Overlay
   ========================================================================== */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: #1a1a2e;
    padding: 40px;
    border-radius: 12px;
    position: relative;
    max-width: 90%;
    max-height: 90%;
    overflow: auto;
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    color: #888;
    font-size: 24px;
    cursor: pointer;
    transition: color 0.2s;
}

.modal-close:hover {
    color: #fff;
}

/* ==========================================================================
   Auth Forms
   ========================================================================== */

.auth-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.9);
    z-index: 100;
}

.auth-form {
    background: #1a1a2e;
    padding: 40px;
    border-radius: 12px;
    width: 320px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.auth-form h2 {
    color: #fff;
    margin-bottom: 24px;
    text-align: center;
}

.auth-input {
    width: 100%;
    padding: 12px;
    margin-bottom: 16px;
    border: 1px solid #333;
    border-radius: 4px;
    background: #0f0f1a;
    color: white;
    font-size: 1em;
    box-sizing: border-box;
}

.auth-input:focus {
    outline: none;
    border-color: #4a90d9;
}

.auth-button {
    width: 100%;
    padding: 12px;
    background: #4a90d9;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 1.1em;
    cursor: pointer;
    transition: background 0.2s;
}

.auth-button:hover {
    background: #357abd;
}

.auth-button:disabled {
    background: #555;
    cursor: not-allowed;
}

.auth-link {
    color: #4a90d9;
    cursor: pointer;
    margin-top: 16px;
    display: block;
    text-align: center;
}

.auth-link:hover {
    text-decoration: underline;
}

.auth-error {
    color: #ff4444;
    margin-bottom: 16px;
    text-align: center;
}

/* ==========================================================================
   Lobby / Queue
   ========================================================================== */

.lobby-container {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #1a1a2e;
    padding: 40px;
    border-radius: 12px;
    text-align: center;
    z-index: 50;
}

.lobby-title {
    color: #fff;
    font-size: 24px;
    margin-bottom: 20px;
}

.queue-button {
    padding: 15px 40px;
    font-size: 18px;
    background: #4ade80;
    color: #000;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.queue-button:hover {
    background: #22c55e;
    transform: scale(1.05);
}

.queue-status {
    color: #888;
    margin-top: 20px;
    font-size: 14px;
}

.queue-count {
    color: #4ade80;
    font-weight: bold;
}

/* ==========================================================================
   Bid UI
   ========================================================================== */

.bid-container {
    position: absolute;
    bottom: 200px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    z-index: 200;
}

.bid-input {
    width: 80px;
    height: 40px;
    font-size: 1.5em;
    text-align: center;
    border: 2px solid #333;
    border-radius: 4px;
    background: #1a1a2e;
    color: #fff;
}

.bid-input:focus {
    outline: none;
    border-color: #4a90d9;
}

.bid-button {
    width: 100px;
    height: 36px;
    font-size: 1.2em;
    background: #4a90d9;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
}

.bid-button:hover {
    background: #357abd;
}

.bid-button:disabled {
    background: #555;
    cursor: not-allowed;
}

.bid-bubble {
    position: absolute;
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    border-radius: 20px;
    font-size: 18px;
    font-weight: bold;
    animation: bubblePop 0.3s ease;
    z-index: 150;
}

@keyframes bubblePop {
    0% { transform: scale(0); opacity: 0; }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}

/* ==========================================================================
   Score Display
   ========================================================================== */

.score-container {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 40px;
    z-index: 100;
}

.score-team {
    text-align: center;
    padding: 12px 24px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 8px;
    color: white;
    min-width: 100px;
}

.score-team.my-team {
    border: 2px solid #4ade80;
}

.score-team.opp-team {
    border: 2px solid #f87171;
}

.score-label {
    font-size: 0.9em;
    color: #888;
    margin-bottom: 4px;
}

.score-value {
    font-size: 2em;
    font-weight: bold;
}

.score-tricks {
    font-size: 0.8em;
    color: #aaa;
    margin-top: 4px;
}

/* ==========================================================================
   Turn Indicator
   ========================================================================== */

.turn-indicator {
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 10px #4ade80;
    animation: pulse 1s infinite;
    z-index: 150;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.3);
        opacity: 0.7;
    }
}

.turn-indicator.self {
    bottom: 180px;
    left: 50%;
    transform: translateX(-50%);
}

.turn-indicator.partner {
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
}

.turn-indicator.left {
    top: 50%;
    left: 80px;
    transform: translateY(-50%);
}

.turn-indicator.right {
    top: 50%;
    right: 80px;
    transform: translateY(-50%);
}

/* ==========================================================================
   Player Display
   ========================================================================== */

.player-info {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    z-index: 50;
}

.player-info.partner {
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
}

.player-info.left {
    top: 50%;
    left: 20px;
    transform: translateY(-50%);
}

.player-info.right {
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
}

.player-avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 3px solid #333;
    object-fit: cover;
}

.player-avatar.teammate {
    border-color: #4ade80;
}

.player-avatar.opponent {
    border-color: #f87171;
}

.player-name {
    color: #fff;
    font-size: 14px;
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ==========================================================================
   Chat UI
   ========================================================================== */

.chat-container {
    position: fixed;
    top: 10px;
    right: 10px;
    bottom: 10px;
    width: 300px;
    min-width: 220px;
    background: rgba(0, 0, 0, 0.85);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    z-index: 500;
}

/* Responsive chat sizing */
@media (max-width: 1400px) {
    .chat-container {
        width: 260px;
    }
}

@media (max-width: 1200px) {
    .chat-container {
        width: 220px;
    }
}

@media (max-width: 1000px) {
    .chat-container {
        width: 180px;
        font-size: 12px;
    }
}

@media (max-width: 800px) {
    .chat-container {
        width: 150px;
        font-size: 11px;
    }

    .chat-header {
        padding: 6px 10px;
        font-size: 12px;
    }

    .chat-input-container {
        padding: 4px;
        gap: 4px;
    }

    .chat-input {
        padding: 4px;
        font-size: 11px;
    }

    .chat-send {
        padding: 4px 8px;
        font-size: 11px;
    }
}

.chat-header {
    padding: 10px 15px;
    background: #1a1a2e;
    border-radius: 8px 8px 0 0;
    color: #fff;
    font-weight: bold;
    border-bottom: 1px solid #333;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.chat-message {
    margin-bottom: 8px;
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.chat-message .sender {
    color: #4a90d9;
    font-weight: bold;
    margin-right: 8px;
}

.chat-message .text {
    color: #fff;
}

.chat-message.system {
    background: rgba(74, 144, 217, 0.2);
    font-style: italic;
}

.chat-input-container {
    display: flex;
    padding: 8px;
    border-top: 1px solid #333;
    gap: 8px;
}

.chat-input {
    flex: 1;
    padding: 8px;
    border: 1px solid #333;
    border-radius: 4px;
    background: #222;
    color: white;
    font-size: 14px;
}

.chat-input:focus {
    outline: none;
    border-color: #4a90d9;
}

.chat-send {
    padding: 8px 16px;
    background: #4a90d9;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.chat-send:hover {
    background: #357abd;
}

/* ==========================================================================
   Trump Display
   ========================================================================== */

.trump-display {
    position: absolute;
    top: 100px;
    left: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    z-index: 50;
}

.trump-label {
    color: #888;
    font-size: 12px;
    text-transform: uppercase;
}

.trump-card {
    width: 60px;
    height: 84px;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

/* ==========================================================================
   Turn Indicator Glow
   ========================================================================== */

.turn-glow {
    box-shadow: 0 0 30px 15px rgba(255, 215, 0, 0.5);
    animation: pulse-glow 1s ease-in-out infinite alternate;
}

@keyframes pulse-glow {
    from { box-shadow: 0 0 20px 10px rgba(255, 215, 0, 0.2); }
    to { box-shadow: 0 0 40px 20px rgba(255, 215, 0, 0.6); }
}

/* ==========================================================================
   Opponent Avatars (DOM-based)
   ========================================================================== */

.opponent-avatar-container {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
    z-index: 50;
    transform: translate(-50%, -50%);
}

.opponent-avatar-img {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
    background-color: #1a1a2e;
    border: none;
}

.opponent-avatar-name {
    color: #ffffff;
    font-size: 18px;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

/* Turn glow for opponent avatars - only apply glow to img, not container */
.opponent-avatar-container.turn-glow {
    box-shadow: none;
    animation: none;
}

.opponent-avatar-container.turn-glow .opponent-avatar-img {
    box-shadow: 0 0 30px 15px rgba(255, 215, 0, 0.5);
    animation: pulse-glow 1s ease-in-out infinite alternate;
}

/* ==========================================================================
   Hand Info
   ========================================================================== */

.hand-info {
    position: absolute;
    top: 20px;
    left: 20px;
    padding: 10px 16px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 8px;
    color: #fff;
    z-index: 50;
}

.hand-number {
    font-size: 24px;
    font-weight: bold;
}

.hand-label {
    font-size: 12px;
    color: #888;
}

/* ==========================================================================
   Toasts / Notifications
   ========================================================================== */

.error-toast,
.success-toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    border-radius: 4px;
    color: white;
    font-weight: bold;
    animation: slideUp 0.3s ease;
    z-index: 2000;
}

.error-toast {
    background: #dc2626;
}

.success-toast {
    background: #22c55e;
}

@keyframes slideUp {
    from {
        transform: translate(-50%, 100%);
        opacity: 0;
    }
    to {
        transform: translate(-50%, 0);
        opacity: 1;
    }
}

/* ==========================================================================
   Rainbow Indicator
   ========================================================================== */

.rainbow-indicator {
    position: absolute;
    padding: 8px 20px;
    background: linear-gradient(90deg, #ff0000, #ff7f00, #ffff00, #00ff00, #0000ff, #4b0082, #9400d3);
    color: #fff;
    font-weight: bold;
    font-size: 18px;
    border-radius: 20px;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
    animation: rainbowGlow 2s ease-in-out infinite;
    z-index: 200;
}

@keyframes rainbowGlow {
    0%, 100% {
        box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
    }
    50% {
        box-shadow: 0 0 20px rgba(255, 255, 255, 0.8);
    }
}

/* ==========================================================================
   Game End Screen
   ========================================================================== */

.game-end-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 500;
}

.game-end-content {
    text-align: center;
    color: #fff;
}

.game-end-title {
    font-size: 48px;
    margin-bottom: 20px;
}

.game-end-title.win {
    color: #4ade80;
}

.game-end-title.lose {
    color: #f87171;
}

.game-end-scores {
    font-size: 24px;
    margin-bottom: 30px;
}

.play-again-button {
    padding: 15px 40px;
    font-size: 20px;
    background: #4a90d9;
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

.play-again-button:hover {
    background: #357abd;
}

/* ==========================================================================
   Chat Bubbles (DOM-based)
   ========================================================================== */

.chat-bubble {
    position: absolute;
    background: #ffffff;
    color: #000000;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 14px;
    font-family: Arial, sans-serif;
    min-width: 40px;
    max-width: 200px;
    word-wrap: break-word;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    z-index: 500;
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.3s ease;
    text-align: center;
}

.chat-bubble.fade-out {
    opacity: 0;
}

.chat-bubble.bid {
    color: #FF0000;
    font-weight: bold;
}

/* Tail pointing down (centered, points at avatar below) */
.chat-bubble.tail-down::after {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    border-width: 10px 8px 0 8px;
    border-style: solid;
    border-color: #ffffff transparent transparent transparent;
}

/* Tail pointing left (for opp1 - left side opponent) */
.chat-bubble.tail-left::after {
    content: '';
    position: absolute;
    left: -10px;
    top: 50%;
    transform: translateY(-50%);
    border-width: 8px 10px 8px 0;
    border-style: solid;
    border-color: transparent #ffffff transparent transparent;
}

/* Tail pointing right (for opp2 - right side opponent) */
.chat-bubble.tail-right::after {
    content: '';
    position: absolute;
    right: -10px;
    top: 50%;
    transform: translateY(-50%);
    border-width: 8px 0 8px 10px;
    border-style: solid;
    border-color: transparent transparent transparent #ffffff;
}

/* ==========================================================================
   Dealer Button (DOM-based)
   ========================================================================== */

.dealer-button {
    position: absolute;
    width: 40px;
    height: 40px;
    z-index: 150;
    pointer-events: none;
    transform: translate(-50%, -50%);
}

.dealer-button img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}
