/* Question subject accordion
   Keeps the subject filter compact while exposing a touch-friendly choice grid. */

/* Both the filter panel and question cards inherit backdrop-filter from the
   shared surface layer, which makes each of them a separate stacking context.
   Keep the whole filter context above the later question-card contexts so the
   absolutely positioned subject and sort menus cannot be painted underneath
   the results list. The sticky header (40) and mobile navigation (90) remain
   above this local layer. */
.questions-workspace > .question-filter-panel {
  position: relative;
  z-index: 30;
  overflow: visible;
}

.question-search-row {
  grid-template-columns: minmax(0, 1fr) minmax(158px, 190px) auto;
  overflow: visible;
}

.question-search-row > .question-search-field {
  grid-column: 1;
  grid-row: 1;
}

.question-search-row > .question-subject-menu {
  grid-column: 2;
  grid-row: 1;
}

.question-search-row > .question-sort-menu {
  grid-column: 3;
  grid-row: 1;
}

.question-subject-menu {
  position: relative;
  min-width: 0;
}

.question-subject-menu > summary {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) 16px;
  width: 100%;
  min-height: 46px;
  align-items: center;
  gap: 8px;
  overflow: hidden;
  border: 1px solid var(--campus-line-strong, #cdd8d1);
  border-radius: 11px;
  background: #fff;
  color: var(--campus-text, #26332e);
  padding: 5px 10px;
  cursor: pointer;
  list-style: none;
}

.question-subject-menu > summary::-webkit-details-marker {
  display: none;
}

.question-subject-menu > summary > .icon {
  width: 18px;
  height: 18px;
  color: var(--campus-green, #14805e);
}

.question-subject-menu > summary:hover {
  border-color: var(--campus-green, #14805e);
  background: var(--campus-green-soft, #edf8f3);
}

.question-subject-menu > summary:focus-visible,
.question-subject-option:focus-visible,
.question-subject-popover-head button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--campus-green, #14805e) 28%, transparent);
  outline-offset: 2px;
}

.question-subject-menu[open] > summary {
  border-color: var(--campus-green, #14805e);
  background: var(--campus-green-soft, #edf8f3);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--campus-green, #14805e) 12%, transparent);
}

.question-subject-summary-copy {
  display: grid;
  min-width: 0;
  gap: 1px;
  text-align: left;
}

.question-subject-summary-copy small {
  color: var(--campus-muted, #6b7772);
  font-size: 9px;
  font-weight: 750;
  line-height: 1;
}

.question-subject-summary-copy strong {
  overflow: hidden;
  color: var(--campus-ink, #17221e);
  font-size: 13px;
  font-weight: 850;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.question-subject-summary-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--campus-muted, #6b7772);
  transform: rotate(90deg);
  transition: transform 160ms ease;
}

.question-subject-summary-chevron .icon {
  width: 15px;
  height: 15px;
}

.question-subject-menu[open] .question-subject-summary-chevron {
  transform: rotate(-90deg);
}

.question-subject-popover {
  position: absolute;
  z-index: 24;
  top: calc(100% + 8px);
  right: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(430px, calc(100vw - 40px));
  max-height: min(500px, calc(100vh - 24px));
  max-height: var(--question-subject-available-height, min(500px, calc(100dvh - 24px)));
  box-sizing: border-box;
  overflow: hidden;
  border: 1px solid var(--campus-line-strong, #cdd8d1);
  border-radius: 14px;
  background: #fff;
  padding: 12px;
  box-shadow: 0 18px 42px rgba(25, 45, 37, 0.16), 0 3px 10px rgba(25, 45, 37, 0.08);
}

.question-subject-menu.opens-up > .question-subject-popover {
  top: auto;
  bottom: calc(100% + 8px);
}

.question-subject-popover-head {
  display: flex;
  min-width: 0;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 2px 11px;
}

.question-subject-popover-head > span {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.question-subject-popover-head strong {
  color: var(--campus-ink, #17221e);
  font-size: 14px;
  font-weight: 900;
}

.question-subject-popover-head small {
  color: var(--campus-muted, #6b7772);
  font-size: 11px;
  line-height: 1.45;
}

.question-subject-popover-head button {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: var(--campus-green-deep, #0f654b);
  padding: 3px 2px;
  font-size: 11px;
  font-weight: 850;
  cursor: pointer;
}

.question-subject-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-height: 0;
  gap: 7px;
  max-height: min(420px, 58vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.question-subject-menu.viewport-tight > .question-subject-popover {
  padding: 8px;
}

.question-subject-menu.viewport-tight .question-subject-popover-head {
  padding-bottom: 7px;
}

.question-subject-menu.viewport-tight .question-subject-popover-head small {
  display: none;
}

.question-subject-menu.viewport-tight .question-subject-option {
  min-height: 48px;
}

.question-subject-option {
  --subject-choice-accent: #64748b;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  min-width: 0;
  min-height: 58px;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--campus-line, #dfe7e2);
  border-radius: 10px;
  background: #fff;
  color: var(--campus-text, #26332e);
  padding: 8px 10px;
  text-align: left;
  cursor: pointer;
  box-shadow: inset 3px 0 0 var(--subject-choice-accent);
}

.question-subject-option.subject-language { --subject-choice-accent: #b85c21; }
.question-subject-option.subject-math { --subject-choice-accent: #2563eb; }
.question-subject-option.subject-english { --subject-choice-accent: #7653a6; }
.question-subject-option.subject-science { --subject-choice-accent: #0f766e; }
.question-subject-option.subject-social { --subject-choice-accent: #9a6b12; }
.question-subject-option.subject-all { --subject-choice-accent: var(--campus-green, #14805e); }

.question-subject-option:hover {
  border-color: color-mix(in srgb, var(--subject-choice-accent) 52%, var(--campus-line, #dfe7e2));
  background: #f8fbf9;
}

.question-subject-option.active {
  border-color: var(--campus-green, #14805e);
  background: var(--campus-green-soft, #edf8f3);
  box-shadow: inset 3px 0 0 var(--campus-green, #14805e), 0 0 0 1px color-mix(in srgb, var(--campus-green, #14805e) 10%, transparent);
}

.question-subject-option-mark {
  display: inline-flex;
  width: 27px;
  height: 27px;
  align-items: center;
  justify-content: center;
  border: 1px solid color-mix(in srgb, var(--subject-choice-accent) 35%, #dfe7e2);
  border-radius: 50%;
  background: color-mix(in srgb, var(--subject-choice-accent) 8%, #fff);
  color: var(--subject-choice-accent);
}

.question-subject-option.active .question-subject-option-mark {
  border-color: var(--campus-green, #14805e);
  background: var(--campus-green, #14805e);
  color: #fff;
}

.question-subject-option-mark .icon {
  width: 14px;
  height: 14px;
  stroke-width: 2.6;
}

.question-subject-option-copy {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.question-subject-option-copy strong {
  overflow: hidden;
  color: var(--campus-ink, #17221e);
  font-size: 13px;
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.question-subject-option-copy small {
  color: var(--campus-muted, #6b7772);
  font-size: 10px;
  font-weight: 700;
}

@media (max-width: 700px) {
  .question-search-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .question-search-row > .question-search-field {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .question-search-row > .question-subject-menu {
    grid-column: 1;
    grid-row: 2;
    width: 100%;
  }

  .question-search-row > .question-sort-menu {
    grid-column: 2;
    grid-row: 2;
  }

  .question-subject-popover {
    right: auto;
    left: 0;
    width: min(430px, calc(100vw - 48px));
  }
}

@media (max-width: 390px) {
  .question-subject-options {
    grid-template-columns: minmax(0, 1fr);
    max-height: 52vh;
  }
}

@media (prefers-reduced-motion: reduce) {
  .question-subject-summary-chevron {
    transition: none;
  }
}
