/**
 * ub/dialog-cards - cards that open a dialog.
 *
 * Two states share one set of rules. Without JavaScript each card is a
 * <details>: the face is the summary, the full text opens inline. With it
 * (.is-enhanced) the face is rebuilt around a button whose ::after covers the
 * whole card, and the text lives in one native <dialog> per block.
 */
.ub-dcards { background: var(--white, #fff); }

.ub-dcards-grid {
  display: grid;
  grid-template-columns: repeat(var(--ub-dc-cols, 4), minmax(0, 1fr));
  gap: 32px 28px;
  margin: 0;
  padding: 0;
  list-style: none;
  align-items: start;
}
.ub-dcards--cols-2 { --ub-dc-cols: 2; }
.ub-dcards--cols-3 { --ub-dc-cols: 3; }
.ub-dcards--cols-4 { --ub-dc-cols: 4; }
/* Once enhanced every card is a button of the same height. */
.ub-dcards-grid:has(> .is-enhanced) { align-items: stretch; }

.ub-dcard {
  position: relative;
  margin: 0;
  background: var(--white, #fff);
  border-top: 4px solid var(--ub-purple, #592d82);
  box-shadow: var(--shadow-sm, 0 4px 6px rgba(0, 0, 0, 0.05));
  scroll-margin-top: 120px;
  transition: transform var(--transition-dur, 300ms) var(--transition-ease, cubic-bezier(0.25, 0.8, 0.25, 1)),
              box-shadow var(--transition-dur, 300ms) var(--transition-ease, cubic-bezier(0.25, 0.8, 0.25, 1));
}
.ub-dcard:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md, 0 10px 20px rgba(0, 0, 0, 0.08));
}

/* The poster. A 3:4 crop by default; `contain` shows it whole on a tint. */
.ub-dcard-media {
  display: block;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  background: var(--bg-light, #f4f7f6);
}
.ub-dcard-media img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 0;
}
.ub-dcard--contain .ub-dcard-media img { object-fit: contain; }

.ub-dcard-title {
  margin: 0;
  font-size: 1.22rem;
  font-weight: 700;
  line-height: 1.25;
  color: var(--ub-purple-dark, #3f1d61);
}
.ub-dcard-meta {
  display: block;
  margin: 0;
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text-light, #5b6a75);
}
.ub-dcard-blurb {
  display: block;
  margin: 0;
  font-size: 0.98rem;
  line-height: 1.55;
  color: var(--text-main, #2c3e50);
}
.ub-dcard-cue {
  display: inline-block;
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ub-purple, #592d82);
}
.ub-dcard-cue::after {
  content: "";
  display: inline-block;
  width: 0.45em;
  height: 0.45em;
  margin-left: 0.5em;
  border-top: 2px solid currentColor;
  border-right: 2px solid currentColor;
  transform: rotate(45deg);
}

/* No JavaScript: <details> */
.ub-dcard-face {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 22px;
  list-style: none;
  cursor: pointer;
}
.ub-dcard-face::-webkit-details-marker { display: none; }
.ub-dcard-face > :not(.ub-dcard-media) { margin-inline: 20px; }
.ub-dcard-face > .ub-dcard-title { margin-top: 10px; }
.ub-dcard-face > .ub-dcard-cue { align-self: flex-start; margin-top: 6px; }
.ub-dcard-face:focus-visible {
  outline: 3px solid var(--ub-purple, #592d82);
  outline-offset: 3px;
}
.ub-dcard-d[open] .ub-dcard-cue { display: none; }
.ub-dcard-body {
  margin: 0 20px;
  padding: 18px 0 24px;
  border-top: 1px solid #E1E7EA;
}
.ub-dcard-body p {
  margin: 0 0 1em;
  font-size: 1rem;
  line-height: 1.65;
  color: var(--text-main, #2c3e50);
}
.ub-dcard-body p:last-child { margin-bottom: 0; }

/* JavaScript: the button covers the card. */
.ub-dcard.is-enhanced { display: flex; flex-direction: column; }
.ub-dcard-text {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 8px;
  padding: 18px 20px 22px;
}
.ub-dcard-text > * { margin: 0; }
.ub-dcard-text .ub-dcard-cue { margin-top: auto; padding-top: 10px; }
.ub-dcard-open {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.ub-dcard-open::after {
  content: "";
  position: absolute;
  inset: 0;
}
.ub-dcard-open:focus-visible { outline: none; }
.ub-dcard-open:focus-visible::after {
  outline: 3px solid var(--ub-purple, #592d82);
  outline-offset: 3px;
}

/* The dialog */
html.ub-dlg-lock,
html.ub-dlg-lock .main-content-wrapper { overflow: hidden; }

.ub-dlg {
  inset: 0;
  width: min(1040px, calc(100vw - 48px));
  max-width: none;
  max-height: min(88vh, 880px);
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: var(--white, #fff);
  color: var(--text-main, #2c3e50);
  box-shadow: var(--shadow-lg, 0 20px 40px rgba(0, 0, 0, 0.12));
}
.ub-dlg::backdrop { background: rgba(27, 16, 35, 0.72); }
.ub-dlg[open] { display: flex; }
.ub-dlg-panel {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 0;
  max-height: min(88vh, 880px);
  border-top: 4px solid var(--ub-purple, #592d82);
}
.ub-dlg-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
}
.ub-dlg-pos {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-light, #5b6a75);
}
.ub-dlg-close { min-height: 44px; min-width: 96px; justify-content: center; font-family: inherit; }
.ub-dlg-scroll {
  display: grid;
  flex: 1;
  grid-template-columns: minmax(0, 40%) minmax(0, 1fr);
  align-items: start;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.ub-dlg-scroll:focus-visible {
  outline: 3px solid var(--ub-purple, #592d82);
  outline-offset: -3px;
}
.ub-dlg--no-media .ub-dlg-scroll { grid-template-columns: minmax(0, 1fr); }
.ub-dlg-media { padding: 4px 0 32px 32px; }
.ub-dlg-media img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 0;
}
.ub-dlg-main { padding: 4px 40px 32px 36px; }
.ub-dlg--no-media .ub-dlg-main { padding-left: 32px; }
.ub-dlg-meta {
  margin: 0 0 8px;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ub-blue-text, #0a6e8f);
}
.ub-dlg-title {
  margin: 0 0 18px;
  font-size: clamp(1.6rem, 1.2rem + 1.2vw, 2.2rem);
  font-weight: 800;
  line-height: 1.15;
  color: var(--ub-purple-dark, #3f1d61);
}
.ub-dlg-body p {
  margin: 0 0 1em;
  font-size: 1.05rem;
  line-height: 1.7;
}
.ub-dlg-body p:last-child { margin-bottom: 0; }
.ub-dlg-nav {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  border-top: 1px solid #E1E7EA;
}
.ub-dlg-nav .btn { min-height: 44px; justify-content: center; font-family: inherit; }

@media (prefers-reduced-motion: no-preference) {
  .ub-dlg[open] { animation: ub-dlg-in 0.3s cubic-bezier(0.25, 0.8, 0.25, 1); }
  .ub-dlg[open]::backdrop { animation: ub-dlg-fade 0.3s cubic-bezier(0.25, 0.8, 0.25, 1); }
}
@keyframes ub-dlg-in {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: none; }
}
@keyframes ub-dlg-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .ub-dcard { transition: none; }
  .ub-dcard:hover { transform: none; }
}

@media (max-width: 1100px) {
  .ub-dcards--cols-3,
  .ub-dcards--cols-4 { --ub-dc-cols: 2; }
}

/* Phones: one column of rows, a small poster beside each title, and the dialog
   becomes a full-screen sheet. */
@media (max-width: 768px) {
  .ub-dcards--cols-2,
  .ub-dcards--cols-3,
  .ub-dcards--cols-4 { --ub-dc-cols: 1; }
  .ub-dcards-grid { gap: 16px; }

  .ub-dcard.is-enhanced {
    display: grid;
    grid-template-columns: 112px minmax(0, 1fr);
  }
  .ub-dcard-text { padding: 14px 16px 14px 16px; gap: 6px; }
  .ub-dcard-title { font-size: 1.1rem; }
  .ub-dcard-blurb {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    overflow: hidden;
  }

  .ub-dcard-face {
    display: grid;
    grid-template-columns: 112px minmax(0, 1fr);
    column-gap: 16px;
    align-content: start;
    padding-bottom: 14px;
  }
  .ub-dcard-face > .ub-dcard-media { grid-row: 1 / span 5; }
  .ub-dcard-face > :not(.ub-dcard-media) { grid-column: 2; margin-inline: 0 16px; }
  .ub-dcard-face > .ub-dcard-title { margin-top: 14px; }
  .ub-dcard-body { margin: 0 16px; }

  .ub-dlg {
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
  }
  .ub-dlg-panel { max-height: 100dvh; height: 100%; }
  .ub-dlg-top { padding: 10px 16px; }
  .ub-dlg-scroll { grid-template-columns: minmax(0, 1fr); }
  .ub-dlg-media { padding: 0 16px 20px; }
  .ub-dlg-main,
  .ub-dlg--no-media .ub-dlg-main { padding: 0 16px 28px; }
  .ub-dlg-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    padding: 12px 16px;
  }
}
