:root {
  --background-color: #f5f7fa;
  --border-color: #e0e0e0;
  --button-color: #3498db;
  --button-text: #ffffff;
  --container-bg: #ffffff;
  --hover-color: #f0f0f0;
  --primary-color: #3498db;
  --secondary-color: #2ecc71;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  --text-color: #333333;
}

.dark-mode {
  --background-color: #0e0f0f;
  --border-color: #333333;
  --button-color: #2980b9;
  --container-bg: #1a1a1a;
  --hover-color: #252525;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  --text-color: #e0e0e0;
}

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

body {
  background-color: var(--background-color);
  color: var(--text-color);
  font-family: 'Inter', sans-serif;
  line-height: 1.6;
  transition: background-color 0.3s, color 0.3s;
}

body.dark-mode #SFctr {
  color: #ffffff !important;
}

#SFctr {
  color: #000000 !important;
  font-family: Arial, Helvetica, sans-serif !important;
  margin-left: 21.4px;
}

#SFctr input {
  background-color: #ffffff !important;
  border: 1px solid #c2c2c2 !important;
  color: #000000 !important;
}

#SFctr .SFfrm button,
#SFctr .SFfrm input[type="password"],
#SFctr .SFfrm input[type="text"] {
  border-radius: 6px;
}

#SFusrlogpst i,
#SFusrlogpst input[type="checkbox"],
#SFusrlogpwd i,
#SFusrlogpwd input[type="checkbox"] {
  display: none !important;
}

#SFusrlogpst strong:first-child {
  font-size: 0;
}

#SFusrlogpwd strong {
  position: relative;
  visibility: hidden;
}

#SFusrlogpwd strong::after {
  content: "Forgot Password?";
  font-size: 12px;
  font-weight: 400;
  left: 100px;
  position: absolute;
  top: 13px;
  visibility: visible;
  white-space: nowrap;
}

.container {
  box-sizing: border-box;
  margin: 3px auto;
  max-width: 1200px;
  padding: 0 20px;
}

.chart-wrapper {
  background-color: var(--container-bg);
  border-radius: 10px;
  box-shadow: var(--shadow);
  margin-bottom: 30px;
  padding: 30px;
  position: relative;
  width: 100%;
}

.controls {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin-bottom: 20px;
}

.custom-select-container {
  position: relative;
  width: 178px;
}

.custom-select-container.age-selector {
  width: 66px;
}

.custom-select-container.age-selector .custom-select-trigger {
  padding: 0 8px;
}

.medium-select {
  width: 178px;
}

.custom-select-trigger {
  align-items: center;
  background-color: var(--container-bg);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  box-sizing: border-box;
  color: var(--text-color);
  cursor: pointer;
  display: flex;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  height: 36px;
  padding: 0 12px;
  position: relative;
  user-select: none;
  width: 100%;
}

.custom-select-trigger span {
  display: inline-block;
  max-width: calc(100% - 20px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-select-trigger.has-icon span,
.size-selector .custom-select-trigger span {
  margin-left: 2px;
  max-width: calc(100% - 38px);
}

.custom-select-trigger::after {
  border-bottom: 1.5px solid var(--text-color);
  border-right: 1.5px solid var(--text-color);
  content: '';
  height: 6px;
  margin-left: auto;
  margin-right: 2px;
  opacity: 0.7;
  transform: rotate(45deg) translateY(-2px);
  transition: transform 0.3s;
  width: 6px;
}

.custom-select-trigger.open::after {
  transform: rotate(-135deg) translateY(1px);
}

.custom-select-trigger iconify-icon,
.custom-select-option iconify-icon {
  flex-shrink: 0;
  margin-right: 7px;
  transform: translateY(-1px);
}

.custom-select-options {
  background-color: var(--container-bg);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  box-shadow: var(--shadow);
  display: none;
  font-size: 14px;
  left: 0;
  margin-top: 4px;
  max-height: 320px;
  overflow-y: auto;
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 1000;
}

.custom-select-option {
  align-items: center;
  color: var(--text-color);
  cursor: pointer;
  display: flex;
  padding: 8px 16px;
}

.custom-select-option:hover {
  background-color: var(--hover-color);
}

.custom-select-option.selected {
  background-color: var(--primary-color);
  color: white;
}

.custom-select-options.multi-select .custom-select-option.selected {
  background-color: var(--hover-color) !important;
  color: var(--text-color) !important;
}

.metric-category-header {
  background-color: rgba(0, 0, 0, 0.03);
  border-bottom: 1px solid var(--border-color);
  color: var(--text-color);
  cursor: default;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.7px;
  margin: 8px 0;
  padding: 10px 16px;
  pointer-events: none;
  text-transform: uppercase;
}

.dark-mode .metric-category-header {
  background-color: rgba(255, 255, 255, 0.05);
}

.metric-category-header:first-child {
  margin-top: 0;
}

.custom-select-option[hidden],
.metric-category-header[hidden] {
  display: none !important;
}

.dropdown-search-wrap {
  background-color: var(--container-bg);
  border-bottom: 1px solid var(--border-color);
  padding: 8px;
  position: sticky;
  top: 0;
  z-index: 2;
}

.dropdown-search-wrap input {
  height: 32px;
  width: 100%;
}

.dropdown-search-wrap input[type="search"]::-webkit-search-decoration,
.dropdown-search-wrap input[type="search"]::-webkit-search-cancel-button,
.dropdown-search-wrap input[type="search"]::-webkit-search-results-button,
.dropdown-search-wrap input[type="search"]::-webkit-search-results-decoration {
  -webkit-appearance: none;
  appearance: none;
}

.option-check {
  background-color: var(--container-bg);
  border: 1.5px solid var(--border-color);
  border-radius: 3px;
  flex-shrink: 0;
  height: 16px;
  margin-right: 8px;
  position: relative;
  width: 16px;
}

.custom-select-option.checked .option-check {
  background-color: var(--primary-color);
  border-color: var(--primary-color);
}

.custom-select-option.checked .option-check::after {
  border-color: #fff;
  border-style: solid;
  border-width: 0 2px 2px 0;
  content: '';
  height: 8px;
  left: 4px;
  position: absolute;
  top: 1px;
  transform: rotate(45deg);
  width: 5px;
}

.league-options-divider {
  background-color: var(--border-color);
  height: 1px;
  margin: 6px 0;
}

.scotland-flag-icon {
  background-color: #005EB8;
  background-image: url('https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/svg/1f3f4-e0067-e0062-e0073-e0063-e0074-e007f.svg');
  background-position: center;
  background-size: 150% 150%;
  border-radius: 50%;
  flex-shrink: 0;
  height: 18px;
  margin-right: 8px;
  overflow: hidden;
  width: 18px;
}

input, select {
  background-color: var(--container-bg);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: var(--text-color);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  height: 36px;
  padding: 8px 12px;
}

input:focus, select:focus {
  border-color: var(--primary-color);
  outline: none;
}

#search-bar {
  -webkit-appearance: none;
  appearance: none;
  flex: 0 0 auto;
  width: 188px;
}

.threshold-min-field {
  align-items: center;
  background-color: var(--container-bg);
  border-radius: 6px;
  border: 1px solid var(--border-color);
  box-sizing: border-box;
  cursor: text;
  display: flex;
  flex: 0 0 auto;
  gap: 6px;
  height: 36px;
  padding: 0 10px;
  position: relative;
  width: 108px;
}

.threshold-min-field:focus-within {
  border-color: var(--primary-color);
}

.threshold-label {
  color: var(--text-color);
  flex-shrink: 0;
  font-size: 14px;
  line-height: 1;
  pointer-events: none;
}

.threshold-gt {
  color: var(--text-color);
  display: none;
  flex-shrink: 0;
  font-size: 14px;
  line-height: 1;
  opacity: 0.7;
}

.threshold-min-field.is-empty:not(:focus-within) .threshold-gt,
.threshold-min-field.is-empty:not(:focus-within) #thresholdMin {
  opacity: 0;
  pointer-events: none;
  position: absolute;
  width: 1px;
}

.threshold-min-field:focus-within .threshold-label,
.threshold-min-field:not(.is-empty) .threshold-label {
  display: none;
}

.threshold-min-field:focus-within .threshold-gt,
.threshold-min-field:not(.is-empty) .threshold-gt {
  display: inline;
}

.threshold-min-field:focus-within #thresholdMin,
.threshold-min-field:not(.is-empty) #thresholdMin {
  opacity: 1;
  pointer-events: auto;
  position: static;
  width: auto;
}

#thresholdMin {
  background: transparent;
  border: none;
  border-radius: 0;
  flex: 1 1 auto;
  height: 100%;
  min-width: 0;
  padding: 0;
  width: auto;
}

#thresholdMin:focus {
  border: none;
  outline: none;
}

.btn {
  background-color: var(--button-color);
  border: none;
  border-radius: 6px;
  box-sizing: border-box;
  color: var(--button-text);
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 500;
  height: 36px;
  padding: 8px 16px;
}

.btn-outline {
  background-color: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-color);
}

.btn-outline:hover {
  background-color: var(--hover-color);
}

.btn-icon {
  align-items: center;
  display: flex;
  justify-content: center;
  padding: 0;
  width: 36px;
}

.btn-icon i {
  font-size: 18px;
}

/* Outline Ionicons render thinner than filled ones; match INDEX stopwatch weight. */
.btn-icon i.ion-ios-browsers-outline,
.btn-icon i.ion-ios-stopwatch-outline {
  -webkit-text-stroke: 0.8px currentColor;
  font-weight: bold;
}

.btn-icon.active {
  background-color: var(--primary-color);
  border-color: var(--primary-color);
  color: var(--button-text);
}

.btn-tooltip {
  display: inline-block;
  position: relative;
}

.btn-tooltip-text {
  background-color: var(--container-bg);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  box-shadow: var(--shadow);
  color: var(--text-color);
  font-size: 12px;
  font-weight: normal;
  left: 50%;
  margin-left: -60px;
  opacity: 0;
  padding: 5px;
  pointer-events: none;
  position: absolute;
  text-align: center;
  bottom: 125%;
  transition: opacity 0.3s;
  visibility: hidden;
  width: 120px;
  z-index: 1001;
}

.btn-tooltip-text::after {
  border-color: var(--border-color) transparent transparent transparent;
  border-style: solid;
  border-width: 5px;
  content: "";
  left: 50%;
  margin-left: -5px;
  position: absolute;
  top: 100%;
}

.btn-tooltip:hover .btn-tooltip-text {
  opacity: 1;
  visibility: visible;
}

.template-menu .custom-select-options {
  left: 0;
  min-width: 220px;
  right: auto;
}

.template-menu:has(.menu-trigger.open) > .btn-tooltip-text {
  display: none;
}

.chart-container {
  align-items: center;
  display: flex;
  justify-content: center;
  margin-top: 30px;
  position: relative;
  width: 100%;
}

#scatter-plot {
  display: block;
  height: auto;
  margin: 0 auto;
  max-width: 1082px;
  width: 100%;
}

.plot-loading {
  align-items: center;
  background-color: var(--container-bg);
  bottom: 0;
  display: flex;
  justify-content: center;
  left: 0;
  opacity: 0.92;
  position: absolute;
  right: 0;
  top: 0;
  z-index: 5;
}

.plot-loading[hidden] {
  display: none;
}

.legend {
  display: none;
  flex-wrap: wrap;
  gap: 15px;
  justify-content: center;
  margin-top: 12px;
  padding: 10px 0 0;
  width: 100%;
}

.legend-item {
  align-items: center;
  display: flex;
  font-size: 12px;
}

.legend-color {
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 50%;
  height: 12px;
  margin-right: 5px;
  width: 12px;
}

.tooltip {
  background-color: var(--container-bg);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  box-shadow: var(--shadow);
  font-size: 12px;
  opacity: 0;
  padding: 10px;
  pointer-events: none;
  position: absolute;
  z-index: 1000;
}

circle {
  cursor: pointer;
  transition: r 0.2s, fill 0.2s;
}

circle.search-match {
  animation: circlePulse 1.5s infinite ease-in-out;
  fill: #ff3366 !important;
  filter: drop-shadow(0 0 5px rgba(255, 51, 102, 0.7));
  stroke: #ffffff;
  stroke-width: 2px;
}

.dark-mode circle.search-match {
  fill: #ff3366 !important;
  filter: drop-shadow(0 0 5px rgba(255, 51, 102, 0.7));
  stroke: #0e0f0f;
  stroke-width: 2px;
}

@keyframes circlePulse {
  0% { r: 6; }
  50% { r: 10.5; }
  100% { r: 6; }
}

.team-label {
  pointer-events: none;
  text-shadow: 0px 0px 2px white, 0px 0px 2px white, 0px 0px 2px white, 0px 0px 2px white;
}

.dark-mode .team-label {
  fill: #f5f5f5 !important;
  text-shadow: 0px 0px 2px #1a1a1a, 0px 0px 2px #1a1a1a, 0px 0px 2px #1a1a1a, 0px 0px 2px #1a1a1a;
}

.team-label.search-match {
  animation: labelPulse 1.5s infinite ease-in-out;
  fill: #ff3366 !important;
  filter: drop-shadow(0 0 2px rgba(255, 255, 255, 1));
  font-weight: 700 !important;
  opacity: 1 !important;
}

@keyframes labelPulse {
  0% { font-size: 12px; }
  50% { font-size: 13px; }
  100% { font-size: 12px; }
}

.dark-mode .team-label.search-match {
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, 1));
}

.team-label.search-dimmed {
  opacity: 0 !important;
}

.x-axis path,
.y-axis path,
.x-axis line,
.y-axis line {
  stroke: #333;
}

.x-axis text,
.y-axis text,
.x-label,
.y-label {
  fill: #333;
  font-family: 'Inter', sans-serif;
}

.dark-mode .x-axis path,
.dark-mode .y-axis path,
.dark-mode .x-axis line,
.dark-mode .y-axis line {
  stroke: #444;
}

.dark-mode .x-axis text,
.dark-mode .y-axis text {
  fill: #aaa;
}

.dark-mode .x-label,
.dark-mode .y-label {
  fill: #ccc;
}

.dark-mode .median-line {
  stroke: rgba(255, 255, 255, 0.2) !important;
}

.dark-mode .xy-line {
  opacity: 0.8;
  stroke: #2ecc71;
}

.dark-mode circle {
  stroke-width: 1px;
}

.dark-mode-toggle {
  align-items: center;
  background-color: var(--container-bg);
  border: 1px solid var(--border-color);
  border-radius: 50%;
  bottom: 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex;
  height: 40px;
  justify-content: center;
  position: fixed;
  right: 20px;
  width: 40px;
  z-index: 100;
}

.toggle-icon::before {
  color: var(--text-color);
  content: "\f467";
  font-family: "Ionicons";
  font-size: 30px;
}

.dark-mode .toggle-icon::before {
  content: "\f3b0";
  font-size: 20px;
}

@media (max-width: 768px) {
  .container {
    margin: 30px auto;
    padding: 0 12px;
  }

  .chart-wrapper {
    padding: 15px;
  }

  #scatter-plot {
    min-height: 500px;
  }

  #search-bar {
    width: 158px;
  }

  .btn-tooltip-text {
    display: none;
  }

  .tooltip {
    max-width: 80%;
  }

  .x-label, .y-label {
    font-size: 12px;
  }
}

@media (max-width: 717px) {
  input, select, .custom-select-trigger, .btn {
    font-size: 13px;
    height: 33px;
  }

  .btn-icon {
    height: 33px;
    width: 33px;
  }

  .threshold-min-field {
    height: 33px;
    padding: 0 10px;
  }

  .threshold-label,
  .threshold-gt {
    font-size: 13px;
  }
}
