/*
 * portfolio-buttons.css — lets an entry on /work/ and /creative/ carry more
 * than one action button (e.g. WATCH TALK + READ ARTICLE).
 *
 * Nothing here changes an entry with a single button. The page markup stays
 * as it is: every button in an item's "buttons" array is already rendered,
 * both by assets/portfolio.php and by renderItems() in the page's script.
 * This file only decides how two or three of them sit together.
 *
 * To enable on a real page, add after elements.css in its <head>:
 *   <link rel="stylesheet" href="/assets/styles/portfolio-buttons.css">
 *
 * Convention: the LAST button is the primary action. It is the one opened
 * when a visitor clicks the entry's image or title, and the one highlighted
 * by the "btn-last-only" treatment the pages use. The sheet writes them in
 * reverse column order: button 3, button 2, primary, left to right.
 */

/* ---- Desktop. One button: nothing changes. Two or more: the buttons leave
        the narrow right-hand column and sit in a right-aligned row under the
        text, so they read as a toolbar rather than a list. Done with grid so the markup
        stays identical to today's. ------------------------------------- */
@media (min-width: 769px) {
  .portfolio-item-content:has(.btn + .btn) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 150px;
    grid-template-rows: auto auto;
    column-gap: 20px;
    row-gap: 6px;
  }

  /* The wrapper dissolves; its two children place themselves on the grid. */
  .portfolio-item-content:has(.btn + .btn) .secondary-info {
    display: contents;
  }

  .portfolio-item-content:has(.btn + .btn) .main-info {
    grid-column: 1;
    grid-row: 1;
  }

  .portfolio-item-content:has(.btn + .btn) .publication-details {
    grid-column: 2;
    grid-row: 1;
  }

  .portfolio-item-content:has(.btn + .btn) .actions {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 10px;
  }
}

/* ---- Mobile (same breakpoint as the pages): the actions share a row with
        the category · date line, and only drop below it when they would
        squeeze the text too far. ------------------------------------------ */
@media (max-width: 768px) {
  .secondary-info:has(.btn + .btn) {
    flex-wrap: wrap;
  }

  .secondary-info .actions {
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    /* Lifts the button off the rule below, so its bottom edge sits level
       with the meta text on the left rather than hanging under it. */
    margin-bottom: 12px;
  }

  /* Two or more buttons share the row with the meta text, exactly like a
     single button does, and only drop below it when there is no room: the
     text keeps the width its two lines need (about 150px) and the buttons
     wrap when they cannot fit beside it. */
  .secondary-info:has(.btn + .btn) .secondary-info-mobile {
    width: auto;
    flex: 1 1 auto;
    min-width: 150px;
  }

  .secondary-info .actions:has(.btn + .btn) {
    flex: 0 0 auto;
    max-width: 100%;
    justify-content: flex-end;
    margin-left: auto;
  }

}

/* ---- Icons asked for by a label token ("[PLAY] TALK", "[DOC] PAPER"),
        see hm_button_label() in assets/portfolio.php. --------------------- */
/* A button label never wraps; a wide one overhangs the right column into
   the gutter instead, which the 20px column gap absorbs. */
.btn {
  white-space: nowrap;
}

.btn:has(.btn-icon, .btn-ext) {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  /* The pages' mobile rule gives .btn a -20px top margin, which an inline
     element ignores but an inline-flex one would obey. Neutralise it. */
  margin-top: 0 !important;
}

.btn .btn-icon {
  flex-shrink: 0;
  display: block;
}

/* External-link mark: tucked inside the button's top-right corner, and
   only while the button is hovered or focused. Out of the flow, so
   the label stays centred and the button keeps its width. Its arrow is
   drawn black, since it only appears on the white hover fill. */
.btn {
  position: relative;
}

.btn .btn-ext {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  display: none;
}

.btn:hover .btn-ext,
.btn:focus-visible .btn-ext {
  display: block;
}

/* Just the arrow, no square: it is only ever seen on the white hover fill. */
.btn .btn-ext rect {
  display: none;
}

.btn .btn-ext path {
  stroke: #000;
}

/* ---- Optional treatments. Each is switched on by a class on <body>. ----- */

/* First button filled white, the rest outlined. */
body.btn-primary-filled .actions .btn:first-child {
  background-color: #fff;
  color: #000;
}
body.btn-primary-filled .actions .btn:first-child:hover {
  background-color: transparent;
  color: #fff;
}

/* Last button filled white, the rest outlined. */
body.btn-last-filled .actions .btn:last-child {
  background-color: #fff;
  color: #000;
}
body.btn-last-filled .actions .btn:last-child:hover {
  background-color: transparent;
  color: #fff;
}

/* Only the first is drawn as a button; the rest read as underlined links. */
body.btn-primary-only .actions .btn:not(:first-child) {
  border-color: transparent;
  padding-left: 0;
  padding-right: 0;
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-thickness: 2px;
}
body.btn-primary-only .actions .btn:not(:first-child):hover {
  background-color: transparent;
  color: #aeaeae;
}

/* Only the last is drawn as a button. The rest are plain text until
   hovered, when they fill white like a hovered button. Padding is kept so
   nothing shifts. */
body.btn-last-only .actions .btn:not(:last-child) {
  border-color: transparent;
}
body.btn-last-only .actions .btn:not(:last-child):hover {
  border-color: #fff;
  background-color: #fff;
  color: #000;
}

/* Only the first is drawn as a button (the treatment the pages use). The
   rest are plain text until hovered, when they fill white like a hovered
   button. Padding is kept so nothing shifts. */
body.btn-first-only .actions .btn:not(:first-child) {
  border-color: transparent;
}
body.btn-first-only .actions .btn:not(:first-child):hover {
  border-color: #fff;
  background-color: #fff;
  color: #000;
}
