/* Endless Scrabble Game Styles */

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Animations */
@keyframes pulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 rgba(76, 175, 80, 0.4);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 20px rgba(76, 175, 80, 0.8);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 rgba(76, 175, 80, 0.4);
    }
}

body {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: white;
    overflow: hidden;
    user-select: none;
}

.game-container {
    width: 100vw;
    height: 100vh;
    position: relative;
}

/* Spielbrett */
.board-container {
    width: 100%;
    height: calc(100% - 140px);
    overflow: hidden;
    /* Dunkler Außenbereich */
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    position: relative;
    cursor: grab;
}

.board-container.dragging {
    cursor: grabbing;
}

.board {
    width: 4040px;  /* 101 tiles * 40px */
    height: 4040px; /* 101 tiles * 40px */
    /* Erdige Farben mit Grid-Linien */
    background: 
        /* Grid-Linien OBEN für Sichtbarkeit */
        linear-gradient(90deg, rgba(0,0,0,0.15) 1px, transparent 1px),
        linear-gradient(rgba(0,0,0,0.15) 1px, transparent 1px),
        /* Erdiger Hintergrund UNTEN */
        linear-gradient(135deg, #8b7355 0%, #a0826d 25%, #967259 50%, #8b6f47 75%, #7a5c3a 100%);
    background-size: 40px 40px, 40px 40px, 100% 100%;
    position: relative;
    transition: none;
    transform-origin: 0 0;
    /* Schatten für Tiefe */
    box-shadow: 
        0 0 100px rgba(0,0,0,0.5),
        inset 0 0 100px rgba(0,0,0,0.2);
    /* Rand für klare Abgrenzung */
    border: 3px solid #5d4e37;
}

.cell {
    width: 40px;
    height: 40px;
    position: absolute;
    border: 1px solid rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    pointer-events: none; /* WICHTIG: Cells sollen keine Events abfangen! */
}

.cell.occupied {
    border: 2px solid #fff;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    animation: placeCell 0.3s ease;
    pointer-events: none; /* Auch besetzte Cells nicht! */
}

/* Punkte auf Board-Tiles - genau wie in der Hand */
.cell.occupied .letter-points {
    position: absolute;
    bottom: 2px;
    right: 2px;
    font-size: 8px;
    color: rgba(255, 255, 255, 0.8);
}

/* Grid-Zellen Highlighting */
.grid-highlight {
    width: 40px !important;
    height: 40px !important;
    position: absolute !important;
    pointer-events: none;
    z-index: 999 !important;
    box-sizing: border-box;
}

.grid-highlight.valid {
    background: rgba(76, 175, 80, 0.6) !important;
    border: 3px solid #4CAF50 !important;
    box-shadow: 0 0 10px rgba(76, 175, 80, 0.8) !important;
}

.grid-highlight.invalid {
    background: rgba(244, 67, 54, 0.6) !important;
    border: 3px solid #f44336 !important;
    box-shadow: 0 0 10px rgba(244, 67, 54, 0.8) !important;
}

.grid-highlight.occupied {
    background: rgba(255, 152, 0, 0.6) !important;
    border: 3px solid #FF9800 !important;
    box-shadow: 0 0 10px rgba(255, 152, 0, 0.8) !important;
}

.drop-indicator.preview {
    background: rgba(255, 235, 59, 0.3);
    border: 2px dashed #FDD835;
    opacity: 1;
}

@keyframes pulse-valid {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

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

/* Nachbar-Highlighting */
.neighbor-highlight {
    width: 40px;
    height: 40px;
    position: absolute;
    pointer-events: none;
    background: rgba(76, 175, 80, 0.1);
    border: 1px solid rgba(76, 175, 80, 0.3);
    z-index: 400;
}

@keyframes placeCell {
    from {
        transform: scale(1.2);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Truhen-Felder */
.cell.chest-field {
    width: 40px;
    height: 40px;
    position: absolute;
    border: 2px solid;
    box-shadow: 
        inset 0 0 10px rgba(0,0,0,0.3),
        0 0 10px rgba(255,215,0,0.5);
    pointer-events: none;
    animation: chestGlow 2s ease-in-out infinite;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.cell.chest-field.wood-chest {
    background: linear-gradient(135deg, #8b4513 0%, #a0522d 50%, #cd853f 100%);
    border-color: #654321;
}

.cell.chest-field.silver-chest {
    background: linear-gradient(135deg, #c0c0c0 0%, #e5e5e5 50%, #ffffff 100%);
    border-color: #999999;
    box-shadow: 
        inset 0 0 10px rgba(0,0,0,0.3),
        0 0 15px rgba(192,192,192,0.8);
}

.cell.chest-field.gold-chest {
    background: linear-gradient(135deg, #ffd700 0%, #ffed4e 50%, #fff8dc 100%);
    border-color: #b8860b;
    box-shadow: 
        inset 0 0 10px rgba(0,0,0,0.3),
        0 0 20px rgba(255,215,0,0.9);
}

@keyframes chestGlow {
    0%, 100% { opacity: 0.8; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.05); }
}

/* Pech-Fallen */
.cell.tar-pit-field {
    width: 40px;
    height: 40px;
    position: absolute;
    background: radial-gradient(ellipse at center, #0f0f0f 0%, #2d2d2d 50%, #1a1a1a 100%);
    border: 2px solid #000;
    box-shadow: 
        inset 0 0 10px rgba(0,0,0,0.8),
        0 0 5px rgba(0,0,0,0.5);
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    animation: tarBubble 3s ease-in-out infinite;
}

@keyframes tarBubble {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(0.95); }
}

/* Wasser-Felder */
.cell.water-field {
    /* Dunkleres Blau */
    background: #2c5aa0;
    border: none;
    box-shadow: none;
    opacity: 1;
    pointer-events: none;
    position: relative;
}

/* Palmen-Felder */
.cell.palm-field {
    background: transparent;
    border: none;
    pointer-events: none;
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
}

/* Felsen-Felder */
.cell.rock-field {
    background: transparent;
    border: none;
    pointer-events: none;
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
}


/* Spieler-Hand */
.player-hand {
    height: 140px;
    background: rgba(0,0,0,0.8);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 1000;
    position: relative;
    backdrop-filter: blur(10px);
}

.letter-tile {
    width: 60px;
    height: 60px;
    background: linear-gradient(145deg, #f0f0f0, #d0d0d0);
    color: #333;
    border: 2px solid #bbb;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: bold;
    cursor: grab;
    transition: all 0.2s ease;
    position: relative;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

.letter-tile:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 16px rgba(0,0,0,0.4);
}

.letter-tile.dragging {
    transform: rotate(5deg) scale(1.1);
    z-index: 1000;
    cursor: grabbing;
    opacity: 0.8;
}

.letter-points {
    position: absolute;
    bottom: 4px;
    right: 6px;
    font-size: 12px;
    opacity: 0.7;
}

/* UI Panels */
.ui-panel {
    position: absolute;
    top: 20px;
    left: 20px;
    background: rgba(0,0,0,0.8);
    padding: 20px;
    border-radius: 12px;
    backdrop-filter: blur(10px);
    z-index: 1000;
    min-width: 250px;
}

.player-info {
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid rgba(255,255,255,0.2);
}

.player-name {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 5px;
}

.score {
    font-size: 28px;
    font-weight: bold;
    margin-bottom: 5px;
}

.territory-count {
    font-size: 14px;
    opacity: 0.9;
}

.swap-container {
    margin-top: 10px;
    min-height: 32px;
}

.swap-timer {
    font-size: 12px;
    padding: 8px;
    background: rgba(255,255,255,0.1);
    border-radius: 6px;
    text-align: center;
}

.swap-timer.ready {
    background: rgba(76, 175, 80, 0.2);
    color: #4CAF50;
}

#swapButtonTop {
    width: 100%;
    font-size: 12px;
    padding: 8px;
    background: rgba(76, 175, 80, 0.2);
    color: #4CAF50;
    border: 1px solid rgba(76, 175, 80, 0.3);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s;
}

#swapButtonTop:hover:not(:disabled) {
    background: rgba(76, 175, 80, 0.3);
    transform: translateY(-1px);
}

#swapButtonTop:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Leaderboard */
.leaderboard {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(0,0,0,0.8);
    padding: 20px;
    border-radius: 12px;
    backdrop-filter: blur(10px);
    z-index: 1000;
    min-width: 200px;
}

.leaderboard h3 {
    margin-bottom: 15px;
    font-size: 16px;
    opacity: 0.9;
}

.leaderboard-entry {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    margin: 4px 0;
    background: rgba(255,255,255,0.05);
    border-radius: 6px;
    font-size: 14px;
}

.leaderboard-entry .player-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-right: 8px;
    display: inline-block;
}

/* Controls */
.controls {
    position: absolute;
    bottom: 160px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    z-index: 1000;
}

.btn {
    background: linear-gradient(145deg, #667eea, #764ba2);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    transition: all 0.2s ease;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

.btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.4);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn.cancel {
    background: linear-gradient(145deg, #f44336, #d32f2f);
}

.btn.swap {
    background: linear-gradient(145deg, #FF9800, #F57C00);
}

/* Feedback */
.word-feedback {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0,0,0,0.95);
    padding: 30px;
    border-radius: 12px;
    font-size: 20px;
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.3s ease;
    min-width: 300px;
    text-align: center;
    pointer-events: none; /* WICHTIG: Feedback blockiert keine Events! */
}

.word-feedback.show {
    opacity: 1;
    pointer-events: auto; /* Nur wenn sichtbar, Events erlauben */
}

.word-feedback.success {
    border: 2px solid #4CAF50;
    color: #4CAF50;
}

.word-feedback.error {
    border: 2px solid #f44336;
    color: #f44336;
}

.word-feedback.info {
    border: 2px solid #2196F3;
    color: #2196F3;
}

/* AI Spinner - Subtil und halbtransparent */
.ai-spinner {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top: 3px solid rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Online Players */
.online-players {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.8);
    padding: 10px 20px;
    border-radius: 20px;
    backdrop-filter: blur(10px);
    z-index: 1000;
    display: flex;
    gap: 15px;
    align-items: center;
}

.online-count {
    display: flex;
    align-items: center;
    gap: 5px;
}

.online-dot {
    width: 8px;
    height: 8px;
    background: #4CAF50;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Login Modal */
.login-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
}

.login-modal.hidden {
    display: none;
}

.login-box {
    background: linear-gradient(145deg, #2a2a2a, #1a1a1a);
    padding: 40px;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.login-box h2 {
    margin-bottom: 20px;
    font-size: 28px;
}

.login-box input {
    width: 100%;
    padding: 12px;
    margin: 10px 0;
    border: none;
    border-radius: 8px;
    background: rgba(255,255,255,0.1);
    color: white;
    font-size: 16px;
}

.login-box input::placeholder {
    color: rgba(255,255,255,0.5);
}

/* Andere Spieler-Cursor */
.other-player-cursor {
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 900;
    opacity: 0.7;
    transition: all 0.3s ease;
}

.other-player-name {
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    white-space: nowrap;
    background: rgba(0,0,0,0.7);
    padding: 2px 6px;
    border-radius: 4px;
}