:root {
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --background-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --card-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    --border-radius: 15px;
    --border-radius-small: 10px;
    --text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    --transition: all 0.3s;
    --min-touch-target: 44px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--background-gradient);
    min-height: 100vh;
    padding: 10px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

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

.header {
    text-align: center;
    margin-bottom: 20px;
    color: white;
    text-shadow: var(--text-shadow);
}

.header h1 {
    font-size: clamp(1.8em, 5vw, 3em);
    margin-bottom: 10px;
    animation: slideDown 0.5s ease;
}

.header p {
    font-size: clamp(0.9em, 3vw, 1.2em);
    opacity: 0.9;
}

.card {
    background: white;
    border-radius: var(--border-radius);
    padding: clamp(15px, 3vw, 25px);
    margin-bottom: 15px;
    box-shadow: var(--card-shadow);
    animation: fadeIn 0.6s ease;
}

.card h3 {
    font-size: clamp(1.2em, 3.5vw, 1.5em);
    margin-bottom: 15px;
}

/* Player Management */
.players-section {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.player-input-group {
    display: flex;
    gap: 10px;
    flex: 1;
    min-width: 250px;
}

.player-input {
    flex: 1;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: var(--border-radius-small);
    font-size: 16px;
    transition: var(--transition);
    min-height: var(--min-touch-target);
    -webkit-appearance: none;
    appearance: none;
}

.player-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.players-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 15px;
}

.player-tag {
    background: var(--primary-gradient);
    color: white;
    padding: 8px 12px;
    border-radius: 20px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    animation: slideIn 0.3s ease;
    font-size: clamp(14px, 2.5vw, 16px);
    max-width: 150px;
}

.player-tag span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.player-tag .remove-btn {
    background: rgba(255, 255, 255, 0.3);
    border: none;
    color: white;
    min-width: 24px;
    min-height: 24px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
    font-size: 18px;
    line-height: 1;
    padding: 0;
}

.player-tag .remove-btn:active {
    transform: scale(0.9);
}

/* Buttons */
.btn {
    padding: clamp(10px, 2.5vw, 12px) clamp(16px, 3vw, 24px);
    border: none;
    border-radius: var(--border-radius-small);
    font-size: clamp(14px, 2.5vw, 16px);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    min-height: var(--min-touch-target);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

.btn:active {
    transform: scale(0.95);
}

.btn-primary {
    background: var(--primary-gradient);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #f5f5f5;
    color: #333;
}

.btn-secondary:hover {
    background: #e0e0e0;
}

.btn-danger {
    background: #ff4757;
    color: white;
}

.btn-danger:hover {
    background: #ff3838;
    transform: translateY(-2px);
}

.btn-save {
    background: #10b981;
    color: white;
}

.btn-save:hover {
    background: #059669;
    transform: translateY(-2px);
}

.btn-load {
    background: #3b82f6;
    color: white;
}

.btn-load:hover {
    background: #2563eb;
    transform: translateY(-2px);
}

/* Leaderboard */
.leaderboard {
    background: linear-gradient(135deg, #f5f5f5 0%, #ffffff 100%);
    border-radius: var(--border-radius);
    padding: 20px;
    margin-bottom: 20px;
}

.leaderboard h3 {
    color: #333;
    margin-bottom: 15px;
    font-size: 1.5em;
}

.leader-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: clamp(12px, 2.5vw, 15px);
    margin-bottom: 10px;
    border-radius: var(--border-radius-small);
    background: white;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    transition: var(--transition);
    min-height: 50px;
}

.leader-item:active {
    transform: scale(0.98);
}

.leader-item.gold {
    background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%);
    color: white;
}

.leader-item.silver {
    background: linear-gradient(135deg, #C0C0C0 0%, #808080 100%);
    color: white;
}

.leader-item.bronze {
    background: linear-gradient(135deg, #CD7F32 0%, #8B4513 100%);
    color: white;
}

.leader-rank {
    font-size: clamp(1.2em, 3vw, 1.5em);
    font-weight: bold;
    width: 40px;
    flex-shrink: 0;
}

.leader-name {
    flex: 1;
    font-size: clamp(1em, 2.5vw, 1.2em);
    font-weight: 600;
    padding: 0 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.leader-score {
    font-size: clamp(1.2em, 3vw, 1.5em);
    font-weight: bold;
    flex-shrink: 0;
}

/* Scoring Section */
.scoring-section {
    margin-top: 20px;
}

.score-inputs {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.score-input-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.score-input-group label {
    font-weight: 600;
    color: #555;
    font-size: clamp(12px, 2.5vw, 14px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.score-input {
    padding: 10px;
    border: 2px solid #e0e0e0;
    border-radius: var(--border-radius-small);
    font-size: clamp(16px, 3vw, 18px);
    text-align: center;
    transition: var(--transition);
    min-height: var(--min-touch-target);
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
}

.score-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.qwirkle-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 5px;
    padding: 5px;
    background: #f0f0f0;
    border-radius: 8px;
}

.qwirkle-checkbox input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
    flex-shrink: 0;
}

.qwirkle-checkbox label {
    cursor: pointer;
    color: #667eea;
    font-weight: 600;
    font-size: clamp(12px, 2.5vw, 14px);
    user-select: none;
    -webkit-user-select: none;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.save-load-section {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 2px solid #e0e0e0;
    flex-wrap: wrap;
}

/* History Table */
.history-table {
    overflow-x: auto;
    margin-top: 20px;
    -webkit-overflow-scrolling: touch;
}

.history-table table {
    width: 100%;
    border-collapse: collapse;
    min-width: 300px;
}

.history-table th,
.history-table td {
    padding: clamp(8px, 2vw, 12px);
    text-align: center;
    border-bottom: 1px solid #e0e0e0;
    font-size: clamp(12px, 2.5vw, 14px);
}

.history-table th {
    background: var(--primary-gradient);
    color: white;
    font-weight: 600;
    position: sticky;
    top: 0;
}

.history-table tr:hover {
    background: #f5f5f5;
}

.history-table .total-row {
    font-weight: bold;
    background: #f0f0f0;
}

/* Statistics */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
    margin-top: 20px;
}

.stat-card {
    background: linear-gradient(135deg, #f5f5f5 0%, #ffffff 100%);
    padding: clamp(10px, 2vw, 15px);
    border-radius: var(--border-radius-small);
    text-align: center;
}

.stat-card h4 {
    color: #667eea;
    margin-bottom: 5px;
    font-size: clamp(0.9em, 2.5vw, 1em);
}

.stat-card .stat-value {
    font-size: clamp(1.5em, 4vw, 2em);
    font-weight: bold;
    color: #333;
}

.stat-card .stat-label {
    color: #666;
    font-size: clamp(0.7em, 2vw, 0.9em);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Animations */
@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

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

/* Mobile Responsive */
@media (max-width: 480px) {
    .score-inputs {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .action-buttons {
        flex-direction: column;
    }

    .action-buttons .btn {
        width: 100%;
    }

    .save-load-section {
        flex-direction: column;
    }

    .save-load-section .btn {
        width: 100%;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .header h1 {
        font-size: 2em;
    }

    .player-input-group {
        min-width: 100%;
    }

    .score-inputs {
        grid-template-columns: 1fr;
    }
}