/*
 * EduGames - Interactive Learning Games
 * (c) 2025-2026 Prof. N. All rights reserved.
 *
 * File:    styles/components/data-selector.css
 * Updated: 2026-10-06 17:41
 * Purpose: The subject / topic / subtopic selection (scripts/components/selector.js): the box above a game, the
 *          subject radio buttons of the home page, and the Random button.
 *
 * Wide screens: a label column (100px) at the left of every drop-down. Phones (768px and less): labels above.
 */

/* The box. Its width is set by the game page layout (styles/core/layout.css). */
#selectorWrapper {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  box-sizing: border-box;
  padding: var(--space-3);
  background-color: var(--bg-panel);
  border: var(--border-width-thin) solid var(--border-color);
  border-radius: var(--border-radius-md);
  box-shadow: var(--shadow-sm);
}

/* One row: the label in the left padding, the control filling the rest */
.data-selector-item {
  position: relative;
  box-sizing: border-box;
  min-height: calc(var(--font-size-base) + 2 * var(--space-2) + 2px + 4px);
  padding-left: 100px;
}

.data-selector-label {
  position: absolute;
  top: 0;
  left: 0;
  box-sizing: border-box;
  width: 90px;
  padding-top: calc(var(--space-2) + 1px);
  padding-right: var(--space-3);
  font-weight: var(--font-weight-bold);
  text-align: right;
  color: var(--text-primary);
}

.data-selector-select {
  display: block;
  box-sizing: border-box;
  width: 100%;
  height: calc(var(--font-size-base) + 2 * var(--space-2) + 4px);
  padding: var(--space-2) var(--space-3);
  font-size: var(--font-size-base);
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border: var(--border-width-thin) solid var(--border-color);
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  transition: border-color var(--transition-fast), background-color 0.3s, color 0.3s;
}

.data-selector-select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-primary) 25%, transparent);
}

.data-selector-select:disabled {
  background-color: var(--bg-app);
  color: var(--text-secondary);
  cursor: not-allowed;
}

/* A drop-down with a checkbox on each row (the Topic and Subtopic lists): the button shows what is ticked, the list opens under it */
.check-dropdown {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: var(--space-2);
}

.check-dropdown-button {
  position: relative;
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
  padding-right: 1.8rem;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.check-dropdown-button::after {
  content: '\25BE';
  position: absolute;
  top: 50%;
  right: var(--space-3);
  transform: translateY(-50%);
  color: var(--text-secondary);
}

.check-dropdown-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 50;
  box-sizing: border-box;
  max-height: min(50vh, 22rem);
  margin-top: 2px;
  overflow-y: auto;
  background-color: var(--bg-surface);
  border: var(--border-width-thin) solid var(--border-color);
  border-radius: var(--border-radius-sm);
  box-shadow: var(--shadow-lg);
}

.check-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  color: var(--text-primary);
  cursor: pointer;
}

.check-row:hover {
  background-color: color-mix(in srgb, var(--color-primary) 10%, transparent);
}

.check-row input {
  flex: none;
  width: 1.05rem;
  height: 1.05rem;
  margin: 0;
  cursor: inherit;
}

/* the first row: ticks or clears every row below it */
.check-all {
  font-weight: var(--font-weight-bold);
  border-bottom: var(--border-width-thin) solid var(--border-color);
}

/* a row the game cannot play: gray, with the reason beside the name */
.check-row.is-off {
  color: var(--text-secondary);
  cursor: not-allowed;
}

.check-row.is-off .check-text {
  opacity: 0.7;
}

.check-reason {
  font-size: var(--font-size-sm);
  font-style: italic;
  color: var(--text-secondary);
}

.check-heading {
  padding: var(--space-1) var(--space-3);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-bold);
  color: var(--text-secondary);
  background-color: var(--bg-app);
}

/* The button that clears every selection, at the right end of the Topic list */
.selector-reset {
  flex: none;
  box-sizing: border-box;
  width: calc(var(--font-size-base) + 2 * var(--space-2) + 4px);
  padding: 0;
  font-size: var(--font-size-base);
  line-height: 1;
  color: var(--text-primary);
  background-color: var(--bg-surface);
  border: var(--border-width-thin) solid var(--border-color);
  border-radius: var(--border-radius-sm);
  cursor: pointer;
}

.selector-reset:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.selector-reset:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

/* The next step, one line under the drop-downs */
.data-selector-hint {
  display: block;
  box-sizing: border-box;
  width: 100%;
  margin-top: var(--space-1);
  font-size: var(--font-size-sm);
  color: var(--text-danger);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.data-selector-error {
  box-sizing: border-box;
  margin: var(--space-2) 0 0 100px; /* under the drop-downs, not under the labels */
  padding: var(--space-2);
  font-weight: var(--font-weight-bold);
  text-align: center;
  color: var(--text-danger);
  background-color: var(--bg-danger);
  border: var(--border-width-thin) solid var(--color-danger);
  border-radius: var(--border-radius-md);
}

/* Subject radio buttons (home page and above a game): the label sits on top of the options */
.subject-chooser {
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding-left: 0;
  border: 0;
}

.subject-chooser .data-selector-label {
  position: static;
  display: block;
  width: auto;
  padding: 0 0 var(--space-2);
  text-align: left;
}

.subject-options {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.subject-options label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-primary);
  cursor: pointer;
}

.subject-load {
  margin-top: var(--space-2);
}

/* The Random button lines up with the drop-downs: the label column (100px) is left free */
.random-button {
  align-self: flex-start;
  margin-left: 100px;
}

.data-selector-row .random-button {
  box-sizing: border-box;
  width: calc(100% - 100px);
}

/* Phones: labels above the controls, full width */
@media (max-width: 768px) {
  .data-selector-item {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-1);
    min-height: 0;
    padding-left: 0;
  }

  .data-selector-label {
    position: static;
    display: block;
    width: auto;
    padding: 0 0 var(--space-1);
    text-align: left;
  }

  /* 16px stops iOS from zooming into a focused select; 36px is easier to tap */
  .data-selector-select {
    height: 36px;
    font-size: 16px;
  }

  .data-selector-hint {
    white-space: normal;
  }

  .data-selector-error,
  .random-button {
    margin-left: 0;
  }

  .data-selector-row .random-button {
    width: 100%;
  }
}
