:root {
  --primary: #00a9b7;
  --accent: #a2c550;
  --text-dark: #333;
  --background: #f4fdfc;
  /* Custom colors based on primary/accent for the Top 5 section */
  --header-bg: var(--primary); 
  --header-text: #fff;
  --category-bg: #e0f8f9; /* Lightened primary for category title */
  --category-border: var(--accent);
}

body {
  margin: 0;
  font-family: sans-serif;
  background: var(--background);
  color: var(--text-dark);
  display: flex;
  flex-direction: column;
  align-items: center;
}

header {
  width: 100%;
  background: white;
  text-align: center;
  padding: 40px 10px 10px;
}

header img {
  max-height: 100px;
}

header h1 {
  margin: 20px 0 0;
  font-size: 2em;
  color: white;
  background: var(--primary);
  padding: 20px;
}

.no-results-message {
    text-align: center;
    padding: 40px 20px;
    margin: 20px auto;
    max-width: 600px;
    background: white;
    border: 2px dashed var(--primary);
    border-radius: 8px;
    color: var(--text-dark);
    font-size: 1.2rem;
    font-style: italic;
}

/* --- Race Tabs --- */
.race-tabs-container {
  width: 100%;
  background: var(--primary);
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.race-tabs-container button {
  background: none;
  border: none;
  padding: 15px 25px;
  font-size: 1.1rem;
  font-weight: bold;
  color: white;
  cursor: pointer;
  outline: none;
  transition: background-color 0.3s;
}

.race-tabs-container button:hover:not(.active) {
  background: rgba(0, 0, 0, 0.1);
}

.race-tabs-container .active {
  background: var(--accent);
  color: var(--text-dark);
}
/* -------------------------- */

.filters {
  background: white;
  width: 100%;
  max-width: 700px; 
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  padding: 20px;
  border-bottom: 1px solid #ddd;
}

.filters select, .filters input {
  padding: 8px;
  font-size: 1rem;
  border: 1px solid var(--primary);
  border-radius: 4px;
}

.filters.hidden {
  display: none;
}

/* --- Loading Indicator Styles --- */
#loadingIndicator {
  width: 100%;
  max-width: 700px;
  padding: 30px;
  text-align: center;
  font-size: 1.5em;
  font-weight: bold;
  color: var(--primary);
  background: white;
  border: 1px solid var(--primary);
  border-radius: 4px;
  margin-top: 20px;
  /* Animation */
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}
/* -------------------------------------- */


.results {
  width: 100%;
  max-width: 700px;
  padding: 20px;
}

/* Standard Table Styles (for race filtering view) */
table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  box-shadow: 0 0 10px rgba(0,0,0,0.05);
}

th, td {
  padding: 10px;
  border-bottom: 1px solid #ddd;
  text-align: left;
}

th {
  background-color: var(--accent);
  color: #fff;
}

tr:nth-child(even) {
  background: #f0f9f9;
}

/* --- Top 5 General Container --- */
.top-5-view {
    width: 100%;
    padding: 0 20px;
    box-sizing: border-box;
}

.top-5-view h2 {
    text-align: center;
    color: var(--text-dark);
    margin-top: 30px;
    border-bottom: 2px solid var(--accent);
    padding-bottom: 10px;
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
}

/* --- Desktop Layout (Default: Side-by-Side Grid) --- */
#desktop-top5-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  max-width: 1200px; /* Max width for the dual columns */
  margin: 20px auto;
}

/* Hide mobile list by default */
#mobile-top5-list {
    display: none;
}

/* The main columns for Male/Female in desktop view */
.gender-column {
  border: 1px solid var(--header-bg);
  background: white;
  border-radius: 4px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column; /* Allows content sections to stack */
}

.gender-column h3 {
  background: var(--header-bg);
  color: var(--header-text);
  margin: 0;
  padding: 15px;
  text-align: center;
  font-size: 1.5em;
  border-radius: 4px 4px 0 0;
}

/* --- Mobile Layout (Interleaved Section Styling) --- */
.mobile-section-wrapper {
    max-width: 700px;
    margin: 20px auto;
}

.mobile-gender-section {
    border: 1px solid var(--primary);
    background: white;
    border-radius: 4px;
    margin-bottom: 15px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.mobile-gender-header {
    background: var(--primary);
    color: var(--header-text);
    margin: 0;
    padding: 12px;
    text-align: center;
    font-size: 1.2em;
    border-radius: 4px 4px 0 0;
}

/* Container for a set of results (Scratch or Category) */
.results-group {
    padding: 10px;
    margin-bottom: 10px;
    flex-grow: 1; 
    display: flex;
    flex-direction: column;
}

.results-group:last-of-type {
    margin-bottom: 0;
}

.results-group h4 {
  margin: 0 0 10px;
  padding: 10px;
  background: var(--category-bg);
  color: var(--text-dark);
  border-left: 5px solid var(--category-border);
}

.top-5-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed; /* Ensures column widths are stable */
}

.top-5-table th, .top-5-table td {
  padding: 8px;
  text-align: left;
  border-bottom: 1px dotted #ddd;
}

.top-5-table th:nth-child(1) { width: 10%; } /* Position */
.top-5-table th:nth-child(2) { width: 55%; } /* Name */
.top-5-table th:nth-child(3) { width: 35%; } /* Time */

.top-5-table th {
  background: none;
  color: var(--text-dark);
  font-weight: normal;
}

/* --- CRITICAL FIX: Ensure all table rows/cells have consistent height --- */
.top-5-table td {
    /* Set a fixed minimum line-height and height to prevent collapsing */
    min-height: 1.2em;
    line-height: 1.2em; 
}
/* ------------------------------------------------------------------------ */

.top-5-table tbody tr:hover {
  background: #f0f9f9;
}

/* --- Mobile Specific Overrides --- */
@media (max-width: 768px) {
    /* Hide the desktop grid on small screens */
    #desktop-top5-grid {
        display: none !important;
    }
    /* Show the mobile interleaved list on small screens */
    #mobile-top5-list {
        display: block !important;
    }
    
    /* Remove padding from results group to save screen space */
    .results-group {
        padding: 5px;
    }
    .results-group h4 {
        padding: 8px;
    }
}