/* ==========================================================================
   components.css
   Building blocks shared by several pages (Media, People, …).

   Contents
     1. Folding blocks (<details class="item">): heading row with title,
        "back to top" button and + / -, as on mehulbhatt.org
     2. Expand All / Collapse All
     3. Links as round tags
     4. Images: colours softened until pointed at
     5. Filter buttons under the page title (Media, Scientific Highlights)
     6. Item body: two columns, subtitle, quote, links, note line
     7. Images and videos in items
     8. Figures and the figure viewer (lightbox.js)
   ========================================================================== */


/* --------------------------------------------------------------------------
   1. Folding blocks
   -------------------------------------------------------------------------- */

.item {
  border-top: var(--rule-item);
  scroll-margin-top: 1rem;
}

.item:last-child {
  border-bottom: var(--rule-item);
}


/* heading row */
.item-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 24px;   /* title | back to top | + / - */
  align-items: center;
  gap: 1rem;
  padding: clamp(1.4rem, 3vw, 1.9rem) 0;
  list-style: none;                    /* no browser triangle */
  cursor: pointer;
}

.item-summary::-webkit-details-marker {
  display: none;                       /* Safari's triangle */
}

.item-title {
  display: flex;
  gap: .7rem;
  align-items: baseline;               /* full width: one line across both columns where it fits */
  font-size: var(--fs-title);
  font-weight: 700;
  line-height: 1.2;
}

.item-title .icon {
  color: var(--icon);
  font-size: .85em;
  transform: translateY(.05em);
}

/* + / - sign: a "+" whose vertical bar disappears when the item is open */
.item-toggle {
  position: relative;
  width: 18px;
  height: 18px;
  justify-self: center;
  color: var(--ink);
}

.item-toggle::before,
.item-toggle::after {
  content: "";
  position: absolute;
  background: currentColor;
}

.item-toggle::before {                 /* horizontal bar */
  top: 8.25px;
  left: 0;
  width: 18px;
  height: 1.5px;
}

.item-toggle::after {                  /* vertical bar */
  top: 0;
  left: 8.25px;
  width: 1.5px;
  height: 18px;
}

.item[open] .item-toggle::after {
  display: none;
}

.item-summary:hover .item-toggle {
  color: var(--accent);
}

.item-body {
  padding-bottom: clamp(1.75rem, 4vw, 2.5rem);
}

@media print {
  .to-top,
  .item-toggle {
    display: none;
  }
}


/* Back to the top of the page: a small round button in the heading row
   (a link, so it scrolls up without opening or closing the item) */
.to-top {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  border-radius: 50%;
  text-decoration: none;
}

.to-top:hover {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}


/* --------------------------------------------------------------------------
   2. Expand All / Collapse All
   -------------------------------------------------------------------------- */

/* Expand All / Collapse All: above the first item and below the last
   (shown by site.js; greyed out when they would do nothing) */
.fold-tools {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin: 0 0 1.5rem;
}

.fold-tools-bottom {
  margin: 1.5rem 0 0;
}

.fold-button {
  min-height: 2.5rem;
  padding: 0 1.1rem;
  font: 600 var(--fs-label) var(--font);
  color: var(--ink);
  background: transparent;
  border: 1.5px solid var(--line);
  border-radius: var(--pill);
  cursor: pointer;
}

.fold-button:hover:not(:disabled) {
  border-color: var(--ink);
}

.fold-button:disabled {
  color: var(--ink-soft);
  opacity: .55;
  cursor: default;
}

@media print {
  .fold-tools {
    display: none;
  }
}


/* --------------------------------------------------------------------------
   3. Links as round tags
   -------------------------------------------------------------------------- */

/* Links as round tags: the old page's first ("primary") link filled, the
   others outlined; a leading "@" or ">" shown lighter, so the name reads first */
.link-tag {
  display: inline-block;               /* (not flex: that would drop the space after "@") */
  padding: .4rem 1rem .45rem;
  font-size: var(--fs-label);
  font-weight: 600;
  line-height: 1.2;
  color: var(--accent);
  text-decoration: none;
  background: transparent;
  border: 1.5px solid var(--accent);
  border-radius: var(--pill);
  transition: background-color .15s ease, color .15s ease;
}

.link-tag.is-primary {
  color: var(--accent-ink);
  background: var(--accent);
}

.link-tag:hover {
  color: var(--accent-ink);
  background: color-mix(in srgb, var(--accent) 88%, #000);
  border-color: color-mix(in srgb, var(--accent) 88%, #000);
}

/* a link that led nowhere on the old page: its text kept, without a link (DECISIONS.md, 4) */
.link-tag.is-unlinked,
.link-tag.is-unlinked:hover {
  color: var(--ink-soft);
  background: transparent;
  border-color: var(--line);
  border-style: dashed;
}

.link-mark {
  font-weight: 400;
  opacity: .6;
}

@media print {
  .link-tag {
    padding: 0;
    color: #000;
    background: none;
    border: 0;
    text-decoration: underline;
  }
}

/* --------------------------------------------------------------------------
   4. Images
   -------------------------------------------------------------------------- */

/* Colours softened; full vibrancy when pointed at (strength: --img-mute in
   base.css). Phones and tablets, which can't point, show full colour. */
@media (hover: hover) {
  .item img,
  .item video.loop {
    filter: saturate(var(--img-mute)) contrast(.96);
    transition: filter .35s ease;
  }

  .item img:hover,
  .item video.loop:hover {
    filter: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .item img,
  .item video.loop {
    transition: none;
  }
}


/* --------------------------------------------------------------------------
   5. Filter buttons under the page title
   -------------------------------------------------------------------------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin: 1.75rem 0 0;
  padding: 0;
  list-style: none;
}

.filters a,
.filters span {                        /* (a label without a link: the uncoloured ones on Highlights and Media) */
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  min-height: 2.5rem;
  padding: 0 1.1rem;
  font-size: var(--fs-label);
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  background: var(--paper);
  border: 1.5px solid var(--ink);
  border-radius: var(--pill);
}

.filters .is-primary a {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}

.filters .icon {
  font-size: .85em;
}


/* --------------------------------------------------------------------------
   6. Item body: two columns side by side (one on phones); the links follow
   the text above them.
   -------------------------------------------------------------------------- */

/* body: two columns */
.item-cols {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.5rem clamp(1.5rem, 4vw, 3rem);
  align-items: start;                  /* each column as tall as its own content */
}

.item-col {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* links follow the text, with a little more room above them */
.item-col > .item-links,
.item-single > .item-links {
  margin-top: .5rem;
}

.item-col > .item-links + .item-links,
.item-single > .item-links + .item-links {
  margin-top: -.4rem;                  /* a second row of links as close as a wrapped row */
}

/* items without two columns: everything in one column, in the old order */
.item-single {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* the subtitle above the text (an <h3> on Media, an <h4> where the item title is an <h3>) */
.item-sub {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
}

.item blockquote {
  margin: 0;
  font-style: italic;
  color: var(--ink-soft);
}

.item-links {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem .6rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.item-note {
  margin: 1.25rem 0 0;
  font-size: var(--fs-small);
  color: var(--ink-soft);
}

@media (max-width: 760px) {
  .item-cols {
    grid-template-columns: 1fr;
  }
}


/* --------------------------------------------------------------------------
   7. Images and videos in items
   -------------------------------------------------------------------------- */

/* an animated picture shown as a looping, silent video (Media) */
.item video.loop {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--img-radius);
}

.item img {
  width: 100%;
  border-radius: var(--img-radius);
}

/* (softened colours until pointed at: section 5) */

/* YouTube videos keep a 16:9 frame at every width */
.video {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #000;
  border-radius: var(--img-radius);
}

.video iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

@media print {
  .video {
    display: none;
  }
}


/* --------------------------------------------------------------------------
   8. Figures and the figure viewer (lightbox.js)
   A figure: the image in a thin frame, its caption below a hairline (as in a
   paper). Clicking opens the viewer: a card of one fixed size in the middle
   of the page with the image and its caption, ‹ › through the group, × to close.
   -------------------------------------------------------------------------- */

.fig {
  display: block;
  color: var(--ink);
  text-decoration: none;
}

.fig img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  object-position: top;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.fig-cap {
  display: block;
  margin-top: .6rem;
  padding-top: .5rem;
  font-size: .8125rem;
  line-height: 1.35;
  color: var(--ink-soft);
  border-top: 1px solid var(--line);
}

a.fig:hover .fig-cap,
a.fig:focus-visible .fig-cap {
  color: var(--accent);
}

@media (hover: hover) {
  a.fig img {
    filter: saturate(var(--img-mute)) contrast(.96);
    transition: filter .35s ease;
  }

  a.fig:hover img {
    filter: none;
  }
}

.lightbox {
  /* a card of one fixed size in the middle of the page: every image fits inside it */
  width: min(92vw, 44rem);
  max-width: none;
  max-height: 92vh;
  padding: 1rem 1rem .9rem;
  overflow: visible;
  color: var(--ink);
  background: var(--paper);
  border: 0;
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .28);
}

.lightbox::backdrop {
  background: rgba(28, 29, 26, .45);
}

.lightbox-figure {
  margin: 0;
}

.lightbox-img {
  display: block;
  width: 100%;
  height: min(65vh, 34rem);            /* the same frame for every image; the image fits inside it */
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.lightbox-caption {
  width: 100%;
  min-height: 2.8em;                   /* room for two lines, so the card keeps its height */
  margin-top: .75rem;
  font-size: var(--fs-small);
  line-height: 1.4;
  text-align: center;
  color: var(--ink-soft);
}

/* a figure from a paper: "PDF" beside the caption */
.lightbox-pdf {
  display: inline-block;
  margin-left: .35rem;
  padding: 0 .55rem;
  font-size: var(--fs-label);
  font-weight: 600;
  line-height: 1.6;
  color: var(--accent);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: var(--pill);
}

.lightbox-pdf:hover,
.lightbox-pdf:focus-visible {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

/* "2 / 5": on its own, at the card's top left (the × is at the top right) */
.lightbox-count {
  margin: -.25rem 0 .6rem .1rem;
  font-size: var(--fs-label);
  font-weight: 700;
  line-height: 1;
  color: var(--accent);
}

.lightbox-count:empty {
  display: none;
}

/* ‹ › on the card's edges, × at its top right */
.lightbox-button {
  position: absolute;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  font: 400 1.6rem/1 var(--font);
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 50%;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .12);
  cursor: pointer;
}

.lightbox-button:hover,
.lightbox-button:focus-visible {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}

.lightbox-prev  { left: -1.25rem;  top: 45%; transform: translateY(-50%); }
.lightbox-next  { right: -1.25rem; top: 45%; transform: translateY(-50%); }
.lightbox-close { right: -.9rem;   top: -.9rem; width: 2.1rem; height: 2.1rem; font-size: 1.3rem; }

.lightbox.is-single .lightbox-prev,
.lightbox.is-single .lightbox-next {
  display: none;
}

@media (max-width: 480px) {
  .lightbox-prev  { left: -.6rem; }
  .lightbox-next  { right: -.6rem; }
  .lightbox-close { right: -.4rem; top: -.6rem; }
}
