html:has(.case-reader:is(.is-visible, .is-closing)) {
  overflow: hidden;
}

dialog.case-reader {
  position: fixed;
  inset: 0;
  /* Nine 16:9 thumbnails with 12px insets, 6px gaps, a number gutter and a divider. */
  --reader-frame-height: round(down, min(
    calc((min(94vw, 1760px) - 99px + 72px * 16 / 81) * 81 / 160),
    calc(min(92dvh, 1100px) - 78px)
  ), 1px);
  --reader-rail-width: round(down, calc(49px + (var(--reader-frame-height) - 72px) * 16 / 81), 1px);
  box-sizing: border-box;
  width: calc(50px + var(--reader-rail-width) + round(nearest, var(--reader-frame-height) * 16 / 9, 1px));
  height: calc(78px + var(--reader-frame-height));
  max-width: none;
  max-height: none;
  margin: auto;
  padding: 0 24px 24px;
  border: 1px solid transparent;
  border-radius: 20px;
  background:
    linear-gradient(135deg, #79576748, #79576718 46%, transparent 90%),
    #17161a;
  box-shadow: 0 32px 110px #000d;
  color: #f4f3ef;
  overflow: hidden;
}

dialog.case-reader::before {
  content: "";
  position: absolute;
  inset: 0 auto auto 0;
  box-sizing: border-box;
  /* Scale a full pixel so the hairline stays visible on 1x displays. */
  width: 250%;
  height: 250%;
  border: 1px solid #eb79a9;
  border-radius: 47.5px;
  transform: scale(.4);
  transform-origin: top left;
  pointer-events: none;
}

dialog.case-reader[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  opacity: 0;
  transform: translateY(16px) scale(.78);
  transition: opacity 420ms cubic-bezier(.76, 0, .82, .2),
              transform 420ms cubic-bezier(.76, 0, .82, .2);
}

dialog.case-reader[open].is-visible {
  opacity: 1;
  transform: none;
  transition-timing-function: cubic-bezier(.18, .8, .24, 1);
}

.case-reader::backdrop {
  background: #09080bd4;
  backdrop-filter: blur(7px);
  opacity: 0;
  transition: opacity 340ms ease-in;
}

.case-reader.is-visible::backdrop {
  opacity: 1;
  transition-timing-function: ease-out;
}

.case-reader-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-sizing: border-box;
  height: 52px;
  padding: 8px 6px 8px 12px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .12em;
}

.case-reader-toolbar > span {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-transform: uppercase;
}

.case-reader-toolbar > span::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ff3c89;
  box-shadow: 0 0 10px #ff3c8950;
}

.case-reader-toolbar button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  color: inherit;
  background: transparent;
  border: 0;
  font: 300 24px/1 system-ui, sans-serif;
  cursor: pointer;
  transition: color .2s ease;
}

.case-reader-toolbar button:is(:hover, :focus-visible) {
  color: #ff87b6;
}

.case-reader iframe {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  border: 0;
  border-radius: 12px;
  background: #0d0d0d;
  box-shadow: 0 0 0 1px #a0a0a024, 0 0 14px #a0a0a012;
}

.case-reader-unavailable {
  align-self: center;
  justify-self: center;
  color: inherit;
}


@media (prefers-reduced-motion: reduce) {
  dialog.case-reader[open], .case-reader::backdrop,
  .case-reader-toolbar button { transition: none; }
}
