/* ===== CSS CUSTOM PROPERTIES ===== */
:root {
  /* Color System */
  --color-background: #0a0a0b;
  --color-surface: #1a1a1c;
  --color-surface-elevated: #252529;
  --color-border: rgba(255, 255, 255, 0.08);
  --color-border-hover: rgba(255, 255, 255, 0.16);
  --color-border-focus: rgba(59, 130, 246, 0.4);

  /* Text Colors */
  --color-text-primary: #ffffff;
  --color-text-secondary: #a1a1aa;
  --color-text-tertiary: #71717a;

  /* Brand Colors */
  --color-primary: #3b82f6;
  --color-accent: #06b6d4;
  --color-error: #ef4444;
  --color-success: #10b981;

  /* Effects */
  --gradient-primary: linear-gradient(135deg, #3b82f6 0%, #06b6d4 100%);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);

  /* Spacing */
  --space-sm: 1rem;
  --space-md: 1.5rem;
  --space-lg: 2rem;
  --space-xl: 3rem;

  /* Typography */
  --font-family-primary: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-family-mono: 'JetBrains Mono', Consolas, Monaco, monospace;

  /* Transitions */
  --transition-base: 300ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Border Radius */
  --radius-lg: 12px;
  --radius-xl: 16px;
}

/* ===== BASE STYLES ===== */
body {
    background-color: var(--color-background);
    color: var(--color-text-primary);
    font-family: var(--font-family-primary);
    margin: 0;
    padding: var(--space-lg);
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0;
}

/* ===== HEADER ===== */
.header {
    text-align: center;
    margin-bottom: var(--space-xl);
}

.header h1 {
    font-size: clamp(2.5rem, 5vw, 3.5rem);
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: var(--space-sm);
}

/* ===== FENCER SELECTOR ===== */
.fencer-select-container {
    max-width: 600px;
    margin: 0 auto var(--space-xl);
    padding: var(--space-lg);
    background: var(--color-surface);
    border-radius: var(--radius-xl);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
}

.fencer-select-container select {
    width: 100%;
    padding: var(--space-sm);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-md);
    font-size: 1rem;
    background-color: var(--color-background);
    color: var(--color-text-primary);
    transition: var(--transition-base);
}

.fencer-select-container select:focus {
    outline: none;
    border-color: var(--color-border-focus);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.fencer-select-container button {
    width: 100%;
    padding: var(--space-sm) var(--space-lg);
    background: var(--gradient-primary);
    color: white;
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: var(--transition-base);
    box-shadow: var(--shadow-md);
}

.fencer-select-container button:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* ===== STATS CONTAINER ===== */
.stats-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-md);
    margin-bottom: var(--space-xl);
}

.stat-card {
    background: var(--color-surface);
    padding: var(--space-md);
    border-radius: var(--radius-lg);
    text-align: center;
    border: 1px solid var(--color-border);
    transition: var(--transition-base);
}

.stat-card:hover {
    transform: translateY(-4px);
    border-color: var(--color-border-hover);
}

.stat-card h3 {
    font-size: 0.9rem;
    color: var(--color-text-secondary);
    margin-bottom: var(--space-sm);
    font-weight: 500;
    text-transform: uppercase;
}

.stat-card .value {
    font-size: 2.25rem;
    color: var(--color-text-primary);
    font-weight: 700;
    font-family: var(--font-family-mono);
}

/* ===== MATCHES OVERVIEW ===== */
.matches-overview {
    margin-bottom: var(--space-xl);
}

.matches-overview h2 {
    font-size: 1.5rem;
    color: var(--color-text-primary);
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-sm);
    border-bottom: 1px solid var(--color-border);
    text-align: left;
}

.matches-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: var(--space-md);
}

.match-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    transition: var(--transition-base);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    padding: var(--space-md);
}

.match-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background-color: var(--color-text-tertiary);
    transition: var(--transition-base);
}

.match-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--color-border-hover);
}

.match-card.victory::before {
    background-color: var(--color-success);
}

.match-card.defeat::before {
    background-color: var(--color-error);
}

.match-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-sm);
    border-bottom: 1px solid var(--color-border);
}

.match-date {
    font-size: 0.8rem;
    color: var(--color-text-secondary);
    font-weight: 500;
}

.match-tournament {
    font-size: 0.8rem;
    color: var(--color-text-tertiary);
    font-weight: 500;
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 60%;
}

.match-details {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    flex-grow: 1;
}

.match-players {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.1rem;
    font-weight: 600;
}

.match-players .vs {
    color: var(--color-text-tertiary);
    font-size: 0.9rem;
    margin: 0 var(--space-sm);
}

.match-players .player,
.match-players .opponent {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.match-players .opponent {
    text-align: right;
    color: var(--color-text-secondary);
}

.match-score {
    font-size: 2.25rem;
    font-weight: 700;
    font-family: var(--font-family-mono);
    text-align: center;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin: var(--space-sm) 0;
}

.match-result {
    text-align: center;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.9rem;
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-md);
    margin-top: auto;
}

.match-card.victory .match-result {
    color: var(--color-success);
    background-color: rgba(16, 185, 129, 0.1);
}

.match-card.defeat .match-result {
    color: var(--color-error);
    background-color: rgba(239, 68, 68, 0.1);
}

/* ===== ANALYSIS GRID & CARDS ===== */
.analysis-grid {
    display: grid;    
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: var(--space-lg);
    margin-bottom: var(--space-xl);
}

.analysis-card {
    background: var(--color-surface);
    border-radius: var(--radius-xl);
    padding: var(--space-lg);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
}

.analysis-card h2 {
    font-size: 1.5rem;
    color: var(--color-text-primary);
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-sm);
    border-bottom: 1px solid var(--color-border);
}

.chart-container {
    height: 400px;
    position: relative;
}
.chart-container canvas {
    background-color: rgba(0,0,0,0.2);
    border-radius: var(--radius-lg);
}

/* ===== TABS ===== */
.tabs {
    display: flex;
    margin-bottom: var(--space-md);
    border-bottom: 1px solid var(--color-border);
    gap: var(--space-sm);
}

.tab {
    padding: var(--space-sm) var(--space-md);
    cursor: pointer;
    border: none;
    background: none;
    color: var(--color-text-secondary);
    font-size: 1rem;
    font-weight: 600;
    transition: var(--transition-base);
    border-bottom: 2px solid transparent;
    position: relative;
    top: 1px;
}

.tab.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ===== DATA TABLE ===== */
.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: var(--space-md);
}

.data-table th,
.data-table td {
    padding: var(--space-sm);
    border-bottom: 1px solid var(--color-border);
    text-align: left;
}

.data-table th {
    background: var(--color-surface-elevated);
    font-weight: 600;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    font-size: 0.8rem;
}

.data-table tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

.data-table tr:hover {
    background-color: var(--color-surface-elevated);
}

/* ===== LOADING & ERROR STATES ===== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(10, 10, 11, 0.8);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--color-surface);
    border-top: 4px solid var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.error-message {
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid var(--color-error);
    color: white;
    padding: var(--space-md);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-md);
    text-align: center;
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 768px) {
    .analysis-grid {
        grid-template-columns: 1fr;
    }
    .stats-container {
        grid-template-columns: repeat(2, 1fr);
    }
    .chart-container {
        height: 300px;
    }
}

@media (max-width: 480px) {
    .stats-container {
        grid-template-columns: 1fr;
    }
}