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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #2d3748;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    margin-bottom: 30px;
}

header h1 {
    font-size: 2.5rem;
    color: #ffffff;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}

/* Connection Status */
.connection-status {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: #fff;
    border-radius: 5px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.status-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #ccc;
    display: inline-block;
}

.status-indicator.connected {
    background: #27ae60;
}

.status-indicator.disconnected {
    background: #e74c3c;
}

/* Buttons */
.btn {
    padding: 12px 24px;
    font-size: 1rem;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.2s;
    font-weight: 500;
}

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

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

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

.btn-secondary {
    background-color: #718096;
    color: white;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.btn-secondary:hover:not(:disabled) {
    background-color: #4a5568;
    transform: translateY(-2px);
    box-shadow: 0 6px 8px rgba(0,0,0,0.15);
}

.btn-small {
    padding: 8px 16px;
    font-size: 0.9rem;
}

/* Lobby */
.lobby {
    background: white;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    max-width: 600px;
    margin: 0 auto;
}

.player-setup {
    margin-bottom: 20px;
}

.player-setup label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
}

.player-setup input {
    width: 100%;
    padding: 10px;
    font-size: 1rem;
    border: 2px solid #ddd;
    border-radius: 5px;
}

.player-setup input:focus {
    outline: none;
    border-color: #3498db;
}

.player-setup input.input-error,
.join-game input.input-error {
    border-color: #e74c3c;
}

.player-setup input.input-error:focus,
.join-game input.input-error:focus {
    border-color: #c0392b;
}

.game-actions {
    margin-top: 30px;
}

.game-actions .btn {
    width: 100%;
    margin-bottom: 15px;
}

.divider {
    text-align: center;
    margin: 15px 0;
    color: #7f8c8d;
}

.join-game {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 10px;
    align-items: center;
}

.join-game label {
    font-weight: 500;
    color: #2d3748;
    white-space: nowrap;
}

.join-game input {
    padding: 10px;
    font-size: 1rem;
    border: 2px solid #ddd;
    border-radius: 5px;
}

.join-game input:focus {
    outline: none;
    border-color: #667eea;
}

.join-game .btn {
    margin: 0;
}

/* Player List */
.player-list-section {
    margin-top: 30px;
    padding: 20px;
    background: #ecf0f1;
    border-radius: 5px;
}

.player-list-section h3 {
    margin-bottom: 15px;
    color: #2c3e50;
}

.game-info {
    margin-bottom: 15px;
    padding: 10px;
    background: white;
    border-radius: 5px;
    font-size: 0.9rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
}

.game-info strong {
    color: #667eea;
}

.player-count {
    color: #7f8c8d;
    font-size: 0.85rem;
}

.player-list {
    list-style: none;
    background: white;
    border-radius: 5px;
    padding: 10px;
}

.player-list li {
    padding: 10px;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    gap: 10px;
}

.player-list li:last-child {
    border-bottom: none;
}

.player-list .player-name {
    flex: 1;
    font-weight: 500;
}

.player-list .player-badge {
    padding: 4px 8px;
    border-radius: 3px;
    font-size: 0.8rem;
    background: #3498db;
    color: white;
}

.player-list .player-badge.creator {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.game-actions-buttons {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

.game-actions-buttons .btn {
    flex: 1;
}

/* Message Toasts */
.message-toast {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 15px 20px;
    border-radius: 5px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    font-weight: 500;
    z-index: 1000;
    animation: slideIn 0.3s ease-out;
    max-width: 400px;
}

.message-error {
    background-color: #e74c3c;
    color: white;
}

.message-success {
    background-color: #27ae60;
    color: white;
}

.message-info {
    background-color: #3498db;
    color: white;
}

.message-toast.fade-out {
    animation: slideOut 0.3s ease-out forwards;
}

@keyframes slideIn {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(400px);
        opacity: 0;
    }
}

/* Loading State for Buttons */
.btn.loading {
    position: relative;
    color: transparent;
    pointer-events: none;
}

.btn.loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -8px;
    border: 2px solid #fff;
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Game Page Layout */
main {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

.scoring-rules {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    min-width: 220px;
    position: sticky;
    top: 20px;
}

.scoring-rules h3 {
    color: #2d3748;
    margin-bottom: 20px;
    font-size: 1.3rem;
    border-bottom: 2px solid #667eea;
    padding-bottom: 10px;
}

.rules-section {
    margin-bottom: 20px;
}

.rules-section h4 {
    color: #4a5568;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

.rules-section ul {
    list-style: none;
    padding: 0;
}

.rules-section li {
    padding: 5px 0;
    color: #2d3748;
    font-size: 0.95rem;
}

.rules-section p {
    color: #718096;
    font-size: 0.9rem;
    margin: 0;
}

.game-content {
    flex: 1;
}

/* Game Board Styles */
.scoreboard {
    display: flex;
    gap: 15px;
    margin-bottom: 30px;
    flex-wrap: wrap;
    justify-content: center;
}

.player-card {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    min-width: 200px;
    text-align: center;
}

.player-card.active {
    border: 3px solid #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
    transform: scale(1.05);
}

.player-card.winner {
    border: 3px solid #f59e0b;
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    box-shadow: 0 8px 20px rgba(245, 158, 11, 0.5);
    transform: scale(1.1);
    animation: winnerPulse 2s ease-in-out infinite;
}

.player-card.winner .player-name::before {
    content: '👑 ';
}

@keyframes winnerPulse {
    0%, 100% {
        box-shadow: 0 8px 20px rgba(245, 158, 11, 0.5);
    }
    50% {
        box-shadow: 0 12px 28px rgba(245, 158, 11, 0.7);
    }
}

/* Dice rolling animation */
@keyframes diceRoll {
    0%, 100% {
        transform: rotate(0deg);
    }
    25% {
        transform: rotate(-10deg) scale(1.05);
    }
    75% {
        transform: rotate(10deg) scale(1.05);
    }
}

.die.rolling {
    animation: diceRoll 0.3s ease-in-out;
}

/* Farkle shake animation */
@keyframes farkleShake {
    0%, 100% {
        transform: translateX(0);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translateX(-10px);
    }
    20%, 40%, 60%, 80% {
        transform: translateX(10px);
    }
}

.game-board.farkle {
    animation: farkleShake 0.8s ease-in-out;
}

/* Score count-up animation */
@keyframes scoreCountUp {
    0% {
        transform: scale(1.5);
        opacity: 0;
        color: #f59e0b;
    }
    50% {
        transform: scale(1.2);
        opacity: 1;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.player-score.updating {
    animation: scoreCountUp 0.5s ease-out;
}

/* Hot dice glow animation */
@keyframes hotDiceGlow {
    0%, 100% {
        box-shadow: 0 0 10px rgba(245, 158, 11, 0.5);
    }
    50% {
        box-shadow: 0 0 30px rgba(245, 158, 11, 1), 0 0 60px rgba(245, 158, 11, 0.5);
    }
}

.dice-container.hot-dice {
    animation: hotDiceGlow 1s ease-in-out;
    border-radius: 12px;
}

/* Button press animation */
.btn:active {
    transform: scale(0.95);
    transition: transform 0.1s;
}

/* Smooth transitions */
.player-card,
.die,
.btn,
.game-message {
    transition: all 0.3s ease;
}

/* Message slide-in animation */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.game-message:not(:empty) {
    animation: slideIn 0.3s ease-out;
}

.player-card .player-name {
    font-size: 1.2rem;
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 10px;
}

.player-card .player-score {
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.game-board {
    background: white;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    max-width: 800px;
    margin: 0 auto;
}

.turn-info {
    text-align: center;
    margin-bottom: 30px;
}

.turn-info h2 {
    color: #2c3e50;
    margin-bottom: 10px;
}

.turn-info p {
    font-size: 1.2rem;
    color: #7f8c8d;
}

.held-dice-section {
    margin: 20px 0;
    padding: 15px;
    background: #f7fafc;
    border-radius: 8px;
    border: 2px dashed #cbd5e0;
}

.held-dice-section h4 {
    margin: 0 0 10px 0;
    color: #4a5568;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.held-dice-container {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    min-height: 50px;
    align-items: center;
}

.held-dice-group {
    display: flex;
    gap: 8px;
    padding: 8px;
    background: white;
    border-radius: 6px;
    border: 1px solid #cbd5e0;
}

.dice-container {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin: 30px 0;
    flex-wrap: wrap;
    min-height: 100px;
}

.die {
    width: 60px;
    height: 60px;
    background: white;
    border: 3px solid #2c3e50;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
}

.die.held {
    width: 50px;
    height: 50px;
    font-size: 1.5rem;
    background: #e2e8f0;
    border: 2px solid #718096;
    cursor: default;
    opacity: 0.8;
}

.die:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.die.selected {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: #667eea;
    transform: scale(1.1);
    box-shadow: 0 6px 12px rgba(102, 126, 234, 0.4);
}

.game-controls {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin: 30px 0;
}

.game-controls .btn {
    min-width: 150px;
}

.game-message {
    text-align: center;
    padding: 15px;
    margin-top: 20px;
    border-radius: 5px;
    font-weight: 500;
    min-height: 50px;
}

.game-message.info {
    background: #d6eaf8;
    color: #2c3e50;
}

.game-message.success {
    background: #d5f4e6;
    color: #27ae60;
}

.game-message.error {
    background: #fadbd8;
    color: #e74c3c;
}

.game-message.warning {
    background: #fcf3cf;
    color: #f39c12;
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }

    header h1 {
        font-size: 2rem;
    }

    .lobby {
        padding: 20px;
    }

    .join-game {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .join-game label {
        margin-bottom: 5px;
    }
    
    .message-toast {
        right: 10px;
        left: 10px;
        max-width: none;
    }
    
    .game-info {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }
    
    .game-actions-buttons {
        flex-direction: column;
    }
    
    .game-board {
        padding: 20px;
    }
    
    .die {
        width: 50px;
        height: 50px;
        font-size: 1.5rem;
    }
    
    .die.held {
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
    }
    
    .held-dice-section {
        padding: 10px;
    }
    
    .held-dice-container {
        gap: 12px;
    }
    
    .held-dice-group {
        gap: 6px;
        padding: 6px;
    }
    
    .game-controls {
        flex-direction: column;
    }
    
    .game-controls .btn {
        width: 100%;
    }
    
    .scoreboard {
        gap: 10px;
    }
    
    .player-card {
        min-width: 150px;
        padding: 15px;
    }
    
    .player-card .player-score {
        font-size: 1.5rem;
    }
    
    main {
        flex-direction: column;
    }
    
    .scoring-rules {
        position: relative;
        top: 0;
        width: 100%;
        min-width: auto;
    }
    
    .scoring-rules h3 {
        font-size: 1.1rem;
    }
    
    .rules-section h4 {
        font-size: 0.85rem;
    }
    
    .rules-section li {
        font-size: 0.9rem;
    }
}
