body {
  font-family: sans-serif;
  margin: 0;
  background: #f5f5f5;
}

header {
  background-color: #222;
  color: white;
  padding: 1rem;
  text-align: center;
}

/* Style for the main header title */
#header-title {
  color: #ffd700; /* Gold color from popup headers */
}

/* Reduce space below the main header */
header h1 {
  margin-bottom: 0.25rem;
}

/* Style for the stats line */
#stats {
  font-size: 1.4rem; /* Smaller font size */
  color: #6495ED; /* Cornflower Blue - a cool blue */
  margin-top: 0.5rem; /* Space below the main title */
  margin-bottom: 1rem; /* Space above the buttons */
}


#sort-buttons {
  display: flex;
  justify-content: center;
  align-items: center; /* Align items vertically for wrappers */
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

/* Common styles for all main sort buttons and sub-menu buttons */
#sort-buttons button, 
.sub-menu-button {
  padding: 0.5rem 1rem;
  border: none;
  color: white;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

/* Default background for main sort buttons (including those in wrappers) */
#sort-buttons > button, /* Targets buttons directly under #sort-buttons */
#height-main-button,
#age-main-button {
 background-color: #444;
}


/* Hover state for main sort buttons and sub-menu buttons */
#sort-buttons button:hover, 
.sub-menu-button:hover {
  background-color: #666;
}

/* Active state for main sort buttons (including those in wrappers) and sub-menu buttons */
#sort-buttons button.active, 
#height-main-button.active,
#age-main-button.active,
.sub-menu-button.active {
  background-color: #007bff; /* A distinct color for active button */
  color: white;
}

/* Wrapper for sort button and its sub-menu */
.sort-button-wrapper {
  position: relative;
  display: inline-block; /* Allows it to sit in the flex row */
}

.sub-menu {
  position: absolute;
  top: 100%; /* Position below the main button */
  left: 50%;
  transform: translateX(-50%);
  margin-top: 5px; /* Small gap between button and sub-menu */
  background-color: #333;
  border-radius: 4px;
  padding: 0.3rem;
  z-index: 100;
  display: flex;
  gap: 0.3rem;
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.sub-menu.hidden {
  display: none !important; /* Use important to ensure it overrides flex if parent is flex */
}

.sub-menu-button {
  background-color: #555;
  font-size: 0.9em;
  padding: 0.4rem 0.8rem; /* Slightly smaller padding for sub-buttons */
}

main {
  padding: 1rem;
}

#cloud {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.idol {
  padding: 0.4rem 6px;
  box-sizing: border-box;
  text-align: center;
  font-weight: bold;
  border-radius: 6px;
  color: white;
  transition: transform 0.4s ease, box-shadow 0.3s ease, outline 0.3s ease;
  background: gray; /* Default background, will be overridden by gradient */
  cursor: pointer;
  position: relative;
}

.highlight-birthday {
  outline: 3px solid black;
  outline-offset: 1px;
}

/* Combined style for red outline for height and age highlights */
.highlight-tallest, .highlight-shortest,
.highlight-oldest, .highlight-youngest {
  outline: 3px solid red;
  outline-offset: 1px;
}

.idol-info {
  font-size: 0.75rem;
  opacity: 0.85;
  margin-top: 2px;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

#cloud.hidden {
  visibility: hidden;
  position: absolute;
  left: -9999px;
}

/* Styles for the existing idol tooltip */
#idol-tooltip {
  position: absolute;
  background-color: rgba(30, 30, 30, 0.95);
  color: #fff;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  box-shadow: 0 6px 12px rgba(0,0,0,0.3);
  z-index: 999;
  pointer-events: none;
  transition: opacity 0.2s ease;
  line-height: 1.4;
}

#idol-tooltip.visible {
  opacity: 1;
}

#idol-tooltip.hidden {
  opacity: 0;
}

#idol-tooltip strong {
  font-size: 1.1rem;
  color: #ffd700;
}

#idol-tooltip br + span { /* This style might not be used if your tooltip structure changed */
  display: block;
  margin-top: 0.25rem;
}

#idol-tooltip::before {
  content: '';
  position: absolute;
  top: -10px;
  left: 20px;
  border-width: 0 10px 10px 10px;
  border-style: solid;
  border-color: transparent transparent rgba(30, 30, 30, 0.95) transparent;
}


/* Styles for the group details overlay */
#group-details-overlay {
  position: absolute;
  background-color: rgba(30, 30, 30, 0.95);
  color: #fff;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  box-shadow: 0 6px 12px rgba(0,0,0,0.3);
  z-index: 1000;
  line-height: 1.4;
  max-height: 600px;
  overflow-y: auto;
  width: 200px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

#group-details-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

#group-details-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

#group-details-overlay h3 {
    margin-top: 0;
    margin-bottom: 0.5rem;
    font-size: 1.2rem;
    color: #ffd700;
}

#group-details-overlay ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

#group-details-overlay li {
    margin-bottom: 0.25rem;
    font-size: 0.9rem;
}

#group-details-overlay li strong {
    font-weight: bold;
}

/* Height Distribution Graph */
#height-distribution-container {
    margin: 2rem auto;
    max-width: 900px;
    background-color: #333;
    padding: 1.5rem;
    border-radius: 8px;
    color: white;
    text-align: center;
}

#height-distribution-container.hidden {
    display: none;
}

#height-distribution-container h2 {
    color: #ffd700;
    margin-top: 0;
    margin-bottom: 1.5rem;
}

#height-distribution-graph {
    display: flex;
    justify-content: space-around;
    align-items: flex-end;
    height: 300px;
    padding-bottom: 20px; /* Space for labels */
    border-bottom: 1px solid #555;
}

.graph-bar-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    margin: 0 2px;
    height: 100%;
    position: relative;
}

.graph-bar {
    width: 100%;
    background-color: #6495ED; /* Cornflower Blue to match stats */
    border-radius: 4px 4px 0 0;
    transition: height 0.5s ease;
    min-height: 1px; /* Ensure 0 values have a baseline if needed, though we filter in JS */
}

.graph-bar:hover {
    background-color: #ffd700;
}

.graph-label {
    margin-top: 5px;
    font-size: 0.8rem;
    color: #ccc;
    transform: rotate(-45deg); /* Slant labels if they are tight */
    transform-origin: center top;
}

.graph-count-label {
    margin-bottom: 5px;
    font-size: 0.8rem;
    color: #fff;
    font-weight: bold;
}
/* Update graph container for dot plot */
#height-distribution-graph {
    align-items: flex-end;
    /* Align columns to bottom */
    height: auto;
    /* Let it grow with dots, or fix it */
    min-height: 250px;
    padding-bottom: 20px;
}

.graph-bar-container {
    justify-content: flex-end;
}

/* Container for the stack of dots */
.graph-dots-container {
    display: flex;
    flex-direction: column-reverse;
    /* Stack from bottom up */
    align-items: center;
    gap: 4px;
    /* Space between dots */
    margin-bottom: 8px;
    /* Space between stack and label */
}

.graph-dot {
    width: 14px;
    height: 14px;
    background-color: #6495ED;
    /* Cornflower Blue */
    border-radius: 50%;
    transition: transform 0.2s ease, background-color 0.2s ease;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.graph-dot:hover {
    transform: scale(1.3);
    background-color: #ffd700;
    /* Gold highlight */
    z-index: 10;
}

/* Remove old bar styles if not needed or override */
.graph-bar,
.graph-count-label {
    display: none;
}
/* Update graph container for text chart */
#height-distribution-container {
    max-width: 1400px;
    /* Wider container */
}

/* Container for the stack of text items */
.graph-dots-container {
    display: flex;
    flex-direction: column-reverse;
    /* Stack from bottom up */
    align-items: center;
    gap: 4px;
    /* Space between items */
    margin-bottom: 8px;
    /* Space between stack and label */
    width: 100%;
}

.graph-text-item {
    font-size: 0.75rem;
    padding: 2px 6px;
    background-color: #6495ED;
    /* Cornflower Blue */
    color: white;
    border-radius: 10px;
    /* Pill shape */
    white-space: nowrap;
    transition: transform 0.2s ease, background-color 0.2s ease;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

.graph-text-item:hover {
    transform: scale(1.1);
    background-color: #ffd700;
    /* Gold highlight */
    color: #222;
    z-index: 10;
}

/* Remove dot styles if present */
.graph-dot {
    display: none;
}
/* Re-use CSS for Age Graph */
#age-distribution-container {
    margin: 2rem auto;
    max-width: 1400px;
    background-color: #333;
    padding: 1.5rem;
    border-radius: 8px;
    color: white;
    text-align: center;
}

#age-distribution-container.hidden {
    display: none;
}

#age-distribution-container h2 {
    color: #ffd700;
    margin-top: 0;
    margin-bottom: 1.5rem;
}

#age-distribution-graph {
    display: flex;
    justify-content: space-around;
    align-items: flex-end;
    height: auto;
    min-height: 250px;
    padding-bottom: 20px;
    border-bottom: 1px solid #555;
}

/* Debut Distribution Graph */
#debut-distribution-container {
    margin: 2rem auto;
    max-width: 1400px;
    background-color: #333;
    padding: 1.5rem;
    border-radius: 8px;
    color: white;
    text-align: center;
}

#debut-distribution-container.hidden {
    display: none;
}

#debut-distribution-container h2 {
    color: #ffd700;
    margin-top: 0;
    margin-bottom: 1.5rem;
}

#debut-distribution-graph {
    display: flex;
    justify-content: space-around;
    align-items: flex-end;
    height: auto;
    min-height: 250px;
    padding-bottom: 20px;
    border-bottom: 1px solid #555;
}
