/* Unit selection usability hotfix, 2026-10-26. Scoped to Unit screen only.
 * Keep the hidden legacy back-home node: app.js still binds its click handler.
 * Old grade/unit data, keyboard, battle HUD and Admin remain untouched. */
#view-units > #back-home[hidden] { display: none !important; }

/* Fit 12 grade choices on ordinary desktop screens; scroll on shorter screens. */
#view-units .grade-sidebar {
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 80px;
  max-height: calc(100dvh - 94px);
  min-height: 0;
  padding: 9px;
  overflow: hidden;
}
#view-units .grade-sidebar h2 {
  flex: none;
  margin: 0 0 6px;
  padding: 5px 4px;
  font-size: 15px;
  line-height: 1.3;
}
#view-units .grade-menu {
  display: grid;
  grid-auto-rows: minmax(44px, auto);
  gap: 4px;
  min-height: 0;
  max-height: none;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-gutter: stable;
  padding-right: 2px;
}
#view-units .grade-menu button {
  min-height: 44px;
  padding: 4px 8px;
  gap: 7px;
  border-radius: 9px;
}
#view-units .grade-menu button::before {
  width: 27px;
  height: 27px;
  flex: 0 0 27px;
  font-size: 16px;
}
#view-units .grade-menu button strong { font-size: 14px; line-height: 1.2; }
#view-units .grade-menu button small { font-size: 10px; line-height: 1.15; margin-top: 1px; }
#view-units .grade-menu button:focus-visible,
#view-units .selection-tools button:focus-visible {
  outline: 3px solid #ffe381;
  outline-offset: 2px;
}

/* Pagination and Start should never be hidden below a 10-card grid. */
#view-units .selection-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  position: sticky;
  top: 78px;
  z-index: 10;
  margin: 0 0 13px;
  padding: 8px 10px;
  border: 1px solid rgba(210,242,255,.36);
  border-radius: 12px;
  background: rgba(11,54,80,.93);
  box-shadow: 0 6px 14px rgba(3,25,43,.18);
  backdrop-filter: blur(8px);
}
#view-units .selection-tools .unit-pager {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  margin: 0;
  gap: 9px;
}
#view-units .selection-tools .unit-pager.hidden { display: none !important; }
#view-units .selection-tools .unit-pager button { min-height: 42px; min-width: 44px; }
#view-units .selection-tools .unit-pager span { min-width: 86px; }
#view-units .selection-tools .selection-footer {
  margin: 0 0 0 auto;
  flex: 0 0 auto;
}
#view-units .selection-tools #quick-join {
  min-height: 44px;
  padding: 9px 18px;
  font-size: 14px;
}
#view-units .selection-tools #quick-join:disabled { opacity: .55; cursor: not-allowed; }

@media (min-width: 781px) and (max-width: 1040px) {
  #view-units .grade-sidebar { top: 120px; max-height: calc(100dvh - 132px); }
  #view-units .selection-tools { top: 120px; }
}
@media (max-width: 780px) {
  #view-units .grade-sidebar {
    display: block;
    position: static;
    max-height: none;
    overflow: visible;
  }
  #view-units .grade-menu {
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    min-height: 0;
    max-height: none;
    padding: 3px 2px 8px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-gutter: auto;
    -webkit-overflow-scrolling: touch;
  }
  #view-units .grade-menu button {
    flex: 0 0 102px;
    min-width: 102px;
    min-height: 46px;
    padding: 5px 7px;
  }
  #view-units .grade-menu button strong { font-size: 13px; }
  #view-units .selection-tools { position: static; flex-wrap: wrap; }
  #view-units .selection-tools .unit-pager { flex: 1 1 auto; }
}
@media (max-width: 560px) {
  #view-units .selection-tools .unit-pager:not(.hidden) {
    flex: 1 1 100%;
    justify-content: center;
  }
  #view-units .selection-tools .selection-footer { width: 100%; margin: 0; }
  #view-units .selection-tools #quick-join { width: 100%; }
}
