:root {
    /* Colors - Dark Premium Theme */
    --bg-main: #121212;
    --bg-surface: #1e1e1e;
    --bg-surface-elevated: #2c2c2c;
    --text-primary: #f0f0f0;
    --text-secondary: #a0a0a0;
    --text-muted: #666666;
    
    /* Accents */
    --accent-primary: #3498db;
    --accent-primary-hover: #2980b9;
    --accent-secondary: #2ecc71;
    --accent-secondary-hover: #27ae60;
    --accent-danger: #e74c3c;
    --accent-danger-hover: #c0392b;
    --accent-warning: #f39c12;
    
    /* Teams */
    --team-a-color: #3498db;
    --team-b-color: #e74c3c;
    
    /* Pitch */
    --pitch-bg: #1a3c20;
    --pitch-line: rgba(255, 255, 255, 0.4);
    
    /* Layout */
    --header-height: 120px;
    --mobile-tabs-height: 50px;
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 16px;
    
    /* Shadows */
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 8px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 16px rgba(0,0,0,0.5);
    
    /* Transition */
    --transition-fast: 0.2s ease;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Utilities */
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.hidden { display: none !important; }
.w-100 { width: 100%; }
.w-50 { width: 50%; }
.w-30 { width: 30%; }
.w-70 { width: 70%; }

/* Buttons */
.btn {
    display: inline-block;
    padding: 10px 16px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color var(--transition-fast), transform var(--transition-fast);
    text-align: center;
}
.btn:active { transform: scale(0.98); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-primary { background-color: var(--accent-primary); color: white; }
.btn-primary:hover { background-color: var(--accent-primary-hover); }
.btn-secondary { background-color: var(--bg-surface-elevated); color: var(--text-primary); border: 1px solid #444; }
.btn-secondary:hover { background-color: #3a3a3a; }
.btn-danger { background-color: var(--accent-danger); color: white; }
.btn-danger:hover { background-color: var(--accent-danger-hover); }
.btn-success { background-color: var(--accent-secondary); color: white; }
.btn-success:hover { background-color: var(--accent-secondary-hover); }
.btn-outline { background-color: transparent; border: 1px solid var(--text-secondary); color: var(--text-primary); }
.btn-outline:hover { border-color: var(--text-primary); }

/* Header */
.match-header {
    background-color: var(--bg-surface);
    padding: 12px 16px;
    border-bottom: 1px solid #333;
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.header-top {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.input-match-name {
    flex-grow: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 600;
    padding: 4px;
    border-bottom: 1px solid transparent;
}
.input-match-name:focus { border-bottom-color: var(--accent-primary); outline: none; }

.input-time {
    width: 100px;
    background: var(--bg-surface-elevated);
    border: 1px solid #444;
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    text-align: center;
    font-weight: 600;
}

.scoreboard {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-main);
    padding: 10px 8px;
    border-radius: var(--radius-lg);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.5);
}

.team-input-group { flex: 1; display: flex; align-items: center; gap: 8px; }
.team-input-group-b { justify-content: flex-end; }
.color-picker { width: 28px; height: 28px; border: none; border-radius: 4px; cursor: pointer; padding: 0; background: transparent; }
.color-picker::-webkit-color-swatch-wrapper { padding: 0; }
.color-picker::-webkit-color-swatch { border: 2px solid #555; border-radius: 4px; }

.input-team-name {
    width: 100%;
    background: transparent;
    border: none;
    font-size: clamp(13px, 4vw, 18px);
    font-weight: 700;
    padding: 0;
}
.input-team-name:focus { outline: none; background: rgba(255,255,255,0.05); border-radius: var(--radius-sm); }
.team-a-color { color: var(--team-a-color); }
.team-b-color { color: var(--team-b-color); }

.score-display {
    font-size: 32px;
    font-weight: 700;
    padding: 0 20px;
    display: flex;
    gap: 12px;
    align-items: center;
    font-family: monospace;
}

.header-actions {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
}
.header-actions::-webkit-scrollbar { display: none; }

/* Mobile Tabs */
.mobile-tabs {
    display: flex;
    background-color: var(--bg-surface);
    border-bottom: 1px solid #333;
}
.tab-btn {
    flex: 1;
    background: none;
    border: none;
    padding: 12px 0;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 14px;
    border-bottom: 3px solid transparent;
    transition: var(--transition-fast);
}
.tab-btn.active {
    color: var(--text-primary);
    border-bottom-color: var(--accent-primary);
}

/* Main Content Layout */
.main-content {
    padding: 16px;
    max-width: 1200px;
    margin: 0 auto;
}

.team-section, .events-section {
    display: none;
    animation: fadeIn 0.3s ease;
}
.team-section.active-tab, .events-section.active-tab {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Team Controls */
.team-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--bg-surface);
    padding: 12px;
    border-radius: var(--radius-md);
}

.formation-select {
    background: var(--bg-main);
    color: var(--text-primary);
    border: 1px solid #444;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 600;
}

.team-btn-group {
    display: flex;
    gap: 8px;
}


/* Pitch */
.pitch-wrapper {
    background-color: var(--bg-surface);
    border-radius: var(--radius-lg);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    
}

.pitch-container {
    width: 100%;
    aspect-ratio: 4 / 3.8;
    max-width: 500px;
    background-color: var(--pitch-bg);
    border-radius: 8px;
    position: relative;
    border: 2px solid var(--pitch-line);
    margin: 0 auto;
    
}

.pitch-lines {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none;
}
.halfway-line {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 2px;
    background-color: var(--pitch-line);
}
.center-circle-top {
    position: absolute;
    top: 0; left: 50%; width: 25%; aspect-ratio: 2 / 1;
    border: 2px solid var(--pitch-line);
    border-top: none;
    border-radius: 0 0 100px 100px;
    transform: translateX(-50%);
}
.penalty-area-bottom {
    position: absolute;
    bottom: 0; left: 20%; width: 60%; height: 25%;
    border: 2px solid var(--pitch-line);
    border-bottom: none;
}
.goal-area-bottom {
    position: absolute;
    bottom: 0; left: 35%; width: 30%; height: 8%;
    border: 2px solid var(--pitch-line);
    border-bottom: none;
}

/* Player Cards */
.players-layer {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
}

.player-card {
    position: absolute;
    transform: translate(-50%, -50%);
    width: 90px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    z-index: 10;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.player-card:hover {
    transform: translate(-50%, -50%) scale(1.1);
    z-index: 20;
}

.is-red-carded .player-number-circle,
.is-subbed-out .player-number-circle {
    position: relative;
    background: rgba(120, 120, 120, 0.8) !important;
    border-color: #888 !important;
}

.is-red-carded .player-info,
.is-subbed-out .player-info {
    opacity: 0.6;
}

.player-number-circle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    color: white;
    background: rgba(0,0,0,0.6);
    border: 2px solid #fff;
    box-shadow: var(--shadow-sm);
    position: relative;
}

#pitch-a .player-number-circle { border-color: var(--team-a-color); background: rgba(52, 152, 219, 0.8); }
#pitch-b .player-number-circle { border-color: var(--team-b-color); background: rgba(231, 76, 60, 0.8); }

.captain-badge {
    position: absolute;
    bottom: -4px;
    left: -4px;
    background: var(--accent-warning);
    color: #000;
    font-size: 10px;
    font-weight: 800;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.goal-assist-container {
    position: absolute;
    top: -6px;
    right: -6px;
    display: flex;
    flex-direction: row-reverse;
    gap: 2px;
    z-index: 2;
    filter: drop-shadow(0 1px 1px rgba(0,0,0,0.5));
}
.badge-icon {
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sub-badge {
    position: absolute;
    top: -6px;
    left: -6px;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    filter: drop-shadow(0 1px 1px rgba(0,0,0,0.5));
}
.card-badge {
    position: absolute;
    bottom: -6px;
    right: -6px;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    filter: drop-shadow(0 1px 1px rgba(0,0,0,0.5));
}

.player-info {
    background: rgba(0,0,0,0.7);
    padding: 2px 6px;
    border-radius: 4px;
    text-align: center;
    width: auto;
    max-width: 100%;
    display: inline-block;
    backdrop-filter: blur(4px);
}
.player-card {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.player-name-display {
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}
.player-meta {
    font-size: 9px;
    color: #ccc;
    line-height: 1.2;
}
.player-memo-display {
    font-size: 9px;
    color: #ffd700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    display: block;
}

/* Bench */
.bench-container {
    background-color: var(--bg-surface);
    border-radius: var(--radius-lg);
    padding: 16px;
    box-shadow: var(--shadow-sm);
}
.bench-container h3 {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.bench-players {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    padding-top: 8px;
}
.bench-card {
    position: relative;
    width: calc(25% - 9px);
    max-width: 90px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}
.bench-card:hover {
    transform: scale(1.05);
}

/* Events Section */
.event-controls-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    background: var(--bg-surface);
    padding: 16px;
    border-radius: var(--radius-lg);
}
.btn-event {
    padding: 12px;
    font-size: 16px;
}
.team-a-event { background-color: rgba(52, 152, 219, 0.2); border: 1px solid var(--team-a-color); color: var(--team-a-color); }
.team-b-event { background-color: rgba(231, 76, 60, 0.2); border: 1px solid var(--team-b-color); color: var(--team-b-color); }
.card-yellow { background-color: rgba(241, 196, 15, 0.2); border: 1px solid #f1c40f; color: #f1c40f; }
.card-red { background-color: rgba(192, 57, 43, 0.2); border: 1px solid #c0392b; color: #e74c3c; }

.timeline {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    padding: 16px;
    min-height: 200px;
}
.timeline-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 0;
}
.timeline-event {
    display: flex;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid #333;
    align-items: center;
}
.timeline-event:last-child { border-bottom: none; }
.event-time { font-weight: 700; color: var(--text-secondary); width: 50px; }
.event-icon { font-size: 20px; }
.event-desc { flex-grow: 1; }
.event-delete {
    background: none; border: none; color: var(--text-muted); font-size: 18px; cursor: pointer;
}
.event-delete:hover { color: var(--accent-danger); }

/* Modals */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal.show {
    display: flex;
    animation: modalFadeIn 0.2s ease;
}
@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--bg-surface);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
}
.modal-export-content {
    max-width: 800px;
}
.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h2 { font-size: 18px; }
.close-modal {
    background: none; border: none; color: var(--text-secondary); font-size: 24px; cursor: pointer;
}
.modal-body {
    padding: 20px;
    overflow-y: auto;
}

/* Forms */
.form-row {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
}
.form-group {
    margin-bottom: 12px;
}
.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.form-group input[type="text"],
.form-group input[type="number"],
.form-group select {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-main);
    border: 1px solid #444;
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    font-family: inherit;
}
.form-group input:focus, .form-group select:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.custom-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
}
.custom-checkbox input { display: none; }
.checkmark {
    width: 18px; height: 18px;
    background: var(--bg-main);
    border: 1px solid #555;
    border-radius: 4px;
    display: flex; justify-content: center; align-items: center;
}
.custom-checkbox input:checked + .checkmark {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}
.custom-checkbox input:checked + .checkmark::after {
    content: '';
    width: 4px; height: 8px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    margin-bottom: 2px;
}

.checkbox-row { margin: 20px 0; }

.player-list-container {
    margin-top: 24px;
    border-top: 1px solid #333;
    padding-top: 20px;
}
.registered-players-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 200px;
    overflow-y: auto;
    padding-right: 4px;
}
.registered-players-list::-webkit-scrollbar { width: 6px; }
.registered-players-list::-webkit-scrollbar-thumb { background: #555; border-radius: 3px; }

.list-player-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-surface-elevated);
    padding: 10px 12px;
    border-radius: var(--radius-md);
}
.list-player-info { display: flex; gap: 12px; align-items: center; }
.list-player-actions { display: flex; gap: 8px; }

/* Selection List */
.selection-list .list-player-item { cursor: pointer; transition: background 0.1s; }
.selection-list .list-player-item:hover { background: #3a3a3a; }
.selection-list .list-player-item.selected-starter { border-left: 4px solid var(--accent-primary); }
.selection-list .list-player-item.selected-bench { border-left: 4px solid var(--accent-secondary); }
.selection-badge {
    background: var(--bg-main); color: var(--text-primary);
    font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 10px;
    margin-left: 8px;
}

/* Export */
.export-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin: 20px 0;
}
.export-mode-toggle { margin-bottom: 16px; }
#export-preview-container {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #333;
}
#export-preview-wrapper {
    background: #000;
    border-radius: var(--radius-md);
    overflow: hidden;
    margin: 12px 0;
    display: flex;
    justify-content: center;
}
#export-preview-image {
    max-width: 100%;
    max-height: 400px;
    object-fit: contain;
}
.export-actions {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}
.share-text-preview textarea {
    width: 100%;
    background: var(--bg-main);
    color: var(--text-primary);
    border: 1px solid #444;
    border-radius: var(--radius-sm);
    padding: 8px;
    margin: 8px 0;
    resize: none;
    font-family: inherit;
}

/* Offscreen Export Container */
#offscreen-export-container {
    position: absolute;
    top: -9999px;
    left: -9999px;
    background-color: var(--bg-main);
}
/* Export Specific Styles (applied when rendering offscreen) */
.exporting-mode {
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
}
.exporting-mode .public-hidden { display: none !important; }

/* Multi-page Views */
.view {
    display: none;
    animation: fadeIn 0.3s ease;
}
.view.active {
    display: block;
}

/* Team Management */
.team-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-surface-elevated);
    padding: 16px;
    margin-bottom: 12px;
    border-radius: var(--radius-md);
    border: 1px solid #444;
}
.team-item-info h3 {
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.team-color-swatch {
    width: 16px; height: 16px; border-radius: 4px; border: 1px solid #888;
}

/* Wizard */
.wizard-player-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    border-bottom: 1px solid #333;
    cursor: pointer;
    transition: background 0.2s;
}
.wizard-player-item:hover {
    background: #333;
}
.wizard-player-item.selected {
    background: rgba(52, 152, 219, 0.2);
    border-left: 3px solid var(--accent-primary);
}

/* Desktop Specific */
@media (min-width: 768px) {
    .mobile-tabs { display: none; }
    
    .main-content {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 24px;
        align-items: start;
    }
    
    .team-section {
        display: flex;
        flex-direction: column;
        gap: 16px;
    }
    
    .events-section {
        grid-column: 1 / -1;
        display: block;
        margin-top: 24px;
    }
    
    .event-controls-grid {
        grid-template-columns: repeat(6, 1fr);
    }
}


/* --- Match List --- */
.match-list-item {
    background: #2a2a2a;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
    border: 1px solid #444;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.match-list-info h4 {
    margin: 0 0 5px 0;
    font-size: 1.1rem;
    color: #fff;
}
.match-list-info p {
    margin: 0;
    font-size: 0.9rem;
    color: #aaa;
}
.match-list-actions {
    display: flex;
    gap: 10px;
}

/* --- Face Photo --- */
.player-photo {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
}

/* Make sure number circle stays on top if needed, or hide it */
.player-number-circle.has-photo {
    background: transparent;
    border: 2px solid rgba(255, 255, 255, 0.8);
    box-shadow: none;
}
.player-number-circle.has-photo .number-text {
    position: absolute;
    top: -5px;
    left: -5px;
    background: #000;
    color: #fff;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #fff;
    z-index: 2;
}


@keyframes pulseHighlight {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.7); background-color: var(--accent-danger); color: white; border-color: transparent; }
    50% { transform: scale(1.05); box-shadow: 0 0 0 10px rgba(231, 76, 60, 0); background-color: #c0392b; color: white; border-color: transparent; }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(231, 76, 60, 0); background-color: var(--accent-danger); color: white; border-color: transparent; }
}
.pulse-highlight {
    animation: pulseHighlight 2s infinite;
    font-weight: bold;
}

.category-tabs { display: flex; gap: 8px; margin-bottom: 16px; border-bottom: 2px solid var(--border-color); padding-bottom: 8px; overflow-x: auto; white-space: nowrap; }
.category-tab { padding: 8px 16px; border-radius: var(--radius-md); font-weight: 500; cursor: pointer; transition: all 0.2s; background: transparent; color: var(--text-secondary); border: none; }
.category-tab:hover { background: rgba(0,0,0,0.05); }
.category-tab.active { background: var(--accent-primary); color: white; }
