/*-- scss:defaults --*/
$font-family-sans-serif: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
$font-family-monospace: "SF Mono", "Consolas", "Liberation Mono", Menlo, monospace;
$h1-font-size: 2.25rem;
$h2-font-size: 1.5rem;
$h3-font-size: 1.25rem;
$line-height-base: 1.6;

/*-- scss:rules --*/

/* ──────────────────────────────────────────────────────────────────────
   Theme tokens (CTTIR/tutorials parity)
   Consumed by assets/js/overview/* and the overview-page CSS below.
   ────────────────────────────────────────────────────────────────────── */
:root {
  --fg:           #23272b;
  --fg-alt:       #5b6770;
  --bg:           #ffffff;
  --surface:      #f6f8fa;
  --rule:         #e1e4e8;
  --accent:       #1a73e8;
  --accent-hover: #0b57d0;
  --accent-soft:  #e8f1fe;
  --shadow-md:    0 6px 18px rgba(0, 0, 0, 0.08);
}

[data-bs-theme="dark"] {
  --fg:           #dee2e6;
  --fg-alt:       #9aa4ad;
  --bg:           #212529;
  --surface:      #2a2f35;
  --rule:         #3a4047;
  --accent:       #66a6f0;
  --accent-hover: #84baf5;
  --accent-soft:  rgba(102, 166, 240, 0.18);
  --shadow-md:    0 6px 18px rgba(0, 0, 0, 0.4);
}

/* ──────────────────────────────────────────────────────────────────────
   Theme toggle: moon in light mode, sun in dark mode.
   Quarto's default toggle renders an SVG toggle-on/off via background-image.
   We override with Bootstrap-Icons font glyphs and clear the SVG bg.
   !important is required because Quarto's bundle ships these rules in
   the same cascade slot.
   ────────────────────────────────────────────────────────────────────── */
.quarto-color-scheme-toggle .bi::before {
  font-family: "bootstrap-icons" !important;
  background-image: none !important;
  height: auto !important;
  width: auto !important;
  font-style: normal;
  font-weight: normal;
  display: inline-block;
  line-height: 1;
}

.quarto-color-scheme-toggle:not(.alternate) .bi::before {
  /* bi-moon-stars-fill — click to switch to dark */
  content: unquote('"\\f494"') !important;
}

.quarto-color-scheme-toggle.alternate .bi::before {
  /* bi-sun-fill — click to switch back to light */
  content: unquote('"\\f5a2"') !important;
}

.quarto-color-scheme-toggle {
  font-size: 1.1rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  color: var(--fg-alt);
  transition: color 0.15s ease, transform 0.2s ease;

  &:hover { color: var(--accent); transform: rotate(15deg); }
  &:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 50%;
  }
}

/* ──────────────────────────────────────────────────────────────────────
   Unify navbar background with body background.
   Both light and dark modes — the navbar previously used Bootstrap's
   $navbar-dark-bg / $navbar-light-bg which differ from body bg.
   ────────────────────────────────────────────────────────────────────── */
.navbar,
.navbar.navbar-dark,
.navbar.bg-dark,
.navbar.bg-primary {
  background-color: var(--bg) !important;
  color: var(--fg) !important;
  border-bottom: 1px solid var(--rule);
}

.navbar .navbar-title,
.navbar .nav-link,
.navbar .navbar-brand,
.navbar .quarto-navbar-tools .quarto-navigation-tool {
  color: var(--fg) !important;
}

.navbar .nav-link:hover,
.navbar .navbar-brand:hover,
.navbar .quarto-navbar-tools .quarto-navigation-tool:hover {
  color: var(--accent) !important;
}

.navbar .dropdown-menu {
  background-color: var(--bg);
  border: 1px solid var(--rule);
}

.navbar .dropdown-menu .dropdown-item {
  color: var(--fg);

  &:hover, &:focus {
    background-color: var(--surface);
    color: var(--accent);
  }
}

/* Page footer matches body background too. */
.page-footer,
.nav-footer {
  background-color: var(--bg) !important;
  color: var(--fg-alt) !important;
  border-top: 1px solid var(--rule);
}

/* ──────────────────────────────────────────────────────────────────────
   Landing-page hero + card grid (CTTIR/tutorials parity)
   Used on index.qmd and the section/topic landing pages.
   ────────────────────────────────────────────────────────────────────── */

/* On any page with a .hero block, hide Quarto's auto title block so
   the page doesn't render the title twice. */
body:has(.hero) #title-block-header {
  display: none;
}

.hero {
  text-align: center;
  padding: 2.5rem 1rem 2rem;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 2rem;

  h1 {
    font-size: 2.75rem;
    font-weight: 700;
    margin: 0.75rem 0 0.5rem;
    letter-spacing: -0.01em;
  }

  .lead, p.lead, > p {
    max-width: 42rem;
    margin: 0.5rem auto 0;
    color: var(--fg-alt);
    font-size: 1.05rem;
  }
}

/* Small uppercase chip / label sitting above cards and headers.
   Used both standalone (in the hero) and inside a .card. */
.kicker, .topic-card-label {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg-alt);
  margin: 0 0 0.5rem;

  p { margin: 0; }
}

.hero .kicker {
  display: block;
  margin: 0 0 0.5rem;
  color: var(--accent);
  font-size: 0.8rem;
}

.card-grid, .topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
  margin: 1.5rem 0 2rem;
}

.card, .topic-card {
  display: block;
  padding: 1.5rem 1.25rem 1.25rem;
  border: 1px solid var(--rule);
  border-radius: 0.6rem;
  text-decoration: none;
  color: inherit;
  background: var(--bg);
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;

  &:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    text-decoration: none;
    box-shadow: var(--shadow-md);
  }

  h3 {
    font-size: 1.1rem;
    margin: 0 0 0.5rem;
    line-height: 1.3;

    a {
      color: inherit;
      text-decoration: none;
    }

    a:hover {
      color: var(--accent);
    }
  }

  p {
    margin: 0;
    font-size: 0.92rem;
    color: var(--fg-alt);
    line-height: 1.5;
  }
}

/* When a topic card's count chip is empty (live-counts JS hid it),
   close the gap above the heading. */
.card .topic-card-label:empty,
.topic-card .topic-card-label:empty {
  display: none;
}

/* App-embed iframe wrapper for shiny tutorials */
.app-embed iframe {
  width: 100%;
  border: 1px solid var(--rule);
  border-radius: 0.5rem;
}

/* Decision-tree wizard */
.decision-node {
  padding: 1rem;
  border: 2px solid var(--rule);
  border-radius: 0.5rem;
  margin: 1rem 0;
  background: var(--bg);

  &.active {
    border-color: var(--accent);
  }
}

.decision-node .btn {
  margin: 0.25rem;
}

/* Shiny app card grid */
.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
  margin: 1.5rem 0;
}

.app-card {
  border: 1px solid var(--rule);
  border-radius: 0.5rem;
  overflow: hidden;
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
  background: var(--bg);

  &:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
  }

  img {
    width: 100%;
    height: 160px;
    object-fit: cover;
  }

  .app-card-body { padding: 1rem; }
  h4 { margin: 0 0 0.5rem 0; font-size: 1rem; }
  p  { margin: 0; font-size: 0.875rem; color: var(--fg-alt); }
}

/* ──────────────────────────────────────────────────────────────────────
   Overview page (CTTIR/tutorials parity)
   The 9 JS modules in assets/js/overview/ render into these elements.
   ────────────────────────────────────────────────────────────────────── */
.network-help {
  font-size: 0.9rem;
  color: var(--fg-alt);
  margin: 0.5rem 0 0.75rem;
}

#tutorial-network {
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 0.5rem;
}

.network-controls {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin: 0.5rem 0 1.5rem;
  flex-wrap: wrap;
}

.network-controls button,
.network-controls select {
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--rule);
  border-radius: 0.35rem;
  background: var(--surface);
  color: var(--fg);
  font-size: 0.9rem;
  cursor: pointer;
}

.filter-summary {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.95rem;
  color: var(--fg-alt);
  margin: 0.5rem 0 0.75rem;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.5rem 0 1.25rem;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.65rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--surface);
  color: var(--fg);
  font-size: 0.82rem;
  cursor: pointer;
  user-select: none;
  line-height: 1.2;

  &[data-active="true"] {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
  }

  .chip-count {
    font-size: 0.75rem;
    opacity: 0.85;
  }

  .chip-swatch {
    width: 0.65rem;
    height: 0.65rem;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
  }

  &:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  &.is-empty { opacity: 0.45; }
}

.filter-bar.label-bar { margin-top: -0.25rem; }

#filter-reset {
  margin-left: auto;
  padding: 0.25rem 0.65rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: transparent;
  color: var(--fg-alt);
  font-size: 0.8rem;
  cursor: pointer;
}

#filter-reset:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.search-row { margin: 0.5rem 0 0.75rem; }
.year-row   { margin: 0.75rem 0 1.5rem; max-width: 32rem; }

.year-label {
  display: block;
  font-size: 0.85rem;
  color: var(--fg-alt);
  margin-bottom: 0.5rem;
}

#year-readout {
  color: var(--fg);
  font-weight: 500;
  margin-left: 0.25rem;
}

#year-slider .range-track {
  position: relative;
  height: 28px;
  background: linear-gradient(var(--rule), var(--rule)) center/100% 4px no-repeat;
  border-radius: 4px;
}

#year-slider .range-fill {
  position: absolute;
  top: 12px;
  height: 4px;
  background: var(--accent);
  border-radius: 4px;
  pointer-events: none;
}

#year-slider .range-input {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 28px;
  margin: 0;
  padding: 0;
  background: transparent;
  appearance: none;
  -webkit-appearance: none;
  pointer-events: none;
}

#year-slider .range-input::-webkit-slider-thumb {
  pointer-events: auto;
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--bg);
  border: 1.5px solid var(--accent);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  cursor: grab;
}

#year-slider .range-input::-moz-range-thumb {
  pointer-events: auto;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--bg);
  border: 1.5px solid var(--accent);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  cursor: grab;
}

#year-slider .range-input::-webkit-slider-runnable-track,
#year-slider .range-input::-moz-range-track {
  background: transparent;
  border: none;
  height: 4px;
}

.autocomplete-wrap {
  position: relative;
  width: 100%;
  max-width: 32rem;
}

.autocomplete-list {
  position: absolute;
  z-index: 10;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 0.25rem 0;
  list-style: none;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 0.4rem;
  box-shadow: var(--shadow-md);
  max-height: 22rem;
  overflow-y: auto;
}

.autocomplete-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.7rem;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--fg);

  &.is-active, &:hover { background: var(--surface); }

  .autocomplete-pill {
    flex-shrink: 0;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.1rem 0.4rem;
    border-radius: 0.25rem;
  }

  .autocomplete-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;

    mark {
      background: var(--accent-soft);
      color: inherit;
      padding: 0;
      font-weight: 600;
    }
  }
}

#overview-search {
  width: 100%;
  max-width: 32rem;
  padding: 0.55rem 0.85rem;
  border: 1px solid var(--rule);
  border-radius: 0.4rem;
  background: var(--surface);
  color: var(--fg);
  font-size: 0.95rem;

  &:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
    border-color: var(--accent);
  }
}

.desc-snippet mark {
  background: var(--accent-soft);
  color: inherit;
  padding: 0 0.1em;
  border-radius: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.tutorial-list-empty {
  padding: 1.5rem 1rem;
  text-align: center;
  color: var(--fg-alt);
  border: 1px dashed var(--rule);
  border-radius: 0.5rem;
}

.heatmap-wrapper {
  margin: 2rem 0 1.5rem;
  border: 1px solid var(--rule);
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--bg);

  summary {
    cursor: pointer;
    font-weight: 500;
    font-size: 0.95rem;
    color: var(--fg);
    list-style: none;

    &::before {
      content: "▸";
      display: inline-block;
      margin-right: 0.5rem;
      transition: transform 0.15s ease;
    }
  }

  &[open] summary::before { transform: rotate(90deg); }
}

.heatmap-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.85rem 0 0.5rem;
  font-size: 0.85rem;
  color: var(--fg-alt);
}

.heatmap-controls input[type="range"] { flex: 0 1 12rem; }

#heatmap-n-readout {
  color: var(--fg);
  font-weight: 500;
}

.heatmap {
  margin-top: 0.5rem;
  overflow-x: auto;
}

.heatmap-empty {
  color: var(--fg-alt);
  font-style: italic;
  padding: 1rem;
}

.heatmap rect:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.all-tutorials-nav {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;

  details { margin: 0.4rem 0; }

  summary {
    cursor: pointer;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  .nav-swatch {
    display: inline-block;
    width: 0.7rem;
    height: 0.7rem;
    border-radius: 50%;
    flex-shrink: 0;
  }

  ul {
    list-style: none;
    padding-left: 1.4rem;
    margin: 0.35rem 0 0.75rem;
  }

  li { margin: 0.15rem 0; }

  .nav-empty {
    color: var(--fg-alt);
    font-style: italic;
  }
}

.tutorial-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.tutorial-card {
  border: 1px solid var(--rule);
  border-radius: 0.5rem;
  padding: 0.85rem 1rem;
  background: var(--bg);
  color: var(--fg);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;

  &:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--accent);
  }

  .topic-pill {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.15rem 0.45rem;
    border-radius: 0.3rem;
    margin-bottom: 0.4rem;
    color: #fff;
  }

  h3 {
    font-size: 1rem;
    margin: 0.1rem 0 0.35rem;
    line-height: 1.3;

    a {
      color: inherit;
      text-decoration: none;
    }

    a:hover {
      color: var(--accent);
      text-decoration: underline;
    }
  }

  .desc {
    font-size: 0.85rem;
    color: var(--fg-alt);
    margin: 0 0 0.4rem;
  }

  .tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
  }

  .tag {
    font-size: 0.72rem;
    padding: 0.1rem 0.4rem;
    border-radius: 0.25rem;
    background: var(--surface);
    color: var(--fg-alt);
    border: 1px solid var(--rule);
  }
}

.downloads-menu {
  display: inline-block;
  position: relative;

  > summary {
    list-style: none;
    cursor: pointer;
    padding: 0.35rem 0.7rem;
    border: 1px solid var(--rule);
    border-radius: 0.35rem;
    background: var(--surface);
    color: var(--fg);
    font-size: 0.9rem;

    &::-webkit-details-marker { display: none; }
  }

  &[open] > summary {
    border-color: var(--accent);
    color: var(--accent);
  }

  ul {
    position: absolute;
    z-index: 5;
    margin-top: 0.35rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg);
    border: 1px solid var(--rule);
    border-radius: 0.35rem;
    list-style: none;
    min-width: 18rem;
    box-shadow: var(--shadow-md);
  }

  li { font-size: 0.85rem; line-height: 1.5; }
}

@media (max-width: 768px) {
  #tutorial-network,
  .network-help,
  .network-controls,
  .heatmap-wrapper {
    display: none;
  }

  .all-tutorials-nav {
    position: static;
    width: auto;
    height: auto;
    padding: 0.5rem 0;
    margin: 0.5rem 0 1.5rem;
    overflow: visible;
    clip: auto;
    white-space: normal;
    border: 0;
  }

  .all-tutorials-nav summary,
  .all-tutorials-nav a {
    min-height: 32px;
    line-height: 1.4;
    padding: 0.25rem 0;
  }

  .tutorial-list { grid-template-columns: 1fr; }

  .filter-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 0.25rem;
  }

  .filter-chip { flex-shrink: 0; }

  #year-slider .range-input::-webkit-slider-thumb,
  #year-slider .range-input::-moz-range-thumb {
    width: 22px;
    height: 22px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tutorial-card,
  .tutorial-card:hover {
    transition: none;
    transform: none;
  }
}
