/* IAL Prep topic bank. Uses the site's colour variables so light and dark mode both work. */
.tb-main {
  max-width: 1240px;
  margin: 0 auto;
  padding: 28px 20px 70px;
}

.tb-status {
  color: var(--muted);
  font-size: 16px;
  margin: 24px 0;
}

.tb-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}
.tb-layout[hidden] { display: none; }   /* not shown, download bar included, until the questions load */

.tb-sidebar {
  position: sticky;
  top: calc(var(--site-nav-h, 0px) + 16px);
  max-height: calc(100vh - var(--site-nav-h, 0px) - 32px);
  max-height: calc(100dvh - var(--site-nav-h, 0px) - 32px);
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 12px;
  box-shadow: var(--shadow-soft);
}

.tb-sidebar h2 {
  margin: 0 0 10px;
  font-size: 15px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--muted);
}

.tb-tree details { margin: 2px 0; }
.tb-tree summary {
  cursor: pointer;
  padding: 7px 8px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.35;
  color: var(--ink);
}
.tb-tree summary:hover,
.tb-tree .tree-leaf:hover,
.tb-tree .tree-all:hover { background: var(--accent-tint); }
.tb-tree .tree-unit > summary { font-weight: 700; color: var(--accent-deep, var(--navy)); }
.tb-tree .tree-topic { margin-left: 8px; }
.tb-tree .tree-topic > summary { font-weight: 600; }
.tb-tree .active { background: var(--accent-tint); outline: 2px solid var(--accent); outline-offset: -2px; }

.tree-go,
.tree-all {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-radius: 8px;
  padding: 6px 8px;
  font: inherit;
  font-size: 13.5px;
  line-height: 1.35;
  color: var(--ink);
  cursor: pointer;
}
.tree-all { font-weight: 700; margin-bottom: 6px; }
/* A spec point: its tick box, then its name as a button. */
.tree-leaf { display: flex; align-items: flex-start; border-radius: 8px; padding-left: 18px; }
.tree-go { flex: 1; min-width: 0; padding-left: 0; }

/* Tick boxes: any number of Units, topics and spec points at once. */
.tree-tick {
  flex: none;
  width: 16px;
  height: 16px;
  margin: 0 7px 0 0;
  vertical-align: -3px;
  accent-color: var(--accent);
  cursor: pointer;
}
.tree-leaf .tree-tick { margin-top: 7px; }

/* The button that closes the topic list on a phone. */
.tb-topics-done { display: none; }

/* Questions done out of the total, on every row of the tree; a bar under each Unit. */
.tb-tree-key { margin: -4px 0 10px; color: var(--muted); font-size: 12.5px; line-height: 1.4; }
.tree-count {
  float: right;
  margin: 0 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.6;
}
.tree-count.is-started { color: var(--accent-strong); }
.tree-count.is-complete { color: #2a7a3b; }
.tree-count.is-complete::before { content: "✓ "; }
.tree-bar {
  display: block;
  clear: both;
  height: 4px;
  margin: 6px 0 2px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--accent-tint);
}
.tree-bar > span { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--accent); }
@media (prefers-reduced-motion: no-preference) {
  .tree-bar > span { transition: width 0.3s cubic-bezier(.2, .9, .2, 1); }
}
:root[data-theme="dark"] .tree-count.is-started { color: var(--accent-deep); }
:root[data-theme="dark"] .tree-count.is-complete { color: #7fd48f; }

/* Text for screen readers only. */
.tb-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.tb-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px 12px;
  align-items: end;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
}

.tb-field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); min-width: 0; }
.tb-field input,
.tb-field select {
  /* A select is as wide as its longest option unless told otherwise, which made the
     whole page wider than a phone screen (and iOS Safari zoomed out to fit it). */
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  font: inherit;
  font-size: 16px; /* 16px or more stops iOS Safari zooming in on focus */
  padding: 9px 10px;
  border: 1px solid var(--line-strong, var(--line));
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
}
.tb-field input:focus-visible,
.tb-field select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.tb-search { grid-column: 1 / -1; }
/* Unit, Topic and Spec point: their own row, wider, since topic names are long. */
.tb-topic-fields {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px 12px;
}
.tb-field select:disabled { opacity: 0.6; cursor: default; }

/* Unit, Topic and Spec point: menus of tick boxes that look like the drop-downs beside them. */
.tb-menu details { position: relative; }
.tb-menu summary {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  list-style: none;
  font-size: 16px;
  line-height: 1.35;
  padding: 9px 32px 9px 10px;
  border: 1px solid var(--line-strong, var(--line));
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tb-menu summary::-webkit-details-marker { display: none; }
.tb-menu summary::after {
  content: "";
  position: absolute;
  right: 13px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-70%) rotate(45deg);
}
.tb-menu details[open] summary::after { transform: translateY(-25%) rotate(225deg); }
.tb-menu summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.tb-menu.is-disabled summary { opacity: 0.6; cursor: default; }
.tb-menu-panel {
  position: absolute;
  z-index: 40;
  top: calc(100% + 4px);
  left: 0;
  box-sizing: border-box;
  width: max(100%, min(420px, calc(100vw - 32px)));
  max-height: min(360px, 60vh);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 6px;
  background: var(--card);
  border: 1px solid var(--line-strong, var(--line));
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 20, 60, 0.18);
  color: var(--ink);
  font-size: 14px;
}
.tb-menu-all {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-radius: 6px;
  padding: 7px 8px;
  font: inherit;
  font-weight: 600;
  color: var(--accent-strong);
  cursor: pointer;
}
.tb-menu-all[aria-pressed="true"] { color: var(--muted); }
.tb-menu-head {
  margin: 10px 8px 2px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--muted);
}
.tb-menu-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 6px;
  line-height: 1.35;
  cursor: pointer;
}
.tb-menu-row input { flex: none; width: 16px; height: 16px; margin: 1px 0 0; accent-color: var(--accent); cursor: pointer; }
.tb-menu-name { flex: 1; min-width: 0; }
.tb-menu-count { color: var(--muted); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.6; }
.tb-menu-row:hover,
.tb-menu-all:hover { background: var(--accent-tint); }
:root[data-theme="dark"] .tb-menu-all { color: var(--accent-deep); }
:root[data-theme="dark"] .tb-menu-all[aria-pressed="true"] { color: var(--muted); }
:root[data-theme="dark"] .tb-menu-panel { box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5); }

.tb-countbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 14px;
  margin: 14px 2px 10px;
}
.tb-count { margin: 0; color: var(--muted); font-size: 14px; }

/* Keyboard shortcuts: the button is only shown where there is a mouse and keyboard. */
.tb-keys-open {
  padding: 4px 8px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.tb-keys-open:hover { background: var(--accent-tint); color: var(--ink); }
@media (hover: none), (pointer: coarse) {
  .tb-keys-open { display: none; }
}
.topicbank kbd {
  display: inline-block;
  min-width: 1.4em;
  padding: 1px 6px;
  border: 1px solid var(--line-strong, var(--line));
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--ink);
  font: 600 12.5px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-align: center;
}

.tb-keys {
  width: min(440px, calc(100vw - 32px));
  box-sizing: border-box;
  padding: 22px 24px 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.25);
}
.tb-keys::backdrop { background: rgba(10, 16, 30, 0.45); }
.tb-keys h2 { margin: 0 0 14px; font-size: 19px; color: var(--accent-deep, var(--navy)); }
.tb-keys dl { display: grid; gap: 8px; margin: 0 0 14px; }
.tb-keys dl > div { display: grid; grid-template-columns: 3em 1fr; align-items: baseline; gap: 10px; }
.tb-keys dt, .tb-keys dd { margin: 0; }
.tb-keys dd { font-size: 15px; }
.tb-keys p { margin: 0 0 16px; color: var(--muted); font-size: 13.5px; line-height: 1.5; }
.tb-keys form { display: flex; justify-content: flex-end; margin: 0; }

/* "Pick up where you left off", over the list when the bank opens without a topic. */
.tb-resume {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  margin: 0 0 14px;
  padding: 12px 16px;
  background: var(--accent-tint);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.tb-resume[hidden] { display: none; }
.tb-resume p { flex: 1 1 280px; margin: 0; color: var(--ink); font-size: 14.5px; line-height: 1.45; overflow-wrap: anywhere; }
.tb-resume-actions { display: flex; gap: 8px; }

/* Space for the navigation bar when the page scrolls to a question or the list. */
.qcard,
.tb-list,
.tb-countbar { scroll-margin-top: calc(var(--site-nav-h, 0px) + 14px); }

.tb-back,
.tb-more,
.tb-topics-toggle {
  background: var(--accent-strong);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 10px 18px;
  font: inherit;
  font-size: 15px;
  cursor: pointer;
}
.tb-back:hover,
.tb-more:hover,
.tb-topics-toggle:hover { background: var(--accent-hover); }
.tb-back { margin-bottom: 12px; }
.tb-more { display: block; margin: 22px auto 0; }
.tb-topics-toggle { display: none; }

.tb-list { display: flex; flex-direction: column; gap: 18px; }

.qcard {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 16px 14px;
  box-shadow: var(--shadow-soft);
}
.qcard.is-done { opacity: 0.72; }
.qcard.is-later { border-left: 5px solid var(--offspec, #e8590c); }

.qcard-name { margin: 0 0 8px; font-size: 18px; line-height: 1.3; color: var(--accent-deep, var(--navy)); }
.qcard-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }

.chip {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent-tint);
  color: var(--accent-deep, var(--navy));
  font-size: 12.5px;
  font-weight: 600;
}
.chip-paper { background: var(--accent-strong); color: #fff; }
.chip-also { background: transparent; border: 1px solid var(--line-strong, var(--line)); color: var(--muted); font-weight: 500; }
.chip-hence { background: var(--offspec-bg, #fff4e6); color: var(--offspec, #e8590c); }

.qcard-img {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.qcard-deps {
  margin: 14px 0 4px;
  padding: 10px 12px;
  background: var(--offspec-bg, #fff4e6);
  border-radius: 8px;
  font-size: 14px;
  color: var(--ink);
}
.qcard-deps ul { margin: 6px 0 0; padding-left: 20px; }
.dep-meta { color: var(--muted); font-size: 12.5px; }
.link-btn {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--accent-strong);
  text-decoration: underline;
  cursor: pointer;
  text-align: left;
}

.qcard-notes { margin-top: 12px; font-size: 14.5px; }
.qcard-notes summary { cursor: pointer; font-weight: 600; color: var(--accent-strong); padding: 4px 0; }
.qcard-notes p { margin: 6px 0; line-height: 1.5; color: var(--ink); word-break: break-word; }

.qcard-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.act {
  background: var(--card);
  border: 1px solid var(--line-strong, var(--line));
  color: var(--ink);
  border-radius: 8px;
  padding: 7px 14px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.act:hover { background: var(--accent-tint); }
.act.on { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.act:disabled { opacity: 0.5; cursor: default; }
.qcard.is-selected { outline: 3px solid var(--accent); outline-offset: -1px; }
/* The question the keyboard shortcuts act on. */
.qcard:focus { outline: none; }
.qcard.is-selected:focus { outline: 3px solid var(--accent); outline-offset: -1px; }
.qcard.is-current { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint), var(--shadow-soft); }

/* Download bar: sticks to the bottom of the screen while you scroll the questions. */
.tb-dl {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 14px;
  margin-top: 22px;
  padding: 12px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px 12px 0 0;
  box-shadow: 0 -6px 18px rgba(0, 20, 60, 0.12);
}
/* Clear of the iPhone home indicator when the page runs edge to edge. */
@supports (padding: env(safe-area-inset-bottom)) {
  .tb-dl { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
}
.tb-dl-count { margin: 0; font-size: 14px; font-weight: 600; color: var(--ink); }
/* Nothing selected yet: just the hint and "Select all". */
.tb-dl.is-empty #dl-clear,
.tb-dl.is-empty .tb-dl-btn { display: none; }
.tb-dl.is-empty .tb-dl-count { font-weight: 500; color: var(--muted); }
/* The light/dark switch floats just above the bar instead of on top of its buttons
   (--dl-h is the bar's height, kept up to date by topicbank.js). */
.topicbank .theme-toggle { bottom: calc(16px + var(--dl-h, 0px)); }
.tb-dl-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.tb-dl-btn {
  background: var(--accent-strong);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 8px 16px;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.tb-dl-btn:hover { background: var(--accent-hover); }
.tb-dl-btn:disabled { opacity: 0.45; cursor: default; background: var(--accent-strong); }

/* Phones and tablets: bigger tap targets. */
@media (pointer: coarse) {
  .act, .tb-dl-btn, .tb-back, .tb-more, .tb-topics-toggle { min-height: 44px; }
  .tree-go, .tree-all, .tb-tree summary { min-height: 40px; }
  .tree-leaf { align-items: center; }
  .tree-tick, .tb-menu-row input { width: 20px; height: 20px; }
  .tree-leaf .tree-tick { margin-top: 0; }
  .tb-menu-row { align-items: center; min-height: 40px; padding-top: 4px; padding-bottom: 4px; }
  .tb-menu-row input { margin-top: 0; }
  .tb-menu-all { min-height: 40px; }
}

@media (max-width: 980px) {
  .tb-layout { grid-template-columns: minmax(0, 1fr); }
  .tb-topics-toggle { display: inline-block; justify-self: start; }
  .tb-sidebar { display: none; position: static; max-height: 60vh; padding-bottom: 0; }
  .tb-sidebar.open { display: block; }
  .tb-topics-done {
    display: block;
    position: sticky;
    bottom: 0;
    width: calc(100% + 24px);
    margin: 10px -12px 0;
    border-radius: 0 0 11px 11px;
  }
  .tb-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tb-search { grid-column: 1 / -1; }
}
@media (max-width: 520px) {
  .tb-main { padding: 20px 12px 60px; }
  .tb-controls { grid-template-columns: minmax(0, 1fr); }
  .tb-dl { margin-left: -12px; margin-right: -12px; border-radius: 0; }
  .tb-dl-actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
  .tb-dl.is-empty .tb-dl-actions { width: auto; display: flex; }
}
@media (prefers-reduced-motion: no-preference) {
  .qcard { transition: opacity 0.2s; }
}
