/* The quiz gallery (science:quiz_library): one pinned bar of section tabs
   and kind chips under the site navbar, a grid of cards, and a dialog that
   opens a card. Same family as the planning hub's lesson-resources gallery
   (planning.css, .plan-lr*). Tokens come from science/tokens.css (.hdwk) and
   theme.css; the four strand colours are the course page's (science-unit.css).
   Colour is a fill — the tile, the card head, the bar segments; words stay
   ink. Inter only. */

.qg-page {
  --qg-top: calc(var(--jm-navbar-height, 56px) + 3px);
  --strand: var(--muted);
  --strand-ink: var(--ink);
  --strand-soft: color-mix(in srgb, var(--strand) 12%, var(--paper));
  --strand-on: var(--ink);
  --qg-shadow: 0 1px 3px rgba(0, 0, 0, .06), 0 6px 20px rgba(0, 0, 0, .05);
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--cream);
  -webkit-font-smoothing: antialiased;
}
.qg-page h1, .qg-page h2, .qg-page p, .qg-page a, .qg-page button { font-family: inherit; }
.qg-page a { color: var(--teal); }
.qg-page :focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }
@media (max-width: 991.98px) {
  /* Below 992px the site bar slides away on scroll-down; the pinned bar moves up to 0. */
  body:has(.jm-chrome-hidden) .qg-page { --qg-top: 0px; }
}

.qg-wrap { max-width: 1320px; margin: 0 auto; padding: 18px 24px 80px; }

/* ---- the head: one title, one line, the way back ---- */
.qg-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin: 0 0 14px; }
.qg-h { margin: 0; font-size: 24px; font-weight: 700; line-height: 1.2; color: var(--ink); }
.qg-lede { margin: 2px 0 0; font-size: 14px; color: var(--muted); }
.qg-page .qg-back {
  flex: none; display: inline-flex; align-items: center; min-height: 36px; padding: 0 13px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--paper);
  font-size: 13.5px; font-weight: 600; color: var(--ink); text-decoration: none; white-space: nowrap;
}
.qg-page .qg-back:hover { background: var(--soft); border-color: var(--teal2); }

/* ---- your homework: first, apart, compact ---- */
.qg-hw { margin: 0 0 18px; padding: 12px 14px 14px; border: 1px solid var(--accent-line); border-radius: 14px; background: var(--accent-soft); }
.qg-page .qg-hw__h { margin: 0 0 8px; font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink); }
.qg-hw__list { display: flex; flex-direction: column; gap: 6px; }
.qg-page .qg-hw__item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px 14px; min-height: 48px;
  padding: 8px 12px; border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 10px;
  background: var(--paper); color: var(--ink); text-decoration: none;
}
.qg-page .qg-hw__item:hover { border-color: var(--teal2); border-left-color: var(--accent); }
.qg-hw__main { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; min-width: 0; }
.qg-hw__title { font-size: 15px; font-weight: 700; }
.qg-hw__meta { font-size: 13px; color: var(--muted); }
.qg-hw .hws-label { display: inline; font-size: 13px; color: var(--muted); }
.qg-hw .hws-status { flex: none; font-size: 14px; }
.qg-hw .hws-comment, .qg-hw .hws-label { font-family: inherit; }

/* ---- the gallery ---- */
.qg { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; scroll-margin-top: calc(var(--qg-top) + 6px); }
.qg [hidden] { display: none !important; }
/* Without JavaScript a tab jumps to its first card; land it below the pinned bar. */
.qg-card[id] { scroll-margin-top: calc(var(--qg-top) + 100px); }

/* The bar pins below the site navbar. minmax(0, 1fr): its no-wrap rows must not set the page's width. */
.qg-bar {
  position: sticky; top: var(--qg-top); z-index: 20; display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px;
  margin: 0 -8px; padding: 7px 8px 8px; background: var(--paper); border-bottom: 1px solid var(--line);
  box-shadow: 0 6px 14px -10px rgba(0, 0, 0, .25);
}
.qg-bar__row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.qg-bar__row:first-child { overflow-x: auto; scrollbar-width: none; }
.qg-bar__row:first-child::-webkit-scrollbar { display: none; }

.qg-units { display: inline-flex; flex: none; gap: 2px; padding: 2px; border: 1.5px solid var(--line); border-radius: 999px; }
.qg-page .qg-unit { padding: 4px 11px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--ink); text-decoration: none; white-space: nowrap; }
.qg-page .qg-unit:hover { background: var(--soft); }
.qg-page .qg-unit.is-on { background: var(--ink); color: #fff; }

.qg-tabs { display: flex; gap: 2px; flex: 1; min-width: 0; }
.qg-page .qg-tab {
  flex: none; padding: 7px 10px 5px; border-bottom: 3px solid transparent; border-radius: 6px 6px 0 0;
  font-size: 14px; font-weight: 600; color: var(--ink); text-decoration: none; white-space: nowrap;
}
.qg-page .qg-tab:hover { background: var(--soft); }
.qg-page .qg-tab.is-on { border-bottom-color: var(--accent); font-weight: 700; }
.qg-tab__n, .qg-chip__n { font-size: 12px; font-weight: 600; color: var(--muted); margin-left: 3px; }
.qg-tab.is-on .qg-tab__n { color: var(--ink); }

.qg-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.qg-chip {
  font: inherit; font-size: 13px; font-weight: 600; color: var(--ink); background: var(--paper);
  border: 1.5px solid var(--line); border-radius: 999px; padding: 4px 12px; cursor: pointer; white-space: nowrap;
}
.qg-chip:hover { border-color: var(--teal2); }
.qg-chip.is-on { background: var(--teal); border-color: var(--teal); color: #fff; }
.qg-chip.is-on .qg-chip__n { color: #fff; opacity: .85; }
.qg-chip:disabled { opacity: .45; cursor: default; }
.qg-chip:disabled:hover { border-color: var(--line); }
.qg-count { margin-left: auto; font-size: 12.5px; font-weight: 600; color: var(--muted); white-space: nowrap; }

/* Under a section tab, the section's full title once. */
.qg-sechead { margin: 2px 0 -2px; font-size: 15px; color: var(--ink); }
.qg-sechead span { color: var(--muted); font-size: 13px; margin-left: 6px; }

.qg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 10px; }

/* Strands, as on the course page: matter teal, atom cyan, table gold, change
   tangerine. Revision and stories take the hub's test/answers colours. */
.qg-strand-matter { --strand: var(--teal2); --strand-ink: var(--teal); }
.qg-strand-atom { --strand: var(--cyan); --strand-ink: color-mix(in srgb, var(--cyan) 38%, var(--ink)); }
.qg-strand-table { --strand: var(--gold); --strand-ink: var(--gold-ink); }
.qg-strand-change { --strand: var(--tangerine); --strand-ink: color-mix(in srgb, var(--tangerine) 60%, var(--ink)); }
.qg-card--revision, .qg-dlg--revision { --strand: var(--ib-blue); --strand-ink: var(--ib-blue); --strand-on: #fff; }
.qg-card--story, .qg-dlg--story { --strand: var(--bs-green); --strand-ink: var(--bs-green); --strand-on: #fff; }
.qg-strand-matter, .qg-strand-atom, .qg-strand-table, .qg-strand-change, .qg-card--revision, .qg-card--story, .qg-dlg--revision, .qg-dlg--story {
  --strand-soft: color-mix(in srgb, var(--strand) 14%, var(--paper));
}

.qg-page .qg-card {
  display: flex; flex-direction: column; gap: 3px; padding: 0 0 10px; min-height: 44px;
  background: var(--paper); border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
  color: var(--ink); text-decoration: none; box-shadow: var(--qg-shadow); transition: transform .12s, box-shadow .12s;
}
.qg-page .qg-card:hover { transform: translateY(-2px); box-shadow: 0 2px 6px rgba(0, 0, 0, .07), 0 10px 26px rgba(0, 0, 0, .08); }
.qg-card__head { display: flex; align-items: center; gap: 9px; padding: 8px 10px; margin-bottom: 4px; background: var(--strand-soft); }

/* The element tile: the section number small, its symbol large. */
.qg-tile {
  position: relative; flex: 0 0 40px; height: 40px; display: grid; place-items: center;
  border-radius: 10px; background: var(--strand); color: var(--strand-on);
}
.qg-tile i { position: absolute; top: 3px; left: 5px; font-size: 9px; font-style: normal; font-weight: 700; line-height: 1; white-space: nowrap; }
.qg-tile b { margin-top: 7px; font-size: 15px; font-weight: 700; line-height: 1; }
.qg-kind { font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--strand-ink); }

.qg-card__name { padding: 0 10px; font-size: 14px; font-weight: 600; line-height: 1.3; text-wrap: balance; }
.qg-card__meta { padding: 0 10px; font-size: 12.5px; color: var(--muted); }
.qg-card__doing { display: flex; flex-wrap: wrap; gap: 0 7px; padding: 0 10px; font-size: 11.5px; color: var(--muted); }
.qg-levels { display: block; width: calc(100% - 20px); height: 4px; margin: 4px 10px 0; border-radius: 2px; overflow: hidden; }
.qg-lv--easy { fill: var(--teal2); }
.qg-lv--medium { fill: var(--gold); }
.qg-lv--hard { fill: var(--accent); }

.qg-empty { margin: 8px 0; padding: 22px; text-align: center; font-size: 14px; color: var(--muted); border: 1px dashed var(--line); border-radius: 12px; }

/* ---- the dialog: a card at a glance and one Start ---- */
dialog.qg-dlg {
  width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 0; border: 0; border-radius: 16px;
  background: var(--paper); color: var(--ink); font-family: var(--font-body);
  box-shadow: 0 30px 80px color-mix(in srgb, var(--ink) 35%, transparent);
}
dialog.qg-dlg[open] { display: flex; flex-direction: column; overflow: hidden; }
dialog.qg-dlg::backdrop { background: color-mix(in srgb, var(--ink) 55%, transparent); }
.qg-dlg__head { display: flex; align-items: center; gap: 10px; padding: 12px 12px 12px 14px; background: var(--strand-soft); }
.qg-dlg__meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.qg-dlg__title { margin: 0; font-size: 18px; font-weight: 700; line-height: 1.25; }
.qg-dlg__x, .qg-dlg__nav {
  width: 36px; height: 36px; flex: none; border: 1.5px solid var(--line); border-radius: 50%; background: var(--paper);
  color: var(--ink); font: inherit; font-size: 20px; line-height: 1; cursor: pointer;
}
.qg-dlg__x:hover, .qg-dlg__nav:hover { background: var(--soft); border-color: var(--teal2); }
.qg-dlg__nav:disabled { opacity: .35; cursor: default; }
.qg-dlg__nav:disabled:hover { background: var(--paper); border-color: var(--line); }
.qg-dlg__body { display: grid; gap: 6px; padding: 12px 16px 4px; overflow: auto; }
.qg-dlg__body p { margin: 0; font-size: 14.5px; line-height: 1.45; }
.qg-dlg__line { color: var(--ink); }
.qg-dlg__facts { color: var(--muted); }
.qg-dlg__levels .qg-levels { width: 100%; margin: 0; height: 6px; }
.qg-dlg__do { color: var(--ink); }
.qg-dlg__note { color: var(--muted); font-size: 13.5px; }
.qg-dlg__actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 16px 12px; }
.qg-page .qg-btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 18px;
  border-radius: 10px; font-size: 15px; font-weight: 700; text-decoration: none;
}
.qg-page .qg-btn--solid { background: var(--teal); color: #fff; }
.qg-page .qg-btn--solid:hover { background: var(--teal-deep); color: #fff; }
.qg-page .qg-btn--outline { background: var(--paper); color: var(--teal); border: 1.5px solid var(--teal); }
.qg-page .qg-btn--outline:hover { background: var(--soft); }
.qg-dlg__foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--line); }
.qg-dlg__pos { font-size: 12.5px; font-weight: 600; color: var(--muted); }

@media (max-width: 640px) {
  .qg-wrap { padding: 12px 16px 72px; }
  .qg-head { margin-bottom: 10px; }
  .qg-h { font-size: 21px; }
  .qg-lede { font-size: 13px; }
  .qg-hw { padding: 10px 10px 10px; }
  /* Title and status on one line, the count and due date under them. */
  .qg-page .qg-hw__item { flex-wrap: wrap; row-gap: 0; padding: 7px 10px; }
  .qg-hw__main { flex: 1 1 0; display: grid; gap: 0; }
  .qg-hw__main > * { grid-column: 1; }
  .qg-hw__title { font-size: 14.5px; }
  .qg-hw__meta, .qg-hw .hws-label { font-size: 12.5px; }
  .qg-hw .hws-status { font-size: 13px; align-self: flex-start; margin-top: 2px; }
  .qg-bar { margin: 0 -16px; padding: 5px 12px 6px; gap: 4px; }
  .qg-page .qg-tab { padding: 6px 9px 4px; font-size: 13.5px; }
  .qg-bar__row:last-child { overflow-x: auto; scrollbar-width: none; }
  .qg-bar__row:last-child::-webkit-scrollbar { display: none; }
  .qg-chips { flex-wrap: nowrap; }
  .qg-chip { flex: none; padding: 3px 10px; font-size: 12.5px; }
  .qg-count { display: none; }
  .qg-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .qg-card__head { gap: 7px; padding: 7px 8px; }
  .qg-tile { flex-basis: 36px; height: 36px; }
  .qg-card__name { font-size: 13.5px; }
  dialog.qg-dlg { width: calc(100vw - 24px); }
  .qg-dlg__body p { font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  .qg-page .qg-card { transition: none; }
  .qg-page .qg-card:hover { transform: none; }
}
