/* 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;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
}

.container {
    margin: 0 auto;
    padding: 12px;
}

/* Header Styles */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding: 6px 10px;
    background: white;
    border-radius: 6px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.header-center {
    display: flex;
    align-items: center;
    gap: 20px;
    flex: 1;
    justify-content: center;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

h1 {
    color: #2c3e50;
    font-size: 1.4rem;
    font-weight: 700;
    margin: 0;
}

.score-section {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
}

.score-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: #2c3e50;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.score-display {
    font-size: 1.6rem;
    font-weight: 800;
    color: #2c3e50;
    text-align: center;
    margin: 0;
    padding: 4px 12px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 6px;
    border: 1px solid #dee2e6;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    min-width: 100px;
}

/* Menu Toggle Button */
.menu-toggle {
    background: #2c3e50;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 1.2rem;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
}

.menu-toggle:hover {
    background: #34495e;
}

.menu-toggle:active {
    background: #1a252f;
}

.menu-icon {
    font-size: 1.4rem;
    font-weight: bold;
}

/* Help Toggle Button */
.help-toggle {
    background: #3498db;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 1.2rem;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    margin-right: 8px;
}

.help-toggle:hover {
    background: #2980b9;
}

.help-toggle:active {
    background: #1f618d;
}

.help-icon {
    font-size: 1.4rem;
    font-weight: bold;
}

/* Side Menu */
.side-menu {
    position: fixed;
    top: 0;
    right: -350px;
    width: 350px;
    height: 100vh;
    background: white;
    box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
    z-index: 9999;
    transition: right 0.3s ease;
    overflow-y: auto;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

.side-menu.open {
    right: 0;
}

.side-menu-header {
    background: #2c3e50;
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #34495e;
}

.side-menu-header h3 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 600;
}

.close-menu {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px;
    border-radius: 3px;
    transition: background-color 0.2s ease;
}

.close-menu:hover {
    background: rgba(255, 255, 255, 0.1);
}

.side-menu-content {
    padding: 20px;
}

.menu-section {
    margin-bottom: 25px;
}

.menu-section h4 {
    color: #2c3e50;
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 12px 0;
    padding-bottom: 8px;
    border-bottom: 1px solid #e9ecef;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.menu-btn {
    background: #f8f9fa;
    color: #2c3e50;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 10px 15px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s ease;
    text-align: left;
}

.menu-btn:hover {
    background: #e9ecef;
    border-color: #adb5bd;
}

.menu-btn:active {
    background: #dee2e6;
}

.menu-btn-danger {
    background: #f8d7da;
    color: #721c24;
    border-color: #f5c6cb;
}

.menu-btn-danger:hover {
    background: #f5c6cb;
    border-color: #f1b0b7;
}

.menu-btn-danger:active {
    background: #f1b0b7;
}

/* Menu Overlay */
.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

.menu-overlay.show {
    opacity: 1;
    visibility: visible;
}

/* Help Menu */
.help-menu {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 500px;
    background: white;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    z-index: 10000;
    border-radius: 12px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
}

.help-menu.show {
    opacity: 1;
    visibility: visible;
}

.help-menu-header {
    background: #3498db;
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 12px 12px 0 0;
    border-bottom: 1px solid #2980b9;
}

.help-menu-header h3 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 600;
}

.close-help {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px;
    border-radius: 3px;
    transition: background-color 0.2s ease;
}

.close-help:hover {
    background: rgba(255, 255, 255, 0.1);
}

.help-menu-content {
    padding: 20px;
}

.help-text {
    color: #2c3e50;
    line-height: 1.6;
}

.help-text p {
    margin: 0;
    font-size: 1rem;
}

/* Help Overlay */
.help-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

.help-overlay.show {
    opacity: 1;
    visibility: visible;
}

/* Hidden Players in Menu */
.hidden-players-list {
    max-height: 200px;
    overflow-y: auto;
}

.no-hidden-players {
    color: #6c757d;
    font-style: italic;
    margin: 0;
    padding: 10px 0;
    text-align: center;
}

.hidden-player-item {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 8px 12px;
    margin-bottom: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    color: #2c3e50;
    transition: all 0.2s ease;
    user-select: none;
}

.hidden-player-item:hover {
    background: #e9ecef;
    border-color: #adb5bd;
}

.hidden-player-item:active {
    background: #dee2e6;
}

/* Emoji Legend */
.emoji-legend {
    padding: 5px 0;
}

.legend-category {
    margin-bottom: 15px;
}

.legend-category h5 {
    color: #495057;
    font-size: 0.85rem;
    font-weight: 600;
    margin: 0 0 8px 0;
    padding-bottom: 4px;
    border-bottom: 1px solid #e9ecef;
}

.legend-items {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0;
    font-size: 0.8rem;
}

.legend-item .emoji {
    font-size: 1.6rem;
    min-width: 24px;
    text-align: center;
}

.legend-item .text {
    color: #6c757d;
    font-size: 0.75rem;
    line-height: 1.2;
}

#teamScore {
    color: #27ae60;
}

#gegnerScore {
    color: #e74c3c;
}

.controls {
    display: flex;
    gap: 6px;
}

/* Button Styles */
.btn {
    padding: 6px 12px;
    border: none;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 70px;
}

.btn-export {
    background-color: #27ae60;
    color: white;
}

.btn-export:hover {
    background-color: #229954;
    transform: translateY(-2px);
}

.btn-reset {
    background-color: #e74c3c;
    color: white;
}

.btn-reset:hover {
    background-color: #c0392b;
    transform: translateY(-2px);
}

.btn-primary {
    background-color: #3498db;
    color: white;
}

.btn-secondary {
    background-color: #95a5a6;
    color: white;
}

/* Stats Container */
.stats-container {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    overflow: auto;
    height: calc(100vh - 120px);
    width: 100%;
}

/* Table Styles */
.stats-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    min-width: 100%;
}

.stats-table thead {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    z-index: 20;
    background-color: #f8f9fa;
}

.group-header-row {
    height: 20px;
    background-color: #f8f9fa;
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    z-index: 21;
}

.stats-table tr {
}

.stats-table th,
.stats-table td {
    padding: 8px 6px;
    text-align: center;
    border: 1px solid #6c757d;
    font-size: 1rem;
    vertical-align: middle;
    white-space: nowrap;
}

.player-header-group {
    background-color: #f8f9fa;
    color: #2c3e50;
    font-weight: 700;
    text-align: center;
    width: 15%;
    min-width: 120px;
    position: sticky;
    left: 0;
    z-index: 25;
    border: 1px solid #6c757d;
    border-bottom: none;
    padding: 4px 8px;
    vertical-align: middle;
}

.player-header {
    background-color: #f8f9fa;
    color: #2c3e50;
    font-weight: 700;
    text-align: left !important;
    padding-left: 12px;
    width: 15%;
    min-width: 120px;
    position: sticky;
    left: 0;
    z-index: 25;
    border: 1px solid #6c757d;
    border-top: none;
    border-bottom: 3px solid #2c3e50 !important;
    box-shadow: 0 3px 0 #2c3e50;
}

.group-header {
    background-color: #f8f9fa;
    color: #2c3e50;
    font-weight: 700;
    font-size: 0.8rem;
    text-align: center;
    padding: 4px 2px;
    position: sticky;
    top: 0;
    z-index: 12;
    border: 1px solid #6c757d;
    border-bottom: none;
    border-right: 1px solid #6c757d;
    vertical-align: middle;
}

.group-header:last-child {
    border-right: none;
}

.action-header {
    background-color: #f8f9fa;
    color: #2c3e50;
    font-weight: 600;
    font-size: 2rem;
    width: 4.25%;
    min-width: 50px;
    position: -webkit-sticky;
    position: sticky;
    top: 20px;
    z-index: 22;
    border: 1px solid #6c757d;
    border-bottom: 3px solid #2c3e50 !important;
    box-shadow: 0 3px 0 #2c3e50;
    padding: 0;
}

/* Darker background for specific columns */
.action-header[title="Tor"],
.action-header[title="Parade"],
.action-header[title="Technischer Fehler"] {
    background-color: #e9ecef;
}

.player-name {
    background-color: #ecf0f1;
    font-weight: 600;
    text-align: left !important;
    padding-left: 12px;
    position: sticky;
    left: 0;
    z-index: 10;
    border-right: 2px solid #bdc3c7;
    width: 15%;
    min-width: 120px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: middle;
}

.player-name.gegner {
    background-color: #e8f4fd;
    color: #2c3e50;
    font-weight: 700;
    border-right: 3px solid #3498db;
    border-bottom: 4px solid #3498db;
}

.player-name.sum {
    background-color: #f8f9fa;
    color: #2c3e50;
    font-weight: 800;
    border-right: 3px solid #6c757d;
    border-top: 2px solid #6c757d;
    position: sticky;
    left: 0;
    bottom: 0;
    z-index: 10;
}

/* Counter Cells */
.counter-cell {
    background-color: #fff;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    width: 4.25%;
    min-width: 50px;
    height: 35px;
    font-weight: 600;
    font-size: 1.4rem;
    vertical-align: middle;
    text-align: center;
    padding: 0;
}

.counter-cell:hover {
    background-color: #f8f9fa;
    transform: scale(1.05);
}

.counter-cell:active {
    background-color: #e3f2fd;
    transform: scale(0.95);
}

.counter-cell.has-value {
    background-color: #e8f5e8;
    color: #2e7d32;
}

.counter-cell.has-value:hover {
    background-color: #d4edda;
}

.counter-cell.sum-cell {
    background-color: #f8f9fa;
    cursor: default;
    font-weight: 700;
    border-top: 2px solid #6c757d;
    position: sticky;
    bottom: 0;
    z-index: 10;
}

.counter-cell.sum-cell:hover {
    background-color: #f8f9fa;
    transform: none;
}

.counter-cell.sum-cell:active {
    background-color: #f8f9fa;
    transform: none;
}

.counter-cell.gegner-cell {
    background-color: #e8f4fd;
    border-bottom: 4px solid #3498db;
}

.counter-cell.gegner-cell:hover {
    background-color: #d1ecf1;
}

.counter-cell.gegner-cell:active {
    background-color: #bee5eb;
}

/* Darker background for specific action columns */
.counter-cell[data-action="⚽"],
.counter-cell[data-action="🫴"],
.counter-cell[data-action="⚠️"] {
    background-color: #e9ecef;
}

.counter-cell[data-action="⚽"]:hover,
.counter-cell[data-action="🫴"]:hover,
.counter-cell[data-action="⚠️"]:hover {
    background-color: #dee2e6;
}

.counter-cell[data-action="⚽"]:active,
.counter-cell[data-action="🫴"]:active,
.counter-cell[data-action="⚠️"]:active {
    background-color: #d1d3d4;
}

/* Context Menu */
.context-menu {
    position: absolute;
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    display: none;
    min-width: 120px;
}

.context-menu-item {
    padding: 12px 16px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-weight: 500;
}

.context-menu-item:hover {
    background-color: #f8f9fa;
}

.context-menu-item:first-child {
    border-radius: 8px 8px 0 0;
}

.context-menu-item:last-child {
    border-radius: 0 0 8px 8px;
}


/* Player Context Menu */
.player-context-menu {
    position: absolute;
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    min-width: 120px;
}

.player-context-menu-item {
    padding: 12px 16px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-weight: 500;
    border-radius: 8px;
}

.player-context-menu-item:hover {
    background-color: #e3f2fd;
    color: #1976d2;
}

/* Hidden Players Section */
.hidden-players-section {
    margin-top: 20px;
    padding: 16px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.hidden-players-section h3 {
    color: #2c3e50;
    font-size: 1.2rem;
    margin-bottom: 12px;
    font-weight: 600;
}

.hidden-players-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.hidden-player-item {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.9rem;
    color: #495057;
    transition: all 0.2s ease;
    user-select: none;
}

.hidden-player-item:hover {
    background: #e3f2fd;
    border-color: #1976d2;
    color: #1976d2;
    transform: translateY(-1px);
}

.hidden-player-item:active {
    transform: translateY(0);
    background: #bbdefb;
}

/* Bottom Controls */
.controls {
    margin-top: 20px;
    display: flex;
    gap: 10px;
    justify-content: center;
    padding: 15px;
    background-color: #f8f9fa;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
    background-color: white;
    margin: 15% auto;
    padding: 30px;
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.modal-content h3 {
    margin-bottom: 20px;
    color: #2c3e50;
    text-align: center;
}

#valueInput {
    width: 100%;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 1.1rem;
    margin-bottom: 20px;
    text-align: center;
}

#valueInput:focus {
    outline: none;
    border-color: #3498db;
}

.modal-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    h1 {
        font-size: 2rem;
    }
    
    .controls {
        flex-direction: column;
        gap: 10px;
    }
    
    .btn {
        min-width: 100px;
        padding: 10px 20px;
    }
    
    .stats-table th,
    .stats-table td {
        padding: 6px 4px;
        font-size: 0.9rem;
    }
    
    .counter-cell {
        height: 32px;
        font-size: 1.3rem;
    }
    
    .player-header {
        min-width: 100px;
        padding-left: 10px;
    }
    
    .action-header {
        min-width: 45px;
        font-size: 1.8rem;
    }
}

@media (max-width: 480px) {
    h1 {
        font-size: 1.5rem;
    }
    
    .stats-table th,
    .stats-table td {
        padding: 4px 3px;
        font-size: 0.8rem;
    }
    
    .counter-cell {
        height: 28px;
        font-size: 1.2rem;
    }
    
    .player-header {
        min-width: 80px;
        padding-left: 8px;
    }
    
    .action-header {
        min-width: 40px;
        font-size: 1.6rem;
    }
    
    .legend-item .emoji {
        font-size: 1.4rem;
        min-width: 20px;
    }
}

/* Mobile and tablet menu fixes */
@media (max-width: 768px) {
    .side-menu {
        width: 100%;
        right: -100%;
        z-index: 9999 !important;
    }
    
    .side-menu.open {
        right: 0;
    }
    
    .menu-overlay {
        z-index: 9998 !important;
    }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
    .counter-cell {
        min-height: 35px;
        min-width: 50px;
    }
    
    .counter-cell:active {
        background-color: #e3f2fd;
        transform: scale(0.95);
    }
    
    /* Mobile menu fixes */
    .side-menu {
        z-index: 9999 !important;
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }
    
    .menu-overlay {
        z-index: 9998 !important;
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }
}

/* Loading and Animation States */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.fade-in {
    animation: fadeIn 0.3s ease-in;
}

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

/* High contrast mode support */
@media (prefers-contrast: high) {
    .counter-cell {
        border: 2px solid #000;
    }
    
    .counter-cell.has-value {
        background-color: #000;
        color: #fff;
    }
}
